Make the buttons consistent and rework the player list
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>
This commit is contained in:
1 parent
e4352a9f34
commit
70e970b24c
39 files changed
+2054
-2177
No files matched your search
+36
-45
@@ -4,90 +4,81 @@
|
||||
[ext_resource type="Texture2D" uid="uid://r4as0nmtoa7p" path="res://noCharacter.png" id="2_hpj3s"]
|
||||
[ext_resource type="Texture2D" uid="uid://b2kj6m8qpsgb1" path="res://icons/person_remove_light.svg" id="3_j3uxe"]
|
||||
|
||||
[node name="PlayerRow" type="Control"]
|
||||
custom_minimum_size = Vector2(2.08165e-12, 40)
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_bottom = 40.0
|
||||
[node name="PlayerRow" type="PanelContainer"]
|
||||
custom_minimum_size = Vector2(0, 40)
|
||||
size_flags_horizontal = 3
|
||||
theme_type_variation = &"ListRowEven"
|
||||
script = ExtResource("1_if4kc")
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
custom_minimum_size = Vector2(2.08165e-12, 40)
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Panel4" type="Panel" parent="HBoxContainer"]
|
||||
custom_minimum_size = Vector2(5, 40)
|
||||
layout_mode = 2
|
||||
theme_type_variation = &"DarkSpacer"
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="Name" type="Label" parent="HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(130, 40)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 1
|
||||
text = ": 0"
|
||||
mouse_filter = 1
|
||||
theme_type_variation = &"TextMedium"
|
||||
vertical_alignment = 1
|
||||
clip_text = true
|
||||
text_overrun_behavior = 3
|
||||
|
||||
[node name="Panel3" type="Panel" parent="HBoxContainer"]
|
||||
custom_minimum_size = Vector2(16, 2.08165e-12)
|
||||
layout_mode = 2
|
||||
theme_type_variation = &"DarkSpacer"
|
||||
|
||||
[node name="Character" type="TextureButton" parent="HBoxContainer"]
|
||||
[node name="Score" type="Label" parent="HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(80, 40)
|
||||
custom_minimum_size = Vector2(40, 0)
|
||||
layout_mode = 2
|
||||
theme_type_variation = &"PlayerScore"
|
||||
text = "0"
|
||||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="CharacterFrame" type="PanelContainer" parent="HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
theme_type_variation = &"PlayerCharacter"
|
||||
|
||||
[node name="Character" type="TextureButton" parent="HBoxContainer/CharacterFrame"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(64, 32)
|
||||
layout_mode = 2
|
||||
tooltip_text = "Change character"
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
texture_normal = ExtResource("2_hpj3s")
|
||||
ignore_texture_size = true
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Panel2" type="Panel" parent="HBoxContainer"]
|
||||
custom_minimum_size = Vector2(30, 40)
|
||||
layout_mode = 2
|
||||
theme_type_variation = &"DarkSpacer"
|
||||
|
||||
[node name="AddPoint" type="Button" parent="HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(40, 40)
|
||||
custom_minimum_size = Vector2(40, 36)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
theme_type_variation = &"StepButton"
|
||||
text = "+1"
|
||||
|
||||
[node name="Panel5" type="Panel" parent="HBoxContainer"]
|
||||
custom_minimum_size = Vector2(3, 40)
|
||||
layout_mode = 2
|
||||
theme_type_variation = &"DarkSpacer"
|
||||
|
||||
[node name="RemovePoint" type="Button" parent="HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(40, 40)
|
||||
custom_minimum_size = Vector2(40, 36)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
theme_type_variation = &"StepButton"
|
||||
text = "-1"
|
||||
|
||||
[node name="Panel" type="Panel" parent="HBoxContainer"]
|
||||
custom_minimum_size = Vector2(30, 40)
|
||||
layout_mode = 2
|
||||
theme_type_variation = &"DarkSpacer"
|
||||
|
||||
[node name="RemovePlayer" type="TextureButton" parent="HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(40, 40)
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(36, 36)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
tooltip_text = "Remove player"
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
texture_normal = ExtResource("3_j3uxe")
|
||||
stretch_mode = 0
|
||||
ignore_texture_size = true
|
||||
stretch_mode = 5
|
||||
+27
-18
@@ -2,7 +2,6 @@
|
||||
|
||||
[ext_resource type="Script" path="res://quiz/players_panel.gd" id="part_script"]
|
||||
[ext_resource type="Texture2D" uid="uid://bcfmpd7h512ef" path="res://icons/person_add_light.svg" id="5_31tjv"]
|
||||
[ext_resource type="Script" uid="uid://cgakje8gb37tf" path="res://quiz/player_name_field.gd" id="7_qsdfy"]
|
||||
|
||||
[sub_resource type="InputEventKey" id="InputEventKey_03bm3"]
|
||||
device = -1
|
||||
@@ -17,6 +16,7 @@ events = [SubResource("InputEventKey_03bm3")]
|
||||
layout_mode = 3
|
||||
offset_right = 641.0
|
||||
offset_bottom = 401.0
|
||||
theme_type_variation = &"PlayerList"
|
||||
script = ExtResource("part_script")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="." unique_id=270084211]
|
||||
@@ -26,55 +26,63 @@ layout_mode = 2
|
||||
custom_minimum_size = Vector2(2.08165e-12, 40)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HeaderBalance" type="Control" parent="VBoxContainer/HBoxContainer"]
|
||||
custom_minimum_size = Vector2(36, 0)
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer" unique_id=1331357386]
|
||||
custom_minimum_size = Vector2(2.08165e-12, 40)
|
||||
custom_minimum_size = Vector2(0, 40)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 1
|
||||
theme_type_variation = &"TextLarge"
|
||||
text = "Players"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="AddPlayersButton" type="TextureButton" parent="VBoxContainer/HBoxContainer" unique_id=634410148]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(2.08165e-12, 40)
|
||||
custom_minimum_size = Vector2(36, 36)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 8
|
||||
size_flags_vertical = 4
|
||||
tooltip_text = "Add or remove players (Alt+A)"
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
shortcut = SubResource("Shortcut_jafqj")
|
||||
texture_normal = ExtResource("5_31tjv")
|
||||
ignore_texture_size = true
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="AddPlayerContainer" type="HBoxContainer" parent="VBoxContainer" unique_id=1371948739]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(2.08165e-12, 40)
|
||||
custom_minimum_size = Vector2(0, 36)
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 8
|
||||
alignment = 1
|
||||
|
||||
[node name="Panel" type="Panel" parent="VBoxContainer/AddPlayerContainer" unique_id=1569854056]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_type_variation = &"DarkSpacer"
|
||||
|
||||
[node name="PlayerNameField" type="TextEdit" parent="VBoxContainer/AddPlayerContainer" unique_id=332535327]
|
||||
[node name="PlayerNameField" type="LineEdit" parent="VBoxContainer/AddPlayerContainer" unique_id=332535327]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(2.08165e-12, 40)
|
||||
custom_minimum_size = Vector2(220, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "Player name"
|
||||
script = ExtResource("7_qsdfy")
|
||||
max_length = 10
|
||||
|
||||
[node name="AddPlayerButton" type="Button" parent="VBoxContainer/AddPlayerContainer" unique_id=245001313]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(2.08165e-12, 40)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
text = "Add"
|
||||
|
||||
[node name="Panel2" type="Panel" parent="VBoxContainer/AddPlayerContainer" unique_id=60215448]
|
||||
custom_minimum_size = Vector2(2.08165e-12, 40)
|
||||
[node name="AddPlayerHint" type="Label" parent="VBoxContainer/AddPlayerContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_type_variation = &"DarkSpacer"
|
||||
theme_type_variation = &"HighlightMedium"
|
||||
text = "Up to 7 players"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer" unique_id=1000000001]
|
||||
layout_mode = 2
|
||||
@@ -84,5 +92,6 @@ horizontal_scroll_mode = 0
|
||||
[node name="PlayersListVBoxContainer" type="VBoxContainer" parent="VBoxContainer/ScrollContainer" unique_id=1000000002]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 15
|
||||
+7
-7
@@ -61,17 +61,17 @@ offset_bottom = 977.0
|
||||
|
||||
[node name="QuizToolbar" parent="." unique_id=1873301941 instance=ExtResource("scene_QuizToolbar")]
|
||||
layout_mode = 0
|
||||
offset_left = 1360.0
|
||||
offset_left = 1216.0
|
||||
offset_top = 64.0
|
||||
offset_right = 1855.0
|
||||
offset_bottom = 95.0
|
||||
offset_right = 1856.0
|
||||
offset_bottom = 100.0
|
||||
|
||||
[node name="SongControls" parent="." unique_id=1640212773 instance=ExtResource("scene_SongControls")]
|
||||
layout_mode = 0
|
||||
offset_left = 65.0
|
||||
offset_top = 944.0
|
||||
offset_right = 368.0
|
||||
offset_bottom = 975.0
|
||||
offset_left = 64.0
|
||||
offset_top = 940.0
|
||||
offset_right = 704.0
|
||||
offset_bottom = 976.0
|
||||
|
||||
[node name="CharacterSelectPopup" parent="." unique_id=1679856322 instance=ExtResource("6_dhrvg")]
|
||||
unique_name_in_owner = true
|
||||
|
||||
@@ -80,6 +80,7 @@ custom_minimum_size = Vector2(30, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
theme_type_variation = &"StepButton"
|
||||
text = "-1"
|
||||
|
||||
[node name="IncreaseHideForSecondsButton" type="Button" parent="CardPanel/VBox/HideForSecondsRow"]
|
||||
@@ -88,6 +89,7 @@ custom_minimum_size = Vector2(30, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
theme_type_variation = &"StepButton"
|
||||
text = "+1"
|
||||
|
||||
[node name="HideLengthCheckButton" type="CheckButton" parent="CardPanel/VBox"]
|
||||
@@ -127,6 +129,7 @@ custom_minimum_size = Vector2(30, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
theme_type_variation = &"StepButton"
|
||||
text = "-1"
|
||||
|
||||
[node name="IncreaseButton" type="Button" parent="CardPanel/VBox/WinningScoreRow"]
|
||||
@@ -135,6 +138,7 @@ custom_minimum_size = Vector2(30, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
theme_type_variation = &"StepButton"
|
||||
text = "+1"
|
||||
|
||||
[node name="InspirationRow" type="HBoxContainer" parent="CardPanel/VBox"]
|
||||
@@ -159,6 +163,7 @@ custom_minimum_size = Vector2(30, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
theme_type_variation = &"StepButton"
|
||||
text = "-1"
|
||||
|
||||
[node name="IncreaseInspirationSpeedButton" type="Button" parent="CardPanel/VBox/InspirationRow"]
|
||||
@@ -167,4 +172,5 @@ custom_minimum_size = Vector2(30, 0)
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
theme_type_variation = &"StepButton"
|
||||
text = "+1"
|
||||
+7
-18
@@ -10,45 +10,34 @@ keycode = 83
|
||||
[sub_resource type="Shortcut" id="Shortcut_search"]
|
||||
events = [SubResource("InputEventKey_search")]
|
||||
|
||||
[node name="QuizToolbar" type="Control" unique_id=1873301941]
|
||||
[node name="QuizToolbar" type="HBoxContainer" unique_id=1873301941]
|
||||
layout_mode = 3
|
||||
offset_right = 495.0
|
||||
offset_bottom = 31.0
|
||||
mouse_filter = 2
|
||||
theme_override_constants/separation = 12
|
||||
alignment = 2
|
||||
script = ExtResource("part_script")
|
||||
|
||||
[node name="SearchButton" type="Button" parent="." unique_id=1782453581]
|
||||
layout_mode = 0
|
||||
offset_right = 111.0
|
||||
offset_bottom = 31.0
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
shortcut = SubResource("Shortcut_search")
|
||||
text = "Search"
|
||||
|
||||
[node name="ResetPlaylistButton" type="Button" parent="." unique_id=1754155620]
|
||||
layout_mode = 0
|
||||
offset_left = 128.0
|
||||
offset_right = 239.0
|
||||
offset_bottom = 31.0
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
text = "Reset playlist"
|
||||
|
||||
[node name="ResetPointsButton" type="Button" parent="." unique_id=942880776]
|
||||
layout_mode = 0
|
||||
offset_left = 256.0
|
||||
offset_right = 367.0
|
||||
offset_bottom = 31.0
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
text = "Reset points"
|
||||
|
||||
[node name="SoundTestButton" type="Button" parent="." unique_id=1332971879]
|
||||
layout_mode = 0
|
||||
offset_left = 384.0
|
||||
offset_right = 495.0
|
||||
offset_bottom = 31.0
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
text = "Sound test"
|
||||
+6
-11
@@ -20,29 +20,24 @@ unicode = 231
|
||||
[sub_resource type="Shortcut" id="Shortcut_d6fml"]
|
||||
events = [SubResource("InputEventKey_7dnqw")]
|
||||
|
||||
[node name="SongControls" type="Control" unique_id=1640212773]
|
||||
[node name="SongControls" type="HBoxContainer" unique_id=1640212773]
|
||||
layout_mode = 3
|
||||
offset_right = 303.0
|
||||
offset_bottom = 31.0
|
||||
mouse_filter = 2
|
||||
theme_override_constants/separation = 12
|
||||
alignment = 0
|
||||
script = ExtResource("part_script")
|
||||
|
||||
[node name="ShowAnswerButton" type="Button" parent="." unique_id=415388039]
|
||||
layout_mode = 0
|
||||
offset_right = 111.0
|
||||
offset_bottom = 31.0
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
action_mode = 0
|
||||
shortcut = SubResource("Shortcut_a7fvb")
|
||||
text = "Show answer"
|
||||
|
||||
[node name="NextButton" type="Button" parent="." unique_id=1744703488]
|
||||
layout_mode = 0
|
||||
offset_left = 128.0
|
||||
offset_right = 303.0
|
||||
offset_bottom = 31.0
|
||||
layout_mode = 2
|
||||
focus_mode = 0
|
||||
disabled = true
|
||||
action_mode = 0
|
||||
shortcut = SubResource("Shortcut_d6fml")
|
||||
text = "Randomize new track"
|
||||
text = "Next song"
|
||||
@@ -1,49 +0,0 @@
|
||||
class_name PlayerNameField
|
||||
extends TextEdit
|
||||
## The field for a new player's name. It keeps to one line of at most
|
||||
## [constant MAX_NAME_LENGTH] characters, and reports Enter so the player can be added.
|
||||
|
||||
## Emitted when Enter is pressed while the field has focus.
|
||||
|
||||
signal enter_key_pressed
|
||||
|
||||
## Emitted when Alt+A is pressed.
|
||||
signal close_pressed
|
||||
|
||||
## The longest name a player can have.
|
||||
const MAX_NAME_LENGTH: int = 10
|
||||
|
||||
var current_text: String = ""
|
||||
var cursor_line: int = 0
|
||||
var cursor_column: int = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
text_changed.connect(_on_text_changed)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and event.pressed:
|
||||
if event.alt_pressed && event.keycode == KEY_A:
|
||||
close_pressed.emit()
|
||||
if has_focus():
|
||||
if event.keycode == KEY_ENTER || event.keycode == KEY_KP_ENTER:
|
||||
enter_key_pressed.emit()
|
||||
|
||||
|
||||
func _on_text_changed() -> void:
|
||||
if text.contains("\n"):
|
||||
text = text.replace("\n", "")
|
||||
|
||||
var new_text: String = text
|
||||
if new_text.length() > MAX_NAME_LENGTH:
|
||||
text = current_text
|
||||
# when replacing the text, the cursor will get moved to the beginning of the
|
||||
# text, so move it back to where it was
|
||||
set_caret_line(cursor_line)
|
||||
set_caret_column(cursor_column)
|
||||
|
||||
current_text = text
|
||||
# save current position of cursor for when we have reached the limit
|
||||
cursor_line = get_caret_line()
|
||||
cursor_column = get_caret_column()
|
||||
@@ -1 +0,0 @@
|
||||
uid://cgakje8gb37tf
|
||||
+21
-11
@@ -1,5 +1,7 @@
|
||||
class_name PlayerRow
|
||||
extends Control
|
||||
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
|
||||
@@ -12,6 +14,8 @@ var player_object: PlayerObject
|
||||
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
|
||||
@@ -25,12 +29,20 @@ func _ready() -> void:
|
||||
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()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
remove_player.visible = Settings.edit_players
|
||||
## 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:
|
||||
@@ -64,15 +76,13 @@ func new_character_selected(character_texture: Texture, character_name: String)
|
||||
|
||||
|
||||
func set_player_character() -> void:
|
||||
character.custom_minimum_size = Vector2(80, 40)
|
||||
character.ignore_texture_size = true
|
||||
character.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
||||
character.texture_normal = player_object.character
|
||||
|
||||
|
||||
func update_score() -> void:
|
||||
if OS.has_feature("debug"):
|
||||
player_name_field.text = "%d %s: %d" % [list_index + 1, player_object.player_name,
|
||||
player_object.player_score]
|
||||
else:
|
||||
player_name_field.text = player_object.player_name + ": " + str(player_object.player_score)
|
||||
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"
|
||||
+40
-13
@@ -21,35 +21,52 @@ var _player_row: PackedScene = preload("res://quiz/PlayerRow.tscn")
|
||||
@onready var add_players_button: TextureButton = %AddPlayersButton
|
||||
@onready var add_player_container: HBoxContainer = %AddPlayerContainer
|
||||
@onready var add_player_button: Button = %AddPlayerButton
|
||||
@onready var new_player_name_field: PlayerNameField = %PlayerNameField
|
||||
@onready var add_player_hint: Label = %AddPlayerHint
|
||||
@onready var new_player_name_field: LineEdit = %PlayerNameField
|
||||
@onready var players_list_container: VBoxContainer = %PlayersListVBoxContainer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
add_players_button.pressed.connect(add_players)
|
||||
add_player_button.pressed.connect(add_player)
|
||||
new_player_name_field.enter_key_pressed.connect(add_player)
|
||||
new_player_name_field.text_submitted.connect(func(_text: String) -> void: add_player())
|
||||
|
||||
|
||||
## Shows or hides the row for adding players, and the buttons for removing them.
|
||||
func add_players() -> void:
|
||||
GameLog.debug("add_players")
|
||||
Settings.edit_players = !Settings.edit_players
|
||||
add_player_container.visible = !add_player_container.visible
|
||||
new_player_name_field.grab_focus()
|
||||
add_player_container.visible = Settings.edit_players
|
||||
for row: PlayerRow in players_list_container.get_children():
|
||||
row.set_editing(Settings.edit_players)
|
||||
_update_add_row()
|
||||
if Settings.edit_players:
|
||||
new_player_name_field.grab_focus()
|
||||
|
||||
|
||||
## Adds a player with the name in the name field, unless it is empty or there are
|
||||
## already as many players as there can be.
|
||||
## Adds a player with the name in the name field. Blank names, names another player
|
||||
## already has, and players beyond [constant Settings.MAX_NUMBER_OF_PLAYERS] are not
|
||||
## added.
|
||||
func add_player() -> void:
|
||||
GameLog.debug("add_player")
|
||||
if new_player_name_field.text != "" \
|
||||
&& Settings.player_array.size() < Settings.MAX_NUMBER_OF_PLAYERS:
|
||||
var new_player_object: PlayerObject = PlayerObject.new(new_player_name_field.text)
|
||||
new_player_name_field.text = ""
|
||||
Settings.player_array.append(new_player_object)
|
||||
player_added.emit(new_player_object)
|
||||
reload()
|
||||
var player_name: String = new_player_name_field.text.strip_edges()
|
||||
if !can_add(player_name):
|
||||
return
|
||||
var new_player_object: PlayerObject = PlayerObject.new(player_name)
|
||||
new_player_name_field.text = ""
|
||||
Settings.player_array.append(new_player_object)
|
||||
player_added.emit(new_player_object)
|
||||
reload()
|
||||
|
||||
|
||||
## Whether a player called [param player_name] can be added.
|
||||
func can_add(player_name: String) -> bool:
|
||||
if player_name.is_empty() || Settings.player_array.size() >= Settings.MAX_NUMBER_OF_PLAYERS:
|
||||
return false
|
||||
for player: PlayerObject in Settings.player_array:
|
||||
if player.player_name.to_lower() == player_name.to_lower():
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
## Shows the players in [code]Settings.player_array[/code] again, e.g. after their
|
||||
@@ -71,6 +88,16 @@ func reload() -> void:
|
||||
|
||||
players_list_container.add_child(new_player)
|
||||
counter += 1
|
||||
_update_add_row()
|
||||
|
||||
|
||||
# A full list can't take more players, so the name field gives way to a note saying so
|
||||
func _update_add_row() -> void:
|
||||
var full: bool = Settings.player_array.size() >= Settings.MAX_NUMBER_OF_PLAYERS
|
||||
add_player_hint.text = "Up to %d players" % Settings.MAX_NUMBER_OF_PLAYERS
|
||||
add_player_hint.visible = full
|
||||
new_player_name_field.visible = !full
|
||||
add_player_button.visible = !full
|
||||
|
||||
|
||||
func _on_change_character_clicked(row: PlayerRow, player_name: String) -> void:
|
||||
|
||||
@@ -8,7 +8,7 @@ signal next_pressed
|
||||
## "Show winner".
|
||||
signal show_winner_pressed
|
||||
|
||||
const NEXT_TEXT: String = "Randomize new track"
|
||||
const NEXT_TEXT: String = "Next song"
|
||||
const SHOW_WINNER_TEXT: String = "Show winner"
|
||||
|
||||
## True while Next reads "Show winner", after the last song of a prepared quiz.
|
||||
|
||||
Reference in new issue
Block a user