diff options
| author | dam <dam@gudinoff> | 2022-04-18 09:06:19 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-04-18 09:06:19 +0000 |
| commit | 79691f93bab7aa093bb606bfb80d2b4b236ee091 (patch) | |
| tree | 6e90c6601893895d7640f478f0cad402cc7590b4 /ui/option_set/option_set.gd | |
| parent | 697e1ba3c4cb0a96c4584f1553de368d46287ab7 (diff) | |
| parent | ee31a9a3d387121030a5f4503adeac5816d7726f (diff) | |
| download | surgery-log-79691f93bab7aa093bb606bfb80d2b4b236ee091.tar.zst surgery-log-79691f93bab7aa093bb606bfb80d2b4b236ee091.zip | |
Merge godot branch.v1.0
Diffstat (limited to 'ui/option_set/option_set.gd')
| -rw-r--r-- | ui/option_set/option_set.gd | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/ui/option_set/option_set.gd b/ui/option_set/option_set.gd new file mode 100644 index 0000000..25ca0ff --- /dev/null +++ b/ui/option_set/option_set.gd @@ -0,0 +1,44 @@ +extends Control +class_name OptionSet + +export var placeholder: String + +var text: String setget set_text, get_text + +func set_text(var value: String): + input.text = value + +func get_text() -> String: + return input.text + +var selected_idx: int + +onready var input := get_node("input") as LineEdit +onready var button := get_node("button") as Button +onready var popup := get_node("/root/main/popup") as ModalPopup +onready var options := get_node("/root/main/option_set_list") as OptionSetList + + +func _ready(): + assert(popup != null, "OptionSet failed to get 'popup' node.") + input.placeholder_text = placeholder + input.connect("focus_entered", input, "set", ["caret_position", input.max_length]) + input.connect("focus_exited", input, "deselect") + + +func show_options(options_array: Array): + options.clear_items() + options.add_items(options_array) + options.select(options_array.find(input.text)) + options.connect("selection_changed", self, "popup_result") + popup.open_popup(input.placeholder_text, options) + + +func popup_result(index: int, text: String): + if index != -1: + selected_idx = index + input.text = text + input.caret_position = input.max_length + popup.close_popup() + + |
