56 lines
1.5 KiB
GDScript
56 lines
1.5 KiB
GDScript
extends Control
|
|
class_name MonsterCardUI
|
|
|
|
signal left_clicked
|
|
signal right_clicked
|
|
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
|
|
health_label.text = "HP %d/%d" % [monster.health, monster.card.base_health]
|
|
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()
|
|
if rect.has_point(mouse_position):
|
|
hovering.emit(delta)
|
|
|
|
func _input(event):
|
|
if event is InputEventMouseButton:
|
|
if !event.is_pressed():
|
|
return
|
|
|
|
var mouse_position = get_global_mouse_position()
|
|
var rect = get_global_rect()
|
|
if not rect.has_point(mouse_position):
|
|
return
|
|
|
|
if event.button_index == MOUSE_BUTTON_LEFT:
|
|
left_clicked.emit()
|
|
elif event.button_index == MOUSE_BUTTON_RIGHT:
|
|
right_clicked.emit()
|