diff --git a/entities/game/memory_game/scenes/MemoryGame.tscn b/entities/game/memory_game/scenes/MemoryGame.tscn index c17e9c35..0c1eba6d 100644 --- a/entities/game/memory_game/scenes/MemoryGame.tscn +++ b/entities/game/memory_game/scenes/MemoryGame.tscn @@ -235,6 +235,7 @@ memory_game = NodePath("../..") debug_functions = Array[ExtResource("34_4hsit")]([SubResource("Resource_8rpam")]) [connection signal="announce_deck" from="." to="World/CardBoard" method="set_deck"] +[connection signal="announce_deck" from="." to="UI/PlayersOverlay" method="set_deck"] [connection signal="game_paused" from="." to="Systems/PlayerInputSystem" method="game_paused"] [connection signal="game_paused" from="." to="World/Camera2D" method="game_paused"] [connection signal="load_game" from="." to="World/CardBoard/CardInteractionField" method="set_board_information"] diff --git a/entities/game/player_name_overlay/scenes/PlayerNameOverlay.tscn b/entities/game/player_name_overlay/scenes/PlayerNameOverlay.tscn index 40250582..3d14262e 100644 --- a/entities/game/player_name_overlay/scenes/PlayerNameOverlay.tscn +++ b/entities/game/player_name_overlay/scenes/PlayerNameOverlay.tscn @@ -12,6 +12,7 @@ [ext_resource type="Script" uid="uid://cpx0qtreblopk" path="res://entities/game/player_name_overlay/scripts/PlayerScoreInformation.gd" id="8_4u670"] [ext_resource type="Resource" uid="uid://85njf66kd3s1" path="res://shared/resources/colors/assets/PlayerDefaultColor.tres" id="9_2q0hc"] [ext_resource type="Shader" uid="uid://u0duqjndk87c" path="res://assets/shaders/ColorReplaceAndShine.gdshader" id="11_2q0hc"] +[ext_resource type="PackedScene" uid="uid://darv1wt1dlt1s" path="res://entities/game/player_overlay_score_board/scenes/PlayerOverlayScoreBoard.tscn" id="11_4vlvt"] [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_qprtf"] texture = ExtResource("2_blt2s") @@ -83,6 +84,7 @@ inactive_color = ExtResource("9_2q0hc") active_color = ExtResource("4_e0a06") [node name="LeftBracket" type="Label" parent="PanelContainer/HBoxContainer/ScoreAndName" unique_id=672300167] +visible = false layout_mode = 2 size_flags_horizontal = 8 text = "(" @@ -91,6 +93,7 @@ inactive_color = ExtResource("9_2q0hc") active_color = ExtResource("4_e0a06") [node name="Score" type="Label" parent="PanelContainer/HBoxContainer/ScoreAndName" unique_id=52366694] +visible = false layout_mode = 2 size_flags_horizontal = 4 theme_override_font_sizes/font_size = 25 @@ -100,6 +103,7 @@ inactive_color = ExtResource("9_2q0hc") active_color = ExtResource("4_e0a06") [node name="RightBracket" type="Label" parent="PanelContainer/HBoxContainer/ScoreAndName" unique_id=1282868630] +visible = false layout_mode = 2 size_flags_horizontal = 0 text = ")" @@ -107,6 +111,12 @@ script = ExtResource("8_4u670") inactive_color = ExtResource("9_2q0hc") active_color = ExtResource("4_e0a06") +[node name="PlayerScoreBoard" parent="PanelContainer/HBoxContainer/ScoreAndName" unique_id=574098440 instance=ExtResource("11_4vlvt")] +layout_mode = 2 +size_flags_horizontal = 0 +offset_transform_enabled = true +offset_transform_position = Vector2(25, 0) + [node name="MarginContainer" type="MarginContainer" parent="PanelContainer/HBoxContainer" unique_id=919225589] layout_mode = 2 size_flags_horizontal = 8 @@ -125,11 +135,15 @@ script = ExtResource("7_4mda4") default_color = ExtResource("9_2q0hc") highlight_color = ExtResource("4_e0a06") +[connection signal="player_did_score" from="." to="PanelContainer/HBoxContainer/ScoreAndName/PlayerScoreBoard" method="add_score"] [connection signal="player_is_active" from="." to="PanelContainer" method="is_active"] [connection signal="player_is_active" from="." to="PanelContainer/HBoxContainer/ScoreAndName" method="is_now_active"] +[connection signal="player_is_active" from="." to="PanelContainer/HBoxContainer/ScoreAndName/PlayerScoreBoard" method="player_is_active"] [connection signal="player_is_active" from="." to="PanelContainer/HBoxContainer/MarginContainer/TextureRect" method="set_highlight_color"] [connection signal="player_is_inactive" from="." to="PanelContainer" method="is_inactive"] [connection signal="player_is_inactive" from="." to="PanelContainer/HBoxContainer/ScoreAndName" method="is_now_inactive"] +[connection signal="player_is_inactive" from="." to="PanelContainer/HBoxContainer/ScoreAndName/PlayerScoreBoard" method="player_is_inactive"] [connection signal="player_is_inactive" from="." to="PanelContainer/HBoxContainer/MarginContainer/TextureRect" method="set_default_color"] [connection signal="player_name_changed" from="." to="PanelContainer/HBoxContainer/ScoreAndName/Name" method="set_text"] [connection signal="player_score_changed" from="." to="PanelContainer/HBoxContainer/ScoreAndName/Score" method="set_new_score"] +[connection signal="texture_changed" from="." to="PanelContainer/HBoxContainer/ScoreAndName/PlayerScoreBoard" method="set_texture"] diff --git a/entities/game/player_name_overlay/scripts/PlayerGameLabel.gd b/entities/game/player_name_overlay/scripts/PlayerGameLabel.gd index d2af0829..808fd714 100644 --- a/entities/game/player_name_overlay/scripts/PlayerGameLabel.gd +++ b/entities/game/player_name_overlay/scripts/PlayerGameLabel.gd @@ -6,6 +6,8 @@ signal player_is_active() signal player_is_inactive() signal player_score_changed(new_value: int) signal player_name_changed(new_player_name: String) +signal player_did_score() +signal texture_changed(texture: Texture2D) @export var player_type_icon_box: TextureRect @export var human_player_icon: Texture @@ -17,11 +19,14 @@ var contained_player: PlayerResource func _ready() -> void: var icon: Texture = human_player_icon - if contained_player.is_ai(): + if contained_player != null and contained_player.is_ai(): icon = ai_player_icon player_type_icon_box.texture = icon round_end() +func set_texture(texture: Texture2D) -> void: + texture_changed.emit(texture) + func set_player(current_player: PlayerResource) -> void: contained_player = current_player @@ -32,9 +37,12 @@ func player_turn(player_id: int) -> void: func player_scored(player_id: int, score: int) -> void: if contained_player.id == player_id: player_score_changed.emit(score) + player_did_score.emit() set_player_name() func set_player_name() -> void: + if contained_player == null: + return player_name_changed.emit(contained_player.get_display_name()) if contained_player.id == active_id: player_is_active.emit() diff --git a/entities/game/player_name_overlay/scripts/PlayerScoreInformation.gd b/entities/game/player_name_overlay/scripts/PlayerScoreInformation.gd index 22bc88d4..9d90362b 100644 --- a/entities/game/player_name_overlay/scripts/PlayerScoreInformation.gd +++ b/entities/game/player_name_overlay/scripts/PlayerScoreInformation.gd @@ -13,4 +13,4 @@ func is_now_active() -> void: func is_now_inactive() -> void: var tween_animation: Tween = create_tween() - tween_animation.tween_property(self, "theme_override_colors/font_color", inactive_color.color, animation_duration) \ No newline at end of file + tween_animation.tween_property(self, "theme_override_colors/font_color", inactive_color.color, animation_duration) diff --git a/entities/game/player_overlay_score_board/scenes/PlayerOverlayScoreBoard.tscn b/entities/game/player_overlay_score_board/scenes/PlayerOverlayScoreBoard.tscn new file mode 100644 index 00000000..652cc479 --- /dev/null +++ b/entities/game/player_overlay_score_board/scenes/PlayerOverlayScoreBoard.tscn @@ -0,0 +1,21 @@ +[gd_scene format=3 uid="uid://darv1wt1dlt1s"] + +[ext_resource type="Script" uid="uid://djok43i733l62" path="res://entities/game/player_overlay_score_board/scripts/PlayerOverlayScoreBoard.gd" id="1_2cdvp"] +[ext_resource type="Texture2D" uid="uid://b0lfebra6adhv" path="res://assets/sprites/Axuree/back_card_1.png" id="2_t84dm"] +[ext_resource type="Resource" uid="uid://c0eqsic62hvl0" path="res://shared/resources/colors/assets/PlayerHighlightColor.tres" id="3_wurbt"] +[ext_resource type="Resource" uid="uid://85njf66kd3s1" path="res://shared/resources/colors/assets/PlayerDefaultColor.tres" id="4_ptxw8"] + +[node name="PlayerScoreBoard" type="Control" unique_id=574098440] +layout_mode = 3 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_2cdvp") +fallback_texture = ExtResource("2_t84dm") +active_color = ExtResource("3_wurbt") +inactive_color = ExtResource("4_ptxw8") +metadata/_custom_type_script = "uid://djok43i733l62" diff --git a/entities/game/player_overlay_score_board/scripts/PlayerOverlayScoreBoard.gd b/entities/game/player_overlay_score_board/scripts/PlayerOverlayScoreBoard.gd new file mode 100644 index 00000000..cb1a0904 --- /dev/null +++ b/entities/game/player_overlay_score_board/scripts/PlayerOverlayScoreBoard.gd @@ -0,0 +1,122 @@ +class_name PlayerOverlayScoreBoard extends Control + +signal _card_animation_done() + +@export_group("Visuals") +@export var fallback_texture: Texture2D +@export var max_size: float = 40 +@export var rotation_limit_degree: float = 8 +@export var min_separation: float = 5 +@export var max_separation: float = 12 +@export var max_visualized_cards: int = 5 +@export var inactive_visibility: float = 0.7 + +@export_group("Label") +@export var active_color: ColorResource +@export var inactive_color: ColorResource + +@export_group("Animation") +## Animation time for the first card +@export var animation_time: float = 0.5 + +## Additional animation time for the second card +@export var animation_time_difference: float = 0.0 + +var _current_spawn_position_x: float = 0 +var _current_card_count: int = 0 +var _texture: Texture2D = null +var _card_templates: Array[TextureRect] = [] +var _is_active: bool = true + +var _label: PlayerScoreCounter = null + +func _ready() -> void: + _label = PlayerScoreCounter.new() + _label.inactive_color = inactive_color + _label.active_color = active_color + _label.custom_minimum_size = Vector2(max_size, max_size) + _label.custom_maximum_size = Vector2(max_size, max_size) + _label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + _label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + _label.z_index = 2 + add_child(_label) + +func player_is_active() -> void: + _label.is_now_active() + _is_active = true + change_visibility(_is_active) + +func player_is_inactive() -> void: + _label.is_now_inactive() + _is_active = false + change_visibility(_is_active) + +func change_visibility(visible: bool) -> void: + var target: float = inactive_visibility + if visible: + target = 1.0 + for card: TextureRect in _card_templates: + var tween: Tween = create_tween() + tween.set_ease(Tween.EASE_IN) + tween.set_trans(Tween.TRANS_SINE) + tween.tween_property(card, "modulate", Color(1.0, 1.0, 1.0, target), animation_time) + +func _get_texture() -> Texture2D: + if _texture != null: + return _texture + return fallback_texture + +func set_texture(new_texture: Texture2D) -> void: + _texture = new_texture + +func add_score() -> void: + _create_card_stack() + _configure_label() + +func _configure_label() -> void: + _label.set_new_score(_current_card_count) + var tween: Tween = create_tween() + tween.set_ease(Tween.EASE_OUT) + tween.tween_property(_label, "offset_left", _current_spawn_position_x + max_size / 2, animation_time) + +func _create_card_stack() -> void: + _current_card_count += 1 + if _current_card_count >= max_visualized_cards: + return + print("spawn card") + var cards: Array[TextureRect] = [ + _create_new_card(), + _create_new_card() + ] + var index: int = 0 + for card: TextureRect in cards: + _card_templates.append(card) + add_child(card) + card.offset_top = -150 + var tween: Tween = create_tween() + tween.set_ease(Tween.EASE_OUT) + tween.set_trans(Tween.TRANS_BACK) + + var time: float = animation_time + if index > 0: + time += animation_time_difference + tween.tween_property(card, "offset_top", 0, time) + tween.finished.connect(func() -> void: _card_animation_done.emit()) + index += 1 + + + + _current_spawn_position_x += randf_range(min_separation, max_separation) + pass + +func _create_new_card() -> TextureRect: + var card_template: TextureRect = TextureRect.new() + card_template.custom_maximum_size = Vector2(max_size, max_size) + card_template.offset_transform_enabled = true + card_template.texture = _get_texture() + card_template.offset_transform_rotation = deg_to_rad(randf_range(-rotation_limit_degree, rotation_limit_degree)) + card_template.offset_left = _current_spawn_position_x + var target_modulate: Color = Color.WHITE + if not _is_active: + target_modulate.a = inactive_visibility + return card_template diff --git a/entities/game/player_overlay_score_board/scripts/PlayerOverlayScoreBoard.gd.uid b/entities/game/player_overlay_score_board/scripts/PlayerOverlayScoreBoard.gd.uid new file mode 100644 index 00000000..210eebe5 --- /dev/null +++ b/entities/game/player_overlay_score_board/scripts/PlayerOverlayScoreBoard.gd.uid @@ -0,0 +1 @@ +uid://djok43i733l62 diff --git a/entities/game/players_overlay/scenes/PlayersOverlay.tscn b/entities/game/players_overlay/scenes/PlayersOverlay.tscn index e527b746..1fd1e2ca 100644 --- a/entities/game/players_overlay/scenes/PlayersOverlay.tscn +++ b/entities/game/players_overlay/scenes/PlayersOverlay.tscn @@ -4,6 +4,7 @@ [ext_resource type="PackedScene" uid="uid://cynb8xjpxqa6w" path="res://entities/game/player_name_overlay/scenes/PlayerNameOverlay.tscn" id="2_ehytq"] [node name="MarginContainer" type="MarginContainer" unique_id=1095593491 node_paths=PackedStringArray("player_target_control")] +custom_minimum_size = Vector2(500, 0) offset_right = 40.0 offset_bottom = 40.0 theme_override_constants/margin_left = 50 diff --git a/entities/game/players_overlay/scripts/PlayerGameOverlay.gd b/entities/game/players_overlay/scripts/PlayerGameOverlay.gd index 535edbe7..0f03f60b 100644 --- a/entities/game/players_overlay/scripts/PlayerGameOverlay.gd +++ b/entities/game/players_overlay/scripts/PlayerGameOverlay.gd @@ -1,5 +1,7 @@ class_name PlayerGameOverlay extends Control +signal set_card_texture(texture: Texture2D) + @export var player_template: PackedScene @export var player_target_control: Control @@ -19,12 +21,16 @@ func _ready() -> void: break _ui_information_system.register_ui_element(name, self) +func set_texture(deck: MemoryDeckResource) -> void: + set_card_texture.emit(deck.get_back_image()) + func add_player(player: PlayerResource) -> void: var node: PlayerGameLabel = player_template.instantiate() as PlayerGameLabel if node == null: return node.set_player(player) player_target_control.add_child(node) + set_card_texture.connect(node.set_texture) func player_changed(player_id: int) -> void: _current_player = player_id diff --git a/shared/resources/colors/assets/PlayerDefaultColor.tres b/shared/resources/colors/assets/PlayerDefaultColor.tres index bc4eabd3..36721abc 100644 --- a/shared/resources/colors/assets/PlayerDefaultColor.tres +++ b/shared/resources/colors/assets/PlayerDefaultColor.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" script_class="ColorResource" load_steps=2 format=3 uid="uid://85njf66kd3s1"] +[gd_resource type="Resource" script_class="ColorResource" format=3 uid="uid://85njf66kd3s1"] [ext_resource type="Script" uid="uid://crr4r8hbc4d1l" path="res://shared/resources/colors/ColorResource.gd" id="1_d0tol"]