Popups fade in while growing and close the reverse way, with the backdrop fading along. The winner gets confetti, bouncing pictures and a score graph that draws itself from the left. Filtered statistics cards and search rows fade in, the tabs slide in from their side, and every button bounces on hover and click (ButtonBounce, now added to all buttons). In the player list the score pops on every point, the first point flashes the row, and a player on match point glows with a "Match point!" tag. A song starting fades in the title, flashes its row (kept across list rebuilds) and pops the play button. Common/anim.gd holds the helpers. A saved "Reduce animations" switch in Settings turns all movement off; the tests use it. The flash colours are theme colours (Palette first_point, match_point, flash) in every theme. Closes #48 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
126 lines
4.2 KiB
GDScript
126 lines
4.2 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.
|
|
##
|
|
## The score pops when it changes. The first point of a game makes the row flash, and a
|
|
## player one point from winning glows and says "Match point!" until that changes.
|
|
|
|
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 match_point_tag: Label = %MatchPointTag
|
|
@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())
|
|
player_object.player_point_given.connect(_on_score_changed)
|
|
player_object.player_point_taken.connect(_on_score_changed)
|
|
player_object.first_point_triggered.connect(_on_first_point)
|
|
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)
|
|
_show_match_point(is_match_point())
|
|
|
|
|
|
## Whether the player is one point from winning. A prepared quiz has no winning score.
|
|
func is_match_point() -> bool:
|
|
return !Settings.is_prepared_quiz() && Settings.winning_score > 1 \
|
|
&& player_object.player_score == Settings.winning_score - 1
|
|
|
|
|
|
func _on_score_changed() -> void:
|
|
Anim.pop(score_label)
|
|
|
|
|
|
func _on_first_point() -> void:
|
|
Anim.flash(self, get_theme_color(&"first_point", &"Palette"), Anim.SLOW * 2)
|
|
Anim.pop(score_label, 1.8, Anim.SLOW)
|
|
|
|
|
|
# The glow and the tag show while the player is on match point
|
|
func _show_match_point(on: bool) -> void:
|
|
var glow: Node = get_node_or_null("Pulse")
|
|
if on == match_point_tag.visible && on == (glow != null):
|
|
return
|
|
match_point_tag.visible = on
|
|
if glow != null:
|
|
glow.queue_free()
|
|
glow.name = "PulseEnding"
|
|
if on:
|
|
Anim.pulse(self, get_theme_color(&"match_point", &"Palette"))
|
|
Anim.pop(match_point_tag, 1.4, Anim.SLOW)
|
|
|
|
|
|
func _set_character_hovered(hovered: bool) -> void:
|
|
character_frame.theme_type_variation = &"PlayerCharacterHover" if hovered \
|
|
else &"PlayerCharacter"
|