grounders-slowjam-2024/addons/fmod/tool/ui/ParameterDisplay.gd

51 lines
1.5 KiB
GDScript

@tool class_name ParameterDisplay extends MarginContainer
var parameter: FmodParameterDescription
func set_parameter(p_parameter: FmodParameterDescription):
show()
parameter = p_parameter
func display_value_selector(should: bool):
%ValueSetterContainer.visible = should
func _ready():
if parameter == null:
hide()
return
var minimum_value = parameter.get_minimum()
var maximum_value = parameter.get_maximum()
var default_value = parameter.get_default_value()
var copy_icon : Texture = EditorInterface.get_editor_theme().get_icon("ActionCopy", "EditorIcons")
%NameCopyButton.icon = copy_icon
%IdCopyButton.icon = copy_icon
%NameLabel.text = parameter.get_name()
%IdLabel.text = str(parameter.get_id())
%RangeLabel.text = "[%s, %s]" % [minimum_value, maximum_value]
%DefaultValueLabel.text = str(default_value)
%NameCopyButton.pressed.connect(_on_copy_name_button)
%IdCopyButton.pressed.connect(_on_copy_id_button)
%BackToDefaultButton.pressed.connect(_on_default_value_button)
%ValueSlider.min_value = minimum_value
%ValueSlider.max_value = maximum_value
%ValueSlider.value = default_value
_on_slider_value_changed(%ValueSlider.value)
%ValueSlider.value_changed.connect(_on_slider_value_changed)
func _on_copy_name_button():
DisplayServer.clipboard_set(%NameLabel.text)
func _on_copy_id_button():
DisplayServer.clipboard_set(%IdLabel.text)
func _on_default_value_button():
%ValueSlider.value = parameter.get_default_value()
func _on_slider_value_changed(value: float):
%CurrentValueLabel.text = str(value)