improving parsing and passing of mouse events

This commit is contained in:
betalars 2023-06-30 00:53:16 +02:00
parent bbec8c4f25
commit 8307380bf0
2 changed files with 26 additions and 5 deletions

View File

@ -51,6 +51,7 @@ var scale_tween
@export var voice_line: AudioStream = null
@export var is_dragable: bool = false
var is_dragged: bool = false
func _ready():
@ -96,12 +97,22 @@ func _on_focus_exited():
print(self, "is not focused")
func _on_mouse_entered():
highlighted = true
if not Input.is_action_pressed("mouse_left"):
highlighted = true
if "handle_hover" in owner:
owner.handle_hover(self)
func _on_mouse_exited():
highlighted = false
func _on_input_event(viewport, event, shape_idx):
if event is InputEventMouseMotion and Input.is_action_pressed("mouse_left") and is_dragable:
if event is InputEventMouseMotion and is_dragged:
position += event.relative
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
if is_dragable:
is_dragged = event.pressed
if "handle_mouse_button" in owner:
owner.handle_mouse_button(self, event)

View File

@ -42,6 +42,7 @@ var modulate_tween
@export var voice_line: AudioStream = null
@export var is_dragable: bool = false
var is_dragged = false
func _ready() -> void:
$Content/Label.text = self.text
@ -63,12 +64,21 @@ func _on_focus_exited():
print(self, "is not focused")
func _on_mouse_entered():
#owner.grab_highlight(self)
highlighted = true
if not Input.is_action_pressed("mouse_left"):
highlighted = true
if "handle_hover" in owner:
owner.handle_hover(self)
func _on_mouse_exited():
highlighted = false
func _on_input_event(viewport, event, shape_idx):
if event is InputEventMouseMotion and Input.is_action_pressed("mouse_left") and is_dragable:
if event is InputEventMouseMotion and is_dragged:
position += event.relative
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
if is_dragable:
is_dragged = event.pressed
if "handle_mouse_button" in owner:
owner.handle_mouse_button(self, event)