From c6e6accbe85a744e4e8a732af100cc550377140a Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 23 Aug 2022 23:17:05 +0200 Subject: [PATCH] Set up post listing, and some basic navigation. Also found and tried a new scripting style. --- game/Main.tscn | 3 ++ game/addons/web_blog/editor/PostEditor.gd | 5 ++ game/addons/web_blog/editor/PostEditor.tscn | 2 - game/addons/web_blog/editor/PostListEntry.gd | 29 ++++++++++ .../addons/web_blog/editor/PostListEntry.tscn | 33 ++++++++++++ game/addons/web_blog/editor/Posts.gd | 54 +++++++++++++++++++ game/addons/web_blog/editor/WebBlogEditor.gd | 32 ++++++++--- .../addons/web_blog/editor/WebBlogEditor.tscn | 2 - game/project.pandemonium | 4 +- 9 files changed, 151 insertions(+), 13 deletions(-) create mode 100644 game/addons/web_blog/editor/PostListEntry.gd create mode 100644 game/addons/web_blog/editor/PostListEntry.tscn diff --git a/game/Main.tscn b/game/Main.tscn index e8f165c..7629068 100644 --- a/game/Main.tscn +++ b/game/Main.tscn @@ -17,6 +17,9 @@ data = "Blog" uri_segment = "blog" script = ExtResource( 2 ) +[node name="WebNoasdsde" type="WebNode" parent="WebRoot/WebBlog"] +script = ExtResource( 3 ) + [node name="asdasd" type="WebNode" parent="WebRoot/WebBlog"] script = ExtResource( 3 ) diff --git a/game/addons/web_blog/editor/PostEditor.gd b/game/addons/web_blog/editor/PostEditor.gd index a36af58..feff25d 100644 --- a/game/addons/web_blog/editor/PostEditor.gd +++ b/game/addons/web_blog/editor/PostEditor.gd @@ -20,3 +20,8 @@ func _on_PostNameLE_text_entered(new_text : String): undo_redo.add_do_property(self, "name", new_text) undo_redo.add_undo_property(self, "name", _post.name) undo_redo.commit_action() + +func _notification(what): + if what == NOTIFICATION_INSTANCED: + var le : LineEdit = get_node("HBoxContainer/PostNameLE") + le.connect("text_entered", self, "_on_PostNameLE_text_entered") diff --git a/game/addons/web_blog/editor/PostEditor.tscn b/game/addons/web_blog/editor/PostEditor.tscn index 161ddc4..7d76d04 100644 --- a/game/addons/web_blog/editor/PostEditor.tscn +++ b/game/addons/web_blog/editor/PostEditor.tscn @@ -25,5 +25,3 @@ margin_bottom = 24.0 size_flags_horizontal = 3 text = "BlogPost" align = 1 - -[connection signal="text_entered" from="HBoxContainer/PostNameLE" to="." method="_on_PostNameLE_text_entered"] diff --git a/game/addons/web_blog/editor/PostListEntry.gd b/game/addons/web_blog/editor/PostListEntry.gd new file mode 100644 index 0000000..b3b5ee8 --- /dev/null +++ b/game/addons/web_blog/editor/PostListEntry.gd @@ -0,0 +1,29 @@ +tool +extends PanelContainer + +signal blog_post_edit_requested(post) + +var undo_redo : UndoRedo = null + +var _post : WebBlogPost + +func set_post(post : WebBlogPost) -> void: + _post = post + + update() + +func update() -> void: + if _post: + get_node("HBC/PostName").text = _post.name + else: + get_node("HBC/PostName").text = "" + +func _notification(what): + if what == NOTIFICATION_INSTANCED: + var _edit_button : Button = get_node("HBC/EditButton") + + _edit_button.connect("pressed", self, "_on_edit_button_pressed") + +func _on_edit_button_pressed() -> void: + if _post: + emit_signal("blog_post_edit_requested", _post) diff --git a/game/addons/web_blog/editor/PostListEntry.tscn b/game/addons/web_blog/editor/PostListEntry.tscn new file mode 100644 index 0000000..145e3b8 --- /dev/null +++ b/game/addons/web_blog/editor/PostListEntry.tscn @@ -0,0 +1,33 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/web_blog/editor/PostListEntry.gd" type="Script" id=1] + +[node name="PostEntry" type="PanelContainer"] +margin_right = 1016.0 +script = ExtResource( 1 ) + +[node name="HBC" type="HBoxContainer" parent="."] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 1009.0 +margin_bottom = 27.0 + +[node name="Label" type="Label" parent="HBC"] +margin_top = 3.0 +margin_right = 76.0 +margin_bottom = 17.0 +text = "Post name:" + +[node name="PostName" type="Label" parent="HBC"] +margin_left = 80.0 +margin_top = 3.0 +margin_right = 962.0 +margin_bottom = 17.0 +size_flags_horizontal = 3 +align = 1 + +[node name="EditButton" type="Button" parent="HBC"] +margin_left = 966.0 +margin_right = 1002.0 +margin_bottom = 20.0 +text = "Edit" diff --git a/game/addons/web_blog/editor/Posts.gd b/game/addons/web_blog/editor/Posts.gd index a7aae29..35acb09 100644 --- a/game/addons/web_blog/editor/Posts.gd +++ b/game/addons/web_blog/editor/Posts.gd @@ -2,6 +2,60 @@ tool extends VBoxContainer signal new_post_request +signal blog_post_edit_requested(post) + +var undo_redo : UndoRedo = null + +var _blog : WebBlog = null + +func create_post_list() -> void: + if !_blog: + return + + var _entry_container : VBoxContainer = get_node("ScrollContainer/OutsideVBC/Entries") + + var PostListEntry : PackedScene = ResourceLoader.load("res://addons/web_blog/editor/PostListEntry.tscn") + + for i in range(_blog.get_child_count()): + var c : Node = _blog.get_child(i) + + if !(c is WebBlogPost): + continue + + var wbp : WebBlogPost = c as WebBlogPost + + var entry = PostListEntry.instance() + entry.undo_redo = undo_redo + entry.set_post(wbp) + entry.connect("blog_post_edit_requested", self, "_on_blog_post_edit_requested") + _entry_container.add_child(entry) + + +func clear() -> void: + var _entry_container : VBoxContainer = get_node("ScrollContainer/OutsideVBC/Entries") + + for i in range(_entry_container.get_child_count()): + _entry_container.get_child(i).queue_free() + +func recreate() -> void: + clear() + create_post_list() + +func set_web_blog(blog : WebBlog) -> void: + if _blog == blog: + return + + _blog = blog + + recreate() + +func _on_blog_post_edit_requested(post) -> void: + emit_signal("blog_post_edit_requested", post) func _on_NewPostButton_pressed(): emit_signal("new_post_request") + +func _notification(what): + if what == NOTIFICATION_VISIBILITY_CHANGED: + if is_visible_in_tree(): + recreate() diff --git a/game/addons/web_blog/editor/WebBlogEditor.gd b/game/addons/web_blog/editor/WebBlogEditor.gd index 19399eb..6c24beb 100644 --- a/game/addons/web_blog/editor/WebBlogEditor.gd +++ b/game/addons/web_blog/editor/WebBlogEditor.gd @@ -18,6 +18,8 @@ func _enter_tree(): wne.add_control_to_tool_bar(_wne_tool_bar_button) _wne_tool_bar_button.connect("toggled", self, "_on_blog_editor_button_toggled") wne.connect("edited_node_changed", self, "_edited_node_changed") + + get_node("Tabs/Posts").undo_redo = undo_redo func _exit_tree(): if _wne_tool_bar_button: @@ -43,6 +45,7 @@ func _edited_node_changed(web_node : WebNode): if wne: if web_node is WebBlog: _edited_blog = web_node + get_node("Tabs/Posts").set_web_blog(_edited_blog) _wne_tool_bar_button.show() _wne_tool_bar_button.pressed = true #wne.switch_to_main_screen_tab(self) @@ -56,6 +59,8 @@ func _on_new_post_requested(): if !_edited_blog: return + var _tabs : TabContainer = get_node("./Tabs") + var post : WebBlogPost = WebBlogPost.new() _edited_blog.add_post(post) @@ -63,11 +68,24 @@ func _on_new_post_requested(): var nps : Control = post_editor_scene.instance() nps.undo_redo = undo_redo nps.set_post(post) - get_node("./Tabs").add_child(nps) - - # Hack for now. Todo add support for this into UndoRedo without hacks -# undo_redo.create_action("Created WebBlog Post") -# undo_redo.add_do_method(_edited_blog, "null_method") -# undo_redo.add_undo_method(_edited_blog, "null_method") -# undo_redo.commit_action() + _tabs.add_child(nps) + _tabs.current_tab = _tabs.get_child_count() - 1 +func _on_blog_post_edit_requested(post : WebBlogPost) -> void: + if !_edited_blog: + return + + var _tabs : TabContainer = get_node("./Tabs") + + var post_editor_scene : PackedScene = ResourceLoader.load("res://addons/web_blog/editor/PostEditor.tscn", "PackedScene") + var nps : Control = post_editor_scene.instance() + nps.undo_redo = undo_redo + nps.set_post(post) + _tabs.add_child(nps) + _tabs.current_tab = _tabs.get_child_count() - 1 + +func _notification(what): + if what == NOTIFICATION_INSTANCED: + var _posts : Control = get_node("Tabs/Posts") + _posts.connect("new_post_request", self, "_on_new_post_requested") + _posts.connect("blog_post_edit_requested", self, "_on_blog_post_edit_requested") diff --git a/game/addons/web_blog/editor/WebBlogEditor.tscn b/game/addons/web_blog/editor/WebBlogEditor.tscn index 7def01b..637d21e 100644 --- a/game/addons/web_blog/editor/WebBlogEditor.tscn +++ b/game/addons/web_blog/editor/WebBlogEditor.tscn @@ -19,5 +19,3 @@ size_flags_vertical = 3 [node name="Posts" parent="Tabs" instance=ExtResource( 3 )] size_flags_horizontal = 3 size_flags_vertical = 3 - -[connection signal="new_post_request" from="Tabs/Posts" to="." method="_on_new_post_requested"] diff --git a/game/project.pandemonium b/game/project.pandemonium index 12198b8..c63732e 100644 --- a/game/project.pandemonium +++ b/game/project.pandemonium @@ -32,8 +32,8 @@ _global_script_classes=[ { _global_script_class_icons={ @"WebBlogPost": "res://addons/web_blog/icons/icon_web_blog_post.svg", @"WebBlogPostEntryTitleText": "res://addons/web_blog/icons/icon_web_blog_post_entry_title_text.svg", -@"WebBlogPostEntry": "res://addons/web_blog/icons/icon_web_blog_post_entry.svg", -@"WebBlog": "res://addons/web_blog/icons/icon_web_blog.svg" +@"WebBlog": "res://addons/web_blog/icons/icon_web_blog.svg", +@"WebBlogPostEntry": "res://addons/web_blog/icons/icon_web_blog_post_entry.svg" } [application]