From c9978d13ba5a0df8ac2b28124c4351055344b95e Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 27 Feb 2020 21:37:50 +0100 Subject: [PATCH] Ported PropToolProp aswell. --- SCsub | 3 +- prop_tool/prop_tool_prop.cpp | 95 ++++++++++++++++++++++++++++++++++++ prop_tool/prop_tool_prop.h | 60 +++++++++++++++++++++++ register_types.cpp | 2 + 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 prop_tool/prop_tool_prop.cpp create mode 100644 prop_tool/prop_tool_prop.h diff --git a/SCsub b/SCsub index 23a663e..a81b167 100644 --- a/SCsub +++ b/SCsub @@ -58,7 +58,8 @@ sources = [ "world/voxel_world_editor.cpp", - "prop_tool/prop_tool_scene.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", diff --git a/prop_tool/prop_tool_prop.cpp b/prop_tool/prop_tool_prop.cpp new file mode 100644 index 0000000..52b0776 --- /dev/null +++ b/prop_tool/prop_tool_prop.cpp @@ -0,0 +1,95 @@ +/* +Copyright (c) 2020 Péter Magyar + +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 "prop_tool_prop.h" + +Ref PropToolProp::get_data() { + if (!is_visible() || !_prop_data.is_valid()) + return Ref(); + + if (!_prop_data.is_valid()) + _prop_data.instance(); + + _prop_prop->set_prop(_prop_data); + _prop_prop->set_snap_to_mesh(_snap_to_mesh); + _prop_prop->set_snap_axis(_snap_axis); + + return _prop_prop; +} +void PropToolProp::set_data(const Ref &data) { + _prop_prop = data; + + if (!_prop_prop.is_valid()) + return; + + _prop_data = _prop_prop->get_prop(); + _snap_to_mesh = _prop_prop->get_snap_to_mesh(); + _snap_axis = _prop_prop->get_snap_axis(); +} + +Ref PropToolProp::get_prop_data() { + return _prop_data; +} +void PropToolProp::set_prop_data(const Ref &data) { + _prop_data = data; +} + +bool PropToolProp::get_snap_to_mesh() const { + return _snap_to_mesh; +} +void PropToolProp::set_snap_to_mesh(const bool value) { + _snap_to_mesh = value; +} + +Vector3 PropToolProp::get_snap_axis() const { + return _snap_axis; +} +void PropToolProp::set_snap_axis(const Vector3 &value) { + _snap_axis = value; +} + +PropToolProp::PropToolProp() { + _snap_to_mesh = false; + _snap_axis = Vector3(0, -1, 0); +} +PropToolProp::~PropToolProp() { + _prop_data.unref(); + _prop_prop.unref(); +} + +void PropToolProp::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_data"), &PropToolProp::get_data); + ClassDB::bind_method(D_METHOD("set_data", "value"), &PropToolProp::set_data); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PropDataProp"), "set_data", "get_data"); + + ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropToolProp::get_snap_to_mesh); + ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropToolProp::set_snap_to_mesh); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh"); + + ClassDB::bind_method(D_METHOD("get_snap_axis"), &PropToolProp::get_snap_axis); + ClassDB::bind_method(D_METHOD("set_snap_axis", "value"), &PropToolProp::set_snap_axis); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "snap_axis"), "set_snap_axis", "get_snap_axis"); + + ClassDB::bind_method(D_METHOD("get_prop_data"), &PropToolProp::get_prop_data); + ClassDB::bind_method(D_METHOD("set_prop_data", "value"), &PropToolProp::set_prop_data); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_data", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "set_prop_data", "get_prop_data"); +} diff --git a/prop_tool/prop_tool_prop.h b/prop_tool/prop_tool_prop.h new file mode 100644 index 0000000..091fae4 --- /dev/null +++ b/prop_tool/prop_tool_prop.h @@ -0,0 +1,60 @@ +/* +Copyright (c) 2020 Péter Magyar + +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 PROP_TOOL_PROP_H +#define PROP_TOOL_PROP_H + +#include "scene/3d/spatial.h" + +#include "../props/prop_data.h" +#include "../props/prop_data_prop.h" + +class PropToolProp : public Spatial { + GDCLASS(PropToolProp, Spatial); + +public: + Ref get_data(); + void set_data(const Ref &data); + + Ref get_prop_data(); + void set_prop_data(const Ref &data); + + bool get_snap_to_mesh() const; + void set_snap_to_mesh(const bool value); + + Vector3 get_snap_axis() const; + void set_snap_axis(const Vector3 &value); + + PropToolProp(); + ~PropToolProp(); + +protected: + static void _bind_methods(); + +private: + Ref _prop_data; + bool _snap_to_mesh; + Vector3 _snap_axis; + Ref _prop_prop; +}; + +#endif diff --git a/register_types.cpp b/register_types.cpp index 05a9431..3d7cd14 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -66,6 +66,7 @@ SOFTWARE. #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" @@ -110,6 +111,7 @@ void register_voxelman_types() { ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class();