class_name ShortcutsPopup extends BasePopup ## Lists the keyboard shortcuts, grouped by what they do. Opened with Alt+K or the ## Shortcuts button. ## Each group's heading and its shortcuts, as [code][keys, what they do][/code]. ## [code]tests/integration/test_shortcuts_popup.gd[/code] checks that every button ## shortcut in the game is here with the right keys. const SHORTCUTS: Array = [ ["Players and points", [ ["Alt + 1–9", "Give a player a point"], ["Alt + Ctrl + 1–9", "Take a point from a player"], ["Alt + A", "Add players"], ]], ["Songs", [ ["Alt + C", "Next song"], ["Alt + V", "Show answer"], ["Alt + X", "Play or pause"], ["Alt + Z", "Restart song"], ["Alt + Ctrl + Left", "Restart song"], ["Alt + Left", "Jump back 5 seconds"], ["Alt + Right", "Jump forward 5 seconds"], ["Alt + Up", "Volume up"], ["Alt + Down", "Volume down"], ]], ["Windows", [ ["Alt + S", "Search"], ["Alt + K", "Shortcuts"], ["Alt + L", "Log"], ["Alt + Enter", "Fullscreen"], ]], ] ## Space above each group but the first. const GROUP_GAP: Vector2 = Vector2(0, 8) @onready var shortcuts_vbox: VBoxContainer = %shortcutsVBox @onready var shortcuts_panel: Panel = %ShortcutsPanel func _ready() -> void: Settings.delete_children(shortcuts_vbox) for group: Array in SHORTCUTS: if shortcuts_vbox.get_child_count() > 0: var gap: Control = Control.new() gap.custom_minimum_size = GROUP_GAP shortcuts_vbox.add_child(gap) var heading: Label = Label.new() heading.theme_type_variation = &"HighlightLarge" heading.text = group[0] shortcuts_vbox.add_child(heading) var row: int = 0 for shortcut: Array in group[1]: shortcuts_vbox.add_child(_make_row(shortcut[0], shortcut[1], row)) row += 1 ## Every key combination in the list, e.g. "Alt + C". static func listed_keys() -> Array[String]: var keys: Array[String] = [] for group: Array in SHORTCUTS: for shortcut: Array in group[1]: keys.append(shortcut[0]) return keys func _make_row(keys: String, action: String, row: int) -> PanelContainer: var panel: PanelContainer = PanelContainer.new() if row % 2 == 0: panel.theme_type_variation = &"ShortcutRowDark" var hbox: HBoxContainer = HBoxContainer.new() for text: String in [keys, action]: var label: Label = Label.new() label.theme_type_variation = &"TextLarge" label.text = text label.size_flags_horizontal = Control.SIZE_EXPAND_FILL hbox.add_child(label) panel.add_child(hbox) return panel