Gamepad: PadInput reads pad events in one fixed layout (sticks move and look, triggers aim and fire, bumpers step slots and build pieces, Start pauses), fed through ClientInput alongside the keys and mouse. Menus take South to choose and East or Start to go back. The tutorial names pad buttons once the pad is used. Aim assist (option, on by default, pad only): friction across an opponent in plain sight near the look, and a pull of at most 9 deg/s while aiming. Client look only; never through cover. Accessibility (new Access tab): colour-vision sets for the signal colours (red-green, blue-yellow), checked by simulated colour vision in test_palette; interface size 90-130%, with the HUD hotbar refitting at the larger sizes; captions for key sounds with direction; reduce motion (calmer aim zoom and hurt flash). Tests for the pad, aim assist, captions, palettes, settings, the menus driven from a pad, and a pad playing through a real offline session. make access-captures renders the new screens and options. Closes #53 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
399 lines
15 KiB
GDScript
399 lines
15 KiB
GDScript
extends TestCase
|
|
|
|
## A10: every menu reachable and navigable, key rebinding through the menu, and the
|
|
## program's flow from the main menu into a practice match, the pause menu, the
|
|
## results and back.
|
|
|
|
const PATH: String = "user://test_menus_settings.cfg"
|
|
|
|
var menus: Menus
|
|
var tree: SceneTree
|
|
|
|
|
|
func before_each() -> void:
|
|
super.before_each()
|
|
tree = Engine.get_main_loop() as SceneTree
|
|
menus = Menus.new()
|
|
menus.use_settings(GameSettings.new(), PATH)
|
|
tree.root.add_child(menus)
|
|
|
|
|
|
func after_each() -> void:
|
|
super.after_each()
|
|
if is_instance_valid(menus):
|
|
menus.free()
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(PATH))
|
|
|
|
|
|
func _press(screen: String, text: String) -> void:
|
|
var buttons: Dictionary = menus.buttons_of(screen)
|
|
assert_true(buttons.has(text), "%s has a '%s' button (has %s)" % [screen, text, buttons.keys()])
|
|
if buttons.has(text):
|
|
(buttons[text] as Button).pressed.emit()
|
|
|
|
|
|
## Settings of a player who has already been offered the tutorial (A12), so the
|
|
## program opens on the main menu.
|
|
func _offered() -> GameSettings:
|
|
var settings: GameSettings = GameSettings.new()
|
|
settings.tutorial_offered = true
|
|
return settings
|
|
|
|
|
|
func _key(keycode: Key) -> InputEventKey:
|
|
var key: InputEventKey = InputEventKey.new()
|
|
key.physical_keycode = keycode
|
|
key.keycode = keycode
|
|
key.pressed = true
|
|
return key
|
|
|
|
|
|
func test_every_screen_is_reachable_from_the_main_menu_and_back() -> void:
|
|
menus.show_screen("main", false)
|
|
assert_eq(menus.current, "main")
|
|
for pair: Array in [["Practice against bots", "practice"], ["Join a server", "join"], ["Settings", "settings"]]:
|
|
_press("main", pair[0])
|
|
assert_eq(menus.current, pair[1])
|
|
assert_true((menus.screens[pair[1]] as Control).visible)
|
|
assert_false((menus.screens["main"] as Control).visible, "one screen at a time")
|
|
menus.back()
|
|
assert_eq(menus.current, "main", "back from %s" % pair[1])
|
|
var quit: Array[bool] = [false]
|
|
menus.quit_requested.connect(func() -> void: quit[0] = true)
|
|
_press("main", "Quit")
|
|
assert_true(quit[0])
|
|
|
|
|
|
func test_every_screen_takes_keyboard_focus_and_escape_goes_back() -> void:
|
|
for screen: String in Menus.SCREENS:
|
|
menus.show_screen(screen, false)
|
|
await tree.process_frame
|
|
var focused: Control = menus.get_viewport().gui_get_focus_owner()
|
|
assert_not_null(focused, "%s focuses something" % screen)
|
|
if focused != null:
|
|
assert_true(menus.screens[screen].is_ancestor_of(focused), "%s's focus is on its own screen" % screen)
|
|
menus.show_screen("main", false)
|
|
_press("main", "Settings")
|
|
await tree.process_frame
|
|
var cancel: InputEventAction = InputEventAction.new()
|
|
cancel.action = "ui_cancel"
|
|
cancel.pressed = true
|
|
menus._unhandled_input(cancel)
|
|
assert_eq(menus.current, "main", "Escape went back")
|
|
|
|
|
|
func test_focus_moves_through_the_main_menu_with_the_arrow_keys() -> void:
|
|
menus.show_screen("main", false)
|
|
await tree.process_frame
|
|
var seen: Array[String] = []
|
|
var focused: Control = menus.get_viewport().gui_get_focus_owner()
|
|
for _step: int in 5:
|
|
assert_not_null(focused)
|
|
if focused == null:
|
|
return
|
|
seen.append((focused as Button).text)
|
|
var next: Control = focused.find_valid_focus_neighbor(SIDE_BOTTOM)
|
|
if next == null:
|
|
break
|
|
next.grab_focus()
|
|
focused = next
|
|
assert_eq(seen, ["Practice against bots", "Tutorial", "Join a server", "Settings", "Quit"] as Array[String])
|
|
|
|
|
|
func test_rebinding_in_the_menu_detects_conflicts() -> void:
|
|
menus.show_screen("settings", false)
|
|
menus.listen_for("jump")
|
|
assert_eq(menus.listening_for, "jump")
|
|
menus._unhandled_input(_key(KEY_W))
|
|
assert_eq(menus.listening_for, "", "stopped listening")
|
|
assert_eq(menus.settings.bindings.code_of("jump"), KEY_SPACE, "W is forward's: refused")
|
|
menus.listen_for("jump")
|
|
menus._unhandled_input(_key(KEY_F))
|
|
assert_eq(menus.settings.bindings.code_of("jump"), KEY_F)
|
|
assert_eq(GameSettings.load_from(PATH).bindings.code_of("jump"), KEY_F, "saved at once")
|
|
menus.listen_for("jump")
|
|
menus._unhandled_input(_key(KEY_ESCAPE))
|
|
assert_eq(menus.settings.bindings.code_of("jump"), KEY_F, "Escape left it")
|
|
assert_eq(menus.current, "settings", "and stayed on the screen")
|
|
_press("settings", "Put every key back")
|
|
assert_eq(menus.settings.bindings.code_of("jump"), KEY_SPACE)
|
|
|
|
|
|
func test_settings_controls_change_and_save_the_settings() -> void:
|
|
menus.show_screen("main", false)
|
|
_press("main", "Settings")
|
|
menus._sensitivity.value = 2.0
|
|
menus._invert.button_pressed = true
|
|
menus._quality.select(0)
|
|
menus._quality.item_selected.emit(0)
|
|
(menus._volumes["music"] as HSlider).value = 0.25
|
|
menus._max_fps.select(2)
|
|
menus._max_fps.item_selected.emit(2)
|
|
menus._print_pass.button_pressed = false
|
|
menus.back()
|
|
var saved: GameSettings = GameSettings.load_from(PATH)
|
|
assert_near(saved.mouse.mouse_sensitivity, 2.0, 0.0001)
|
|
assert_true(saved.mouse.invert_y)
|
|
assert_eq(saved.quality, 0)
|
|
assert_near(saved.music_volume, 0.25, 0.0001)
|
|
assert_eq(saved.max_fps, GameSettings.FRAME_CAPS[2])
|
|
assert_false(saved.print_pass)
|
|
# And the next time the screen opens, it shows them.
|
|
var reopened: Menus = Menus.new()
|
|
reopened.use_settings(saved, PATH)
|
|
assert_near(reopened._sensitivity.value, 2.0, 0.0001)
|
|
assert_eq(reopened._quality.selected, 0)
|
|
reopened.free()
|
|
|
|
|
|
func test_practice_and_join_say_what_was_asked() -> void:
|
|
var asked: Array = []
|
|
menus.practice_requested.connect(func(bots: int, difficulty: int, team_size: int) -> void: asked.append(["practice", bots, difficulty, team_size]))
|
|
menus.join_requested.connect(func(host: String, port: int, player_name: String) -> void: asked.append(["join", host, port, player_name]))
|
|
menus.show_screen("practice", false)
|
|
menus._bots.value = 5
|
|
menus._difficulty.select(1)
|
|
_press("practice", "Set out")
|
|
assert_eq(asked.pop_back(), ["practice", 5, 0, 1])
|
|
menus._mode.select(1)
|
|
_press("practice", "Set out")
|
|
assert_eq(asked.pop_back(), ["practice", 5, 0, Tuning.DUO_TEAM_SIZE], "duos (M7)")
|
|
assert_eq(menus.settings.practice_team_size, Tuning.DUO_TEAM_SIZE)
|
|
menus.show_screen("join", false)
|
|
menus._name.text = "Wren"
|
|
menus._address.text = "not a port:x"
|
|
_press("join", "Join this address")
|
|
assert_true(asked.is_empty(), "a bad address isn't joined")
|
|
assert_true(menus._join_note.text.contains("isn't an address"))
|
|
menus._address.text = "127.0.0.1:24999"
|
|
_press("join", "Join this address")
|
|
assert_eq(asked.pop_back(), ["join", "127.0.0.1", 24999, "Wren"])
|
|
assert_eq(GameSettings.load_from(PATH).last_server, "127.0.0.1:24999")
|
|
# A found server, chosen from the list.
|
|
menus.show_servers([
|
|
{"name": "Old", "players": 9, "max_players": 24, "address": "192.0.2.9", "port": 24650, "source": "lan", "compatible": false},
|
|
{"name": "Harbour", "players": 3, "max_players": 24, "address": "127.0.0.1", "port": 24651, "source": "lan", "compatible": true},
|
|
] as Array[Dictionary])
|
|
menus._servers.select(0)
|
|
_press("join", "Join the chosen server")
|
|
assert_true(asked.is_empty(), "another version can't be joined")
|
|
menus._servers.select(1)
|
|
_press("join", "Join the chosen server")
|
|
assert_eq(asked.pop_back(), ["join", "127.0.0.1", 24651, "Wren"])
|
|
|
|
|
|
func test_results_say_where_you_placed() -> void:
|
|
menus.show_results(1, 24, 3, ["Ada drowned"] as Array[String])
|
|
assert_eq(menus.current, "results")
|
|
assert_eq(menus._results_title.text, "Last on dry ground")
|
|
assert_true(menus._results_body.text.contains("Eliminations: 3"))
|
|
menus.show_results(7, 24, 0, [] as Array[String])
|
|
assert_eq(menus._results_title.text, "Placed 7 of 24")
|
|
|
|
|
|
func test_the_shell_goes_from_the_menu_to_a_match_and_back() -> void:
|
|
menus.free()
|
|
var shell: AppShell = AppShell.new(_offered(), PATH)
|
|
shell.grab_mouse = false
|
|
tree.root.add_child(shell)
|
|
assert_eq(shell.menus.current, "main")
|
|
shell.menus.settings.practice_bots = 3
|
|
_press_in(shell.menus, "main", "Practice against bots")
|
|
_press_in(shell.menus, "practice", "Set out")
|
|
assert_not_null(shell.session, "a match began")
|
|
assert_not_null(shell.session.local, "offline")
|
|
assert_false(shell.menus.visible, "the menus are out of the way")
|
|
for _frame: int in 30:
|
|
shell.session.pump(1.0 / 30.0)
|
|
shell.watch_match()
|
|
assert_true(shell.session.game.world != null, "the world arrived")
|
|
# Escape: the pause menu, and the player's keys stop.
|
|
shell.session.pause_requested.emit()
|
|
assert_eq(shell.menus.current, "pause")
|
|
assert_true(shell.session.paused)
|
|
_press_in(shell.menus, "pause", "Settings")
|
|
assert_eq(shell.menus.current, "settings")
|
|
shell.menus.back()
|
|
assert_eq(shell.menus.current, "pause", "settings goes back to the pause menu")
|
|
_press_in(shell.menus, "pause", "Back to the match")
|
|
assert_false(shell.session.paused)
|
|
assert_false(shell.menus.visible)
|
|
# Leaving: back to the main menu with no match.
|
|
shell.pause()
|
|
_press_in(shell.menus, "pause", "Leave the match")
|
|
assert_null(shell.session)
|
|
assert_eq(shell.menus.current, "main")
|
|
shell.free()
|
|
|
|
|
|
func test_the_shell_shows_results_when_a_match_you_played_ends() -> void:
|
|
menus.free()
|
|
var shell: AppShell = AppShell.new(_offered(), PATH)
|
|
shell.grab_mouse = false
|
|
tree.root.add_child(shell)
|
|
var rules: MatchRules = MatchRules.new()
|
|
rules.max_players = 2
|
|
rules.min_players = 1
|
|
rules.lobby_ticks = 2
|
|
rules.countdown_ticks = 2
|
|
rules.results_ticks = 600
|
|
var practice: ClientSession = ClientSession.new()
|
|
practice.play_offline(4, 1, rules)
|
|
shell.adopt(practice)
|
|
var game: ClientGame = practice.game
|
|
var server: Match = practice.local.loop.match_flow
|
|
var frames: int = 0
|
|
while not game.playing() and frames < 400:
|
|
practice.pump(1.0 / 30.0)
|
|
shell.watch_match()
|
|
frames += 1
|
|
assert_true(game.playing(), "in the match")
|
|
# The bot falls to this player, and the match ends with them on top.
|
|
var bot_handle: int = -1
|
|
for handle: int in server.participants:
|
|
if handle != LocalServer.HANDLE:
|
|
bot_handle = handle
|
|
var bot: SimEntity = server.sim.entities.find(int(server.entity_of[bot_handle]))
|
|
bot.health = 0
|
|
bot.last_attacker = int(server.entity_of[LocalServer.HANDLE])
|
|
bot.last_cause = SimEntity.CAUSE_WEAPON
|
|
while game.match_phase != Match.RESULTS and frames < 800:
|
|
practice.pump(1.0 / 30.0)
|
|
shell.watch_match()
|
|
frames += 1
|
|
assert_eq(game.match_phase, Match.RESULTS)
|
|
assert_eq(shell.menus.current, "results")
|
|
assert_eq(shell.menus._results_title.text, "Last on dry ground")
|
|
assert_true(shell.menus._results_body.text.contains("Eliminations: 1"), shell.menus._results_body.text)
|
|
_press_in(shell.menus, "results", "Back to the main menu")
|
|
assert_eq(shell.menus.current, "main")
|
|
shell.free()
|
|
|
|
|
|
func _press_in(on: Menus, screen: String, text: String) -> void:
|
|
var buttons: Dictionary = on.buttons_of(screen)
|
|
assert_true(buttons.has(text), "%s has a '%s' button (has %s)" % [screen, text, buttons.keys()])
|
|
if buttons.has(text):
|
|
(buttons[text] as Button).pressed.emit()
|
|
|
|
|
|
func test_menu_buttons_knock_when_pointed_at_and_pressed() -> void:
|
|
var sounds: MenuSounds = MenuSounds.new()
|
|
tree.root.add_child(sounds)
|
|
sounds.attach(menus)
|
|
var main: Dictionary = menus.buttons_of("main")
|
|
var first: Button = main.values()[0]
|
|
first.mouse_entered.emit()
|
|
assert_eq(sounds.heard.back(), "ui_hover")
|
|
var later: Button = Button.new()
|
|
later.text = "Back"
|
|
menus.add_child(later)
|
|
later.pressed.emit()
|
|
assert_eq(sounds.heard.back(), "ui_back", "a button made later is hooked too")
|
|
sounds.free()
|
|
later.free()
|
|
SoundBank.clear()
|
|
|
|
|
|
func test_main_menu_shows_the_version_and_commit() -> void:
|
|
var build: Label = menus.find_child("Build", true, false) as Label
|
|
assert_not_null(build, "the main menu has a build line")
|
|
if build != null:
|
|
assert_eq(build.text, "Version " + BuildInfo.describe())
|
|
|
|
|
|
static func _pad(index: JoyButton, pressed: bool = true) -> InputEventJoypadButton:
|
|
var event: InputEventJoypadButton = InputEventJoypadButton.new()
|
|
event.button_index = index
|
|
event.pressed = pressed
|
|
return event
|
|
|
|
|
|
## A press and release through Input, the way a real pad's events arrive (some
|
|
## controls, such as sliders and tab bars, follow the pad through Input's state).
|
|
func _pad_tap(index: JoyButton) -> void:
|
|
Input.parse_input_event(_pad(index, true))
|
|
Input.flush_buffered_events()
|
|
await tree.process_frame
|
|
Input.parse_input_event(_pad(index, false))
|
|
Input.flush_buffered_events()
|
|
await tree.process_frame
|
|
|
|
|
|
func test_the_menus_work_from_a_gamepad() -> void:
|
|
menus.show_screen("main", false)
|
|
await tree.process_frame
|
|
await _pad_tap(JOY_BUTTON_DPAD_DOWN)
|
|
var focused: Control = menus.get_viewport().gui_get_focus_owner()
|
|
assert_true(focused is Button and (focused as Button).text == "Tutorial", "the D-pad moved the focus down: %s" % focused)
|
|
var asked: Array[bool] = [false]
|
|
menus.tutorial_requested.connect(func() -> void: asked[0] = true)
|
|
await _pad_tap(JOY_BUTTON_A)
|
|
assert_true(asked[0], "South chose the focused button")
|
|
# Into settings and through its tabs, then back with East.
|
|
menus.show_screen("main", false)
|
|
await tree.process_frame
|
|
for _step: int in 3:
|
|
await _pad_tap(JOY_BUTTON_DPAD_DOWN)
|
|
assert_eq((menus.get_viewport().gui_get_focus_owner() as Button).text, "Settings")
|
|
await _pad_tap(JOY_BUTTON_A)
|
|
assert_eq(menus.current, "settings")
|
|
var tabs: TabContainer = menus._tabs
|
|
var first: int = tabs.current_tab
|
|
await _pad_tap(JOY_BUTTON_DPAD_RIGHT)
|
|
assert_eq(tabs.current_tab, first + 1, "the D-pad changes tab")
|
|
await _pad_tap(JOY_BUTTON_B)
|
|
assert_eq(menus.current, "main", "East went back")
|
|
|
|
|
|
func test_the_pause_menu_closes_with_start() -> void:
|
|
menus.show_screen("pause", false)
|
|
await tree.process_frame
|
|
var resumed: Array[bool] = [false]
|
|
menus.resume_requested.connect(func() -> void: resumed[0] = true)
|
|
await _pad_tap(JOY_BUTTON_START)
|
|
assert_true(resumed[0])
|
|
|
|
|
|
func test_a_slider_and_a_switch_change_from_the_pad() -> void:
|
|
menus.show_screen("settings", false)
|
|
await tree.process_frame
|
|
menus._tabs.current_tab = 2 # Gamepad
|
|
await tree.process_frame
|
|
menus._pad_speed.grab_focus()
|
|
var before: float = settings_speed()
|
|
await _pad_tap(JOY_BUTTON_DPAD_RIGHT)
|
|
assert_true(settings_speed() > before, "D-pad right turned the slider up")
|
|
menus._aim_assist.grab_focus()
|
|
await _pad_tap(JOY_BUTTON_A)
|
|
assert_false(menus.settings.mouse.aim_assist, "South switched aim assist off")
|
|
|
|
|
|
func settings_speed() -> float:
|
|
return menus.settings.mouse.pad_sensitivity
|
|
|
|
|
|
func test_rebinding_can_be_left_from_the_pad() -> void:
|
|
menus.show_screen("settings", false)
|
|
await tree.process_frame
|
|
menus.listen_for("jump")
|
|
await _pad_tap(JOY_BUTTON_B)
|
|
assert_eq(menus.listening_for, "", "East stopped listening")
|
|
assert_eq(menus.current, "settings", "and stayed on settings")
|
|
assert_eq(menus.settings.bindings.code_of("jump"), KEY_SPACE)
|
|
|
|
|
|
func test_the_access_tab_changes_the_settings() -> void:
|
|
menus.show_screen("settings", false)
|
|
await tree.process_frame
|
|
menus._vision.select(Palette.VISION_RED_GREEN)
|
|
menus._vision.item_selected.emit(Palette.VISION_RED_GREEN)
|
|
menus._ui_scale.item_selected.emit(2)
|
|
menus._captions.toggled.emit(true)
|
|
menus._reduce_motion.toggled.emit(true)
|
|
assert_eq(menus.settings.vision, Palette.VISION_RED_GREEN)
|
|
assert_eq(menus.settings.ui_scale, GameSettings.UI_SCALES[2])
|
|
assert_true(menus.settings.captions)
|
|
assert_true(menus.settings.reduce_motion)
|
|
assert_eq(GameSettings.load_from(PATH).vision, Palette.VISION_RED_GREEN, "saved at once")
|