From 7010e1b688e01d579f32f5f26f4f0c2c5fbe2d61 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 28 Sep 2022 00:06:47 +0800 Subject: [PATCH] Added initial implementation of script inspector --- .../Inspector/SHEditorInspector.cpp | 7 + SHADE_Engine/src/Editor/SHEditorUI.cpp | 628 +++++++----------- SHADE_Engine/src/Editor/SHEditorUI.h | 567 ++++++++-------- SHADE_Engine/src/Editor/SHEditorUI.hpp | 78 +-- SHADE_Engine/src/Scripting/SHScriptEngine.cpp | 78 ++- SHADE_Engine/src/Scripting/SHScriptEngine.h | 2 +- SHADE_Managed/src/Editor/Editor.cxx | 72 +- SHADE_Managed/src/Editor/Editor.hxx | 8 +- TempScriptsFolder/TestScript.cs | 5 +- 9 files changed, 662 insertions(+), 783 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index fba9512e..ed4792de 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -12,6 +12,8 @@ #include "Editor/SHEditorWidgets.hpp" #include "SHEditorComponentView.hpp" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" +#include "Scripting/SHScriptEngine.h" +#include "ECS_Base/Managers/SHSystemManager.h" namespace SHADE { @@ -61,6 +63,11 @@ namespace SHADE DrawAddComponentButton(eid); ImGui::EndMenu(); } + + // Render Scripts + SHScriptEngine* scriptEngine = static_cast(SHSystemManager::GetSystem()); + scriptEngine->RenderScriptsInInspector(eid); + } ImGui::End(); } diff --git a/SHADE_Engine/src/Editor/SHEditorUI.cpp b/SHADE_Engine/src/Editor/SHEditorUI.cpp index cbeb164f..16e06f09 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.cpp +++ b/SHADE_Engine/src/Editor/SHEditorUI.cpp @@ -10,412 +10,276 @@ Reproduction or disclosure of this file or its contents without the prior writte of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ // Precompiled Header -#include +#include "SHpch.h" // Primary Header -#include "Editor/EditorUI.h" +#include "SHEditorUI.h" // External Dependencies #include -// Project Headers -#include "Core/Resource/ResourceManager.h" -#include "Editor/ImGuiExtensions.h" -#include "Editor/Editor.h" -namespace Pls +namespace SHADE { - /*---------------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - ID Stack */ - /*---------------------------------------------------------------------------------*/ - void EditorUI::PushID(const std::string& id) + /*-----------------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - ID Stack */ + /*-----------------------------------------------------------------------------------*/ + void SHEditorUI::PushID(const std::string& id) + { + ImGui::PushID(id.c_str()); + } + + void SHEditorUI::PushID(int id) + { + ImGui::PushID(id); + } + + void SHEditorUI::PopID() + { + ImGui::PopID(); + } + + /*-----------------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Indent */ + /*-----------------------------------------------------------------------------------*/ + void SHEditorUI::Indent() + { + ImGui::Indent(); + } + void SHEditorUI::Unindent() + { + ImGui::Unindent(); + } + + /*-----------------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Organizers */ + /*-----------------------------------------------------------------------------------*/ + bool SHEditorUI::CollapsingHeader(const std::string& title) + { + return ImGui::CollapsingHeader(title.c_str()); + } + + void SHEditorUI::SameLine() + { + ImGui::SameLine(); + } + + void SHEditorUI::Separator() + { + ImGui::Separator(); + } + + bool SHEditorUI::BeginMenu(const std::string& label) + { + return ImGui::BeginMenu(label.data()); + } + + bool SHEditorUI::BeginMenu(const std::string& label, const char* icon) + { + return ImGui::BeginMenu(std::format("{} {}", icon, label.data()).data()); + } + + void SHEditorUI::EndMenu() + { + ImGui::EndMenu(); + } + + /*-----------------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Pop Ups */ + /*-----------------------------------------------------------------------------------*/ + bool SHEditorUI::BeginPopup(const std::string& label) + { + return ImGui::BeginPopup(label.c_str()); + } + + bool SHEditorUI::BeginPopupContextItem(const std::string& label) + { + return ImGui::BeginPopupContextItem(label.data()); + } + + void SHEditorUI::EndPopup() + { + ImGui::EndPopup(); + } + void SHEditorUI::OpenPopup(const std::string& label) + { + ImGui::OpenPopup(label.c_str()); + } + + bool SHEditorUI::MenuItem(const std::string& label) + { + return ImGui::MenuItem(label.c_str()); + } + + /*-----------------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Widgets */ + /*-----------------------------------------------------------------------------------*/ + void SHEditorUI::Text(const std::string& title) + { + ImGui::Text(title.c_str()); + } + bool SHEditorUI::SmallButton(const std::string& title) + { + return ImGui::SmallButton(title.c_str()); + } + bool SHEditorUI::Button(const std::string& title) + { + return ImGui::Button(title.c_str()); + } + + bool SHEditorUI::Selectable(const std::string& label) + { + return ImGui::Selectable(label.data()); + } + + bool SHEditorUI::Selectable(const std::string& label, const char* icon) + { + return ImGui::Selectable(std::format("{} {}", icon, label).data()); + } + + bool SHEditorUI::InputCheckbox(const std::string& label, bool& value) + { + return ImGui::Checkbox(label.c_str(), &value); + } + bool SHEditorUI::InputInt(const std::string& label, int& value) + { + return ImGui::InputInt(label.c_str(), &value, + 1, 10, + ImGuiInputTextFlags_EnterReturnsTrue); + } + bool SHEditorUI::InputUnsignedInt(const std::string& label, unsigned int& value) + { + int signedVal = static_cast(value); + const bool CHANGED = InputInt(label, signedVal); + if (CHANGED) { - ImGui::PushID(id.c_str()); + signedVal = std::clamp(signedVal, 0, std::numeric_limits::max()); + value = static_cast(signedVal); + } + return CHANGED; + } + bool SHEditorUI::InputFloat(const std::string& label, float& value) + { + return ImGui::InputFloat(label.c_str(), &value, + 0.1f, 1.0f, "%.3f", + ImGuiInputTextFlags_EnterReturnsTrue); + } + bool SHEditorUI::InputDouble(const std::string& label, double& value) + { + return ImGui::InputDouble(label.c_str(), &value, + 0.1, 1.0, "%.3f", + ImGuiInputTextFlags_EnterReturnsTrue); + } + bool SHEditorUI::InputAngle(const std::string& label, double& value) + { + return ImGui::InputDouble(label.c_str(), &value, + 1.0, 45.0, "%.3f", + ImGuiInputTextFlags_EnterReturnsTrue); + } + + bool SHEditorUI::InputSlider(const std::string& label, double min, double max, double& value) + { + float val = static_cast(value); + const bool CHANGED = ImGui::SliderFloat(label.c_str(), &val, + static_cast(min), static_cast(max), "%.3f", + ImGuiInputTextFlags_EnterReturnsTrue); + + if (CHANGED) + { + value = val; } - void EditorUI::PushID(int id) - { - ImGui::PushID(id); - } - void EditorUI::PopID() - { - ImGui::PopID(); - } + return CHANGED; + } - /*---------------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Indent */ - /*---------------------------------------------------------------------------------*/ - void EditorUI::Indent() + bool SHEditorUI::InputVec2(const std::string& label, SHVec2& value) + { + float vec[2] = { - ImGui::Indent(); - } - void EditorUI::Unindent() + static_cast(value.x), + static_cast(value.y) + }; + const bool CHANGED = ImGui::InputFloat2(label.c_str(), vec, "%.3f", + ImGuiInputTextFlags_EnterReturnsTrue); + if (CHANGED) { - ImGui::Unindent(); + value.x = vec[0]; + value.y = vec[1]; } + return CHANGED; + } + bool SHEditorUI::InputVec3(const std::string& label, SHVec3& value) + { + float vec[3] = + { + static_cast(value.x), + static_cast(value.y), + static_cast(value.z) + }; + const bool CHANGED = ImGui::InputFloat3(label.c_str(), vec, "%.3f", + ImGuiInputTextFlags_EnterReturnsTrue); + if (CHANGED) + { + value.x = vec[0]; + value.y = vec[1]; + value.z = vec[2]; + } + return CHANGED; + } - /*---------------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Organisers */ - /*---------------------------------------------------------------------------------*/ - bool EditorUI::CollapsingHeader(const std::string& title) + bool SHEditorUI::InputSliderVec3(const std::string& label, double min, double max, SHVec3& value) + { + float vec[3] = { - return ImGui::CollapsingHeader(title.c_str()); - } - - /*---------------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Pop Ups */ - /*---------------------------------------------------------------------------------*/ - bool EditorUI::BeginPopup(const std::string& label) + static_cast(value.x), + static_cast(value.y), + static_cast(value.z) + }; + const bool CHANGED = ImGui::SliderFloat3(label.c_str(), vec, + static_cast(min), static_cast(max), "%.3f", + ImGuiInputTextFlags_EnterReturnsTrue); + if (CHANGED) { - return ImGui::BeginPopup(label.c_str()); - } - void EditorUI::EndPopup() - { - ImGui::EndPopup(); - } - void EditorUI::OpenPopup(const std::string& label) - { - ImGui::OpenPopup(label.c_str()); + value.x = vec[0]; + value.y = vec[1]; + value.z = vec[2]; } + return CHANGED; + } - bool EditorUI::MenuItem(const std::string& label) + bool SHEditorUI::InputTextField(const std::string& label, std::string& value) + { + std::array buffer = { '\0' }; + strcpy_s(buffer.data(), TEXT_FIELD_MAX_LENGTH, value.c_str()); + const bool CHANGED = ImGui::InputText(label.c_str(), &buffer[0], TEXT_FIELD_MAX_LENGTH); + if (CHANGED) { - return ImGui::MenuItem(label.c_str()); + value = std::string(buffer.data(), buffer.data() + TEXT_FIELD_MAX_LENGTH); } + return CHANGED; + } - /*---------------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Widgets */ - /*---------------------------------------------------------------------------------*/ - void EditorUI::Text(const std::string& title) + bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector& enumNames) + { + + // Clamp input value + const std::string& INITIAL_NAME = v >= static_cast(enumNames.size()) ? "Unknown" : enumNames[v]; + bool b = false; + if (ImGui::BeginCombo(label.c_str(), INITIAL_NAME.c_str(), ImGuiComboFlags_None)) { - ImGui::Text(title.c_str()); - } - bool EditorUI::SmallButton(const std::string& title) - { - return ImGui::SmallButton(title.c_str()); - } - bool EditorUI::Button(const std::string& title) - { - return ImGui::Button(title.c_str()); - } - bool EditorUI::InputCheckbox(const std::string& label, bool& value) - { - return ImGui::Checkbox(label.c_str(), &value); - } - bool EditorUI::InputInt(const std::string& label, int& value) - { - return ImGui::InputInt(label.c_str(), &value, - 1, 10, - ImGuiInputTextFlags_EnterReturnsTrue); - } - bool EditorUI::InputUnsignedInt(const std::string& label, unsigned int& value) - { - int signedVal = static_cast(value); - const bool CHANGED = InputInt(label, signedVal); - if (CHANGED) + for (int i = 0; i < enumNames.size(); ++i) + { + const bool IS_SELECTED = v == i; + if (ImGui::Selectable(enumNames[i].c_str(), IS_SELECTED)) { - signedVal = std::clamp(signedVal, 0, std::numeric_limits::max()); - value = static_cast(signedVal); + v = i; + b = true; } - return CHANGED; - } - bool EditorUI::InputFloat(const std::string& label, float& value) - { - return ImGui::InputFloat(label.c_str(), &value, - 0.1f, 1.0f, "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue); - } - bool EditorUI::InputDouble(const std::string& label, double& value) - { - return ImGui::InputDouble(label.c_str(), &value, - 0.1, 1.0, "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue); - } - bool EditorUI::InputAngle(const std::string& label, double& value) - { - return ImGui::InputDouble(label.c_str(), &value, - 1.0, 45.0, "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue); - } - - bool EditorUI::InputSlider(const std::string& label, double min, double max, double& value) - { - float val = static_cast(value); - const bool CHANGED = ImGui::SliderFloat(label.c_str(), &val, - static_cast(min), static_cast(max), "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue); - - if (CHANGED) + if (IS_SELECTED) { - value = val; + ImGui::SetItemDefaultFocus(); } - - - return CHANGED; + } + ImGui::EndCombo(); } - - bool EditorUI::InputVec2(const std::string& label, vec2& value) - { - float vec[2] = - { - static_cast(value.x), - static_cast(value.y) - }; - const bool CHANGED = ImGui::InputFloat2(label.c_str(), vec, "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue); - if (CHANGED) - { - value.x = vec[0]; - value.y = vec[1]; - } - return CHANGED; - } - bool EditorUI::InputVec3(const std::string& label, vec3& value) - { - float vec[3] = - { - static_cast(value.x), - static_cast(value.y), - static_cast(value.z) - }; - const bool CHANGED = ImGui::InputFloat3(label.c_str(), vec, "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue); - if (CHANGED) - { - value.x = vec[0]; - value.y = vec[1]; - value.z = vec[2]; - } - return CHANGED; - } - - bool EditorUI::InputSliderVec3(const std::string& label, double min, double max, vec3& value) - { - float vec[3] = - { - static_cast(value.x), - static_cast(value.y), - static_cast(value.z) - }; - const bool CHANGED = ImGui::SliderFloat3(label.c_str(), vec, - static_cast(min), static_cast(max), "%.3f", - ImGuiInputTextFlags_EnterReturnsTrue); - if (CHANGED) - { - value.x = vec[0]; - value.y = vec[1]; - value.z = vec[2]; - } - return CHANGED; - } - - bool EditorUI::InputColor(const std::string& label, GFX::Color& value) - { - float color[4] = - { - value.R, - value.G, - value.B, - value.A - }; - const bool CHANGED = ImGui::ColorEdit4(label.c_str(), color, - ImGuiColorEditFlags_AlphaBar | - ImGuiColorEditFlags_AlphaPreview | - ImGuiColorEditFlags_Float); - if (CHANGED) - { - value.R = color[0]; - value.G = color[1]; - value.B = color[2]; - value.A = std::clamp(color[3], 0.f, 1.f); - } - return CHANGED; - } - bool EditorUI::InputTextField(const std::string& label, std::string& value) - { - std::array buffer = { '\0' }; - strcpy_s(buffer.data(), TEXT_FIELD_MAX_LENGTH, value.c_str()); - const bool CHANGED = ImGui::InputText(label.c_str(), &buffer[0], TEXT_FIELD_MAX_LENGTH); - if (CHANGED) - { - value = std::string(buffer.data(), buffer.data() + TEXT_FIELD_MAX_LENGTH); - } - return CHANGED; - } - - bool EditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector& enumNames) - { - - // Clamp input value - const std::string& INITIAL_NAME = v >= static_cast(enumNames.size()) ? "Unknown" : enumNames[v]; - bool b = false; - if (ImGui::BeginCombo(label.c_str(), INITIAL_NAME.c_str(), ImGuiComboFlags_None)) - { - for (int i = 0; i < enumNames.size(); ++i) - { - const bool IS_SELECTED = v == i; - if (ImGui::Selectable(enumNames[i].c_str(), IS_SELECTED)) - { - v = i; - b = true; - } - if (IS_SELECTED) - { - ImGui::SetItemDefaultFocus(); - } - } - ImGui::EndCombo(); - } - return b; - } - - bool EditorUI::InputTextureDropDown(const std::string& label, Resource::Snowflake& v) - { - static std::vector> resources; - - // Register texture popup - bool hasChanges = false; - if (ImGui::BeginPopup("Texture Menu")) - { - if (ImGui::Button("None")) - { - v = Resource::INVALID_SNOWFLAKE; - ImGui::CloseCurrentPopup(); - hasChanges = true; - } - for (auto& rscWrapper : resources) - { - Resource& rsc = rscWrapper.get(); - - ImGui::PushID(static_cast(rsc.GetID())); - - const GFX::Texture* TEX = rsc.LoadTexture(); - if (TEX == nullptr) - { - continue; - } - const ImTextureID TEX_ID = reinterpret_cast(static_cast(TEX->GetHandle())); - const std::string NAME = rsc.GetPath().filename().string(); - const std::string FP = rsc.GetPath().string(); - if (ImGui::ImageButtonWithText(TEX_ID, NAME.c_str())) - { - v = rsc.GetID(); - ImGui::CloseCurrentPopup(); - hasChanges = true; - } - ImGui::TextDisabled(FP.c_str()); - - ImGui::PopID(); - } - ImGui::EndPopup(); - } - - // Get texture ID of resource - ImTextureID texID = 0; - std::string texName = "None"; - Resource* rsc = ResourceManager::Find(v); - if (rsc) - { - // File - if (rsc->IsType()) - { - GFX::Texture* tex = rsc->LoadTexture(); - if (tex) - { - texID = reinterpret_cast(static_cast(tex->GetHandle())); - } - } - else - { - // TODO (Clarence): replace with missing texture image - texID = Editor::Editor::GetInternalTexture("scene.png"); - } - texName = rsc->GetPath().filename().string(); - } - - // Show texture selection menu - if (ImGui::ImageButtonWithText(texID, texName.c_str(), label.c_str())) - { - resources = ResourceManager::FindAllOfType(); - ImGui::OpenPopup("Texture Menu"); - } - - return hasChanges; - } - bool EditorUI::InputFontDropDown(const char* label, Resource::Snowflake& v) - { - static std::vector> resources; - - // Register texture popup - bool hasChanges = false; - if (ImGui::BeginPopup("Font Menu")) - { - if (ImGui::Button("None")) - { - v = Resource::INVALID_SNOWFLAKE; - ImGui::CloseCurrentPopup(); - hasChanges = true; - } - for (auto& rscWrapper : resources) - { - Resource& rsc = rscWrapper.get(); - - ImGui::PushID(static_cast(rsc.GetID())); - - const GFX::Font* FONT = rsc.LoadFont(); - if (FONT == nullptr) - { - continue; - } - const std::string NAME = rsc.GetPath().filename().string(); - const std::string FP = rsc.GetPath().string(); - if (ImGui::Button(NAME.c_str())) - { - v = rsc.GetID(); - ImGui::CloseCurrentPopup(); - hasChanges = true; - } - ImGui::TextDisabled(FP.c_str()); - - ImGui::PopID(); - } - ImGui::EndPopup(); - } - - // Get font ID of resource - ImTextureID fontID = 0; - std::string fontName = "None"; - Resource* rsc = ResourceManager::Find(v); - - if (rsc) - { - // File - if (rsc) - { - GFX::Font* font = rsc->LoadFont(); - if (font) - { - fontID = reinterpret_cast(static_cast(font->GetID())); - if (font->CreatedThisFrame()) - { - font->OnCreate() = false; - hasChanges = true; - } - } - } - else - { - // TODO (Clarence): replace with missing texture image - fontID = Editor::Editor::GetInternalFont("selawk.tff"); - } - fontName = rsc->GetPath().filename().string(); - } - - // Show font selection menu - if (ImGui::ButtonWithText(fontName.c_str(), label)) - { - resources = ResourceManager::FindAllOfType(); - ImGui::OpenPopup("Font Menu"); - } - - return hasChanges; - } -} // namespace PlushieEngine + return b; + } +} diff --git a/SHADE_Engine/src/Editor/SHEditorUI.h b/SHADE_Engine/src/Editor/SHEditorUI.h index ce9d8608..06768b87 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.h +++ b/SHADE_Engine/src/Editor/SHEditorUI.h @@ -1,312 +1,297 @@ /************************************************************************************//*! -\file EditorUI.h -\author Tng Kah Wei, kahwei.tng, 390009620 (50%) +\file SHEditorUI.h +\author Tng Kah Wei, kahwei.tng, 390009620 \par email: kahwei.tng\@digipen.edu -\author Tay Yan Chong Clarence, t.yanchongclarence, 620008720 (50%) \par email: t.yanchongclarence\@digipen.edu -\date Nov 7, 2021 -\brief Defines a class that encapsulates the running of a Plushie Engine - application. +\date Sep 27, 2022 +\brief Defines a class that contains wrapper functions for ImGui. -Copyright (C) 2021 DigiPen Institute of Technology. +Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ #pragma once -// Platform Defines -#include "PlushieDefines.h" // Standard Library -#include // std::function -#include // std::string +#include // std::function +#include // std::string +// Project Includes +#include "Math/Vector/SHVec2.h" +#include "Math/Vector/SHVec3.h" +#include "Math/Vector/SHVec4.h" +#include "Math/SHMatrix.h" -#include "Core/Resource/Resource.h" -#include "Graphics/Color.h" -#include "Math/Vector2.h" -#include "Math/Vector3.h" - -namespace Pls +namespace SHADE { + /// + /// Static class that contains useful functions for Editor UI using ImGui. + /// + class SH_API SHEditorUI final + { + public: + /*-----------------------------------------------------------------------------*/ + /* Constants */ + /*-----------------------------------------------------------------------------*/ /// - /// Static class that contains useful functions for Editor UI using ImGui. + /// Maximum length of a string supported by InputTextField() /// - class PLS_API EditorUI final - { - public: - /*-----------------------------------------------------------------------------*/ - /* Constants */ - /*-----------------------------------------------------------------------------*/ - /// - /// Maximum length of a string supported by InputTextField() - /// - static constexpr size_t TEXT_FIELD_MAX_LENGTH = 256; + static constexpr size_t TEXT_FIELD_MAX_LENGTH = 256; - /*-----------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - ID Stack */ - /*-----------------------------------------------------------------------------*/ - /// - /// Marks the start of a stack of ImGui widgets with the specified id. - ///
- /// Wraps up ImGui::PushID(). - ///
- /// String-based ID. - static void PushID(const std::string& id); - /// - /// Marks the start of a stack of ImGui widgets with the specified id. - ///
- /// Wraps up ImGui::PushID(). - ///
- /// Integer-based ID. - static void PushID(int id); - /// - /// Marks the end of a stack of ImGui widgets from the last PushID() call. - ///
- /// Wraps up ImGui::PopID(). - ///
- static void PopID(); + /*-----------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - ID Stack */ + /*-----------------------------------------------------------------------------*/ + /// + /// Marks the start of a stack of ImGui widgets with the specified id. + ///
+ /// Wraps up ImGui::PushID(). + ///
+ /// String-based ID. + static void PushID(const std::string& id); + /// + /// Marks the start of a stack of ImGui widgets with the specified id. + ///
+ /// Wraps up ImGui::PushID(). + ///
+ /// Integer-based ID. + static void PushID(int id); + /// + /// Marks the end of a stack of ImGui widgets from the last PushID() call. + ///
+ /// Wraps up ImGui::PopID(). + ///
+ static void PopID(); - /*-----------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Indent */ - /*-----------------------------------------------------------------------------*/ - /// - /// Indents the widgets rendered after this call. - ///
- /// Wraps up ImGui::Indent(). - ///
- static void Indent(); - /// - /// Unindents the widgets rendered after this call. - ///
- /// Wraps up ImGui::Unindent(). - ///
- static void Unindent(); + /*-----------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Indent */ + /*-----------------------------------------------------------------------------*/ + /// + /// Indents the widgets rendered after this call. + ///
+ /// Wraps up ImGui::Indent(). + ///
+ static void Indent(); + /// + /// Unindents the widgets rendered after this call. + ///
+ /// Wraps up ImGui::Unindent(). + ///
+ static void Unindent(); - /*-----------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Organisers */ - /*-----------------------------------------------------------------------------*/ - /// - /// Creates a collapsing title header. - ///
- /// Wraps up ImGui::CollapsingHeader(). - ///
- /// Label for the header. - /// True if the header is open, false otherwise. - static bool CollapsingHeader(const std::string& title); + /*-----------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Organizers */ + /*-----------------------------------------------------------------------------*/ + /// + /// Creates a collapsing title header. + ///
+ /// Wraps up ImGui::CollapsingHeader(). + ///
+ /// Label for the header. + /// True if the header is open, false otherwise. + static bool CollapsingHeader(const std::string& title); + static void SameLine(); + static void Separator(); - /*-----------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Pop Ups */ - /*-----------------------------------------------------------------------------*/ - /// - /// Marks the start of a definition of a mini pop up that can show options. - ///
- /// Wraps up ImGui::BeginPopup(). - ///
- /// Label used to identify this widget. - /// Whether or not the pop up is open. - static bool BeginPopup(const std::string& label); - /// - /// Marks the end of a definition of a mini pop up that can show options. - ///
- /// Wraps up ImGui::EndPopup(). - ///
- static void EndPopup(); - /// - /// Opens the popup that was defined with the specified label. - ///
- /// Wraps up ImGui::OpenPopup(). - ///
- static void OpenPopup(const std::string& label); - /// - /// Creates a menu item in the list of items for a mini popup. - ///
- /// Wraps up ImGui::MenuItem(). - ///
- /// Label used to identify this widget. - /// Whether or not the menu item was selected. - static bool MenuItem(const std::string& label); + /*-----------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Menu */ + /*-----------------------------------------------------------------------------*/ + static bool BeginMenu(const std::string& label); + static bool BeginMenu(const std::string& label, const char* icon); + static void EndMenu(); - /*-----------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Widgets */ - /*-----------------------------------------------------------------------------*/ - /// - /// Creates a visual text widget. - ///
- /// Wraps up ImGui::Text(). - ///
- /// Text to display. - static void Text(const std::string& title); - /// - /// Creates a small inline button widget. - ///
- /// Wraps up ImGui::SmallButton(). - ///
- /// Text to display. - /// True if button was pressed. - static bool SmallButton(const std::string& title); - /// - /// Creates a inline button widget. - ///
- /// Wraps up ImGui::Button(). - ///
- /// Text to display. - /// True if button was pressed. - static bool Button(const std::string& title); - /// - /// Creates a checkbox widget for boolean input. - ///
- /// Wraps up ImGui::Checkbox(). - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputCheckbox(const std::string& label, bool& value); - /// - /// Creates a integer field widget for integer input. - ///
- /// Wraps up ImGui::InputInt(). - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputInt(const std::string& label, int& value); - /// - /// Creates a integer field widget for unsigned integer input. - ///
- /// Wraps up ImGui::InputInt() with an additional clamping of values. - ///
- /// Note: As a result, the range of this function limits it to the maximum - /// value of a 32-bit signed integer instead of a 32-bit unsigned integer. - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputUnsignedInt(const std::string& label, unsigned int& value); - /// - /// Creates a decimal field widget for single precision float input. - ///
- /// Wraps up ImGui::InputFloat(). - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputFloat(const std::string& label, float& value); - /// - /// Creates a decimal field widget for double precision float input. - ///
- /// Wraps up ImGui::InputDouble(). - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputDouble(const std::string& label, double& value); - /// - /// Creates a decimal field widget for double input with increments of higher - /// steps meant for angle variables. - ///
- /// Wraps up ImGui::InputDouble(). - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputAngle(const std::string& label, double& value); - /// - /// Creates a double slider field widget for double input. - ///
- /// Wraps up ImGui::InputSliderFloat(). - ///
- /// Label used to identify this widget. - /// Minimum value of the slider. - /// Maximum value of the slider. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputSlider(const std::string& label, double min, double max, double& value); - /// - /// Creates a 2x double field widget for Vector2 input. - ///
- /// Wraps up ImGui::InputFloat2(). - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputVec2(const std::string& label, vec2& value); - /// - /// Creates a 3x double field widget for Vector3 input. - ///
- /// Wraps up ImGui::InputFloat3(). - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputVec3(const std::string& label, vec3& value); - /// - /// Creates a 3x double slider field widget for Vector3 input. - ///
- /// Wraps up ImGui::InputSliderFloat3(). - ///
- /// Label used to identify this widget. - /// Minimum value of the slider. - /// Maximum value of the slider. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputSliderVec3(const std::string& label, double min, double max, vec3& value); - /// - /// Creates a colour field widget for Color input. - ///
- /// Wraps up ImGui::ColorEdit4(). - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputColor(const std::string& label, GFX::Color& value); - /// - /// Creates a text field widget for string input. - ///
- /// Wraps up ImGui::InputText(). - ///
- /// Label used to identify this widget. - /// Reference to the variable to store the result. - /// True if the value was changed. - static bool InputTextField(const std::string& label, std::string& value); - /// - /// Creates a combo box for enumeration input. - /// - /// The type of enum to input. - /// The name of the input. - /// The reference to the value to modify. - /// The maximum value of the enum. - /// - /// Conversion function from the type of enum - /// to C-style string. - /// Whether the value was modified. - template - static bool InputEnumCombo(const std::string& label, Enum& v, int maxVal, std::function toStrFn); - /// - /// Creates a combo box for enumeration input using a specified list of names. - /// - /// The name of the input. - /// The reference to the value to modify. - /// Vector of names for each enumeration value. - /// Whether the value was modified. - static bool InputEnumCombo(const std::string& label, int& v, const std::vector& enumNames); - /// - /// Creates a drop down widget for texture selection. - /// - /// The name of the input. - /// The reference to the value to modify. - /// Whether the value was modified. - static bool InputTextureDropDown(const std::string& label, Resource::Snowflake& v); - /// - /// Creates a drop down widget for font selection. - /// - /// The name of the input. - /// The reference to the value to modify. - /// Whether the value was modified. - static bool InputFontDropDown(const char* label, Resource::Snowflake& v); + /*-----------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Pop Ups */ + /*-----------------------------------------------------------------------------*/ + /// + /// Marks the start of a definition of a mini pop up that can show options. + ///
+ /// Wraps up ImGui::BeginPopup(). + ///
+ /// Label used to identify this widget. + /// Whether or not the pop up is open. + static bool BeginPopup(const std::string& label); + static bool BeginPopupContextItem(const std::string& label); + /// + /// Marks the end of a definition of a mini pop up that can show options. + ///
+ /// Wraps up ImGui::EndPopup(). + ///
+ static void EndPopup(); + /// + /// Opens the popup that was defined with the specified label. + ///
+ /// Wraps up ImGui::OpenPopup(). + ///
+ static void OpenPopup(const std::string& label); + /// + /// Creates a menu item in the list of items for a mini popup. + ///
+ /// Wraps up ImGui::MenuItem(). + ///
+ /// Label used to identify this widget. + /// Whether or not the menu item was selected. + static bool MenuItem(const std::string& label); + + /*-----------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Widgets */ + /*-----------------------------------------------------------------------------*/ + /// + /// Creates a visual text widget. + ///
+ /// Wraps up ImGui::Text(). + ///
+ /// Text to display. + static void Text(const std::string& title); + /// + /// Creates a small inline button widget. + ///
+ /// Wraps up ImGui::SmallButton(). + ///
+ /// Text to display. + /// True if button was pressed. + static bool SmallButton(const std::string& title); + /// + /// Creates a inline button widget. + ///
+ /// Wraps up ImGui::Button(). + ///
+ /// Text to display. + /// True if button was pressed. + static bool Button(const std::string& title); + static bool Selectable(const std::string& label); + static bool Selectable(const std::string& label, const char* icon); + /// + /// Creates a checkbox widget for boolean input. + ///
+ /// Wraps up ImGui::Checkbox(). + ///
+ /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputCheckbox(const std::string& label, bool& value); + /// + /// Creates a integer field widget for integer input. + ///
+ /// Wraps up ImGui::InputInt(). + ///
+ /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputInt(const std::string& label, int& value); + /// + /// Creates a integer field widget for unsigned integer input. + ///
+ /// Wraps up ImGui::InputInt() with an additional clamping of values. + ///
+ /// Note: As a result, the range of this function limits it to the maximum + /// value of a 32-bit signed integer instead of a 32-bit unsigned integer. + ///
+ /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputUnsignedInt(const std::string& label, unsigned int& value); + /// + /// Creates a decimal field widget for single precision float input. + ///
+ /// Wraps up ImGui::InputFloat(). + ///
+ /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputFloat(const std::string& label, float& value); + /// + /// Creates a decimal field widget for double precision float input. + ///
+ /// Wraps up ImGui::InputDouble(). + ///
+ /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputDouble(const std::string& label, double& value); + /// + /// Creates a decimal field widget for double input with increments of higher + /// steps meant for angle variables. + ///
+ /// Wraps up ImGui::InputDouble(). + ///
+ /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputAngle(const std::string& label, double& value); + /// + /// Creates a double slider field widget for double input. + ///
+ /// Wraps up ImGui::InputSliderFloat(). + ///
+ /// Label used to identify this widget. + /// Minimum value of the slider. + /// Maximum value of the slider. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputSlider(const std::string& label, double min, double max, double& value); + /// + /// Creates a 2x double field widget for Vector2 input. + ///
+ /// Wraps up ImGui::InputFloat2(). + ///
+ /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputVec2(const std::string& label, SHVec2& value); + /// + /// Creates a 3x double field widget for Vector3 input. + ///
+ /// Wraps up ImGui::InputFloat3(). + ///
+ /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputVec3(const std::string& label, SHVec3& value); + /// + /// Creates a 3x double slider field widget for Vector3 input. + ///
+ /// Wraps up ImGui::InputSliderFloat3(). + ///
+ /// Label used to identify this widget. + /// Minimum value of the slider. + /// Maximum value of the slider. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputSliderVec3(const std::string& label, double min, double max, SHVec3& value); + /// + /// Creates a text field widget for string input. + ///
+ /// Wraps up ImGui::InputText(). + ///
+ /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// True if the value was changed. + static bool InputTextField(const std::string& label, std::string& value); + /// + /// Creates a combo box for enumeration input. + /// + /// The type of enum to input. + /// The name of the input. + /// The reference to the value to modify. + /// The maximum value of the enum. + /// + /// Conversion function from the type of enum to C-style string. + /// + /// Whether the value was modified. + template + static bool InputEnumCombo(const std::string& label, Enum& v, int maxVal, std::function toStrFn); + /// + /// Creates a combo box for enumeration input using a specified list of names. + /// + /// The name of the input. + /// The reference to the value to modify. + /// Vector of names for each enumeration value. + /// Whether the value was modified. + static bool InputEnumCombo(const std::string& label, int& v, const std::vector& enumNames); - private: - // Prevent instantiation of this static class - EditorUI() = delete; - }; -} // namespace PlushieEngine + private: + // Prevent instantiation of this static class + SHEditorUI() = delete; + }; +} -#include "EditorUI.hpp" \ No newline at end of file +#include "SHEditorUI.hpp" \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/SHEditorUI.hpp b/SHADE_Engine/src/Editor/SHEditorUI.hpp index d7a3eae7..f3af0412 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.hpp +++ b/SHADE_Engine/src/Editor/SHEditorUI.hpp @@ -1,49 +1,51 @@ /************************************************************************************//*! -\file EditorUI.hpp -\author Tay Yan Chong Clarence, t.yanchongclarence, 620008720 -\par email: t.yanchongclarence\@digipen.edu -\date Nov 8, 2021 +\file SHEditorUI.hpp +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Sep 27, 2022 \brief Contains the implementation of editor inspector template functions. -Copyright (C) 2021 DigiPen Institute of Technology. +Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ // Primary Header -#include "EditorUI.h" +#include "SHEditorUI.h" +// External Dependencies +#include -namespace Pls +namespace SHADE { - /*---------------------------------------------------------------------------------*/ - /* ImGui Wrapper Functions - Widgets */ - /*---------------------------------------------------------------------------------*/ - template - inline bool EditorUI::InputEnumCombo(const std::string& label, Enum& v, int maxVal, std::function toStrFn) + /*---------------------------------------------------------------------------------*/ + /* ImGui Wrapper Functions - Widgets */ + /*---------------------------------------------------------------------------------*/ + template + inline bool SHEditorUI::InputEnumCombo(const std::string& label, Enum& v, int maxVal, std::function toStrFn) + { + std::vector values; + for (int i = 0; i <= maxVal; ++i) { - std::vector values; - for (int i = 0; i <= maxVal; ++i) - { - values.emplace_back(static_cast(i)); - } - bool b = false; - if (ImGui::BeginCombo(label.c_str(), toStrFn(v), ImGuiComboFlags_None)) - { - for (int i = 0; i <= maxVal; ++i) - { - const auto VALUE = values[i]; - const bool IS_SELECTED = v == VALUE; - if (ImGui::Selectable(toStrFn(VALUE), IS_SELECTED)) - { - v = VALUE; - b = true; - } - if (IS_SELECTED) - { - ImGui::SetItemDefaultFocus(); - } - } - ImGui::EndCombo(); - } - return b; + values.emplace_back(static_cast(i)); } -} // namespace PlushieEngine + bool b = false; + if (ImGui::BeginCombo(label.c_str(), toStrFn(v), ImGuiComboFlags_None)) + { + for (int i = 0; i <= maxVal; ++i) + { + const auto VALUE = values[i]; + const bool IS_SELECTED = v == VALUE; + if (ImGui::Selectable(toStrFn(VALUE), IS_SELECTED)) + { + v = VALUE; + b = true; + } + if (IS_SELECTED) + { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + return b; + } +} diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 0c3e89e6..d613dbfe 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -82,22 +82,18 @@ namespace SHADE void SHScriptEngine::Exit() { - // Do not allow deinitialization if not initialised - if (!dotNet.IsLoaded()) - { - SHLOG_ERROR("[ScriptEngine] Attempted to clean up an unloaded DotNetRuntime."); - return; - } + // Do not allow deinitialization if not initialised + if (!dotNet.IsLoaded()) + { + SHLOG_ERROR("[ScriptEngine] Attempted to clean up an unloaded DotNetRuntime."); + return; + } - // Unlink events - /*ECS::OnEntityCreated -= onEntityCreate; - ECS::OnEntityDestroy -= onEntityDestroy;*/ + // Clean up the CSharp Engine + csEngineExit(); - // Clean up the CSharp Engine - csEngineExit(); - - // Shut down the CLR - dotNet.Exit(); + // Shut down the CLR + dotNet.Exit(); } /*-----------------------------------------------------------------------------------*/ @@ -105,15 +101,15 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ bool SHScriptEngine::AddScript(EntityID entity, const std::string_view& scriptName) { - return csScriptsAdd(entity, scriptName.data()); + return csScriptsAdd(entity, scriptName.data()); } void SHScriptEngine::RemoveAllScripts(EntityID entity) { - csScriptsRemoveAll(entity); + csScriptsRemoveAll(entity); } void SHScriptEngine::RemoveAllScriptsImmediately(EntityID entity, bool callOnDestroy) { - csScriptsRemoveAllImmediately(entity, callOnDestroy); + csScriptsRemoveAllImmediately(entity, callOnDestroy); } /*---------------------------------------------------------------------------------*/ @@ -121,24 +117,24 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ std::string SHScriptEngine::SerialiseScripts(const SHEntity& entity) const { - // Create buffer needed to store serialised script data - constexpr int BUFFER_SIZE = 10240; - std::unique_ptr buffer { new char[BUFFER_SIZE] }; - std::memset(buffer.get(), 0, BUFFER_SIZE); + // Create buffer needed to store serialised script data + constexpr int BUFFER_SIZE = 10240; + std::unique_ptr buffer { new char[BUFFER_SIZE] }; + std::memset(buffer.get(), 0, BUFFER_SIZE); - // Attempt to serialise the script - std::string result; - if (csScriptsSerialise(entity.GetEID(), buffer.get(), BUFFER_SIZE)) - { - result = std::string(buffer.get()); - } - else - { - SHLOG_ERROR("[ScriptEngine] Failed to serialise scripts as string buffer is too small!"); - } + // Attempt to serialise the script + std::string result; + if (csScriptsSerialise(entity.GetEID(), buffer.get(), BUFFER_SIZE)) + { + result = std::string(buffer.get()); + } + else + { + SHLOG_ERROR("[ScriptEngine] Failed to serialise scripts as string buffer is too small!"); + } - // Return an empty string since we failed to serialise - return result; + // Return an empty string since we failed to serialise + return result; } /*-----------------------------------------------------------------------------------*/ @@ -152,9 +148,9 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ /* Script Editor Functions */ /*-----------------------------------------------------------------------------------*/ - void SHScriptEngine::RenderScriptsInInspector(const SHEntity& entity) const + void SHScriptEngine::RenderScriptsInInspector(EntityID entity) const { - csEditorRenderScripts(entity.GetEID()); + csEditorRenderScripts(entity); } /*-----------------------------------------------------------------------------------*/ @@ -267,7 +263,7 @@ namespace SHADE // Attempt to create the file std::ofstream file(path); if (!file.is_open()) - throw std::runtime_error("Unable to create CsProj file!"); + throw std::runtime_error("Unable to create CsProj file!"); // Fill the file file << FILE_CONTENTS; @@ -281,9 +277,9 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ SHEventHandle SHScriptEngine::onEntityDestroyed(SHEventPtr eventPtr) { - auto eventData = reinterpret_cast*>(eventPtr.get()); - csScriptsRemoveAll(eventData->data->eid); - return eventData->handle; + auto eventData = reinterpret_cast*>(eventPtr.get()); + csScriptsRemoveAll(eventData->data->eid); + return eventData->handle; } /*-----------------------------------------------------------------------------------*/ @@ -397,13 +393,13 @@ namespace SHADE DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_NAMESPACE + ".ScriptStore", "SerialiseScriptsYaml" - ); + );*/ csEditorRenderScripts = dotNet.GetFunctionPtr ( DEFAULT_CSHARP_LIB_NAME, DEFAULT_CSHARP_NAMESPACE + ".Editor", "RenderScriptsInInspector" - );*/ + ); } void SHScriptEngine::registerEvents() diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.h b/SHADE_Engine/src/Scripting/SHScriptEngine.h index 329bb3a5..710421e8 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.h +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.h @@ -170,7 +170,7 @@ namespace SHADE /// rendering code. /// /// The Entity to render the Scripts of. - void RenderScriptsInInspector(const SHEntity& entity) const; + void RenderScriptsInInspector(EntityID entity) const; /*-----------------------------------------------------------------------------*/ /* Static Utility Functions */ diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index d6b02c8c..db49201b 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -17,15 +17,17 @@ of DigiPen Institute of Technology is prohibited. // Primary Header #include "Editor/Editor.hxx" // External Dependencies -#include "Editor/SHEditorUI::.h" +#include "Editor/SHEditorUI.h" // Project Headers #include "Components/Component.hxx" #include "Scripts/ScriptStore.hxx" #include "Utility/Convert.hxx" #include "Utility/Debug.hxx" #include "Serialisation/ReflectionUtilities.hxx" +#include "Editor/IconsMaterialDesign.h" // Using Directives +using namespace System; using namespace System::Collections::Generic; /*-------------------------------------------------------------------------------------*/ @@ -46,7 +48,7 @@ using namespace System::Collections::Generic; (field->FieldType == MANAGED_TYPE::typeid) \ { \ NATIVE_TYPE val = safe_cast(field->GetValue(object)); \ - if (SHEditorUI::::FUNC(Convert::ToNative(field->Name), val)) \ + if (SHEditorUI::FUNC(Convert::ToNative(field->Name), val)) \ { \ field->SetValue(object, val); \ } \ @@ -67,7 +69,7 @@ using namespace System::Collections::Generic; (field->FieldType == MANAGED_TYPE::typeid) \ { \ NATIVE_TYPE val = Convert::ToNative(safe_cast(field->GetValue(object))); \ - if (SHEditorUI::::FUNC(Convert::ToNative(field->Name), val)) \ + if (SHEditorUI::FUNC(Convert::ToNative(field->Name), val)) \ { \ field->SetValue(object, Convert::ToCLI(val)); \ } \ @@ -99,10 +101,31 @@ namespace SHADE } // Render Add Script - //RenderScriptAddButton(entity); + RenderScriptAddButton(entity); SAFE_NATIVE_CALL_END_N("SHADE_Managed.Editor.RenderScriptsInInspector") } + void Editor::RenderScriptAddButton(Entity entity) + { + // Get list of Scripts + auto scriptTypes = ScriptStore::GetAvailableScriptList(); + + // Define pop up + if (SHEditorUI::BeginMenu("Add Script", ICON_MD_LIBRARY_ADD)) + { + for each (Type ^ type in scriptTypes) + { + if (SHEditorUI::Selectable(Convert::ToNative(type->Name))) + { + // Add the script + ScriptStore::AddScriptViaName(entity, type->Name); + } + } + + SHEditorUI::EndMenu(); + } + } + /*---------------------------------------------------------------------------------*/ /* Helper Functions */ /*---------------------------------------------------------------------------------*/ @@ -110,30 +133,23 @@ namespace SHADE { // Constants const std::string LABEL = Convert::ToNative(script->GetType()->Name); - const char* CONTEXT_MENU_ID = "scriptContextMenu"; // Header - SHEditorUI::::PushID(index); - if (SHEditorUI::::CollapsingHeader(LABEL)) + SHEditorUI::PushID(index); + if (SHEditorUI::CollapsingHeader(LABEL)) { - SHEditorUI::::PushID(LABEL); - SHEditorUI::::Indent(); + SHEditorUI::PushID(LABEL); + SHEditorUI::Indent(); { - // Define context menu - if (SHEditorUI::::BeginPopup(CONTEXT_MENU_ID)) + // Right Click Menu + if (SHEditorUI::BeginPopupContextItem("scriptContextMenu")) { - if (SHEditorUI::::MenuItem("Remove Script")) + if (SHEditorUI::Selectable("Delete Script", ICON_MD_DELETE)) { // Mark script for removal ScriptStore::RemoveScript(entity, script); } - SHEditorUI::::EndPopup(); - } - - // Context menu button - if (SHEditorUI::::SmallButton("...")) - { - SHEditorUI::::OpenPopup(CONTEXT_MENU_ID); + SHEditorUI::EndPopup(); } // Go through all fields and output them @@ -146,16 +162,16 @@ namespace SHADE continue; // Render the input field for this field - SHEditorUI::::PushID(LABEL + std::to_string(id++)); + SHEditorUI::PushID(LABEL + std::to_string(id++)); renderFieldInInspector(field, script); - SHEditorUI::::PopID(); + SHEditorUI::PopID(); } } - SHEditorUI::::Unindent(); - SHEditorUI::::PopID(); + SHEditorUI::Unindent(); + SHEditorUI::PopID(); } - SHEditorUI::::PopID(); + SHEditorUI::PopID(); } void Editor::renderFieldInInspector(Reflection::FieldInfo^ field, Object^ object) { @@ -180,13 +196,13 @@ namespace SHADE } int val = safe_cast(field->GetValue(object)); - if (SHEditorUI::::InputEnumCombo(Convert::ToNative(field->Name), val, nativeEnumNames)) + if (SHEditorUI::InputEnumCombo(Convert::ToNative(field->Name), val, nativeEnumNames)) { field->SetValue(object, val); } } - else if RENDER_FIELD_CASTED(Vector2, vec2, InputVec2) - else if RENDER_FIELD_CASTED(Vector3, vec3, InputVec3) + else if RENDER_FIELD_CASTED(Vector2, SHVec2, InputVec2) + else if RENDER_FIELD_CASTED(Vector3, SHVec3, InputVec3) else if (field->FieldType == String::typeid) { // Prevent issues where String^ is null due to being empty @@ -198,7 +214,7 @@ namespace SHADE // Actual Field std::string val = Convert::ToNative(stringVal); - if (SHEditorUI::::InputTextField(Convert::ToNative(field->Name), val)) + if (SHEditorUI::InputTextField(Convert::ToNative(field->Name), val)) { field->SetValue(object, Convert::ToCLI(val)); } diff --git a/SHADE_Managed/src/Editor/Editor.hxx b/SHADE_Managed/src/Editor/Editor.hxx index b85e9203..a38cbf79 100644 --- a/SHADE_Managed/src/Editor/Editor.hxx +++ b/SHADE_Managed/src/Editor/Editor.hxx @@ -36,7 +36,13 @@ namespace SHADE /// rendering code. /// /// The Entity to render the Scripts of. - static void RenderScriptsInInspector(Entity entity); + static void RenderScriptsInInspector(Entity entity); + /// + /// Renders a dropdown button that allows for the addition of PlushieScripts + /// onto the specified Entity. + /// + /// The Entity to add PlushieScripts to. + static void RenderScriptAddButton(Entity entity); private: /*-----------------------------------------------------------------------------*/ diff --git a/TempScriptsFolder/TestScript.cs b/TempScriptsFolder/TestScript.cs index 8159a78e..185b543e 100644 --- a/TempScriptsFolder/TestScript.cs +++ b/TempScriptsFolder/TestScript.cs @@ -2,6 +2,9 @@ using SHADE; public class TestScript : Script { + public double Speed = 1.0; + public Vector3 ATestVector; + public bool ABoolean; private Transform Transform; private double time = 0.0; public TestScript(GameObject gameObj) : base(gameObj) {} @@ -21,7 +24,7 @@ public class TestScript : Script } protected override void update() { - time += 0.16; + time += Speed * 0.16; Transform.GlobalPosition = new Vector3(System.Math.Sin(time), System.Math.Cos(time), 0.0f); } protected override void onDestroy()