aboutsummaryrefslogtreecommitdiff
path: root/option_set/option_set.gd
diff options
context:
space:
mode:
Diffstat (limited to 'option_set/option_set.gd')
-rw-r--r--option_set/option_set.gd39
1 files changed, 29 insertions, 10 deletions
diff --git a/option_set/option_set.gd b/option_set/option_set.gd
index 62d10d0..040566a 100644
--- a/option_set/option_set.gd
+++ b/option_set/option_set.gd
@@ -1,7 +1,6 @@
extends Control
class_name OptionSet
-var options: Array
var text: String setget set_text, get_text
func set_text(var value: String):
@@ -10,9 +9,12 @@ func set_text(var value: String):
func get_text() -> String:
return input.text
+var selected_idx: int
+
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 popup := get_node("/root/main/popup") as ModalPopup
+onready var options := get_node("/root/main/option_set_list") as OptionSetList
func _ready():
@@ -23,14 +25,31 @@ func _ready():
func show_options(options_array: Array):
- options = options_array
- popup.connect("item_selected", self, "option_selected", [], CONNECT_ONESHOT)
- popup.popup_options(options)
+ options.clear_items()
+ var main = get_node("/root/main")
+ main.remove_child(options)
+ options.add_items(options_array)
+ if options_array[selected_idx] == input.text:
+ options.select(selected_idx)
+ else:
+ options.unselect()
+ options.connect("item_selected", self, "option_selected", [], CONNECT_ONESHOT)
+ popup.popup_control(options)
+# popup.connect("item_selected", self, "option_selected", [], CONNECT_ONESHOT)
+# popup.clear_items()
+# popup_opt.visible = true
+# get_node("/root/main/popup/blur")
+# popup.add_items(options)
+
+
+func option_selected(index: int, text: String):
+ selected_idx = index
+ input.text = text
+ input.caret_position = input.max_length
+ button.release_focus()
+ options.visible = false
+ var main = get_node("/root/main")
+ main.add_child(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()