pandemonium_cms/game/addons/web_pages/editor/PageEditor.gd

207 lines
6.9 KiB
GDScript3
Raw Normal View History

tool
2022-08-25 10:56:43 +02:00
extends PanelContainer
2022-08-25 15:09:54 +02:00
var WebPageEntryEditor : PackedScene = null
2022-08-25 02:07:31 +02:00
var _wne_tool_bar_button : Button = null
2022-08-25 02:26:57 +02:00
var _page : WebPage = null
var undo_redo : UndoRedo = null
2022-08-25 10:56:43 +02:00
var _entry_name_line_edit : LineEdit = null
var _uri_segment_line_edit : LineEdit = null
var _add_entry_popup : AcceptDialog = null
2022-08-25 15:09:54 +02:00
var _entries_container : Control = null
var _main_add_button : Button = null
2022-08-25 15:09:54 +02:00
var _entry_add_after : WebPageEntry = null
2022-08-25 10:56:43 +02:00
2022-08-25 02:26:57 +02:00
func set_page(page : WebPage):
2022-08-25 15:09:54 +02:00
if _page:
_page.disconnect("entries_changed", self, "on_page_entries_changed")
2022-08-25 02:26:57 +02:00
_page = page
2022-08-25 15:09:54 +02:00
if _page:
_page.connect("entries_changed", self, "on_page_entries_changed")
2022-08-25 10:56:43 +02:00
_entry_name_line_edit.text = page.name
_uri_segment_line_edit.text = page.uri_segment
2022-08-25 15:09:54 +02:00
recreate()
func recreate() -> void:
clear()
create_editors()
func create_editors() -> void:
if _page.entries.size() > 0:
_main_add_button.hide()
2022-08-25 15:09:54 +02:00
for i in range(_page.entries.size()):
var e : WebPageEntry = _page.entries[i]
if e:
var ee : Control = create_editor_for_entry(e)
_entries_container.add_child(ee)
func create_editor_for_entry(entry : WebPageEntry) -> Control:
var c : Control = WebPageEntryEditor.instance() as Control
c.set_entry(entry, undo_redo)
c.connect("entry_add_requested_after", self, "_on_entry_add_requested_after")
c.connect("entry_move_up_requested", self, "_on_entry_move_up_requested")
c.connect("entry_move_down_requested", self, "_on_entry_move_down_requested")
c.connect("entry_delete_requested", self, "_on_entry_delete_requested")
2022-08-25 15:09:54 +02:00
return c
func clear() -> void:
_main_add_button.show()
2022-08-25 15:09:54 +02:00
for i in range(_entries_container.get_child_count()):
_entries_container.get_child(i).queue_free()
func add_entry(entry : WebPageEntry, after : WebPageEntry = null) -> void:
undo_redo.create_action("Added web page entry")
undo_redo.add_do_method(_page, "add_entry", entry, after)
undo_redo.add_undo_method(_page, "remove_entry", entry)
undo_redo.commit_action()
func remove_entry(entry : WebPageEntry) -> void:
var after : WebPageEntry = _page.get_entry_before(entry)
undo_redo.create_action("Added web page entry")
undo_redo.add_do_method(_page, "remove_entry", entry)
undo_redo.add_undo_method(_page, "add_entry", entry, after)
undo_redo.commit_action()
func move_entry_up(entry : WebPageEntry) -> void:
undo_redo.create_action("Added web page entry")
undo_redo.add_do_method(_page, "move_entry_up", entry)
undo_redo.add_undo_method(_page, "move_entry_down", entry)
undo_redo.commit_action()
func move_entry_down(entry : WebPageEntry) -> void:
undo_redo.create_action("Added web page entry")
undo_redo.add_do_method(_page, "move_entry_down", entry)
undo_redo.add_undo_method(_page, "move_entry_up", entry)
undo_redo.commit_action()
func _notification(what):
if what == NOTIFICATION_INSTANCED:
2022-08-25 10:56:43 +02:00
_entry_name_line_edit = get_node("MC/Name/EntryNameLineEdit")
_entry_name_line_edit.connect("text_entered", self, "_on_entry_name_line_edit_text_entered")
_uri_segment_line_edit = get_node("MC/URISegment/URISegmentLE")
_uri_segment_line_edit.connect("text_entered", self, "_on_uri_segment_line_edit_text_entered")
_add_entry_popup = get_node("Popups/AddEntryPopup")
_add_entry_popup.connect("on_entry_class_selected", self, "_on_add_entry_class_selected")
2022-08-25 15:09:54 +02:00
_entries_container = get_node("MC/EntriesContainer/MainVB/Entries")
_main_add_button = get_node("MC/EntriesContainer/MainVB/MainAddButton")
_main_add_button.connect("pressed", self, "_on_entry_add_requested")
2022-08-25 15:09:54 +02:00
WebPageEntryEditor = ResourceLoader.load("res://addons/web_pages/editor/WebPageEntryEditor.tscn", "PackedScene") as PackedScene
2022-08-25 02:07:31 +02:00
elif what == NOTIFICATION_ENTER_TREE:
var wne : Control = Engine.get_global("WebNodeEditor")
if wne:
_wne_tool_bar_button = Button.new()
2022-08-25 02:17:30 +02:00
_wne_tool_bar_button.set_text("Web Page Editor")
2022-08-25 02:07:31 +02:00
_wne_tool_bar_button.set_toggle_mode(true)
_wne_tool_bar_button.set_pressed(false)
_wne_tool_bar_button.set_button_group(wne.get_main_button_group())
_wne_tool_bar_button.set_keep_pressed_outside(true)
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")
elif what == NOTIFICATION_EXIT_TREE:
if _wne_tool_bar_button:
_wne_tool_bar_button.queue_free()
_wne_tool_bar_button = null
var wne : Control = Engine.get_global("WebNodeEditor")
if wne:
wne.disconnect("edited_node_changed", self, "_edited_node_changed")
2022-08-25 10:56:43 +02:00
func _on_entry_name_line_edit_text_entered(new_text : String):
undo_redo.create_action("Page name changed.")
undo_redo.add_do_property(_page, "name", new_text)
undo_redo.add_undo_property(_page, "name", _page.name)
undo_redo.add_do_property(_entry_name_line_edit, "text", new_text)
undo_redo.add_undo_property(_entry_name_line_edit, "text", _page.name)
undo_redo.add_do_property(self, "name", new_text)
undo_redo.add_undo_property(self, "name", _page.name)
undo_redo.commit_action()
2022-08-25 02:07:31 +02:00
2022-08-25 10:56:43 +02:00
func _on_uri_segment_line_edit_text_entered(new_text : String):
undo_redo.create_action("Page uri segment changed.")
undo_redo.add_do_property(_page, "uri_segment", new_text)
undo_redo.add_undo_property(_page, "uri_segment", _page.uri_segment)
undo_redo.add_do_property(_uri_segment_line_edit, "text", new_text)
undo_redo.add_undo_property(_uri_segment_line_edit, "text", _page.uri_segment)
undo_redo.commit_action()
2022-08-25 02:07:31 +02:00
func _on_blog_editor_button_toggled(on):
if on:
var wne : Control = Engine.get_global("WebNodeEditor")
if wne:
wne.switch_to_main_screen_tab(self)
_wne_tool_bar_button.set_pressed_no_signal(true)
func _edited_node_changed(web_node : WebNode):
if !_wne_tool_bar_button:
return
var wne : Control = Engine.get_global("WebNodeEditor")
if wne:
if web_node is WebPage:
2022-08-25 02:26:57 +02:00
set_page(web_node)
#_page = web_node
2022-08-25 02:07:31 +02:00
_wne_tool_bar_button.show()
_wne_tool_bar_button.pressed = true
#wne.switch_to_main_screen_tab(self)
else:
_wne_tool_bar_button.hide()
2022-08-25 02:26:57 +02:00
#_page = null
2022-08-25 02:07:31 +02:00
#add method to switch off to the prev screen
#wne.switch_to_main_screen_tab(self)
2022-08-25 15:09:54 +02:00
func on_page_entries_changed() -> void:
recreate()
2022-08-25 10:56:43 +02:00
func _on_add_entry_class_selected(cls_name : String) -> void:
2022-08-25 15:09:54 +02:00
var entry : WebPageEntry = null
if cls_name == "WebPageEntryTitleText":
entry = WebPageEntryTitleText.new()
elif cls_name == "WebPageEntryText":
entry = WebPageEntryText.new()
elif cls_name == "WebPageEntryImage":
entry = WebPageEntryImage.new()
2022-08-25 15:09:54 +02:00
if !entry:
PLogger.log_error("PageEditor: Couldn't create entry for: " + cls_name)
return
2022-08-25 15:09:54 +02:00
add_entry(entry, _entry_add_after)
func _on_entry_add_requested() -> void:
_entry_add_after = null
_add_entry_popup.popup_centered()
func _on_entry_add_requested_after(entry) -> void:
_entry_add_after = entry
_add_entry_popup.popup_centered()
func _on_entry_move_up_requested(entry) -> void:
move_entry_up(entry)
func _on_entry_move_down_requested(entry) -> void:
move_entry_down(entry)
func _on_entry_delete_requested(entry) -> void:
remove_entry(entry)