Card cast
This commit is contained in:
parent
7df936cd01
commit
52572f8c37
17 changed files with 124 additions and 30 deletions
|
|
@ -8,13 +8,17 @@ const ROTATION = PI/6.
|
|||
@export var card_resource: CardResource
|
||||
var dragged: bool = false
|
||||
|
||||
var spawned_unit: Unit
|
||||
|
||||
func _ready() -> void:
|
||||
$UnitPreview.texture = card_resource.preview
|
||||
$Preview.texture = card_resource.preview
|
||||
texture = card_resource.background
|
||||
$CostBubble/Cost.text = str(card_resource.cost)
|
||||
$ExperimentalBadge.visible = card_resource.experimental
|
||||
$Name.text = tr(card_resource.name_key)
|
||||
$Description.text = tr(card_resource.description_key)
|
||||
|
||||
GameplaySignalBus.unit_spawn_cancelled.connect(on_unit_spawn_cancelled)
|
||||
|
||||
func _gui_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
|
|
@ -31,6 +35,9 @@ func _input(event: InputEvent) -> void:
|
|||
var pos = global_position
|
||||
top_level = false
|
||||
global_position = pos
|
||||
|
||||
cast()
|
||||
|
||||
accept_event()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
|
|
@ -42,3 +49,24 @@ func _process(_delta: float) -> void:
|
|||
global_position = lerp(global_position,mouse_pos,0.25)
|
||||
var relative_x = mouse_pos.x - global_position.x
|
||||
rotation = lerp(rotation,clamp(relative_x/PIXEL_PER_ROTATION*ROTATION,-ROTATION,ROTATION),0.25)
|
||||
|
||||
func cast() -> void:
|
||||
if card_resource is UnitCard:
|
||||
spawned_unit = card_resource.spawned_unit.instantiate()
|
||||
get_tree().current_scene.add_child(spawned_unit)
|
||||
spawned_unit.global_position = get_tree().current_scene.get_global_mouse_position()
|
||||
|
||||
GameplaySignalBus.unit_spawn_confirmed.connect(confirm_use)
|
||||
GameplaySignalBus.spawn_unit.emit(spawned_unit)
|
||||
|
||||
func on_unit_spawn_cancelled() -> void:
|
||||
if GameplaySignalBus.unit_spawn_confirmed.is_connected(confirm_use):
|
||||
GameplaySignalBus.unit_spawn_confirmed.disconnect(confirm_use)
|
||||
|
||||
if spawned_unit != null:
|
||||
spawned_unit.queue_free()
|
||||
|
||||
func confirm_use() -> void:
|
||||
GameplaySignalBus.unit_spawn_confirmed.disconnect(confirm_use)
|
||||
|
||||
queue_free()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue