diff options
| author | dam <dam@gudinoff> | 2022-02-18 01:34:43 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-02-18 01:34:43 +0000 |
| commit | 283c0f2d84420bd02550dd4404b306d427fd58af (patch) | |
| tree | 3999ad958556bcccba63b5fca05880accdc827f3 /option_set/option_set.gd | |
| parent | 48a26128f175047528fcc1c96590f1a7bbc281eb (diff) | |
| download | surgery-log-283c0f2d84420bd02550dd4404b306d427fd58af.tar.zst surgery-log-283c0f2d84420bd02550dd4404b306d427fd58af.zip | |
Implemented custom option set control. Fixed option sets text input zone being hidden below the button.
Diffstat (limited to 'option_set/option_set.gd')
| -rw-r--r-- | option_set/option_set.gd | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/option_set/option_set.gd b/option_set/option_set.gd index e9cac3f..62d10d0 100644 --- a/option_set/option_set.gd +++ b/option_set/option_set.gd @@ -1,6 +1,7 @@ extends Control class_name OptionSet +var options: Array var text: String setget set_text, get_text func set_text(var value: String): @@ -9,7 +10,27 @@ func set_text(var value: String): func get_text() -> String: return input.text +onready var input := get_node("input") as LineEdit +onready var button := get_node("options") as Button # @DAM Maybe rename this. Also requires renaming on stage. +onready var popup := get_node("/root/main/popup_list") as PopupList -onready var input := get_node("input") as LineEdit +func _ready(): + assert(popup != null, "OptionSet failed to get 'popup' node.") + + input.connect("focus_entered", input, "set", ["caret_position", input.max_length]) + input.connect("focus_exited", input, "deselect") + + +func show_options(options_array: Array): + options = options_array + popup.connect("item_selected", self, "option_selected", [], CONNECT_ONESHOT) + popup.popup_options(options) + + +func option_selected(index: int): + if index >= 0 && index < options.size(): + input.text = options[index] + input.caret_position = input.max_length + button.release_focus() |
