@@ -10,7 +10,9 @@ signal modified
1010
1111@export var variant_type : Variant .Type = TYPE_STRING
1212@export var block_type : Types .BlockType = Types .BlockType .VALUE
13- var option : bool = false
13+ @export var option_data : OptionData :
14+ set = _set_option_data
15+
1416var default_value : Variant
1517
1618@onready var _panel := % Panel
@@ -42,16 +44,13 @@ var default_value: Variant
4244
4345
4446func set_raw_input (raw_input ):
45- if option :
46- _panel .visible = false
47- _option_input .clear ()
48- var option_data : OptionData = raw_input as OptionData
49- for item in option_data .items :
50- _option_input .add_item (item .capitalize ())
51- _option_input .select (option_data .selected )
52-
47+ if option_data :
48+ _update_option_input (raw_input )
5349 return
5450
51+ if raw_input == null :
52+ raw_input = default_value
53+
5554 match variant_type :
5655 TYPE_COLOR :
5756 _color_input .color = raw_input
@@ -61,19 +60,16 @@ func set_raw_input(raw_input):
6160 _x_line_edit .text = ("%.4f " % raw_input .x ).rstrip ("0" ).rstrip ("." )
6261 _y_line_edit .text = ("%.4f " % raw_input .y ).rstrip ("0" ).rstrip ("." )
6362 TYPE_BOOL :
64- _bool_input_option .select (raw_input )
63+ _bool_input_option .select (1 if raw_input else 0 )
6564 TYPE_NIL :
66- _line_edit .text = raw_input
65+ _line_edit .text = raw_input if raw_input else ""
6766 _ :
68- _line_edit .text = "" if raw_input == null else str ( raw_input )
67+ _line_edit .text = str ( raw_input ) if raw_input else ""
6968
7069
7170func get_raw_input ():
72- if option :
73- var options : Array = []
74- for i in _option_input .item_count :
75- options .append (_option_input .get_item_text (i ).to_snake_case ())
76- return OptionData .new (options , _option_input .selected )
71+ if option_data :
72+ return _option_input .get_selected_metadata ()
7773
7874 match variant_type :
7975 TYPE_COLOR :
@@ -92,20 +88,32 @@ func get_raw_input():
9288 return _line_edit .text
9389
9490
91+ func _set_option_data (new_option_data : OptionData ) -> void :
92+ option_data = new_option_data
93+
94+ if not is_node_ready ():
95+ return
96+
97+ _update_option_input ()
98+
99+
95100func _set_placeholder (new_placeholder : String ) -> void :
96101 placeholder = new_placeholder
97102
98103 if not is_node_ready ():
99104 return
100105
101106 _line_edit .placeholder_text = placeholder
107+ _input_switcher .tooltip_text = placeholder
108+ _option_input .tooltip_text = placeholder
102109
103110
104111func _ready ():
105112 var stylebox = _panel .get_theme_stylebox ("panel" )
106113 stylebox .bg_color = Color .WHITE
107114
108115 _set_placeholder (placeholder )
116+ _set_option_data (option_data )
109117
110118 snap_point .block_type = block_type
111119 snap_point .variant_type = variant_type
@@ -132,8 +140,8 @@ func get_string() -> String:
132140
133141 var input = get_raw_input ()
134142
135- if option :
136- return _option_input . get_item_text ( _option_input . selected ). to_snake_case ()
143+ if option_data :
144+ return input
137145
138146 match variant_type :
139147 TYPE_STRING :
@@ -194,7 +202,7 @@ func _on_y_line_edit_focus_exited():
194202func _update_visible_input ():
195203 if snap_point .has_snapped_block ():
196204 _switch_input (null )
197- elif option :
205+ elif option_data :
198206 _switch_input (_option_input )
199207 else :
200208 match variant_type :
@@ -211,6 +219,29 @@ func _update_visible_input():
211219func _switch_input (node : Node ):
212220 for c in _input_switcher .get_children ():
213221 c .visible = c == node
222+ _panel .visible = node not in [_option_input ]
223+
224+
225+ func _update_option_input (current_value : Variant = null ):
226+ if not option_data :
227+ return
228+
229+ if current_value == null :
230+ current_value = _option_input .get_selected_metadata ()
231+
232+ _option_input .clear ()
233+
234+ var selected_item_index : int = - 1
235+
236+ for item in option_data .items :
237+ var item_index = _option_input .item_count
238+ var option_label = item .capitalize ()
239+ _option_input .add_item (option_label )
240+ _option_input .set_item_metadata (item_index , item )
241+ if item == current_value :
242+ selected_item_index = item_index
243+
244+ _option_input .select (selected_item_index )
214245
215246
216247func _on_color_input_color_changed (color ):
0 commit comments