The bar is rounded and a little taller, with a round orange play button and a restart button that lights up orange under the mouse. The icons sit inside their buttons with room around them, and are one colour, cropped to their shape. Progress fills in orange, the volume slider gets a speaker icon, and the buttons say their shortcut keys in their tooltips. Buttons grow a little under the mouse and shrink while held down, and the play button pops when it switches between play and pause. ButtonBounce holds these animations so other buttons can use them too.
100 lines
3.4 KiB
GDScript
100 lines
3.4 KiB
GDScript
extends MainWindowTestSuite
|
||
## The Shortcuts popup lists every shortcut in the game with the right keys, grouped by
|
||
## what they do.
|
||
|
||
var _popup: ShortcutsPopup
|
||
|
||
|
||
func before_test() -> void:
|
||
super()
|
||
_popup = _window.get_node("ShortcutsPopup")
|
||
|
||
|
||
## How the list writes [param event]: "Alt + Ctrl + Left", with player numbers as 1–9.
|
||
static func _key_text(event: InputEventKey) -> String:
|
||
var parts: PackedStringArray = []
|
||
if event.alt_pressed:
|
||
parts.append("Alt")
|
||
if event.ctrl_pressed:
|
||
parts.append("Ctrl")
|
||
var keycode: Key = event.keycode if event.keycode != KEY_NONE else event.physical_keycode
|
||
var key: String = OS.get_keycode_string(keycode)
|
||
parts.append("1–9" if key.is_valid_int() else key)
|
||
return " + ".join(parts)
|
||
|
||
|
||
## Every button in [param node] and below it that has a keyboard shortcut.
|
||
func _buttons_with_shortcuts(node: Node) -> Array[BaseButton]:
|
||
var buttons: Array[BaseButton] = []
|
||
if node is BaseButton && node.shortcut != null:
|
||
buttons.append(node)
|
||
for child: Node in node.get_children():
|
||
buttons.append_array(_buttons_with_shortcuts(child))
|
||
return buttons
|
||
|
||
|
||
func _description(keys: String) -> String:
|
||
for group: Array in ShortcutsPopup.SHORTCUTS:
|
||
for shortcut: Array in group[1]:
|
||
if shortcut[0] == keys:
|
||
return shortcut[1]
|
||
return ""
|
||
|
||
|
||
func test_every_button_shortcut_is_listed() -> void:
|
||
# A player row brings the point keys
|
||
_add_player("Crono")
|
||
var buttons: Array[BaseButton] = _buttons_with_shortcuts(_window)
|
||
assert_int(buttons.size()).is_greater(5)
|
||
|
||
for button: BaseButton in buttons:
|
||
for event: InputEvent in button.shortcut.events:
|
||
var keys: String = _key_text(event)
|
||
assert_array(ShortcutsPopup.listed_keys()).override_failure_message(
|
||
"%s (%s) is not in the list" % [keys, button.name]).contains([keys])
|
||
|
||
|
||
func test_buttons_do_what_the_list_says() -> void:
|
||
var expected: Dictionary = {
|
||
"SongControls/NextButton": "Next song",
|
||
"SongControls/ShowAnswerButton": "Show answer",
|
||
"MusicPlayer/PlayerBar/MusicPlayerContainer/PlayButton": "Play or pause",
|
||
"MusicPlayer/PlayerBar/MusicPlayerContainer/RestartButton": "Restart song",
|
||
}
|
||
for path: String in expected:
|
||
var button: BaseButton = _quiz.get_node(path)
|
||
assert_str(_description(_key_text(button.shortcut.events[0]))) \
|
||
.override_failure_message(path).is_equal(expected[path])
|
||
|
||
|
||
func test_keys_are_listed_once() -> void:
|
||
var keys: Array[String] = ShortcutsPopup.listed_keys()
|
||
for keys_text: String in keys:
|
||
assert_int(keys.count(keys_text)).override_failure_message(keys_text).is_equal(1)
|
||
|
||
|
||
func test_groups_have_headings_and_rows() -> void:
|
||
_popup.open()
|
||
await _runner.simulate_frames(1)
|
||
|
||
var headings: Array[String] = []
|
||
var rows: int = 0
|
||
for child: Node in _popup.shortcuts_vbox.get_children():
|
||
if child is Label:
|
||
headings.append(child.text)
|
||
elif child is PanelContainer:
|
||
rows += 1
|
||
assert_array(headings).contains_exactly(["Players and points", "Songs", "Windows"])
|
||
assert_int(rows).is_equal(ShortcutsPopup.listed_keys().size())
|
||
|
||
|
||
func test_list_fits_without_scrolling_or_empty_space() -> void:
|
||
_popup.open()
|
||
await _runner.simulate_frames(2)
|
||
|
||
var scroll: ScrollContainer = _popup.shortcuts_vbox.get_parent()
|
||
var content: float = _popup.shortcuts_vbox.get_combined_minimum_size().y
|
||
assert_float(content).is_less_equal(scroll.size.y)
|
||
assert_float(scroll.size.y - content).override_failure_message(
|
||
"%d px empty below the list" % (scroll.size.y - content)).is_less_equal(30.0)
|