A13: Gamepad and accessibility
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>
This commit is contained in:
@@ -300,3 +300,99 @@ func test_main_menu_shows_the_version_and_commit() -> void:
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user