Skip to content

Commit

Permalink
Improve min and max of number fields in visual editor (#2318)
Browse files Browse the repository at this point in the history
The number field now defaults to min max of -INF and INF.
A few events now specify a min (mainly animation lengths).

This allows giving any numers in conditions and in the Set Variable event, which is quite nice.
  • Loading branch information
Jowan-Spooner authored Jun 28, 2024
1 parent b5271df commit eae9f2f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
8 changes: 4 additions & 4 deletions addons/dialogic/Editor/Events/Fields/field_condition.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[ext_resource type="PackedScene" uid="uid://dm5hxmhyyxgq" path="res://addons/dialogic/Editor/Events/Fields/field_bool_check.tscn" id="5_1x02a"]
[ext_resource type="PackedScene" uid="uid://dpwhshre1n4t6" path="res://addons/dialogic/Editor/Events/Fields/field_options_dynamic.tscn" id="6_5a2xd"]

[sub_resource type="Image" id="Image_cgfp5"]
[sub_resource type="Image" id="Image_je1w7"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
Expand All @@ -16,8 +16,8 @@ data = {
"width": 16
}

[sub_resource type="ImageTexture" id="ImageTexture_4jujf"]
image = SubResource("Image_cgfp5")
[sub_resource type="ImageTexture" id="ImageTexture_81s3d"]
image = SubResource("Image_je1w7")

[node name="Field_Condition" type="HBoxContainer"]
offset_right = 77.0
Expand Down Expand Up @@ -94,7 +94,7 @@ unique_name_in_owner = true
layout_mode = 2
tooltip_text = "Use complex expression"
toggle_mode = true
icon = SubResource("ImageTexture_4jujf")
icon = SubResource("ImageTexture_81s3d")

[connection signal="value_changed" from="SimpleEditor/Value1Variable" to="." method="_on_value_1_variable_value_changed"]
[connection signal="text_changed" from="ComplexEditor" to="." method="_on_complex_editor_text_changed"]
Expand Down
9 changes: 5 additions & 4 deletions addons/dialogic/Editor/Events/Fields/field_number.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ extends DialogicVisualEditorField

## Event block field for integers and floats. Improved version of the native spinbox.

@export var allow_string : bool = false
@export var allow_string: bool = false
@export var step: float = 0.1
@export var enforce_step: bool = true
@export var min: float = 0
@export var max: float= 999
@export var min: float = -INF
@export var max: float = INF
@export var value = 0.0
@export var prefix: String = ""
@export var suffix: String = ""
Expand All @@ -24,7 +24,6 @@ func _ready() -> void:

update_prefix(prefix)
update_suffix(suffix)
$Value_Panel.add_theme_stylebox_override('panel', get_theme_stylebox('panel', 'DialogicEventEdit'))


func _load_display_info(info: Dictionary) -> void:
Expand Down Expand Up @@ -157,6 +156,8 @@ func _on_decrement_button_down(button: NodePath) -> void:


func _on_value_text_submitted(new_text: String, no_signal:= false) -> void:
if new_text.is_empty() and not allow_string:
new_text = "0.0"
if new_text.is_valid_float():
var temp: float = min(max(new_text.to_float(), min), max)
if !enforce_step:
Expand Down
33 changes: 10 additions & 23 deletions addons/dialogic/Editor/Events/Fields/field_number.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 0
script = ExtResource("1_0jdnn")
prefix = null

[node name="Value_Panel" type="PanelContainer" parent="."]
layout_mode = 2
theme_type_variation = &"DialogicEventEdit"

[node name="Layout" type="HBoxContainer" parent="Value_Panel"]
layout_mode = 2
Expand Down Expand Up @@ -106,26 +106,17 @@ shortcut_keys_enabled = false
drag_and_drop_selection_enabled = false
text_direction = 1

[node name="HBoxContainer" type="HBoxContainer" parent="Value_Panel/Layout"]
layout_mode = 2
theme_override_constants/separation = 0

[node name="Spacer" type="MarginContainer" parent="Value_Panel/Layout/HBoxContainer"]
layout_mode = 2
mouse_filter = 2
theme_override_constants/margin_right = 1

[node name="Spin" type="VBoxContainer" parent="Value_Panel/Layout/HBoxContainer"]
[node name="Spin" type="VBoxContainer" parent="Value_Panel/Layout"]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/separation = 0
alignment = 1

[node name="Increment" type="Button" parent="Value_Panel/Layout/HBoxContainer/Spin"]
[node name="Increment" type="Button" parent="Value_Panel/Layout/Spin"]
layout_mode = 2
size_flags_vertical = 3
auto_translate = false
focus_neighbor_left = NodePath("../../../Value")
focus_neighbor_left = NodePath("../../Value")
focus_neighbor_top = NodePath(".")
focus_neighbor_bottom = NodePath("../Decrement")
theme_override_colors/icon_hover_color = Color(0.412738, 0.550094, 0.760917, 1)
Expand All @@ -139,11 +130,11 @@ icon = ExtResource("3_v5cne")
flat = true
vertical_icon_alignment = 2

[node name="Decrement" type="Button" parent="Value_Panel/Layout/HBoxContainer/Spin"]
[node name="Decrement" type="Button" parent="Value_Panel/Layout/Spin"]
layout_mode = 2
size_flags_vertical = 3
auto_translate = false
focus_neighbor_left = NodePath("../../../Value")
focus_neighbor_left = NodePath("../../Value")
focus_neighbor_top = NodePath("../Increment")
focus_neighbor_bottom = NodePath(".")
theme_override_colors/icon_hover_color = Color(0.412738, 0.550094, 0.760917, 1)
Expand All @@ -157,17 +148,13 @@ icon = ExtResource("4_ph52o")
flat = true
vertical_icon_alignment = 2

[node name="Spacer" type="Control" parent="."]
custom_minimum_size = Vector2(3, 0)
layout_mode = 2

[connection signal="gui_input" from="Value_Panel/Layout/Prefix" to="." method="_on_sublabel_clicked"]
[connection signal="focus_entered" from="Value_Panel/Layout/Value" to="." method="_on_value_focus_entered"]
[connection signal="focus_exited" from="Value_Panel/Layout/Value" to="." method="_on_value_focus_exited"]
[connection signal="gui_input" from="Value_Panel/Layout/Value" to="." method="_on_gui_input"]
[connection signal="text_submitted" from="Value_Panel/Layout/Value" to="." method="_on_value_text_submitted"]
[connection signal="gui_input" from="Value_Panel/Layout/Suffix" to="." method="_on_sublabel_clicked"]
[connection signal="button_down" from="Value_Panel/Layout/HBoxContainer/Spin/Increment" to="." method="_on_increment_button_down" binds= [NodePath("%Spin/Increment")]]
[connection signal="gui_input" from="Value_Panel/Layout/HBoxContainer/Spin/Increment" to="." method="_on_gui_input"]
[connection signal="button_down" from="Value_Panel/Layout/HBoxContainer/Spin/Decrement" to="." method="_on_decrement_button_down" binds= [NodePath("%Spin/Decrement")]]
[connection signal="gui_input" from="Value_Panel/Layout/HBoxContainer/Spin/Decrement" to="." method="_on_gui_input"]
[connection signal="button_down" from="Value_Panel/Layout/Spin/Increment" to="." method="_on_increment_button_down" binds= [NodePath("%Spin/Increment")]]
[connection signal="gui_input" from="Value_Panel/Layout/Spin/Increment" to="." method="_on_gui_input"]
[connection signal="button_down" from="Value_Panel/Layout/Spin/Decrement" to="." method="_on_decrement_button_down" binds= [NodePath("%Spin/Decrement")]]
[connection signal="gui_input" from="Value_Panel/Layout/Spin/Decrement" to="." method="_on_gui_input"]
8 changes: 4 additions & 4 deletions addons/dialogic/Modules/Character/event_character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func build_event_editor() -> void:
'placeholder' : 'Default',
'enable_pretty_name' : true},
'should_show_fade_options()')
add_body_edit('fade_length', ValueType.NUMBER, {'left_text':'Length:', 'suffix':'s'},
add_body_edit('fade_length', ValueType.NUMBER, {'left_text':'Length:', 'suffix':'s', "min":0},
'should_show_fade_options() and !fade_animation.is_empty()')
add_body_line_break("should_show_fade_options()")
add_body_edit('animation_name', ValueType.DYNAMIC_OPTIONS,
Expand All @@ -393,14 +393,14 @@ func build_event_editor() -> void:
'placeholder' : 'Default',
'enable_pretty_name' : true},
'should_show_animation_options()')
add_body_edit('animation_length', ValueType.NUMBER, {'left_text':'Length:', 'suffix':'s'},
add_body_edit('animation_length', ValueType.NUMBER, {'left_text':'Length:', 'suffix':'s', "min":0},
'should_show_animation_options() and !animation_name.is_empty()')
add_body_edit('animation_wait', ValueType.BOOL, {'left_text':'Await end:'},
'should_show_animation_options() and !animation_name.is_empty()')
add_body_edit('animation_repeats', ValueType.NUMBER, {'left_text':'Repeat:', 'mode':1},
add_body_edit('animation_repeats', ValueType.NUMBER, {'left_text':'Repeat:', 'mode':1, "min":1},
'should_show_animation_options() and !animation_name.is_empty() and action == %s)' %Actions.UPDATE)
add_body_line_break()
add_body_edit('transform_time', ValueType.NUMBER, {'left_text':'Movement duration:'},
add_body_edit('transform_time', ValueType.NUMBER, {'left_text':'Movement duration:', "min":0},
"should_show_transform_options()")
add_body_edit("transform_trans", ValueType.FIXED_OPTIONS, {'options':trans_options, 'left_text':"Trans:"}, 'should_show_transform_options() and transform_time > 0')
add_body_edit("transform_ease", ValueType.FIXED_OPTIONS, {'options':ease_options, 'left_text':"Ease:"}, 'should_show_transform_options() and transform_time > 0')
Expand Down
2 changes: 1 addition & 1 deletion addons/dialogic/Modules/Wait/event_wait.gd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func get_shortcode_parameters() -> Dictionary:
################################################################################

func build_event_editor() -> void:
add_header_edit('time', ValueType.NUMBER, {'left_text':'Wait', 'autofocus':true, 'min':0})
add_header_edit('time', ValueType.NUMBER, {'left_text':'Wait', 'autofocus':true, 'min':0.1})
add_header_label('seconds', 'time != 1')
add_header_label('second', 'time == 1')
add_body_edit('hide_text', ValueType.BOOL, {'left_text':'Hide text box:'})

0 comments on commit eae9f2f

Please sign in to comment.