Merge #41: menus and settings at phone scale
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
abbe12b92d
10 changed files with 1139 additions and 46 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -4,10 +4,13 @@ extends Camera3D
|
|||
## Angled top-down camera that trails a target. The framing comes entirely from pitch / yaw /
|
||||
## distance (the transform is overwritten every frame, also in the editor so the framing can be
|
||||
## previewed). PlayerCharacter moves relative to this camera's yaw. Mouse wheel zooms. On a phone
|
||||
## (MobilePort) it starts closer, at PHONE_DISTANCE.
|
||||
## (MobilePort) it starts closer, at PHONE_DISTANCE, and then sits at the Camera distance setting
|
||||
## (GameSettings.apply_touch finds it through GROUP).
|
||||
|
||||
## The phones' distance (the small screen), in place of distance's default when the game starts.
|
||||
const PHONE_DISTANCE := 12.0
|
||||
## Every follow camera is in this group, for the settings.
|
||||
const GROUP := &"follow_camera"
|
||||
|
||||
@export var target: Node3D
|
||||
@export_range(5.0, 89.0) var pitch_deg := 50.0
|
||||
|
|
@ -26,6 +29,7 @@ var _focus := Vector3.ZERO
|
|||
|
||||
func _ready() -> void:
|
||||
physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF
|
||||
add_to_group(GROUP)
|
||||
if not Engine.is_editor_hint() and MobilePort.active():
|
||||
distance = PHONE_DISTANCE
|
||||
snap_to_target()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ extends Node3D
|
|||
## * Health lives in FarmState and carries over between nights (D7). try_damage() is the only
|
||||
## way to hurt the scarecrow: after an accepted hit it is invulnerable for
|
||||
## invulnerability_time, so several hits on one tick cost one hit's damage. Hits blink the
|
||||
## model red, tint the screen (ScarecrowHud), and interrupt patching.
|
||||
## model red, tint the screen (ScarecrowHud), and interrupt patching. On a phone with the
|
||||
## Haptics setting on (haptics, set by GameSettings), the local scarecrow's hits buzz.
|
||||
## * Fear (fear action): every thief within fear_radius flees for fear_duration; carriers
|
||||
## drop their crop (D5) and thieves mid-steal lose their progress. Then fear_cooldown
|
||||
## seconds until the next one. A ring under the scarecrow shows that fear is ready.
|
||||
|
|
@ -27,6 +28,14 @@ signal patch_cancelled
|
|||
signal patch_denied(missing: Dictionary)
|
||||
|
||||
const BURST_TIME := 0.45
|
||||
## A hit's buzz on a phone, in milliseconds.
|
||||
const HIT_BUZZ_MS := 30
|
||||
|
||||
## Whether an accepted hit buzzes the phone: the Haptics setting on a phone (GameSettings.apply
|
||||
## sets it on every change). Read once per hit, never per frame.
|
||||
static var haptics := false
|
||||
## Buzzes so far (buzz()), for tests: the vibration itself can't be observed.
|
||||
static var buzzes := 0
|
||||
|
||||
var config: GameConfig
|
||||
var campaign: CampaignController
|
||||
|
|
@ -181,12 +190,20 @@ func try_damage(amount: int = 1) -> bool:
|
|||
s.record_event("scarecrow_damage", mini(amount, hp()))
|
||||
_set_hp(hp() - amount)
|
||||
cancel_patch()
|
||||
if haptics and remote == null: # (the host's kit for its partner doesn't buzz the host)
|
||||
buzz()
|
||||
damaged.emit(hp())
|
||||
if hp() <= 0:
|
||||
_die()
|
||||
return true
|
||||
|
||||
|
||||
## A short buzz (Input.vibrate_handheld; nothing on desktop), counted in buzzes.
|
||||
static func buzz() -> void:
|
||||
buzzes += 1
|
||||
Input.vibrate_handheld(HIT_BUZZ_MS)
|
||||
|
||||
|
||||
## Fear burst at the scarecrow. Returns how many thieves fled, or -1 if it isn't ready.
|
||||
func use_fear() -> int:
|
||||
if not alive or fear_left > 0.0:
|
||||
|
|
|
|||
|
|
@ -10,10 +10,35 @@ extends CenterContainer
|
|||
## Co-op your name (the lobby and your name tag), and your microphone for voice chat
|
||||
## (not on phones: MobilePort)
|
||||
## Every change is applied and saved at once (changed); Back or Escape / B closes it.
|
||||
## On a phone (MobilePort) the list is shorter and made for fingers:
|
||||
## Audio as on desktop
|
||||
## Touch Interface size, Swap sticks, Camera distance, Haptics, then how the touch
|
||||
## controls work (touch_guide, in place of the bindings)
|
||||
## Display 3D resolution scale
|
||||
## Gameplay tips on the first day and night
|
||||
## (no dead zones, Fullscreen, VSync, pixel size, mouse note, or co-op; Reset to defaults leaves
|
||||
## those alone). The panel fills the safe area (fit), its rows are at least the minimum touch
|
||||
## target tall, and the list scrolls by dragging anywhere on it. A slider only takes a finger that
|
||||
## moves mostly sideways (TouchSlider), so scrolling never nudges a value; the Interface size
|
||||
## applies when its finger lifts (the whole menu rescales with it).
|
||||
|
||||
signal changed
|
||||
signal closed
|
||||
|
||||
const PANEL_MARGIN := 28
|
||||
const BUTTON_HEIGHT := 54.0
|
||||
const SCROLL_SIZE := Vector2(980.0, 640.0)
|
||||
## Phones: a safe area shorter than this (a phone's; not an iPad's) gets the compact panel.
|
||||
const COMPACT_HEIGHT := 800.0
|
||||
## Phones: the panel keeps this far inside the safe area.
|
||||
const EDGE := 8.0
|
||||
## Phones: how far a finger moves (points) before it scrolls the list or takes a slider.
|
||||
const DRAG_SLOP_PT := 10.0
|
||||
## Phones: the setting that applies when its slider's finger lifts, not while it moves.
|
||||
const ON_RELEASE := "interface_size"
|
||||
## Shown here, but Reset to defaults leaves them alone (co-op's).
|
||||
const KEEP_ON_RESET: Array[String] = ["player_name", "microphone"]
|
||||
|
||||
## (label, actions) shown in the bindings list.
|
||||
const BINDINGS := [
|
||||
["Move", []],
|
||||
|
|
@ -43,34 +68,54 @@ const PAD_BUTTONS := {
|
|||
var settings: GameSettings
|
||||
var is_open := false
|
||||
var back_button: Button
|
||||
var reset_button: Button
|
||||
## Controls by setting, for tests: "volume/Master", "move_dead_zone", "aim_dead_zone",
|
||||
## "fullscreen", "vsync", "resolution_scale", "show_tips".
|
||||
## "fullscreen", "vsync", "resolution_scale", "show_tips"; on phones "interface_size",
|
||||
## "swap_sticks", "camera_distance", "haptics" instead of the dead zones, Fullscreen, VSync, and
|
||||
## the pixel size.
|
||||
var controls := {}
|
||||
|
||||
var _box: VBoxContainer
|
||||
var _scroll: ScrollContainer
|
||||
var _values := {} # setting -> value Label
|
||||
var _loading := false
|
||||
var _phone := false
|
||||
var _panel: PanelContainer
|
||||
var _margin: MarginContainer
|
||||
var _outer: VBoxContainer
|
||||
var _title: Label
|
||||
var _tall: Array[Control] = [] # phones: the rows, at least the minimum touch target tall
|
||||
var _guide: Array[Label] = []
|
||||
## Phones: the finger dragging the list (drag_begin), and whether it has started scrolling it.
|
||||
var _drag_on := false
|
||||
var _drag_scrolling := false
|
||||
var _drag_from := Vector2.ZERO
|
||||
var _drag_start := 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
_phone = MobilePort.active()
|
||||
var panel := PanelContainer.new()
|
||||
add_child(panel)
|
||||
_panel = panel
|
||||
var margin := MarginContainer.new()
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
margin.add_theme_constant_override("margin_" + side, 28)
|
||||
margin.add_theme_constant_override("margin_" + side, PANEL_MARGIN)
|
||||
panel.add_child(margin)
|
||||
_margin = margin
|
||||
var outer := VBoxContainer.new()
|
||||
outer.add_theme_constant_override("separation", 14)
|
||||
margin.add_child(outer)
|
||||
_outer = outer
|
||||
var title := Label.new()
|
||||
_title = title
|
||||
title.text = "Settings"
|
||||
title.add_theme_font_size_override("font_size", 44)
|
||||
title.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
outer.add_child(title)
|
||||
_scroll = ScrollContainer.new()
|
||||
_scroll.custom_minimum_size = Vector2(980.0, 640.0)
|
||||
_scroll.custom_minimum_size = SCROLL_SIZE
|
||||
_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
_scroll.follow_focus = true
|
||||
outer.add_child(_scroll)
|
||||
|
|
@ -81,20 +126,30 @@ func _ready() -> void:
|
|||
_head("Audio")
|
||||
for bus in GameSettings.BUSES:
|
||||
_slider("volume/" + bus, GameSettings.BUS_NAMES[bus], 0.0, 1.0, 0.05)
|
||||
_head("Controls")
|
||||
_slider("move_dead_zone", "Move stick dead zone", 0.05, 0.9, 0.05)
|
||||
_slider("aim_dead_zone", "Aim stick dead zone", 0.05, 0.9, 0.05)
|
||||
_note("Mouse aim follows the cursor directly, so it has no sensitivity to set.")
|
||||
_bindings()
|
||||
_head("Display")
|
||||
_check("fullscreen", "Fullscreen")
|
||||
_check("vsync", "VSync")
|
||||
_slider("pixel_size", "Pixel size", 1.0, GameSettings.MAX_PIXEL_SIZE, 1.0)
|
||||
_slider("resolution_scale", "3D resolution scale", 0.5, 1.0, 0.05)
|
||||
_note("Pixel size 1 turns the pixel look off; the resolution scale is used only then.")
|
||||
if _phone:
|
||||
_head("Touch")
|
||||
_slider("interface_size", "Interface size", GameSettings.INTERFACE_SIZE_MIN, GameSettings.INTERFACE_SIZE_MAX, 0.05)
|
||||
_check("swap_sticks", "Swap the sticks (move on the %s)" % ("left" if TouchSticks.MOVE_ON_RIGHT else "right"))
|
||||
_slider("camera_distance", "Camera distance", GameSettings.CAMERA_DISTANCE_MIN, GameSettings.CAMERA_DISTANCE_MAX, 1.0)
|
||||
_check("haptics", "Buzz when the scarecrow is hit")
|
||||
_touch_guide()
|
||||
_head("Display")
|
||||
_slider("resolution_scale", "3D resolution scale", 0.5, 1.0, 0.05)
|
||||
else:
|
||||
_head("Controls")
|
||||
_slider("move_dead_zone", "Move stick dead zone", 0.05, 0.9, 0.05)
|
||||
_slider("aim_dead_zone", "Aim stick dead zone", 0.05, 0.9, 0.05)
|
||||
_note("Mouse aim follows the cursor directly, so it has no sensitivity to set.")
|
||||
_bindings()
|
||||
_head("Display")
|
||||
_check("fullscreen", "Fullscreen")
|
||||
_check("vsync", "VSync")
|
||||
_slider("pixel_size", "Pixel size", 1.0, GameSettings.MAX_PIXEL_SIZE, 1.0)
|
||||
_slider("resolution_scale", "3D resolution scale", 0.5, 1.0, 0.05)
|
||||
_note("Pixel size 1 turns the pixel look off; the resolution scale is used only then.")
|
||||
_head("Gameplay")
|
||||
_check("show_tips", "Tips on the first day and night")
|
||||
if not MobilePort.active(): # no co-op on phones
|
||||
if not _phone: # no co-op on phones
|
||||
_head("Co-op")
|
||||
_text("player_name", "Your name")
|
||||
_check("microphone", "Send my microphone in voice chat")
|
||||
|
|
@ -103,21 +158,76 @@ func _ready() -> void:
|
|||
outer.add_child(row)
|
||||
back_button = Button.new()
|
||||
back_button.text = "Back"
|
||||
back_button.custom_minimum_size = Vector2(220.0, 54.0)
|
||||
back_button.custom_minimum_size = Vector2(220.0, BUTTON_HEIGHT)
|
||||
back_button.pressed.connect(close)
|
||||
row.add_child(back_button)
|
||||
var reset := Button.new()
|
||||
reset.text = "Reset to defaults"
|
||||
reset.custom_minimum_size = Vector2(280.0, 54.0)
|
||||
reset.pressed.connect(func() -> void:
|
||||
var fresh := GameSettings.new()
|
||||
for key in ["volume", "move_dead_zone", "aim_dead_zone", "fullscreen", "vsync", "pixel_size", "resolution_scale", "show_tips"]:
|
||||
settings.set(key, fresh.get(key))
|
||||
_load()
|
||||
changed.emit())
|
||||
row.add_child(reset)
|
||||
reset_button = Button.new()
|
||||
reset_button.text = "Reset to defaults"
|
||||
reset_button.custom_minimum_size = Vector2(280.0, BUTTON_HEIGHT)
|
||||
reset_button.pressed.connect(reset_to_defaults)
|
||||
row.add_child(reset_button)
|
||||
visible = false
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
if _phone:
|
||||
_scroll.gui_input.connect(_on_list_input)
|
||||
get_viewport().size_changed.connect(fit)
|
||||
fit()
|
||||
|
||||
|
||||
## Reset to defaults: every setting shown here but co-op's. What isn't shown (on a phone the dead
|
||||
## zones, Fullscreen, VSync, and the pixel size; on desktop the touch settings) stays as it is.
|
||||
func reset_to_defaults() -> void:
|
||||
var fresh := GameSettings.new()
|
||||
for key: String in controls:
|
||||
if key in KEEP_ON_RESET:
|
||||
continue
|
||||
if key.begins_with("volume/"):
|
||||
var bus := key.trim_prefix("volume/")
|
||||
settings.volume[bus] = fresh.volume[bus]
|
||||
else:
|
||||
settings.set(key, fresh.get(key))
|
||||
_load()
|
||||
changed.emit()
|
||||
_refresh_guide()
|
||||
|
||||
|
||||
## A phone: the panel fills the safe area (up to the desktop's size), the rows and buttons at
|
||||
## least the minimum touch target tall, with a smaller title and margins on a phone's short
|
||||
## canvas. (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)
|
||||
var compact := safe.size.y < COMPACT_HEIGHT
|
||||
var m := 14 if compact else PANEL_MARGIN
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
_margin.add_theme_constant_override("margin_" + side, m)
|
||||
_title.add_theme_font_size_override("font_size", 32 if compact else 44)
|
||||
_outer.add_theme_constant_override("separation", 8 if compact else 14)
|
||||
var target := UiTheme.touch_height(self, 0.0)
|
||||
for c in _tall:
|
||||
c.custom_minimum_size.y = target
|
||||
for b: Button in [back_button, reset_button]:
|
||||
b.custom_minimum_size.y = UiTheme.touch_height(self, BUTTON_HEIGHT)
|
||||
_scroll.custom_minimum_size = Vector2.ZERO
|
||||
var chrome := Vector2(2.0 * m + _panel.get_theme_stylebox(&"panel").get_minimum_size().x,
|
||||
_panel.get_combined_minimum_size().y - _scroll.get_combined_minimum_size().y)
|
||||
_scroll.custom_minimum_size = Vector2(minf(SCROLL_SIZE.x, safe.size.x - chrome.x - 2.0 * EDGE),
|
||||
minf(SCROLL_SIZE.y, safe.size.y - chrome.y - 2.0 * EDGE)).max(Vector2(160.0, 120.0))
|
||||
queue_redraw() # the dim covers the screen from wherever the inset put this
|
||||
|
||||
|
||||
## How the touch controls work (the guide on a phone, in place of the bindings): the sticks'
|
||||
## sides as Prompts says (they follow Swap sticks), then the buttons, the hotbar, and the backpack.
|
||||
static func touch_guide() -> PackedStringArray:
|
||||
return PackedStringArray([
|
||||
"Move: touch the %s half of the screen and slide your thumb." % Prompts.move_side(),
|
||||
"Attack: touch the %s half and slide toward an alien to aim and attack." % Prompts.attack_side(),
|
||||
"Use: hold it to gather, repair, or upgrade; tap it for the workbench or the shed. Build (by day) starts building.",
|
||||
"Fear scares off everything nearby. Bomb throws a pumpkin bomb. Hold Patch to patch up with straw.",
|
||||
"Pause is at the top of the screen. Tap the hotbar to switch weapons, and the backpack to see your pouch.",
|
||||
])
|
||||
|
||||
|
||||
func open(p_settings: GameSettings) -> void:
|
||||
|
|
@ -126,17 +236,23 @@ func open(p_settings: GameSettings) -> void:
|
|||
is_open = true
|
||||
visible = true
|
||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
fit()
|
||||
_scroll.scroll_vertical = 0
|
||||
(controls["volume/Master"] as Control).grab_focus.call_deferred()
|
||||
|
||||
|
||||
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:
|
||||
if not is_open:
|
||||
return
|
||||
drag_end()
|
||||
is_open = false
|
||||
visible = false
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
|
@ -193,6 +309,7 @@ func _load() -> void:
|
|||
elif c is LineEdit:
|
||||
(c as LineEdit).text = String(v)
|
||||
_loading = false
|
||||
_refresh_guide()
|
||||
|
||||
|
||||
func _apply_value(key: String, v: Variant) -> void:
|
||||
|
|
@ -205,6 +322,7 @@ func _apply_value(key: String, v: Variant) -> void:
|
|||
if v is float:
|
||||
_show_value(key, v)
|
||||
changed.emit()
|
||||
_refresh_guide() # (after Main applied it: Swap sticks moves the sticks, and the guide's sides)
|
||||
|
||||
|
||||
func _show_value(key: String, v: float) -> void:
|
||||
|
|
@ -212,6 +330,8 @@ func _show_value(key: String, v: float) -> void:
|
|||
return
|
||||
if key == "pixel_size":
|
||||
(_values[key] as Label).text = "Off" if roundi(v) <= 1 else "%d×" % roundi(v)
|
||||
elif key == "camera_distance":
|
||||
(_values[key] as Label).text = "%d m" % roundi(v)
|
||||
else:
|
||||
(_values[key] as Label).text = "%d%%" % roundi(v * 100.0)
|
||||
|
||||
|
|
@ -240,19 +360,36 @@ func _slider(key: String, label: String, lo: float, hi: float, step: float) -> v
|
|||
l.text = label
|
||||
l.custom_minimum_size = Vector2(340.0, 0.0)
|
||||
row.add_child(l)
|
||||
var s := HSlider.new()
|
||||
var s: HSlider = TouchSlider.new(self) if _phone else HSlider.new()
|
||||
s.min_value = lo
|
||||
s.max_value = hi
|
||||
s.step = step
|
||||
s.custom_minimum_size = Vector2(440.0, 32.0)
|
||||
s.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
s.value_changed.connect(func(v: float) -> void: _apply_value(key, v))
|
||||
s.value_changed.connect(func(v: float) -> void:
|
||||
if key == ON_RELEASE and s is TouchSlider and (s as TouchSlider).sliding():
|
||||
_show_value(key, v) # applied when the finger lifts
|
||||
else:
|
||||
_apply_value(key, v))
|
||||
row.add_child(s)
|
||||
var value := Label.new()
|
||||
value.custom_minimum_size = Vector2(80.0, 0.0)
|
||||
row.add_child(value)
|
||||
controls[key] = s
|
||||
_values[key] = value
|
||||
if _phone: # the row shares its width, and all of its (touch-tall) height is the slider's
|
||||
l.custom_minimum_size.x = 0.0
|
||||
l.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
l.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
s.custom_minimum_size.x = 200.0
|
||||
s.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
s.size_flags_stretch_ratio = 1.4
|
||||
s.size_flags_vertical = Control.SIZE_FILL
|
||||
value.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
if key == ON_RELEASE:
|
||||
s.drag_ended.connect(func(_changed: bool) -> void: _apply_value(key, s.value))
|
||||
_tall.append(row)
|
||||
|
||||
|
||||
func _text(key: String, label: String) -> void:
|
||||
|
|
@ -278,6 +415,28 @@ func _check(key: String, label: String) -> void:
|
|||
c.toggled.connect(func(on: bool) -> void: _apply_value(key, on))
|
||||
_box.add_child(c)
|
||||
controls[key] = c
|
||||
if _phone:
|
||||
c.mouse_filter = Control.MOUSE_FILTER_PASS # a drag from it reaches the list, which scrolls
|
||||
_tall.append(c)
|
||||
|
||||
|
||||
## Phones: the touch guide's lines (touch_guide), under a caption.
|
||||
func _touch_guide() -> void:
|
||||
_note("Playing by touch")
|
||||
for i in touch_guide().size():
|
||||
var l := Label.new()
|
||||
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
l.add_theme_font_size_override("font_size", 19)
|
||||
_box.add_child(l)
|
||||
_guide.append(l)
|
||||
|
||||
|
||||
func _refresh_guide() -> void:
|
||||
if _guide.is_empty():
|
||||
return
|
||||
var lines := touch_guide()
|
||||
for i in _guide.size():
|
||||
_guide[i].text = lines[i]
|
||||
|
||||
|
||||
func _bindings() -> void:
|
||||
|
|
@ -313,3 +472,129 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||
if is_open and event.is_action_pressed("ui_cancel"):
|
||||
close()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
# --- Phones: the list scrolls by dragging (see the class notes) ---
|
||||
|
||||
## How far a finger moves (canvas pixels) before it scrolls the list or takes a slider.
|
||||
func drag_slop() -> float:
|
||||
return MobilePort.minimum_target(self) * DRAG_SLOP_PT / MobilePort.TARGET_PT
|
||||
|
||||
|
||||
## Every touch the rows pass on (the check boxes pass theirs; a TouchSlider hands over its own):
|
||||
## a finger that goes up or down by more than drag_slop scrolls the list. Godot's own touch
|
||||
## scrolling never sees them (it would scroll too).
|
||||
func _on_list_input(e: InputEvent) -> void:
|
||||
var mb := e as InputEventMouseButton
|
||||
if mb != null and mb.button_index == MOUSE_BUTTON_LEFT:
|
||||
if mb.pressed:
|
||||
drag_begin(mb.global_position)
|
||||
else:
|
||||
drag_end()
|
||||
_scroll.accept_event()
|
||||
elif e is InputEventMouseMotion:
|
||||
if _drag_on:
|
||||
drag_move((e as InputEventMouseMotion).global_position)
|
||||
_scroll.accept_event()
|
||||
elif e is InputEventScreenTouch or e is InputEventScreenDrag:
|
||||
_scroll.accept_event()
|
||||
|
||||
|
||||
## A finger down on the list at this canvas point.
|
||||
func drag_begin(at: Vector2) -> void:
|
||||
_drag_on = true
|
||||
_drag_scrolling = false
|
||||
_drag_from = at
|
||||
|
||||
|
||||
## The finger at this point: once it's gone far enough up or down (or now, when forced: a slider
|
||||
## handing it over), the list follows it.
|
||||
func drag_move(at: Vector2, force := false) -> void:
|
||||
if not _drag_on:
|
||||
return
|
||||
if not _drag_scrolling:
|
||||
if not force and absf(at.y - _drag_from.y) <= drag_slop():
|
||||
return
|
||||
_drag_scrolling = true
|
||||
_drag_from = at
|
||||
_drag_start = _scroll.scroll_vertical
|
||||
_box.propagate_notification(NOTIFICATION_SCROLL_BEGIN) # a check box under the finger lets go
|
||||
return
|
||||
_scroll.scroll_vertical = roundi(_drag_start - (at.y - _drag_from.y))
|
||||
|
||||
|
||||
func drag_end() -> void:
|
||||
_drag_on = false
|
||||
_drag_scrolling = false
|
||||
|
||||
|
||||
## A slider in the phone's scrolling list. A finger on it waits to see which way it goes: past the
|
||||
## menu's drag_slop, mostly sideways takes the slider (the value follows the finger), and mostly up
|
||||
## or down hands the finger to the list, which scrolls. A tap sets the value where it lands, as a
|
||||
## click does. Keys and the gamepad work as on any slider.
|
||||
class TouchSlider extends HSlider:
|
||||
enum Finger { NONE, WAITING, SLIDING, SCROLLING }
|
||||
|
||||
var menu: SettingsMenu
|
||||
var finger := Finger.NONE
|
||||
var _from := Vector2.ZERO
|
||||
|
||||
func _init(p_menu: SettingsMenu) -> void:
|
||||
menu = p_menu
|
||||
|
||||
## A finger is moving the value now.
|
||||
func sliding() -> bool:
|
||||
return finger == Finger.SLIDING
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_VISIBILITY_CHANGED and not is_visible_in_tree():
|
||||
finger = Finger.NONE
|
||||
|
||||
func _gui_input(e: InputEvent) -> void:
|
||||
var mb := e as InputEventMouseButton
|
||||
if mb != null and mb.button_index == MOUSE_BUTTON_LEFT:
|
||||
var was := finger
|
||||
finger = Finger.NONE
|
||||
if mb.pressed:
|
||||
finger = Finger.WAITING
|
||||
_from = mb.global_position
|
||||
elif was == Finger.WAITING:
|
||||
_slide_to(mb.position) # a tap
|
||||
elif was == Finger.SLIDING:
|
||||
drag_ended.emit(true)
|
||||
elif was == Finger.SCROLLING:
|
||||
menu.drag_end()
|
||||
accept_event()
|
||||
return
|
||||
var mm := e as InputEventMouseMotion
|
||||
if mm == null or finger == Finger.NONE:
|
||||
return
|
||||
if not (mm.button_mask & MOUSE_BUTTON_MASK_LEFT): # its release went elsewhere
|
||||
if finger == Finger.SCROLLING:
|
||||
menu.drag_end()
|
||||
finger = Finger.NONE
|
||||
return
|
||||
match finger:
|
||||
Finger.WAITING:
|
||||
var d := mm.global_position - _from
|
||||
if d.length() > menu.drag_slop():
|
||||
if absf(d.x) > absf(d.y):
|
||||
finger = Finger.SLIDING
|
||||
drag_started.emit()
|
||||
_slide_to(mm.position)
|
||||
else:
|
||||
finger = Finger.SCROLLING
|
||||
menu.drag_begin(_from)
|
||||
menu.drag_move(mm.global_position, true)
|
||||
Finger.SLIDING:
|
||||
_slide_to(mm.position)
|
||||
Finger.SCROLLING:
|
||||
menu.drag_move(mm.global_position)
|
||||
accept_event()
|
||||
|
||||
## The value under this point (local), as a click on a slider sets it.
|
||||
func _slide_to(at: Vector2) -> void:
|
||||
var grab := float(get_theme_icon(&"grabber").get_width())
|
||||
var room := size.x - grab
|
||||
if room > 0.0:
|
||||
set_as_ratio(clampf((at.x - grab * 0.5) / room, 0.0, 1.0))
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ extends RefCounted
|
|||
## boxes, and tabs to match. Labels keep the default look; the HUD sets its own sizes.
|
||||
## sketch() is the hand-drawn theme the in-game panels use instead (the pause menu and its
|
||||
## questions, the workbench and shed shops), to match the HUD's pouch panel (Sketch).
|
||||
## touch_height, inset_to_safe_area, and overlay_rect fit the menus on a phone.
|
||||
|
||||
const TEXT := Color(0.95, 0.93, 0.85)
|
||||
const GOLD := Color(0.95, 0.82, 0.45)
|
||||
|
|
@ -67,6 +68,35 @@ static func sketch() -> Theme:
|
|||
return t
|
||||
|
||||
|
||||
## --- Menus on a phone (MobilePort): touch-sized buttons, inside the safe area ---
|
||||
## The menus (MainMenu, PauseMenu, ConfirmBox, SettingsMenu) fit themselves on a phone when they
|
||||
## open and whenever the canvas changes (the window, or the Interface size); desktop keeps the
|
||||
## layout they're built with.
|
||||
|
||||
## A canvas item's height on a phone: at least the minimum touch target (44 pt,
|
||||
## MobilePort.minimum_target). On desktop, h.
|
||||
static func touch_height(ci: CanvasItem, h: float) -> float:
|
||||
return maxf(h, ceilf(MobilePort.minimum_target(ci))) if MobilePort.active() else h
|
||||
|
||||
|
||||
## A full-screen overlay (a CenterContainer menu, a child of a CanvasLayer) inset to the safe area,
|
||||
## so what it centers sits clear of the notch, the rounded corners, and the home indicator. Its
|
||||
## dim and its input still cover the whole screen (overlay_rect).
|
||||
static func inset_to_safe_area(c: Control) -> void:
|
||||
var safe := MobilePort.safe_rect(c)
|
||||
var view := c.get_viewport_rect().size
|
||||
c.offset_left = safe.position.x
|
||||
c.offset_top = safe.position.y
|
||||
c.offset_right = safe.end.x - view.x
|
||||
c.offset_bottom = safe.end.y - view.y
|
||||
|
||||
|
||||
## The whole screen in an overlay's coordinates (its own rect unless inset_to_safe_area moved it):
|
||||
## what it dims, and where it takes the pointer so nothing behind it does.
|
||||
static func overlay_rect(c: Control) -> Rect2:
|
||||
return Rect2(-c.position, c.get_viewport_rect().size)
|
||||
|
||||
|
||||
static func _margins(s: StyleBox, x: float, y: float) -> void:
|
||||
s.content_margin_left = x
|
||||
s.content_margin_right = x
|
||||
|
|
|
|||
546
game/tests/mobile/menus_test.gd
Normal file
546
game/tests/mobile/menus_test.gd
Normal file
|
|
@ -0,0 +1,546 @@
|
|||
extends RefCounted
|
||||
## #41, the menus and settings at phone scale, through the entry scene (main.tscn, test save and
|
||||
## settings paths) with MobilePort.forced:
|
||||
## * Fitting: the main menu, the pause menu, the question (ConfirmBox), and settings keep every
|
||||
## button inside the safe area, at least the minimum touch target tall, on a 19.5:9 phone
|
||||
## (about 1.6x, notch and home indicator insets), an iPhone SE (the 1.7 cap, the same insets),
|
||||
## and a 4:3 iPad (1x, status bar and home indicator insets); the main menu's column stays
|
||||
## clear of its credits, and the pause menu's buttons keep their focus order.
|
||||
## * Phone settings: Audio, Touch (Interface size, Swap sticks, Camera distance, Haptics, the touch
|
||||
## guide), Display (3D resolution scale), Gameplay; none of the desktop-only rows. The list
|
||||
## scrolls by dragging (from a slider too, which then keeps its value); a sideways drag moves a
|
||||
## slider and doesn't scroll; a drag from a check box doesn't toggle it, a tap does. The
|
||||
## Interface size applies when its finger lifts.
|
||||
## * GameSettings: the touch settings round-trip through the file, with fallbacks and clamping;
|
||||
## Swap sticks reaches every node in &"touch_controls" (a stub here: TouchSticks and
|
||||
## TouchButtons join with #38); Camera distance sets the follow camera on a phone (at start and
|
||||
## live), never on desktop; Reset to defaults leaves what isn't shown alone (both platforms).
|
||||
## * Haptics: a hit buzzes (Scarecrow.buzz) on a phone with it on, not with it off, never on
|
||||
## desktop.
|
||||
## * Desktop (forced 0): the settings list has the same sections and rows as before, at the same
|
||||
## sizes.
|
||||
|
||||
const Touch := preload("res://game/tests/mobile/touch.gd")
|
||||
const SAVE := "user://test_menus_save.json"
|
||||
const SETTINGS := "user://test_menus_settings.cfg"
|
||||
const ROUND_TRIP := "user://test_menus_round_trip.cfg"
|
||||
const DT := 1.0 / 60.0
|
||||
## name, window pixels, density (0: the preview's guess from the shape), insets in window pixels
|
||||
## (left, top, right, bottom), and the canvas that gives (about).
|
||||
const DEVICES := [
|
||||
["19.5:9 phone", Vector2i(2340, 1080), 0.0, [140, 0, 140, 60], Vector2(1469, 678)],
|
||||
["iPhone SE", Vector2i(1334, 750), 326.0, [140, 0, 140, 60], Vector2(1130, 635)],
|
||||
["4:3 iPad", Vector2i(1600, 1200), 0.0, [0, 40, 0, 40], Vector2(1920, 1440)],
|
||||
]
|
||||
## The desktop settings list, as before #41: a head, a row (its label), a check box, a note, or
|
||||
## the bindings grid (its cell count).
|
||||
const DESKTOP_ROWS := [
|
||||
"head:Audio", "row:Master volume", "row:Music and stingers", "row:Sound effects", "row:Ambience",
|
||||
"row:Voice chat (your friend)",
|
||||
"head:Controls", "row:Move stick dead zone", "row:Aim stick dead zone",
|
||||
"note:Mouse aim follows the cursor directly, so it has no sensitivity to set.", "grid:51",
|
||||
"head:Display", "check:Fullscreen", "check:VSync", "row:Pixel size", "row:3D resolution scale",
|
||||
"note:Pixel size 1 turns the pixel look off; the resolution scale is used only then.",
|
||||
"head:Gameplay", "check:Tips on the first day and night",
|
||||
"head:Co-op", "row:Your name", "check:Send my microphone in voice chat",
|
||||
]
|
||||
const PHONE_ROWS := [
|
||||
"head:Audio", "row:Master volume", "row:Music and stingers", "row:Sound effects", "row:Ambience",
|
||||
"row:Voice chat (your friend)",
|
||||
"head:Touch", "row:Interface size", "check:Swap the sticks (move on the left)", "row:Camera distance",
|
||||
"check:Buzz when the scarecrow is hit", "note:Playing by touch", "guide", "guide", "guide", "guide", "guide",
|
||||
"head:Display", "row:3D resolution scale",
|
||||
"head:Gameplay", "check:Tips on the first day and night",
|
||||
]
|
||||
|
||||
|
||||
## A node in &"touch_controls" standing in for TouchSticks and TouchButtons (#38).
|
||||
class Stub extends Node:
|
||||
var calls: Array = [] # swap_sticks at each apply_settings
|
||||
|
||||
func apply_settings(s: GameSettings) -> void:
|
||||
calls.append(s.swap_sticks)
|
||||
|
||||
|
||||
var t: GameTestRunner
|
||||
var main: Main
|
||||
|
||||
|
||||
func run(p_t) -> void:
|
||||
t = p_t
|
||||
var root := t.root
|
||||
var pixels := [root.scaling_3d_mode, root.scaling_3d_scale, root.msaa_3d]
|
||||
_clean()
|
||||
_round_trip()
|
||||
MobilePort.forced = 1
|
||||
var seed := GameSettings.new() # a phone's defaults, but the camera at 15 m
|
||||
seed.camera_distance = 15.0
|
||||
seed.save_to(SETTINGS)
|
||||
_set_device(DEVICES[0])
|
||||
main = await _start()
|
||||
_camera(15.0, "phones: the Camera distance setting (15) decides the camera's distance at start")
|
||||
for d: Array in DEVICES:
|
||||
await _device(d)
|
||||
await _main_menu(d[0])
|
||||
await _confirm_over(main.main_menu, d[0] + " (main menu)")
|
||||
await _settings_layout(d[0])
|
||||
await _device(DEVICES[0])
|
||||
main.main_menu.new_button.pressed.emit()
|
||||
t.check(main.screen == Main.Screen.PLAYING, "(a new vacation)")
|
||||
main.pause()
|
||||
for d: Array in DEVICES:
|
||||
await _device(d)
|
||||
await _pause_menu(d[0])
|
||||
main.pause_menu.restart_button.pressed.emit()
|
||||
await _confirm_over(main.pause_menu, d[0] + " (pause menu)")
|
||||
await _device(DEVICES[0])
|
||||
main.pause_menu.settings_button.pressed.emit()
|
||||
await _frames()
|
||||
_phone_rows()
|
||||
await _drags()
|
||||
await _swap()
|
||||
await _camera_live()
|
||||
await _interface_size()
|
||||
await _reset_phone()
|
||||
main.settings_menu.back_button.pressed.emit()
|
||||
main.resume()
|
||||
await _haptics_phone()
|
||||
await _stop()
|
||||
|
||||
MobilePort.forced = 0
|
||||
MobilePort.preview_insets = []
|
||||
MobilePort.preview_dpi = 0.0
|
||||
root.size = Vector2i(1920, 1080)
|
||||
seed.haptics = true
|
||||
seed.save_to(SETTINGS)
|
||||
main = await _start()
|
||||
_camera(16.0, "desktop: the camera starts 16 m away whatever the Camera distance setting (15)")
|
||||
await _desktop()
|
||||
await _stop()
|
||||
|
||||
MobilePort.forced = -1
|
||||
MobilePort.preview_insets = []
|
||||
MobilePort.preview_dpi = 0.0
|
||||
Scarecrow.haptics = false
|
||||
GameSettings.new().apply(null) # the defaults for the audio and dead zones, as test_save does
|
||||
root.scaling_3d_mode = pixels[0]
|
||||
root.scaling_3d_scale = pixels[1]
|
||||
root.msaa_3d = pixels[2]
|
||||
_clean()
|
||||
|
||||
|
||||
func _clean() -> void:
|
||||
for p in [SAVE, SAVE + ".tmp", SETTINGS, ROUND_TRIP]:
|
||||
if FileAccess.file_exists(p):
|
||||
DirAccess.remove_absolute(ProjectSettings.globalize_path(p))
|
||||
|
||||
|
||||
func _start() -> Main:
|
||||
var m := (load("res://game/scenes/main.tscn") as PackedScene).instantiate() as Main
|
||||
m.save_path = SAVE
|
||||
m.settings_path = SETTINGS
|
||||
t.root.add_child(m)
|
||||
await _frames()
|
||||
await t.physics_frame
|
||||
return m
|
||||
|
||||
|
||||
func _stop() -> void:
|
||||
main.queue_free()
|
||||
main = null
|
||||
t.paused = false
|
||||
await t.process_frame
|
||||
|
||||
|
||||
func _frames() -> void:
|
||||
await t.process_frame
|
||||
await t.process_frame
|
||||
|
||||
|
||||
func _set_device(d: Array) -> void:
|
||||
MobilePort.preview_dpi = d[2]
|
||||
MobilePort.preview_insets = d[3]
|
||||
t.root.size = d[1]
|
||||
|
||||
|
||||
## The window turns into this device: its size, density, and insets, and the scale for it.
|
||||
func _device(d: Array) -> void:
|
||||
_set_device(d)
|
||||
main.settings.apply_scale(t.root)
|
||||
await _frames()
|
||||
var canvas := t.root.get_visible_rect().size
|
||||
var want: Vector2 = d[4]
|
||||
t.check(absf(canvas.x - want.x) < 3.0 and absf(canvas.y - want.y) < 3.0,
|
||||
"%s: the canvas is about %s (%s, ×%.2f)" % [d[0], want, canvas, t.root.content_scale_factor])
|
||||
|
||||
|
||||
## Each control visible in the safe area, at least the minimum target tall when it's a target.
|
||||
func _fit(where: String, what: String, controls: Array, safe: Rect2, target: float, tall := true) -> void:
|
||||
var bad := PackedStringArray()
|
||||
for c: Control in controls:
|
||||
var r := c.get_global_rect()
|
||||
var name := (c as Button).text if c is Button else String(c.name)
|
||||
if not c.is_visible_in_tree():
|
||||
bad.append("%s hidden" % name)
|
||||
elif not safe.grow(0.5).encloses(r):
|
||||
bad.append("%s at %s" % [name, r])
|
||||
elif tall and r.size.y < target - 0.5:
|
||||
bad.append("%s %.0f tall" % [name, r.size.y])
|
||||
t.check(bad.is_empty(), "%s: %s inside the safe area %s%s (%s)" % [where, what, Rect2i(safe),
|
||||
", at least %.0f tall" % target if tall else "", ", ".join(bad) if not bad.is_empty() else "all %d" % controls.size()])
|
||||
|
||||
|
||||
func _main_menu(device: String) -> void:
|
||||
var mm := main.main_menu
|
||||
t.check(mm.visible and main.screen == Main.Screen.MENU, "(%s: the main menu)" % device)
|
||||
var safe := MobilePort.safe_rect(mm)
|
||||
var target := MobilePort.minimum_target(mm)
|
||||
_fit(device + " main menu", "Continue, New vacation, and Settings", [mm.continue_button, mm.new_button, mm.settings_button], safe, target)
|
||||
_fit(device + " main menu", "the title, the save note, and the credits", [mm._title, mm._sub, mm.save_note, mm._credits], safe, target, false)
|
||||
var column := mm._box.get_global_rect()
|
||||
var credits := mm._credits.get_global_rect()
|
||||
t.check(column.end.y <= credits.position.y, "%s main menu: the column (to %.0f) stays above the credits (from %.0f)" % [device, column.end.y, credits.position.y])
|
||||
t.check(not mm.coop_button.visible and not mm.quit_button.visible, "%s main menu: no co-op, no Quit" % device)
|
||||
|
||||
|
||||
func _pause_menu(device: String) -> void:
|
||||
var pm := main.pause_menu
|
||||
t.check(pm.visible and main.screen == Main.Screen.PAUSED, "(%s: the pause menu)" % device)
|
||||
var safe := MobilePort.safe_rect(pm)
|
||||
var target := MobilePort.minimum_target(pm)
|
||||
_fit(device + " pause menu", "Resume, Restart the night, Settings, and Save & quit", [pm.resume_button, pm.restart_button,
|
||||
pm.settings_button, pm.menu_button], safe, target)
|
||||
_fit(device + " pause menu", "the panel", [pm._panel], safe, target, false)
|
||||
t.check(pm.resume_button.find_valid_focus_neighbor(SIDE_BOTTOM) == pm.restart_button
|
||||
and pm.restart_button.find_valid_focus_neighbor(SIDE_BOTTOM) == pm.settings_button
|
||||
and pm.settings_button.find_valid_focus_neighbor(SIDE_BOTTOM) == pm.menu_button
|
||||
and pm.menu_button.find_valid_focus_neighbor(SIDE_TOP) == pm.settings_button,
|
||||
"%s pause menu: up and down go through the buttons in order" % device)
|
||||
|
||||
|
||||
## A question over this menu (the longest the game asks).
|
||||
func _confirm_over(menu: Control, where: String) -> void:
|
||||
var box := main.confirm
|
||||
if not box.is_open:
|
||||
box.ask("Start a new vacation? It replaces your saved one (the morning of day 12 of 30).", "New vacation", func() -> void: pass)
|
||||
await _frames()
|
||||
var safe := MobilePort.safe_rect(box)
|
||||
var target := MobilePort.minimum_target(box)
|
||||
_fit(where + " question", "its two buttons", [box.yes_button, box.no_button], safe, target)
|
||||
_fit(where + " question", "the message", [box.message], safe, target, false)
|
||||
t.check(box.no_button.has_focus(), "%s question: Cancel is focused" % where)
|
||||
box.close()
|
||||
t.check(menu.visible, "(%s: closed, the menu still there)" % where)
|
||||
|
||||
|
||||
func _settings_layout(device: String) -> void:
|
||||
main.main_menu.settings_button.pressed.emit()
|
||||
var sm := main.settings_menu
|
||||
await _frames()
|
||||
t.check(sm.is_open, "(%s: settings)" % device)
|
||||
var safe := MobilePort.safe_rect(sm)
|
||||
var target := MobilePort.minimum_target(sm)
|
||||
_fit(device + " settings", "Back and Reset to defaults", [sm.back_button, sm.reset_button], safe, target)
|
||||
_fit(device + " settings", "the panel and its list", [sm._panel, sm._scroll], safe, target, false)
|
||||
var short := PackedStringArray()
|
||||
for c in sm._tall:
|
||||
if c.size.y < target - 0.5:
|
||||
short.append("%s %.0f" % [c.name, c.size.y])
|
||||
t.check(sm._tall.size() == 11 and short.is_empty(), "%s settings: every row (%d) at least %.0f tall (%s)" % [device,
|
||||
sm._tall.size(), target, ", ".join(short)])
|
||||
t.check(sm._scroll.size.y >= 240.0, "%s settings: the list shows a good part (%.0f tall)" % [device, sm._scroll.size.y])
|
||||
sm.back_button.pressed.emit()
|
||||
await _frames()
|
||||
t.check(not sm.is_open and main.main_menu.settings_button.has_focus(), "(%s: back to the main menu)" % device)
|
||||
|
||||
|
||||
func _row_name(c: Node) -> String:
|
||||
if c is CheckBox:
|
||||
return "check:" + (c as CheckBox).text
|
||||
if c is GridContainer:
|
||||
return "grid:%d" % c.get_child_count()
|
||||
if c is HBoxContainer:
|
||||
return "row:" + (c.get_child(0) as Label).text
|
||||
var l := c as Label
|
||||
if l == null:
|
||||
return c.get_class()
|
||||
if l.autowrap_mode != TextServer.AUTOWRAP_OFF:
|
||||
return "guide"
|
||||
return ("head:" if l.get_theme_font_size(&"font_size") == 28 else "note:") + l.text
|
||||
|
||||
|
||||
func _rows(sm: SettingsMenu) -> Array:
|
||||
return sm._box.get_children().map(_row_name)
|
||||
|
||||
|
||||
func _phone_rows() -> void:
|
||||
var sm := main.settings_menu
|
||||
var rows := _rows(sm)
|
||||
t.check(rows == PHONE_ROWS, "phone settings: Audio, Touch with the guide, Display, Gameplay (%s)" % ", ".join(rows))
|
||||
for key in ["move_dead_zone", "aim_dead_zone", "fullscreen", "vsync", "pixel_size", "player_name", "microphone"]:
|
||||
t.check(not sm.controls.has(key), "phone settings: no %s" % key)
|
||||
var guide := SettingsMenu.touch_guide()
|
||||
t.check(guide[0] == "Move: touch the right half of the screen and slide your thumb."
|
||||
and guide[1] == "Attack: touch the left half and slide toward an alien to aim and attack.",
|
||||
"the guide's sticks follow Prompts (move on the %s): '%s'" % [Prompts.move_side(), guide[0]])
|
||||
var all := " ".join(guide)
|
||||
t.check(["Use", "Build", "Fear", "Bomb", "Patch", "Pause", "hotbar", "backpack"].all(func(w: String) -> bool: return all.contains(w)),
|
||||
"and it names Use, Build, Fear, Bomb, Patch, Pause, the hotbar, and the backpack")
|
||||
var shown := sm._guide.map(func(l: Label) -> String: return l.text)
|
||||
t.check(shown == Array(guide), "the guide shows those lines")
|
||||
t.check((sm._values["camera_distance"] as Label).text == "15 m" and (sm._values["interface_size"] as Label).text == "100%",
|
||||
"Camera distance reads 15 m and Interface size 100%")
|
||||
|
||||
|
||||
## Fingers on the list: scrolling from a slider leaves its value; sideways moves it.
|
||||
func _drags() -> void:
|
||||
var sm := main.settings_menu
|
||||
var scroll := sm._scroll
|
||||
var music := sm.controls["volume/Music"] as HSlider
|
||||
scroll.scroll_vertical = 0
|
||||
await _frames()
|
||||
var before := music.value
|
||||
var at := music.get_global_rect().get_center()
|
||||
_swipe(at, at + Vector2(6.0, -180.0))
|
||||
await _frames()
|
||||
t.check(is_equal_approx(music.value, before) and scroll.scroll_vertical > 100,
|
||||
"a drag up starting on a slider scrolls the list (%d px) and leaves the value (%.2f)" % [scroll.scroll_vertical, music.value])
|
||||
scroll.scroll_vertical = 0
|
||||
await _frames()
|
||||
at = music.get_global_rect().get_center()
|
||||
_swipe(at, at + Vector2(-160.0, 10.0))
|
||||
await _frames()
|
||||
t.check(music.value < before - 0.1 and scroll.scroll_vertical == 0,
|
||||
"a sideways drag moves the slider (%.2f, was %.2f) and doesn't scroll" % [music.value, before])
|
||||
var r := music.get_global_rect()
|
||||
Touch.tap(0, Vector2(r.end.x - 2.0, r.get_center().y))
|
||||
t.check(is_equal_approx(music.value, 1.0) and is_equal_approx(main.settings.volume["Music"], 1.0),
|
||||
"a tap at a slider's end sets it there (%.2f)" % music.value)
|
||||
var tips := sm.controls["show_tips"] as CheckBox
|
||||
scroll.ensure_control_visible(tips)
|
||||
await _frames()
|
||||
var top := scroll.scroll_vertical
|
||||
var on := tips.button_pressed
|
||||
at = tips.get_global_rect().get_center()
|
||||
_swipe(at, at + Vector2(0.0, 150.0))
|
||||
await _frames()
|
||||
t.check(tips.button_pressed == on and scroll.scroll_vertical < top - 80,
|
||||
"a drag down from a check box scrolls (%d to %d) and doesn't toggle it" % [top, scroll.scroll_vertical])
|
||||
scroll.ensure_control_visible(tips)
|
||||
await _frames()
|
||||
Touch.tap(0, tips.get_global_rect().get_center())
|
||||
t.check(tips.button_pressed != on and main.settings.show_tips != on, "a tap on it toggles it")
|
||||
tips.button_pressed = on
|
||||
|
||||
|
||||
## A finger down at one point, moved to another in steps, and lifted.
|
||||
func _swipe(from: Vector2, to: Vector2, steps := 8) -> void:
|
||||
Touch.touch(0, from, true)
|
||||
var last := from
|
||||
for i in steps:
|
||||
var p := from.lerp(to, float(i + 1) / steps)
|
||||
Touch.drag(0, last, p)
|
||||
last = p
|
||||
Touch.touch(0, to, false)
|
||||
|
||||
|
||||
func _swap() -> void:
|
||||
var sm := main.settings_menu
|
||||
var stub := Stub.new()
|
||||
t.root.add_child(stub)
|
||||
stub.add_to_group(&"touch_controls")
|
||||
var swap := sm.controls["swap_sticks"] as CheckBox
|
||||
sm._scroll.ensure_control_visible(swap)
|
||||
await _frames()
|
||||
t.check(not swap.button_pressed and not main.settings.swap_sticks, "(Swap sticks off)")
|
||||
Touch.tap(0, swap.get_global_rect().get_center())
|
||||
t.check(swap.button_pressed and main.settings.swap_sticks and stub.calls == [true]
|
||||
and GameSettings.load_from(SETTINGS).swap_sticks,
|
||||
"tapping Swap sticks saves it and hands the settings to the touch controls (%s)" % [stub.calls])
|
||||
swap.button_pressed = false
|
||||
t.check(stub.calls == [true, false] and not GameSettings.load_from(SETTINGS).swap_sticks, "and off again")
|
||||
stub.free()
|
||||
|
||||
|
||||
func _camera(want: float, what: String) -> void:
|
||||
var cam := main.sim.camera as FollowCamera
|
||||
t.check(cam != null and is_equal_approx(cam.distance, want) and cam.is_in_group(FollowCamera.GROUP), "%s (%.1f)" % [what, cam.distance])
|
||||
|
||||
|
||||
func _camera_live() -> void:
|
||||
var slider := main.settings_menu.controls["camera_distance"] as HSlider
|
||||
t.check(slider.min_value == 8.0 and slider.max_value == 20.0, "Camera distance goes from 8 to 20 m")
|
||||
slider.value = 19.0
|
||||
_camera(19.0, "moving Camera distance moves the camera at once")
|
||||
t.check(is_equal_approx(GameSettings.load_from(SETTINGS).camera_distance, 19.0) and (main.settings_menu._values["camera_distance"] as Label).text == "19 m",
|
||||
"and it's saved and reads 19 m")
|
||||
slider.value = 15.0
|
||||
|
||||
|
||||
## Interface size: the menu rescales only when the finger lifts.
|
||||
func _interface_size() -> void:
|
||||
var sm := main.settings_menu
|
||||
var slider := sm.controls["interface_size"] as HSlider
|
||||
t.check(is_equal_approx(slider.min_value, 0.8) and is_equal_approx(slider.max_value, 1.3), "Interface size goes from 80% to 130%")
|
||||
sm._scroll.ensure_control_visible(slider)
|
||||
await _frames()
|
||||
var factor := t.root.content_scale_factor
|
||||
var r := slider.get_global_rect()
|
||||
var from := r.get_center()
|
||||
var to := Vector2(r.end.x - 4.0, from.y)
|
||||
Touch.touch(0, from, true)
|
||||
Touch.drag(0, from, from + Vector2(40.0, 0.0))
|
||||
Touch.drag(0, from + Vector2(40.0, 0.0), to)
|
||||
t.check(slider.value > 1.2 and is_equal_approx(t.root.content_scale_factor, factor) and main.settings.interface_size == 1.0,
|
||||
"dragging Interface size (to %d%%) doesn't rescale yet" % roundi(slider.value * 100.0))
|
||||
Touch.touch(0, to, false)
|
||||
t.check(is_equal_approx(main.settings.interface_size, slider.value) and is_equal_approx(t.root.content_scale_factor, MobilePort.ui_scale(slider.value))
|
||||
and t.root.content_scale_factor > factor * 1.15, "lifting the finger applies it: ×%.2f, was ×%.2f" % [t.root.content_scale_factor, factor])
|
||||
await _frames()
|
||||
var safe := MobilePort.safe_rect(sm)
|
||||
_fit("at %d%%" % roundi(slider.value * 100.0), "settings' panel and buttons", [sm._panel, sm.back_button, sm.reset_button], safe,
|
||||
MobilePort.minimum_target(sm))
|
||||
slider.value = 1.0
|
||||
t.check(is_equal_approx(t.root.content_scale_factor, factor) and main.settings.interface_size == 1.0, "a key or a set value applies at once (back to 100%)")
|
||||
await _frames()
|
||||
|
||||
|
||||
func _reset_phone() -> void:
|
||||
var sm := main.settings_menu
|
||||
var s := main.settings
|
||||
s.move_dead_zone = 0.5
|
||||
s.aim_dead_zone = 0.6
|
||||
s.fullscreen = true
|
||||
s.vsync = false
|
||||
s.pixel_size = 3
|
||||
s.volume["Music"] = 0.2
|
||||
s.interface_size = 1.0 # (the canvas stays; the reset of the size itself is checked on desktop's side)
|
||||
s.swap_sticks = true
|
||||
s.camera_distance = 18.0
|
||||
s.haptics = false
|
||||
s.resolution_scale = 0.6
|
||||
s.show_tips = false
|
||||
sm.reset_to_defaults()
|
||||
var fresh := GameSettings.new()
|
||||
t.check(s.volume["Music"] == fresh.volume["Music"] and not s.swap_sticks and s.camera_distance == FollowCamera.PHONE_DISTANCE
|
||||
and s.haptics and s.resolution_scale == fresh.resolution_scale and s.show_tips,
|
||||
"phone Reset to defaults resets what's shown (volumes, the touch settings, resolution, tips)")
|
||||
t.check(s.move_dead_zone == 0.5 and s.aim_dead_zone == 0.6 and s.fullscreen and not s.vsync and s.pixel_size == 3,
|
||||
"and leaves the hidden ones alone (dead zones, Fullscreen, VSync, pixel size)")
|
||||
_camera(FollowCamera.PHONE_DISTANCE, "and the camera goes back to 12 m")
|
||||
s.move_dead_zone = fresh.move_dead_zone
|
||||
s.aim_dead_zone = fresh.aim_dead_zone
|
||||
s.fullscreen = false
|
||||
s.vsync = true
|
||||
s.pixel_size = fresh.pixel_size
|
||||
s.camera_distance = 15.0
|
||||
sm._load()
|
||||
main._on_settings_changed()
|
||||
|
||||
|
||||
func _haptics_phone() -> void:
|
||||
var sim := main.sim
|
||||
sim.intro.skip() # (the scarecrow can't be hit during the intro)
|
||||
var waited := 0.0
|
||||
while sim.intro.busy() and waited < 10.0:
|
||||
sim.intro.step(DT)
|
||||
waited += DT
|
||||
var kit := sim.scarecrow
|
||||
t.check(kit.alive and not sim.intro.busy(), "(the intro skipped: the first morning)")
|
||||
var hp := kit.hp()
|
||||
t.check(main.settings.haptics and Scarecrow.haptics, "phones: Haptics on (the default) arms the buzz")
|
||||
var n := Scarecrow.buzzes
|
||||
kit.invulnerable_left = 0.0
|
||||
t.check(kit.try_damage(1) and Scarecrow.buzzes == n + 1, "phones: a hit buzzes with Haptics on")
|
||||
t.check(not kit.try_damage(1) and Scarecrow.buzzes == n + 1, "a hit refused (invulnerable) doesn't")
|
||||
main.settings.haptics = false
|
||||
main._on_settings_changed()
|
||||
kit.invulnerable_left = 0.0
|
||||
t.check(not Scarecrow.haptics and kit.try_damage(1) and Scarecrow.buzzes == n + 1, "with Haptics off a hit doesn't buzz")
|
||||
main.settings.haptics = true
|
||||
main._on_settings_changed()
|
||||
kit.invulnerable_left = 0.0
|
||||
main.sim.campaign.state.scarecrow_hp = hp
|
||||
|
||||
|
||||
## The settings file's touch section: saved, loaded, clamped, and a default when it's wrong.
|
||||
func _round_trip() -> void:
|
||||
var g := GameSettings.new()
|
||||
t.check(not g.swap_sticks and g.camera_distance == FollowCamera.PHONE_DISTANCE and g.haptics and g.interface_size == 1.0,
|
||||
"touch defaults: sticks as they are, the camera 12 m, Haptics on, Interface size 100%")
|
||||
g.swap_sticks = true
|
||||
g.camera_distance = 17.0
|
||||
g.haptics = false
|
||||
g.interface_size = 1.15
|
||||
g.save_to(ROUND_TRIP)
|
||||
var f := ConfigFile.new()
|
||||
f.load(ROUND_TRIP)
|
||||
t.check(f.get_value("touch", "swap_sticks") == true and f.get_value("touch", "camera_distance") == 17.0
|
||||
and f.get_value("touch", "haptics") == false and is_equal_approx(f.get_value("touch", "interface_size"), 1.15),
|
||||
"they're saved under [touch]: %s" % [f.get_section_keys("touch")])
|
||||
var back := GameSettings.load_from(ROUND_TRIP)
|
||||
t.check(back.swap_sticks and back.camera_distance == 17.0 and not back.haptics and is_equal_approx(back.interface_size, 1.15),
|
||||
"and load back")
|
||||
for bad: Array in [[30.0, 20.0, "too far: 20"], [2, 8.0, "too close: 8"], ["far", 12.0, "not a number: 12"], [NAN, 12.0, "NaN: 12"]]:
|
||||
f.set_value("touch", "camera_distance", bad[0])
|
||||
f.save(ROUND_TRIP)
|
||||
t.check(GameSettings.load_from(ROUND_TRIP).camera_distance == bad[1], "a camera distance %s" % bad[2])
|
||||
f.set_value("touch", "swap_sticks", "yes")
|
||||
f.set_value("touch", "haptics", 0)
|
||||
f.save(ROUND_TRIP)
|
||||
var odd := GameSettings.load_from(ROUND_TRIP)
|
||||
t.check(not odd.swap_sticks and odd.haptics, "Swap sticks and Haptics that aren't true/false load as the defaults (off, on)")
|
||||
f.erase_section("touch")
|
||||
f.save(ROUND_TRIP)
|
||||
var none := GameSettings.load_from(ROUND_TRIP)
|
||||
t.check(not none.swap_sticks and none.camera_distance == 12.0 and none.haptics and none.interface_size == 1.0,
|
||||
"a file without [touch] (from before) loads the defaults")
|
||||
|
||||
|
||||
func _desktop() -> void:
|
||||
t.check(t.root.content_scale_factor == 1.0 and not Scarecrow.haptics, "desktop: factor 1, and no buzz armed though Haptics is on")
|
||||
var kit := main.sim.scarecrow
|
||||
var n := Scarecrow.buzzes
|
||||
kit.invulnerable_left = 0.0
|
||||
t.check(kit.try_damage(1) and Scarecrow.buzzes == n, "desktop: a hit doesn't buzz")
|
||||
kit.invulnerable_left = 0.0
|
||||
var mm := main.main_menu
|
||||
t.check(mm._box.position == Vector2(110.0, 150.0) and mm._shade.offset_right == 700.0 and mm.new_button.custom_minimum_size == Vector2(380.0, 62.0)
|
||||
and mm._credits.autowrap_mode == TextServer.AUTOWRAP_OFF and mm._credits.offset_top == -60.0,
|
||||
"desktop main menu: the column at (110, 150), the shade 700 wide, 380x62 buttons, the credits as before")
|
||||
main.main_menu.settings_button.pressed.emit()
|
||||
await _frames()
|
||||
var sm := main.settings_menu
|
||||
var rows := _rows(sm)
|
||||
t.check(rows == DESKTOP_ROWS, "desktop settings: the same sections and rows as before (%s)" % ", ".join(rows))
|
||||
var music := sm.controls["volume/Music"] as HSlider
|
||||
t.check(not (music is SettingsMenu.TouchSlider) and music.custom_minimum_size == Vector2(440.0, 32.0)
|
||||
and (music.get_parent().get_child(0) as Label).custom_minimum_size == Vector2(340.0, 0.0)
|
||||
and sm._scroll.custom_minimum_size == Vector2(980.0, 640.0) and sm.back_button.custom_minimum_size == Vector2(220.0, 54.0)
|
||||
and sm.reset_button.custom_minimum_size == Vector2(280.0, 54.0) and sm._title.get_theme_font_size(&"font_size") == 44
|
||||
and sm.offset_left == 0.0 and sm.offset_bottom == 0.0 and sm._tall.is_empty(),
|
||||
"desktop settings: the same sizes (sliders 440x32, labels 340, the list 980x640, buttons 220 and 280 by 54)")
|
||||
var panel := sm._panel.get_global_rect()
|
||||
t.check(panel.get_center().distance_to(Vector2(960.0, 540.0)) <= 1.0, "desktop settings: centered (%s)" % panel)
|
||||
for key in ["interface_size", "swap_sticks", "camera_distance", "haptics"]:
|
||||
t.check(not sm.controls.has(key), "desktop settings: no %s" % key)
|
||||
var s := main.settings
|
||||
s.interface_size = 1.2
|
||||
s.swap_sticks = true
|
||||
s.camera_distance = 18.0
|
||||
s.haptics = false
|
||||
s.move_dead_zone = 0.5
|
||||
sm.reset_to_defaults()
|
||||
t.check(is_equal_approx(s.interface_size, 1.2) and s.swap_sticks and s.camera_distance == 18.0 and not s.haptics,
|
||||
"desktop Reset to defaults leaves the touch settings alone")
|
||||
t.check(s.move_dead_zone == GameSettings.new().move_dead_zone, "and resets what's shown (the dead zone)")
|
||||
_camera(16.0, "desktop: the Camera distance setting never moves the camera")
|
||||
sm.back_button.pressed.emit()
|
||||
await _frames()
|
||||
var pm := main.pause_menu
|
||||
t.check(pm._side == null and pm.resume_button.get_parent() == pm._box and pm.resume_button.custom_minimum_size == Vector2(420.0, 56.0)
|
||||
and pm._assets[0].get_parent() is HBoxContainer and pm.offset_top == 0.0,
|
||||
"desktop pause menu: one column, 420x56 buttons, as before")
|
||||
var box := main.confirm
|
||||
t.check(box.yes_button.custom_minimum_size == Vector2(240.0, 54.0) and box.no_button.custom_minimum_size == Vector2(200.0, 54.0)
|
||||
and box.offset_left == 0.0 and box.offset_bottom == 0.0, "desktop question: 240x54 and 200x54 buttons, full screen")
|
||||
1
game/tests/mobile/menus_test.gd.uid
Normal file
1
game/tests/mobile/menus_test.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://diluix7elstq8
|
||||
Loading…
Add table
Add a link
Reference in a new issue