diff --git a/demo_game.gd b/demo_game.gd index fdf9321..10c92e5 100644 --- a/demo_game.gd +++ b/demo_game.gd @@ -8,7 +8,8 @@ signal opponent_played_rts(move: String) @export var player_1_deck: Array[Card] @export var player_2_deck: Array[Card] -@onready var match_manager = $MatchManager + +@onready var match_manager: MatchManager = $MatchManager @onready var own_side = $Own @onready var opponent_side = $Opponent @onready var start_game_btn = $StartGameButton @@ -30,6 +31,9 @@ var player_2_action: Action: var id var signal_connected := false +func _ready() -> void: + _update_phase_info(Match.Phase.PREGAME) + func init(player_id: int) -> void: id = player_id @@ -44,6 +48,7 @@ func init(player_id: int) -> void: if card.id not in id_to_card: id_to_card[card.id] = card + print(match_manager.phase) match_manager.init({ MatchManager.PLAYER_1_ID: player_1_deck, MatchManager.PLAYER_2_ID: player_2_deck @@ -59,6 +64,7 @@ var transition_history: Array[PhaseTransition] = [] func _on_match_manager_state_transitioned(transition: PhaseTransition): start_game_btn.visible = match_manager.phase == Match.Phase.PREGAME transition_history.append(transition) + _update_phase_info(transition.to) print("Phase: ", Match.phase_to_str(transition.from), " -> ", Match.phase_to_str(transition.to)) func _on_start_game_button_button_up() -> void: @@ -113,3 +119,12 @@ func rpc_opponent_rps_move(move: String) -> void: if player_1_action: match_manager.resolve(player_action_queue) player_action_queue.clear() + +func _update_phase_info(phase: Match.Phase): + var phaseHeaders: Container = get_node("%PhaseInfo/PhaseHeader") + for child: Label in phaseHeaders.get_children(): + child.modulate = Color.DIM_GRAY + var target = phaseHeaders.get_node(Match.phase_to_str(phase)) + phaseHeaders.visible = target != null + if target: + target.modulate = Color.WHITE diff --git a/demo_game.tscn b/demo_game.tscn index 22935eb..80db856 100644 --- a/demo_game.tscn +++ b/demo_game.tscn @@ -6,7 +6,7 @@ [ext_resource type="PackedScene" uid="uid://cikstg43mudkn" path="res://tcg/match/match_manager.tscn" id="3_3yhrl"] [ext_resource type="Resource" uid="uid://cs7q8i7bvohmj" path="res://data/cards/monster/capytain.tres" id="3_we1tk"] [ext_resource type="Resource" uid="uid://4eod3m0vc5a8" path="res://data/cards/support/potion.tres" id="4_kkhfk"] -[ext_resource type="Resource" uid="uid://di76avwc0gn8e" path="res://data/cards/monster/axoluna.tres" id="5_3cm5x"] +[ext_resource type="Resource" uid="uid://deo8mj887rfx1" path="res://data/cards/monster/axoluna.tres" id="5_3cm5x"] [ext_resource type="Resource" uid="uid://bcrlaam8uq6xt" path="res://data/cards/support/lifesteal.tres" id="6_potm8"] [ext_resource type="PackedScene" uid="uid://bhrelvt51cbp2" path="res://ui/card_template/monster_card.tscn" id="7_4ah45"] [ext_resource type="Resource" uid="uid://dgxcvdo6x6kst" path="res://data/cards/support/all_out_attack.tres" id="7_nvv8k"] @@ -20,6 +20,7 @@ [ext_resource type="Resource" uid="uid://bmst884k0myvd" path="res://data/cards/monster/cattogato.tres" id="12_xqqfn"] [ext_resource type="Texture2D" uid="uid://6trhu2r7h6g3" path="res://assets/card_base/illust bg 1.png" id="13_bdgfp"] [ext_resource type="Texture2D" uid="uid://b0pclmv0j0r12" path="res://assets/card_base/kertas.png" id="18_gwpy8"] +[ext_resource type="Theme" uid="uid://is34t82g4jg" path="res://cards.tres" id="19_3iovu"] [ext_resource type="Texture2D" uid="uid://ch04c20lkis6j" path="res://assets/card_base/gunting.png" id="19_clnw6"] [ext_resource type="Texture2D" uid="uid://bywa8qlwvcksd" path="res://assets/card_base/batu.png" id="20_672ya"] @@ -261,18 +262,6 @@ offset_bottom = 31.0 grow_horizontal = 2 alignment = 1 -[node name="Button" type="Button" parent="Opponent/Hand"] -layout_mode = 2 -text = "CARD_1" - -[node name="Button2" type="Button" parent="Opponent/Hand"] -layout_mode = 2 -text = "CARD_2" - -[node name="Button3" type="Button" parent="Opponent/Hand"] -layout_mode = 2 -text = "CARD_3" - [node name="EnergyLabel" type="Label" parent="Opponent"] layout_mode = 2 offset_top = 35.0 @@ -313,6 +302,50 @@ text = "Start Game" [node name="MatchManager" parent="." instance=ExtResource("3_3yhrl")] +[node name="PhaseInfo" type="VBoxContainer" parent="."] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = 347.0 +offset_top = -102.0 +offset_right = 864.0 +offset_bottom = 106.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="PhaseHeader" type="VBoxContainer" parent="PhaseInfo"] +layout_mode = 2 +theme_override_constants/separation = 24 +alignment = 2 + +[node name="Summon" type="Label" parent="PhaseInfo/PhaseHeader"] +layout_mode = 2 +theme = ExtResource("19_3iovu") +theme_override_font_sizes/font_size = 24 +text = "Summon" + +[node name="Support 1" type="Label" parent="PhaseInfo/PhaseHeader"] +layout_mode = 2 +theme = ExtResource("19_3iovu") +theme_override_font_sizes/font_size = 24 +text = "Support (1)" + +[node name="RPS" type="Label" parent="PhaseInfo/PhaseHeader"] +layout_mode = 2 +theme = ExtResource("19_3iovu") +theme_override_font_sizes/font_size = 24 +text = "Rock, Paper, Scissors" + +[node name="Support 2" type="Label" parent="PhaseInfo/PhaseHeader"] +layout_mode = 2 +theme = ExtResource("19_3iovu") +theme_override_font_sizes/font_size = 24 +text = "Support (2)" + [connection signal="play_card" from="Own" to="." method="_on_own_play_card"] [connection signal="rps_move" from="Own" to="." method="_on_own_rps_move"] [connection signal="button_down" from="Own/HBoxContainer/KertasButton" to="Own" method="_on_kertas_button_button_down"] diff --git a/player_side.gd b/player_side.gd index aec31f2..1075011 100644 --- a/player_side.gd +++ b/player_side.gd @@ -23,6 +23,13 @@ var show_buttons: bool var signal_connected: bool var selected_card: Control +var hovering_cards_this_frame: Array[Control] = [] +var hovering_cards_duration: Dictionary = {} +const original_hover_position = 50 # hard coded idk what's a good way to find this value +const hover_animation_time = 0.1 +const hover_height_offset = -50 +const selected_height_offset = -100 + func attach(match_manager: MatchManager, show_buttons: bool = true): self.show_buttons = show_buttons self.match_manager = match_manager @@ -39,6 +46,7 @@ func _ready(): child.queue_free() func _on_update(transition): + hovering_cards_duration.clear() selected_card = null for child in deck.get_children(): @@ -87,6 +95,7 @@ func _on_update(transition): skip_btn.left_clicked.connect(func (): _pop_this_card(skip_btn) play_card.emit(null)) + skip_btn.hovering.connect(func (delta): _do_hover(skip_btn, delta)) deck.add_child(skip_btn) for card: Card in player.hand: @@ -118,6 +127,7 @@ func _on_update(transition): monster_card.left_clicked.connect(func (): _pop_this_card(monster_card) play_card.emit(card)) + monster_card.hovering.connect(func (delta): _do_hover(monster_card, delta)) deck.add_child(monster_card) elif card is SupportCard and card.type == "red": @@ -133,6 +143,7 @@ func _on_update(transition): btn.left_clicked.connect(func (): _pop_this_card(btn) play_card.emit(card)) + btn.hovering.connect(func (delta): _do_hover(btn, delta)) if rps_button_container: rps_button_container.visible = match_manager.phase == Match.Phase.RPS @@ -142,10 +153,48 @@ func _on_update(transition): func _pop_this_card(control: Control): if selected_card: - selected_card.size_flags_vertical = Control.SIZE_SHRINK_END + selected_card.position = Vector2(selected_card.position.x, original_hover_position) - control.size_flags_vertical = Control.SIZE_SHRINK_BEGIN selected_card = control + selected_card.position = Vector2(selected_card.position.x, original_hover_position + selected_height_offset) + +func _do_hover(control: Control, delta: float): + if control == selected_card: + if control in hovering_cards_duration: + hovering_cards_duration.erase(control) + return + + var duration: float + if control in hovering_cards_duration: + duration = hovering_cards_duration[control] + duration = clampf(duration + delta, 0, hover_animation_time) + hovering_cards_duration[control] = duration + else: + hovering_cards_duration[control] = delta + duration = delta + + var height = lerpf(0, hover_height_offset, duration / hover_animation_time) + original_hover_position + control.position = Vector2(control.position.x, height) + + hovering_cards_this_frame.append(control) + +func _process(delta): + for card in hovering_cards_duration.keys(): + if !card or card in hovering_cards_this_frame: + continue + + var duration = hovering_cards_duration[card] + duration = maxf(0, duration - delta) + + var height = lerpf(0, hover_height_offset, duration / hover_animation_time) + original_hover_position + card.position = Vector2(card.position.x, height) + + if duration == 0: + hovering_cards_duration.erase(card) + else: + hovering_cards_duration[card] = duration + + hovering_cards_this_frame.clear() func _on_kertas_button_button_down() -> void: