aboutsummaryrefslogtreecommitdiff
path: root/option_set
diff options
context:
space:
mode:
Diffstat (limited to 'option_set')
-rw-r--r--option_set/option_set.gd23
-rw-r--r--option_set/option_set.tscn3
2 files changed, 24 insertions, 2 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()
diff --git a/option_set/option_set.tscn b/option_set/option_set.tscn
index fc2aff5..bf15806 100644
--- a/option_set/option_set.tscn
+++ b/option_set/option_set.tscn
@@ -15,7 +15,8 @@ anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -100.0
size_flags_horizontal = 3
-placeholder_text = "option set placeholder"
+text = "placeholder"
+max_length = 4096
caret_blink = true
caret_blink_speed = 0.5
__meta__ = {