Buttons get 12 px of side padding. The top bar buttons, the quiz toolbar and Show answer/Next are laid out in rows with 12 px gaps and are all 36 px tall, and the ±1 buttons use a compact StepButton style. "Randomize new track" is now "Next song". Player rows show the name and the score apart, alternate like the other lists and highlight the character under the mouse. The name field is a LineEdit with a 10-letter limit; blank and duplicate names are refused, and a full list says "Up to 7 players". Remove buttons update when editing is switched instead of every frame, and the spacer panels are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
2.9 KiB
GDScript
89 lines
2.9 KiB
GDScript
class_name PlayerRow
|
|
extends PanelContainer
|
|
## One player in the player list: their name, points and character, and buttons for
|
|
## giving and taking points. Clicking the character picks another one.
|
|
|
|
signal change_character_clicked
|
|
signal player_removed
|
|
|
|
## The player shown in this row.
|
|
var player_object: PlayerObject
|
|
|
|
## Position in Settings.player_array. Only used for the keybinds: Alt+<list_index + 1>
|
|
## gives this player a point and Ctrl+Alt+<list_index + 1> takes one away.
|
|
var list_index: int
|
|
|
|
@onready var player_name_field: Label = %Name
|
|
@onready var score_label: Label = %Score
|
|
@onready var character_frame: PanelContainer = %CharacterFrame
|
|
@onready var add_button: Button = %AddPoint
|
|
@onready var minus_button: Button = %RemovePoint
|
|
@onready var character: TextureButton = %Character
|
|
@onready var remove_player: TextureButton = %RemovePlayer
|
|
|
|
|
|
func _ready() -> void:
|
|
add_button.pressed.connect(add_point)
|
|
add_button.set_shortcut(create_button_shortcut(list_index, false))
|
|
minus_button.pressed.connect(minus_point)
|
|
minus_button.set_shortcut(create_button_shortcut(list_index, true))
|
|
character.pressed.connect(change_character)
|
|
remove_player.pressed.connect(func() -> void: player_removed.emit())
|
|
character.mouse_entered.connect(_set_character_hovered.bind(true))
|
|
character.mouse_exited.connect(_set_character_hovered.bind(false))
|
|
# Rows take turns being lighter and darker, like the other lists
|
|
theme_type_variation = &"ListRowOdd" if list_index % 2 == 1 else &"ListRowEven"
|
|
player_name_field.text = player_object.player_name
|
|
player_name_field.tooltip_text = player_object.player_name
|
|
set_editing(Settings.edit_players)
|
|
update_score()
|
|
set_player_character()
|
|
|
|
|
|
## Shows the button that removes the player while the player list is being edited.
|
|
func set_editing(editing: bool) -> void:
|
|
remove_player.visible = editing
|
|
|
|
|
|
func create_button_shortcut(index: int, ctrl_pressed: bool) -> Shortcut:
|
|
var button_shortcut: Shortcut = Shortcut.new()
|
|
var button_event: InputEventKey = InputEventKey.new()
|
|
button_event.keycode = KEY_1 + index
|
|
button_event.alt_pressed = true
|
|
button_event.ctrl_pressed = ctrl_pressed
|
|
button_shortcut.events.append(button_event)
|
|
return button_shortcut
|
|
|
|
|
|
func add_point() -> void:
|
|
player_object.add_point()
|
|
update_score()
|
|
|
|
|
|
func minus_point() -> void:
|
|
player_object.minus_point()
|
|
update_score()
|
|
|
|
|
|
func change_character() -> void:
|
|
change_character_clicked.emit()
|
|
|
|
|
|
func new_character_selected(character_texture: Texture, character_name: String) -> void:
|
|
GameLog.debug("Back in player list with new")
|
|
player_object.set_character(character_texture, character_name)
|
|
set_player_character()
|
|
|
|
|
|
func set_player_character() -> void:
|
|
character.texture_normal = player_object.character
|
|
|
|
|
|
func update_score() -> void:
|
|
score_label.text = str(player_object.player_score)
|
|
|
|
|
|
func _set_character_hovered(hovered: bool) -> void:
|
|
character_frame.theme_type_variation = &"PlayerCharacterHover" if hovered \
|
|
else &"PlayerCharacter"
|