#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
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue