mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-14 10:17:20 +01:00
Lots of work on porting PropTool, and the editor plugin itself.
This commit is contained in:
parent
6178cf92d6
commit
2bf00fd547
@ -1,7 +1,18 @@
|
||||
#include "prop_tool.h"
|
||||
|
||||
#include "../props/prop_data.h"
|
||||
#include "../props/prop_data_entity.h"
|
||||
#include "../props/prop_data_light.h"
|
||||
#include "../props/prop_data_mesh.h"
|
||||
#include "../props/prop_data_prop.h"
|
||||
#include "../props/prop_data_scene.h"
|
||||
|
||||
#include "prop_tool_entity.h"
|
||||
#include "prop_tool_light.h"
|
||||
#include "prop_tool_mesh.h"
|
||||
#include "prop_tool_prop.h"
|
||||
#include "prop_tool_scene.h"
|
||||
|
||||
#include "core/io/resource_saver.h"
|
||||
#include "prop_tool_editor_plugin.h"
|
||||
|
||||
@ -68,60 +79,65 @@ void PropTool::save_node(Node *node, Transform parent_transform) {
|
||||
}
|
||||
|
||||
void PropTool::rebuild_hierarchy() {
|
||||
/*
|
||||
for ch in get_children():
|
||||
ch.queue_free()
|
||||
|
||||
if target_prop == null:
|
||||
return
|
||||
|
||||
snap_to_mesh = target_prop.snap_to_mesh
|
||||
snap_axis = target_prop.snap_axis
|
||||
|
||||
for i in range(target_prop.get_prop_count()):
|
||||
print(i)
|
||||
var prop : PropDataEntry = target_prop.get_prop(i)
|
||||
|
||||
if prop is PropDataLight:
|
||||
var l : PropToolLight = PropToolLight.new()
|
||||
|
||||
add_child(l)
|
||||
l.owner = self
|
||||
l.transform = prop.transform
|
||||
|
||||
l.set_data(prop as PropDataLight)
|
||||
elif prop is PropDataMesh:
|
||||
var m : PropToolMesh = PropToolMesh.new()
|
||||
|
||||
add_child(m)
|
||||
m.owner = self
|
||||
m.transform = prop.transform
|
||||
|
||||
m.set_data(prop as PropDataMesh)
|
||||
elif prop is PropDataScene:
|
||||
var s : PropToolScene = PropToolScene.new()
|
||||
|
||||
add_child(s)
|
||||
s.owner = self
|
||||
s.transform = prop.transform
|
||||
|
||||
s.set_data(prop as PropDataScene)
|
||||
elif prop is PropDataProp:
|
||||
var s : Node = plugin.create_or_get_scene(prop.prop)
|
||||
|
||||
add_child(s)
|
||||
s.owner = self
|
||||
s.transform = prop.transform
|
||||
#s.set_target_prop(prop.prop)
|
||||
elif prop is PropDataEntity:
|
||||
var s : PropToolEntity = PropToolEntity.new()
|
||||
|
||||
add_child(s)
|
||||
s.owner = self
|
||||
s.transform = prop.transform
|
||||
|
||||
s.set_data(prop as PropDataEntity)
|
||||
*/
|
||||
for (int i = 0; i < get_child_count(); ++i)
|
||||
get_child(i)->queue_delete();
|
||||
|
||||
if (!_target_prop.is_valid())
|
||||
return;
|
||||
|
||||
_snap_to_mesh = _target_prop->get_snap_to_mesh();
|
||||
_snap_axis = _target_prop->get_snap_axis();
|
||||
|
||||
for (int i = 0; i < _target_prop->get_prop_count(); ++i) {
|
||||
Ref<PropDataEntry> prop = _target_prop->get_prop(i);
|
||||
|
||||
Ref<PropDataLight> prop_light = prop;
|
||||
Ref<PropDataMesh> prop_mesh = prop;
|
||||
Ref<PropDataScene> prop_scene = prop;
|
||||
Ref<PropDataProp> prop_prop = prop;
|
||||
Ref<PropDataEntity> prop_entity = prop;
|
||||
|
||||
if (prop_light.is_valid()) {
|
||||
PropToolLight *l = memnew(PropToolLight);
|
||||
|
||||
add_child(l);
|
||||
l->set_owner(this);
|
||||
l->set_transform(prop->get_transform());
|
||||
|
||||
l->set_data(prop_light);
|
||||
} else if (prop_mesh.is_valid()) {
|
||||
PropToolMesh *m = memnew(PropToolMesh);
|
||||
|
||||
add_child(m);
|
||||
m->set_owner(this);
|
||||
m->set_transform(prop->get_transform());
|
||||
|
||||
m->set_data(prop_mesh);
|
||||
} else if (prop_scene.is_valid()) {
|
||||
PropToolScene *s = memnew(PropToolScene);
|
||||
|
||||
add_child(s);
|
||||
s->set_owner(this);
|
||||
s->set_transform(prop->get_transform());
|
||||
|
||||
s->set_data(prop_scene);
|
||||
} else if (prop_prop.is_valid()) {
|
||||
PropTool *s = _plugin->create_or_get_scene(prop_prop->get_prop());
|
||||
|
||||
add_child(s);
|
||||
s->set_owner(this);
|
||||
s->set_transform(prop->get_transform());
|
||||
s->set_target_prop(prop_prop->get_prop());
|
||||
} else if (prop_entity.is_valid()) {
|
||||
PropToolEntity *s = memnew(PropToolEntity);
|
||||
|
||||
add_child(s);
|
||||
s->set_owner(this);
|
||||
s->set_transform(prop->get_transform());
|
||||
|
||||
s->set_data(prop_entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropTool::refresh_set(bool value) {
|
||||
@ -167,9 +183,9 @@ void PropTool::load_scene_for(PropTool *t, const Ref<PropData> &prop) {
|
||||
|
||||
t->queue_delete();
|
||||
|
||||
//Node *s = _plugin->create_or_get_scene(prop);
|
||||
Node *s = _plugin->create_or_get_scene(prop);
|
||||
|
||||
//add_child(s);
|
||||
add_child(s);
|
||||
//s->set_owner(this);
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ class PropData;
|
||||
#include "scene/3d/spatial.h"
|
||||
|
||||
class propData;
|
||||
class PropToolEditorPlugin;
|
||||
|
||||
class PropTool : public Spatial {
|
||||
GDCLASS(PropTool, Spatial);
|
||||
@ -60,7 +61,7 @@ private:
|
||||
Ref<PropData> _target_prop;
|
||||
bool _snap_to_mesh;
|
||||
Vector3 _snap_axis;
|
||||
EditorPlugin *_plugin;
|
||||
PropToolEditorPlugin *_plugin;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -24,65 +24,286 @@ SOFTWARE.
|
||||
|
||||
#include "editor/editor_scale.h"
|
||||
|
||||
void PropDataEditor::edit(const Ref<PropData> &prop) {
|
||||
void PropToolEditorPlugin::edit(Object *p_object) {
|
||||
Ref<PropData> pedited_prop(p_object);
|
||||
|
||||
String p = create_or_get_scene_path(pedited_prop);
|
||||
|
||||
get_editor_interface()->open_scene_from_path(p);
|
||||
}
|
||||
|
||||
|
||||
void PropDataEditor::_bind_methods() {
|
||||
}
|
||||
|
||||
PropDataEditor::PropDataEditor(EditorNode *p_editor) {
|
||||
set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
set_custom_minimum_size(Size2(0, 200) * EDSCALE);
|
||||
|
||||
Tree *tree = memnew(Tree);
|
||||
tree->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
|
||||
add_child(tree);
|
||||
|
||||
ViewportContainer *container = memnew(ViewportContainer);
|
||||
container->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
container->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
container->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
add_child(container);
|
||||
|
||||
Viewport *viewport = memnew(Viewport);
|
||||
viewport->set_size(Size2(400, 400));
|
||||
container->add_child(viewport);
|
||||
|
||||
set_split_offset(200 * EDSCALE);
|
||||
}
|
||||
PropDataEditor::~PropDataEditor() {
|
||||
}
|
||||
|
||||
void PropDataEditorPlugin::edit(Object *p_object) {
|
||||
}
|
||||
|
||||
bool PropDataEditorPlugin::handles(Object *p_object) const {
|
||||
bool PropToolEditorPlugin::handles(Object *p_object) const {
|
||||
|
||||
bool handles = p_object->is_class("PropData");
|
||||
|
||||
if (handles) {
|
||||
prop_editor_button->show();
|
||||
light_button->show();
|
||||
mesh_button->show();
|
||||
prop_button->show();
|
||||
scene_button->show();
|
||||
entity_button->show();
|
||||
|
||||
} else {
|
||||
prop_editor_button->hide();
|
||||
light_button->hide();
|
||||
mesh_button->hide();
|
||||
prop_button->hide();
|
||||
scene_button->hide();
|
||||
entity_button->hide();
|
||||
}
|
||||
|
||||
return handles;
|
||||
}
|
||||
|
||||
void PropDataEditorPlugin::make_visible(bool p_visible) {
|
||||
void PropToolEditorPlugin::make_visible(bool p_visible) {
|
||||
}
|
||||
|
||||
PropDataEditorPlugin::PropDataEditorPlugin(EditorNode *p_node) {
|
||||
String PropToolEditorPlugin::create_or_get_scene_path(const Ref<PropData> &data) {
|
||||
|
||||
String path = temp_path + data->get_path().get_file().get_basename() + ".tscn";
|
||||
|
||||
//Directory dir : Directory = Directory.new()
|
||||
|
||||
//if not dir.file_exists(path):
|
||||
// create_scene(data)
|
||||
|
||||
return path
|
||||
}
|
||||
PropTool *PropToolEditorPlugin::create_or_get_scene(const Ref<PropData> &data) {
|
||||
/*
|
||||
ERR_FAIL_COND_V(!data.is_valid(), NULL);
|
||||
|
||||
String path = temp_path + data->get_path().get_file().get_basename() + ".tscn";
|
||||
|
||||
var dir : Directory = Directory.new();
|
||||
|
||||
Ref<PackedScene> ps;
|
||||
|
||||
if not dir.file_exists(path):;
|
||||
ps = create_scene(data);
|
||||
else:;
|
||||
ps = ResourceLoader.load(path, "PackedScene");
|
||||
|
||||
if ps == null:;
|
||||
return null;
|
||||
|
||||
var pt : PropTool = ps.instance() as PropTool;
|
||||
pt.plugin = self;
|
||||
return pt;
|
||||
*/
|
||||
|
||||
return NULL;
|
||||
}
|
||||
Ref<PackedScene> PropToolEditorPlugin::create_scene(const Ref<PropData> &data) {
|
||||
/*
|
||||
func create_scene(data: PropData) -> PackedScene:
|
||||
var pt : PropTool = PropTool.new()
|
||||
|
||||
pt.plugin = self
|
||||
pt.set_target_prop(data)
|
||||
|
||||
var ps : PackedScene = PackedScene.new()
|
||||
ps.pack(pt)
|
||||
|
||||
var err = ResourceSaver.save(temp_path + data.resource_path.get_file().get_basename() + ".tscn", ps)
|
||||
|
||||
pt.queue_free()
|
||||
return ps
|
||||
|
||||
*/
|
||||
|
||||
return Ref<PackedScene>();
|
||||
}
|
||||
|
||||
PropToolEditorPlugin::PropToolEditorPlugin(EditorNode *p_node) {
|
||||
temp_path = "res://addons/prop_tool/scenes/temp/";
|
||||
|
||||
editor = p_node;
|
||||
|
||||
prop_editor = memnew(PropDataEditor(editor));
|
||||
light_button = memnew(ToolButton);
|
||||
light_button->set_text("Light");
|
||||
light_button->connect("pressed", this, "add_light");
|
||||
|
||||
prop_editor_button = add_control_to_bottom_panel(prop_editor, "Prop");
|
||||
mesh_button = memnew(ToolButton);
|
||||
mesh_button->set_text("Mesh");
|
||||
mesh_button->connect("pressed", this, "add_mesh");
|
||||
|
||||
prop_editor->hide();
|
||||
prop_button = memnew(ToolButton);
|
||||
prop_button->set_text("Prop");
|
||||
prop_button->connect("pressed", this, "add_prop");
|
||||
|
||||
scene_button = memnew(ToolButton);
|
||||
scene_button->set_text("Scene");
|
||||
scene_button->connect("pressed", this, "add_scene");
|
||||
|
||||
entity_button = memnew(ToolButton);
|
||||
entity_button->set_text("Entity");
|
||||
entity_button->connect("pressed", this, "add_entity");
|
||||
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, light_button);
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, mesh_button);
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, prop_button);
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, scene_button);
|
||||
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, entity_button);
|
||||
|
||||
light_button->hide();
|
||||
mesh_button->hide();
|
||||
prop_button->hide();
|
||||
scene_button->hide();
|
||||
entity_button->hide();
|
||||
|
||||
//connect("scene_changed", this, "scene_changed");
|
||||
}
|
||||
|
||||
PropDataEditorPlugin::~PropDataEditorPlugin() {
|
||||
PropToolEditorPlugin::~PropToolEditorPlugin() {
|
||||
_edited_prop.unref();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
func scene_changed(scene):
|
||||
if scene.has_method("set_target_prop"):
|
||||
scene.plugin = self
|
||||
|
||||
if not buttons_added:
|
||||
light_button.show()
|
||||
mesh_button.show()
|
||||
prop_button.show()
|
||||
scene_button.show()
|
||||
entity_button.show()
|
||||
# add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, light_button)
|
||||
# add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, mesh_button)
|
||||
# add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, prop_button)
|
||||
# add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, scene_button)
|
||||
# add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, entity_button)
|
||||
|
||||
buttons_added = true
|
||||
else:
|
||||
if buttons_added:
|
||||
light_button.hide()
|
||||
mesh_button.hide()
|
||||
prop_button.hide()
|
||||
scene_button.hide()
|
||||
entity_button.hide()
|
||||
#
|
||||
# remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, light_button)
|
||||
# remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, mesh_button)
|
||||
# remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, prop_button)
|
||||
# remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, scene_button)
|
||||
# remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, entity_button)
|
||||
|
||||
buttons_added = false
|
||||
|
||||
func apply_changes() -> void:
|
||||
var scene : Node = get_editor_interface().get_edited_scene_root()
|
||||
|
||||
if scene is PropTool:
|
||||
# if scene.has_method("set_target_prop") and scene.has_method("save"):
|
||||
scene.save()
|
||||
|
||||
|
||||
|
||||
func add_light():
|
||||
var selection : Array = get_editor_interface().get_selection().get_selected_nodes()
|
||||
var selected : Node
|
||||
|
||||
if selection.size() != 1:
|
||||
selected = get_editor_interface().get_edited_scene_root()
|
||||
else:
|
||||
selected = selection[0]
|
||||
|
||||
var s : Node = selected
|
||||
var n = PropToolLight.new()
|
||||
|
||||
var u : UndoRedo = get_undo_redo()
|
||||
u.create_action("Add Light")
|
||||
u.add_do_method(s, "add_child", n)
|
||||
u.add_do_property(n, "owner", get_editor_interface().get_edited_scene_root())
|
||||
u.add_undo_method(s, "remove_child", n)
|
||||
u.commit_action()
|
||||
|
||||
get_editor_interface().get_selection().clear()
|
||||
get_editor_interface().get_selection().add_node(n)
|
||||
|
||||
|
||||
func add_mesh():
|
||||
var selected : Array = get_editor_interface().get_selection().get_selected_nodes()
|
||||
|
||||
if selected.size() != 1:
|
||||
return
|
||||
|
||||
var s : Node = selected[0]
|
||||
var n = PropToolMesh.new()
|
||||
|
||||
var u : UndoRedo = get_undo_redo()
|
||||
u.create_action("Add Mesh")
|
||||
u.add_do_method(s, "add_child", n)
|
||||
u.add_do_property(n, "owner", get_editor_interface().get_edited_scene_root())
|
||||
u.add_undo_method(s, "remove_child", n)
|
||||
u.commit_action()
|
||||
|
||||
get_editor_interface().get_selection().clear()
|
||||
get_editor_interface().get_selection().add_node(n)
|
||||
|
||||
|
||||
func add_prop():
|
||||
var selected : Array = get_editor_interface().get_selection().get_selected_nodes()
|
||||
|
||||
if selected.size() != 1:
|
||||
return
|
||||
|
||||
var s : Node = selected[0]
|
||||
var n = PropTool.new()
|
||||
|
||||
var u : UndoRedo = get_undo_redo()
|
||||
u.create_action("Add Prop")
|
||||
u.add_do_method(s, "add_child", n)
|
||||
u.add_do_property(n, "owner", get_editor_interface().get_edited_scene_root())
|
||||
u.add_undo_method(s, "remove_child", n)
|
||||
u.commit_action()
|
||||
|
||||
get_editor_interface().get_selection().clear()
|
||||
get_editor_interface().get_selection().add_node(n)
|
||||
|
||||
func add_scene():
|
||||
var selected : Array = get_editor_interface().get_selection().get_selected_nodes()
|
||||
|
||||
if selected.size() != 1:
|
||||
return
|
||||
|
||||
var s : Node = selected[0]
|
||||
var n = PropToolScene.new()
|
||||
|
||||
var u : UndoRedo = get_undo_redo()
|
||||
u.create_action("Add Scene")
|
||||
u.add_do_method(s, "add_child", n)
|
||||
u.add_do_property(n, "owner", get_editor_interface().get_edited_scene_root())
|
||||
u.add_undo_method(s, "remove_child", n)
|
||||
u.commit_action()
|
||||
|
||||
get_editor_interface().get_selection().clear()
|
||||
get_editor_interface().get_selection().add_node(n)
|
||||
|
||||
func add_entity():
|
||||
var selected : Array = get_editor_interface().get_selection().get_selected_nodes()
|
||||
|
||||
if selected.size() != 1:
|
||||
return
|
||||
|
||||
var s : Node = selected[0]
|
||||
var n = PropToolEntity.new()
|
||||
|
||||
var u : UndoRedo = get_undo_redo()
|
||||
u.create_action("Add Entity")
|
||||
u.add_do_method(s, "add_child", n)
|
||||
u.add_do_property(n, "owner", get_editor_interface().get_edited_scene_root())
|
||||
u.add_undo_method(s, "remove_child", n)
|
||||
u.commit_action()
|
||||
|
||||
get_editor_interface().get_selection().clear()
|
||||
get_editor_interface().get_selection().add_node(n)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
@ -36,25 +36,8 @@ SOFTWARE.
|
||||
|
||||
#include "editor/plugins/spatial_editor_plugin.h"
|
||||
|
||||
class PropDataEditor : public HSplitContainer {
|
||||
GDCLASS(PropDataEditor, HSplitContainer);
|
||||
|
||||
public:
|
||||
void edit(const Ref<PropData> &prop);
|
||||
|
||||
PropDataEditor() {}
|
||||
PropDataEditor(EditorNode *p_editor);
|
||||
~PropDataEditor();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class PropDataEditorPlugin : public EditorPlugin {
|
||||
|
||||
GDCLASS(PropDataEditorPlugin, EditorPlugin);
|
||||
class PropToolEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(PropToolEditorPlugin, EditorPlugin);
|
||||
|
||||
public:
|
||||
virtual String get_name() const { return "PropData"; }
|
||||
@ -63,14 +46,30 @@ public:
|
||||
virtual bool handles(Object *p_object) const;
|
||||
virtual void make_visible(bool p_visible);
|
||||
|
||||
PropDataEditorPlugin(EditorNode *p_node);
|
||||
~PropDataEditorPlugin();
|
||||
String create_or_get_scene_path(const Ref<PropData> &data);
|
||||
PropTool *create_or_get_scene(const Ref<PropData> &data);
|
||||
Ref<PackedScene> create_scene(const Ref<PropData> &data);
|
||||
|
||||
PropToolEditorPlugin(EditorNode *p_node);
|
||||
~PropToolEditorPlugin();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
private:
|
||||
PropDataEditor *prop_editor;
|
||||
ToolButton *prop_editor_button;
|
||||
String temp_path;
|
||||
|
||||
ToolButton *light_button;
|
||||
ToolButton *mesh_button;
|
||||
ToolButton *prop_button;
|
||||
ToolButton *scene_button;
|
||||
ToolButton *entity_button;
|
||||
|
||||
ToolButton *edited_prop;
|
||||
|
||||
EditorNode *editor;
|
||||
|
||||
Ref<PropData> _edited_prop;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user