From b092f87e567f9cd2ce1275039ab49b52697afb2d Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sat, 15 Jan 2022 12:22:54 +0100 Subject: [PATCH 1/8] Settings update --- addons/advanced-text/nodes/AdvancedTextLabel.gd | 4 ++-- addons/advanced-text/plugin.gd | 17 ++++++++--------- addons/project-settings-helpers/ProjectTools.gd | 14 ++++++++++++-- project.godot | 4 ---- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/addons/advanced-text/nodes/AdvancedTextLabel.gd b/addons/advanced-text/nodes/AdvancedTextLabel.gd index bc448de..045a2d0 100644 --- a/addons/advanced-text/nodes/AdvancedTextLabel.gd +++ b/addons/advanced-text/nodes/AdvancedTextLabel.gd @@ -57,7 +57,7 @@ func _get_text_parser(_markup_str:String): # for some reason loading default parser setting works only in editor # so I save it as metadata and load it during runtime if Engine.editor_hint: - default = ProjectSettings.get("advanced_text/markup") + default = ProjectSettings.get("addons/advanced_text/markup") set_meta("_default_markup", default) else: default = get_meta("_default_markup") @@ -107,7 +107,7 @@ func _on_update() -> void: if p == null: return - var vars_json = ProjectSettings.get("advanced_text/default_vars") + var vars_json = ProjectSettings.get("addons/advanced_text/default_vars") var default_vars = parse_json(vars_json) if default_vars: diff --git a/addons/advanced-text/plugin.gd b/addons/advanced-text/plugin.gd index a6b5e7d..c831be4 100644 --- a/addons/advanced-text/plugin.gd +++ b/addons/advanced-text/plugin.gd @@ -6,26 +6,29 @@ var markup_text_editor var editor_parent : Control var button_parent : Control -var default_property_list:Dictionary = { - "advanced_text/markup" : [ +var default_properties := { + "addons/advanced_text/markup" : [ "markdown", PropertyInfo.new( "", TYPE_STRING, PROPERTY_HINT_ENUM, "markdown,renpy,bbcode", PROPERTY_USAGE_CATEGORY) ], - "advanced_text/default_vars" : [ + "addons/advanced_text/default_vars" : [ # json string JSON.print({ "test_setting" : "variable from project settings" }, "\t"), PropertyInfo.new( "", TYPE_STRING, PROPERTY_HINT_MULTILINE_TEXT, - "", - PROPERTY_USAGE_CATEGORY) + "", PROPERTY_USAGE_CATEGORY) ], } func _enter_tree(): + ProjectTools.set_settings_dict(default_properties) + var property_keys := default_properties.keys() + ProjectTools.set_settings_order(property_keys, 1) + # loads all parser onces var parsers_dir := "res://addons/advanced-text/parsers/" add_autoload_singleton("EBBCodeParser", parsers_dir + "EBBCodeParser.gd") @@ -65,10 +68,6 @@ func _enter_tree(): connect("scene_changed", self, "_on_scene_changed") - for property_key in default_property_list.keys(): - var property_value = default_property_list[property_key] - ProjectTools.set_setting(property_key, property_value[0], property_value[1]) - func _exit_tree(): # remove MarkupTextEditor from EditorUI markup_text_editor.queue_free() diff --git a/addons/project-settings-helpers/ProjectTools.gd b/addons/project-settings-helpers/ProjectTools.gd index a2d64c7..aea3fe3 100644 --- a/addons/project-settings-helpers/ProjectTools.gd +++ b/addons/project-settings-helpers/ProjectTools.gd @@ -1,14 +1,24 @@ tool class_name ProjectTools extends Reference -# author: willnationsdev +# author: willnationsdev & jeremi360 # license: MIT # description: A utility for any features useful in the context of a Godot Project. - static func set_setting(p_name: String, p_default_value, p_pinfo: PropertyInfo) -> void: p_pinfo.name = p_name if not ProjectSettings.has_setting(p_name): ProjectSettings.set_setting(p_name, p_default_value) + ProjectSettings.add_property_info(p_pinfo.to_dict()) ProjectSettings.set_initial_value(p_name, p_default_value) + +static func set_settings_dict(settings_dict:Dictionary) -> void: + for property_key in settings_dict.keys(): + var property_value = settings_dict[property_key] + set_setting(property_key, property_value[0], property_value[1]) + +static func set_settings_order(properties: Array, p_order: int) -> void: + for p in properties: + ProjectSettings.set_order(p, p_order) + p_order += 1 \ No newline at end of file diff --git a/project.godot b/project.godot index e7e3b6d..127e508 100644 --- a/project.godot +++ b/project.godot @@ -42,10 +42,6 @@ _global_script_class_icons={ "PropertyInfo": "" } -[advanced_text] - -default_vars="{\"test_setting\" : \"variable from project settings\"}" - [application] config/name="AdvancedTextLabel" From fdf3e90e1b6c1f78b44502efcabaad3e5438ce62 Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sat, 15 Jan 2022 12:32:38 +0100 Subject: [PATCH 2/8] fix tabs bug on switching to unsported text files --- .../MarkupTextEditor/MarkupTextEditor.gd | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd index 4501078..52fafcc 100644 --- a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd +++ b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd @@ -266,8 +266,15 @@ func _set_markup_id(id: int): if id != markup_id: markups_options.selected = id edit_tabs.current_tab = id - preview_tabs.current_tab = id - help_tabs.current_tab = id + + preview_toggle.visible = id != 3 + preview_tabs.visible = id != 3 + help_button.visible = id != 3 + + if id != 3: + preview_tabs.current_tab = id + help_tabs.current_tab = id + markup_id = id if selected_node: @@ -321,7 +328,7 @@ func _on_node_selected(node: Node): var _markup_str_id = node.markup if _markup_str_id == "default": - _markup_str_id = ProjectSettings.get("advanced_text/markup") + _markup_str_id = ProjectSettings.get("addons/advanced_text/markup") var _markup_id = markups_str.find(_markup_str_id) markups_options.disabled = false From 3c850cac0ff34b833d28ab611100d0cb6bfa916b Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sat, 15 Jan 2022 12:39:56 +0100 Subject: [PATCH 3/8] fix bug that makes open selected_node to many times at once --- addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd index 52fafcc..b4ad43b 100644 --- a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd +++ b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd @@ -324,6 +324,9 @@ func _process(delta: float) -> void: # print("type", selected_node.get_class()) func _on_node_selected(node: Node): + if selected_node == node: + return + if node is AdvancedTextLabel: var _markup_str_id = node.markup @@ -466,7 +469,6 @@ func _on_file_open(file_path:String, modified_text := ""): _update_file_data(f_data) save_files_ram() - func save_files_ram(): print("save files ram") f.open_compressed(files_ram_path, File.WRITE) From f4cced471ed7f8b529f2a7daf0ffc9ab36ae0c07 Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sat, 15 Jan 2022 12:55:12 +0100 Subject: [PATCH 4/8] fix bug that makes open selected_file to many times at once --- .../MarkupTextEditor/MarkupTextEditor.gd | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd index b4ad43b..e16f34b 100644 --- a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd +++ b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd @@ -81,6 +81,7 @@ const markups_str := ["markdown", "renpy", "bbcode"] var files_ram := {} var files_boxes := {} +var current_file_path := "" var current_file_data := {} var last_file_data := {} var paths_dir := {} @@ -213,7 +214,6 @@ func get_current_edit_tab() -> TextEdit: var e_id := edit_tabs.current_tab return e_tabs[e_id] - func update_text_preview(caller:TextEdit, text_from_edit_tab := true): if not caller.visible: return @@ -230,7 +230,6 @@ func update_text_preview(caller:TextEdit, text_from_edit_tab := true): current_preview_tab.markup_text = text - func _on_text_changed(caller:TextEdit): if !caller.visible: return @@ -255,7 +254,6 @@ func _on_text_changed(caller:TextEdit): if selected_node is CodeEdit: selected_node.text = caller.text - func _on_option_selected(id: int): if id != markup_id: _set_markup_id(id) @@ -372,18 +370,15 @@ func _on_node_selected(node: Node): file_icon.texture = get_icon("NodeWarning", "EditorIcons") file_name_label.text = "Unsupported Node Type" - func _on_file_open_button_pressed(): file_popup.mode = FileDialog.MODE_OPEN_FILES file_popup.popup_centered(Vector2(700, 500)) - func _on_file_save_as_button_pressed(): file_popup.mode = FileDialog.MODE_SAVE_FILE saving_as_mode = true file_popup.popup_centered(Vector2(700, 500)) - func _on_file_selected(file_path:String): # var file_path = file_popup.current_path match file_popup.mode: @@ -410,7 +405,14 @@ func _on_files_selected(file_paths:Array): func _on_file_open(file_path:String, modified_text := ""): if file_path.empty(): return + + if current_file_path == file_path: + return + + current_file_path = file_path + # print_debug("open file ", file_path) + # file is already open so just switch to it var file_name = file_path.get_file() var file_ext = file_path.get_extension() @@ -418,7 +420,7 @@ func _on_file_open(file_path:String, modified_text := ""): if file_path in paths_dir.keys(): # add switching to file var f_tab = paths_dir[file_path] - f_tab.emit_signal("pressed", f_tab) + f_tab.emit_signal("pressed") return # print("open not opened file", file_path) @@ -467,8 +469,12 @@ func _on_file_open(file_path:String, modified_text := ""): files_ram[f_box] = f_data files_boxes[file_name] = f_box _update_file_data(f_data) + save_files_ram() + f_button.emit_signal("pressed") + + func save_files_ram(): print("save files ram") f.open_compressed(files_ram_path, File.WRITE) From f2c8849cbbaf94e85dc87ade2d97be782e453d16 Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sat, 15 Jan 2022 16:42:40 +0100 Subject: [PATCH 5/8] fix too many times upadting file data at once --- .../MarkupTextEditor/MarkupTextEditor.gd | 45 ++++++++++--------- addons/advanced-text/emojis_import.gd | 3 +- tests/AdvancedTextLabelTest.tscn | 2 + 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd index e16f34b..c2f18df 100644 --- a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd +++ b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd @@ -172,12 +172,10 @@ func _ready(): ch.connect("text_changed", self, "update_text_preview", [ch, true]) ch.connect("text_changed", self, "_on_text_changed", [ch]) - func _on_visibility_changed(): var edit_node := selected_node_toggle.pressed set_process(edit_node && visible) - func _on_nodes_toggle(toggled:bool): last_file_data = current_file_data text = "" @@ -194,11 +192,10 @@ func _on_nodes_toggle(toggled:bool): set_process(toggled) - func _on_files_toggle(toggled:bool): files_tab.visible = toggled if last_file_data: - _update_file_data(last_file_data) + _update_file_data(last_file_data, current_file_path) else: file_icon.texture = get_icon("New", "EditorIcons") @@ -398,7 +395,7 @@ func _on_file_selected(file_path:String): _on_file_save_button_pressed() func _on_files_selected(file_paths:Array): - # print("open files", file_paths) + print("open files", file_paths) for file_path in file_paths: _on_file_open(file_path) @@ -408,22 +405,21 @@ func _on_file_open(file_path:String, modified_text := ""): if current_file_path == file_path: return - - current_file_path = file_path - # print_debug("open file ", file_path) - - # file is already open so just switch to it + print_debug("open file ", file_path) var file_name = file_path.get_file() var file_ext = file_path.get_extension() - + + # if file is already open so just switch to it if file_path in paths_dir.keys(): # add switching to file - var f_tab = paths_dir[file_path] - f_tab.emit_signal("pressed") + print_debug("file already open") + var f_tab_button = paths_dir[file_path].get_node("FileButton") + print_debug("switch to tab ", f_tab_button.text) + f_tab_button.emit_signal("pressed") return - # print("open not opened file", file_path) + print("open not opened file", file_path) var f_box = file_box_scene.instance() f_box.name = file_name @@ -468,7 +464,7 @@ func _on_file_open(file_path:String, modified_text := ""): paths_dir[file_path] = f_box files_ram[f_box] = f_data files_boxes[file_name] = f_box - _update_file_data(f_data) + _update_file_data(f_data, file_path) save_files_ram() @@ -495,8 +491,16 @@ func save_files_ram(): f.close() -func _update_file_data(f_data): - # print("load file data to ram") +func _update_file_data(f_data:Dictionary, file_path:String): + if last_file_data == f_data: + return + + if file_path == current_file_path: + return + + current_file_path = file_path + + print("load file data to ram") markups_options.disabled = true var b : Button = f_data["f_button"] @@ -526,11 +530,12 @@ func _update_file_data(f_data): update_text_preview(get_current_edit_tab(), false) current_file_data = f_data file_save_button.disabled = not f_data["modified"] - # print("file loaded") + print("file loaded") func _on_file_button_pressed(file_box: Node): var f_data = files_ram[file_box] - _update_file_data(f_data) + var file_path = f_data["path"] + _update_file_data(f_data, file_path) func _on_file_close_button_pressed(file_box: Node): var f_data = files_ram[file_box] @@ -570,5 +575,5 @@ func _on_file_save_button_pressed(): f.close() f_data["modified"] = false - _update_file_data(f_data) + _update_file_data(f_data, file_path) save_files_ram() diff --git a/addons/advanced-text/emojis_import.gd b/addons/advanced-text/emojis_import.gd index d84b5f3..5740bde 100644 --- a/addons/advanced-text/emojis_import.gd +++ b/addons/advanced-text/emojis_import.gd @@ -13,8 +13,7 @@ var _warning_shown : = false func _init(): if !_plugin_enabled: - var plugins :=[] - plugins = ProjectSettings.get_setting("editor_plugins/enabled") + var plugins = ProjectSettings.get_setting("editor_plugins/enabled") if plugins.empty(): if !_warning_shown: push_warning("emojis-for-godot are not enabled") diff --git a/tests/AdvancedTextLabelTest.tscn b/tests/AdvancedTextLabelTest.tscn index 346c3a4..37f9fa4 100644 --- a/tests/AdvancedTextLabelTest.tscn +++ b/tests/AdvancedTextLabelTest.tscn @@ -519,6 +519,8 @@ script = ExtResource( 1 ) __meta__ = { "_default_markup": "markdown" } +markup_text_file = "" markup_text = "**This is normally Markdown** @color=#c39f00 {variable from settings:} @color=lime{}" +markup = "default" headers_fonts = [ ExtResource( 4 ), ExtResource( 2 ), ExtResource( 5 ) ] From 88a450cc1bb29034b74387abdd17a92a525f11e0 Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sat, 15 Jan 2022 21:07:31 +0100 Subject: [PATCH 6/8] more opt code of tracking selected nodes --- .../MarkupTextEditor/MarkupTextEditor.gd | 66 ++++++++++--------- addons/advanced-text/plugin.gd | 5 ++ 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd index c2f18df..ba644cf 100644 --- a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd +++ b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd @@ -120,7 +120,6 @@ func load_last_session(files_ram_path : String): files_tab.visible = true - func _ready(): emoji_button.hide() _on_nodes_toggle(true) @@ -186,6 +185,7 @@ func _on_nodes_toggle(toggled:bool): if selected_node: _on_node_selected(selected_node) + else: file_icon.texture = get_icon("NodeWarning", "EditorIcons") file_name_label.text = "None Node is Selected" @@ -201,11 +201,9 @@ func _on_files_toggle(toggled:bool): file_icon.texture = get_icon("New", "EditorIcons") file_name_label.text = "Unnamed Text File" - func _on_toggle(toggled: bool): preview_tabs.visible = toggled - func get_current_edit_tab() -> TextEdit: var e_tabs := edit_tabs.get_children() var e_id := edit_tabs.current_tab @@ -258,23 +256,25 @@ func _on_option_selected(id: int): update_text_preview(current, text.empty()) func _set_markup_id(id: int): - if id != markup_id: - markups_options.selected = id - edit_tabs.current_tab = id - - preview_toggle.visible = id != 3 - preview_tabs.visible = id != 3 - help_button.visible = id != 3 - - if id != 3: - preview_tabs.current_tab = id - help_tabs.current_tab = id + if id == markup_id: + return - markup_id = id + markup_id = id + markups_options.selected = id + edit_tabs.current_tab = id + preview_toggle.visible = id != 3 + preview_tabs.visible = id != 3 + help_button.visible = id != 3 + + if id == 3: + return - if selected_node: - if selected_node is AdvancedTextLabel: - selected_node.markup = markups_str[id] + preview_tabs.current_tab = id + help_tabs.current_tab = id + + if selected_node: + if selected_node is AdvancedTextLabel: + selected_node.markup = markups_str[id] func _on_help_button_pressed(): var m = markups_options.get_item_text(markup_id) @@ -295,6 +295,8 @@ func get_selected_node() -> Node: var s = editor.get_selection() var selected_nodes = s.get_selected_nodes() + + print("selected_nodes ", selected_nodes.size()) if selected_nodes.size() == 0: return null @@ -306,22 +308,25 @@ func get_selected_node() -> Node: func _process(delta: float) -> void: if not editor: return - - var selected_node = get_selected_node() - if !selected_node: - return - preview_toggle.pressed = true - preview_tabs.visible = true - file_name_label.text = selected_node.name - toggle_nodes_mode() + if Input.is_action_just_pressed("mouse_left_button"): + var selected_node = get_selected_node() + if !selected_node: + return + + preview_toggle.pressed = true + preview_tabs.visible = true + file_name_label.text = selected_node.name + toggle_nodes_mode() - # print("type", selected_node.get_class()) + # print("type", selected_node.get_class()) func _on_node_selected(node: Node): if selected_node == node: return + selected_node = node + if node is AdvancedTextLabel: var _markup_str_id = node.markup @@ -334,6 +339,7 @@ func _on_node_selected(node: Node): if node.markup_text_file: toggle_files_mode() + print("loading text file from node") _on_file_open(node.markup_text_file) else: @@ -470,7 +476,6 @@ func _on_file_open(file_path:String, modified_text := ""): f_button.emit_signal("pressed") - func save_files_ram(): print("save files ram") f.open_compressed(files_ram_path, File.WRITE) @@ -490,14 +495,15 @@ func save_files_ram(): f.store_var(data_to_save) f.close() - func _update_file_data(f_data:Dictionary, file_path:String): if last_file_data == f_data: return + last_file_data = f_data + if file_path == current_file_path: return - + current_file_path = file_path print("load file data to ram") diff --git a/addons/advanced-text/plugin.gd b/addons/advanced-text/plugin.gd index c831be4..67e686a 100644 --- a/addons/advanced-text/plugin.gd +++ b/addons/advanced-text/plugin.gd @@ -29,6 +29,11 @@ func _enter_tree(): var property_keys := default_properties.keys() ProjectTools.set_settings_order(property_keys, 1) + InputMap.add_action("mouse_left_button") + var mouse_left_button_event := InputEventMouseButton.new() + mouse_left_button_event.device = BUTTON_LEFT + InputMap.action_add_event("mouse_left_button", mouse_left_button_event) + # loads all parser onces var parsers_dir := "res://addons/advanced-text/parsers/" add_autoload_singleton("EBBCodeParser", parsers_dir + "EBBCodeParser.gd") From 905a4ec052647236e3d5eaf74f187abfde29d248 Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sat, 15 Jan 2022 22:11:17 +0100 Subject: [PATCH 7/8] more opt selecting nodes --- .../MarkupTextEditor/MarkupTextEditor.gd | 86 ++++++++++++------- .../MarkupTextEditor/MarkupTextEditor.tscn | 22 ++--- addons/advanced-text/plugin.gd | 5 -- 3 files changed, 64 insertions(+), 49 deletions(-) diff --git a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd index ba644cf..f27a854 100644 --- a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd +++ b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd @@ -75,7 +75,7 @@ onready var file_save_as_button : Button = get_node(file_save_as_button_nodepath var markup_id := 0 var text: = "" var editor : EditorInterface -var selected_node : Node +var last_selected_node : Node var saving_as_mode := false const markups_str := ["markdown", "renpy", "bbcode"] @@ -172,8 +172,7 @@ func _ready(): ch.connect("text_changed", self, "_on_text_changed", [ch]) func _on_visibility_changed(): - var edit_node := selected_node_toggle.pressed - set_process(edit_node && visible) + set_process(visible) func _on_nodes_toggle(toggled:bool): last_file_data = current_file_data @@ -181,17 +180,15 @@ func _on_nodes_toggle(toggled:bool): var tab = get_current_edit_tab() update_text_preview(tab, false) - var selected_node = get_selected_node() + var last_selected_node = get_selected_node() - if selected_node: - _on_node_selected(selected_node) + if last_selected_node: + _on_node_selected(last_selected_node) else: file_icon.texture = get_icon("NodeWarning", "EditorIcons") file_name_label.text = "None Node is Selected" - set_process(toggled) - func _on_files_toggle(toggled:bool): files_tab.visible = toggled if last_file_data: @@ -236,18 +233,18 @@ func _on_text_changed(caller:TextEdit): file_modified_icon.show() file_save_button.disabled = false - if selected_node: - if selected_node is AdvancedTextLabel: - selected_node.markup_text = caller.text + if last_selected_node: + if last_selected_node is AdvancedTextLabel: + last_selected_node.markup_text = caller.text - if selected_node is RichTextLabel: - if selected_node.bbcode_enabled: - selected_node.markup_text = caller.text + if last_selected_node is RichTextLabel: + if last_selected_node.bbcode_enabled: + last_selected_node.markup_text = caller.text else: - selected_node.text = caller.text + last_selected_node.text = caller.text - if selected_node is CodeEdit: - selected_node.text = caller.text + if last_selected_node is CodeEdit: + last_selected_node.text = caller.text func _on_option_selected(id: int): if id != markup_id: @@ -272,9 +269,9 @@ func _set_markup_id(id: int): preview_tabs.current_tab = id help_tabs.current_tab = id - if selected_node: - if selected_node is AdvancedTextLabel: - selected_node.markup = markups_str[id] + if last_selected_node: + if last_selected_node is AdvancedTextLabel: + last_selected_node.markup = markups_str[id] func _on_help_button_pressed(): var m = markups_options.get_item_text(markup_id) @@ -296,36 +293,59 @@ func get_selected_node() -> Node: var s = editor.get_selection() var selected_nodes = s.get_selected_nodes() - print("selected_nodes ", selected_nodes.size()) + # print("selected_nodes ", selected_nodes.size()) if selected_nodes.size() == 0: return null - if selected_node != selected_nodes[0]: + if last_selected_node != selected_nodes[0]: return selected_nodes[0] else: return null +var mouse_button_released = true +var mouse_button_just_pressed = false + func _process(delta: float) -> void: if not editor: return + + # there is no selected node changed signal + # so I need to check if the selected node changed in _process() + # also adding InputMap.add_action() doesn't work in editor + if Input.is_mouse_button_pressed(BUTTON_LEFT): + if mouse_button_released: + mouse_button_just_pressed = true + mouse_button_released = false + else: + mouse_button_just_pressed = false + + else: + mouse_button_released = true + mouse_button_just_pressed = false + + if !mouse_button_just_pressed: + return - if Input.is_action_just_pressed("mouse_left_button"): - var selected_node = get_selected_node() - if !selected_node: - return + var selected_node = get_selected_node() + if !selected_node: + return + + if selected_node == last_selected_node: + return - preview_toggle.pressed = true - preview_tabs.visible = true - file_name_label.text = selected_node.name - toggle_nodes_mode() + last_selected_node = selected_node + preview_toggle.pressed = true + preview_tabs.visible = true + file_name_label.text = selected_node.name + toggle_nodes_mode() - # print("type", selected_node.get_class()) + # print("type", last_selected_node.get_class()) func _on_node_selected(node: Node): - if selected_node == node: + if last_selected_node == node: return - selected_node = node + last_selected_node = node if node is AdvancedTextLabel: var _markup_str_id = node.markup diff --git a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.tscn b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.tscn index da90ed6..3cae885 100644 --- a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.tscn +++ b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.tscn @@ -124,9 +124,9 @@ size_flags_horizontal = 3 size_flags_vertical = 3 [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/CenterContainer2"] -margin_left = 96.0 +margin_left = 80.0 margin_top = 12.0 -margin_right = 176.0 +margin_right = 191.0 margin_bottom = 28.0 [node name="FileIcon" type="TextureRect" parent="VBoxContainer/HBoxContainer/CenterContainer2/HBoxContainer"] @@ -134,7 +134,7 @@ margin_right = 16.0 margin_bottom = 16.0 size_flags_horizontal = 3 size_flags_vertical = 3 -texture = ExtResource( 13 ) +texture = ExtResource( 12 ) stretch_mode = 6 __meta__ = { "_edit_use_anchors_": false @@ -143,10 +143,10 @@ __meta__ = { [node name="FileName" type="Label" parent="VBoxContainer/HBoxContainer/CenterContainer2/HBoxContainer"] margin_left = 20.0 margin_top = 1.0 -margin_right = 80.0 +margin_right = 111.0 margin_bottom = 15.0 size_flags_horizontal = 3 -text = "renpy.rpy" +text = "markdown.md" [node name="ModifiedIcon" type="TextureRect" parent="VBoxContainer/HBoxContainer/CenterContainer2/HBoxContainer"] visible = false @@ -187,12 +187,12 @@ margin_bottom = 22.0 grow_horizontal = 2 grow_vertical = 2 disabled = true -text = "RenPy" -icon = ExtResource( 13 ) +text = "Markdown" +icon = ExtResource( 12 ) flat = true clip_text = true items = [ "Markdown", ExtResource( 12 ), false, 0, null, "RenPy", ExtResource( 13 ), false, 1, null, "BBCode", ExtResource( 14 ), false, 2, null ] -selected = 1 +selected = 0 [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"] margin_left = 800.0 @@ -328,7 +328,6 @@ __meta__ = { } [node name="MarkdownEdit" type="TextEdit" parent="VBoxContainer/HSplitContainer/HBox/EditorsContainer"] -visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 @@ -409,6 +408,7 @@ __meta__ = { configs = [ "res://addons/advanced-text/highlights/bbcode.json", "res://addons/advanced-text/highlights/markdown.json" ] [node name="RenPyEdit" type="TextEdit" parent="VBoxContainer/HSplitContainer/HBox/EditorsContainer"] +visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 @@ -613,7 +613,6 @@ size_flags_vertical = 3 tabs_visible = false [node name="MarkdownTextLabel" type="RichTextLabel" parent="VBoxContainer/HSplitContainer/HBox/PreviewsContainer"] -visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 @@ -809,6 +808,7 @@ test_dict.key1 = headers_fonts = [ ExtResource( 17 ), ExtResource( 16 ), ExtResource( 18 ) ] [node name="RenPyTextLabel" type="RichTextLabel" parent="VBoxContainer/HSplitContainer/HBox/PreviewsContainer"] +visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 @@ -1128,7 +1128,6 @@ __meta__ = { } [node name="MarkdownHelp" type="HSplitContainer" parent="PopupHelp/HelperContainer"] -visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 @@ -1308,6 +1307,7 @@ wave amp=50 freq=2]wave[/wave] headers_fonts = [ ExtResource( 17 ), ExtResource( 16 ), ExtResource( 18 ) ] [node name="RenPyHelp" type="HSplitContainer" parent="PopupHelp/HelperContainer"] +visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 diff --git a/addons/advanced-text/plugin.gd b/addons/advanced-text/plugin.gd index 67e686a..c831be4 100644 --- a/addons/advanced-text/plugin.gd +++ b/addons/advanced-text/plugin.gd @@ -29,11 +29,6 @@ func _enter_tree(): var property_keys := default_properties.keys() ProjectTools.set_settings_order(property_keys, 1) - InputMap.add_action("mouse_left_button") - var mouse_left_button_event := InputEventMouseButton.new() - mouse_left_button_event.device = BUTTON_LEFT - InputMap.action_add_event("mouse_left_button", mouse_left_button_event) - # loads all parser onces var parsers_dir := "res://addons/advanced-text/parsers/" add_autoload_singleton("EBBCodeParser", parsers_dir + "EBBCodeParser.gd") From 544c65dc6935391ca2017db0ffdeeb0020095bd6 Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sat, 15 Jan 2022 22:22:17 +0100 Subject: [PATCH 8/8] fix on selecting nodes --- addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd index f27a854..ad0712a 100644 --- a/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd +++ b/addons/advanced-text/MarkupTextEditor/MarkupTextEditor.gd @@ -338,15 +338,11 @@ func _process(delta: float) -> void: preview_tabs.visible = true file_name_label.text = selected_node.name toggle_nodes_mode() + _on_node_selected(selected_node) # print("type", last_selected_node.get_class()) func _on_node_selected(node: Node): - if last_selected_node == node: - return - - last_selected_node = node - if node is AdvancedTextLabel: var _markup_str_id = node.markup @@ -566,7 +562,7 @@ func _on_file_button_pressed(file_box: Node): func _on_file_close_button_pressed(file_box: Node): var f_data = files_ram[file_box] var f_button = f_data["f_button"] - # todo add ask for save if text is changed + # todo add ask for save if text was changed files_box.remove_child(file_box) files_boxes.erase(file_box.name) files_ram.erase(file_box)