2024-01-20 12:17:43 +00:00
|
|
|
class_name ButtonClass extends Node
|
|
|
|
|
|
|
|
@export var cursor : CursorManager
|
|
|
|
@export var alias : String
|
|
|
|
@export var isActive : bool
|
|
|
|
@export var isDynamic : bool
|
|
|
|
@export var ui : CanvasItem
|
2024-01-28 11:58:35 +00:00
|
|
|
@export var ui_control : Control
|
2024-01-20 12:17:43 +00:00
|
|
|
@export var speaker_press : AudioStreamPlayer2D
|
|
|
|
@export var speaker_hover : AudioStreamPlayer2D
|
2024-04-05 10:52:30 +01:00
|
|
|
@export var rebind : Node
|
|
|
|
@export var language : bool
|
|
|
|
@export var options : OptionsManager
|
|
|
|
@export var rebindManager : Rebinding
|
2024-01-20 12:17:43 +00:00
|
|
|
@export var playing : bool
|
2024-01-28 11:58:35 +00:00
|
|
|
@export var altsound : bool
|
2024-04-05 10:52:30 +01:00
|
|
|
@export var ui_opacity_inactive : float = 1
|
|
|
|
@export var ui_opacity_active : float = .78
|
|
|
|
@export var resetting : bool
|
2024-10-28 16:42:34 +00:00
|
|
|
@export var pipe : LobbyManager
|
2024-04-13 15:32:57 +01:00
|
|
|
@export var adding_cursor : bool
|
|
|
|
@export var t : Label
|
2024-01-28 11:58:35 +00:00
|
|
|
var mainActive = true
|
2024-04-13 15:32:57 +01:00
|
|
|
var orig
|
2024-01-20 12:17:43 +00:00
|
|
|
|
|
|
|
func _ready():
|
2024-04-13 15:32:57 +01:00
|
|
|
if (adding_cursor): orig = t.text
|
2024-01-28 11:58:35 +00:00
|
|
|
ui_control = get_parent()
|
2024-04-05 10:52:30 +01:00
|
|
|
get_parent().connect("focus_entered", OnHover)
|
|
|
|
get_parent().connect("focus_exited", OnExit)
|
2024-01-20 12:17:43 +00:00
|
|
|
get_parent().connect("mouse_entered", OnHover)
|
|
|
|
get_parent().connect("mouse_exited", OnExit)
|
|
|
|
get_parent().connect("pressed", OnPress)
|
2024-04-05 10:52:30 +01:00
|
|
|
if (isDynamic): ui.modulate.a = ui_opacity_inactive
|
2024-01-28 11:58:35 +00:00
|
|
|
|
|
|
|
func SetFilter(alias : String):
|
|
|
|
match(alias):
|
|
|
|
"ignore":
|
|
|
|
ui_control.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
"stop":
|
|
|
|
ui_control.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
|
|
|
2024-01-20 12:17:43 +00:00
|
|
|
func OnHover():
|
2024-01-28 11:58:35 +00:00
|
|
|
if (isActive && mainActive):
|
2024-01-20 12:17:43 +00:00
|
|
|
if (isDynamic):
|
|
|
|
speaker_hover.pitch_scale = randf_range(.95, 1.0)
|
|
|
|
speaker_hover.play()
|
2024-04-05 10:52:30 +01:00
|
|
|
ui.modulate.a = ui_opacity_active
|
2024-01-20 12:17:43 +00:00
|
|
|
cursor.SetCursorImage("hover")
|
2024-04-13 15:32:57 +01:00
|
|
|
if (adding_cursor): t.text = "< " + tr(orig) + " >"
|
2024-01-20 12:17:43 +00:00
|
|
|
|
|
|
|
func OnExit():
|
2024-01-28 11:58:35 +00:00
|
|
|
if (isActive && mainActive):
|
2024-01-20 12:17:43 +00:00
|
|
|
if (isDynamic):
|
2024-04-05 10:52:30 +01:00
|
|
|
ui.modulate.a = ui_opacity_inactive
|
2024-01-20 12:17:43 +00:00
|
|
|
cursor.SetCursorImage("point")
|
2024-04-13 15:32:57 +01:00
|
|
|
if (adding_cursor): t.text = tr(orig)
|
2024-01-20 12:17:43 +00:00
|
|
|
|
|
|
|
signal is_pressed
|
|
|
|
func OnPress():
|
2024-01-28 11:58:35 +00:00
|
|
|
if (isActive && mainActive):
|
|
|
|
if (altsound): speaker_press.play()
|
2024-01-20 12:17:43 +00:00
|
|
|
if (isDynamic && playing): speaker_press.play()
|
2024-04-05 10:52:30 +01:00
|
|
|
if (rebind != null): rebindManager.GetRebind(rebind)
|
|
|
|
if (language): options.AdjustLanguage(alias)
|
2024-10-28 16:42:34 +00:00
|
|
|
if (pipe != null): pipe.Pipe(alias)
|
2024-01-20 12:17:43 +00:00
|
|
|
emit_signal("is_pressed")
|