More work on porting PropTool.

This commit is contained in:
Relintai 2020-02-29 00:21:59 +01:00
parent 2bf00fd547
commit d8d34d5bce
6 changed files with 58 additions and 52 deletions

3
SCsub
View File

@ -58,12 +58,13 @@ sources = [
"world/voxel_world_editor.cpp",
"prop_tool/prop_tool.cpp",
"prop_tool/prop_tool_entity.cpp",
"prop_tool/prop_tool_prop.cpp",
"prop_tool/prop_tool_scene.cpp",
"prop_tool/prop_tool_light.cpp",
"prop_tool/prop_tool_mesh.cpp",
#"prop_tool/prop_tool_editor_plugin.cpp",
"prop_tool/prop_tool_editor_plugin.cpp",
]
if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes':

View File

@ -151,10 +151,6 @@ void PropTool::set_target_prop(const Ref<PropData> &prop) {
rebuild_hierarchy();
}
void PropTool::get_plugin() {
//return _plugin;
}
void PropTool::target_prop_set(const Ref<PropData> &prop) {
_target_prop = prop;
@ -189,6 +185,14 @@ void PropTool::load_scene_for(PropTool *t, const Ref<PropData> &prop) {
//s->set_owner(this);
}
PropToolEditorPlugin *PropTool::get_plugin() {
return _plugin;
}
void PropTool::set_plugin(PropToolEditorPlugin *plugin) {
_plugin = plugin;
}
PropTool::PropTool() {
_snap_to_mesh = false;
_snap_axis = Vector3(0, -1, 0);
@ -197,3 +201,9 @@ PropTool::PropTool(EditorNode *p_editor) {
_snap_to_mesh = false;
_snap_axis = Vector3(0, -1, 0);
}
PropTool::~PropTool() {
_target_prop.unref();
}
void PropTool::_bind_methods() {
}

View File

@ -45,10 +45,12 @@ public:
void rebuild_hierarchy();
void refresh_set(bool value);
void set_target_prop(const Ref<PropData> &prop);
void get_plugin();
void target_prop_set(const Ref<PropData> &prop);
void load_scene_for(PropTool *t, const Ref<PropData> &prop);
PropToolEditorPlugin *get_plugin();
void set_plugin(PropToolEditorPlugin *plugin);
PropTool();
PropTool(EditorNode *p_editor);
~PropTool();

View File

@ -22,7 +22,11 @@ SOFTWARE.
#include "prop_tool_editor_plugin.h"
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "editor/editor_scale.h"
#include "prop_tool.h"
#include "scene/resources/packed_scene.h"
void PropToolEditorPlugin::edit(Object *p_object) {
Ref<PropData> pedited_prop(p_object);
@ -61,57 +65,44 @@ 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 (!FileAccess::exists(path))
create_scene(data);
//if not dir.file_exists(path):
// create_scene(data)
return path
return path;
}
PropTool *PropToolEditorPlugin::create_or_get_scene(const Ref<PropData> &data) {
/*
ERR_FAIL_COND_V(!data.is_valid(), NULL);
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> ps;
if (!FileAccess::exists(path))
ps = create_scene(data);
else
ps = ResourceLoader::load(path, "PackedScene");
if (!ps.is_valid())
return NULL;
PropTool *pt = Object::cast_to<PropTool>(ps->instance());
pt->set_plugin(this);
return pt;
}
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)
PropTool *pt = memnew(PropTool);
pt.queue_free()
return ps
pt->set_plugin(this);
pt->set_target_prop(data);
*/
Ref<PackedScene> ps;
ps.instance();
ps->pack(pt);
return Ref<PackedScene>();
Error err = ResourceSaver::save(temp_path + data->get_path().get_file().get_basename() + ".tscn", ps);
pt->queue_delete();
return ps;
}
PropToolEditorPlugin::PropToolEditorPlugin(EditorNode *p_node) {

View File

@ -36,6 +36,8 @@ SOFTWARE.
#include "editor/plugins/spatial_editor_plugin.h"
class PropTool;
class PropToolEditorPlugin : public EditorPlugin {
GDCLASS(PropToolEditorPlugin, EditorPlugin);
@ -54,8 +56,6 @@ public:
~PropToolEditorPlugin();
protected:
void _notification(int p_what);
private:
String temp_path;

View File

@ -64,12 +64,13 @@ SOFTWARE.
#include "world/voxel_world_editor.h"
#include "prop_tool/prop_tool.h"
#include "prop_tool/prop_tool_editor_plugin.h"
#include "prop_tool/prop_tool_entity.h"
#include "prop_tool/prop_tool_light.h"
#include "prop_tool/prop_tool_mesh.h"
#include "prop_tool/prop_tool_prop.h"
#include "prop_tool/prop_tool_scene.h"
//#include "prop_tool/prop_tool_editor_plugin.h"
void register_voxelman_types() {
ClassDB::register_class<VoxelmanQueue>();
@ -112,6 +113,7 @@ void register_voxelman_types() {
ClassDB::register_class<GroundClutterFoliage>();
ClassDB::register_class<PropTool>();
ClassDB::register_class<PropToolEntity>();
ClassDB::register_class<PropToolProp>();
ClassDB::register_class<PropToolMesh>();
@ -122,9 +124,9 @@ void register_voxelman_types() {
EditorPlugins::add_by_type<VoxelWorldEditorPlugin>();
#endif
//#ifdef TOOLS_ENABLED
// EditorPlugins::add_by_type<PropToolEditorPlugin>();
//#endif
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<PropToolEditorPlugin>();
#endif
}
void unregister_voxelman_types() {