Added barebones editor plugin to edit VoxelGeneratorGraph (does nothing for now)

master
Marc Gilleron 2020-03-01 18:12:16 +00:00
parent a3b623ad3d
commit e7c720ceeb
6 changed files with 122 additions and 0 deletions

1
SCsub
View File

@ -17,6 +17,7 @@ files = [
"terrain/*.cpp",
"math/*.cpp",
"edition/*.cpp",
"editor/*.cpp",
"thirdparty/lz4/*.c"
]

View File

@ -0,0 +1,26 @@
#include "voxel_graph_editor.h"
#include "../generators/graph/voxel_generator_graph.h"
#include <scene/gui/graph_edit.h>
VoxelGraphEditor::VoxelGraphEditor() {
_graph_edit = memnew(GraphEdit);
_graph_edit->set_anchors_preset(Control::PRESET_WIDE);
add_child(_graph_edit);
}
void VoxelGraphEditor::set_graph(Ref<VoxelGeneratorGraph> graph) {
if (_graph == graph) {
return;
}
// if (_graph.is_valid()) {
// }
_graph = graph;
// if (_graph.is_valid()) {
// }
}
void VoxelGraphEditor::_bind_methods() {
}

View File

@ -0,0 +1,25 @@
#ifndef VOXEL_GRAPH_EDITOR_H
#define VOXEL_GRAPH_EDITOR_H
#include <scene/gui/control.h>
class VoxelGeneratorGraph;
class GraphEdit;
class PopupMenu;
class VoxelGraphEditor : public Control {
GDCLASS(VoxelGraphEditor, Control)
public:
VoxelGraphEditor();
void set_graph(Ref<VoxelGeneratorGraph> graph);
private:
static void _bind_methods();
Ref<VoxelGeneratorGraph> _graph;
GraphEdit *_graph_edit = nullptr;
PopupMenu *_context_menu = nullptr;
};
#endif // VOXEL_GRAPH_EDITOR_H

View File

@ -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<VoxelGeneratorGraph>(p_object);
return graph_ptr != nullptr;
}
void VoxelGraphEditorPlugin::edit(Object *p_object) {
VoxelGeneratorGraph *graph_ptr = Object::cast_to<VoxelGeneratorGraph>(p_object);
Ref<VoxelGeneratorGraph> 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();
}
}
}

View File

@ -0,0 +1,23 @@
#ifndef VOXEL_GRAPH_EDITOR_PLUGIN_H
#define VOXEL_GRAPH_EDITOR_PLUGIN_H
#include <editor/editor_plugin.h>
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

View File

@ -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<VoxelGraphEditorPlugin>();
#endif
}
@ -89,5 +93,8 @@ void unregister_voxel_types() {
#ifdef TOOLS_ENABLED
VoxelDebug::free_debug_box_mesh();
// TODO No remove?
//EditorPlugins::remove_by_type<VoxelGraphEditorPlugin>();
#endif
}