]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Editor/Events/Fields/field_options_fixed.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Editor / Events / Fields / field_options_fixed.gd
1 @tool
2 extends DialogicVisualEditorField
3
4 ## Event block field for constant options. For varying options use ComplexPicker.
5
6 var options: Array = []
7
8 ## if true, only the symbol will be displayed. In the dropdown text will be visible.
9 ## Useful for making UI simpler
10 var symbol_only := false:
11         set(value):
12                 symbol_only = value
13                 if value: self.text = ""
14
15 var current_value: Variant = -1
16
17
18 func _ready() -> void:
19         add_theme_color_override("font_disabled_color", get_theme_color("font_color", "MenuButton"))
20         self.about_to_popup.connect(insert_options)
21         call("get_popup").index_pressed.connect(index_pressed)
22
23
24 func _load_display_info(info:Dictionary) -> void:
25         options = info.get('options', [])
26         self.disabled = info.get('disabled', false)
27         symbol_only = info.get('symbol_only', false)
28
29
30 func _set_value(value:Variant) -> void:
31         for option in options:
32                 if option['value'] == value:
33                         if typeof(option.get('icon')) == TYPE_ARRAY:
34                                 option.icon = callv('get_theme_icon', option.get('icon'))
35                         if !symbol_only:
36                                 self.text = option['label']
37                         self.icon = option.get('icon', null)
38                         current_value = value
39
40
41 func get_value() -> Variant:
42         return current_value
43
44
45 func insert_options() -> void:
46         call("get_popup").clear()
47
48         var idx := 0
49         for option in options:
50                 if typeof(option.get('icon')) == TYPE_ARRAY:
51                         option.icon = callv('get_theme_icon', option.get('icon'))
52                 call("get_popup").add_icon_item(option.get('icon', null), option['label'])
53                 call("get_popup").set_item_metadata(idx, option['value'])
54                 idx += 1
55
56
57 func index_pressed(idx:int) -> void:
58         current_value = idx
59         if !symbol_only:
60                 self.text = call("get_popup").get_item_text(idx)
61         self.icon  =call("get_popup").get_item_icon(idx)
62         value_changed.emit(property_name, call("get_popup").get_item_metadata(idx))