diff --git a/addons/dialogic/Editor/Events/Fields/field_text_multiline.gd b/addons/dialogic/Editor/Events/Fields/field_text_multiline.gd index 8d9d54114..5b63d31e5 100644 --- a/addons/dialogic/Editor/Events/Fields/field_text_multiline.gd +++ b/addons/dialogic/Editor/Events/Fields/field_text_multiline.gd @@ -8,6 +8,7 @@ extends DialogicVisualEditorField var previous_width := 0 var height_recalculation_queued := false +var line_count := 0 #region MAIN METHODS ################################################################################ @@ -66,10 +67,14 @@ func queue_height_recalculation(): ## TODO Remove again once https://github.com/godotengine/godot/issues/80546 is fixed. func recalculate_height() -> void: height_recalculation_queued = false - var font :Font = get_theme_font("font") - var text_size = font.get_multiline_string_size(self.text+' ', HORIZONTAL_ALIGNMENT_LEFT, size.x, get_theme_font_size("font_size")) - custom_minimum_size.y = text_size.y+20+4*(floor(text_size.y/get_theme_font_size("font_size"))) + var font: Font = get_theme_font("font") + var text_size = font.get_multiline_string_size(self.text+' ', HORIZONTAL_ALIGNMENT_LEFT, size.x-14, get_theme_font_size("font_size")) + custom_minimum_size.y = text_size.y+20+4*(ceil(text_size.y/get_theme_font_size("font_size"))) self.scroll_vertical = 0 + if get_parent().get_child(get_index()).get_visible_line_count() != line_count: + if find_parent("VisualEditor"): + find_parent("VisualEditor").indent_events() + line_count = get_parent().get_child(get_index()).get_visible_line_count() #endregion diff --git a/addons/dialogic/Editor/TimelineEditor/TextEditor/CodeCompletionHelper.gd b/addons/dialogic/Editor/TimelineEditor/TextEditor/CodeCompletionHelper.gd index 563049025..7d3b92a2d 100644 --- a/addons/dialogic/Editor/TimelineEditor/TextEditor/CodeCompletionHelper.gd +++ b/addons/dialogic/Editor/TimelineEditor/TextEditor/CodeCompletionHelper.gd @@ -3,8 +3,8 @@ extends Node enum Modes {TEXT_EVENT_ONLY, FULL_HIGHLIGHTING} -var syntax_highlighter :SyntaxHighlighter = load("res://addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd").new() -var text_syntax_highlighter :SyntaxHighlighter = load("res://addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd").new() +var syntax_highlighter: SyntaxHighlighter = load("res://addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd").new() +var text_syntax_highlighter: SyntaxHighlighter = load("res://addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd").new() # These RegEx's are used to deduce information from the current line for auto-completion @@ -29,8 +29,7 @@ func _ready(): text_syntax_highlighter.mode = text_syntax_highlighter.Modes.TEXT_EVENT_ONLY -################################################################################ -## AUTO COMPLETION +#region AUTO COMPLETION ################################################################################ # Helper that gets the current line with a special character where the caret is @@ -65,7 +64,7 @@ func request_code_completion(force:bool, text:CodeEdit, mode:=Modes.FULL_HIGHLIG # make sure shortcode event references are loaded if mode == Modes.FULL_HIGHLIGHTING: - var hidden_events :Array= DialogicUtil.get_editor_setting('hidden_event_buttons', []) + var hidden_events: Array = DialogicUtil.get_editor_setting('hidden_event_buttons', []) if shortcode_events.is_empty(): for event in DialogicResourceUtil.get_event_cache(): if event.get_shortcode() != 'default_shortcode': @@ -103,7 +102,7 @@ func request_code_completion(force:bool, text:CodeEdit, mode:=Modes.FULL_HIGHLIG # The completion will check if the letter is already present and add it otherwise. # Shortcode event suggestions - if line.begins_with('[') and !text_event.text_effects_regex.search(line.get_slice(' ', 0)) and mode == Modes.FULL_HIGHLIGHTING: + if mode == Modes.FULL_HIGHLIGHTING and syntax_highlighter.line_is_shortcode_event(text.get_caret_line()): if symbol == '[': # suggest shortcodes if a shortcode event has just begun var shortcodes := shortcode_events.keys() @@ -116,7 +115,8 @@ func request_code_completion(force:bool, text:CodeEdit, mode:=Modes.FULL_HIGHLIG else: text.add_code_completion_option(CodeEdit.KIND_MEMBER, shortcode, shortcode+" ", shortcode_events[shortcode].event_color.lerp(syntax_highlighter.normal_color, 0.3), shortcode_events[shortcode]._get_icon()) else: - var current_shortcode := completion_shortcode_getter_regex.search(line) + var full_event_text: String = syntax_highlighter.get_full_event(text.get_caret_line()) + var current_shortcode := completion_shortcode_getter_regex.search(full_event_text) if !current_shortcode: text.update_code_completion_options(false) return @@ -128,9 +128,9 @@ func request_code_completion(force:bool, text:CodeEdit, mode:=Modes.FULL_HIGHLIG # suggest parameters if symbol == ' ' and line.count('"')%2 == 0: - var parameters :Array = shortcode_events[code].get_shortcode_parameters().keys() + var parameters: Array = shortcode_events[code].get_shortcode_parameters().keys() for param in parameters: - if !param+'=' in line: + if !param+'=' in full_event_text: text.add_code_completion_option(CodeEdit.KIND_MEMBER, param, param+'="' , shortcode_events[code].event_color.lerp(syntax_highlighter.normal_color, 0.3), text.get_theme_icon("MemberProperty", "EditorIcons")) # suggest values @@ -152,7 +152,7 @@ func request_code_completion(force:bool, text:CodeEdit, mode:=Modes.FULL_HIGHLIG text.update_code_completion_options(true) return - var suggestions : Dictionary= shortcode_events[code].get_shortcode_parameters()[current_parameter]['suggestions'].call() + var suggestions: Dictionary= shortcode_events[code].get_shortcode_parameters()[current_parameter]['suggestions'].call() for key in suggestions.keys(): if suggestions[key].has('text_alt'): text.add_code_completion_option(CodeEdit.KIND_MEMBER, key, suggestions[key].text_alt[0], shortcode_events[code].event_color.lerp(syntax_highlighter.normal_color, 0.3), suggestions[key].get('icon', null), '" ') @@ -265,8 +265,9 @@ func confirm_code_completion(replace:bool, text:CodeEdit) -> void: text.set_caret_column(text.get_caret_column()+1) -################################################################################ -## SYMBOL CLICKING +#endregion + +#region SYMBOL CLICKING ################################################################################ # Performs an action (like opening a link) when a valid symbol was clicked @@ -290,3 +291,4 @@ func symbol_validate(symbol:String, text:CodeEdit) -> void: if symbol in DialogicResourceUtil.get_timeline_directory(): text.set_symbol_lookup_word_as_valid(true) +#endregion diff --git a/addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd b/addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd index ea13e3715..56f6b83bd 100644 --- a/addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd +++ b/addons/dialogic/Editor/TimelineEditor/TextEditor/syntax_highlighter.gd @@ -64,15 +64,19 @@ func _get_line_syntax_highlighting(line:int) -> Dictionary: dict = color_translation_id(dict, str_line) if mode == Modes.FULL_HIGHLIGHTING: - if str_line.strip_edges().begins_with("[") and !text_event.text_effects_regex.search(str_line.get_slice(' ', 0)): - var result:= shortcode_regex.search(str_line) + if line_is_shortcode_event(line): + var full_event := get_full_event(line) + var result := shortcode_regex.search(full_event) if result: if result.get_string('id') in shortcode_events: - dict[result.get_start('id')] = {"color":shortcode_events[result.get_string('id')].event_color.lerp(normal_color, 0.4)} - dict[result.get_end('id')] = {"color":normal_color} - - if result.get_string('args'): - color_shortcode_content(dict, str_line, result.get_start('args'), result.get_end('args'), shortcode_events[result.get_string('id')].event_color) + if full_event.begins_with(str_line): + dict[result.get_start('id')] = {"color":shortcode_events[result.get_string('id')].event_color.lerp(normal_color, 0.4)} + dict[result.get_end('id')] = {"color":normal_color} + + if result.get_string('args'): + color_shortcode_content(dict, str_line, result.get_start('args'), result.get_end('args'), shortcode_events[result.get_string('id')].event_color) + else: + color_shortcode_content(dict, str_line, 0, 0, shortcode_events[result.get_string('id')].event_color) return fix_dict(dict) else: @@ -86,6 +90,39 @@ func _get_line_syntax_highlighting(line:int) -> Dictionary: return fix_dict(dict) +func line_is_shortcode_event(line_idx:int) -> bool: + var str_line := get_text_edit().get_line(line_idx) + if text_event.text_effects_regex.search(str_line.get_slice(' ', 0)): + return false + + if str_line.strip_edges().begins_with("["): + return true + + if line_idx > 0 and get_text_edit().get_line(line_idx-1).ends_with('\\'): + return line_is_shortcode_event(line_idx-1) + + return false + + +func get_full_event(line_idx:int) -> String: + var str_line := get_text_edit().get_line(line_idx) + var offset := 1 + # Add previous lines + while get_text_edit().get_line(line_idx-offset).ends_with('\\'): + str_line = get_text_edit().get_line(line_idx-offset).trim_suffix('\\')+"\n"+str_line + offset += 1 + + # This is commented out, as it is not needed right now. + # However without it, this isn't actually the full event. + # Might need to be included some day. + #offset = 0 + ## Add following lines + #while get_text_edit().get_line(line_idx+offset).ends_with('\\'): + #str_line = str_line.trim_suffix('\\')+"\n"+get_text_edit().get_line(line_idx+offset) + #offset += 1 + + return str_line + func fix_dict(dict:Dictionary) -> Dictionary: var d := {} var k := dict.keys() @@ -151,7 +188,7 @@ func color_region(dict:Dictionary, color:Color, line:String, start:String, end:S func color_shortcode_content(dict:Dictionary, line:String, from:int = 0, to:int = 0, base_color:=normal_color) -> Dictionary: if to <= from: to = len(line)-1 - var args_result:= shortcode_param_regex.search_all(line.substr(from, to-from+2)) + var args_result := shortcode_param_regex.search_all(line.substr(from, to-from+2)) for x in args_result: dict[x.get_start()+from] = {"color":base_color.lerp(normal_color, 0.5)} dict[x.get_start('value')+from-1] = {"color":base_color.lerp(normal_color, 0.7)} diff --git a/addons/dialogic/Modules/Text/event_text.gd b/addons/dialogic/Modules/Text/event_text.gd index 6080b51a8..8a27c4a93 100644 --- a/addons/dialogic/Modules/Text/event_text.gd +++ b/addons/dialogic/Modules/Text/event_text.gd @@ -131,7 +131,7 @@ func _execute() -> void: state = States.IDLE # Handling potential Choice Events. - if dialogic.has_subsystem('Choices') and dialogic.Choices.is_question(dialogic.current_event_idx): + if section_idx == len(split_text)-1 and dialogic.has_subsystem('Choices') and dialogic.Choices.is_question(dialogic.current_event_idx): dialogic.Text.show_next_indicators(true) end_text_event() diff --git a/addons/dialogic/Resources/timeline.gd b/addons/dialogic/Resources/timeline.gd index ac5c9b530..2f74204ad 100644 --- a/addons/dialogic/Resources/timeline.gd +++ b/addons/dialogic/Resources/timeline.gd @@ -119,19 +119,17 @@ func process() -> void: break event.empty_lines_above = empty_lines - # add the following lines until the event says it's full, there is an empty line or the indent changes + # add the following lines until the event says it's full or there is an empty line while !event.is_string_full_event(event_content): idx += 1 if idx == len(lines): break - var following_line: String = lines[idx] - var following_line_stripped: String = following_line.strip_edges(true, false) - var following_line_indent: String = following_line.substr(0,len(following_line)-len(following_line_stripped)) + + var following_line_stripped: String = lines[idx].strip_edges(true, false) + if following_line_stripped.is_empty(): break - if following_line_indent != indent: - idx -= 1 - break + event_content += "\n"+following_line_stripped event._load_from_string(event_content)