removing many mouse movement bugs
This commit is contained in:
parent
f5fac26176
commit
09e306c974
|
|
@ -12,6 +12,8 @@ var focus_stickies:bool = true:
|
||||||
set(stickies):
|
set(stickies):
|
||||||
if stickies and sticky_note_container.get_child_count() == 0: return
|
if stickies and sticky_note_container.get_child_count() == 0: return
|
||||||
|
|
||||||
|
# this messes things up if called unneeded.
|
||||||
|
if focus_stickies != stickies:
|
||||||
focus_stickies = stickies
|
focus_stickies = stickies
|
||||||
|
|
||||||
if not current_context == ASSIGN:
|
if not current_context == ASSIGN:
|
||||||
|
|
@ -32,6 +34,9 @@ var has_stage = false:
|
||||||
process_mode = Node.PROCESS_MODE_INHERIT
|
process_mode = Node.PROCESS_MODE_INHERIT
|
||||||
else:
|
else:
|
||||||
process_mode = Node.PROCESS_MODE_DISABLED
|
process_mode = Node.PROCESS_MODE_DISABLED
|
||||||
|
for sticky in dropzone.get_children():
|
||||||
|
if sticky is StickyNote:
|
||||||
|
sticky.is_dragged = false
|
||||||
visible = has_stage
|
visible = has_stage
|
||||||
|
|
||||||
@onready var dropzone = $HBoxContainer/dropzone
|
@onready var dropzone = $HBoxContainer/dropzone
|
||||||
|
|
@ -69,6 +74,8 @@ var mementos_collected: int = 0:
|
||||||
|
|
||||||
@onready var currently_active_node: Area2D = null:
|
@onready var currently_active_node: Area2D = null:
|
||||||
set(new_node):
|
set(new_node):
|
||||||
|
# this makes sure no accidental context switches can happen while a card is being dragged.
|
||||||
|
if not current_context == DRAG:
|
||||||
if not currently_active_node == null:
|
if not currently_active_node == null:
|
||||||
currently_active_node.highlighted = false
|
currently_active_node.highlighted = false
|
||||||
currently_active_node = new_node
|
currently_active_node = new_node
|
||||||
|
|
@ -157,16 +164,16 @@ func add_sticky_note(sticky: StickyNote):
|
||||||
func is_in_dropzone(to_check: Node) -> bool:
|
func is_in_dropzone(to_check: Node) -> bool:
|
||||||
return dropzone.get_rect().has_point(to_check.global_position)
|
return dropzone.get_rect().has_point(to_check.global_position)
|
||||||
|
|
||||||
# called if a mouse button is pressed
|
# Called by notes when a mouse event needs handling
|
||||||
func handle_mouse_button(to_handle: Area2D, input: InputEvent):
|
func handle_mouse_button(input: InputEventMouseButton, to_handle = currently_active_node):
|
||||||
# No two areas can be dragged at the same time.
|
|
||||||
# Make sure that only the same area is dragged.
|
# Makes sure that only the same area is dragged.
|
||||||
# Otherwise overlapping areas are dragged at the same time.
|
# Otherwise overlapping areas are dragged at the same time.
|
||||||
if current_context == DRAG and to_handle != currently_active_node:
|
if current_context == DRAG and to_handle != currently_active_node:
|
||||||
return
|
return
|
||||||
|
|
||||||
currently_active_node = to_handle # update currently selected
|
if input.button_index == MOUSE_BUTTON_MASK_LEFT and input.pressed:
|
||||||
if input.is_action_pressed("mouse_left"):
|
currently_active_node = to_handle
|
||||||
to_handle.is_dragged = true
|
to_handle.is_dragged = true
|
||||||
if to_handle is StickyNote:
|
if to_handle is StickyNote:
|
||||||
if not to_handle.on_board:
|
if not to_handle.on_board:
|
||||||
|
|
@ -176,7 +183,7 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
|
||||||
current_context = DRAG
|
current_context = DRAG
|
||||||
|
|
||||||
# when Drag stops ...
|
# when Drag stops ...
|
||||||
if input.is_action_released("mouse_left"):
|
if input.button_index == MOUSE_BUTTON_MASK_LEFT and not input.pressed:
|
||||||
to_handle.is_dragged = false
|
to_handle.is_dragged = false
|
||||||
if to_handle is StickyNote:
|
if to_handle is StickyNote:
|
||||||
if is_in_dropzone(to_handle):
|
if is_in_dropzone(to_handle):
|
||||||
|
|
@ -216,6 +223,7 @@ func handle_mouse_button(to_handle: Area2D, input: InputEvent):
|
||||||
if input.is_action_pressed("mouse_right") and current_context == DRAG:
|
if input.is_action_pressed("mouse_right") and current_context == DRAG:
|
||||||
to_handle.reset_drag()
|
to_handle.reset_drag()
|
||||||
|
|
||||||
|
|
||||||
func _return_sticky_notes_to_panels():
|
func _return_sticky_notes_to_panels():
|
||||||
for panel in sticky_note_container.get_children():
|
for panel in sticky_note_container.get_children():
|
||||||
panel.reclaim_sticky_note()
|
panel.reclaim_sticky_note()
|
||||||
|
|
@ -272,7 +280,15 @@ func _input(event):
|
||||||
State.leave_stage(self)
|
State.leave_stage(self)
|
||||||
|
|
||||||
# Return, if the input is a mouse event (mouse events are handled separately)
|
# Return, if the input is a mouse event (mouse events are handled separately)
|
||||||
if event is InputEventMouse or !has_stage or not is_instance_valid(currently_active_node): return
|
if not has_stage or not is_instance_valid(currently_active_node): return
|
||||||
|
|
||||||
|
if event is InputEventMouse:
|
||||||
|
# makes sure to pass release events so notes do not get attached to the mouse while the cursor leaves the area.
|
||||||
|
if event is InputEventMouseButton and current_context == DRAG:
|
||||||
|
if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
|
||||||
|
handle_mouse_button(event)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
if current_context != DRAG:
|
if current_context != DRAG:
|
||||||
if event.is_action_pressed("ui_up"):
|
if event.is_action_pressed("ui_up"):
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,10 @@ var mouse_offset: Vector2
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
||||||
|
input_event.connect(_on_input_event)
|
||||||
|
mouse_entered.connect(_on_mouse_entered)
|
||||||
|
mouse_exited.connect(_on_mouse_exited)
|
||||||
|
|
||||||
_handle_wiggle(0)
|
_handle_wiggle(0)
|
||||||
if not Engine.is_editor_hint() and is_inside_tree():
|
if not Engine.is_editor_hint() and is_inside_tree():
|
||||||
for sticky_note in self.get_children():
|
for sticky_note in self.get_children():
|
||||||
|
|
@ -131,6 +135,11 @@ func replace_with(card: Card):
|
||||||
self.voice_line = card.voice_line
|
self.voice_line = card.voice_line
|
||||||
self.name = card.name
|
self.name = card.name
|
||||||
|
|
||||||
|
func _input(event: InputEvent) -> void:
|
||||||
|
if event is InputEventMouseButton:
|
||||||
|
if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
|
||||||
|
is_dragged = false
|
||||||
|
|
||||||
func _on_focus_entered():
|
func _on_focus_entered():
|
||||||
print(self, "is focused")
|
print(self, "is focused")
|
||||||
|
|
||||||
|
|
@ -142,7 +151,7 @@ func _on_mouse_entered():
|
||||||
if not Input.is_action_pressed("mouse_left"):
|
if not Input.is_action_pressed("mouse_left"):
|
||||||
# Do nothing if mouse hovers over sticky_note
|
# Do nothing if mouse hovers over sticky_note
|
||||||
if has_sticky_note_attached():
|
if has_sticky_note_attached():
|
||||||
if get_child(-1).highlighted:
|
if current_sticky_note.highlighted:
|
||||||
return
|
return
|
||||||
highlighted = true
|
highlighted = true
|
||||||
if "handle_hover" in owner:
|
if "handle_hover" in owner:
|
||||||
|
|
@ -162,7 +171,7 @@ func _on_input_event(viewport, event, shape_idx):
|
||||||
if "handle_mouse_button" in owner:
|
if "handle_mouse_button" in owner:
|
||||||
mouse_offset = (get_viewport().get_mouse_position() - position)
|
mouse_offset = (get_viewport().get_mouse_position() - position)
|
||||||
if highlighted:
|
if highlighted:
|
||||||
owner.handle_mouse_button(self, event)
|
owner.handle_mouse_button(event, self)
|
||||||
|
|
||||||
func _move_card():
|
func _move_card():
|
||||||
if is_dragged:
|
if is_dragged:
|
||||||
|
|
@ -205,7 +214,7 @@ func exchange_sticky_note_with(new_note: StickyNote) -> StickyNote:
|
||||||
attach_sticky_note(new_note)
|
attach_sticky_note(new_note)
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
## TODO why does this exist?
|
# This makes sure this node highlights itself when focus has left the sticky note.
|
||||||
func check_hover():
|
func check_hover():
|
||||||
if is_mouse_entered:
|
if is_mouse_entered:
|
||||||
_on_mouse_entered()
|
_on_mouse_entered()
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,3 @@ autowrap_mode = 3
|
||||||
|
|
||||||
[node name="sticky note anchor" type="Node2D" parent="."]
|
[node name="sticky note anchor" type="Node2D" parent="."]
|
||||||
position = Vector2(-66, 83)
|
position = Vector2(-66, 83)
|
||||||
|
|
||||||
[connection signal="input_event" from="." to="." method="_on_input_event"]
|
|
||||||
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
|
|
||||||
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@
|
||||||
|
|
||||||
extends Area2D
|
extends Area2D
|
||||||
class_name StickyNote
|
class_name StickyNote
|
||||||
var sibling
|
var sibling: StickyNote
|
||||||
var shift_tween
|
var shift_tween: Tween
|
||||||
var modulate_tween
|
var modulate_tween: Tween
|
||||||
|
var card_stick_tween: Tween
|
||||||
|
var hovering_cards: Array[Card]
|
||||||
|
var hover_pos_shift: float
|
||||||
|
|
||||||
|
|
||||||
signal transform_tween_finished
|
signal transform_tween_finished
|
||||||
|
|
||||||
|
|
@ -50,6 +54,7 @@ var is_dragged: bool = false:
|
||||||
set(dragged):
|
set(dragged):
|
||||||
is_dragged = dragged
|
is_dragged = dragged
|
||||||
z_index = int(dragged)
|
z_index = int(dragged)
|
||||||
|
if not is_dragged: highlighted = false
|
||||||
|
|
||||||
var initial_drag_position: Vector2
|
var initial_drag_position: Vector2
|
||||||
var mouse_diff: Vector2
|
var mouse_diff: Vector2
|
||||||
|
|
@ -61,6 +66,12 @@ var attached_to: Node = null
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
|
||||||
|
input_event.connect(_on_input_event)
|
||||||
|
mouse_entered.connect(_on_mouse_entered)
|
||||||
|
mouse_exited.connect(_on_mouse_exited)
|
||||||
|
area_entered.connect(_on_area_enter)
|
||||||
|
area_exited.connect(_on_area_exit)
|
||||||
|
|
||||||
$Content/Label.text = self.text
|
$Content/Label.text = self.text
|
||||||
$Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation)
|
$Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation)
|
||||||
|
|
||||||
|
|
@ -89,12 +100,6 @@ func _process(delta: float) -> void:
|
||||||
|
|
||||||
_move_sticky_note()
|
_move_sticky_note()
|
||||||
|
|
||||||
func _on_focus_entered():
|
|
||||||
print(self, "is focused")
|
|
||||||
|
|
||||||
func _on_focus_exited():
|
|
||||||
print(self, "is not focused")
|
|
||||||
|
|
||||||
func _on_mouse_entered():
|
func _on_mouse_entered():
|
||||||
if not Input.is_action_pressed("mouse_left"):
|
if not Input.is_action_pressed("mouse_left"):
|
||||||
highlighted = true
|
highlighted = true
|
||||||
|
|
@ -102,26 +107,55 @@ func _on_mouse_entered():
|
||||||
owner.handle_hover(self)
|
owner.handle_hover(self)
|
||||||
|
|
||||||
func _on_mouse_exited():
|
func _on_mouse_exited():
|
||||||
highlighted = false
|
|
||||||
if is_sticky_note_attached() and "check_hover" in get_parent():
|
if is_sticky_note_attached() and "check_hover" in get_parent():
|
||||||
get_parent().check_hover()
|
get_parent().check_hover()
|
||||||
|
|
||||||
func _on_input_event(viewport, event, shape_idx):
|
if not is_dragged:
|
||||||
|
highlighted = false
|
||||||
|
|
||||||
|
func _on_area_enter(card: Area2D):
|
||||||
|
print(card)
|
||||||
|
if card is Card:
|
||||||
|
if hovering_cards == []:
|
||||||
|
hovering_cards = [card]
|
||||||
|
card_stick_tween = get_tree().create_tween()
|
||||||
|
card_stick_tween.set_ease(Tween.EASE_IN_OUT)
|
||||||
|
card_stick_tween.tween_property(self, "hover_pos_shift", 0.3, 0.3)
|
||||||
|
else:
|
||||||
|
hovering_cards.append(card)
|
||||||
|
|
||||||
|
func _on_area_exit(card: Area2D):
|
||||||
|
if hovering_cards.has(card):
|
||||||
|
hovering_cards.erase(card)
|
||||||
|
card.highlighted = false
|
||||||
|
if hovering_cards == []:
|
||||||
|
hover_pos_shift = 0
|
||||||
|
$Content.position = Vector2.ZERO
|
||||||
|
|
||||||
|
func _on_input_event(viewport, event, shape_idx):
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
if event.button_index == MOUSE_BUTTON_LEFT or event.button_index == MOUSE_BUTTON_RIGHT:
|
if event.button_index == MOUSE_BUTTON_LEFT or event.button_index == MOUSE_BUTTON_RIGHT:
|
||||||
if "handle_mouse_button" in owner:
|
if "handle_mouse_button" in owner:
|
||||||
mouse_diff = get_viewport().get_mouse_position()
|
mouse_diff = get_viewport().get_mouse_position()
|
||||||
initial_drag_position = global_position
|
initial_drag_position = global_position
|
||||||
owner.handle_mouse_button(self, event)
|
owner.handle_mouse_button(event, self)
|
||||||
|
|
||||||
func _move_sticky_note():
|
func _move_sticky_note():
|
||||||
if is_dragged:
|
if is_dragged:
|
||||||
position = initial_drag_position + get_viewport().get_mouse_position() - mouse_diff
|
position = initial_drag_position + get_viewport().get_mouse_position() - mouse_diff
|
||||||
|
|
||||||
|
if hovering_cards != []:
|
||||||
|
var closest: Card = hovering_cards[0]
|
||||||
|
for card in hovering_cards:
|
||||||
|
card.highlighted = false
|
||||||
|
if (closest.position - position).length() > (closest.position - position).length():
|
||||||
|
card = closest
|
||||||
|
closest.highlighted = true
|
||||||
|
$Content.position = (closest.sticky_note_anchor.global_position - global_position) * hover_pos_shift
|
||||||
|
|
||||||
func is_sticky_note_attached() -> bool:
|
func is_sticky_note_attached() -> bool:
|
||||||
# there is probably a nicer way to do this
|
# there is probably a nicer way to do this
|
||||||
return self.get_parent().get_parent() is Card
|
return self.get_parent() is Card
|
||||||
|
|
||||||
func tween_transform_to(target: Transform2D):
|
func tween_transform_to(target: Transform2D):
|
||||||
var transform_tween: Tween = create_tween()
|
var transform_tween: Tween = create_tween()
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,3 @@ theme = ExtResource("3_qmm0h")
|
||||||
theme_type_variation = &"card_text"
|
theme_type_variation = &"card_text"
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
autowrap_mode = 3
|
autowrap_mode = 3
|
||||||
|
|
||||||
[connection signal="input_event" from="." to="." method="_on_input_event"]
|
|
||||||
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
|
|
||||||
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
|
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,3 @@ autowrap_mode = 3
|
||||||
|
|
||||||
[node name="sticky note anchor" type="Node2D" parent="."]
|
[node name="sticky note anchor" type="Node2D" parent="."]
|
||||||
position = Vector2(-65.6478, 60.3852)
|
position = Vector2(-65.6478, 60.3852)
|
||||||
|
|
||||||
[connection signal="input_event" from="." to="." method="_on_input_event"]
|
|
||||||
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
|
|
||||||
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue