From c05b6038fb9674e25ee04818c0356b0c19cc99c6 Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Tue, 17 Jan 2023 20:10:09 +0100 Subject: [PATCH 1/4] fix AdvancedTextButton --- .../AdvancedTextButton/AdvancedTextButton.gd | 42 ++++++++++--------- .../AdvancedTextButton.tscn | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.gd b/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.gd index 1dae68a..ea19204 100644 --- a/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.gd +++ b/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.gd @@ -2,24 +2,19 @@ tool extends Button class_name AdvancedTextButton +onready var adv_label := $AdvancedTextLabel + export(String, MULTILINE) var markup_text := "" setget _set_markup_text export(String, "default", "markdown", "renpy", "bbcode") var markup := "default" setget _set_markup -# onready var adv_label := $AdvancedTextLabel -var adv_label : AdvancedTextLabel func _ready(): - if Engine.editor_hint and !adv_label: - adv_label = AdvancedTextLabel.new() - adv_label.scroll_active = false - adv_label.mouse_filter = MOUSE_FILTER_PASS - adv_label.rect_clip_content = false - add_child(adv_label) - adv_label.owner = self - - else: + if !adv_label: adv_label = $AdvancedTextLabel - + + adv_label.scroll_active = false + adv_label.mouse_filter = MOUSE_FILTER_PASS + adv_label.rect_clip_content = false _set_markup(markup) _set_markup_text(markup_text) @@ -28,26 +23,32 @@ func _ready(): connect("pressed", self, "_on_pressed") connect("toggled", self, "_on_toggled") + func _set_markup_text(text: String): if !adv_label: return - + + markup_text = text adv_label.markup_text = text yield(get_tree(), "idle_frame") rect_size = adv_label.rect_size + func _set_markup(markup: String): if !adv_label: return + markup = markup adv_label.markup = markup yield(get_tree(), "idle_frame") rect_size = adv_label.rect_size -func _set_label_color(color_name:String): + +func _set_label_color(color_name: String): adv_label.modulate = get_color(color_name, "Button") -func _set(property:String, value)->bool: + +func _set(property: String, value) -> bool: if property in get_property_list(): set(property, value) else: @@ -59,29 +60,32 @@ func _set(property:String, value)->bool: _set_label_color("font_color_disabled") else: _set_label_color("font_color") - + return true + func is_toggled(): return pressed and toggle_mode + func _on_mouse_entered(): if not (disabled or is_toggled()): _set_label_color("font_color_hover") + func _on_mouse_exited(): if not (disabled or is_toggled()): _set_label_color("font_color") + func _on_pressed(): if not disabled: _set_label_color("font_color_pressed") -func _on_toggled(value:bool): + +func _on_toggled(value: bool): if not disabled: if value: _set_label_color("font_color_pressed") else: _set_label_color("font_color") - - diff --git a/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.tscn b/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.tscn index ca32329..94965f3 100644 --- a/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.tscn +++ b/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.tscn @@ -12,7 +12,7 @@ size_flags_horizontal = 3 theme = ExtResource( 2 ) script = ExtResource( 3 ) -[node name="RichTextLabel" type="RichTextLabel" parent="."] +[node name="AdvancedTextLabel" type="RichTextLabel" parent="."] margin_right = 373.0 margin_bottom = 20.0 rect_clip_content = false From 0fd59ad23f00dfa8440c70b5e8aa48b8d9dee68b Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Tue, 17 Jan 2023 20:10:36 +0100 Subject: [PATCH 2/4] update other examples to use new AdvancedTextButton --- .../EditTextOnClick/EditTextOnClick.gd | 16 ++++++++++------ .../EditTextOnClick/EditTextOnClick.tscn | 9 ++++++--- .../EditTextOnClickPopup.gd | 18 +++++++++++------- .../EditTextOnClickPopup.tscn | 14 ++++---------- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.gd b/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.gd index a434462..90869ad 100644 --- a/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.gd +++ b/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.gd @@ -1,24 +1,28 @@ +tool extends TabContainer export(String, MULTILINE) var text := "[center][shake rate=5 level=10]**Clik to edit me**[/shake][/center]" -export (NodePath) onready var label = get_node(label) -export (NodePath) onready var save_button = get_node(save_button) -export (NodePath) onready var m_edit = get_node(m_edit) -export (NodePath) onready var button = get_node(button) +export(NodePath) onready var button = get_node(button) +export(NodePath) onready var save_button = get_node(save_button) +export(NodePath) onready var m_edit = get_node(m_edit) + func _ready(): - label.markup_text = text m_edit.text = text + button.markup_text = text button.connect("pressed", self, "_on_button_pressed") save_button.connect("pressed", self, "_on_save_button_pressed") + func _on_button_pressed(): current_tab = 1 + func _on_save_button_pressed(): - label.markup_text = m_edit.text + button.markup_text = m_edit.text current_tab = 0 + func _process(delta): if m_edit.visible: if Input.is_key_pressed(KEY_ESCAPE): diff --git a/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.tscn b/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.tscn index 5fba77d..6933c9f 100644 --- a/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.tscn +++ b/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.tscn @@ -18,14 +18,17 @@ script = ExtResource( 3 ) __meta__ = { "_edit_use_anchors_": false } +button = NodePath("AdvancedTextButton") +save_button = NodePath("MarkupEdit/SaveButton") +m_edit = NodePath("MarkupEdit") [node name="AdvancedTextButton" parent="." instance=ExtResource( 1 )] anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 margin_top = 8.0 -margin_right = -4.0 -margin_bottom = -4.0 +margin_right = 57.0 +margin_bottom = -177.0 [node name="MarkupEdit" type="TextEdit" parent="."] visible = false @@ -41,7 +44,7 @@ syntax_highlighting = true script = ExtResource( 2 ) configs = [ "res://addons/advanced-text/highlights/bbcode.json", "res://addons/advanced-text/highlights/markdown.json" ] -[node name="Button" type="Button" parent="MarkupEdit"] +[node name="SaveButton" type="Button" parent="MarkupEdit"] anchor_left = 1.0 anchor_top = 1.0 anchor_right = 1.0 diff --git a/addons/advanced-text/examples/EditTextOnClickPopup/EditTextOnClickPopup.gd b/addons/advanced-text/examples/EditTextOnClickPopup/EditTextOnClickPopup.gd index c29ddbd..cd21212 100644 --- a/addons/advanced-text/examples/EditTextOnClickPopup/EditTextOnClickPopup.gd +++ b/addons/advanced-text/examples/EditTextOnClickPopup/EditTextOnClickPopup.gd @@ -1,29 +1,33 @@ +tool extends Control export(String, MULTILINE) var text := "[center][shake rate=5 level=10]**Clik to edit me**[/shake][/center]" -export (NodePath) onready var label = get_node(label) -export (NodePath) onready var m_edit = get_node(m_edit) -export (NodePath) onready var button = get_node(button) +export(NodePath) onready var m_edit = get_node(m_edit) +export(NodePath) onready var button = get_node(button) + func _ready(): - label.markup_text = text + button.markup_text = text m_edit.text = text button.connect("toggled", self, "_on_button_toggled") m_edit.connect("text_changed", self, "_on_text_changed") -func _on_button_toggled(toggled:bool): + +func _on_button_toggled(toggled: bool): if toggled: var pos = button.rect_global_position pos.y += button.rect_size.y var r = $Popup.rect_size var rect = Rect2(pos, r) $Popup.popup(rect) - + else: $Popup.hide() + func _on_text_changed(): - label.markup_text = m_edit.text + button.markup_text = m_edit.text + func _process(delta): if $Popup.visible: diff --git a/addons/advanced-text/examples/EditTextOnClickPopup/EditTextOnClickPopup.tscn b/addons/advanced-text/examples/EditTextOnClickPopup/EditTextOnClickPopup.tscn index 388444e..b8e3dcf 100644 --- a/addons/advanced-text/examples/EditTextOnClickPopup/EditTextOnClickPopup.tscn +++ b/addons/advanced-text/examples/EditTextOnClickPopup/EditTextOnClickPopup.tscn @@ -17,23 +17,19 @@ script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false } +m_edit = NodePath("Popup/MarkupEdit") +button = NodePath("AdvancedTextButton") [node name="AdvancedTextButton" parent="." instance=ExtResource( 3 )] anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 margin_top = 8.0 -margin_right = -4.0 -margin_bottom = -4.0 -size_flags_horizontal = 3 +margin_right = 91.0 +margin_bottom = -2.0 size_flags_vertical = 3 toggle_mode = true -[node name="AdvancedTextLabel" parent="AdvancedTextButton" index="0"] -bbcode_text = "[center][shake rate=5 level=10][b]Clik to edit me[/b][/shake][/center]" -text = "Clik to edit me" -markup_text = "[center][shake rate=5 level=10]**Clik to edit me**[/shake][/center]" - [node name="Popup" type="Popup" parent="."] visible = true margin_left = 4.0 @@ -50,5 +46,3 @@ anchor_bottom = 1.0 syntax_highlighting = true script = ExtResource( 1 ) configs = [ "res://addons/advanced-text/highlights/bbcode.json", "res://addons/advanced-text/highlights/markdown.json" ] - -[editable path="AdvancedTextButton"] From f5fcc2bdced71c9bddb06c93e93404037dc4e367 Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sun, 22 Jan 2023 17:02:46 +0100 Subject: [PATCH 3/4] fix bugs not saving node paths in EditTextOnClick example --- .../EditTextOnClick/EditTextOnClick.gd | 44 ++++++++++++-- .../EditTextOnClick/EditTextOnClick.tscn | 58 +++++++++++++------ 2 files changed, 77 insertions(+), 25 deletions(-) diff --git a/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.gd b/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.gd index 90869ad..7178dbd 100644 --- a/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.gd +++ b/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.gd @@ -1,29 +1,61 @@ -tool extends TabContainer export(String, MULTILINE) var text := "[center][shake rate=5 level=10]**Clik to edit me**[/shake][/center]" -export(NodePath) onready var button = get_node(button) -export(NodePath) onready var save_button = get_node(save_button) -export(NodePath) onready var m_edit = get_node(m_edit) +export var _button: NodePath +export var _edit: NodePath +export var _buttons_container: NodePath +export var _save_button: NodePath +export var _cancel_button: NodePath + +var button: AdvancedTextButton +var m_edit: TextEdit +var buttons_container: Control +var save_button: Button +var cancel_button: Button func _ready(): + button = get_node(_button) + m_edit = get_node(_edit) + buttons_container = get_node(_buttons_container) + save_button = get_node(_save_button) + cancel_button = get_node(_cancel_button) + m_edit.text = text button.markup_text = text button.connect("pressed", self, "_on_button_pressed") save_button.connect("pressed", self, "_on_save_button_pressed") + cancel_button.connect("pressed", self, "_on_cancel_button_pressed") func _on_button_pressed(): + m_edit.text = button.markup_text + m_edit.rect_min_size = button.rect_size current_tab = 1 + buttons_container.show() func _on_save_button_pressed(): button.markup_text = m_edit.text current_tab = 0 + buttons_container.hide() + + +func _on_cancel_button_pressed(): + m_edit.text = button.markup_text + current_tab = 0 + buttons_container.hide() func _process(delta): - if m_edit.visible: + if current_tab == 1: if Input.is_key_pressed(KEY_ESCAPE): - current_tab = 0 + _on_cancel_button_pressed() + return + + if Input.is_key_pressed(KEY_ENTER): + if Input.is_key_pressed(KEY_MASK_SHIFT): + m_edit.text += "\n" + return + + _on_save_button_pressed() diff --git a/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.tscn b/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.tscn index 6933c9f..a2d79cd 100644 --- a/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.tscn +++ b/addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.tscn @@ -4,33 +4,42 @@ [ext_resource path="res://addons/advanced-text/nodes/CodeEdit.gd" type="Script" id=2] [ext_resource path="res://addons/advanced-text/examples/EditTextOnClick/EditTextOnClick.gd" type="Script" id=3] -[node name="EditTextOnClick" type="TabContainer"] +[node name="EditTextOnClick" type="VBoxContainer"] anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -margin_left = -156.0 -margin_top = -18.0 -margin_right = 164.0 -margin_bottom = 191.0 +margin_left = -189.0 +margin_top = -104.5 +margin_right = 189.0 +margin_bottom = 104.5 + +[node name="Tabs" type="TabContainer" parent="."] +margin_right = 378.0 +margin_bottom = 209.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 tabs_visible = false script = ExtResource( 3 ) __meta__ = { "_edit_use_anchors_": false } -button = NodePath("AdvancedTextButton") -save_button = NodePath("MarkupEdit/SaveButton") -m_edit = NodePath("MarkupEdit") +_button = NodePath("AdvancedTextButton") +_edit = NodePath("MarkupEdit") +_buttons_container = NodePath("../HBoxContainer") +_save_button = NodePath("../HBoxContainer/SaveButton") +_cancel_button = NodePath("../HBoxContainer/CancelButton") -[node name="AdvancedTextButton" parent="." instance=ExtResource( 1 )] +[node name="AdvancedTextButton" parent="Tabs" instance=ExtResource( 1 )] anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 4.0 margin_top = 8.0 -margin_right = 57.0 -margin_bottom = -177.0 +margin_right = -4.0 +margin_bottom = -4.0 +rect_min_size = Vector2( 0, 0 ) -[node name="MarkupEdit" type="TextEdit" parent="."] +[node name="MarkupEdit" type="TextEdit" parent="Tabs"] visible = false anchor_right = 1.0 anchor_bottom = 1.0 @@ -44,14 +53,25 @@ syntax_highlighting = true script = ExtResource( 2 ) configs = [ "res://addons/advanced-text/highlights/bbcode.json", "res://addons/advanced-text/highlights/markdown.json" ] -[node name="SaveButton" type="Button" parent="MarkupEdit"] -anchor_left = 1.0 -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_left = -41.0 -margin_top = -20.0 +[node name="HBoxContainer" type="HBoxContainer" parent="."] +visible = false +margin_top = 38.0 +margin_right = 98.0 +margin_bottom = 58.0 + +[node name="SaveButton" type="Button" parent="HBoxContainer"] +margin_right = 41.0 +margin_bottom = 20.0 text = "save" __meta__ = { "_edit_use_anchors_": false } + +[node name="CancelButton" type="Button" parent="HBoxContainer"] +margin_left = 45.0 +margin_right = 98.0 +margin_bottom = 20.0 +text = "cancel" +__meta__ = { +"_edit_use_anchors_": false +} From 0c79e76139db9a7595a0c645204b295aa700c1f3 Mon Sep 17 00:00:00 2001 From: Jeremi Biernacki Date: Sun, 22 Jan 2023 17:03:08 +0100 Subject: [PATCH 4/4] fix loading AdvancedTextButton bugs --- .../AdvancedTextButton/AdvancedTextButton.gd | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.gd b/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.gd index ea19204..08aed2a 100644 --- a/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.gd +++ b/addons/advanced-text/examples/AdvancedTextButton/AdvancedTextButton.gd @@ -7,6 +7,8 @@ onready var adv_label := $AdvancedTextLabel export(String, MULTILINE) var markup_text := "" setget _set_markup_text export(String, "default", "markdown", "renpy", "bbcode") var markup := "default" setget _set_markup +var ready := false + func _ready(): if !adv_label: @@ -22,26 +24,37 @@ func _ready(): connect("mouse_exited", self, "_on_mouse_exited") connect("pressed", self, "_on_pressed") connect("toggled", self, "_on_toggled") + ready = true + + +func size_update(): + rect_min_size = adv_label.rect_min_size func _set_markup_text(text: String): + if Engine.editor_hint or !ready: + return + if !adv_label: return markup_text = text adv_label.markup_text = text yield(get_tree(), "idle_frame") - rect_size = adv_label.rect_size + size_update() func _set_markup(markup: String): + if Engine.editor_hint or !ready: + return + if !adv_label: return markup = markup adv_label.markup = markup yield(get_tree(), "idle_frame") - rect_size = adv_label.rect_size + size_update() func _set_label_color(color_name: String):