tcg/ui/card_template/monster_card.gd

55 lines
1.7 KiB
GDScript3
Raw Permalink Normal View History

2025-01-25 22:00:20 +07:00
extends Control
2025-01-26 01:58:35 +07:00
class_name MonsterCardUI
2025-01-25 22:00:20 +07:00
2025-01-26 01:58:35 +07:00
signal left_clicked
signal right_clicked
2025-01-26 11:49:25 +07:00
signal un_right_clicked
2025-01-26 01:58:35 +07:00
signal hovering(delta: float)
@export var name_label : Label
@export var health_label : Label
@export var energy_pip_container :Container
@export var icon_texture_rect : TextureRect
@export var paper_damage : Label
@export var scissors_damage : Label
@export var rock_damage : Label
func show_monster(monster: MatchMonster):
if !monster:
name_label.text = ""
health_label.text = "HP"
icon_texture_rect.texture = null
return
name_label.text = monster.card.id
2025-01-26 09:48:01 +07:00
health_label.text = "HP %d/%d" % [monster.health, monster.card.base_health]
2025-01-26 01:58:35 +07:00
icon_texture_rect.texture = monster.card.icon
paper_damage.text = str(monster.card.paper)
scissors_damage.text = str(monster.card.scissors)
rock_damage.text = str(monster.card.rock)
var shown_stars = 0
for child in energy_pip_container.get_children():
var tr = child as TextureRect
tr.visible = shown_stars < monster.card.energy_cost
shown_stars += 1
func _process(delta):
var mouse_position = get_global_mouse_position()
var rect = get_global_rect()
2025-01-26 11:49:25 +07:00
if rect.has_point(mouse_position) and get_window().has_focus():
2025-01-26 01:58:35 +07:00
hovering.emit(delta)
func _input(event):
if event is InputEventMouseButton:
var mouse_position = get_global_mouse_position()
var rect = get_global_rect()
2025-01-26 11:49:25 +07:00
if rect.has_point(mouse_position) and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() and get_window().has_focus():
2025-01-26 01:58:35 +07:00
left_clicked.emit()
2025-01-26 11:49:25 +07:00
elif rect.has_point(mouse_position) and event.button_index == MOUSE_BUTTON_RIGHT and event.is_pressed() and get_window().has_focus():
2025-01-26 01:58:35 +07:00
right_clicked.emit()
2025-01-26 11:49:25 +07:00
elif event.button_index == MOUSE_BUTTON_RIGHT and !event.is_pressed():
un_right_clicked.emit()