A10: Menus and settings

The game now opens on a main menu when it has a window: practice
against bots (count and skill), join a server (by address, or from a
LAN search list), settings, and quit. In a match, Escape brings up a
pause menu (the match goes on) with settings and leave; when a match
the player was in ends, a results screen shows their place,
eliminations and the last of the feed.

- KeyBindings: every action rebindable to a key or mouse button.
  bind() refuses an input another action uses and names it; Escape is
  reserved. ClientInput reads keys through the bindings.
- GameSettings: bindings, mouse, graphics (quality preset and the
  print pass), audio (master, music and effects buses), display
  (window mode, vsync, frame cap), name, last server and practice
  choices, saved in user://settings.cfg. Missing, unreadable or
  corrupt files and bad values fall back to defaults, value by value;
  hand-edited key clashes are repaired on load.
- Menus (src/ui): paper-and-ink panels, brass focus edge, keyboard
  navigable; a drawn sea-and-tide-post backdrop, or an ink wash over
  a match. AppShell runs menus and the session.
- LocalServer takes a bot difficulty.
- make menu-captures renders every screen.

Closes #50

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 11:30:09 -05:00
co-authored by Claude Opus 5.5
parent 386653f782
commit c504551b28
39 changed files with 2022 additions and 50 deletions
+33 -26
View File
@@ -1,12 +1,12 @@
## Turns the keyboard and mouse into the local player's commands, one per tick.
##
## Keys (physical positions, so they sit the same on any layout):
## Keys come from `bindings` (KeyBindings, set in the settings menu). By default:
## W A S D move · Space jump · Ctrl crouch · Shift sprint · left mouse use or fire ·
## right mouse aim · R reload · E pick up or open · G drop the held item ·
## 1 the boathook, 2 to 6 the five slots · B build mode on and off ·
## in build mode 1 to 5 pick wall, floor, ramp, roof or breakwater, Tab the material,
## and left mouse places.
## Rebinding and gamepads come with the settings menu.
## Gamepads come with A13.
##
## With `autoplay` on, a simple script plays instead: it leaps from the barge over
## land, glides, and walks about. That is for tests and for checking a connection with
@@ -15,6 +15,7 @@ class_name ClientInput
extends RefCounted
var settings: InputSettings = InputSettings.new()
var bindings: KeyBindings = KeyBindings.new()
## The look direction, in radians, in the simulation's convention.
var yaw: float = 0.0
var pitch: float = 0.0
@@ -29,6 +30,14 @@ var build_kind: int = StructureSet.WALL
var material: int = Materials.DRIFTWOOD
var autoplay: bool = false
## Actions held down, and the command buttons they hold.
const HELD: Dictionary = {
"jump": PlayerCommand.BUTTON_JUMP, "crouch": PlayerCommand.BUTTON_CROUCH,
"sprint": PlayerCommand.BUTTON_SPRINT, "reload": PlayerCommand.BUTTON_RELOAD,
"interact": PlayerCommand.BUTTON_INTERACT, "drop": PlayerCommand.BUTTON_DROP,
"fire": PlayerCommand.BUTTON_FIRE, "aim": PlayerCommand.BUTTON_AIM,
}
func aiming() -> bool:
return buttons & PlayerCommand.BUTTON_AIM != 0 and not build_mode
@@ -39,22 +48,13 @@ func poll() -> void:
if autoplay:
return
move = Vector2(
_axis(KEY_D, KEY_A),
_axis(KEY_W, KEY_S),
_axis("right", "left"),
_axis("forward", "back"),
)
buttons = 0
var keys: Dictionary = {
KEY_SPACE: PlayerCommand.BUTTON_JUMP, KEY_CTRL: PlayerCommand.BUTTON_CROUCH,
KEY_SHIFT: PlayerCommand.BUTTON_SPRINT, KEY_R: PlayerCommand.BUTTON_RELOAD,
KEY_E: PlayerCommand.BUTTON_INTERACT, KEY_G: PlayerCommand.BUTTON_DROP,
}
for key: Key in keys:
if Input.is_physical_key_pressed(key):
buttons |= int(keys[key])
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
buttons |= PlayerCommand.BUTTON_FIRE
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
buttons |= PlayerCommand.BUTTON_AIM
for action: String in HELD:
if bindings.is_held(action):
buttons |= int(HELD[action])
## Takes one input event: mouse motion turns the look, and keys that act once per
@@ -66,9 +66,9 @@ func handle(event: InputEvent, captured: bool) -> void:
if motion != null and captured:
turn(motion.relative)
return
var key: InputEventKey = event as InputEventKey
if key != null and key.pressed and not key.echo:
press(key.physical_keycode)
var action: String = bindings.action_for_event(event)
if not action.is_empty():
act(action)
## Turns the look by a mouse motion, in pixels.
@@ -78,14 +78,21 @@ func turn(relative: Vector2) -> void:
pitch = look.y
## A key that acts once per press: the number row, build mode and the material.
## A key that acts once per press, by its default binding (for tests and scripts).
func press(keycode: Key) -> void:
if keycode == KEY_B:
var action: String = bindings.action_using(int(keycode))
if not action.is_empty():
act(action)
## An action that happens once per press: build mode, the material, the number row.
func act(action: String) -> void:
if action == "build":
build_mode = not build_mode
elif keycode == KEY_TAB and build_mode:
elif action == "material" and build_mode:
material = (material + 1) % Materials.NAMES.size()
elif keycode >= KEY_1 and keycode <= KEY_9:
var number: int = keycode - KEY_1
elif action.begins_with("slot_"):
var number: int = action.substr(5).to_int()
if build_mode:
if number < StructureSet.KINDS.size():
build_kind = number
@@ -127,5 +134,5 @@ func autoplay_command(tick: int, me: SimEntity, ground: SimGround) -> PlayerComm
return command(tick)
func _axis(positive: Key, negative: Key) -> float:
return (1.0 if Input.is_physical_key_pressed(positive) else 0.0) - (1.0 if Input.is_physical_key_pressed(negative) else 0.0)
func _axis(positive: String, negative: String) -> float:
return (1.0 if bindings.is_held(positive) else 0.0) - (1.0 if bindings.is_held(negative) else 0.0)
+169
View File
@@ -0,0 +1,169 @@
## Everything the player can set, saved in the user's config file between launches:
## key bindings, the mouse (InputSettings), graphics, audio and the display.
##
## load_from() never fails: a missing, unreadable or corrupt file, or any value of the
## wrong type or out of range, gives the default for what it spoils.
class_name GameSettings
extends RefCounted
const DEFAULT_PATH: String = InputSettings.DEFAULT_PATH
## Graphics quality presets (H2 tunes what each does).
const QUALITY_NAMES: Array[String] = ["Low", "Medium", "High"]
const QUALITY_LOW: int = 0
const QUALITY_MEDIUM: int = 1
const QUALITY_HIGH: int = 2
## Per preset: sun shadow distance in metres (0 = no shadows) and 3D render scale.
const QUALITY: Array[Dictionary] = [
{"shadow_distance": 0.0, "render_scale": 0.75},
{"shadow_distance": 200.0, "render_scale": 1.0},
{"shadow_distance": 400.0, "render_scale": 1.0},
]
const WINDOW_MODES: Array[String] = ["Windowed", "Fullscreen", "Exclusive fullscreen"]
## Frame caps offered, 0 for none.
const FRAME_CAPS: Array[int] = [0, 30, 60, 90, 120, 144, 165, 240]
const MAX_NAME_LENGTH: int = 24
var bindings: KeyBindings = KeyBindings.new()
var mouse: InputSettings = InputSettings.new()
var quality: int = QUALITY_HIGH:
set(value):
quality = clampi(value, 0, QUALITY_NAMES.size() - 1)
## The woodcut print pass (docs/STYLE.md).
var print_pass: bool = true
## Volumes from 0 to 1.
var master_volume: float = 0.8:
set(value):
master_volume = clampf(value, 0.0, 1.0)
var music_volume: float = 0.6:
set(value):
music_volume = clampf(value, 0.0, 1.0)
var effects_volume: float = 0.9:
set(value):
effects_volume = clampf(value, 0.0, 1.0)
var window_mode: int = 0:
set(value):
window_mode = clampi(value, 0, WINDOW_MODES.size() - 1)
var vsync: bool = true
var max_fps: int = 0:
set(value):
max_fps = value if FRAME_CAPS.has(value) else 0
## The name others see, and the last server joined.
var player_name: String = ClientConfig.DEFAULT_NAME:
set(value):
var clean: String = value.strip_edges().left(MAX_NAME_LENGTH)
player_name = clean if not clean.is_empty() else ClientConfig.DEFAULT_NAME
var last_server: String = ""
## Practice: how many bots, and their difficulty (-1 mixed, else an index into
## Tuning.BOT_DIFFICULTIES).
var practice_bots: int = Tuning.SOLO_PLAYERS - 1:
set(value):
practice_bots = clampi(value, 1, Tuning.SOLO_PLAYERS - 1)
var practice_difficulty: int = -1:
set(value):
practice_difficulty = clampi(value, -1, Tuning.BOT_DIFFICULTIES.size() - 1)
func shadow_distance() -> float:
return float(QUALITY[quality]["shadow_distance"])
func render_scale() -> float:
return float(QUALITY[quality]["render_scale"])
func save(path: String = DEFAULT_PATH) -> Error:
var config: ConfigFile = ConfigFile.new()
# The mouse keeps its own section, as InputSettings has always saved it.
config.set_value(InputSettings.SECTION, "mouse_sensitivity", mouse.mouse_sensitivity)
config.set_value(InputSettings.SECTION, "aim_sensitivity_scale", mouse.aim_sensitivity_scale)
config.set_value(InputSettings.SECTION, "invert_y", mouse.invert_y)
bindings.write(config)
config.set_value("graphics", "quality", quality)
config.set_value("graphics", "print_pass", print_pass)
config.set_value("audio", "master", master_volume)
config.set_value("audio", "music", music_volume)
config.set_value("audio", "effects", effects_volume)
config.set_value("display", "window_mode", window_mode)
config.set_value("display", "vsync", vsync)
config.set_value("display", "max_fps", max_fps)
config.set_value("player", "name", player_name)
config.set_value("player", "last_server", last_server)
config.set_value("practice", "bots", practice_bots)
config.set_value("practice", "difficulty", practice_difficulty)
return config.save(path)
static func load_from(path: String = DEFAULT_PATH) -> GameSettings:
var settings: GameSettings = GameSettings.new()
var config: ConfigFile = ConfigFile.new()
if config.load(path) != OK:
return settings
settings.mouse = InputSettings.load_from(path)
settings.bindings = KeyBindings.read(config)
settings.quality = _int(config, "graphics", "quality", settings.quality)
settings.print_pass = _bool(config, "graphics", "print_pass", settings.print_pass)
settings.master_volume = _float(config, "audio", "master", settings.master_volume)
settings.music_volume = _float(config, "audio", "music", settings.music_volume)
settings.effects_volume = _float(config, "audio", "effects", settings.effects_volume)
settings.window_mode = _int(config, "display", "window_mode", settings.window_mode)
settings.vsync = _bool(config, "display", "vsync", settings.vsync)
settings.max_fps = _int(config, "display", "max_fps", settings.max_fps)
var name_value: Variant = config.get_value("player", "name", settings.player_name)
if name_value is String:
settings.player_name = name_value
var server_value: Variant = config.get_value("player", "last_server", "")
if server_value is String:
settings.last_server = String(server_value).strip_edges().left(255)
settings.practice_bots = _int(config, "practice", "bots", settings.practice_bots)
settings.practice_difficulty = _int(config, "practice", "difficulty", settings.practice_difficulty)
return settings
## Applies the display and audio settings to the running program. Graphics apply to
## each MatchView as it is made (MatchView.apply_settings). Does nothing to the window
## when there is none.
func apply_to_program(tree: SceneTree) -> void:
_apply_audio()
if DisplayServer.get_name() == "headless":
return
Engine.max_fps = max_fps
DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if vsync else DisplayServer.VSYNC_DISABLED)
var modes: Array[DisplayServer.WindowMode] = [DisplayServer.WINDOW_MODE_WINDOWED, DisplayServer.WINDOW_MODE_FULLSCREEN, DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN]
if DisplayServer.window_get_mode() != modes[window_mode]:
DisplayServer.window_set_mode(modes[window_mode])
if tree != null and tree.root != null:
tree.root.scaling_3d_scale = render_scale()
## Sets the Master bus, and the Music and Effects buses, making them if they aren't
## there yet (A8's sounds play on them).
func _apply_audio() -> void:
for bus: Array in [["Master", master_volume], ["Music", music_volume], ["Effects", effects_volume]]:
var index: int = AudioServer.get_bus_index(bus[0])
if index < 0:
AudioServer.add_bus()
index = AudioServer.bus_count - 1
AudioServer.set_bus_name(index, bus[0])
AudioServer.set_bus_send(index, "Master")
var volume: float = float(bus[1])
AudioServer.set_bus_mute(index, volume <= 0.0)
AudioServer.set_bus_volume_db(index, linear_to_db(maxf(volume, 0.0001)))
static func _int(config: ConfigFile, section: String, key: String, fallback: int) -> int:
var value: Variant = config.get_value(section, key, fallback)
return int(value) if value is int else fallback
static func _float(config: ConfigFile, section: String, key: String, fallback: float) -> float:
var value: Variant = config.get_value(section, key, fallback)
if (value is float and is_finite(value)) or value is int:
return float(value)
return fallback
static func _bool(config: ConfigFile, section: String, key: String, fallback: bool) -> bool:
var value: Variant = config.get_value(section, key, fallback)
return bool(value) if value is bool else fallback
+1
View File
@@ -0,0 +1 @@
uid://c7fawn3kb6yfm
+2 -2
View File
@@ -49,10 +49,10 @@ static func load_from(path: String = DEFAULT_PATH) -> InputSettings:
if config.load(path) != OK:
return settings
var sensitivity: Variant = config.get_value(SECTION, "mouse_sensitivity", 1.0)
if sensitivity is float or sensitivity is int:
if (sensitivity is float and is_finite(sensitivity)) or sensitivity is int:
settings.mouse_sensitivity = float(sensitivity)
var aim_scale: Variant = config.get_value(SECTION, "aim_sensitivity_scale", 0.6)
if aim_scale is float or aim_scale is int:
if (aim_scale is float and is_finite(aim_scale)) or aim_scale is int:
settings.aim_sensitivity_scale = float(aim_scale)
var invert: Variant = config.get_value(SECTION, "invert_y", false)
if invert is bool:
+195
View File
@@ -0,0 +1,195 @@
## Which key or mouse button does what. Each action has one input, held as a code: a
## physical keycode (positions, so they sit the same on any layout), or a mouse button
## as its negative index (-1 left, -2 right, ...).
##
## The number keys do double duty by design: slot N's key also picks build piece N in
## build mode, so the builds have no actions of their own.
##
## bind() refuses an input another action already uses and names that action, so the
## settings menu can say what clashes. Escape is kept for menus and can't be bound.
class_name KeyBindings
extends RefCounted
## Every action, in the order the settings menu lists them, with its default input.
const ACTIONS: Array[Dictionary] = [
{"id": "forward", "label": "Forward", "default": KEY_W},
{"id": "back", "label": "Back", "default": KEY_S},
{"id": "left", "label": "Left", "default": KEY_A},
{"id": "right", "label": "Right", "default": KEY_D},
{"id": "jump", "label": "Jump", "default": KEY_SPACE},
{"id": "crouch", "label": "Crouch", "default": KEY_CTRL},
{"id": "sprint", "label": "Sprint", "default": KEY_SHIFT},
{"id": "fire", "label": "Use, fire or place", "default": -MOUSE_BUTTON_LEFT},
{"id": "aim", "label": "Aim", "default": -MOUSE_BUTTON_RIGHT},
{"id": "reload", "label": "Reload", "default": KEY_R},
{"id": "interact", "label": "Pick up or open", "default": KEY_E},
{"id": "drop", "label": "Drop held item", "default": KEY_G},
{"id": "build", "label": "Build mode", "default": KEY_B},
{"id": "material", "label": "Next material", "default": KEY_TAB},
{"id": "slot_0", "label": "Boathook / wall", "default": KEY_1},
{"id": "slot_1", "label": "Slot 1 / floor", "default": KEY_2},
{"id": "slot_2", "label": "Slot 2 / ramp", "default": KEY_3},
{"id": "slot_3", "label": "Slot 3 / roof", "default": KEY_4},
{"id": "slot_4", "label": "Slot 4 / breakwater", "default": KEY_5},
{"id": "slot_5", "label": "Slot 5", "default": KEY_6},
]
## Kept for opening and closing menus.
const RESERVED: Array[int] = [KEY_ESCAPE]
## Action id -> code.
var codes: Dictionary = {}
func _init() -> void:
reset()
## Every action back to its default.
func reset() -> void:
codes.clear()
for action: Dictionary in ACTIONS:
codes[action["id"]] = int(action["default"])
static func has_action(action: String) -> bool:
return _index_of(action) >= 0
static func default_of(action: String) -> int:
var index: int = _index_of(action)
return int(ACTIONS[index]["default"]) if index >= 0 else 0
static func label_of(action: String) -> String:
var index: int = _index_of(action)
return String(ACTIONS[index]["label"]) if index >= 0 else action
func code_of(action: String) -> int:
return int(codes.get(action, 0))
## The action using `code`, other than `except`, or "" if none.
func action_using(code: int, except: String = "") -> String:
for action: String in codes:
if action != except and int(codes[action]) == code:
return action
return ""
## Binds `action` to `code`. Returns "" when done, or why not: "unknown action",
## "reserved", "not an input", or the id of the action that already uses it (nothing
## changes then).
func bind(action: String, code: int) -> String:
if not has_action(action):
return "unknown action"
if RESERVED.has(code):
return "reserved"
if not is_valid_code(code):
return "not an input"
var other: String = action_using(code, action)
if not other.is_empty():
return other
codes[action] = code
return ""
## Every action whose input another action also uses (only possible in a hand-edited
## settings file; load_from() repairs those).
func conflicts() -> Array[String]:
var found: Array[String] = []
for action: String in codes:
if not action_using(int(codes[action]), action).is_empty():
found.append(action)
found.sort()
return found
## True if the input for `action` is held now.
func is_held(action: String) -> bool:
var code: int = code_of(action)
if code < 0:
return Input.is_mouse_button_pressed(-code as MouseButton)
if code > 0:
return Input.is_physical_key_pressed(code as Key)
return false
## The action a press event is for, or "".
func action_for_event(event: InputEvent) -> String:
var code: int = code_of_event(event)
return action_using(code) if code != 0 else ""
## The code of a key or mouse button press, or 0 for anything else.
static func code_of_event(event: InputEvent) -> int:
var key: InputEventKey = event as InputEventKey
if key != null and key.pressed and not key.echo:
return int(key.physical_keycode) if key.physical_keycode != KEY_NONE else int(key.keycode)
var button: InputEventMouseButton = event as InputEventMouseButton
if button != null and button.pressed:
return -int(button.button_index)
return 0
static func is_valid_code(code: int) -> bool:
if code < 0:
return -code >= MOUSE_BUTTON_LEFT and -code <= MOUSE_BUTTON_XBUTTON2 and -code != MOUSE_BUTTON_WHEEL_UP and -code != MOUSE_BUTTON_WHEEL_DOWN
return code > 0 and not OS.get_keycode_string(code as Key).is_empty()
## A name for a code, for the settings menu.
static func describe(code: int) -> String:
if code < 0:
match -code:
MOUSE_BUTTON_LEFT:
return "Left mouse"
MOUSE_BUTTON_RIGHT:
return "Right mouse"
MOUSE_BUTTON_MIDDLE:
return "Middle mouse"
_:
return "Mouse %d" % -code
if code == 0:
return "None"
return OS.get_keycode_string(code as Key)
## Writes every binding into `config`'s "keys" section.
func write(config: ConfigFile) -> void:
for action: String in codes:
config.set_value("keys", action, int(codes[action]))
## Reads bindings from `config`. Anything missing, malformed or clashing with an
## earlier action keeps its default, and a default taken by then is left unbound
## rather than doubled.
static func read(config: ConfigFile) -> KeyBindings:
var bindings: KeyBindings = KeyBindings.new()
for action: Dictionary in ACTIONS:
var id: String = action["id"]
if not config.has_section_key("keys", id):
continue
var value: Variant = config.get_value("keys", id)
if value is int and is_valid_code(value) and not RESERVED.has(value):
bindings.codes[id] = int(value)
# Repair clashes in list order: the first action keeps its input.
var taken: Dictionary = {}
for action: Dictionary in ACTIONS:
var id: String = action["id"]
var code: int = int(bindings.codes[id])
if taken.has(code):
code = int(action["default"])
if taken.has(code):
code = 0
bindings.codes[id] = code
if code != 0:
taken[code] = true
return bindings
static func _index_of(action: String) -> int:
for index: int in ACTIONS.size():
if ACTIONS[index]["id"] == action:
return index
return -1
+1
View File
@@ -0,0 +1 @@
uid://br7i81anq3yf4
+13 -1
View File
@@ -19,6 +19,17 @@ var camera: Camera3D
var rig: CameraRig = CameraRig.new()
## The woodcut print pass over the camera (Look.add_print_pass).
var print_pass: MeshInstance3D
var sun: DirectionalLight3D
## Applies the player's graphics settings: the sun's shadows and the print pass.
func apply_settings(settings: GameSettings) -> void:
var distance: float = settings.shadow_distance()
if sun != null:
sun.shadow_enabled = distance > 0.0
sun.directional_shadow_max_distance = maxf(distance, 1.0)
if print_pass != null:
print_pass.visible = settings.print_pass
## Builds the scene for `simulation`. `local_id` is the player this client plays, or 0.
@@ -27,7 +38,8 @@ func setup(simulation: Simulation, local_id: int = 0) -> void:
var world: WorldEnvironment = WorldEnvironment.new()
world.environment = Look.environment()
add_child(world)
add_child(Look.sun())
sun = Look.sun()
add_child(sun)
camera = Camera3D.new()
camera.near = CameraRig.NEAR
+4 -2
View File
@@ -1,7 +1,7 @@
## Tidewall's one table of colours: the drowned-coast palette from docs/STYLE.md.
## Every colour the client draws with comes from here, so the look stays one look; a
## test (test_palette.gd) fails on a colour literal anywhere else in src/client or
## src/app. All values are sRGB. Add a colour here, named for what it is in the world,
## test (test_palette.gd) fails on a colour literal anywhere else in src/client,
## src/app or src/ui. All values are sRGB. Add a colour here, named for what it is in the world,
## before using it, and add it to the table in docs/STYLE.md.
class_name Palette
extends RefCounted
@@ -80,6 +80,8 @@ const INK: Color = Color(0.16, 0.13, 0.11)
const PAPER: Color = Color(0.91, 0.87, 0.78)
## Paper in shadow, for panel edges and dimmed text.
const PAPER_DIM: Color = Color(0.66, 0.62, 0.54)
## Brass seen on paper: the edge of the menu control that has focus.
const GILT_DEEP: Color = Color(0.62, 0.45, 0.12)
## Dark text outline on the HUD.
const OUTLINE: Color = Color(0.08, 0.08, 0.08)