summaryrefslogtreecommitdiff
path: root/modules/navigation/editor
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-03-28 14:10:28 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-03-28 16:48:15 +0200
commit5fe6984639b5db9efa14103698e489040315ebfb (patch)
tree11a76ba5ab636182d0b0a334bb2ada196ef86e98 /modules/navigation/editor
parent41d075de5865c8b088c83219431661bc2d1f1802 (diff)
Modules: Don't build editor-specific classes in templates
They're moved to an `editor` subfolder so that we can easily handle them separately.
Diffstat (limited to 'modules/navigation/editor')
-rw-r--r--modules/navigation/editor/navigation_mesh_editor_plugin.cpp157
-rw-r--r--modules/navigation/editor/navigation_mesh_editor_plugin.h86
2 files changed, 243 insertions, 0 deletions
diff --git a/modules/navigation/editor/navigation_mesh_editor_plugin.cpp b/modules/navigation/editor/navigation_mesh_editor_plugin.cpp
new file mode 100644
index 0000000000..c243e3e6e3
--- /dev/null
+++ b/modules/navigation/editor/navigation_mesh_editor_plugin.cpp
@@ -0,0 +1,157 @@
+/*************************************************************************/
+/* navigation_mesh_editor_plugin.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "navigation_mesh_editor_plugin.h"
+
+#ifdef TOOLS_ENABLED
+
+#include "../navigation_mesh_generator.h"
+#include "core/io/marshalls.h"
+#include "core/io/resource_saver.h"
+#include "editor/editor_node.h"
+#include "scene/3d/mesh_instance_3d.h"
+#include "scene/gui/box_container.h"
+
+void NavigationMeshEditor::_node_removed(Node *p_node) {
+ if (p_node == node) {
+ node = nullptr;
+
+ hide();
+ }
+}
+
+void NavigationMeshEditor::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ button_bake->set_icon(get_theme_icon(SNAME("Bake"), SNAME("EditorIcons")));
+ button_reset->set_icon(get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")));
+ } break;
+ }
+}
+
+void NavigationMeshEditor::_bake_pressed() {
+ button_bake->set_pressed(false);
+
+ ERR_FAIL_COND(!node);
+ if (!node->get_navigation_mesh().is_valid()) {
+ err_dialog->set_text(TTR("A NavigationMesh resource must be set or created for this node to work."));
+ err_dialog->popup_centered();
+ return;
+ }
+
+ NavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh());
+ NavigationMeshGenerator::get_singleton()->bake(node->get_navigation_mesh(), node);
+
+ node->update_gizmos();
+}
+
+void NavigationMeshEditor::_clear_pressed() {
+ if (node) {
+ NavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh());
+ }
+
+ button_bake->set_pressed(false);
+ bake_info->set_text("");
+
+ if (node) {
+ node->update_gizmos();
+ }
+}
+
+void NavigationMeshEditor::edit(NavigationRegion3D *p_nav_region) {
+ if (p_nav_region == nullptr || node == p_nav_region) {
+ return;
+ }
+
+ node = p_nav_region;
+}
+
+void NavigationMeshEditor::_bind_methods() {
+}
+
+NavigationMeshEditor::NavigationMeshEditor() {
+ bake_hbox = memnew(HBoxContainer);
+
+ button_bake = memnew(Button);
+ button_bake->set_flat(true);
+ bake_hbox->add_child(button_bake);
+ button_bake->set_toggle_mode(true);
+ button_bake->set_text(TTR("Bake NavMesh"));
+ button_bake->connect("pressed", callable_mp(this, &NavigationMeshEditor::_bake_pressed));
+
+ button_reset = memnew(Button);
+ button_reset->set_flat(true);
+ bake_hbox->add_child(button_reset);
+ // No button text, we only use a revert icon which is set when entering the tree.
+ button_reset->set_tooltip(TTR("Clear the navigation mesh."));
+ button_reset->connect("pressed", callable_mp(this, &NavigationMeshEditor::_clear_pressed));
+
+ bake_info = memnew(Label);
+ bake_hbox->add_child(bake_info);
+
+ err_dialog = memnew(AcceptDialog);
+ add_child(err_dialog);
+ node = nullptr;
+}
+
+NavigationMeshEditor::~NavigationMeshEditor() {
+}
+
+void NavigationMeshEditorPlugin::edit(Object *p_object) {
+ navigation_mesh_editor->edit(Object::cast_to<NavigationRegion3D>(p_object));
+}
+
+bool NavigationMeshEditorPlugin::handles(Object *p_object) const {
+ return p_object->is_class("NavigationRegion3D");
+}
+
+void NavigationMeshEditorPlugin::make_visible(bool p_visible) {
+ if (p_visible) {
+ navigation_mesh_editor->show();
+ navigation_mesh_editor->bake_hbox->show();
+ } else {
+ navigation_mesh_editor->hide();
+ navigation_mesh_editor->bake_hbox->hide();
+ navigation_mesh_editor->edit(nullptr);
+ }
+}
+
+NavigationMeshEditorPlugin::NavigationMeshEditorPlugin() {
+ navigation_mesh_editor = memnew(NavigationMeshEditor);
+ EditorNode::get_singleton()->get_main_control()->add_child(navigation_mesh_editor);
+ add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, navigation_mesh_editor->bake_hbox);
+ navigation_mesh_editor->hide();
+ navigation_mesh_editor->bake_hbox->hide();
+}
+
+NavigationMeshEditorPlugin::~NavigationMeshEditorPlugin() {
+}
+
+#endif // TOOLS_ENABLED
diff --git a/modules/navigation/editor/navigation_mesh_editor_plugin.h b/modules/navigation/editor/navigation_mesh_editor_plugin.h
new file mode 100644
index 0000000000..3c3e804fd2
--- /dev/null
+++ b/modules/navigation/editor/navigation_mesh_editor_plugin.h
@@ -0,0 +1,86 @@
+/*************************************************************************/
+/* navigation_mesh_editor_plugin.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef NAVIGATION_MESH_EDITOR_PLUGIN_H
+#define NAVIGATION_MESH_EDITOR_PLUGIN_H
+
+#ifdef TOOLS_ENABLED
+
+#include "editor/editor_plugin.h"
+
+class NavigationRegion3D;
+
+class NavigationMeshEditor : public Control {
+ friend class NavigationMeshEditorPlugin;
+
+ GDCLASS(NavigationMeshEditor, Control);
+
+ AcceptDialog *err_dialog;
+
+ HBoxContainer *bake_hbox;
+ Button *button_bake;
+ Button *button_reset;
+ Label *bake_info;
+
+ NavigationRegion3D *node;
+
+ void _bake_pressed();
+ void _clear_pressed();
+
+protected:
+ void _node_removed(Node *p_node);
+ static void _bind_methods();
+ void _notification(int p_what);
+
+public:
+ void edit(NavigationRegion3D *p_nav_region);
+ NavigationMeshEditor();
+ ~NavigationMeshEditor();
+};
+
+class NavigationMeshEditorPlugin : public EditorPlugin {
+ GDCLASS(NavigationMeshEditorPlugin, EditorPlugin);
+
+ NavigationMeshEditor *navigation_mesh_editor;
+
+public:
+ virtual String get_name() const override { return "NavigationMesh"; }
+ bool has_main_screen() const override { return false; }
+ virtual void edit(Object *p_object) override;
+ virtual bool handles(Object *p_object) const override;
+ virtual void make_visible(bool p_visible) override;
+
+ NavigationMeshEditorPlugin();
+ ~NavigationMeshEditorPlugin();
+};
+
+#endif // TOOLS_ENABLED
+
+#endif // NAVIGATION_MESH_EDITOR_PLUGIN_H