Skip to content

Commit b87ed04

Browse files
UI: Improve usage of number field on floats, ints and vectors (#2638)
* Fix spinbox issue: style setting for text_max_width can not be greater than 100 * Very slightly adjust code * Improve Vector and Number fields * Use number field for floats and ints --------- Co-authored-by: jinyang <jinyangcruise@163.com>
1 parent 4825ceb commit b87ed04

File tree

11 files changed

+108
-49
lines changed

11 files changed

+108
-49
lines changed

addons/dialogic/Core/DialogicUtil.gd

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,36 +433,49 @@ static func setup_script_property_edit_node(property_info: Dictionary, value:Var
433433
input.select(value)
434434
input.item_selected.connect(DialogicUtil._on_export_int_enum_submitted.bind(property_info.name, property_changed))
435435
else:
436-
input = SpinBox.new()
437-
input.value_changed.connect(DialogicUtil._on_export_number_submitted.bind(property_info.name, property_changed))
436+
input = load("res://addons/dialogic/Editor/Events/Fields/field_number.tscn").instantiate()
437+
input.property_name = property_info['name']
438+
input.use_int_mode()
439+
438440
if ',' in property_info.hint_string:
439441
input.min_value = int(property_info.hint_string.get_slice(',', 0))
440442
input.max_value = int(property_info.hint_string.get_slice(',', 1))
441443
if property_info.hint_string.count(',') > 1:
442444
input.step = int(property_info.hint_string.get_slice(',', 2))
443445
else:
444446
input.step = 1
445-
input.allow_greater = true
446-
input.allow_lesser = true
447+
input.max_value = INF
448+
input.min_value = -INF
449+
447450
if value != null:
448-
input.value = value
451+
input.set_value(value)
452+
input.value_changed.connect(DialogicUtil._on_export_number_submitted.bind(property_changed))
449453
TYPE_FLOAT:
450-
input = SpinBox.new()
454+
input = load("res://addons/dialogic/Editor/Events/Fields/field_number.tscn").instantiate()
455+
input.property_name = property_info['name']
456+
input.use_float_mode()
451457
input.step = 0.01
452458
if ',' in property_info.hint_string:
453459
input.min_value = float(property_info.hint_string.get_slice(',', 0))
454460
input.max_value = float(property_info.hint_string.get_slice(',', 1))
455461
if property_info.hint_string.count(',') > 1:
456462
input.step = float(property_info.hint_string.get_slice(',', 2))
457-
input.value_changed.connect(DialogicUtil._on_export_number_submitted.bind(property_info.name, property_changed))
458463
if value != null:
459-
input.value = value
464+
input.set_value(value)
465+
input.value_changed.connect(DialogicUtil._on_export_number_submitted.bind(property_changed))
460466
TYPE_VECTOR2, TYPE_VECTOR3, TYPE_VECTOR4:
461467
var vectorSize: String = type_string(typeof(value))[-1]
462468
input = load("res://addons/dialogic/Editor/Events/Fields/field_vector" + vectorSize + ".tscn").instantiate()
463469
input.property_name = property_info['name']
464470
input.set_value(value)
465471
input.value_changed.connect(DialogicUtil._on_export_vector_submitted.bind(property_changed))
472+
TYPE_VECTOR2I, TYPE_VECTOR3I, TYPE_VECTOR4I:
473+
var vectorSize: String = type_string(typeof(value))[-2]
474+
input = load("res://addons/dialogic/Editor/Events/Fields/field_vector" + vectorSize + ".tscn").instantiate()
475+
input.step = 1
476+
input.property_name = property_info['name']
477+
input.set_value(value)
478+
input.value_changed.connect(DialogicUtil._on_export_vectori_submitted.bind(property_changed))
466479
TYPE_STRING:
467480
if property_info['hint'] & PROPERTY_HINT_FILE or property_info['hint'] & PROPERTY_HINT_DIR:
468481
input = load("res://addons/dialogic/Editor/Events/Fields/field_file.tscn").instantiate()
@@ -520,7 +533,7 @@ static func _on_export_color_submitted(color:Color, property_name:String, callab
520533
static func _on_export_int_enum_submitted(item:int, property_name:String, callable: Callable) -> void:
521534
callable.call(property_name, var_to_str(item))
522535

523-
static func _on_export_number_submitted(value:float, property_name:String, callable: Callable) -> void:
536+
static func _on_export_number_submitted(property_name:String, value:float, callable: Callable) -> void:
524537
callable.call(property_name, var_to_str(value))
525538

526539
static func _on_export_file_submitted(property_name:String, value:String, callable: Callable) -> void:
@@ -532,6 +545,13 @@ static func _on_export_string_enum_submitted(value:int, property_name:String, li
532545
static func _on_export_vector_submitted(property_name:String, value:Variant, callable: Callable) -> void:
533546
callable.call(property_name, var_to_str(value))
534547

548+
static func _on_export_vectori_submitted(property_name:String, value:Variant, callable: Callable) -> void:
549+
match typeof(value):
550+
TYPE_VECTOR2: value = Vector2i(value)
551+
TYPE_VECTOR3: value = Vector3i(value)
552+
TYPE_VECTOR4: value = Vector4i(value)
553+
callable.call(property_name, var_to_str(value))
554+
535555
static func _on_export_dict_submitted(property_name:String, value:Variant, callable: Callable) -> void:
536556
callable.call(property_name, var_to_str(value))
537557

addons/dialogic/Editor/Events/Fields/field_number.gd

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ extends DialogicVisualEditorField
1414
@export var allow_string: bool = false
1515
@export var step: float = 0.1
1616
@export var enforce_step: bool = true
17-
@export var min: float = -INF
18-
@export var max: float = INF
17+
@export var min_value: float = -INF
18+
@export var max_value: float = INF
1919
@export var value = 0.0
2020
@export var prefix: String = ""
2121
@export var suffix: String = ""
@@ -37,8 +37,8 @@ func _load_display_info(info: Dictionary) -> void:
3737

3838
for option in info.keys():
3939
match option:
40-
'min': min = info[option]
41-
'max': max = info[option]
40+
'min': min_value = info[option]
41+
'max': max_value = info[option]
4242
'prefix': update_prefix(info[option])
4343
'suffix': update_suffix(info[option])
4444
'step':
@@ -61,22 +61,20 @@ func get_value() -> float:
6161
return value
6262

6363

64-
func use_float_mode(value_step: float = 0.1) -> void:
65-
#step = value_step
64+
func use_float_mode() -> void:
6665
update_suffix("")
6766
enforce_step = false
6867

6968

70-
func use_int_mode(value_step: float = 1) -> void:
71-
#step = value_step
69+
func use_int_mode() -> void:
7270
update_suffix("")
7371
enforce_step = true
7472

7573

76-
func use_decibel_mode(value_step: float = step) -> void:
77-
max = 6
74+
func use_decibel_mode() -> void:
75+
max_value = 6
7876
update_suffix("dB")
79-
min = -80
77+
min_value = -80
8078

8179
#endregion
8280

@@ -160,19 +158,22 @@ func _on_value_text_submitted(new_text: String, no_signal:= false) -> void:
160158
if new_text.is_empty() and not allow_string:
161159
new_text = "0.0"
162160
if new_text.is_valid_float():
163-
var temp: float = min(max(new_text.to_float(), min), max)
164-
if !enforce_step:
161+
var temp: float = min(max(new_text.to_float(), min_value), max_value)
162+
if not enforce_step:
165163
value = temp
166164
else:
167165
value = snapped(temp, step)
168166
elif allow_string:
169167
value = new_text
170-
%Value.text = str(value).pad_decimals(len(str(float(step)-floorf(step)))-2)
168+
%Value.text = str(value).pad_decimals(
169+
max(
170+
len(str(float(step)-floorf(step)))-2,
171+
len(str(float(value)-floorf(value)))-2,))
171172
if not no_signal:
172173
value_changed.emit(property_name, value)
173174
# Visually disable Up or Down arrow when limit is reached to better indicate a limit has been hit
174-
%Spin/Decrement.disabled = value <= min
175-
%Spin/Increment.disabled = value >= max
175+
%Spin/Decrement.disabled = value <= min_value
176+
%Spin/Increment.disabled = value >= max_value
176177

177178

178179
# If prefix or suffix was clicked, select the actual value box instead and move the caret to the closest side.

addons/dialogic/Editor/Events/Fields/field_number.tscn

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ border_color = Color(0, 0, 0, 0)
3434
anchors_preset = 15
3535
anchor_right = 1.0
3636
anchor_bottom = 1.0
37-
offset_right = -1102.0
37+
offset_right = -1011.0
3838
offset_bottom = -617.0
3939
grow_horizontal = 2
4040
grow_vertical = 2
4141
theme_override_constants/separation = 0
4242
script = ExtResource("1_0jdnn")
43-
mode = null
43+
min_value = 0.0
44+
max_value = null
4445

4546
[node name="Value_Panel" type="PanelContainer" parent="."]
4647
layout_mode = 2
48+
size_flags_horizontal = 3
4749
theme_type_variation = &"DialogicEventEdit"
4850

4951
[node name="Layout" type="HBoxContainer" parent="Value_Panel"]
@@ -61,8 +63,8 @@ size_flags_vertical = 4
6163
mouse_filter = 1
6264
mouse_default_cursor_shape = 1
6365
theme_override_colors/default_color = Color(0.54099, 0.540991, 0.54099, 1)
64-
theme_override_styles/focus = SubResource("StyleBoxEmpty_sj3oj")
6566
theme_override_styles/normal = SubResource("StyleBoxEmpty_sj3oj")
67+
theme_override_styles/focus = SubResource("StyleBoxEmpty_sj3oj")
6668
bbcode_enabled = true
6769
fit_content = true
6870
scroll_active = false
@@ -78,11 +80,10 @@ layout_mode = 2
7880
size_flags_horizontal = 3
7981
focus_mode = 1
8082
theme_override_constants/minimum_character_width = 0
81-
theme_override_styles/focus = SubResource("StyleBoxEmpty_8yqsu")
82-
theme_override_styles/read_only = SubResource("StyleBoxEmpty_8yqsu")
8383
theme_override_styles/normal = SubResource("StyleBoxEmpty_8yqsu")
84+
theme_override_styles/read_only = SubResource("StyleBoxEmpty_8yqsu")
85+
theme_override_styles/focus = SubResource("StyleBoxEmpty_8yqsu")
8486
text = "0"
85-
alignment = 1
8687
expand_to_text_length = true
8788
virtual_keyboard_type = 3
8889

@@ -96,8 +97,8 @@ size_flags_horizontal = 8
9697
size_flags_vertical = 4
9798
mouse_default_cursor_shape = 1
9899
theme_override_colors/default_color = Color(0.435192, 0.435192, 0.435192, 1)
99-
theme_override_styles/focus = SubResource("StyleBoxEmpty_smq50")
100100
theme_override_styles/normal = SubResource("StyleBoxEmpty_smq50")
101+
theme_override_styles/focus = SubResource("StyleBoxEmpty_smq50")
101102
bbcode_enabled = true
102103
fit_content = true
103104
scroll_active = false
@@ -122,11 +123,11 @@ focus_neighbor_top = NodePath(".")
122123
focus_neighbor_bottom = NodePath("../Decrement")
123124
theme_override_colors/icon_focus_color = Color(0.412738, 0.550094, 0.760917, 1)
124125
theme_override_colors/icon_hover_color = Color(0.412738, 0.550094, 0.760917, 1)
125-
theme_override_styles/focus = SubResource("StyleBoxFlat_increment")
126-
theme_override_styles/disabled = SubResource("StyleBoxFlat_increment")
127-
theme_override_styles/hover = SubResource("StyleBoxFlat_increment")
128-
theme_override_styles/pressed = SubResource("StyleBoxFlat_increment")
129126
theme_override_styles/normal = SubResource("StyleBoxFlat_increment")
127+
theme_override_styles/pressed = SubResource("StyleBoxFlat_increment")
128+
theme_override_styles/hover = SubResource("StyleBoxFlat_increment")
129+
theme_override_styles/disabled = SubResource("StyleBoxFlat_increment")
130+
theme_override_styles/focus = SubResource("StyleBoxFlat_increment")
130131
icon = ExtResource("3_v5cne")
131132
flat = true
132133
vertical_icon_alignment = 2
@@ -140,11 +141,11 @@ focus_neighbor_top = NodePath("../Increment")
140141
focus_neighbor_bottom = NodePath(".")
141142
theme_override_colors/icon_focus_color = Color(0.412738, 0.550094, 0.760917, 1)
142143
theme_override_colors/icon_hover_color = Color(0.412738, 0.550094, 0.760917, 1)
143-
theme_override_styles/focus = SubResource("StyleBoxFlat_decrement")
144-
theme_override_styles/disabled = SubResource("StyleBoxFlat_decrement")
145-
theme_override_styles/hover = SubResource("StyleBoxFlat_decrement")
146-
theme_override_styles/pressed = SubResource("StyleBoxFlat_decrement")
147144
theme_override_styles/normal = SubResource("StyleBoxFlat_decrement")
145+
theme_override_styles/pressed = SubResource("StyleBoxFlat_decrement")
146+
theme_override_styles/hover = SubResource("StyleBoxFlat_decrement")
147+
theme_override_styles/disabled = SubResource("StyleBoxFlat_decrement")
148+
theme_override_styles/focus = SubResource("StyleBoxFlat_decrement")
148149
icon = ExtResource("4_ph52o")
149150
flat = true
150151
vertical_icon_alignment = 2

addons/dialogic/Editor/Events/Fields/field_text_multiline.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func _autofocus() -> void:
3131
#region SIGNAL METHODS
3232
################################################################################
3333

34-
func _on_text_changed(value := "") -> void:
34+
func _on_text_changed(_value := "") -> void:
3535
value_changed.emit(property_name, self.text)
3636

3737
#endregion

addons/dialogic/Editor/Events/Fields/field_vector2.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ func _on_sub_value_changed(sub_component: String, value: float) -> void:
2424
func _update_sub_component_text(value: Variant) -> void:
2525
$X._on_value_text_submitted(str(value.x), true)
2626
$Y._on_value_text_submitted(str(value.y), true)
27+
28+
29+
func _on_step_changed(new_step:float) -> void:
30+
$X.step = new_step
31+
$Y.step = new_step

addons/dialogic/Editor/Events/Fields/field_vector2.tscn

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ script = ExtResource("1_v6lp0")
1616

1717
[node name="X" parent="." instance=ExtResource("2_a0b6y")]
1818
layout_mode = 2
19-
mode = 0
20-
step = 0.001
19+
size_flags_horizontal = 3
2120
enforce_step = false
2221
min = -9999.0
2322
max = 9999.0
23+
prefix = "x"
2424

2525
[node name="Y" parent="." instance=ExtResource("2_a0b6y")]
2626
layout_mode = 2
27-
mode = 0
28-
step = 0.001
27+
size_flags_horizontal = 3
2928
enforce_step = false
3029
min = -9999.0
3130
max = 9999.0
31+
prefix = "y"

addons/dialogic/Editor/Events/Fields/field_vector3.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ func _update_sub_component_text(value: Variant) -> void:
2626
$X._on_value_text_submitted(str(value.x), true)
2727
$Y._on_value_text_submitted(str(value.y), true)
2828
$Z._on_value_text_submitted(str(value.z), true)
29+
30+
31+
func _on_step_changed(new_step:float) -> void:
32+
$X.step = new_step
33+
$Y.step = new_step
34+
$Z.step = new_step

addons/dialogic/Editor/Events/Fields/field_vector3.tscn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ script = ExtResource("2_gktf1")
1010

1111
[node name="Z" parent="." index="2" instance=ExtResource("3_k0u0p")]
1212
layout_mode = 2
13-
step = 0.001
13+
size_flags_horizontal = 3
14+
enforce_step = false
1415
min = -9999.0
1516
max = 9999.0
16-
affix = "z:"
17+
prefix = "z"

addons/dialogic/Editor/Events/Fields/field_vector4.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ func _update_sub_component_text(value: Variant) -> void:
2828
$Y._on_value_text_submitted(str(value.y), true)
2929
$Z._on_value_text_submitted(str(value.z), true)
3030
$W._on_value_text_submitted(str(value.w), true)
31+
32+
33+
func _on_step_changed(new_step:float) -> void:
34+
$X.step = new_step
35+
$Y.step = new_step
36+
$Z.step = new_step
37+
$W.step = new_step

addons/dialogic/Editor/Events/Fields/field_vector4.tscn

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88
offset_right = -908.0
99
script = ExtResource("2_yksrc")
1010

11+
[node name="X" parent="." index="0"]
12+
size_flags_horizontal = 1
13+
prefix = ""
14+
15+
[node name="Y" parent="." index="1"]
16+
size_flags_horizontal = 1
17+
prefix = ""
18+
1119
[node name="W" parent="." index="3" instance=ExtResource("3_1jogk")]
1220
layout_mode = 2
13-
step = 0.001
21+
size_flags_horizontal = 3
22+
enforce_step = false
1423
min = -9999.0
1524
max = 9999.0
16-
affix = "w:"
25+
prefix = "w"

0 commit comments

Comments
 (0)