List Serialization and Editor for Scripts #193
|
@ -18,12 +18,9 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Editor/Editor.hxx"
|
#include "Editor/Editor.hxx"
|
||||||
// STL Includes
|
// STL Includes
|
||||||
#include <memory>
|
#include <memory>
|
||||||
// External Dependencies
|
|
||||||
#include "Editor/SHEditorUI.h"
|
|
||||||
// Project Headers
|
// Project Headers
|
||||||
#include "Components/Component.hxx"
|
#include "Components/Component.hxx"
|
||||||
#include "Scripts/ScriptStore.hxx"
|
#include "Scripts/ScriptStore.hxx"
|
||||||
#include "Utility/Convert.hxx"
|
|
||||||
#include "Utility/Debug.hxx"
|
#include "Utility/Debug.hxx"
|
||||||
#include "Serialisation/ReflectionUtilities.hxx"
|
#include "Serialisation/ReflectionUtilities.hxx"
|
||||||
#include "Editor/IconsMaterialDesign.h"
|
#include "Editor/IconsMaterialDesign.h"
|
||||||
|
@ -154,18 +151,20 @@ namespace SHADE
|
||||||
bool isHovered = false;
|
bool isHovered = false;
|
||||||
|
|
||||||
const bool MODIFIED_PRIMITIVE =
|
const bool MODIFIED_PRIMITIVE =
|
||||||
renderFieldInInspector<int , Int16 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
renderFieldInInspector<int , Int16 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
||||||
renderFieldInInspector<int , Int32 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
renderFieldInInspector<int , Int32 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
||||||
renderFieldInInspector<int , Int64 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
renderFieldInInspector<int , Int64 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
||||||
renderFieldInInspector<int , UInt16 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
renderFieldInInspector<int , UInt16 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
||||||
renderFieldInInspector<int , UInt32 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
renderFieldInInspector<int , UInt32 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
||||||
renderFieldInInspector<int , UInt64 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
renderFieldInInspector<int , UInt64 >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
||||||
renderFieldInInspector<int , Byte >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
renderFieldInInspector<int , Byte >(field, object, SHEditorUI::InputInt , &isHovered) ||
|
||||||
renderFieldInInspector<bool , bool >(field, object, SHEditorUI::InputCheckbox, &isHovered) ||
|
renderFieldInInspector<bool , bool >(field, object, SHEditorUI::InputCheckbox, &isHovered) ||
|
||||||
renderFieldInInspector<float , float >(field, object, SHEditorUI::InputFloat , &isHovered) ||
|
renderFieldInInspector<float , float >(field, object, SHEditorUI::InputFloat , &isHovered) ||
|
||||||
renderFieldInInspector<double, double >(field, object, SHEditorUI::InputDouble , &isHovered) ||
|
renderFieldInInspector<double , double >(field, object, SHEditorUI::InputDouble , &isHovered) ||
|
||||||
renderFieldInInspector<SHVec2, Vector2>(field, object, SHEditorUI::InputVec2 , &isHovered) ||
|
renderFieldInInspector<SHVec2 , Vector2 >(field, object, SHEditorUI::InputVec2 , &isHovered) ||
|
||||||
renderFieldInInspector<SHVec3, Vector3>(field, object, SHEditorUI::InputVec3 , &isHovered);
|
renderFieldInInspector<SHVec3 , Vector3 >(field, object, SHEditorUI::InputVec3 , &isHovered) ||
|
||||||
|
renderFieldInInspector<uint32_t , GameObject >(field, object, nullptr , &isHovered) ||
|
||||||
|
renderFieldInInspector<std::string, System::String^>(field, object, nullptr , &isHovered);
|
||||||
|
|
||||||
if (!MODIFIED_PRIMITIVE)
|
if (!MODIFIED_PRIMITIVE)
|
||||||
{
|
{
|
||||||
|
@ -187,40 +186,6 @@ namespace SHADE
|
||||||
registerUndoAction(object, field, val, oldVal);
|
registerUndoAction(object, field, val, oldVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (field->FieldType == String::typeid)
|
|
||||||
{
|
|
||||||
// Prevent issues where String^ is null due to being empty
|
|
||||||
String^ stringVal = safe_cast<String^>(field->GetValue(object));
|
|
||||||
if (stringVal == nullptr)
|
|
||||||
{
|
|
||||||
stringVal = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actual Field
|
|
||||||
std::string val = Convert::ToNative(stringVal);
|
|
||||||
std::string oldVal = val;
|
|
||||||
if (SHEditorUI::InputTextField(Convert::ToNative(field->Name), val, &isHovered))
|
|
||||||
{
|
|
||||||
field->SetValue(object, Convert::ToCLI(val));
|
|
||||||
registerUndoAction(object, field, Convert::ToCLI(val), Convert::ToCLI(oldVal));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (field->FieldType == GameObject::typeid)
|
|
||||||
{
|
|
||||||
GameObject gameObj = safe_cast<GameObject>(field->GetValue(object));
|
|
||||||
uint32_t entityId = gameObj.GetEntity();
|
|
||||||
if (SHEditorUI::InputGameObjectField(Convert::ToNative(field->Name), entityId, &isHovered, !gameObj))
|
|
||||||
{
|
|
||||||
GameObject newVal = GameObject(entityId);
|
|
||||||
if (entityId != MAX_EID)
|
|
||||||
{
|
|
||||||
// Null GameObject set
|
|
||||||
newVal = GameObject(entityId);
|
|
||||||
}
|
|
||||||
field->SetValue(object, newVal);
|
|
||||||
registerUndoAction(object, field, newVal, gameObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Any List
|
// Any List
|
||||||
else if (field->FieldType->IsGenericType && field->FieldType->GetGenericTypeDefinition() == System::Collections::Generic::List<int>::typeid->GetGenericTypeDefinition())
|
else if (field->FieldType->IsGenericType && field->FieldType->GetGenericTypeDefinition() == System::Collections::Generic::List<int>::typeid->GetGenericTypeDefinition())
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,10 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
// Primary Include
|
// Primary Include
|
||||||
#include "Editor.hxx"
|
#include "Editor.hxx"
|
||||||
|
// External Dependencies
|
||||||
|
#include "Editor/SHEditorUI.h"
|
||||||
|
// Project Includes
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -102,6 +106,41 @@ namespace SHADE
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
bool Editor::renderFieldInInspector<std::string, System::String^>(const std::string& fieldName, System::String^% managedVal, EditorFieldFunc<std::string>, bool* isHovered, RangeAttribute^)
|
||||||
|
{
|
||||||
|
// Prevent issues where String^ is null due to being empty
|
||||||
|
if (managedVal == nullptr)
|
||||||
|
managedVal = "";
|
||||||
|
|
||||||
|
// Actual Field
|
||||||
|
std::string val = Convert::ToNative(managedVal);
|
||||||
|
if (SHEditorUI::InputTextField(fieldName, val, isHovered))
|
||||||
|
{
|
||||||
|
managedVal = Convert::ToCLI(val);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
bool Editor::renderFieldInInspector<uint32_t, GameObject>(const std::string& fieldName, GameObject% managedVal, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
|
||||||
|
{
|
||||||
|
uint32_t entityId = managedVal.GetEntity();
|
||||||
|
if (SHEditorUI::InputGameObjectField(fieldName, entityId, isHovered, !managedVal))
|
||||||
|
{
|
||||||
|
GameObject newVal = GameObject(entityId);
|
||||||
|
if (entityId != MAX_EID)
|
||||||
|
{
|
||||||
|
// Null GameObject set
|
||||||
|
newVal = GameObject(entityId);
|
||||||
|
}
|
||||||
|
managedVal = newVal;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue