small racing game im working on
Diffstat (limited to 'ui/multi_button.gd')
-rw-r--r--ui/multi_button.gd31
1 files changed, 31 insertions, 0 deletions
diff --git a/ui/multi_button.gd b/ui/multi_button.gd
new file mode 100644
index 0000000..3db2b39
--- /dev/null
+++ b/ui/multi_button.gd
@@ -0,0 +1,31 @@
+extends Button
+class_name MultiButton
+
+@export var secondary: Control
+
+func update(_var = null): # cant unbind when connecting signals in code
+ var color: StringName = &"font_color"
+ if disabled:
+ color = &"font_disabled_color"
+ elif button_pressed:
+ color = &"font_pressed_color"
+ elif (is_hovered() if _var == null else _var) || has_focus():
+ color = &"font_hover_color"
+ set_c(get_theme_color(color))
+
+func set_c(c: Color) -> void:
+ if secondary is Label:
+ secondary.label_settings.font_color = c
+ elif secondary is TextureRect:
+ secondary.modulate = c
+
+func _ready() -> void:
+ update()
+ toggled.connect(update)
+ focus_entered.connect(update)
+ focus_exited.connect(update)
+ mouse_entered.connect(update.bind(true))
+ mouse_exited.connect(update.bind(false))
+ pressed.connect(update)
+ button_up.connect(update)
+ button_down.connect(update)