From dfc03839dbfa0910479aa77402c9c83f03b0d9d0 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 11 Nov 2022 22:18:32 +0800 Subject: [PATCH] Renamed functions for clarity --- SHADE_Managed/src/Editor/Editor.cxx | 68 ++++++++++++++--------------- SHADE_Managed/src/Editor/Editor.h++ | 18 ++++---- SHADE_Managed/src/Editor/Editor.hxx | 29 +++++++++--- 3 files changed, 67 insertions(+), 48 deletions(-) diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index ef5557c6..d26bd252 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -153,28 +153,28 @@ namespace SHADE bool isHovered = false; const bool MODIFIED_PRIMITIVE = - renderFieldInInspector(field, object, SHEditorUI::InputInt , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputInt , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputInt , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputInt , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputInt , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputInt , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputInt , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputCheckbox, &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputFloat , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputDouble , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputVec2 , &isHovered) || - renderFieldInInspector(field, object, SHEditorUI::InputVec3 , &isHovered) || - renderFieldInInspector(field, object, nullptr , &isHovered) || - renderFieldInInspector(field, object, nullptr , &isHovered) || - renderFieldInInspector(field, object, nullptr , &isHovered); + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputCheckbox, &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputFloat , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputDouble , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputVec2 , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputVec3 , &isHovered) || + renderSpecificField(field, object, nullptr , &isHovered) || + renderSpecificField(field, object, nullptr , &isHovered) || + renderSpecificField(field, object, nullptr , &isHovered); if (!MODIFIED_PRIMITIVE) { // Any List if (field->FieldType->IsGenericType && field->FieldType->GetGenericTypeDefinition() == System::Collections::Generic::List::typeid->GetGenericTypeDefinition()) { - System::Type^ listType = field->FieldType->GenericTypeArguments[0]; + /* System::Type^ listType = field->FieldType->GenericTypeArguments[0]; RangeAttribute^ rangeAttrib = hasAttribute(field); System::Collections::IList^ iList = safe_cast(field->GetValue(object)); @@ -193,7 +193,7 @@ namespace SHADE SHEditorUI::SameLine(); SHEditorUI::Button("-"); } - SHEditorUI::Unindent(); + SHEditorUI::Unindent();*/ } else { @@ -277,29 +277,29 @@ namespace SHADE } } - bool Editor::renderFieldInInspector(const std::string& fieldName, System::Object^% object, RangeAttribute^ rangeAttrib) + bool Editor::renderFieldEditor(const std::string& fieldName, System::Object^% object, RangeAttribute^ rangeAttrib) { const bool MODIFIED_PRIMITIVE = - renderFieldInInspector(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputCheckbox, nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputFloat , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputDouble , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputVec2 , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, SHEditorUI::InputVec3 , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, nullptr , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, nullptr , nullptr, rangeAttrib) || - renderFieldInInspector(fieldName, object, nullptr , nullptr, rangeAttrib); + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputCheckbox, nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputFloat , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputDouble , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputVec2 , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, SHEditorUI::InputVec3 , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib) || + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib); return MODIFIED_PRIMITIVE; } - bool Editor::renderEnumFieldInInspector(const std::string& fieldName, System::Object^% object, bool* isHovered) + bool Editor::renderEnumEditor(const std::string& fieldName, System::Object^% object, bool* isHovered) { // Get all the names of the enums const array^ ENUM_NAMES = object->GetType()->GetEnumNames(); diff --git a/SHADE_Managed/src/Editor/Editor.h++ b/SHADE_Managed/src/Editor/Editor.h++ index ead03f49..8fbc6348 100644 --- a/SHADE_Managed/src/Editor/Editor.h++ +++ b/SHADE_Managed/src/Editor/Editor.h++ @@ -24,7 +24,7 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { template - bool Editor::renderFieldInInspector(System::Reflection::FieldInfo^ fieldInfo, System::Object^ object, EditorFieldFunc fieldEditor, bool* isHovered) + bool Editor::renderSpecificField(System::Reflection::FieldInfo^ fieldInfo, System::Object^ object, EditorFieldFunc fieldEditor, bool* isHovered) { if constexpr (std::is_same_v) { @@ -33,7 +33,7 @@ namespace SHADE System::Object^ enumObj = fieldInfo->GetValue(object); int oldVal = safe_cast(enumObj); int val = oldVal; - if (renderEnumFieldInInspector + if (renderEnumEditor ( Convert::ToNative(fieldInfo->Name), enumObj, @@ -59,7 +59,7 @@ namespace SHADE ManagedType oldVal = safe_cast(fieldInfo->GetValue(object)); ManagedType val = oldVal; - if (renderFieldInInspector + if (renderFieldEditorInternal ( Convert::ToNative(fieldInfo->Name), &val, @@ -80,14 +80,14 @@ namespace SHADE } template - bool Editor::renderFieldInInspector(const std::string& fieldName, System::Object^% object, EditorFieldFunc fieldEditor, bool* isHovered, RangeAttribute^ rangeAttrib) + bool Editor::renderFieldEditor(const std::string& fieldName, System::Object^% object, EditorFieldFunc fieldEditor, bool* isHovered, RangeAttribute^ rangeAttrib) { if constexpr (std::is_same_v) { if (object->GetType()->IsSubclassOf(Enum::typeid)) { int managedVal = safe_cast(object); - if (renderFieldInInspector(fieldName, &managedVal, fieldEditor, isHovered, rangeAttrib)) + if (renderFieldEditorInternal(fieldName, &managedVal, fieldEditor, isHovered, rangeAttrib)) { object = managedVal; } @@ -100,7 +100,7 @@ namespace SHADE { ManagedType managedVal = safe_cast(object); cli::interior_ptr managedValPtr = &managedVal; - if (renderFieldInInspector(fieldName, managedValPtr, fieldEditor, isHovered, rangeAttrib)) + if (renderFieldEditorInternal(fieldName, managedValPtr, fieldEditor, isHovered, rangeAttrib)) { object = managedVal; return true; @@ -114,7 +114,7 @@ namespace SHADE template - bool Editor::renderFieldInInspector(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc fieldEditor, bool* isHovered, RangeAttribute^ rangeAttrib) + bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc fieldEditor, bool* isHovered, RangeAttribute^ rangeAttrib) { // Retrieve the native version of the object NativeType val; @@ -167,7 +167,7 @@ namespace SHADE return false; } template<> - bool Editor::renderFieldInInspector(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) + bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) { // Prevent issues where String^ is null due to being empty if (*managedValPtr == nullptr) @@ -184,7 +184,7 @@ namespace SHADE return false; } template<> - bool Editor::renderFieldInInspector(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) + bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) { uint32_t entityId = managedValPtr->GetEntity(); if (SHEditorUI::InputGameObjectField(fieldName, entityId, isHovered, !(*managedValPtr))) diff --git a/SHADE_Managed/src/Editor/Editor.hxx b/SHADE_Managed/src/Editor/Editor.hxx index f9bf751f..54ab128d 100644 --- a/SHADE_Managed/src/Editor/Editor.hxx +++ b/SHADE_Managed/src/Editor/Editor.hxx @@ -90,8 +90,8 @@ namespace SHADE /// The object that contains the data of the field to render. /// static void renderFieldInInspector(System::Reflection::FieldInfo^ field, System::Object^ object); - static bool renderFieldInInspector(const std::string& fieldName, System::Object^% object, RangeAttribute^ rangeAttrib); - static bool renderEnumFieldInInspector(const std::string& fieldName, System::Object^% object, bool* isHovered); + static bool renderFieldEditor(const std::string& fieldName, System::Object^% object, RangeAttribute^ rangeAttrib); + static bool renderEnumEditor(const std::string& fieldName, System::Object^% object, bool* isHovered); /// /// Checks if the specified field is of the specified native and managed type /// equivalent and renders a ImGui field editor based on the specified field @@ -107,7 +107,7 @@ namespace SHADE /// /// True if the field is modified. template - static bool renderFieldInInspector(System::Reflection::FieldInfo^ fieldInfo, System::Object^ object, EditorFieldFunc fieldEditor, bool* isHovered); + static bool renderSpecificField(System::Reflection::FieldInfo^ fieldInfo, System::Object^ object, EditorFieldFunc fieldEditor, bool* isHovered); /// /// Renders a ImGui field editor based on the type of parameters specified. /// @@ -127,9 +127,28 @@ namespace SHADE /// /// True if the field is modified. template - static bool renderFieldInInspector(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc fieldEditor, bool* isHovered, RangeAttribute^ rangeAttrib); + static bool renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc fieldEditor, bool* isHovered, RangeAttribute^ rangeAttrib); + /// + /// Renders a ImGui field editor based on the type of parameters specified. + /// + /// Native type of the field. + /// Managed type of the field. + /// Label to use for the field editor. + /// + /// Tracking reference for the managed variable to modify. + /// + /// ImGui field editor function to use. + /// + /// Pointer to a bool that stores if the field editor was hovered over. + /// + /// + /// If provided and the type supports it, the field will be rendered with a + /// slider instead. + /// + /// True if the field is modified. template - static bool renderFieldInInspector(const std::string& fieldName, System::Object^% object, EditorFieldFunc fieldEditor, bool* isHovered, RangeAttribute^ rangeAttrib); + static bool renderFieldEditor(const std::string& fieldName, System::Object^% object, EditorFieldFunc fieldEditor, bool* isHovered, RangeAttribute^ rangeAttrib); + /// /// Renders a context menu when right clicked for the scripts ///