#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:
parent
5392ae09af
commit
0c401171f3
10 changed files with 1139 additions and 46 deletions
|
|
@ -12,7 +12,9 @@ extends RefCounted
|
|||
## * Gameplay: whether the tips show on the first day and night (Tutorial).
|
||||
## * Co-op: your player name, and whether your microphone is sent in voice chat.
|
||||
## * Touch (phones): the interface size, times the scale the screen's size calls for
|
||||
## (MobilePort.ui_scale; it doesn't change desktop).
|
||||
## (MobilePort.ui_scale; it doesn't change desktop), the sticks swapped, the camera's
|
||||
## distance, and a buzz when the scarecrow is hit. Saved on every platform; only phones
|
||||
## apply them (and show them: SettingsMenu).
|
||||
## Values missing from the file or out of range fall back to the defaults, so an old or
|
||||
## hand-edited file never breaks the game.
|
||||
|
||||
|
|
@ -22,6 +24,11 @@ const BUS_NAMES := {"Master": "Master volume", "Music": "Music and stingers", "S
|
|||
"Voice": "Voice chat (your friend)"}
|
||||
const DEFAULT_VOLUME := {"Master": 0.8, "Music": 0.7, "SFX": 0.8, "Ambience": 0.6, "Voice": 1.0}
|
||||
const MAX_PIXEL_SIZE := 8
|
||||
## Phones: the Interface size's range (MobilePort.ui_scale clamps to the same) and the camera's.
|
||||
const INTERFACE_SIZE_MIN := 0.8
|
||||
const INTERFACE_SIZE_MAX := 1.3
|
||||
const CAMERA_DISTANCE_MIN := 8.0
|
||||
const CAMERA_DISTANCE_MAX := 20.0
|
||||
|
||||
var volume := DEFAULT_VOLUME.duplicate()
|
||||
var move_dead_zone := 0.2
|
||||
|
|
@ -37,8 +44,9 @@ var player_name := ""
|
|||
var microphone := true
|
||||
## Phones: the Interface size, 0.8-1.3 times the scale the screen calls for (MobilePort.ui_scale).
|
||||
var interface_size := 1.0
|
||||
## Phones: the sticks swapped (move on the left: TouchSticks, TouchButtons), the camera's distance
|
||||
## (FollowCamera, 8-20 m), and a short buzz when the scarecrow is hit. Saved and applied by #41.
|
||||
## Phones: the sticks swapped (TouchSticks, TouchButtons: the move stick on the other half), the
|
||||
## follow camera's distance (8-20 m, in place of FollowCamera.PHONE_DISTANCE), and a short buzz
|
||||
## when the scarecrow is hit (Scarecrow.haptics).
|
||||
var swap_sticks := false
|
||||
var camera_distance := FollowCamera.PHONE_DISTANCE
|
||||
var haptics := true
|
||||
|
|
@ -61,7 +69,12 @@ static func load_from(path: String = PATH) -> GameSettings:
|
|||
var n: Variant = f.get_value("coop", "player_name", "")
|
||||
g.player_name = String(n).strip_edges().left(20) if n is String else ""
|
||||
g.microphone = _flag(f.get_value("coop", "microphone", g.microphone), g.microphone)
|
||||
g.interface_size = _number(f.get_value("touch", "interface_size", g.interface_size), 0.8, 1.3, g.interface_size)
|
||||
g.interface_size = _number(f.get_value("touch", "interface_size", g.interface_size), INTERFACE_SIZE_MIN,
|
||||
INTERFACE_SIZE_MAX, g.interface_size)
|
||||
g.swap_sticks = _flag(f.get_value("touch", "swap_sticks", g.swap_sticks), g.swap_sticks)
|
||||
g.camera_distance = _number(f.get_value("touch", "camera_distance", g.camera_distance), CAMERA_DISTANCE_MIN,
|
||||
CAMERA_DISTANCE_MAX, g.camera_distance)
|
||||
g.haptics = _flag(f.get_value("touch", "haptics", g.haptics), g.haptics)
|
||||
return g
|
||||
|
||||
|
||||
|
|
@ -79,11 +92,15 @@ func save_to(path: String = PATH) -> Error:
|
|||
f.set_value("coop", "player_name", player_name)
|
||||
f.set_value("coop", "microphone", microphone)
|
||||
f.set_value("touch", "interface_size", interface_size)
|
||||
f.set_value("touch", "swap_sticks", swap_sticks)
|
||||
f.set_value("touch", "camera_distance", camera_distance)
|
||||
f.set_value("touch", "haptics", haptics)
|
||||
return f.save(path)
|
||||
|
||||
|
||||
## Applies everything: bus volumes, dead zones (into config too, when given), the interface
|
||||
## scale, and the display (skipped without a real display, e.g. headless).
|
||||
## scale, the touch settings (apply_touch), and the display (skipped without a real display, e.g.
|
||||
## headless).
|
||||
func apply(viewport: Viewport, config: GameConfig = null) -> void:
|
||||
for bus in BUSES:
|
||||
var i := AudioServer.get_bus_index(bus)
|
||||
|
|
@ -100,6 +117,7 @@ func apply(viewport: Viewport, config: GameConfig = null) -> void:
|
|||
if viewport != null:
|
||||
apply_pixels(viewport)
|
||||
apply_scale(viewport)
|
||||
apply_touch(viewport.get_tree() if viewport != null else Engine.get_main_loop() as SceneTree)
|
||||
if DisplayServer.get_name() == "headless":
|
||||
return
|
||||
var mode := DisplayServer.window_get_mode()
|
||||
|
|
@ -133,6 +151,22 @@ func apply_scale(viewport: Viewport) -> void:
|
|||
window.content_scale_factor = MobilePort.ui_scale(interface_size)
|
||||
|
||||
|
||||
## The touch settings, live: every node in group &"touch_controls" (TouchSticks, TouchButtons)
|
||||
## gets apply_settings(self) (the sticks' sides follow swap_sticks), and on a phone the follow
|
||||
## camera (group FollowCamera.GROUP) moves to camera_distance and a hit buzzes when haptics is on
|
||||
## (Scarecrow.haptics). Desktop's camera keeps its own distance (16, and the mouse wheel's zoom).
|
||||
## Main applies the settings after the farm is ready, so on a phone this is what sets the
|
||||
## camera's distance.
|
||||
func apply_touch(tree: SceneTree) -> void:
|
||||
Scarecrow.haptics = haptics and MobilePort.active()
|
||||
if tree == null:
|
||||
return
|
||||
tree.call_group(&"touch_controls", &"apply_settings", self)
|
||||
if MobilePort.active():
|
||||
for cam in tree.get_nodes_in_group(FollowCamera.GROUP):
|
||||
(cam as FollowCamera).distance = camera_distance
|
||||
|
||||
|
||||
static func _number(v: Variant, lo: float, hi: float, fallback: float) -> float:
|
||||
if not (v is float or v is int):
|
||||
return fallback
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue