diff --git a/assets/scripts/BouncingItem.lua b/assets/scripts/BouncingItem.lua index f8eb045..ca0192d 100644 --- a/assets/scripts/BouncingItem.lua +++ b/assets/scripts/BouncingItem.lua @@ -146,7 +146,7 @@ function OnUpdate(deltaTime) -- Apply the new position to the Transform component transform:SetPosition(new_position) - -- === Optional: Log Current Rotation and Position === + -- Log Current Rotation and Position === -- Uncomment the following lines if you wish to log the gun's current rotation and position -- local current_rotation = transform:GetRotation() -- Engine.Log(string.format("Gun Rotation: (X: %.2f, Y: %.2f, Z: %.2f)", current_rotation.x, current_rotation.y, current_rotation.z), {1, 1, 1, 1}) diff --git a/assets/scripts/camera.lua b/assets/scripts/camera.lua new file mode 100644 index 0000000..be828da --- /dev/null +++ b/assets/scripts/camera.lua @@ -0,0 +1,35 @@ +local Engine = require("./assets/scripts/engine") + + +local transform = nil + +local new_rotation = 0 + +local new_rotationSpeed = 15 + +function OnInit() + local gameObject = Engine.GetGameObjectByTag("Camera") + transform = gameObject:GetComponent("Transform") + Engine.Log("Init Done") +end + + +function OnUpdate(deltaTime) + local gameObject = Engine.GetGameObjectByTag("Camera") + transform = gameObject:GetComponent("Transform") + + local old_rotation = transform:GetRotation() + + + local rotation = { + x = old_rotation.x, -- Preserving existing new_rotation on X-axis + y = new_rotation, -- Updated new_rotation on Y-axis for spinning + z = old_rotation.z -- Preserving existing new_rotation on Z-axis + } + -- Apply the new new_rotation to the Transform component + transform:SetRotation(rotation) + new_rotation = new_rotation + (deltaTime * new_rotationSpeed) + if new_rotation >= 360 then + new_rotation = 0 + end +end \ No newline at end of file diff --git a/imgui.ini b/imgui.ini index 37fcd39..d3ad093 100644 --- a/imgui.ini +++ b/imgui.ini @@ -1,6 +1,6 @@ [Window][DockSpace] Pos=0,0 -Size=1920,1177 +Size=1280,720 Collapsed=0 [Window][Debug##Default] @@ -80,8 +80,8 @@ Collapsed=0 DockId=0x0000001F,0 [Window][Performance##performance] -Pos=8,746 -Size=322,423 +Pos=8,435 +Size=322,277 Collapsed=0 DockId=0x0000001C,0 @@ -104,8 +104,8 @@ Collapsed=0 DockId=0x0000000F,0 [Window][Scene Window##SceneWindow] -Pos=8,30 -Size=322,714 +Pos=8,28 +Size=322,405 Collapsed=0 DockId=0x0000001B,0 @@ -134,28 +134,28 @@ Collapsed=0 DockId=0x0000001E,0 [Window][ Logger##logger] -Pos=332,828 -Size=1187,341 +Pos=607,354 +Size=277,358 Collapsed=0 -DockId=0x00000020,1 +DockId=0x00000024,0 [Window][ Editor##EditorWindow] -Pos=332,30 -Size=1187,796 +Pos=332,28 +Size=552,324 Collapsed=0 DockId=0x0000001F,0 [Window][ Inspector##InspectorWindow] -Pos=1521,30 -Size=391,1139 +Pos=886,28 +Size=386,684 Collapsed=0 DockId=0x00000022,0 [Window][ Profiler] -Pos=332,828 -Size=1187,341 +Pos=332,354 +Size=273,358 Collapsed=0 -DockId=0x00000020,0 +DockId=0x00000023,0 [Table][0xE9E836E4,4] Column 0 Weight=1.2999 @@ -170,40 +170,42 @@ Column 2 Weight=1.0000 Column 3 Weight=1.0000 [Docking][Data] -DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,53 Size=1904,1139 Split=X Selected=0xF7365A5A - DockNode ID=0x00000021 Parent=0x14621557 SizeRef=871,1139 Split=X - DockNode ID=0x00000013 Parent=0x00000021 SizeRef=322,1142 Split=Y Selected=0x818D04BB - DockNode ID=0x0000001B Parent=0x00000013 SizeRef=264,714 HiddenTabBar=1 Selected=0x1D5D92B6 - DockNode ID=0x0000001C Parent=0x00000013 SizeRef=264,423 HiddenTabBar=1 Selected=0x818D04BB - DockNode ID=0x00000014 Parent=0x00000021 SizeRef=547,1142 Split=X - DockNode ID=0x00000015 Parent=0x00000014 SizeRef=1158,1142 Split=X - DockNode ID=0x00000011 Parent=0x00000015 SizeRef=265,1142 Selected=0x1D5D92B6 - DockNode ID=0x00000012 Parent=0x00000015 SizeRef=1259,1142 Split=X - DockNode ID=0x00000009 Parent=0x00000012 SizeRef=364,1142 Split=Y Selected=0x3DC5AC3F - DockNode ID=0x00000005 Parent=0x00000009 SizeRef=364,745 Split=Y Selected=0x3DC5AC3F - DockNode ID=0x0000000B Parent=0x00000005 SizeRef=364,452 HiddenTabBar=1 Selected=0x3DC5AC3F - DockNode ID=0x0000000C Parent=0x00000005 SizeRef=364,291 Selected=0xAE3C694A - DockNode ID=0x00000006 Parent=0x00000009 SizeRef=364,395 HiddenTabBar=1 Selected=0x726D8899 - DockNode ID=0x0000000A Parent=0x00000012 SizeRef=1538,1142 Split=X - DockNode ID=0x00000007 Parent=0x0000000A SizeRef=357,1142 Selected=0x7737E8B2 - DockNode ID=0x00000008 Parent=0x0000000A SizeRef=1545,1142 Split=X - DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1202,1142 Split=Y Selected=0xDF0EC458 - DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1202,849 Split=Y Selected=0xDF0EC458 - DockNode ID=0x0000000D Parent=0x00000003 SizeRef=1202,571 Split=Y Selected=0xDFF75B3F - DockNode ID=0x00000017 Parent=0x0000000D SizeRef=1202,776 Split=Y Selected=0xDFF75B3F - DockNode ID=0x0000001D Parent=0x00000017 SizeRef=518,720 Split=Y Selected=0xDFF75B3F - DockNode ID=0x0000001F Parent=0x0000001D SizeRef=518,796 CentralNode=1 Selected=0x9A7B23B9 - DockNode ID=0x00000020 Parent=0x0000001D SizeRef=518,341 Selected=0x7A66B86B - DockNode ID=0x0000001E Parent=0x00000017 SizeRef=518,417 Selected=0xC74E1AEE - DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1202,364 Split=X Selected=0x1C0788A1 - DockNode ID=0x00000019 Parent=0x00000018 SizeRef=601,364 Selected=0x1C0788A1 - DockNode ID=0x0000001A Parent=0x00000018 SizeRef=599,364 Selected=0x9B5D3198 - DockNode ID=0x0000000E Parent=0x00000003 SizeRef=1202,569 Selected=0xE98146C5 - DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1202,291 Selected=0x9DD4E196 - DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB - DockNode ID=0x00000016 Parent=0x00000014 SizeRef=420,1142 Selected=0x8D0E8380 - DockNode ID=0x00000022 Parent=0x14621557 SizeRef=391,1139 Selected=0xD1D25642 -DockSpace ID=0xC6145A92 Pos=8,27 Size=1904,1142 Split=X - DockNode ID=0x0000000F Parent=0xC6145A92 SizeRef=301,1142 Selected=0xA8433A03 - DockNode ID=0x00000010 Parent=0xC6145A92 SizeRef=1601,1142 CentralNode=1 +DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=172,215 Size=1264,684 Split=X Selected=0xF7365A5A + DockNode ID=0x00000021 Parent=0x14621557 SizeRef=876,1139 Split=X + DockNode ID=0x00000013 Parent=0x00000021 SizeRef=322,1142 Split=Y Selected=0x818D04BB + DockNode ID=0x0000001B Parent=0x00000013 SizeRef=264,675 HiddenTabBar=1 Selected=0x1D5D92B6 + DockNode ID=0x0000001C Parent=0x00000013 SizeRef=264,463 HiddenTabBar=1 Selected=0x818D04BB + DockNode ID=0x00000014 Parent=0x00000021 SizeRef=552,1142 Split=X + DockNode ID=0x00000015 Parent=0x00000014 SizeRef=1158,1142 Split=X + DockNode ID=0x00000011 Parent=0x00000015 SizeRef=265,1142 Selected=0x1D5D92B6 + DockNode ID=0x00000012 Parent=0x00000015 SizeRef=1259,1142 Split=X + DockNode ID=0x00000009 Parent=0x00000012 SizeRef=364,1142 Split=Y Selected=0x3DC5AC3F + DockNode ID=0x00000005 Parent=0x00000009 SizeRef=364,745 Split=Y Selected=0x3DC5AC3F + DockNode ID=0x0000000B Parent=0x00000005 SizeRef=364,452 HiddenTabBar=1 Selected=0x3DC5AC3F + DockNode ID=0x0000000C Parent=0x00000005 SizeRef=364,291 Selected=0xAE3C694A + DockNode ID=0x00000006 Parent=0x00000009 SizeRef=364,395 HiddenTabBar=1 Selected=0x726D8899 + DockNode ID=0x0000000A Parent=0x00000012 SizeRef=1538,1142 Split=X + DockNode ID=0x00000007 Parent=0x0000000A SizeRef=357,1142 Selected=0x7737E8B2 + DockNode ID=0x00000008 Parent=0x0000000A SizeRef=1545,1142 Split=X + DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1202,1142 Split=Y Selected=0xDF0EC458 + DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1202,849 Split=Y Selected=0xDF0EC458 + DockNode ID=0x0000000D Parent=0x00000003 SizeRef=1202,571 Split=Y Selected=0xDFF75B3F + DockNode ID=0x00000017 Parent=0x0000000D SizeRef=1202,776 Split=Y Selected=0xDFF75B3F + DockNode ID=0x0000001D Parent=0x00000017 SizeRef=518,720 Split=Y Selected=0xDFF75B3F + DockNode ID=0x0000001F Parent=0x0000001D SizeRef=518,779 CentralNode=1 Selected=0x9A7B23B9 + DockNode ID=0x00000020 Parent=0x0000001D SizeRef=518,358 Split=X Selected=0x7A66B86B + DockNode ID=0x00000023 Parent=0x00000020 SizeRef=273,358 HiddenTabBar=1 Selected=0x7A66B86B + DockNode ID=0x00000024 Parent=0x00000020 SizeRef=277,358 HiddenTabBar=1 Selected=0x1F29F1F5 + DockNode ID=0x0000001E Parent=0x00000017 SizeRef=518,417 Selected=0xC74E1AEE + DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1202,364 Split=X Selected=0x1C0788A1 + DockNode ID=0x00000019 Parent=0x00000018 SizeRef=601,364 Selected=0x1C0788A1 + DockNode ID=0x0000001A Parent=0x00000018 SizeRef=599,364 Selected=0x9B5D3198 + DockNode ID=0x0000000E Parent=0x00000003 SizeRef=1202,569 Selected=0xE98146C5 + DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1202,291 Selected=0x9DD4E196 + DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB + DockNode ID=0x00000016 Parent=0x00000014 SizeRef=420,1142 Selected=0x8D0E8380 + DockNode ID=0x00000022 Parent=0x14621557 SizeRef=386,1139 Selected=0xD1D25642 +DockSpace ID=0xC6145A92 Pos=8,27 Size=1904,1142 Split=X + DockNode ID=0x0000000F Parent=0xC6145A92 SizeRef=301,1142 Selected=0xA8433A03 + DockNode ID=0x00000010 Parent=0xC6145A92 SizeRef=1601,1142 CentralNode=1 diff --git a/scenes/Default.scene b/scenes/Default.scene index 27e811b..8ebce6c 100644 --- a/scenes/Default.scene +++ b/scenes/Default.scene @@ -3,8 +3,8 @@ Entities: Name: Bacround Components: Transform: - Position: [0, 400, 0] - Rotation: [0, -90, 0] + Position: [0, 300, 0] + Rotation: [0, 0, 0] Scale: [1, 1, 1] Mesh: MeshPath: assets/models/sponza.obj @@ -160,5 +160,19 @@ Entities: - id: 26 type: texture_diffuse path: textures/vase_hanging.tga + - ID: 1 + Name: Camera + Components: + Transform: + Position: [0, 200, 0] + Rotation: [0, 1.02622044, 0] + Scale: [1, 1, 1] ScriptComponent: - ScriptPath: assets/scripts/BouncingItem.lua \ No newline at end of file + ScriptPath: assets/scripts/camera.lua + CameraComponent: + IsPerspective: true + DefaultRuntimeCamera: true + FOV: 45 + AspectRatio: 1.75 + NearPlane: 0.100000001 + FarPlane: 7000 \ No newline at end of file diff --git a/src/Componenets/CameraComponent.cpp b/src/Componenets/CameraComponent.cpp index 16bf9f6..338604f 100644 --- a/src/Componenets/CameraComponent.cpp +++ b/src/Componenets/CameraComponent.cpp @@ -8,6 +8,8 @@ #include "gcml.h" +extern std::shared_ptr g_RuntimeCameraObject; + // Constructor implementation CameraComponent::CameraComponent() : IsPerspective(true), FOV(45.0f), AspectRatio(16.0f / 9.0f), @@ -70,6 +72,10 @@ void CameraComponent::Deserialize(const YAML::Node &node) if (node["DefaultRuntimeCamera"]) { DefaultRuntimeCamera = node["DefaultRuntimeCamera"].as(); + if (DefaultRuntimeCamera) + { + g_RuntimeCameraObject = shared_from_this(); + } } if (IsPerspective) @@ -143,7 +149,7 @@ void CameraComponent::Update(float _deltaTime) void CameraComponent::UpdateViewMatrix() { - + if (m_Owner) { @@ -169,14 +175,6 @@ void CameraComponent::UpdateViewMatrix() m_ViewMatrix = glm::lookAt(position, position + forward, up); } - else - { - DEBUG_PRINT("Transform component missing on GameObject: %s", m_Owner->name.c_str()); - } - } - else - { - DEBUG_PRINT("Game Object has no parent"); } } diff --git a/src/Componenets/CameraComponent.h b/src/Componenets/CameraComponent.h index a09ef2e..448b3b9 100644 --- a/src/Componenets/CameraComponent.h +++ b/src/Componenets/CameraComponent.h @@ -7,8 +7,10 @@ #include #include #include +#include // Include for std::enable_shared_from_this -class CameraComponent : public Component + +class CameraComponent : public Component, public std::enable_shared_from_this { public: // Updated constructor to accept GameObject* diff --git a/src/Componenets/GameObject.cpp b/src/Componenets/GameObject.cpp index e722772..d325f84 100644 --- a/src/Componenets/GameObject.cpp +++ b/src/Componenets/GameObject.cpp @@ -5,14 +5,18 @@ #include "gcml.h" #include "../Windows/LoggerWindow.h" +#include "CameraComponent.h" extern LoggerWindow *g_LoggerWindow; +extern CameraComponent *g_RuntimeCameraObject; GameObject::GameObject(int id, const std::string &name) : id(id), name(name) { } + + int GameObject::GetComponentCount() const { return static_cast(components.size()); @@ -23,8 +27,6 @@ std::string GameObject::GetName() const return name; } - - void GameObject::AddComponent(const std::shared_ptr &component) { component->SetOwner(this); @@ -32,19 +34,78 @@ void GameObject::AddComponent(const std::shared_ptr &component) // std::cout << "Added " << component->GetName() << std::endl; } -void GameObject::Update(float deltaTime) { +bool GameObject::RemoveComponent(const std::shared_ptr &component) +{ + if (!component) + { + std::cerr << "Attempted to remove a null component.\n"; + return false; + } + + // Retrieve the component's name + const std::string& componentName = component->GetName(); + + // Log the removal attempt + DEBUG_PRINT("Removing %s", componentName.c_str()); + + // Find the component in the map + auto it = components.find(componentName); + if (it != components.end()) + { + // Verify that the component to remove matches the one in the map + if (it->second == component) + { + // Check if the component is a CameraComponent + if (componentName == CameraComponent::GetStaticName()) + { + // Attempt to cast to CameraComponent + std::shared_ptr camera = std::dynamic_pointer_cast(it->second); + if (camera) + { + // Lock the mutex to ensure thread safety when accessing the global camera + + // Compare shared_ptrs directly + if (g_RuntimeCameraObject == camera.get()) + { + // Unset the active camera + g_RuntimeCameraObject = nullptr; + if (g_LoggerWindow) + { + g_LoggerWindow->AddLog("Active Camera has been removed."); + } + else + { + std::cerr << "Logger window is not initialized.\n"; + } + DEBUG_PRINT("Active Camera has been unset."); + } + } + } + + // Erase the component from the map + components.erase(it); + DEBUG_PRINT("Removed %s", componentName.c_str()); + return true; + } + } +} + +void GameObject::Update(float deltaTime) +{ // Iterate using range-based for loop - for (const auto& [componentName, componentPtr] : components) { - if (componentPtr) { // Check if the pointer is valid + for (const auto &[componentName, componentPtr] : components) + { + if (componentPtr) + { // Check if the pointer is valid componentPtr->Update(deltaTime); // Call the Update method - } else { + } + else + { DEBUG_PRINT("Warning: '%s' is not a valid pointer:", componentName.c_str()); } } - } - std::shared_ptr GameObject::GetComponentByName(const std::string &name) const { auto it = components.find(name); diff --git a/src/Componenets/GameObject.h b/src/Componenets/GameObject.h index 9d91e8f..4451fc7 100644 --- a/src/Componenets/GameObject.h +++ b/src/Componenets/GameObject.h @@ -29,6 +29,10 @@ public: std::string GetName() const; void AddComponent(const std::shared_ptr &component); + bool RemoveComponent(const std::shared_ptr &component); + + + std::shared_ptr GetComponentByName(const std::string &name) const; void Update(float deltaTime); diff --git a/src/Engine.cpp b/src/Engine.cpp index daf8554..8df220b 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -190,7 +190,7 @@ void MyEngine::Run() // Possibly create more GameObjects with different positions or textures - ThemeManager_ChangeTheme(2); + ThemeManager_ChangeTheme(3); DEBUG_PRINT("Changed Theme to default"); while (!glfwWindowShouldClose(m_Window) && m_Running) diff --git a/src/Engine/AssetManager.h b/src/Engine/AssetManager.h index 216349b..84af886 100644 --- a/src/Engine/AssetManager.h +++ b/src/Engine/AssetManager.h @@ -194,23 +194,23 @@ public: std::string key = generateKey(type, path); // 2) Check if it’s already loaded - // auto it = m_AssetMap.find(key); - // if (it != m_AssetMap.end()) - //{ - // // Debug: Log the variant type - // if (std::holds_alternative>(it->second)) - // { - // #ifdef DEBUG - // DebugAssetMap(); - // #endif - // std::cout << "[AssetManager] Retrieved asset from cache: " << key << std::endl; - // return std::get>(it->second); - // } - // else - // { - // throw std::runtime_error("Asset type mismatch for key: " + key); - // } - //} + auto it = m_AssetMap.find(key); + if (it != m_AssetMap.end()) + { + // Debug: Log the variant type + if (std::holds_alternative>(it->second)) + { + #ifdef DEBUG + DebugAssetMap(); + #endif + std::cout << "[AssetManager] Retrieved asset from cache: " << key << std::endl; + return std::get>(it->second); + } + else + { + throw std::runtime_error("Asset type mismatch for key: " + key); + } + } // 3) Not loaded yet @@ -223,7 +223,8 @@ public: DEBUG_PRINT("[AssetManager] Failed to load asset: %s", path.c_str()); return nullptr; // For smart pointers, return nullptr on failure } - m_AssetMap[key] = assetData; + m_AssetMap.emplace(key, assetData); + return std::get>(assetData); } catch (const std::exception &e) diff --git a/src/Engine/LuaAPI.cpp b/src/Engine/LuaAPI.cpp index f192927..40d6e52 100644 --- a/src/Engine/LuaAPI.cpp +++ b/src/Engine/LuaAPI.cpp @@ -27,7 +27,6 @@ extern std::vector> g_GameObjects; std::string LuaManager::m_ScriptName = "LUA_UNDEFINED"; std::unordered_map LuaManager::m_ExposedVariables; - // Constructor LuaManager::LuaManager() : ScriptPath(""), m_LuaState(nullptr), m_LastErrorMessage("") @@ -107,6 +106,15 @@ bool LuaManager::Initialize(const std::string &scriptPath) lua_pop(m_LuaState, 1); // Pop the Engine table from the stack + lua_getglobal(m_LuaState, "package"); + lua_getfield(m_LuaState, -1, "path"); // get package.path + std::string currentPath = lua_tostring(m_LuaState, -1); + std::string newPath = currentPath + ";./assets/scripts/?.lua"; + lua_pop(m_LuaState, 1); // remove original package.path + lua_pushstring(m_LuaState, newPath.c_str()); + lua_setfield(m_LuaState, -2, "path"); // set package.path + lua_pop(m_LuaState, 1); // remove package table + // Execute the Lua script if (luaL_dofile(m_LuaState, ScriptPath.c_str()) != LUA_OK) { @@ -155,13 +163,13 @@ bool LuaManager::Initialize(const std::string &scriptPath) return true; } -std::unordered_map LuaManager::GetExposedVariables() { +std::unordered_map LuaManager::GetExposedVariables() +{ return m_ExposedVariables; } - - -void LuaManager::UpdateVariable(const std::string &name, const LuaManager::LuaExposedVariant &value) { +void LuaManager::UpdateVariable(const std::string &name, const LuaManager::LuaExposedVariant &value) +{ if (!m_LuaState) return; @@ -175,15 +183,24 @@ void LuaManager::UpdateVariable(const std::string &name, const LuaManager::LuaEx lua_pushstring(m_LuaState, name.c_str()); // Push the new value based on its type - if (std::holds_alternative(value)) { + if (std::holds_alternative(value)) + { lua_pushinteger(m_LuaState, std::get(value)); - } else if (std::holds_alternative(value)) { + } + else if (std::holds_alternative(value)) + { lua_pushnumber(m_LuaState, std::get(value)); - } else if (std::holds_alternative(value)) { + } + else if (std::holds_alternative(value)) + { lua_pushstring(m_LuaState, std::get(value).c_str()); - } else if (std::holds_alternative(value)) { + } + else if (std::holds_alternative(value)) + { lua_pushboolean(m_LuaState, std::get(value)); - } else { + } + else + { lua_pop(m_LuaState, 1); // Clean up stack return; } @@ -195,48 +212,51 @@ void LuaManager::UpdateVariable(const std::string &name, const LuaManager::LuaEx lua_pop(m_LuaState, 1); } - - - -int LuaManager::Lua_Engine_Expose(lua_State* L) { +int LuaManager::Lua_Engine_Expose(lua_State *L) +{ // Check that at least two arguments are passed: name and value - if (lua_gettop(L) < 2) { + if (lua_gettop(L) < 2) + { luaL_error(L, "Expose function requires at least two arguments: name and value"); return 0; } // First argument: variable name (string) - if (!lua_isstring(L, 1)) { + if (!lua_isstring(L, 1)) + { luaL_error(L, "First argument to Expose must be a string (variable name)"); return 0; } - const char* varName = lua_tostring(L, 1); + const char *varName = lua_tostring(L, 1); // Second argument: variable value (supports int, float, string, bool) LuaExposedVariant varValue; int type = lua_type(L, 2); - switch (type) { - case LUA_TNUMBER: + switch (type) + { + case LUA_TNUMBER: #if LUA_VERSION_NUM >= 503 - if (lua_isinteger(L, 2)) { - varValue = static_cast(lua_tointeger(L, 2)); - } else + if (lua_isinteger(L, 2)) + { + varValue = static_cast(lua_tointeger(L, 2)); + } + else #endif - { - varValue = static_cast(lua_tonumber(L, 2)); - } - break; - case LUA_TSTRING: - varValue = std::string(lua_tostring(L, 2)); - break; - case LUA_TBOOLEAN: - varValue = static_cast(lua_toboolean(L, 2)); - break; - default: - luaL_error(L, "Unsupported variable type for Expose"); - return 0; + { + varValue = static_cast(lua_tonumber(L, 2)); + } + break; + case LUA_TSTRING: + varValue = std::string(lua_tostring(L, 2)); + break; + case LUA_TBOOLEAN: + varValue = static_cast(lua_toboolean(L, 2)); + break; + default: + luaL_error(L, "Unsupported variable type for Expose"); + return 0; } // Store the variable in the static m_ExposedVariables map @@ -248,15 +268,24 @@ int LuaManager::Lua_Engine_Expose(lua_State* L) { lua_pushstring(L, varName); // Push the variable name // Push the value to Lua based on its type - if (std::holds_alternative(varValue)) { + if (std::holds_alternative(varValue)) + { lua_pushinteger(L, std::get(varValue)); - } else if (std::holds_alternative(varValue)) { + } + else if (std::holds_alternative(varValue)) + { lua_pushnumber(L, std::get(varValue)); - } else if (std::holds_alternative(varValue)) { + } + else if (std::holds_alternative(varValue)) + { lua_pushstring(L, std::get(varValue).c_str()); - } else if (std::holds_alternative(varValue)) { + } + else if (std::holds_alternative(varValue)) + { lua_pushboolean(L, std::get(varValue)); - } else { + } + else + { lua_pop(L, 1); // Clean up stack return 0; } @@ -270,40 +299,18 @@ int LuaManager::Lua_Engine_Expose(lua_State* L) { return 0; } - - -// Update function called every frame void LuaManager::Update(float deltaTime) { - if (!m_LuaState) { - if (g_LoggerWindow) - { - g_LoggerWindow->AddLog("LuaManager: Lua state is not initialized.", std::optional(ImVec4(1.0f, 0.0f, 0.0f, 1.0f))); - } - else - { - DEBUG_PRINT("LuaManager: Lua state is not initialized."); - } + LogError("Lua state is not initialized."); return; } // Push the 'OnUpdate' function onto the stack lua_getglobal(m_LuaState, "OnUpdate"); - if (!lua_isfunction(m_LuaState, -1)) - { - if (g_LoggerWindow) - { - g_LoggerWindow->AddLog("LuaManager: 'OnUpdate' is not a function.", std::optional(ImVec4(1.0f, 0.0f, 0.0f, 1.0f))); - } - else - { - DEBUG_PRINT("LuaManager: 'OnUpdate' is not a function."); - } - lua_pop(m_LuaState, 1); // Remove non-function value from stack - return; - } + + // Push the deltaTime argument lua_pushnumber(m_LuaState, deltaTime); @@ -311,48 +318,49 @@ void LuaManager::Update(float deltaTime) // Call the 'OnUpdate' function with 1 argument and 0 return values if (lua_pcall(m_LuaState, 1, 0, 0) != LUA_OK) { - const char *luaError = lua_tostring(m_LuaState, -1); - if (luaError) - { - std::string errorMsg(luaError); - // Prevent duplicate error logs - if (errorMsg != m_LastErrorMessage) - { - if (g_LoggerWindow) - { - std::string formattedError = "LuaManager Error in OnUpdate: " + errorMsg; - ImVec4 redColor = ImVec4(1.0f, 0.0f, 0.0f, 1.0f); - g_LoggerWindow->AddLog(formattedError.c_str(), std::optional(redColor)); - } - else - { - DEBUG_PRINT("LuaManager Error in OnUpdate: %s", errorMsg.c_str()); - } - m_LastErrorMessage = errorMsg; - } - } - else - { - if (g_LoggerWindow) - { - g_LoggerWindow->AddLog("LuaManager: Unknown error in OnUpdate.", std::optional(ImVec4(1.0f, 0.0f, 0.0f, 1.0f))); - } - else - { - DEBUG_PRINT("LuaManager: Unknown error in OnUpdate."); - } - } - - lua_pop(m_LuaState, 1); // Remove error message from stack + HandleLuaError("OnUpdate"); return; } else { - // Reset last error message on successful call m_LastErrorMessage.clear(); } } +void LuaManager::LogError(const char *message) +{ + if (g_LoggerWindow) + { + g_LoggerWindow->AddLog(message, ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); + } + else + { + DEBUG_PRINT("%s", message); + } +} + +void LuaManager::HandleLuaError(const std::string &functionName) +{ + const char *luaError = lua_tostring(m_LuaState, -1); + if (luaError) + { + std::string errorMsg(luaError); + if (errorMsg != m_LastErrorMessage) + { + std::string formattedError = "LuaManager Error in " + functionName + ": " + errorMsg; + LogError(formattedError.c_str()); + m_LastErrorMessage = errorMsg; + } + } + else + { + std::string errorMsg = "LuaManager: Unknown error in " + functionName + "."; + LogError(errorMsg.c_str()); + } + + lua_pop(m_LuaState, 1); // Remove error message from stack +} + // Update function called every frame void LuaManager::CallLuaFunction(std::string functionName) { @@ -374,7 +382,7 @@ void LuaManager::CallLuaFunction(std::string functionName) lua_getglobal(m_LuaState, functionName.c_str()); if (!lua_isfunction(m_LuaState, -1)) { - DEBUG_PRINT("LuaManager: 'OnUpdate' is not a function."); + DEBUG_PRINT("LuaManager: '%s' is not a function.", functionName.c_str()); return; } diff --git a/src/Engine/LuaAPI.h b/src/Engine/LuaAPI.h index 290a668..b955620 100644 --- a/src/Engine/LuaAPI.h +++ b/src/Engine/LuaAPI.h @@ -82,6 +82,11 @@ private: // Last error message to prevent duplicate logging std::string m_LastErrorMessage; + + + void LogError(const char* message); + void HandleLuaError(const std::string& functionName); + void RegisterAllMetatables(); void RegisterComponentMetaTable(); diff --git a/src/Engine/ThemeManagmer.cpp b/src/Engine/ThemeManager.cpp similarity index 60% rename from src/Engine/ThemeManagmer.cpp rename to src/Engine/ThemeManager.cpp index 96e356c..25e5114 100644 --- a/src/Engine/ThemeManagmer.cpp +++ b/src/Engine/ThemeManager.cpp @@ -6,6 +6,188 @@ #include "imgui.h" extern LoggerWindow *g_LoggerWindow; +void SetupImGuiStyle_Tesseract_Black() +{ + // Hazy Dark style by kaitabuchi314 from ImThemes + ImGuiStyle& style = ImGui::GetStyle(); + + style.Alpha = 1.0f; + style.DisabledAlpha = 0.6000000238418579f; + style.WindowPadding = ImVec2(5.5f, 8.300000190734863f); + style.WindowRounding = 4.5f; + style.WindowBorderSize = 1.0f; + style.WindowMinSize = ImVec2(32.0f, 32.0f); + style.WindowTitleAlign = ImVec2(0.0f, 0.5f); + style.WindowMenuButtonPosition = ImGuiDir_Left; + style.ChildRounding = 3.200000047683716f; + style.ChildBorderSize = 1.0f; + style.PopupRounding = 2.700000047683716f; + style.PopupBorderSize = 1.0f; + style.FramePadding = ImVec2(4.0f, 3.0f); + style.FrameRounding = 2.400000095367432f; + style.FrameBorderSize = 0.0f; + style.ItemSpacing = ImVec2(8.0f, 4.0f); + style.ItemInnerSpacing = ImVec2(4.0f, 4.0f); + style.CellPadding = ImVec2(4.0f, 2.0f); + style.IndentSpacing = 21.0f; + style.ColumnsMinSpacing = 6.0f; + style.ScrollbarSize = 14.0f; + style.ScrollbarRounding = 9.0f; + style.GrabMinSize = 10.0f; + style.GrabRounding = 3.200000047683716f; + style.TabRounding = 3.5f; + style.TabBorderSize = 1.0f; + style.TabMinWidthForCloseButton = 0.0f; + style.ColorButtonPosition = ImGuiDir_Right; + style.ButtonTextAlign = ImVec2(0.5f, 0.5f); + style.SelectableTextAlign = ImVec2(0.0f, 0.0f); + + style.Colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); + style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.4980392158031464f, 0.4980392158031464f, 0.4980392158031464f, 1.0f); + style.Colors[ImGuiCol_WindowBg] = ImVec4(0.05882352963089943f, 0.05882352963089943f, 0.05882352963089943f, 0.9399999976158142f); + style.Colors[ImGuiCol_ChildBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); + style.Colors[ImGuiCol_PopupBg] = ImVec4(0.0784313753247261f, 0.0784313753247261f, 0.0784313753247261f, 0.9399999976158142f); + style.Colors[ImGuiCol_Border] = ImVec4(0.4274509847164154f, 0.4274509847164154f, 0.4980392158031464f, 0.5f); + style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); + style.Colors[ImGuiCol_FrameBg] = ImVec4(0.1372549086809158f, 0.1725490242242813f, 0.2274509817361832f, 0.5400000214576721f); + style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.2117647081613541f, 0.2549019753932953f, 0.3019607961177826f, 0.4000000059604645f); + style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.04313725605607033f, 0.0470588244497776f, 0.0470588244497776f, 0.6700000166893005f); + style.Colors[ImGuiCol_TitleBg] = ImVec4(0.03921568766236305f, 0.03921568766236305f, 0.03921568766236305f, 1.0f); + style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.0784313753247261f, 0.08235294371843338f, 0.09019608050584793f, 1.0f); + style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.0f, 0.0f, 0.0f, 0.5099999904632568f); + style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.1372549086809158f, 0.1372549086809158f, 0.1372549086809158f, 1.0f); + style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.01960784383118153f, 0.01960784383118153f, 0.01960784383118153f, 0.5299999713897705f); + style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.3098039329051971f, 0.3098039329051971f, 0.3098039329051971f, 1.0f); + style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.407843142747879f, 0.407843142747879f, 0.407843142747879f, 1.0f); + style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.5098039507865906f, 0.5098039507865906f, 0.5098039507865906f, 1.0f); + style.Colors[ImGuiCol_CheckMark] = ImVec4(0.7176470756530762f, 0.7843137383460999f, 0.843137264251709f, 1.0f); + style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.47843137383461f, 0.5254902243614197f, 0.572549045085907f, 1.0f); + style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.2901960909366608f, 0.3176470696926117f, 0.3529411852359772f, 1.0f); + style.Colors[ImGuiCol_Button] = ImVec4(0.1490196138620377f, 0.1607843190431595f, 0.1764705926179886f, 0.4000000059604645f); + style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.1372549086809158f, 0.1450980454683304f, 0.1568627506494522f, 1.0f); + style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.0784313753247261f, 0.08627451211214066f, 0.09019608050584793f, 1.0f); + style.Colors[ImGuiCol_Header] = ImVec4(0.196078434586525f, 0.2156862765550613f, 0.239215686917305f, 0.3100000023841858f); + style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.1647058874368668f, 0.1764705926179886f, 0.1921568661928177f, 0.800000011920929f); + style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.07450980693101883f, 0.08235294371843338f, 0.09019608050584793f, 1.0f); + style.Colors[ImGuiCol_Separator] = ImVec4(0.4274509847164154f, 0.4274509847164154f, 0.4980392158031464f, 0.5f); + style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.239215686917305f, 0.3254902064800262f, 0.4235294163227081f, 0.7799999713897705f); + style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.2745098173618317f, 0.3803921639919281f, 0.4980392158031464f, 1.0f); + style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.2901960909366608f, 0.3294117748737335f, 0.3764705955982208f, 0.2000000029802322f); + style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.239215686917305f, 0.2980392277240753f, 0.3686274588108063f, 0.6700000166893005f); + style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.1647058874368668f, 0.1764705926179886f, 0.1882352977991104f, 0.949999988079071f); + style.Colors[ImGuiCol_Tab] = ImVec4(0.1176470592617989f, 0.125490203499794f, 0.1333333402872086f, 0.8619999885559082f); + style.Colors[ImGuiCol_TabHovered] = ImVec4(0.3294117748737335f, 0.407843142747879f, 0.501960813999176f, 0.800000011920929f); + style.Colors[ImGuiCol_TabActive] = ImVec4(0.2431372553110123f, 0.2470588237047195f, 0.2549019753932953f, 1.0f); + style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.06666667014360428f, 0.1019607856869698f, 0.1450980454683304f, 0.9724000096321106f); + style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.1333333402872086f, 0.2588235437870026f, 0.4235294163227081f, 1.0f); + style.Colors[ImGuiCol_PlotLines] = ImVec4(0.6078431606292725f, 0.6078431606292725f, 0.6078431606292725f, 1.0f); + style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.0f, 0.4274509847164154f, 0.3490196168422699f, 1.0f); + style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.8980392217636108f, 0.6980392336845398f, 0.0f, 1.0f); + style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.0f, 0.6000000238418579f, 0.0f, 1.0f); + style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.1882352977991104f, 0.1882352977991104f, 0.2000000029802322f, 1.0f); + style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.3098039329051971f, 0.3098039329051971f, 0.3490196168422699f, 1.0f); + style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.2274509817361832f, 0.2274509817361832f, 0.2470588237047195f, 1.0f); + style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); + style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.0f, 1.0f, 1.0f, 0.05999999865889549f); + style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.2588235437870026f, 0.5882353186607361f, 0.9764705896377563f, 0.3499999940395355f); + style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.0f, 1.0f, 0.0f, 0.8999999761581421f); + style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.2588235437870026f, 0.5882353186607361f, 0.9764705896377563f, 1.0f); + style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0f, 1.0f, 1.0f, 0.699999988079071f); + style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.800000011920929f, 0.800000011920929f, 0.800000011920929f, 0.2000000029802322f); + style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.800000011920929f, 0.800000011920929f, 0.800000011920929f, 0.3499999940395355f); +} + +void SetupImGuiStyle_Deep_Dark() +{ + // Deep Dark style by janekb04 from ImThemes + ImGuiStyle& style = ImGui::GetStyle(); + + style.Alpha = 1.0f; + style.DisabledAlpha = 0.6000000238418579f; + style.WindowPadding = ImVec2(8.0f, 8.0f); + style.WindowRounding = 7.0f; + style.WindowBorderSize = 1.0f; + style.WindowMinSize = ImVec2(32.0f, 32.0f); + style.WindowTitleAlign = ImVec2(0.0f, 0.5f); + style.WindowMenuButtonPosition = ImGuiDir_Left; + style.ChildRounding = 4.0f; + style.ChildBorderSize = 1.0f; + style.PopupRounding = 4.0f; + style.PopupBorderSize = 1.0f; + style.FramePadding = ImVec2(5.0f, 2.0f); + style.FrameRounding = 3.0f; + style.FrameBorderSize = 1.0f; + style.ItemSpacing = ImVec2(6.0f, 6.0f); + style.ItemInnerSpacing = ImVec2(6.0f, 6.0f); + style.CellPadding = ImVec2(6.0f, 6.0f); + style.IndentSpacing = 25.0f; + style.ColumnsMinSpacing = 6.0f; + style.ScrollbarSize = 15.0f; + style.ScrollbarRounding = 9.0f; + style.GrabMinSize = 10.0f; + style.GrabRounding = 3.0f; + style.TabRounding = 4.0f; + style.TabBorderSize = 1.0f; + style.TabMinWidthForCloseButton = 0.0f; + style.ColorButtonPosition = ImGuiDir_Right; + style.ButtonTextAlign = ImVec2(0.5f, 0.5f); + style.SelectableTextAlign = ImVec2(0.0f, 0.0f); + + style.Colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); + style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.4980392158031464f, 0.4980392158031464f, 0.4980392158031464f, 1.0f); + style.Colors[ImGuiCol_WindowBg] = ImVec4(0.09803921729326248f, 0.09803921729326248f, 0.09803921729326248f, 1.0f); + style.Colors[ImGuiCol_ChildBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); + style.Colors[ImGuiCol_PopupBg] = ImVec4(0.1882352977991104f, 0.1882352977991104f, 0.1882352977991104f, 0.9200000166893005f); + style.Colors[ImGuiCol_Border] = ImVec4(0.1882352977991104f, 0.1882352977991104f, 0.1882352977991104f, 0.2899999916553497f); + style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.0f, 0.0f, 0.0f, 0.239999994635582f); + style.Colors[ImGuiCol_FrameBg] = ImVec4(0.0470588244497776f, 0.0470588244497776f, 0.0470588244497776f, 0.5400000214576721f); + style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.1882352977991104f, 0.1882352977991104f, 0.1882352977991104f, 0.5400000214576721f); + style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.2000000029802322f, 0.2196078449487686f, 0.2274509817361832f, 1.0f); + style.Colors[ImGuiCol_TitleBg] = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); + style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.05882352963089943f, 0.05882352963089943f, 0.05882352963089943f, 1.0f); + style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); + style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.1372549086809158f, 0.1372549086809158f, 0.1372549086809158f, 1.0f); + style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.0470588244497776f, 0.0470588244497776f, 0.0470588244497776f, 0.5400000214576721f); + style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.3372549116611481f, 0.3372549116611481f, 0.3372549116611481f, 0.5400000214576721f); + style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.4000000059604645f, 0.4000000059604645f, 0.4000000059604645f, 0.5400000214576721f); + style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.5568627715110779f, 0.5568627715110779f, 0.5568627715110779f, 0.5400000214576721f); + style.Colors[ImGuiCol_CheckMark] = ImVec4(0.3294117748737335f, 0.6666666865348816f, 0.8588235378265381f, 1.0f); + style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.3372549116611481f, 0.3372549116611481f, 0.3372549116611481f, 0.5400000214576721f); + style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.5568627715110779f, 0.5568627715110779f, 0.5568627715110779f, 0.5400000214576721f); + style.Colors[ImGuiCol_Button] = ImVec4(0.0470588244497776f, 0.0470588244497776f, 0.0470588244497776f, 0.5400000214576721f); + style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.1882352977991104f, 0.1882352977991104f, 0.1882352977991104f, 0.5400000214576721f); + style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.2000000029802322f, 0.2196078449487686f, 0.2274509817361832f, 1.0f); + style.Colors[ImGuiCol_Header] = ImVec4(0.0f, 0.0f, 0.0f, 0.5199999809265137f); + style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.0f, 0.0f, 0.0f, 0.3600000143051147f); + style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.2000000029802322f, 0.2196078449487686f, 0.2274509817361832f, 0.3300000131130219f); + style.Colors[ImGuiCol_Separator] = ImVec4(0.2784313857555389f, 0.2784313857555389f, 0.2784313857555389f, 0.2899999916553497f); + style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.4392156898975372f, 0.4392156898975372f, 0.4392156898975372f, 0.2899999916553497f); + style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.4000000059604645f, 0.4392156898975372f, 0.4666666686534882f, 1.0f); + style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.2784313857555389f, 0.2784313857555389f, 0.2784313857555389f, 0.2899999916553497f); + style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.4392156898975372f, 0.4392156898975372f, 0.4392156898975372f, 0.2899999916553497f); + style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.4000000059604645f, 0.4392156898975372f, 0.4666666686534882f, 1.0f); + style.Colors[ImGuiCol_Tab] = ImVec4(0.0f, 0.0f, 0.0f, 0.5199999809265137f); + style.Colors[ImGuiCol_TabHovered] = ImVec4(0.1372549086809158f, 0.1372549086809158f, 0.1372549086809158f, 1.0f); + style.Colors[ImGuiCol_TabActive] = ImVec4(0.2000000029802322f, 0.2000000029802322f, 0.2000000029802322f, 0.3600000143051147f); + style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.0f, 0.0f, 0.0f, 0.5199999809265137f); + style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.1372549086809158f, 0.1372549086809158f, 0.1372549086809158f, 1.0f); + style.Colors[ImGuiCol_PlotLines] = ImVec4(1.0f, 0.0f, 0.0f, 1.0f); + style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.0f, 0.0f, 0.0f, 1.0f); + style.Colors[ImGuiCol_PlotHistogram] = ImVec4(1.0f, 0.0f, 0.0f, 1.0f); + style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.0f, 0.0f, 0.0f, 1.0f); + style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.5199999809265137f); + style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.0f, 0.0f, 0.0f, 0.5199999809265137f); + style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.2784313857555389f, 0.2784313857555389f, 0.2784313857555389f, 0.2899999916553497f); + style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); + style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.0f, 1.0f, 1.0f, 0.05999999865889549f); + style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.2000000029802322f, 0.2196078449487686f, 0.2274509817361832f, 1.0f); + style.Colors[ImGuiCol_DragDropTarget] = ImVec4(0.3294117748737335f, 0.6666666865348816f, 0.8588235378265381f, 1.0f); + style.Colors[ImGuiCol_NavHighlight] = ImVec4(1.0f, 0.0f, 0.0f, 1.0f); + style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0f, 0.0f, 0.0f, 0.699999988079071f); + style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(1.0f, 0.0f, 0.0f, 0.2000000029802322f); + style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(1.0f, 0.0f, 0.0f, 0.3499999940395355f); +} + void SetupImGuiStyle_Bootsrap() { @@ -299,6 +481,12 @@ void ThemeManager_ChangeTheme(int ThemeID) SetupImGuiStyle_Windark(); // Add your logic for Option 3 here break; + case 3: + SetupImGuiStyle_Deep_Dark(); + break; + case 4: + SetupImGuiStyle_Tesseract_Black(); + break; default: SetupImGuiStyle_Windark(); diff --git a/src/Windows/InspectorWindow.cpp b/src/Windows/InspectorWindow.cpp index a14ce85..a186930 100644 --- a/src/Windows/InspectorWindow.cpp +++ b/src/Windows/InspectorWindow.cpp @@ -181,6 +181,9 @@ void InspectorWindow::Show() // printf("%p\n", &transform); if (transformOpen) { + //if (ImGui::Button("Remove##Transform")) { + // g_SelectedObject->RemoveComponent(transform); + //} if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); @@ -253,12 +256,14 @@ void InspectorWindow::Show() ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); // Create a collapsing header for the Camera component - bool cameraOpen = ImGui::CollapsingHeader(ICON_FA_CAMERA "Camera##CamerInspector", ImGuiTreeNodeFlags_DefaultOpen); + bool cameraOpen = ImGui::CollapsingHeader(ICON_FA_CAMERA " Camera##CamerInspector", ImGuiTreeNodeFlags_DefaultOpen); ImGui::PopStyleColor(); // Revert text color if (cameraOpen) { - + if (ImGui::Button("Remove##Camera")) { + g_SelectedObject->RemoveComponent(camera); + } // Edit Field of View (FOV) if (ImGui::InputFloat("Field of View°", &camera->FOV, 1.0f, 10.0f, "%.1f")) { @@ -297,7 +302,6 @@ void InspectorWindow::Show() camera->AspectRatio = 1.77f; // Default to 16:9 } - // *** Begin Changed Code *** // Replace the "Orthographic" Checkbox with a "Perspective" Switch @@ -337,7 +341,6 @@ void InspectorWindow::Show() projectionMode.c_str(), g_SelectedObject->name.c_str()); } - ImGui::PopStyleVar(); // Optional: Add a tooltip for the Perspective switch if (ImGui::IsItemHovered()) @@ -347,14 +350,6 @@ void InspectorWindow::Show() ImGui::EndTooltip(); } - // *** End Changed Code *** - - // Add more camera properties here as needed - - ImGui::Spacing(); - - // Replace the "Set as Primary" Button with a Checkbox - // Determine if the current camera is the primary camera bool isPrimary = (g_RuntimeCameraObject == camera); @@ -392,6 +387,8 @@ void InspectorWindow::Show() g_LoggerWindow->AddLog("Unset Primary Camera: %s", ImVec4(1.0f, 0.0f, 0.0f, 1.0f), g_SelectedObject->name.c_str()); } } + ImGui::PopStyleVar(); + //// Optional: Indicate if this camera is currently the primary camera // if (g_RuntimeCameraObject == camera) @@ -415,7 +412,9 @@ void InspectorWindow::Show() if (meshOpen) { - // --- Mesh Path (Editable) --- + if (ImGui::Button("Remove##Mesh")) { + g_SelectedObject->RemoveComponent(mesh); + } const size_t BUFFER_SIZE = 256; char buffer[BUFFER_SIZE]; strncpy(buffer, mesh->MeshPath.c_str(), BUFFER_SIZE - 1); @@ -424,9 +423,10 @@ void InspectorWindow::Show() if (ImGui::InputText("Mesh Path", buffer, BUFFER_SIZE)) { mesh->MeshPath = buffer; - // Optionally, trigger reloading the mesh if the path changes - // Example: + } + if (ImGui::Button("Reload Mesh")) { std::shared_ptr model = g_AssetManager->loadAsset(AssetType::MODEL, mesh->MeshPath.c_str()); + } // --- Submeshes Information --- @@ -518,6 +518,9 @@ void InspectorWindow::Show() if (scriptOpen) { + if (ImGui::Button("Remove##Script")) { + g_SelectedObject->RemoveComponent(script); + } // Define a maximum buffer size for script path const size_t BUFFER_SIZE = 256; diff --git a/src/Windows/PerformanceWindow.cpp b/src/Windows/PerformanceWindow.cpp index 07d825a..daf8f5e 100644 --- a/src/Windows/PerformanceWindow.cpp +++ b/src/Windows/PerformanceWindow.cpp @@ -166,7 +166,7 @@ void PerformanceWindow::Show(float fps, float ms) - const char *options[] = {"Bootsrap", "Duck Red", "Windark"}; + const char *options[] = {"Bootsrap", "Duck Red", "Windark", "Deep Dark", "Tesseract Black"}; static int current_option = -1; // No selection initially const char *preview_value = (current_option >= 0 && current_option < 3) ? options[current_option] : "Select an option";