#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 Control
## vacation, Play with a friend (co-op, CoopMenu; not on phones), Settings, and Quit (not on
## phones either), and a notice line (e.g.
## why a co-op game ended). Mouse, keyboard, and gamepad work through focus.
## On a phone the column and the credits sit inside the safe area (clear of the notch and the home
## indicator), the buttons at least the minimum touch target tall, with smaller type and gaps
## when the canvas is too short for the desktop's (fit).
signal continue_requested
signal new_requested
@ -12,6 +15,18 @@ signal settings_requested
signal coop_requested
signal quit_requested
const BUTTON_SIZE := Vector2(380.0, 62.0)
## Phones: the layouts to try, roomiest first (the first is the desktop's): the title's,
## subtitle's, and credits' font sizes, the gap above the buttons, the column's gaps, and its
## distance from the safe area's top-left corner (the credits line up with it, BOTTOM_PAD above
## the safe area's bottom).
const LAYOUTS: Array[Dictionary] = [
{"title": 92, "sub": 28, "credits": 16, "gap": 50.0, "separation": 16, "pad": Vector2(110.0, 150.0)},
{"title": 72, "sub": 26, "credits": 16, "gap": 12.0, "separation": 10, "pad": Vector2(56.0, 28.0)},
{"title": 60, "sub": 22, "credits": 14, "gap": 0.0, "separation": 6, "pad": Vector2(40.0, 10.0)},
]
const BOTTOM_PAD := 14.0
var continue_button: Button
var new_button: Button
var settings_button: Button
@ -20,6 +35,14 @@ var notice: Label
var quit_button: Button
var save_note: Label
var _phone := false
var _shade: ColorRect
var _box: VBoxContainer
var _title: Label
var _sub: Label
var _gap: Control
var _credits: Label
func _ready() -> void:
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
@ -29,7 +52,9 @@ func _ready() -> void:
add_child(shade)
shade.set_anchors_and_offsets_preset(Control.PRESET_LEFT_WIDE)
shade.offset_right = 700.0
_shade = shade
var box := VBoxContainer.new()
_box = box
box.position = Vector2(110.0, 150.0)
box.add_theme_constant_override("separation", 16)
add_child(box)
@ -40,14 +65,17 @@ func _ready() -> void:
title.add_theme_color_override("font_outline_color", Color(0.15, 0.1, 0.05))
title.add_theme_constant_override("outline_size", 14)
box.add_child(title)
_title = title
var sub := Label.new()
sub.text = "The farmers are away. You're the scarecrow."
sub.add_theme_font_size_override("font_size", 28)
sub.add_theme_color_override("font_color", UiTheme.TEXT)
box.add_child(sub)
_sub = sub
var gap := Control.new()
gap.custom_minimum_size = Vector2(0.0, 50.0)
box.add_child(gap)
_gap = gap
continue_button = _button(box, "Continue")
continue_button.pressed.connect(func() -> void: continue_requested.emit())
save_note = Label.new()
@ -76,7 +104,45 @@ func _ready() -> void:
credits.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_LEFT)
credits.offset_top = -60.0
credits.offset_left = 110.0
_credits = credits
visible = false
_phone = MobilePort.active()
if _phone:
get_viewport().size_changed.connect(fit)
fit()
## A phone: the column and the credits (wrapped to the column's width, so they stay on the shade)
## inside the safe area, the buttons at least the minimum touch target tall, in the roomiest of
## LAYOUTS that fits. (Nothing on desktop.)
func fit() -> void:
if not _phone or not is_inside_tree():
return
var safe := MobilePort.safe_rect(self)
var view := get_viewport_rect().size
for b: Button in [continue_button, new_button, coop_button, settings_button, quit_button]:
b.custom_minimum_size.y = UiTheme.touch_height(self, BUTTON_SIZE.y)
for layout in LAYOUTS:
var pad: Vector2 = layout["pad"]
_title.add_theme_font_size_override("font_size", layout["title"])
_sub.add_theme_font_size_override("font_size", layout["sub"])
_gap.custom_minimum_size.y = layout["gap"]
_box.add_theme_constant_override("separation", layout["separation"])
var column := _box.get_combined_minimum_size()
_credits.add_theme_font_size_override("font_size", layout["credits"])
_credits.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART # under the column, on its shade
_credits.custom_minimum_size.x = column.x
_credits.size = Vector2(column.x, 0.0)
var credits_h := _credits.get_combined_minimum_size().y
_box.position = safe.position + pad
_box.size = column
_credits.offset_left = safe.position.x + pad.x
_credits.offset_right = _credits.offset_left + _credits.custom_minimum_size.x
_credits.offset_bottom = safe.end.y - view.y - BOTTOM_PAD
_credits.offset_top = _credits.offset_bottom - credits_h
_shade.offset_right = _box.position.x + column.x + pad.x
if pad.y + column.y + BOTTOM_PAD + credits_h + BOTTOM_PAD <= safe.size.y and pad.x + column.x <= safe.size.x:
break
## Shows the menu for the save as read (SaveGame.read): Continue says where it resumes, or is
@ -91,6 +157,7 @@ func open(saved: SaveGame.Loaded, nights: int) -> void:
(" · saved " + saved.saved_at.replace("T", " ").left(16)) if saved.saved_at != "" else ""]
else:
save_note.text = saved.message if saved != null else "No saved vacation"
fit()
_focus_first.call_deferred()
@ -109,7 +176,7 @@ func _button(parent: Control, text: String) -> Button:
var b := Button.new()
b.text = text
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
b.custom_minimum_size = Vector2(380.0, 62.0)
b.custom_minimum_size = BUTTON_SIZE
b.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
b.add_theme_font_size_override("font_size", 28)
parent.add_child(b)