Skip to content

Commit d910b35

Browse files
Fix character event update mode behaviour (#1686)
* Fix character event update mode behaviour The functionality works great now, it's just UI that's pretty messy now. Hope I can get some help with that. * Update icons to be somewhat better * Fix some charatcer event default stuff
1 parent d76cf79 commit d910b35

File tree

15 files changed

+323
-61
lines changed

15 files changed

+323
-61
lines changed

addons/dialogic/Editor/Events/EventBlock/event_block.gd

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,15 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void:
174174
editor_node = load("res://addons/dialogic/Editor/Events/Fields/SinglelineText.tscn").instantiate()
175175
editor_node.placeholder = p.display_info.get('placeholder', '')
176176
elif p.dialogic_type == resource.ValueType.BOOL:
177-
editor_node = load("res://addons/dialogic/Editor/Events/Fields/Bool.tscn").instantiate()
178-
177+
if p.display_info.has('icon') or p.display_info.has('editor_icon'):
178+
editor_node = load("res://addons/dialogic/Editor/Events/Fields/BoolButton.tscn").instantiate()
179+
if p.display_info.has('editor_icon'):
180+
editor_node.icon = callv('get_theme_icon', p.display_info.editor_icon)
181+
else:
182+
editor_node.icon = p.display_info.get('icon', null)
183+
else:
184+
editor_node = load("res://addons/dialogic/Editor/Events/Fields/Bool.tscn").instantiate()
185+
editor_node.tooltip_text = p.display_info.get('tooltip', "")
179186
elif p.dialogic_type == resource.ValueType.FILE:
180187
editor_node = load("res://addons/dialogic/Editor/Events/Fields/FilePicker.tscn").instantiate()
181188
editor_node.file_filter = p.display_info.get('file_filter', '')

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/Bool.gd" id="1"]
44

55
[node name="Bool" type="CheckButton"]
6+
offset_right = 44.0
7+
offset_bottom = 24.0
68
script = ExtResource("1")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@tool
2+
extends Button
3+
4+
## Event block field for boolean values.
5+
6+
signal value_changed
7+
var property_name : String
8+
9+
10+
func _ready() -> void:
11+
toggled.connect(_on_value_changed)
12+
13+
14+
func set_value(value:bool) -> void:
15+
button_pressed = value
16+
17+
18+
func _on_value_changed(value:bool) -> void:
19+
value_changed.emit(property_name, value)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://iypxcctv080u"]
2+
3+
[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/BoolButton.gd" id="1_5iob7"]
4+
5+
[node name="Bool" type="Button"]
6+
toggle_mode = true
7+
flat = true
8+
script = ExtResource("1_5iob7")
Lines changed: 7 additions & 2 deletions
Loading

addons/dialogic/Editor/Images/Resources/portrait.svg.import

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ type="CompressedTexture2D"
55
uid="uid://dfi7fhfc4dbc3"
66
path="res://.godot/imported/portrait.svg-7d29c7cfe3e086d65dce33c3d66c48cd.ctex"
77
metadata={
8-
"editor_dark_theme": true,
9-
"editor_scale": 1.0,
108
"has_editor_variant": true,
119
"vram_texture": false
1210
}

addons/dialogic/Modules/Character/event_character.gd

Lines changed: 71 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ var extra_data: String = ""
4141

4242
### Helpers
4343

44-
## Indicates if the z_index should be updated.
45-
var _update_zindex: bool = false
44+
## Indicators for whether something should be updated (UPDATE mode only)
45+
var set_portrait := false
46+
var set_position := false
47+
var set_z_index := false
48+
var set_mirrored := false
4649
## Used to set the character resource from the unique name identifier and vice versa
4750
var _character_from_directory: String:
4851
get:
@@ -95,13 +98,16 @@ func _execute() -> void:
9598
finish()
9699
return
97100

98-
dialogic.Portraits.change_character_portrait(character, portrait, false)
99-
dialogic.Portraits.change_character_mirror(character, mirrored)
101+
if set_portrait:
102+
dialogic.Portraits.change_character_portrait(character, portrait, false)
100103

101-
if _update_zindex:
104+
if set_mirrored:
105+
dialogic.Portraits.change_character_mirror(character, mirrored)
106+
107+
if set_z_index:
102108
dialogic.Portraits.change_character_z_index(character, z_index)
103109

104-
if position != 0:
110+
if set_position:
105111
dialogic.Portraits.move_character(character, position, position_move_time)
106112

107113
if animation_name:
@@ -157,38 +163,41 @@ func to_text() -> String:
157163
if name.count(" ") > 0:
158164
name = '"' + name + '"'
159165
result_string += name
160-
if portrait.strip_edges() != default_values.get('portrait', '') and action != Actions.LEAVE:
166+
if portrait.strip_edges() != default_values.get('portrait', '') and action != Actions.LEAVE and (action != Actions.UPDATE or set_portrait):
161167
result_string+= " ("+portrait+")"
162168

163-
if action != Actions.LEAVE:
169+
if action != Actions.LEAVE and (action != Actions.UPDATE or set_position):
164170
result_string += " "+str(position)
165171

166-
if animation_name != "" or z_index != default_values.get('z_index', 0) or mirrored != default_values.get('mirrored', false) or position_move_time != default_values.get('position_move_time', 0) or extra_data != default_values.get('extra_data', ""):
167-
result_string += " ["
168-
if animation_name:
169-
result_string += 'animation="'+DialogicUtil.pretty_name(animation_name)+'"'
172+
var shortcode := "["
173+
if animation_name:
174+
shortcode += 'animation="'+DialogicUtil.pretty_name(animation_name)+'"'
175+
176+
if animation_length != default_values.get('animation_length', 0.5):
177+
shortcode += ' length="'+str(animation_length)+'"'
170178

171-
if animation_length != 0.5:
172-
result_string += ' length="'+str(animation_length)+'"'
173-
174-
if animation_wait:
175-
result_string += ' wait="'+str(animation_wait)+'"'
176-
177-
if animation_repeats != 1:
178-
result_string += ' repeat="'+str(animation_repeats)+'"'
179-
if z_index != 0:
180-
result_string += ' z_index="' + str(z_index) + '"'
179+
if animation_wait != default_values.get('animation_wait', false):
180+
shortcode += ' wait="'+str(animation_wait)+'"'
181181

182-
if mirrored:
183-
result_string += ' mirrored="' + str(mirrored) + '"'
184-
185-
if position_move_time != 0:
186-
result_string += ' move_time="' + str(position_move_time) + '"'
182+
if animation_repeats != default_values.get('animation_repeats', 1) and action == Actions.UPDATE:
183+
shortcode += ' repeat="'+str(animation_repeats)+'"'
184+
185+
if z_index != default_values.get('z_index', 0) or (action == Actions.UPDATE and set_z_index):
186+
shortcode += ' z_index="' + str(z_index) + '"'
187187

188-
if extra_data != "":
189-
result_string += ' extra_data="' + extra_data + '"'
190-
191-
result_string += "]"
188+
if mirrored != default_values.get('mirrored', false) or (action == Actions.UPDATE and set_mirrored):
189+
shortcode += ' mirrored="' + str(mirrored) + '"'
190+
191+
if position_move_time != default_values.get('position_move_time', 0) and action == Actions.UPDATE and set_position:
192+
shortcode += ' move_time="' + str(position_move_time) + '"'
193+
194+
if extra_data != "":
195+
shortcode += ' extra_data="' + extra_data + '"'
196+
197+
shortcode += "]"
198+
199+
if shortcode != "[]":
200+
result_string += " "+shortcode
192201
return result_string
193202

194203

@@ -203,8 +212,6 @@ func from_text(string:String) -> void:
203212
if _character_from_directory in _character_directory.keys():
204213
character = _character_directory[_character_from_directory]['resource']
205214

206-
207-
208215
var result := regex.search(string)
209216

210217
match result.get_string('type'):
@@ -245,12 +252,11 @@ func from_text(string:String) -> void:
245252

246253
if !result.get_string('portrait').is_empty():
247254
portrait = result.get_string('portrait').strip_edges().trim_prefix('(').trim_suffix(')')
255+
set_portrait = true
248256

249257
if result.get_string('position'):
250-
position = result.get_string('position').to_int()
251-
elif action == Actions.UPDATE:
252-
# Override the normal default if it's an Update
253-
position = 0
258+
position = int(result.get_string('position'))
259+
set_position = true
254260

255261
if result.get_string('shortcode'):
256262
var shortcode_params = parse_shortcode_parameters(result.get_string('shortcode'))
@@ -270,19 +276,19 @@ func from_text(string:String) -> void:
270276

271277
animation_wait = DialogicUtil.str_to_bool(shortcode_params.get('wait', 'false'))
272278

273-
#repeat is supported on Update, the other two should not be checking this
279+
#repeat is supported on Update, the other two should not be checking this
274280
if action == Actions.UPDATE:
275-
animation_repeats = int(shortcode_params.get('repeat', 1))
276-
position_move_time = shortcode_params.get('move_time', 0.0)
281+
animation_repeats = int(shortcode_params.get('repeat', animation_repeats))
282+
position_move_time = shortcode_params.get('move_time', position_move_time)
277283
#move time is only supported on Update, but it isnt part of the animations so its separate
278284
if action == Actions.UPDATE:
279-
if typeof(shortcode_params.get('move_time', 0)) == TYPE_STRING:
280-
position_move_time = shortcode_params.get('move_time', 0.0).to_float()
285+
position_move_time = float(shortcode_params.get('move_time', position_move_time))
286+
287+
z_index = int(shortcode_params.get('z_index', z_index))
288+
set_z_index = shortcode_params.has('z_index')
281289

282-
if typeof(shortcode_params.get('z_index', 0)) == TYPE_STRING:
283-
z_index = shortcode_params.get('z_index', 0).to_int()
284-
_update_zindex = true
285-
mirrored = DialogicUtil.str_to_bool(shortcode_params.get('mirrored', 'false'))
290+
mirrored = DialogicUtil.str_to_bool(shortcode_params.get('mirrored', str(mirrored)))
291+
set_mirrored = shortcode_params.has('mirrored')
286292
extra_data = shortcode_params.get('extra_data', "")
287293

288294

@@ -303,8 +309,8 @@ func get_shortcode_parameters() -> Dictionary:
303309
"position" : {"property": "position", "default": 1},
304310

305311
# "animation_name" : {"property": "animation_name", "default": ""},
306-
# "animation_length" : {"property": "animation_length", "default": 0.5},
307-
# "animation_wait" : {"property": "animation_wait", "default": false},
312+
"animation_length" : {"property": "animation_length", "default": 0.5},
313+
"animation_wait" : {"property": "animation_wait", "default": false},
308314
"animation_repeats" : {"property": "animation_repeats", "default": 1},
309315

310316
"z_index" : {"property": "z_index", "default": 0},
@@ -352,14 +358,21 @@ func build_event_editor() -> void:
352358
'autofocus' : true})
353359
# add_header_button('', _on_character_edit_pressed, 'Edit character', ["ExternalLink", "EditorIcons"], 'character != null and _character_from_directory != "--All--"')
354360

