From e7c720ceebed667e15ef6975d537e66224ff0c42 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sun, 1 Mar 2020 18:12:16 +0000 Subject: [PATCH] Added barebones editor plugin to edit VoxelGeneratorGraph (does nothing for now) --- SCsub | 1 + editor/voxel_graph_editor.cpp | 26 ++++++++++++++++++ editor/voxel_graph_editor.h | 25 +++++++++++++++++ editor/voxel_graph_editor_plugin.cpp | 40 ++++++++++++++++++++++++++++ editor/voxel_graph_editor_plugin.h | 23 ++++++++++++++++ register_types.cpp | 7 +++++ 6 files changed, 122 insertions(+) create mode 100644 editor/voxel_graph_editor.cpp create mode 100644 editor/voxel_graph_editor.h create mode 100644 editor/voxel_graph_editor_plugin.cpp create mode 100644 editor/voxel_graph_editor_plugin.h diff --git a/SCsub b/SCsub index 08e4a993..1f65f07c 100644 --- a/SCsub +++ b/SCsub @@ -17,6 +17,7 @@ files = [ "terrain/*.cpp", "math/*.cpp", "edition/*.cpp", + "editor/*.cpp", "thirdparty/lz4/*.c" ] diff --git a/editor/voxel_graph_editor.cpp b/editor/voxel_graph_editor.cpp new file mode 100644 index 00000000..57c4f5f6 --- /dev/null +++ b/editor/voxel_graph_editor.cpp @@ -0,0 +1,26 @@ +#include "voxel_graph_editor.h" +#include "../generators/graph/voxel_generator_graph.h" +#include + +VoxelGraphEditor::VoxelGraphEditor() { + _graph_edit = memnew(GraphEdit); + _graph_edit->set_anchors_preset(Control::PRESET_WIDE); + add_child(_graph_edit); +} + +void VoxelGraphEditor::set_graph(Ref graph) { + if (_graph == graph) { + return; + } + + // if (_graph.is_valid()) { + // } + + _graph = graph; + + // if (_graph.is_valid()) { + // } +} + +void VoxelGraphEditor::_bind_methods() { +} diff --git a/editor/voxel_graph_editor.h b/editor/voxel_graph_editor.h new file mode 100644 index 00000000..e1f411a1 --- /dev/null +++ b/editor/voxel_graph_editor.h @@ -0,0 +1,25 @@ +#ifndef VOXEL_GRAPH_EDITOR_H +#define VOXEL_GRAPH_EDITOR_H + +#include + +class VoxelGeneratorGraph; +class GraphEdit; +class PopupMenu; + +class VoxelGraphEditor : public Control { + GDCLASS(VoxelGraphEditor, Control) +public: + VoxelGraphEditor(); + + void set_graph(Ref graph); + +private: + static void _bind_methods(); + + Ref _graph; + GraphEdit *_graph_edit = nullptr; + PopupMenu *_context_menu = nullptr; +}; + +#endif // VOXEL_GRAPH_EDITOR_H diff --git a/editor/voxel_graph_editor_plugin.cpp b/editor/voxel_graph_editor_plugin.cpp new file mode 100644 index 00000000..2b3d24ec --- /dev/null +++ b/editor/voxel_graph_editor_plugin.cpp @@ -0,0 +1,40 @@ +#include "voxel_graph_editor_plugin.h" +#include "../generators/graph/voxel_generator_graph.h" +//#include "editor/editor_node.h" +#include "editor/editor_scale.h" +#include "voxel_graph_editor.h" + +VoxelGraphEditorPlugin::VoxelGraphEditorPlugin(EditorNode *p_node) { + //EditorInterface *ed = get_editor_interface(); + _graph_editor = memnew(VoxelGraphEditor); + _graph_editor->set_custom_minimum_size(Size2(0, 300) * EDSCALE); + _bottom_panel_button = add_control_to_bottom_panel(_graph_editor, TTR("Voxel Graph")); + _bottom_panel_button->hide(); +} + +bool VoxelGraphEditorPlugin::handles(Object *p_object) const { + if (p_object == nullptr) { + return false; + } + VoxelGeneratorGraph *graph_ptr = Object::cast_to(p_object); + return graph_ptr != nullptr; +} + +void VoxelGraphEditorPlugin::edit(Object *p_object) { + VoxelGeneratorGraph *graph_ptr = Object::cast_to(p_object); + Ref graph(graph_ptr); + _graph_editor->set_graph(graph); +} + +void VoxelGraphEditorPlugin::make_visible(bool visible) { + if (visible) { + _bottom_panel_button->show(); + make_bottom_panel_item_visible(_graph_editor); + } else { + _bottom_panel_button->hide(); + edit(nullptr); + if (_graph_editor->is_visible_in_tree()) { + hide_bottom_panel(); + } + } +} diff --git a/editor/voxel_graph_editor_plugin.h b/editor/voxel_graph_editor_plugin.h new file mode 100644 index 00000000..5cc60b7c --- /dev/null +++ b/editor/voxel_graph_editor_plugin.h @@ -0,0 +1,23 @@ +#ifndef VOXEL_GRAPH_EDITOR_PLUGIN_H +#define VOXEL_GRAPH_EDITOR_PLUGIN_H + +#include + +class VoxelGraphEditor; +//class ToolButton; + +class VoxelGraphEditorPlugin : public EditorPlugin { + GDCLASS(VoxelGraphEditorPlugin, EditorPlugin) +public: + VoxelGraphEditorPlugin(EditorNode *p_node); + + bool handles(Object *p_object) const override; + void edit(Object *p_object) override; + void make_visible(bool visible) override; + +private: + VoxelGraphEditor *_graph_editor = nullptr; + ToolButton *_bottom_panel_button = nullptr; +}; + +#endif // VOXEL_GRAPH_EDITOR_PLUGIN_H diff --git a/register_types.cpp b/register_types.cpp index ec266200..3075f2d3 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -1,5 +1,7 @@ #include "register_types.h" #include "edition/voxel_tool.h" +#include "editor/editor_plugin.h" +#include "editor/voxel_graph_editor_plugin.h" #include "generators/graph/voxel_generator_graph.h" #include "generators/graph/voxel_graph_node_db.h" #include "generators/voxel_generator_flat.h" @@ -73,6 +75,8 @@ void register_voxel_types() { #ifdef TOOLS_ENABLED VoxelDebug::create_debug_box_mesh(); + + EditorPlugins::add_by_type(); #endif } @@ -89,5 +93,8 @@ void unregister_voxel_types() { #ifdef TOOLS_ENABLED VoxelDebug::free_debug_box_mesh(); + + // TODO No remove? + //EditorPlugins::remove_by_type(); #endif }