[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix character event update mode behaviour (#1686)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Jowan-Spooner authored Aug 24, 2023
1 parent d76cf79 commit d910b35
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 61 deletions.
11 changes: 9 additions & 2 deletions addons/dialogic/Editor/Events/EventBlock/event_block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,15 @@ func build_editor(build_header:bool = true, build_body:bool = false) -> void:
editor_node = load("res://addons/dialogic/Editor/Events/Fields/SinglelineText.tscn").instantiate()
editor_node.placeholder = p.display_info.get('placeholder', '')
elif p.dialogic_type == resource.ValueType.BOOL:
editor_node = load("res://addons/dialogic/Editor/Events/Fields/Bool.tscn").instantiate()

if p.display_info.has('icon') or p.display_info.has('editor_icon'):
editor_node = load("res://addons/dialogic/Editor/Events/Fields/BoolButton.tscn").instantiate()
if p.display_info.has('editor_icon'):
editor_node.icon = callv('get_theme_icon', p.display_info.editor_icon)
else:
editor_node.icon = p.display_info.get('icon', null)
else:
editor_node = load("res://addons/dialogic/Editor/Events/Fields/Bool.tscn").instantiate()
editor_node.tooltip_text = p.display_info.get('tooltip', "")
elif p.dialogic_type == resource.ValueType.FILE:
editor_node = load("res://addons/dialogic/Editor/Events/Fields/FilePicker.tscn").instantiate()
editor_node.file_filter = p.display_info.get('file_filter', '')
Expand Down
2 changes: 2 additions & 0 deletions addons/dialogic/Editor/Events/Fields/Bool.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/Bool.gd" id="1"]

[node name="Bool" type="CheckButton"]
offset_right = 44.0
offset_bottom = 24.0
script = ExtResource("1")
19 changes: 19 additions & 0 deletions addons/dialogic/Editor/Events/Fields/BoolButton.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@tool
extends Button

## Event block field for boolean values.

signal value_changed
var property_name : String


func _ready() -> void:
toggled.connect(_on_value_changed)


func set_value(value:bool) -> void:
button_pressed = value


func _on_value_changed(value:bool) -> void:
value_changed.emit(property_name, value)
8 changes: 8 additions & 0 deletions addons/dialogic/Editor/Events/Fields/BoolButton.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://iypxcctv080u"]

[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/Fields/BoolButton.gd" id="1_5iob7"]

[node name="Bool" type="Button"]
toggle_mode = true
flat = true
script = ExtResource("1_5iob7")
9 changes: 7 additions & 2 deletions addons/dialogic/Editor/Images/Resources/portrait.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions addons/dialogic/Editor/Images/Resources/portrait.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ type="CompressedTexture2D"
uid="uid://dfi7fhfc4dbc3"
path="res://.godot/imported/portrait.svg-7d29c7cfe3e086d65dce33c3d66c48cd.ctex"
metadata={
"editor_dark_theme": true,
"editor_scale": 1.0,
"has_editor_variant": true,
"vram_texture": false
}
Expand Down
126 changes: 71 additions & 55 deletions addons/dialogic/Modules/Character/event_character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ var extra_data: String = ""

### Helpers

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

dialogic.Portraits.change_character_portrait(character, portrait, false)
dialogic.Portraits.change_character_mirror(character, mirrored)
if set_portrait:
dialogic.Portraits.change_character_portrait(character, portrait, false)

if _update_zindex:
if set_mirrored:
dialogic.Portraits.change_character_mirror(character, mirrored)

if set_z_index:
dialogic.Portraits.change_character_z_index(character, z_index)

if position != 0:
if set_position:
dialogic.Portraits.move_character(character, position, position_move_time)

if animation_name:
Expand Down Expand Up @@ -157,38 +163,41 @@ func to_text() -> String:
if name.count(" ") > 0:
name = '"' + name + '"'
result_string += name
if portrait.strip_edges() != default_values.get('portrait', '') and action != Actions.LEAVE:
if portrait.strip_edges() != default_values.get('portrait', '') and action != Actions.LEAVE and (action != Actions.UPDATE or set_portrait):
result_string+= " ("+portrait+")"

if action != Actions.LEAVE:
if action != Actions.LEAVE and (action != Actions.UPDATE or set_position):
result_string += " "+str(position)

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', ""):
result_string += " ["
if animation_name:
result_string += 'animation="'+DialogicUtil.pretty_name(animation_name)+'"'
var shortcode := "["
if animation_name:
shortcode += 'animation="'+DialogicUtil.pretty_name(animation_name)+'"'

if animation_length != default_values.get('animation_length', 0.5):
shortcode += ' length="'+str(animation_length)+'"'

if animation_length != 0.5:
result_string += ' length="'+str(animation_length)+'"'

if animation_wait:
result_string += ' wait="'+str(animation_wait)+'"'

if animation_repeats != 1:
result_string += ' repeat="'+str(animation_repeats)+'"'
if z_index != 0:
result_string += ' z_index="' + str(z_index) + '"'
if animation_wait != default_values.get('animation_wait', false):
shortcode += ' wait="'+str(animation_wait)+'"'

if mirrored:
result_string += ' mirrored="' + str(mirrored) + '"'
if position_move_time != 0:
result_string += ' move_time="' + str(position_move_time) + '"'
if animation_repeats != default_values.get('animation_repeats', 1) and action == Actions.UPDATE:
shortcode += ' repeat="'+str(animation_repeats)+'"'

if z_index != default_values.get('z_index', 0) or (action == Actions.UPDATE and set_z_index):
shortcode += ' z_index="' + str(z_index) + '"'

if extra_data != "":
result_string += ' extra_data="' + extra_data + '"'

result_string += "]"
if mirrored != default_values.get('mirrored', false) or (action == Actions.UPDATE and set_mirrored):
shortcode += ' mirrored="' + str(mirrored) + '"'

if position_move_time != default_values.get('position_move_time', 0) and action == Actions.UPDATE and set_position:
shortcode += ' move_time="' + str(position_move_time) + '"'

if extra_data != "":
shortcode += ' extra_data="' + extra_data + '"'

shortcode += "]"

if shortcode != "[]":
result_string += " "+shortcode
return result_string


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



var result := regex.search(string)

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

if !result.get_string('portrait').is_empty():
portrait = result.get_string('portrait').strip_edges().trim_prefix('(').trim_suffix(')')
set_portrait = true

if result.get_string('position'):
position = result.get_string('position').to_int()
elif action == Actions.UPDATE:
# Override the normal default if it's an Update
position = 0
position = int(result.get_string('position'))
set_position = true

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

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

#repeat is supported on Update, the other two should not be checking this
#repeat is supported on Update, the other two should not be checking this
if action == Actions.UPDATE:
animation_repeats = int(shortcode_params.get('repeat', 1))
position_move_time = shortcode_params.get('move_time', 0.0)
animation_repeats = int(shortcode_params.get('repeat', animation_repeats))
position_move_time = shortcode_params.get('move_time', position_move_time)
#move time is only supported on Update, but it isnt part of the animations so its separate
if action == Actions.UPDATE:
if typeof(shortcode_params.get('move_time', 0)) == TYPE_STRING:
position_move_time = shortcode_params.get('move_time', 0.0).to_float()
position_move_time = float(shortcode_params.get('move_time', position_move_time))

z_index = int(shortcode_params.get('z_index', z_index))
set_z_index = shortcode_params.has('z_index')

if typeof(shortcode_params.get('z_index', 0)) == TYPE_STRING:
z_index = shortcode_params.get('z_index', 0).to_int()
_update_zindex = true
mirrored = DialogicUtil.str_to_bool(shortcode_params.get('mirrored', 'false'))
mirrored = DialogicUtil.str_to_bool(shortcode_params.get('mirrored', str(mirrored)))
set_mirrored = shortcode_params.has('mirrored')
extra_data = shortcode_params.get('extra_data', "")


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

# "animation_name" : {"property": "animation_name", "default": ""},
# "animation_length" : {"property": "animation_length", "default": 0.5},
# "animation_wait" : {"property": "animation_wait", "default": false},
"animation_length" : {"property": "animation_length", "default": 0.5},
"animation_wait" : {"property": "animation_wait", "default": false},
"animation_repeats" : {"property": "animation_repeats", "default": 1},

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

add_header_edit('set_portrait', ValueType.BOOL, '', '',
{'icon':load("res://addons/dialogic/Modules/Character/update_portrait.svg"),
'tooltip':'Change Portrait'}, "action == Actions.UPDATE")
add_header_edit('portrait', ValueType.COMPLEX_PICKER, '', '',
{'placeholder' : 'Default',
'collapse_when_empty':true,
'suggestions_func' : get_portrait_suggestions,
'icon' : load("res://addons/dialogic/Editor/Images/Resources/portrait.svg")},
'should_show_portrait_selector()')
add_header_edit('position', ValueType.INTEGER, ' at position', '', {},
'character != null and !has_no_portraits() and action != %s' %Actions.LEAVE)
add_header_edit('set_position', ValueType.BOOL, '', '',
{'icon': load("res://addons/dialogic/Modules/Character/update_position.svg"), 'tooltip':'Change Position'}, "action == Actions.UPDATE")
add_header_label('at position', 'character != null and !has_no_portraits() and action == Actions.JOIN')
add_header_label('to position', 'character != null and !has_no_portraits() and action == Actions.UPDATE and set_position')
add_header_edit('position', ValueType.INTEGER, '', '', {},
'character != null and !has_no_portraits() and action != %s and (action != Actions.UPDATE or set_position)' %Actions.LEAVE)

# Body
add_body_edit('animation_name', ValueType.COMPLEX_PICKER, 'Animation:', '',
Expand All @@ -374,19 +387,22 @@ func build_event_editor() -> void:
'should_show_animation_options() and !animation_name.is_empty()')
add_body_edit('animation_repeats', ValueType.INTEGER, 'Repeat:', '', {},
'should_show_animation_options() and !animation_name.is_empty() and action == %s)' %Actions.UPDATE)
add_body_line_break()
add_body_edit('position_move_time', ValueType.FLOAT, 'Movement duration:', '', {},
'action == %s and set_position' %Actions.UPDATE)
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")
add_body_edit('z_index', ValueType.INTEGER, 'Z-index:', "",{},
'action != %s' %Actions.LEAVE)
'action != %s and (action != Actions.UPDATE or set_z_index)' %Actions.LEAVE)
add_body_edit('set_mirrored', ValueType.BOOL, '', '', {'icon':load("res://addons/dialogic/Modules/Character/update_mirror.svg"), 'tooltip':'Change Mirroring'}, "action == Actions.UPDATE")
add_body_edit('mirrored', ValueType.BOOL, 'Mirrored:', "",{},
'action != %s' %Actions.LEAVE)
add_body_edit('position_move_time', ValueType.FLOAT, 'Movement duration:', '', {},
'action == %s' %Actions.UPDATE)
'action != %s and (action != Actions.UPDATE or set_mirrored)' %Actions.LEAVE)


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

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

func has_no_portraits() -> bool:
return character and character.portraits.is_empty()
Expand Down
Loading

0 comments on commit d910b35

Please sign in to comment.