2026-01-24 14:29:16 +02:00
|
|
|
@tool
|
|
|
|
|
class_name ControllerButton
|
|
|
|
|
extends ColorRect
|
|
|
|
|
|
2026-01-24 21:46:06 +02:00
|
|
|
const text_shader = preload("uid://crnhvx5xfqmj7")
|
|
|
|
|
|
2026-01-24 14:29:16 +02:00
|
|
|
@onready var label_node: RichTextLabel = $Label
|
|
|
|
|
|
|
|
|
|
@export var input_code: String
|
|
|
|
|
@export var label: String:
|
|
|
|
|
set(val):
|
|
|
|
|
label = val
|
|
|
|
|
if Engine.is_editor_hint() && self.label_node != null:
|
2026-01-24 21:46:06 +02:00
|
|
|
if val.begins_with("uid://"):
|
|
|
|
|
self.label_node.text = "[img]%s[/img]" % label
|
|
|
|
|
else:
|
|
|
|
|
self.label_node.text = label
|
|
|
|
|
|
|
|
|
|
var default_color: Color
|
|
|
|
|
var active_color: Color
|
|
|
|
|
var text_color: Color
|
2026-01-24 14:29:16 +02:00
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2026-01-24 21:46:06 +02:00
|
|
|
self.default_color = Config.default_button_color.value
|
|
|
|
|
self.active_color = Config.active_color.value
|
|
|
|
|
self.text_color = Config.text_color.value
|
|
|
|
|
|
2026-01-24 18:40:25 +02:00
|
|
|
if Config.buttons_labels.value:
|
|
|
|
|
self.label_node.text = self.label
|
|
|
|
|
else:
|
|
|
|
|
self.label_node.text = ""
|
2026-01-24 20:11:47 +02:00
|
|
|
|
2026-01-24 21:46:06 +02:00
|
|
|
self.label_node.add_theme_color_override("default_color", self.text_color)
|
|
|
|
|
self.color = default_color
|
2026-01-24 20:11:47 +02:00
|
|
|
|
2026-01-24 14:29:16 +02:00
|
|
|
assert(self.input_code, "Missing input code for %s" % self.name)
|
|
|
|
|
assert(InputMap.has_action(self.input_code), "Invalid input code for %s" % self.name)
|
2026-01-24 21:46:06 +02:00
|
|
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
|
|
|
if Engine.is_editor_hint():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
var has_action_pressed := Input.is_action_pressed(self.input_code)
|
|
|
|
|
if Config.color_button_text.value:
|
|
|
|
|
self.label_node.set_instance_shader_parameter("TextColor", self.active_color if has_action_pressed else self.text_color)
|
|
|
|
|
else:
|
|
|
|
|
self.color = self.active_color if has_action_pressed else self.default_color
|