89 lines
No EOL
2.8 KiB
GDScript
89 lines
No EOL
2.8 KiB
GDScript
extends Panel
|
|
class_name CardSlot
|
|
|
|
signal card_selected(card_slot, card)
|
|
|
|
var current_card = null
|
|
var dragging = false
|
|
var drag_offset = Vector2()
|
|
|
|
@onready var card_name_label = $CardNameLabel
|
|
@onready var card_rank_label = $RankLabel
|
|
@onready var card_border = $CardBorder
|
|
@onready var card_bg = $CardBackground
|
|
|
|
# Card rank colors
|
|
var rank_colors = {
|
|
Card.Rank.RANK_0: Color(0.9, 0.1, 0.1, 1.0), # Red
|
|
Card.Rank.RANK_1: Color(0.9, 0.6, 0.1, 1.0), # Orange
|
|
Card.Rank.RANK_2: Color(0.1, 0.7, 0.1, 1.0), # Green
|
|
Card.Rank.RANK_3: Color(0.1, 0.7, 0.9, 1.0) # Blue
|
|
}
|
|
|
|
func _ready():
|
|
# Set up card appearance
|
|
update_appearance()
|
|
|
|
# Connect signals for interaction
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
gui_input.connect(_on_gui_input)
|
|
if card_border:
|
|
card_border.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
|
|
func set_card(card):
|
|
current_card = card
|
|
update_appearance()
|
|
|
|
func clear():
|
|
current_card = null
|
|
update_appearance()
|
|
|
|
func has_card():
|
|
return current_card != null
|
|
|
|
func update_appearance():
|
|
if current_card:
|
|
# Show card details
|
|
card_name_label.text = current_card.cardName
|
|
card_name_label.visible = true
|
|
|
|
# Set rank display
|
|
card_rank_label.text = str(current_card.rank)
|
|
card_rank_label.visible = true
|
|
|
|
# Set color based on rank
|
|
if current_card.rank in rank_colors:
|
|
card_rank_label.add_theme_color_override("font_color", rank_colors[current_card.rank])
|
|
card_border.modulate = rank_colors[current_card.rank]
|
|
|
|
# Show card background
|
|
card_bg.modulate = Color(0.2, 0.2, 0.25, 1.0)
|
|
else:
|
|
# Empty slot
|
|
card_name_label.visible = false
|
|
card_rank_label.visible = false
|
|
card_border.modulate = Color(0.4, 0.4, 0.4, 0.5)
|
|
card_bg.modulate = Color(0.15, 0.15, 0.15, 0.8)
|
|
|
|
func _on_gui_input(event):
|
|
if event is InputEventMouseButton:
|
|
if event.button_index == MOUSE_BUTTON_LEFT:
|
|
if event.pressed:
|
|
# Start drag
|
|
if current_card:
|
|
emit_signal("card_selected", self, current_card)
|
|
# dragging = true
|
|
# drag_offset = get_global_mouse_position() - global_position
|
|
# else:
|
|
# # End drag
|
|
# if dragging:
|
|
# dragging = false
|
|
# emit_signal("card_selected", self, current_card)
|
|
# elif current_card:
|
|
# # Just a click, still select the card
|
|
# emit_signal("card_selected", self, current_card)
|
|
|
|
func _process(delta):
|
|
if dragging:
|
|
# Update position while dragging
|
|
global_position = get_global_mouse_position() - drag_offset |