@tool extends OptionButton class_name CustomOptionButton signal onValueChanged(value : String) var selectedValue : String var options : Dictionary func _ready() -> void: allow_reselect = true item_selected.connect(itemHasBeenSelected) func setOptions(options : Dictionary, defaultSelectedValue : String = "") -> void: self.options = options clear() options.keys().map(add_item) selectItemByValue(defaultSelectedValue) func addOption(value : String, displayName : String, autoSelect : bool = false) -> void: add_item(displayName) options.set(value, displayName) if autoSelect: selected = options.size() - 1 selectedValue = value func itemHasBeenSelected(index : int) -> void: var value = options.get(get_item_text(index)) if selectedValue != value: selectedValue = value onValueChanged.emit(selectedValue) func selectItemByValue(value : String) -> void: var name = options.find_key(value) for i in item_count: if get_item_text(i) == name: selected = i selectedValue = value return if options: selected = 0 itemHasBeenSelected(0)