#41: menus and settings at phone scale

On phones the main menu, pause menu, question box, and settings fit the
scaled canvas inside the safe area, with buttons and rows at least 44 pt
tall (19.5:9 at 1.6x, the iPhone SE at the 1.7 cap, 4:3 iPads). The
pause menu puts its buttons in a column beside the rest.

Phone settings: Audio, Touch (Interface size, Swap sticks, Camera
distance, Haptics, and a short touch-controls guide), Display (3D
resolution scale), and Gameplay. The list scrolls by dragging, and a
slider only moves after a mostly sideways drag. GameSettings saves the
touch settings under [touch] and applies them live (&"touch_controls",
the follow camera on phones). A hit buzzes the phone with Haptics on.
Desktop menus are unchanged. Test: game/tests/mobile/menus_test.gd.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-14 15:20:15 -04:00
parent 5392ae09af
commit 0c401171f3
10 changed files with 1139 additions and 46 deletions

View file

@ -5,6 +5,9 @@ extends CenterContainer
## (crops, animals, supplies; asset_counts), then Resume, Restart the night, Settings, Save & quit
## to the menu, and Quit the game (not on phones, MobilePort), with a reminder of what Continue
## picks up (the vacation is saved every morning).
## On a phone the buttons stand in a column beside the rest (the panel is wide and short enough
## for a phone held sideways), the whole panel in the middle of the safe area with touch-sized
## buttons, and on a short canvas (a phone's, not an iPad's) smaller type: fit.
signal resume_requested
signal restart_requested
@ -12,6 +15,15 @@ signal settings_requested
signal menu_requested
signal quit_requested
const BUTTON_SIZE := Vector2(420.0, 56.0)
## Phones: the sizes as built (REGULAR), and the smaller ones for when those don't fit (COMPACT):
## the font sizes of the title, where you are, the assets, the note, and the buttons; the note's
## width, the buttons' width, and the gaps.
const REGULAR := {"title": 56, "where": 28, "assets": 30, "note": 22, "button": 30, "note_width": 520.0,
"button_width": 420.0, "separation": 14}
const COMPACT := {"title": 44, "where": 24, "assets": 26, "note": 20, "button": 28, "note_width": 380.0,
"button_width": 340.0, "separation": 10}
var resume_button: Button
var restart_button: Button
var settings_button: Button
@ -20,12 +32,20 @@ var quit_button: Button
var _where: Label
var _note: Label
var _assets: Array[Label] = []
var _phone := false
var _panel: PanelContainer
var _box: VBoxContainer
var _title: Label
var _buttons: Array[Button] = []
var _side: VBoxContainer # phones: the buttons' column
func _ready() -> void:
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
theme = UiTheme.sketch()
_phone = MobilePort.active()
var panel := PanelContainer.new()
_panel = panel
add_child(panel)
var margin := MarginContainer.new()
for side in ["left", "right", "top", "bottom"]:
@ -34,7 +54,9 @@ func _ready() -> void:
var box := VBoxContainer.new()
box.add_theme_constant_override("separation", 14)
margin.add_child(box)
_box = box
var title := Label.new()
_title = title
title.text = "Paused"
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
title.add_theme_font_size_override("font_size", 56)
@ -45,9 +67,17 @@ func _ready() -> void:
_where.add_theme_font_size_override("font_size", 28)
_where.add_theme_color_override("font_color", Sketch.DIM)
box.add_child(_where)
var assets := HBoxContainer.new()
assets.alignment = BoxContainer.ALIGNMENT_CENTER
assets.add_theme_constant_override("separation", 30)
var assets: Container
if _phone: # a narrower column: the assets wrap
var flow := HFlowContainer.new()
flow.alignment = FlowContainer.ALIGNMENT_CENTER
flow.add_theme_constant_override("h_separation", 30)
assets = flow
else:
var row := HBoxContainer.new()
row.alignment = BoxContainer.ALIGNMENT_CENTER
row.add_theme_constant_override("separation", 30)
assets = row
box.add_child(assets)
for c in 3:
var l := Label.new()
@ -73,8 +103,58 @@ func _ready() -> void:
_note.add_theme_font_size_override("font_size", 22)
_note.add_theme_color_override("font_color", Sketch.DIM)
box.add_child(_note)
_buttons = [resume_button, restart_button, settings_button, menu_button, quit_button]
if _phone:
_side_by_side(margin)
visible = false
mouse_filter = Control.MOUSE_FILTER_IGNORE
if _phone:
get_viewport().size_changed.connect(fit)
fit()
## Phones: the buttons move to a column of their own beside the title, the assets, and the note.
func _side_by_side(margin: MarginContainer) -> void:
var columns := HBoxContainer.new()
columns.add_theme_constant_override("separation", 24)
margin.remove_child(_box)
margin.add_child(columns)
_box.alignment = BoxContainer.ALIGNMENT_CENTER
columns.add_child(_box)
_side = VBoxContainer.new()
_side.alignment = BoxContainer.ALIGNMENT_CENTER
columns.add_child(_side)
for b in _buttons:
b.reparent(_side, false)
## A phone: the panel in the middle of the safe area, the buttons at least the minimum touch
## target tall, and the compact sizes when the regular ones don't fit. (Nothing on desktop.)
func fit() -> void:
if not _phone or not is_inside_tree():
return
UiTheme.inset_to_safe_area(self)
var safe := MobilePort.safe_rect(self)
for sizes: Dictionary in [REGULAR, COMPACT]:
_use(sizes)
var need := _panel.get_combined_minimum_size()
if need.x <= safe.size.x and need.y <= safe.size.y:
break
queue_redraw() # the dim covers the screen from wherever the inset put this
func _use(sizes: Dictionary) -> void:
_title.add_theme_font_size_override("font_size", sizes["title"])
_where.add_theme_font_size_override("font_size", sizes["where"])
for l in _assets:
l.add_theme_font_size_override("font_size", sizes["assets"])
_note.add_theme_font_size_override("font_size", sizes["note"])
_note.custom_minimum_size.x = sizes["note_width"]
for b in _buttons:
b.add_theme_font_size_override("font_size", sizes["button"])
b.custom_minimum_size = Vector2(sizes["button_width"], UiTheme.touch_height(self, BUTTON_SIZE.y))
_box.add_theme_constant_override("separation", sizes["separation"])
_side.add_theme_constant_override("separation", sizes["separation"])
## coop: 0 solo, 1 hosting a co-op game, 2 a partner in one (the farm doesn't stop for menus).
@ -97,6 +177,7 @@ func open(campaign: CampaignController, coop: int = 0) -> void:
_note.text = "Co-op: the farm keeps going while you're in this menu. Only the host can restart the night; the host's game is saved."
visible = true
mouse_filter = Control.MOUSE_FILTER_STOP
fit()
resume_button.grab_focus.call_deferred()
@ -118,7 +199,11 @@ func describe_assets() -> String:
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, size), Color(0.0, 0.0, 0.0, 0.4)) # dims what's behind
draw_rect(UiTheme.overlay_rect(self), Color(0.0, 0.0, 0.0, 0.4)) # dims what's behind
func _has_point(point: Vector2) -> bool:
return UiTheme.overlay_rect(self).has_point(point) # all of the screen, also outside the safe area
func close() -> void:
@ -129,7 +214,7 @@ func close() -> void:
func _button(parent: Control, text: String) -> Button:
var b := Button.new()
b.text = text
b.custom_minimum_size = Vector2(420.0, 56.0)
b.custom_minimum_size = BUTTON_SIZE
b.add_theme_font_size_override("font_size", 30)
parent.add_child(b)
return b