361+
add_header_edit('set_portrait', ValueType.BOOL, '', '',
362+
{'icon':load("res://addons/dialogic/Modules/Character/update_portrait.svg"),
363+
'tooltip':'Change Portrait'}, "action == Actions.UPDATE")
355364
add_header_edit('portrait', ValueType.COMPLEX_PICKER, '', '',
356365
{'placeholder' : 'Default',
357366
'collapse_when_empty':true,
358367
'suggestions_func' : get_portrait_suggestions,
359368
'icon' : load("res://addons/dialogic/Editor/Images/Resources/portrait.svg")},
360369
'should_show_portrait_selector()')
361-
add_header_edit('position', ValueType.INTEGER, ' at position', '', {},
362-
'character != null and !has_no_portraits() and action != %s' %Actions.LEAVE)
370+
add_header_edit('set_position', ValueType.BOOL, '', '',
371+
{'icon': load("res://addons/dialogic/Modules/Character/update_position.svg"), 'tooltip':'Change Position'}, "action == Actions.UPDATE")
372+
add_header_label('at position', 'character != null and !has_no_portraits() and action == Actions.JOIN')
373+
add_header_label('to position', 'character != null and !has_no_portraits() and action == Actions.UPDATE and set_position')
374+
add_header_edit('position', ValueType.INTEGER, '', '', {},
375+
'character != null and !has_no_portraits() and action != %s and (action != Actions.UPDATE or set_position)' %Actions.LEAVE)
363376

