challenge-editor/scene/card.gd

111 lines
2.7 KiB
GDScript3
Raw Normal View History

2024-09-24 11:59:54 +08:00
extends Control
2024-09-24 17:26:44 +08:00
class_name Card
2024-09-24 11:59:54 +08:00
@onready var state_machine: StateMachine = $state_machine
@onready var fight_card: TextureRect = $fight_card
2024-09-25 11:52:36 +08:00
@onready var arrow: card_arrow = $arrow
var target_queue:int=-1
2024-09-24 17:26:44 +08:00
var scale_multiple:float=1.1
2024-09-25 18:04:02 +08:00
signal queue
2024-09-24 17:26:44 +08:00
func _ready() -> void:
state_machine.launch()
2024-09-24 11:59:54 +08:00
2024-09-25 11:52:36 +08:00
2024-09-24 11:59:54 +08:00
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.
2024-09-24 17:26:44 +08:00
var data:Dictionary
2024-09-25 11:52:36 +08:00
##设置卡牌信息
2024-09-24 17:26:44 +08:00
func set_data(id:String):
2024-09-25 11:52:36 +08:00
var d=Global.get_card_data(id)
if d!=null:
data=d
fight_card.set_data(d)
if data.has("target_queue"):
target_queue=data["target_queue"]
2024-09-25 18:04:02 +08:00
arrow.set_select_queue(target_queue)
2024-09-24 11:59:54 +08:00
pass
2024-09-25 11:52:36 +08:00
##该卡牌是否需要选择目标
func need_target():
return target_queue!=-1
##获取该卡牌的目标
func get_target()->int:
return target_queue
2024-09-24 17:26:44 +08:00
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
2024-09-25 18:04:02 +08:00
signal move_finished_sig
2024-09-24 17:26:44 +08:00
func move_finished():
state_machine.send_message("move_finished")
2024-09-25 18:04:02 +08:00
move_finished_sig.emit()
2024-09-24 17:26:44 +08:00
pass
2024-09-25 23:56:53 +08:00
2024-09-24 17:26:44 +08:00
func up():
2024-09-25 23:56:53 +08:00
z_index=basic_index+10
2024-09-24 17:26:44 +08:00
scale_to(scale_multiple)
2024-09-25 23:56:53 +08:00
var basic_index:int=0:
set(val):
basic_index=val
down()
pass
2024-09-24 17:26:44 +08:00
func down():
2024-09-25 23:56:53 +08:00
z_index=basic_index
2024-09-24 17:26:44 +08:00
scale_to(1)
2024-09-25 18:04:02 +08:00
func show_big():
2024-09-25 23:56:53 +08:00
z_index=basic_index+10
2024-09-25 18:04:02 +08:00
scale_to(1.5)
2024-09-24 11:59:54 +08:00
var last_scale_tween:Tween
func scale_to(sc:float):
if last_scale_tween!=null:
last_scale_tween.kill()
2024-09-24 17:26:44 +08:00
last_scale_tween=create_tween()
2024-09-24 11:59:54 +08:00
last_scale_tween.tween_property(fight_card,"scale",Vector2(sc,sc),0.1)
2024-09-24 17:26:44 +08:00
func get_machine()->CardMachine:
return get_parent()
func get_self_index_position():
2024-09-25 18:04:02 +08:00
return get_machine().get_index_position(get_machine().get_card_index(self))
func get_queue_position():
return get_machine().get_queue_pos()
func get_exe_position():
return get_machine().get_exe_position()
2024-09-24 17:26:44 +08:00
func request_resize():
state_machine.send_message("resize")
2024-09-25 11:52:36 +08:00
func open_arrow():
arrow.start()
func close_arrow():
arrow.stop()
func set_arrow_queue(q:int):
arrow.set_select_queue(q)
2024-09-25 18:04:02 +08:00
func get_select_result():
return arrow.get_target()
func clear():
state_machine.change_state("discard",0)
#执行目标
var target
func exe():
print("exe")
move_to(self.position,get_exe_position())
await move_finished_sig
show_big()
await get_tree().create_timer(0.2).timeout
2024-09-26 17:54:02 +08:00
Global.use_card(data,Global.now_fight_scene.user,target)
2024-09-25 18:04:02 +08:00
await get_tree().create_timer(0.2).timeout
down()
print("执行完毕")
state_machine.change_state("discard",0)
return 0