buckshotroulette-decomp/ButtonClass.gd

68 lines
2.0 KiB
GDScript3
Raw Normal View History

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
@export var ui_control : Control
2024-01-20 12:17:43 +00:00
@export var speaker_press : AudioStreamPlayer2D
@export var speaker_hover : AudioStreamPlayer2D
@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
@export var altsound : bool
@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
@export var adding_cursor : bool
@export var t : Label
var mainActive = true
var orig
2024-01-20 12:17:43 +00:00
func _ready():
if (adding_cursor): orig = t.text
ui_control = get_parent()
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)
if (isDynamic): ui.modulate.a = ui_opacity_inactive
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():
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()
ui.modulate.a = ui_opacity_active
2024-01-20 12:17:43 +00:00
cursor.SetCursorImage("hover")
if (adding_cursor): t.text = "< " + tr(orig) + " >"
2024-01-20 12:17:43 +00:00
func OnExit():
if (isActive && mainActive):
2024-01-20 12:17:43 +00:00
if (isDynamic):
ui.modulate.a = ui_opacity_inactive
2024-01-20 12:17:43 +00:00
cursor.SetCursorImage("point")
if (adding_cursor): t.text = tr(orig)
2024-01-20 12:17:43 +00:00
signal is_pressed
func OnPress():
if (isActive && mainActive):
if (altsound): speaker_press.play()
2024-01-20 12:17:43 +00:00
if (isDynamic && playing): speaker_press.play()
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")