364377
# Body
365378
add_body_edit('animation_name', ValueType.COMPLEX_PICKER, 'Animation:', '',
@@ -374,19 +387,22 @@ func build_event_editor() -> void:
374387
'should_show_animation_options() and !animation_name.is_empty()')
375388
add_body_edit('animation_repeats', ValueType.INTEGER, 'Repeat:', '', {},
376389
'should_show_animation_options() and !animation_name.is_empty() and action == %s)' %Actions.UPDATE)
390+
add_body_line_break()
391+
add_body_edit('position_move_time', ValueType.FLOAT, 'Movement duration:', '', {},
392+
'action == %s and set_position' %Actions.UPDATE)
393+
add_body_edit('set_z_index', ValueType.BOOL, '', '', {'icon':load("res://addons/dialogic/Modules/Character/update_z_index.svg"), 'tooltip':'Change Z-Index'}, "action == Actions.UPDATE")
377394
add_body_edit('z_index', ValueType.INTEGER, 'Z-index:', "",{},
378-
'action != %s' %Actions.LEAVE)
395+
'action != %s and (action != Actions.UPDATE or set_z_index)' %Actions.LEAVE)
396+
add_body_edit('set_mirrored', ValueType.BOOL, '', '', {'icon':load("res://addons/dialogic/Modules/Character/update_mirror.svg"), 'tooltip':'Change Mirroring'}, "action == Actions.UPDATE")
379397
add_body_edit('mirrored', ValueType.BOOL, 'Mirrored:', "",{},
380-
'action != %s' %Actions.LEAVE)
381-
add_body_edit('position_move_time', ValueType.FLOAT, 'Movement duration:', '', {},
382-
'action == %s' %Actions.UPDATE)
398+
'action != %s and (action != Actions.UPDATE or set_mirrored)' %Actions.LEAVE)
383399

384400

385401
func should_show_animation_options() -> bool:
386402
return (character != null and !character.portraits.is_empty()) or _character_from_directory == '--All--'
387403

388404
func should_show_portrait_selector() -> bool:
389-
return character != null and len(character.portraits) > 1 and action != Actions.LEAVE
405+
return character != null and len(character.portraits) > 1 and action != Actions.LEAVE and (action != Actions.UPDATE or set_portrait)
390406

391407
func has_no_portraits() -> bool:
392408
return character and character.portraits.is_empty()

0 commit comments

Comments
 (0)