refines card movement
This commit is contained in:
parent
45919dc5ae
commit
933e6b715c
@ -32,3 +32,8 @@ MAIN={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
SELECT={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
@ -14,62 +14,65 @@ var oracle_text: String
|
||||
var tapped: bool
|
||||
|
||||
# Card input state.
|
||||
var is_focused: bool # Is the card a focus?
|
||||
var is_dragging: bool # Is the card currently being dragged?
|
||||
var hovered: bool # Is the mouse currently on this card?
|
||||
var dragging: bool # Is the card currently being dragged?
|
||||
var focused: bool # Is this card currently a focus?
|
||||
|
||||
var mouse_offset: Vector2
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if is_focused:
|
||||
focused = hovered or dragging
|
||||
|
||||
if focused:
|
||||
# TODO: Export handling keypresses to its own area.
|
||||
if Input.is_action_just_pressed("MAIN"):
|
||||
tapped = not tapped
|
||||
$TweenController.tap(tapped, delta)
|
||||
|
||||
if is_dragging:
|
||||
if Input.is_action_just_pressed("SELECT"):
|
||||
dragging = true
|
||||
Input.set_default_cursor_shape(Input.CURSOR_DRAG)
|
||||
mouse_offset = get_global_mouse_position() - global_position
|
||||
|
||||
if Input.is_action_just_released("SELECT"):
|
||||
dragging = false
|
||||
check_hover()
|
||||
|
||||
if dragging:
|
||||
$TweenController.move_to(get_global_mouse_position() - mouse_offset, delta)
|
||||
|
||||
|
||||
func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||
if event is not InputEventMouseButton:
|
||||
return
|
||||
|
||||
match event.button_index:
|
||||
# MOUSE BUTTONS
|
||||
MOUSE_BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
Input.set_default_cursor_shape(Input.CURSOR_DRAG)
|
||||
mouse_offset = get_global_mouse_position() - global_position
|
||||
is_dragging = true
|
||||
else:
|
||||
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
|
||||
is_dragging = false
|
||||
MOUSE_BUTTON_RIGHT:
|
||||
# TODO: Tooltip menu for right-button clicking on cards.
|
||||
pass
|
||||
# This is called when we want to apply the behaviour of the mouse being
|
||||
# inside/outside the card when we can't trigger the enter/exit triggers.
|
||||
func check_hover() -> void:
|
||||
if hovered:
|
||||
_on_mouse_entered()
|
||||
else:
|
||||
_on_mouse_exited()
|
||||
|
||||
|
||||
func _on_mouse_entered() -> void:
|
||||
# Do not care about mouse entering if we're dragging the card.
|
||||
if is_dragging:
|
||||
hovered = true
|
||||
|
||||
# Do not apply any more effects if we're dragging the card.
|
||||
if dragging:
|
||||
return
|
||||
|
||||
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
|
||||
$TweenController.scale(1.05)
|
||||
is_focused = true
|
||||
|
||||
|
||||
func _on_mouse_exited() -> void:
|
||||
# Do not care about mouse exiting if we're dragging the card.
|
||||
if is_dragging:
|
||||
hovered = false
|
||||
|
||||
# Do not apply any more effects if we're dragging the card.
|
||||
if dragging:
|
||||
return
|
||||
|
||||
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
|
||||
$TweenController.scale(1.0)
|
||||
|
||||
is_focused = false
|
||||
|
||||
|
||||
func _card_error(error_type: String) -> String:
|
||||
return "ERROR::CARD::%s::%s::%s::\n" % [card_id, card_name, error_type]
|
||||
|
@ -18,7 +18,7 @@ shape = SubResource("RectangleShape2D_kikvd")
|
||||
|
||||
[node name="TweenController" type="Node2D" parent="."]
|
||||
script = ExtResource("2_imta7")
|
||||
move_speed = 50.0
|
||||
|
||||
[connection signal="input_event" from="Area2D" to="." method="_on_input_event"]
|
||||
[connection signal="mouse_entered" from="Area2D" to="." method="_on_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="Area2D" to="." method="_on_mouse_exited"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user