2025-01-25 11:57:55 +07:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
|
|
signal play_card(card: Card)
|
|
|
|
|
signal rps_move(move: String)
|
|
|
|
|
@export var player_id: int
|
|
|
|
|
@export var deck: Container
|
|
|
|
|
@export var energy_label: Label
|
2025-01-26 01:58:35 +07:00
|
|
|
@export var skip_card_prefab: PackedScene
|
|
|
|
|
@export var support_red_card_prefab: PackedScene
|
|
|
|
|
@export var support_green_card_prefab: PackedScene
|
|
|
|
|
@export var monster_card_prefab: PackedScene
|
|
|
|
|
|
|
|
|
|
@onready var monster_card_ui := $"MonsterCard"
|
|
|
|
|
@onready var support1_green := $"Support1GreenCard"
|
|
|
|
|
@onready var support2_green := $"Support2GreenCard"
|
|
|
|
|
@onready var support2_red := $"Support2RedCard"
|
|
|
|
|
@onready var incoming_damage_label := $"IncomingDamageLabel"
|
2025-01-25 11:57:55 +07:00
|
|
|
|
|
|
|
|
var match_manager: MatchManager
|
2025-01-25 18:47:56 +07:00
|
|
|
var show_buttons: bool
|
|
|
|
|
var signal_connected: bool
|
2025-01-26 01:58:35 +07:00
|
|
|
var selected_card: Control
|
2025-01-25 11:57:55 +07:00
|
|
|
|
2025-01-25 18:47:56 +07:00
|
|
|
func attach(match_manager: MatchManager, show_buttons: bool = true):
|
|
|
|
|
self.show_buttons = show_buttons
|
2025-01-25 11:57:55 +07:00
|
|
|
self.match_manager = match_manager
|
2025-01-25 18:47:56 +07:00
|
|
|
if !signal_connected:
|
|
|
|
|
match_manager.state_transitioned.connect(_on_update)
|
|
|
|
|
signal_connected = true
|
2025-01-25 11:57:55 +07:00
|
|
|
|
2025-01-26 01:58:35 +07:00
|
|
|
func _ready():
|
|
|
|
|
monster_card_ui.visible = false
|
|
|
|
|
support1_green.visible = false
|
|
|
|
|
support2_green.visible = false
|
|
|
|
|
support2_red.visible = false
|
2025-01-26 02:32:21 +07:00
|
|
|
for child in deck.get_children():
|
|
|
|
|
child.queue_free()
|
2025-01-26 01:58:35 +07:00
|
|
|
|
2025-01-25 11:57:55 +07:00
|
|
|
func _on_update(transition):
|
2025-01-26 01:58:35 +07:00
|
|
|
selected_card = null
|
|
|
|
|
|
2025-01-25 11:57:55 +07:00
|
|
|
for child in deck.get_children():
|
|
|
|
|
child.queue_free()
|
|
|
|
|
var player: MatchPlayer = match_manager.players.get(player_id) as MatchPlayer
|
|
|
|
|
if not player:
|
|
|
|
|
return
|
|
|
|
|
energy_label.text = "Energy: " + str(player.energy)
|
2025-01-26 01:58:35 +07:00
|
|
|
|
|
|
|
|
if match_manager.support_cards_1.has(player):
|
|
|
|
|
support1_green.visible = true
|
|
|
|
|
support1_green.card = match_manager.support_cards_1[player]
|
|
|
|
|
else:
|
|
|
|
|
support1_green.visible = false
|
|
|
|
|
|
|
|
|
|
if match_manager.support_cards_2.has(player):
|
|
|
|
|
var card: SupportCard = match_manager.support_cards_2[player]
|
|
|
|
|
if card.type == "green":
|
|
|
|
|
support2_green.visible = true
|
|
|
|
|
support2_green.card = card
|
|
|
|
|
else:
|
|
|
|
|
support2_red.visible = true
|
|
|
|
|
support2_red.card = card
|
|
|
|
|
else:
|
|
|
|
|
support2_green.visible = false
|
|
|
|
|
support2_red.visible = false
|
|
|
|
|
|
|
|
|
|
|
2025-01-25 11:57:55 +07:00
|
|
|
var monster = player.monster
|
2025-01-26 01:58:35 +07:00
|
|
|
|
2025-01-25 11:57:55 +07:00
|
|
|
if monster:
|
2025-01-26 01:58:35 +07:00
|
|
|
monster_card_ui.visible = true
|
|
|
|
|
monster_card_ui.show_monster(monster)
|
2025-01-25 15:07:03 +07:00
|
|
|
incoming_damage_label.text = "Incoming Damage: " + str(monster.health_delta)
|
2025-01-26 01:58:35 +07:00
|
|
|
else:
|
|
|
|
|
monster_card_ui.visible = false
|
2025-01-25 11:57:55 +07:00
|
|
|
if match_manager.phase in [Match.Phase.SUMMON, Match.Phase.SUPPORT_1, Match.Phase.SUPPORT_2]:
|
2025-01-25 18:47:56 +07:00
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
match_manager.phase != Match.Phase.SUMMON && show_buttons
|
|
|
|
|
) or (
|
|
|
|
|
match_manager.phase == Match.Phase.SUMMON and player.monster and player.monster.health > 0 && show_buttons
|
|
|
|
|
):
|
2025-01-26 01:58:35 +07:00
|
|
|
var skip_btn:CardBase = skip_card_prefab.instantiate()
|
|
|
|
|
skip_btn.left_clicked.connect(func ():
|
|
|
|
|
_pop_this_card(skip_btn)
|
|
|
|
|
play_card.emit(null))
|
2025-01-25 18:47:56 +07:00
|
|
|
deck.add_child(skip_btn)
|
|
|
|
|
|
2025-01-25 11:57:55 +07:00
|
|
|
for card: Card in player.hand:
|
2025-01-25 18:47:56 +07:00
|
|
|
#if match_manager.phase == Match.Phase.SUMMON and card is not MonsterCard:
|
|
|
|
|
#continue
|
|
|
|
|
#if (match_manager.phase == Match.Phase.SUPPORT_1 or match_manager.phase == Match.Phase.SUPPORT_2) and card is not SupportCard:
|
|
|
|
|
#continue
|
|
|
|
|
#if match_manager.phase == Match.Phase.SUPPORT_1 and card.type == "red":
|
|
|
|
|
#continue
|
|
|
|
|
|
|
|
|
|
if !show_buttons :
|
2025-01-25 11:57:55 +07:00
|
|
|
continue
|
2025-01-25 18:47:56 +07:00
|
|
|
|
2025-01-26 01:58:35 +07:00
|
|
|
var is_disabled = (
|
2025-01-25 11:57:55 +07:00
|
|
|
card is MonsterCard and match_manager.phase != Match.Phase.SUMMON
|
|
|
|
|
) or (
|
|
|
|
|
card is SupportCard and match_manager.phase != Match.Phase.SUPPORT_1 and match_manager.phase != Match.Phase.SUPPORT_2
|
|
|
|
|
) or (
|
|
|
|
|
card is SupportCard and card.type == "red" and match_manager.phase != Match.Phase.SUPPORT_2
|
2025-01-25 18:47:56 +07:00
|
|
|
) or (
|
|
|
|
|
card is MonsterCard and match_manager.phase == Match.Phase.SUMMON and player.monster and player.monster.health > 0
|
2025-01-25 11:57:55 +07:00
|
|
|
)
|
2025-01-26 01:58:35 +07:00
|
|
|
|
|
|
|
|
var btn: CardBase = null
|
|
|
|
|
if card is MonsterCard:
|
|
|
|
|
var monster_card:MonsterCardUI = monster_card_prefab.instantiate()
|
|
|
|
|
monster_card.show_monster(MatchMonster.new(card, card.base_health, 0))
|
|
|
|
|
|
|
|
|
|
if !is_disabled:
|
|
|
|
|
monster_card.left_clicked.connect(func ():
|
|
|
|
|
_pop_this_card(monster_card)
|
|
|
|
|
play_card.emit(card))
|
|
|
|
|
deck.add_child(monster_card)
|
|
|
|
|
|
|
|
|
|
elif card is SupportCard and card.type == "red":
|
|
|
|
|
btn = support_red_card_prefab.instantiate()
|
|
|
|
|
btn.card = card
|
|
|
|
|
deck.add_child(btn)
|
|
|
|
|
else:
|
|
|
|
|
btn = support_green_card_prefab.instantiate()
|
|
|
|
|
btn.card = card
|
|
|
|
|
deck.add_child(btn)
|
|
|
|
|
|
|
|
|
|
if btn and !is_disabled:
|
|
|
|
|
btn.left_clicked.connect(func ():
|
|
|
|
|
_pop_this_card(btn)
|
|
|
|
|
play_card.emit(card))
|
|
|
|
|
|
2025-01-25 11:57:55 +07:00
|
|
|
if match_manager.phase == Match.Phase.RPS:
|
|
|
|
|
for move in ["rock", "paper", "scissors"]:
|
2025-01-25 18:47:56 +07:00
|
|
|
|
|
|
|
|
if !show_buttons:
|
|
|
|
|
continue
|
|
|
|
|
|
2025-01-25 11:57:55 +07:00
|
|
|
var btn = Button.new()
|
|
|
|
|
btn.text = move
|
|
|
|
|
btn.button_up.connect(func (): rps_move.emit(move))
|
|
|
|
|
deck.add_child(btn)
|
2025-01-26 01:58:35 +07:00
|
|
|
|
|
|
|
|
func _pop_this_card(control: Control):
|
|
|
|
|
if selected_card:
|
|
|
|
|
selected_card.size_flags_vertical = Control.SIZE_SHRINK_END
|
2025-01-25 11:57:55 +07:00
|
|
|
|
2025-01-26 01:58:35 +07:00
|
|
|
control.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
|
|
|
|
|
selected_card = control
|