mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-24 04:46:48 +01:00
Set up WebEditorPlugin to hide / show the web editor tab in a way that feels right. The tab itself is empty though at the moment.
This commit is contained in:
parent
8d4e878ff6
commit
e38dfb7c40
@ -27,7 +27,14 @@ SOFTWARE.
|
||||
|
||||
#include "editor/editor_node.h"
|
||||
|
||||
void WebEditorPlugin::make_visible(const bool visible) {
|
||||
void WebEditorPlugin::make_visible(bool visible) {
|
||||
if (visible) {
|
||||
if (is_inside_tree()) {
|
||||
_scene_has_webnode = true;
|
||||
editor->editor_set_visible_by_name("Web", true);
|
||||
}
|
||||
}
|
||||
|
||||
window->set_visible(visible);
|
||||
}
|
||||
|
||||
@ -44,26 +51,94 @@ bool WebEditorPlugin::has_main_screen() const {
|
||||
}
|
||||
|
||||
void WebEditorPlugin::edit(Object *p_object) {
|
||||
//WebNode *wn = Object::cast_to<WebNode>(p_object);
|
||||
WebNode *wn = Object::cast_to<WebNode>(p_object);
|
||||
|
||||
//if (wn) {
|
||||
// window->set_node(wn);
|
||||
//}
|
||||
if (wn) {
|
||||
// window->set_node(wn);
|
||||
|
||||
get_editor_interface()->set_main_screen_editor("Web");
|
||||
}
|
||||
}
|
||||
|
||||
bool WebEditorPlugin::handles(Object *p_object) const {
|
||||
return p_object->is_class("WebNode");
|
||||
}
|
||||
|
||||
void WebEditorPlugin::edited_scene_changed() {
|
||||
Node *edited_scene = editor->get_edited_scene();
|
||||
|
||||
_scene_has_webnode = scene_has_webnode(edited_scene);
|
||||
editor->editor_set_visible_by_name("Web", _scene_has_webnode);
|
||||
}
|
||||
|
||||
bool WebEditorPlugin::scene_has_webnode(Node *p_node) {
|
||||
if (!p_node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Object::cast_to<WebNode>(p_node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < p_node->get_child_count(); ++i) {
|
||||
Node *n = p_node->get_child(i);
|
||||
|
||||
if (scene_has_webnode(n)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WebEditorPlugin::scene_has_webnode_skip(Node *p_node, Node *skip) {
|
||||
if (!p_node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (p_node == skip) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Object::cast_to<WebNode>(p_node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < p_node->get_child_count(); ++i) {
|
||||
Node *n = p_node->get_child(i);
|
||||
|
||||
if (scene_has_webnode_skip(n, skip)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebEditorPlugin::on_node_removed(Node *p_node) {
|
||||
if (!_scene_has_webnode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Object::cast_to<WebNode>(p_node)) {
|
||||
if (!scene_has_webnode_skip(editor->get_edited_scene(), p_node)) {
|
||||
editor->editor_set_visible_by_name("Web", false);
|
||||
_scene_has_webnode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WebEditorPlugin::WebEditorPlugin(EditorNode *p_node) {
|
||||
editor = p_node;
|
||||
|
||||
window = memnew(WebEditor);
|
||||
|
||||
get_editor_interface()->get_editor_viewport()->add_child(window);
|
||||
editor->get_viewport()->add_child(window);
|
||||
_icon = get_editor_interface()->get_base_control()->get_theme_icon("WebNodeEditor", "EditorIcons");
|
||||
|
||||
make_visible(false);
|
||||
|
||||
_scene_has_webnode = false;
|
||||
}
|
||||
|
||||
WebEditorPlugin::~WebEditorPlugin() {
|
||||
@ -71,12 +146,16 @@ WebEditorPlugin::~WebEditorPlugin() {
|
||||
|
||||
void WebEditorPlugin::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
get_editor_interface()->set_main_screen_editor_tab_button_visible("Web", false);
|
||||
case NOTIFICATION_POST_ENTER_TREE: {
|
||||
editor->editor_set_visible_by_name("Web", false);
|
||||
get_tree()->connect("node_removed", this, "on_node_removed");
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
get_tree()->disconnect("node_removed", this, "on_node_removed");
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void WebEditorPlugin::_bind_methods() {
|
||||
//ClassDB::bind_method(D_METHOD(""), &WebEditorPlugin::);
|
||||
ClassDB::bind_method(D_METHOD("on_node_removed", "node"), &WebEditorPlugin::on_node_removed);
|
||||
}
|
||||
|
@ -34,12 +34,16 @@ class WebEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(WebEditorPlugin, EditorPlugin);
|
||||
|
||||
public:
|
||||
void make_visible(const bool visible);
|
||||
void make_visible(bool visible);
|
||||
const Ref<Texture> get_icon() const;
|
||||
bool has_main_screen() const;
|
||||
String get_name() const;
|
||||
void edit(Object *p_object);
|
||||
bool handles(Object *p_object) const;
|
||||
void edited_scene_changed();
|
||||
|
||||
bool scene_has_webnode(Node *p_node);
|
||||
bool scene_has_webnode_skip(Node *p_node, Node *skip);
|
||||
|
||||
WebEditorPlugin(EditorNode *p_node);
|
||||
~WebEditorPlugin();
|
||||
@ -49,11 +53,14 @@ public:
|
||||
WebEditor *window;
|
||||
|
||||
protected:
|
||||
void on_node_removed(Node *p_child);
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
Ref<Texture> _icon;
|
||||
bool _scene_has_webnode;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user