143 lines
4.5 KiB
GDScript
143 lines
4.5 KiB
GDScript
# Add or modify this in your CardVisual.gd script
|
|
|
|
extends Control
|
|
class_name CardVisual
|
|
|
|
signal pressed
|
|
|
|
# Card data
|
|
var current_card = null
|
|
var is_selected = false
|
|
var price = 50
|
|
|
|
# Node references
|
|
@onready var card_container = $CardContainer
|
|
@onready var name_label = $CardContainer/VBoxContainer/NameLabel
|
|
@onready var rank_label = $CardContainer/VBoxContainer/RankLabel
|
|
@onready var price_label = $CardContainer/VBoxContainer/PriceLabel
|
|
|
|
# Card rank colors
|
|
var rank_colors = {
|
|
Card.Rank.RANK_0: Color(0.8, 0.2, 0.2, 1.0), # Red
|
|
Card.Rank.RANK_1: Color(0.95, 0.6, 0.1, 1.0), # Orange
|
|
Card.Rank.RANK_2: Color(0.2, 0.8, 0.2, 1.0), # Green
|
|
Card.Rank.RANK_3: Color(0.2, 0.7, 0.95, 1.0) # Blue
|
|
}
|
|
|
|
func _ready():
|
|
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
gui_input.connect(_on_gui_input)
|
|
if card_container:
|
|
card_container.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
for child in get_children():
|
|
if child is Control:
|
|
child.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
|
|
connect("mouse_entered", Callable(self, "_on_mouse_entered"))
|
|
connect("mouse_exited", Callable(self, "_on_mouse_exited"))
|
|
# gui_input.connect(_on_gui_input)
|
|
|
|
|
|
|
|
func set_card(card):
|
|
current_card = card
|
|
if card == null:
|
|
card_container.visible = false
|
|
return
|
|
|
|
card_container.visible = true
|
|
|
|
name_label.text = card.cardName
|
|
|
|
var rank_text = ""
|
|
match card.rank:
|
|
Card.Rank.RANK_0:
|
|
rank_text = "Rank 0"
|
|
Card.Rank.RANK_1:
|
|
rank_text = "Rank 1"
|
|
Card.Rank.RANK_2:
|
|
rank_text = "Rank 2"
|
|
Card.Rank.RANK_3:
|
|
rank_text = "Rank 3"
|
|
|
|
rank_label.text = rank_text
|
|
|
|
# Set color based on rank
|
|
if card.rank in rank_colors:
|
|
var color = rank_colors[card.rank]
|
|
name_label.add_theme_color_override("font_color", color)
|
|
rank_label.add_theme_color_override("font_color", color)
|
|
|
|
var panel_style = card_container.get_theme_stylebox("panel").duplicate()
|
|
var bg_color = Color(panel_style.bg_color)
|
|
bg_color = bg_color.lerp(color, 0.05) # Very subtle tint
|
|
panel_style.bg_color = bg_color
|
|
card_container.add_theme_stylebox_override("panel", panel_style)
|
|
|
|
update_selected_state()
|
|
|
|
|
|
func hide_price():
|
|
if price_label:
|
|
price_label.visible = false
|
|
|
|
func set_price(new_price):
|
|
price = new_price
|
|
if price_label:
|
|
price_label.visible = true
|
|
price_label.text = str(price) + " gold"
|
|
|
|
func set_selected(selected):
|
|
is_selected = selected
|
|
update_selected_state()
|
|
|
|
func update_selected_state():
|
|
if !card_container:
|
|
return
|
|
|
|
if is_selected:
|
|
card_container.modulate = Color(1.2, 1.2, 1.2) # Slightly brighter
|
|
card_container.scale = Vector2(1.1, 1.1) # Slightly larger
|
|
|
|
# Yellow border
|
|
var panel_style = card_container.get_theme_stylebox("panel").duplicate()
|
|
panel_style.border_width_left = 3
|
|
panel_style.border_width_top = 3
|
|
panel_style.border_width_right = 3
|
|
panel_style.border_width_bottom = 3
|
|
panel_style.border_color = Color(1.0, 0.8, 0.0, 1.0) # Gold border
|
|
card_container.add_theme_stylebox_override("panel", panel_style)
|
|
else:
|
|
# Normal appearance when not selected
|
|
card_container.modulate = Color(1.0, 1.0, 1.0)
|
|
card_container.scale = Vector2(1.0, 1.0)
|
|
|
|
# Remove border
|
|
var panel_style = card_container.get_theme_stylebox("panel").duplicate()
|
|
panel_style.border_width_left = 0
|
|
panel_style.border_width_top = 0
|
|
panel_style.border_width_right = 0
|
|
panel_style.border_width_bottom = 0
|
|
card_container.add_theme_stylebox_override("panel", panel_style)
|
|
|
|
func _on_gui_input(event):
|
|
if event is InputEventMouseButton:
|
|
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
|
emit_signal("pressed")
|
|
|
|
var tween = create_tween()
|
|
tween.tween_property(card_container, "scale", Vector2(1.05, 1.05), 0.1)
|
|
tween.tween_property(card_container, "scale", Vector2(1.1 if is_selected else 1.0, 1.1 if is_selected else 1.0), 0.1)
|
|
|
|
func _on_mouse_entered():
|
|
|
|
if !is_selected:
|
|
var tween = create_tween()
|
|
tween.tween_property(card_container, "scale", Vector2(1.05, 1.05), 0.1)
|
|
|
|
func _on_mouse_exited():
|
|
|
|
if !is_selected:
|
|
var tween = create_tween()
|
|
tween.tween_property(card_container, "scale", Vector2(1.0, 1.0), 0.1)
|