2025-03-18 15:47:09 +08:00
|
|
|
extends TextureButton
|
|
|
|
|
|
|
|
class_name Card
|
|
|
|
|
|
|
|
enum Category {
|
|
|
|
Onion,
|
|
|
|
Cabbage,
|
|
|
|
Carrot,
|
|
|
|
Bucket
|
|
|
|
}
|
|
|
|
|
|
|
|
@export var mouse_follow_speed: int = 50
|
|
|
|
|
|
|
|
@export var index : Vector2 = Global.invalid_cell_index
|
|
|
|
@export var category : Category = Category.Cabbage
|
|
|
|
@export var value : int = 0
|
|
|
|
|
|
|
|
@export var onion_texture : Texture2D
|
|
|
|
@export var cabbage_texture : Texture2D
|
|
|
|
@export var carrot_texture : Texture2D
|
|
|
|
@export var bucket_texture : Texture2D
|
|
|
|
|
|
|
|
var origin_pos : Vector2
|
|
|
|
var has_mouse : bool
|
|
|
|
var settled : bool
|
|
|
|
|
|
|
|
func setup_card(category: Category, value: int) -> void:
|
|
|
|
origin_pos = global_position
|
2025-03-20 02:03:37 +08:00
|
|
|
self.category = category
|
|
|
|
self.value = value
|
|
|
|
setup_sprite(category, value)
|
2025-03-18 15:47:09 +08:00
|
|
|
|
2025-03-20 02:03:37 +08:00
|
|
|
func setup_sprite(category: Category, value: int) -> void:
|
2025-03-18 15:47:09 +08:00
|
|
|
$Value.text = str(value)
|
|
|
|
match category :
|
|
|
|
Category.Onion:
|
|
|
|
texture_normal = onion_texture
|
|
|
|
Category.Cabbage:
|
|
|
|
texture_normal = cabbage_texture
|
|
|
|
Category.Carrot:
|
|
|
|
texture_normal = carrot_texture
|
|
|
|
Category.Bucket:
|
|
|
|
texture_normal = bucket_texture
|
2025-03-20 02:03:37 +08:00
|
|
|
$Value.text = ""
|
2025-03-18 15:47:09 +08:00
|
|
|
|
|
|
|
func _on_button_down() -> void:
|
|
|
|
if !settled:
|
|
|
|
has_mouse = true
|
|
|
|
get_node("/root/GameRoot").emit_signal("dragging_card", self)
|
|
|
|
|
|
|
|
func _on_button_up() -> void:
|
2025-03-20 00:56:38 +08:00
|
|
|
has_mouse = false
|
|
|
|
if !settled:
|
|
|
|
global_position = origin_pos
|
2025-03-18 15:47:09 +08:00
|
|
|
|
|
|
|
func _process(delta):
|
2025-03-20 00:56:38 +08:00
|
|
|
if has_mouse and !settled:
|
|
|
|
var mouse_pos = get_global_mouse_position()
|
|
|
|
var target_pos = Vector2(mouse_pos.x + 2, mouse_pos.y + 2)
|
|
|
|
global_position = global_position.lerp(target_pos, mouse_follow_speed*delta)
|