challenge-editor/scene/card.gd
2024-09-25 11:52:36 +08:00

78 lines
1.9 KiB
GDScript

extends Control
class_name Card
@onready var state_machine: StateMachine = $state_machine
@onready var fight_card: TextureRect = $fight_card
@onready var arrow: card_arrow = $arrow
var target_queue:int=-1
var scale_multiple:float=1.1
func _ready() -> void:
state_machine.launch()
func _on_fight_card_mouse_entered() -> void:
state_machine.send_message("mouse_enter")
pass # Replace with function body.
func _on_fight_card_mouse_exited() -> void:
state_machine.send_message("mouse_exit")
pass # Replace with function body.
var data:Dictionary
##设置卡牌信息
func set_data(id:String):
var d=Global.get_card_data(id)
print(d)
if d!=null:
data=d
fight_card.set_data(d)
if data.has("target_queue"):
target_queue=data["target_queue"]
pass
##该卡牌是否需要选择目标
func need_target():
return target_queue!=-1
##获取该卡牌的目标
func get_target()->int:
return target_queue
var last_move_tween:Tween
func move_to(from_pos:Vector2,to_pos:Vector2,time:float=0.5):
if last_move_tween!=null:
last_move_tween.kill()
self.position=from_pos
var tween=create_tween()
tween.set_trans(Tween.TRANS_QUAD)
tween.tween_property(self,"position",to_pos,time)
tween.tween_callback(move_finished)
last_move_tween=tween
func move_finished():
state_machine.send_message("move_finished")
pass
func up():
z_index=1
scale_to(scale_multiple)
func down():
z_index=0
scale_to(1)
var last_scale_tween:Tween
func scale_to(sc:float):
if last_scale_tween!=null:
last_scale_tween.kill()
last_scale_tween=create_tween()
last_scale_tween.tween_property(fight_card,"scale",Vector2(sc,sc),0.1)
func get_machine()->CardMachine:
return get_parent()
func get_self_index_position():
return get_machine().get_index_position(get_index())
func request_resize():
state_machine.send_message("resize")
func open_arrow():
arrow.start()
func close_arrow():
arrow.stop()
func set_arrow_queue(q:int):
arrow.set_select_queue(q)