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:
@@ -26,6 +26,13 @@ var frames: int = 0
|
||||
|
||||
## The in-game HUD, once the session is in a scene tree.
|
||||
var hud: Hud = null
|
||||
## The player's settings (see use_settings()).
|
||||
var settings: GameSettings = GameSettings.new()
|
||||
## Escape asks for the pause menu: whoever runs the session shows it (AppShell). With
|
||||
## nobody listening, Escape only lets go of the mouse.
|
||||
signal pause_requested
|
||||
## True while a menu is over the match: the keys and mouse don't play.
|
||||
var paused: bool = false
|
||||
|
||||
var _viewed: Simulation = null
|
||||
var _status: Label = null
|
||||
@@ -45,8 +52,23 @@ func connect_to(host: String, port: int, player_name: String) -> Error:
|
||||
|
||||
|
||||
## Starts an offline match of this player and `bots` bots on a server in this process.
|
||||
func play_offline(match_seed: int, bots: int, rules: MatchRules = null) -> void:
|
||||
local = LocalServer.new(match_seed, bots, rules)
|
||||
func play_offline(match_seed: int, bots: int, rules: MatchRules = null, difficulty: int = -1) -> void:
|
||||
local = LocalServer.new(match_seed, bots, rules, difficulty)
|
||||
|
||||
|
||||
## Takes the player's settings: their keys and mouse now, and graphics for each
|
||||
## match's view.
|
||||
func use_settings(with: GameSettings) -> void:
|
||||
settings = with
|
||||
input.settings = with.mouse
|
||||
input.bindings = with.bindings
|
||||
if view != null:
|
||||
view.apply_settings(with)
|
||||
|
||||
|
||||
## The handle this client plays as: the server's name for it in the feed.
|
||||
func own_handle() -> int:
|
||||
return LocalServer.HANDLE if local != null else (link.handle if link != null else 0)
|
||||
|
||||
|
||||
## Leaves the server, if there is one across the network.
|
||||
@@ -72,7 +94,12 @@ func status_text() -> String:
|
||||
## One frame: packets in, commands out, and the picture brought up to date.
|
||||
func pump(delta: float) -> void:
|
||||
frames += 1
|
||||
input.poll()
|
||||
if paused:
|
||||
# Nothing held while a menu is up, so the player stops rather than runs on.
|
||||
input.move = Vector2.ZERO
|
||||
input.buttons = 0
|
||||
else:
|
||||
input.poll()
|
||||
if link != null:
|
||||
game.poll()
|
||||
if local != null:
|
||||
@@ -109,20 +136,22 @@ func _process(delta: float) -> void:
|
||||
|
||||
## What the HUD should show now.
|
||||
func hud_state() -> HudState:
|
||||
var handle: int = LocalServer.HANDLE if local != null else (link.handle if link != null else 0)
|
||||
return HudState.from_client(game, input, handle)
|
||||
return HudState.from_client(game, input, own_handle())
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
var captured: bool = Input.mouse_mode == Input.MOUSE_MODE_CAPTURED
|
||||
var key: InputEventKey = event as InputEventKey
|
||||
var click: InputEventMouseButton = event as InputEventMouseButton
|
||||
if key != null and key.pressed and key.physical_keycode == KEY_ESCAPE:
|
||||
# Escape lets go of the mouse; a click takes it back.
|
||||
if key != null and key.pressed and not key.echo and key.physical_keycode == KEY_ESCAPE:
|
||||
# Escape lets go of the mouse and asks for the pause menu; a click takes the
|
||||
# mouse back when there is no menu.
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
elif click != null and click.pressed and not captured and not input.autoplay:
|
||||
pause_requested.emit()
|
||||
get_viewport().set_input_as_handled()
|
||||
elif click != null and click.pressed and not captured and not input.autoplay and not paused:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
else:
|
||||
elif not paused:
|
||||
input.handle(event, captured)
|
||||
|
||||
|
||||
@@ -149,6 +178,7 @@ func _show(delta: float) -> void:
|
||||
if _viewed != null:
|
||||
view = MatchView.new()
|
||||
view.setup(_viewed, 0)
|
||||
view.apply_settings(settings)
|
||||
add_child(view)
|
||||
move_child(view, 0)
|
||||
ghost = BuildGhost.new()
|
||||
|
||||
Reference in New Issue
Block a user