Card drag
This commit is contained in:
parent
621bcf75cb
commit
0418606bd8
11 changed files with 92 additions and 0 deletions
|
|
@ -2,10 +2,38 @@ extends TextureRect
|
|||
|
||||
class_name Card
|
||||
|
||||
const PIXEL_PER_ROTATION: float = 32.
|
||||
const ROTATION = PI/6.
|
||||
|
||||
@export var card_resource: CardResource
|
||||
var dragged: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
$UnitPreview.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)
|
||||
|
||||
func _gui_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
dragged = true
|
||||
top_level = true
|
||||
accept_event()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if dragged and event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
|
||||
dragged = false
|
||||
top_level = false
|
||||
accept_event()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not dragged:
|
||||
rotation = lerp(rotation,0.,0.25)
|
||||
return
|
||||
|
||||
var mouse_pos = get_global_mouse_position()-get_combined_pivot_offset()
|
||||
position = lerp(position,mouse_pos,0.25)
|
||||
var relative_x = mouse_pos.x - position.x
|
||||
rotation = lerp(rotation,clamp(relative_x/PIXEL_PER_ROTATION*ROTATION,-ROTATION,ROTATION),0.25)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue