4 ## Event block field part for a value that can change type.
9 var value_type: int = -1
11 var current_value: Variant
13 func _ready() -> void:
14 %ValueType.options = [{
16 'icon': ["String", "EditorIcons"],
19 'label': 'Number (int)',
20 'icon': ["int", "EditorIcons"],
23 'label': 'Number (float)',
24 'icon': ["float", "EditorIcons"],
28 'icon': ["bool", "EditorIcons"],
31 'label': 'Expression',
32 'icon': ["Variant", "EditorIcons"],
36 %ValueType.symbol_only = true
37 %ValueType.value_changed.connect(_on_type_changed.bind())
38 %ValueType.tooltip_text = "Change type"
41 func set_value(value:Variant):
42 change_field_type(deduce_type(value))
43 %ValueType.set_value(deduce_type(value))
47 value_field.button_pressed = value
49 value_field.text = value
51 value_field.set_value(value)
53 value_field.text = value.trim_prefix('@')
56 func deduce_type(value:Variant) -> int:
57 if value is String and value.begins_with('@'):
63 func _on_type_changed(prop:String, type:Variant) -> void:
64 if type == value_type:
69 if typeof(current_value) == TYPE_STRING:
70 current_value = DialogicUtil.str_to_bool(current_value)
71 elif value_type == TYPE_FLOAT or value_type == TYPE_INT:
72 current_value = bool(current_value)
74 current_value = true if current_value else false
75 set_value(current_value)
77 current_value = str(current_value).trim_prefix('@')
78 set_value(current_value)
80 current_value = float(current_value)
81 set_value(current_value)
83 current_value = int(current_value)
84 set_value(current_value)
86 current_value = var_to_str(current_value)
87 set_value('@'+current_value)
90 emit_signal.call_deferred('value_changed')
93 func get_value() -> Variant:
97 func _on_delete_pressed() -> void:
102 func change_field_type(type:int) -> void:
103 if type == value_type:
109 value_field.queue_free()
112 value_field = CheckBox.new()
113 value_field.toggled.connect(_on_bool_toggled)
115 value_field = LineEdit.new()
116 value_field.theme_type_variation = "DialogicEventEdit"
117 value_field.text_changed.connect(_on_str_text_changed)
118 value_field.expand_to_text_length = true
119 TYPE_FLOAT, TYPE_INT:
120 value_field = load("res://addons/dialogic/Editor/Events/Fields/field_number.tscn").instantiate()
121 if type == TYPE_FLOAT:
122 value_field.use_float_mode()
124 value_field.use_int_mode()
125 value_field.value_changed.connect(_on_number_value_changed.bind(type == TYPE_INT))
127 value_field = LineEdit.new()
128 value_field.expand_to_text_length = true
129 value_field.text_changed.connect(_on_expression_changed)
130 add_child(value_field)
131 move_child(value_field, 1)
134 func _on_bool_toggled(value:bool) -> void:
135 current_value = value
139 func _on_str_text_changed(value:String) -> void:
140 current_value = value
144 func _on_expression_changed(value:String) -> void:
145 current_value = '@'+value
149 func _on_number_value_changed(prop:String, value:float, int := false) -> void:
151 current_value = int(value)
153 current_value = value