33 lines
846 B
GDScript
33 lines
846 B
GDScript
extends Area2D
|
|
class_name MouseInteractionComponent
|
|
|
|
@export var stickyHold: bool = false #When this is true the action can be held even tho the mouse has allready left the area
|
|
|
|
var mouseInside: bool = false #When mouse is inside collision
|
|
var mousePressedL: bool = false #When Left mouse button is pressed down
|
|
|
|
var actionHeld: bool = false
|
|
signal actionPressed
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("MinigameClick"):
|
|
mousePressedL = true
|
|
if event.is_action_released("MinigameClick"):
|
|
mousePressedL = false
|
|
|
|
func _process(_delta: float) -> void:
|
|
if mousePressedL and (mouseInside or (stickyHold and actionHeld)):
|
|
if !actionHeld:
|
|
actionPressed.emit()
|
|
|
|
actionHeld = true
|
|
else:
|
|
actionHeld = false
|
|
|
|
|
|
func _mouse_enter() -> void:
|
|
mouseInside = true
|
|
|
|
func _mouse_exit() -> void:
|
|
mouseInside = false
|