#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

@ -2,7 +2,10 @@ class_name ConfirmBox
extends CenterContainer
## A yes / no question over the menus (Main): the message, the confirming button, and Cancel
## (focused, so a stray Enter / A never throws progress away). Escape / B cancels. Hand-drawn like
## the pause menu it mostly opens from (UiTheme.sketch).
## the pause menu it mostly opens from (UiTheme.sketch). On a phone it sits in the middle of the
## safe area with touch-sized buttons (fit).
const BUTTON_HEIGHT := 54.0
var message: Label
var yes_button: Button
@ -10,6 +13,7 @@ var no_button: Button
var is_open := false
var _on_yes: Callable
var _phone := false
func _ready() -> void:
@ -36,18 +40,33 @@ func _ready() -> void:
row.add_theme_constant_override("separation", 24)
box.add_child(row)
yes_button = Button.new()
yes_button.custom_minimum_size = Vector2(240.0, 54.0)
yes_button.custom_minimum_size = Vector2(240.0, BUTTON_HEIGHT)
yes_button.add_theme_font_size_override("font_size", 30)
yes_button.pressed.connect(_yes)
row.add_child(yes_button)
no_button = Button.new()
no_button.text = "Cancel"
no_button.custom_minimum_size = Vector2(200.0, 54.0)
no_button.custom_minimum_size = Vector2(200.0, BUTTON_HEIGHT)
no_button.add_theme_font_size_override("font_size", 30)
no_button.pressed.connect(close)
row.add_child(no_button)
visible = false
mouse_filter = Control.MOUSE_FILTER_IGNORE
_phone = MobilePort.active()
if _phone:
get_viewport().size_changed.connect(fit)
fit()
## A phone: inside the safe area, the buttons at least the minimum touch target tall. (Nothing on
## desktop.)
func fit() -> void:
if not _phone or not is_inside_tree():
return
UiTheme.inset_to_safe_area(self)
for b: Button in [yes_button, no_button]:
b.custom_minimum_size.y = UiTheme.touch_height(self, BUTTON_HEIGHT)
queue_redraw() # the dim covers the screen from wherever the inset put this
func ask(text: String, confirm_text: String, on_yes: Callable) -> void:
@ -57,6 +76,7 @@ func ask(text: String, confirm_text: String, on_yes: Callable) -> void:
is_open = true
visible = true
mouse_filter = Control.MOUSE_FILTER_STOP
fit()
no_button.grab_focus.call_deferred()
@ -69,7 +89,11 @@ func close() -> void:
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, size), Color(0.0, 0.0, 0.0, 0.45)) # dims what's behind
draw_rect(UiTheme.overlay_rect(self), Color(0.0, 0.0, 0.0, 0.45)) # 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 _yes() -> void: