Fix and tidy the Character select, Shortcuts, Log and QR popups
Build / test (push) Successful in 41s
Build / build (push) Successful in 1m13s

Character select
- A card only picks its character when it is clicked. Before, every card
  watched every click, so clicking below the panel could pick a card
  scrolled out of view there.
- Six columns of fixed-size cards that scroll for any number of
  characters, with a gap between the cards and the scrollbar.
- Pictures are read as PNG, JPG or WebP by their first bytes, so JPGs no
  longer print an error. Names are split into words ("Paper Mario") and
  the card under the mouse is highlighted.

Shortcuts
- Alt+Z restarts the song; it was listed as "Reset".
- Grouped by what the keys do, in sentence case, and the panel fits the
  list. A test checks that every button shortcut is listed.

Log
- Scrolls to the newest row, alternates row colours and says "Nothing
  has happened yet" when empty.

QR
- A title, and the code is set up in one place.
This commit is contained in:
Sansan committed 2026-10-07 15:24:43 +02:00
1 parent b2d547b650
commit 8d21b0617d
23 files changed
+4694 -5349

No files matched your search

@@ -0,0 +1,115 @@
extends MainWindowTestSuite
## The character select popup: picking a character by clicking its card, scrolling when
## there are more characters than fit, and reading the pictures and names.
## More characters than fit without scrolling. The number changes on the server over
## time, so nothing here depends on it.
const CHARACTER_COUNT: int = 27
var _popup: CharacterSelectPopup
var _crono: PlayerObject
var _picked: Array[Texture2D] = []
func _before_window_starts() -> void:
var names: Array[String] = []
var png: PackedByteArray = _picture().save_png_to_buffer()
for i: int in CHARACTER_COUNT:
names.append("Character%d.png" % i)
_server.respond_bytes("/character?name=" + names[i].uri_encode(), png)
_server.respond_json("/character/list", names)
func before_test() -> void:
super()
_picked.clear()
_popup = _quiz.get_node("CharacterSelectPopup")
_popup.character_selected.connect(func(texture: Texture2D) -> void: _picked.append(texture))
# Opened from the player's row, like clicking the player's picture
_crono = _add_player("Crono")
_player_row(_crono).change_character()
await _runner.simulate_frames(2)
func _picture() -> Image:
var image: Image = Image.create(20, 10, false, Image.FORMAT_RGB8)
image.fill(Color.ORANGE)
return image
func _cards() -> Array[Node]:
return _popup.character_grid.get_children()
func test_one_card_per_character_in_six_columns() -> void:
assert_int(_cards().size()).is_equal(CHARACTER_COUNT)
assert_int(_popup.character_grid.columns).is_equal(6)
assert_object((_cards()[0] as CharacterCard).character_image.texture).is_not_null()
func test_more_characters_than_fit_can_be_scrolled() -> void:
var scroll: ScrollContainer = _popup.find_child("ScrollContainer")
assert_float(_popup.character_grid.size.y).is_greater(scroll.size.y)
assert_bool(scroll.get_v_scroll_bar().visible).is_true()
func test_cards_keep_away_from_the_scrollbar() -> void:
var scroll: ScrollContainer = _popup.find_child("ScrollContainer")
var scrollbar: Rect2 = scroll.get_v_scroll_bar().get_global_rect()
var last_column: Rect2 = (_cards()[5] as Control).get_global_rect()
assert_float(scrollbar.position.x - last_column.end.x).is_greater_equal(20.0)
func test_clicking_a_card_picks_that_character() -> void:
var card: CharacterCard = _cards()[2]
await _click_at(card.get_global_rect().get_center())
assert_array(_picked).contains_exactly([card.character_image.texture])
assert_object(_crono.character).is_same(card.character_image.texture)
assert_bool(_popup.visible).is_false()
func test_click_where_a_scrolled_away_card_is_picks_nothing() -> void:
# The last row is below the visible part of the list, under the bottom of the panel
var hidden_card: CharacterCard = _cards().back()
var where: Vector2 = hidden_card.get_global_rect().get_center()
assert_bool(_popup.panel.get_global_rect().has_point(where)).is_false()
await _click_at(where)
assert_array(_picked).is_empty()
assert_bool(_popup.visible).is_false()
func test_hovering_a_card_highlights_it() -> void:
var card: CharacterCard = _cards()[0]
card.mouse_entered.emit()
assert_str(String(card.theme_type_variation)).is_equal("CharacterCardHover")
card.mouse_exited.emit()
assert_str(String(card.theme_type_variation)).is_equal("CharacterCard")
func test_names_are_shown_without_extension_and_split_into_words() -> void:
assert_str(CharacterCard.display_name("PaperMario.png")).is_equal("Paper Mario")
assert_str(CharacterCard.display_name("Mizuti.jpg")).is_equal("Mizuti")
assert_str(CharacterCard.display_name("Kingdom Hearts.png")).is_equal("Kingdom Hearts")
assert_str((_cards()[3] as CharacterCard).character_name_label.text).is_equal("Character3")
func test_png_jpg_and_webp_pictures_are_read() -> void:
var picture: Image = _picture()
for bytes: PackedByteArray in [picture.save_png_to_buffer(),
picture.save_jpg_to_buffer(), picture.save_webp_to_buffer()]:
var image: Image = CharacterCard.image_from_bytes(bytes)
assert_object(image).is_not_null()
assert_vector(Vector2(image.get_size())).is_equal(Vector2(20, 10))
func test_something_that_is_not_a_picture_gives_null() -> void:
assert_object(CharacterCard.image_from_bytes("not a picture".to_utf8_buffer())).is_null()
assert_object(CharacterCard.image_from_bytes(PackedByteArray())).is_null()
@@ -0,0 +1 @@
uid://bivqa3ioaqra
@@ -0,0 +1,71 @@
extends MainWindowTestSuite
## The Log popup (rows, empty state, scrolling to the newest row) and the QR popup.
var _log: LogPopup
var _qr: QRPopup
func before_test() -> void:
super()
_log = _window.get_node("LogPopup")
_qr = _window.get_node("QRPopup")
func test_empty_log_says_so() -> void:
_log.open()
assert_bool(_log.empty_label.visible).is_true()
func test_log_rows_alternate_and_hide_the_empty_text() -> void:
_log.add_log_row("Crono got a point")
_log.add_log_row("Marle got a point")
_log.open()
var rows: Array[Node] = _log.log_box.get_children()
assert_str((rows[0] as ListRow).text).ends_with("Crono got a point")
assert_str(String((rows[0] as ListRow).theme_type_variation)).is_equal("ListRowEven")
assert_str(String((rows[1] as ListRow).theme_type_variation)).is_equal("ListRowOdd")
assert_bool(_log.empty_label.visible).is_false()
func test_log_shows_the_newest_row() -> void:
_log.open()
for i: int in 40:
_log.add_log_row("Event %d" % i)
await _runner.simulate_frames(4)
var scroll: ScrollContainer = _log.log_scroll
var newest: Rect2 = (_log.log_box.get_children().back() as Control).get_global_rect()
assert_bool(scroll.get_global_rect().encloses(newest)).is_true()
func test_log_scrolls_to_the_newest_row_when_opened() -> void:
for i: int in 40:
_log.add_log_row("Event %d" % i)
_log.open()
await _runner.simulate_frames(4)
var newest: Rect2 = (_log.log_box.get_children().back() as Control).get_global_rect()
assert_bool(_log.log_scroll.get_global_rect().encloses(newest)).is_true()
func test_qr_popup_has_a_title_and_the_search_address() -> void:
_qr.open()
assert_str((_qr.qr_panel.get_node("TitleLabel") as Label).text) \
.is_equal("Scan to search on your phone")
assert_str(_qr.url_label.text).is_equal(Settings.default_path + "/search")
assert_str(_qr.qr_code_rect.data).is_equal(_qr.url_label.text)
func test_qr_code_follows_the_server_picked_in_the_settings() -> void:
_qr.open()
_qr.close()
Settings.default_path = "http://localhost:8080"
_qr.open()
assert_str(_qr.url_label.text).is_equal("http://localhost:8080/search")
assert_str(_qr.qr_code_rect.data).is_equal("http://localhost:8080/search")
@@ -0,0 +1 @@
uid://cm030oben0fhb
+2 -2
View File
@@ -238,5 +238,5 @@ func test_log_adds_one_row_per_point_with_padded_time() -> void:
assert_int(log_box.get_child_count()).is_equal(2)
var time_pattern: RegEx = RegEx.create_from_string("^\\d\\d:\\d\\d:\\d\\d Crono got a point$")
assert_object(time_pattern.search((log_box.get_child(0) as Label).text)).is_not_null()
assert_str((log_box.get_child(1) as Label).text).ends_with("Crono lost a point")
assert_object(time_pattern.search((log_box.get_child(0) as ListRow).text)).is_not_null()
assert_str((log_box.get_child(1) as ListRow).text).ends_with("Crono lost a point")
+99
View File
@@ -0,0 +1,99 @@
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/PlayTextureButton": "Play or pause",
"MusicPlayer/PlayerBar/MusicPlayerContainer/RestartTextureButton": "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)
@@ -0,0 +1 @@
uid://u58i760ykxxp
+1
View File
@@ -16,6 +16,7 @@ const STYLES: Dictionary = {
"PopupBackground": "Panel",
"DarkSpacer": "Panel",
"CharacterCard": "Panel",
"CharacterCardHover": "Panel",
"MusicList": "PanelContainer",
"SongRow": "PanelContainer",
"ShortcutRowDark": "PanelContainer",