From 080c2c70d52ee0d9abb9c5b38863f0fb1f9ce0dd Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 13:09:40 +0800 Subject: [PATCH 1/7] Added canvas to serialization --- SHADE_Engine/src/Serialization/SHSerialization.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 607b4666..db3e3690 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -15,6 +15,7 @@ #include "Math/Transform/SHTransformComponent.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Physics/Interface/SHRigidBodyComponent.h" +#include "UI/SHCanvasComponent.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Scripting/SHScriptEngine.h" @@ -212,6 +213,8 @@ namespace SHADE AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); + node[ComponentsNode] = components; @@ -264,6 +267,7 @@ namespace SHADE AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); return componentIDList; } @@ -341,6 +345,7 @@ namespace SHADE SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); } } -- 2.40.1 From cf10724f3a34fb0d4f0a2a70870bd5e8b02e623f Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 13:17:45 +0800 Subject: [PATCH 2/7] Update SHSerialization.cpp --- SHADE_Engine/src/Serialization/SHSerialization.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 6e7912c2..931d3a4c 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -212,7 +212,7 @@ namespace SHADE AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); - AddConvComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); @@ -267,7 +267,7 @@ namespace SHADE AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); - AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); @@ -346,7 +346,7 @@ namespace SHADE SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); - SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); -- 2.40.1 From 5d0414979734e0f8276dd03fa98741c1485f8333 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 14:02:45 +0800 Subject: [PATCH 3/7] buttons WIP --- SHADE_Engine/src/UI/SHButtonComponent.cpp | 15 +++++++++++ SHADE_Engine/src/UI/SHButtonComponent.h | 31 +++++++++++++++++++++++ SHADE_Engine/src/UI/SHUISystem.cpp | 4 +++ SHADE_Engine/src/UI/SHUISystem.h | 12 ++++++++- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 SHADE_Engine/src/UI/SHButtonComponent.cpp create mode 100644 SHADE_Engine/src/UI/SHButtonComponent.h diff --git a/SHADE_Engine/src/UI/SHButtonComponent.cpp b/SHADE_Engine/src/UI/SHButtonComponent.cpp new file mode 100644 index 00000000..d711d682 --- /dev/null +++ b/SHADE_Engine/src/UI/SHButtonComponent.cpp @@ -0,0 +1,15 @@ +#include "SHpch.h" +#include "SHButtonComponent.h" + + +namespace SHADE +{ + SHButtonComponent::SHButtonComponent() + :size(0.0f), offset(0.0f), isHovered(false) + { + } + + + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHButtonComponent.h b/SHADE_Engine/src/UI/SHButtonComponent.h new file mode 100644 index 00000000..e68f354f --- /dev/null +++ b/SHADE_Engine/src/UI/SHButtonComponent.h @@ -0,0 +1,31 @@ +#pragma once + +#include "SH_API.h" +#include "ECS_Base/Components/SHComponent.h" +#include "Math/Vector/SHVec3.h" +#include "Math/Vector/SHVec2.h" + + +namespace SHADE +{ + class SH_API SHButtonComponent final: public SHComponent + { + public: + SHButtonComponent(); + ~SHButtonComponent() = default; + + SHVec2 size; + SHVec2 offset; + + + + private: + + bool isHovered; + + + + }; + + +} \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index d7dfe3c5..44730529 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -108,6 +108,10 @@ namespace SHADE } } + void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept + { + + } }//end namespace diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index 3da7efb3..15b710aa 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -4,6 +4,7 @@ #include "ECS_Base/System/SHSystem.h" #include "ECS_Base/System/SHSystemRoutine.h" #include "SHUIComponent.h" +#include "SHButtonComponent.h" #include "SHCanvasComponent.h" #include "Scene/SHSceneGraph.h" #include "Scene/SHSceneManager.h" @@ -39,13 +40,22 @@ namespace SHADE friend class UpdateUIMatrixRoutine; + class SH_API UpdateButtonsRoutine final: public SHSystemRoutine + { + public: + UpdateButtonsRoutine() : SHSystemRoutine("Update Buttons Routine", true) {}; + virtual void Execute(double dt) noexcept override final; + }; + friend class UpdateButtonsRoutine; + + void Init(); void Exit(); private: void UpdateUIComponent(SHUIComponent& comp) noexcept; - + void UpdateButtonComponent(SHButtonComponent& comp) noexcept; -- 2.40.1 From a612e71f0c298acd50dac1b64bf5ca78630dcd5d Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 20:39:15 +0800 Subject: [PATCH 4/7] Added Buttons, Added Canvas Scaling matrix, Added Serialization of buttons and camera arm --- Assets/Scenes/M2Scene.shade | 35 ++++++ .../src/Application/SBApplication.cpp | 2 + SHADE_Engine/src/Camera/SHCameraDirector.cpp | 17 +++ SHADE_Engine/src/Camera/SHCameraDirector.h | 2 + SHADE_Engine/src/Camera/SHCameraSystem.cpp | 4 + .../Inspector/SHEditorInspector.cpp | 6 + SHADE_Engine/src/Editor/SHEditorWidgets.hpp | 6 +- .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 3 +- .../MiddleEnd/Batching/SHSuperBatch.cpp | 6 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 +- .../MiddleEnd/Interface/SHRenderable.cpp | 8 +- .../src/Serialization/SHSerialization.cpp | 8 ++ SHADE_Engine/src/UI/SHButtonComponent.cpp | 47 +++++++- SHADE_Engine/src/UI/SHButtonComponent.h | 23 +++- SHADE_Engine/src/UI/SHUISystem.cpp | 110 +++++++++++++++++- SHADE_Engine/src/UI/SHUISystem.h | 10 +- 16 files changed, 272 insertions(+), 17 deletions(-) diff --git a/Assets/Scenes/M2Scene.shade b/Assets/Scenes/M2Scene.shade index 8b61dc67..aeb4eaed 100644 --- a/Assets/Scenes/M2Scene.shade +++ b/Assets/Scenes/M2Scene.shade @@ -13,6 +13,7 @@ Near: 0.00999999978 Far: 10000 Perspective: true + IsActive: true Light Component: Position: {x: 0, y: 0, z: 0} Type: Directional @@ -20,6 +21,7 @@ Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1} Layer: 4294967295 Strength: 0 + IsActive: true Scripts: ~ - EID: 7 Name: BigBoi @@ -30,9 +32,11 @@ Translate: {x: 0, y: -16.8647861, z: -14.039052} Rotate: {x: -0, y: 0, z: -0} Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975} + IsActive: true Renderable Component: Mesh: 149697411 Material: 126974645 + IsActive: true Scripts: ~ - EID: 8 Name: AmbientLight @@ -46,4 +50,35 @@ Color: {x: 1, y: 1, z: 1, w: 1} Layer: 4294967295 Strength: 0.25 + IsActive: true + Scripts: ~ +- EID: 6 + Name: Default + IsActive: true + NumberOfChildren: 1 + Components: + Canvas Component: + Canvas Width: 10 + Canvas Height: 10 + IsActive: true + Scripts: ~ +- EID: 5 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 129340704 + IsActive: true + Button Component: + Default Texture: 0 + Hovered Texture: 0 + Clicked Texture: 0 + IsActive: true Scripts: ~ \ No newline at end of file diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 1a00941f..06c42d2d 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -126,7 +126,9 @@ namespace Sandbox //SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); + SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); #ifdef SHEDITOR diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.cpp b/SHADE_Engine/src/Camera/SHCameraDirector.cpp index 29e2dcde..650315a0 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.cpp +++ b/SHADE_Engine/src/Camera/SHCameraDirector.cpp @@ -89,5 +89,22 @@ namespace SHADE return SHMatrix::Identity; } + float SHCameraDirector::GetWidth() noexcept + { + SHCameraComponent* camComponent = GetMainCameraComponent(); + if (camComponent) + return camComponent->GetWidth(); + else + return 0.0f; + } + + float SHCameraDirector::GetHeight() noexcept + { + SHCameraComponent* camComponent = GetMainCameraComponent(); + if (camComponent) + return camComponent->GetHeight(); + else + return 0.0f; + } } diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.h b/SHADE_Engine/src/Camera/SHCameraDirector.h index 8538a824..381531d6 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.h +++ b/SHADE_Engine/src/Camera/SHCameraDirector.h @@ -30,6 +30,8 @@ namespace SHADE void SetMainCamera(SHCameraComponent& cam) noexcept; SHMatrix const& GetOrthoMatrix() noexcept; SHMatrix const& GetPerspectiveMatrix() noexcept; + float GetWidth() noexcept; + float GetHeight() noexcept; private: SHMatrix viewMatrix; diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 489b05a1..30bdec29 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -57,6 +57,8 @@ namespace SHADE //std::cout << camera.yaw << std::endl; + + camera.pitch -= mouseY * dt * camera.turnSpeed.x; camera.yaw -= mouseX * dt * camera.turnSpeed.y; camera.dirtyView = true; @@ -150,6 +152,8 @@ namespace SHADE void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept { + + if (camera.isActive == false) return; diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index c4287e6f..83647da7 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -20,6 +20,7 @@ #include "Camera/SHCameraArmComponent.h" #include "UI/SHUIComponent.h" #include "UI/SHCanvasComponent.h" +#include "UI/SHButtonComponent.h" #include "SHEditorComponentView.h" #include "AudioSystem/SHAudioListenerComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" @@ -149,6 +150,10 @@ namespace SHADE { DrawComponent(textRendererComponent); } + if (auto buttonComponent = SHComponentManager::GetComponent_s(eid)) + { + DrawComponent(buttonComponent); + } ImGui::Separator(); // Render Scripts SHScriptEngine* scriptEngine = static_cast(SHSystemManager::GetSystem()); @@ -161,6 +166,7 @@ namespace SHADE DrawAddComponentButton(eid); DrawAddComponentButton(eid); DrawAddComponentButton(eid); + DrawAddComponentButton(eid); // Components that require Transforms diff --git a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp index 2681e916..403992cc 100644 --- a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp +++ b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp @@ -454,12 +454,12 @@ namespace SHADE ImGui::BeginGroup(); ImGui::PushID(label.data()); TextLabel(label); - const bool hasChange = ImGui::DragScalar("##dragScalar", data_type, &value, speed, &p_min, &p_max, displayFormat, flags); + const bool hasChange = ImGui::InputScalar("##dragScalar", data_type, &value); static bool startRecording = false; if (hasChange) { SHCommandManager::PerformCommand(std::reinterpret_pointer_cast(std::make_shared>(get(), value, set)), startRecording); - if (!startRecording) + if (!startRecording && ImGui::IsMouseDown(ImGuiMouseButton_Left)) startRecording = true; } if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) @@ -477,7 +477,7 @@ namespace SHADE ImGui::EndTooltip(); } } - return hasChange; + return false; } static bool DragFloat(const std::string_view& label, std::function get, std::function set, std::string_view const& tooltip = {}, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 9b4b02b0..afa2f9e0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -313,7 +313,8 @@ namespace SHADE auto uiComp = SHComponentManager::GetComponent_s(rendId); if (uiComp) { - transformData.emplace_back(uiComp->GetMatrix()); + if(uiComp->isActive) + transformData.emplace_back(uiComp->GetMatrix()); } else transformData.emplace_back(transform->GetTRS()); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp index ec19691f..58993026 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp @@ -55,7 +55,11 @@ namespace SHADE void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept { - Handle baseMat = (renderable->HasMaterialChanged() ? renderable->GetPrevMaterial() : renderable->GetMaterial())->GetBaseMaterial(); + Handle matInst = renderable->HasMaterialChanged() ? renderable->GetPrevMaterial() : renderable->GetMaterial(); + if (!matInst) + return; + + Handle baseMat = matInst->GetBaseMaterial(); const Handle PIPELINE = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline(); // Check if we have a Batch with the same pipeline yet diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index af09c819..03ca0b3d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -968,7 +968,7 @@ namespace SHADE for (auto& renderable : renderables) { // Check if the material instance is now unused - renderable.CleanUpMaterials(); + renderable.CleanUpMaterials(); if (!renderable.HasChanged()) continue; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index e22de5ab..9a180575 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -34,9 +34,10 @@ namespace SHADE void SHRenderable::OnDestroy() { // Remove from SuperBatch - if (sharedMaterial) + auto currMat = GetMaterial(); + if (currMat) { - Handle superBatch = sharedMaterial->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch(); + Handle superBatch = currMat->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch(); superBatch->Remove(this); } @@ -64,7 +65,6 @@ namespace SHADE if (material) { oldMaterial = material; - material.Free(); material = {}; } else if (sharedMaterial) @@ -144,6 +144,8 @@ namespace SHADE { matChanged = false; meshChanged = false; + if (oldMaterial) + oldMaterial.Free(); oldMaterial = {}; oldMesh = {}; } diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 931d3a4c..99e4fa41 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -12,10 +12,12 @@ #include "Assets/Asset Types/SHSceneAsset.h" #include "Camera/SHCameraComponent.h" +#include "Camera/SHCameraArmComponent.h" #include "Math/Transform/SHTransformComponent.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Physics/Interface/SHRigidBodyComponent.h" #include "UI/SHCanvasComponent.h" +#include "UI/SHButtonComponent.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Scripting/SHScriptEngine.h" @@ -208,12 +210,14 @@ namespace SHADE AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); AddConvComponentToComponentNode(components, eid); @@ -263,12 +267,14 @@ namespace SHADE AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); return componentIDList; @@ -343,11 +349,13 @@ namespace SHADE return; SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); } diff --git a/SHADE_Engine/src/UI/SHButtonComponent.cpp b/SHADE_Engine/src/UI/SHButtonComponent.cpp index d711d682..7b275128 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.cpp +++ b/SHADE_Engine/src/UI/SHButtonComponent.cpp @@ -5,11 +5,54 @@ namespace SHADE { SHButtonComponent::SHButtonComponent() - :size(0.0f), offset(0.0f), isHovered(false) + :size(1.0f), offset(0.0f), isHovered(false), isClicked(false), + defaultTexture(0), hoveredTexture(0), clickedTexture(0) { } - + AssetID SHButtonComponent::GetDefaultTexture() const noexcept + { + return defaultTexture; + } + + AssetID SHButtonComponent::GetHoveredTexture() const noexcept + { + return hoveredTexture; + } + + AssetID SHButtonComponent::GetClickedTexture() const noexcept + { + return clickedTexture; + } + + void SHButtonComponent::SetDefaultTexture(AssetID texture) noexcept + { + defaultTexture = texture; + } + + void SHButtonComponent::SetHoveredTexture(AssetID texture) noexcept + { + hoveredTexture = texture; + } + + void SHButtonComponent::SetClickedTexture(AssetID texture) noexcept + { + clickedTexture = texture; + } + +} + + +RTTR_REGISTRATION +{ + using namespace SHADE; + using namespace rttr; + + registration::class_("Button Component") + .property("Default Texture", &SHButtonComponent::GetDefaultTexture, &SHButtonComponent::SetDefaultTexture) + .property("Hovered Texture", &SHButtonComponent::GetHoveredTexture, &SHButtonComponent::SetHoveredTexture) + .property("Clicked Texture", &SHButtonComponent::GetClickedTexture, &SHButtonComponent::SetClickedTexture) + ; } \ No newline at end of file diff --git a/SHADE_Engine/src/UI/SHButtonComponent.h b/SHADE_Engine/src/UI/SHButtonComponent.h index e68f354f..39790b6a 100644 --- a/SHADE_Engine/src/UI/SHButtonComponent.h +++ b/SHADE_Engine/src/UI/SHButtonComponent.h @@ -1,30 +1,47 @@ #pragma once +#include + #include "SH_API.h" #include "ECS_Base/Components/SHComponent.h" #include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec2.h" - +#include "Assets/SHAssetMacros.h" namespace SHADE { + class SH_API SHButtonComponent final: public SHComponent { public: SHButtonComponent(); - ~SHButtonComponent() = default; + virtual ~SHButtonComponent() = default; SHVec2 size; SHVec2 offset; + AssetID GetClickedTexture() const noexcept; + AssetID GetDefaultTexture() const noexcept; + AssetID GetHoveredTexture() const noexcept; + void SetDefaultTexture(AssetID texture) noexcept; + void SetHoveredTexture(AssetID texture) noexcept; + void SetClickedTexture(AssetID texture) noexcept; + + + + friend class SHUISystem; private: bool isHovered; + bool isClicked; + AssetID defaultTexture; + AssetID hoveredTexture; + AssetID clickedTexture; - + RTTR_ENABLE() }; diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index 44730529..a499a475 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -3,6 +3,12 @@ #include "ECS_Base/Managers/SHComponentManager.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Math/Transform/SHTransformComponent.h" +#include "Graphics/MiddleEnd/Interface/SHRenderable.h" +#include "Camera/SHCameraSystem.h" +#include "Editor/EditorWindow/SHEditorWindowManager.h" +#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h" +#include "Resource/SHResourceManager.h" +#include "Input/SHInputManager.h" namespace SHADE { @@ -12,6 +18,7 @@ namespace SHADE SystemFamily::GetID(); SHComponentManager::CreateComponentSparseSet(); SHComponentManager::CreateComponentSparseSet(); + SHComponentManager::CreateComponentSparseSet(); } void SHUISystem::Exit() @@ -95,7 +102,7 @@ namespace SHADE { auto transform = SHComponentManager::GetComponent(comp.GetEID()); if (canvasComp != nullptr) - comp.localToCanvasMatrix = canvasComp->GetMatrix() * transform->GetTRS(); + comp.localToCanvasMatrix = canvasComp->GetMatrix()* transform->GetTRS(); else comp.localToCanvasMatrix = transform->GetTRS(); } @@ -108,10 +115,109 @@ namespace SHADE } } - void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept + void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept { + auto cameraSystem = SHSystemManager::GetSystem(); + + comp.canvasMatrix = SHMatrix::Identity; + comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f ); + comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f ); + } + void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept + { + SHUISystem* system = (SHUISystem*)GetSystem(); + auto& dense = SHComponentManager::GetDense(); + for (auto& comp : dense) + { + if(SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) + system->UpdateCanvasComponent(comp); + } } + void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept + { + if (!SHComponentManager::HasComponent(comp.GetEID()) || !SHComponentManager::HasComponent(comp.GetEID())) + { + return; + } + auto cameraSystem = SHSystemManager::GetSystem(); + auto uiComp = SHComponentManager::GetComponent(comp.GetEID()); + + SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f , 0.0f,1.0f); + SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f); + + SHVec2 topExtent{ topExtent4.x,-topExtent4.y }; + SHVec2 btmExtent{ btmExtent4.x,-btmExtent4.y }; + + + + SHVec2 windowSize; + SHVec2 mousePos; +#ifdef SHEDITOR + + windowSize = SHEditorWindowManager::GetEditorWindow()->windowSize; + mousePos = SHEditorWindowManager::GetEditorWindow()->viewportMousePos; + + + +#endif + + + + SHVec2 camSize{ cameraSystem->GetDirector(0)->GetWidth() , cameraSystem->GetDirector(0)->GetHeight() }; + + topExtent += camSize * 0.5f; + btmExtent += camSize * 0.5f; + + //Convert everything to using ratios + topExtent /= camSize; + btmExtent /= camSize; + + mousePos /= windowSize; + + //SHLOG_INFO("mousePos: {} , {}", mousePos.x, mousePos.y); + comp.isClicked = false; + if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x + && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) + { + comp.isHovered = true; + if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + comp.isClicked = true; + } + //SHLOG_INFO("BUTTON HOVERED"); + + + } + else + { + comp.isHovered = false; + + //SHLOG_INFO("BUTTON NOT HOVERED") + } + + + if (SHComponentManager::HasComponent(comp.GetEID())) + { + //auto renderable = SHComponentManager::GetComponent_s(comp.GetEID()); + //auto texture = SHResourceManager::Get(comp.GetDefaultTexture()); + + //auto material = renderable->GetModifiableMaterial(); + //material->SetProperty("texture", comp.GetDefaultTexture()); + } + } + + void SHUISystem::UpdateButtonsRoutine::Execute(double dt) noexcept + { + SHUISystem* system = (SHUISystem*)GetSystem(); + auto& dense = SHComponentManager::GetDense(); + for (auto& comp : dense) + { + if (SHSceneManager::CheckNodeAndComponentsActive(comp.GetEID())) + system->UpdateButtonComponent(comp); + } + } + }//end namespace diff --git a/SHADE_Engine/src/UI/SHUISystem.h b/SHADE_Engine/src/UI/SHUISystem.h index 15b710aa..04e057ad 100644 --- a/SHADE_Engine/src/UI/SHUISystem.h +++ b/SHADE_Engine/src/UI/SHUISystem.h @@ -39,6 +39,14 @@ namespace SHADE }; friend class UpdateUIMatrixRoutine; + class SH_API UpdateCanvasMatrixRoutine final: public SHSystemRoutine + { + public: + UpdateCanvasMatrixRoutine() :SHSystemRoutine("Update Canvas Matrix Routine", true) {}; + virtual void Execute(double dt) noexcept override final; + }; + friend class UpdateCanvasMatrixRoutine; + class SH_API UpdateButtonsRoutine final: public SHSystemRoutine { @@ -56,7 +64,7 @@ namespace SHADE private: void UpdateUIComponent(SHUIComponent& comp) noexcept; void UpdateButtonComponent(SHButtonComponent& comp) noexcept; - + void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept; }; -- 2.40.1 From 62c4b3837d42e8831877dc53fdc11ba2d40a9bbc Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Tue, 22 Nov 2022 20:46:05 +0800 Subject: [PATCH 5/7] Fixed bug where transform dirty flags were not being properly cleared. This was preventing bodies from going to sleep and transforms always updating. --- .../src/Math/Transform/SHTransformSystem.cpp | 4 ++-- .../src/Physics/System/SHPhysicsSystemRoutines.cpp | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp index 94c133dd..38d44984 100644 --- a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp @@ -47,14 +47,14 @@ namespace SHADE { // Get the current scene graph to traverse and update const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); - UpdateEntity(SCENE_GRAPH.GetRoot(), !IsRunInEditorPause); + UpdateEntity(SCENE_GRAPH.GetRoot(), false); } void SHTransformSystem::TransformPostPhysicsUpdate::Execute(double) noexcept { // Get the current scene graph to traverse and update const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); - UpdateEntity(SCENE_GRAPH.GetRoot(), IsRunInEditorPause); + UpdateEntity(SCENE_GRAPH.GetRoot(), true); } void SHTransformSystem::Init() diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp index 45f236f3..24bd2f81 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp @@ -302,9 +302,12 @@ namespace SHADE { colliderComponent->position = WORLD_POS; colliderComponent->orientation = WORLD_ROT; - colliderComponent->scale = WORLD_SCL; - colliderComponent->RecomputeCollisionShapes(); + if (colliderComponent->scale != WORLD_SCL) + { + colliderComponent->scale = WORLD_SCL; + colliderComponent->RecomputeCollisionShapes(); + } } } @@ -325,7 +328,11 @@ namespace SHADE if (physicsObject.GetRigidBody()->isActive()) physicsObject.prevTransform = CURRENT_TF; - // Sync with rigid bodies. If an object doesn't have a rigidbody, no update is needed here as it is done in pre-update. + // Skip sleeping objects + if (physicsObject.GetRigidBody()->isSleeping()) + return; + + // Sync with rigid bodies if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive(physicsObject.entityID)) { // Skip static bodies -- 2.40.1 From 142f025692a562426c11434d4145f893b9474ec2 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Tue, 22 Nov 2022 20:54:16 +0800 Subject: [PATCH 6/7] Added check for editor camera. --- Assets/Application.SHConfig | 2 +- Assets/Scenes/UI Test.shade | 79 ++++++++++++++++++++++++++++++ Assets/Scenes/UI Test.shade.shmeta | 3 ++ SHADE_Engine/src/UI/SHUISystem.cpp | 19 ++++++- 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 Assets/Scenes/UI Test.shade create mode 100644 Assets/Scenes/UI Test.shade.shmeta diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index 3f7a4ac0..c9b34a7a 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 94283040 +Starting Scene ID: 94246101 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/UI Test.shade b/Assets/Scenes/UI Test.shade new file mode 100644 index 00000000..b6aab1a1 --- /dev/null +++ b/Assets/Scenes/UI Test.shade @@ -0,0 +1,79 @@ +- EID: 0 + Name: Canvas + IsActive: true + NumberOfChildren: 1 + Components: + Canvas Component: + Canvas Width: 10 + Canvas Height: 10 + IsActive: true + Scripts: ~ +- EID: 6 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Renderable Component: + Mesh: 141771688 + Material: 129340704 + IsActive: true + Scripts: ~ +- EID: 1 + Name: Camera + IsActive: true + NumberOfChildren: 0 + Components: + Camera Component: + Position: {x: 0, y: 3, z: 8} + Pitch: 0 + Yaw: 0 + Roll: 0 + Width: 1920 + Height: 1080 + Near: 0.00999999978 + Far: 10000 + Perspective: true + IsActive: true + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Directional + Direction: {x: 1.79999995, y: 0, z: 1} + Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1} + Layer: 4294967295 + Strength: 0 + IsActive: true + Scripts: ~ +- EID: 7 + Name: BigBoi + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -16.8647861, z: -14.039052} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975} + IsActive: true + Renderable Component: + Mesh: 149697411 + Material: 126974645 + IsActive: true + Scripts: ~ +- EID: 8 + Name: AmbientLight + IsActive: true + NumberOfChildren: 0 + Components: + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Ambient + Direction: {x: 0, y: 0, z: 1} + Color: {x: 1, y: 1, z: 1, w: 1} + Layer: 4294967295 + Strength: 0.25 + IsActive: true + Scripts: ~ \ No newline at end of file diff --git a/Assets/Scenes/UI Test.shade.shmeta b/Assets/Scenes/UI Test.shade.shmeta new file mode 100644 index 00000000..0e80f988 --- /dev/null +++ b/Assets/Scenes/UI Test.shade.shmeta @@ -0,0 +1,3 @@ +Name: UI Test +ID: 96139961 +Type: 5 diff --git a/SHADE_Engine/src/UI/SHUISystem.cpp b/SHADE_Engine/src/UI/SHUISystem.cpp index a499a475..247eb6cc 100644 --- a/SHADE_Engine/src/UI/SHUISystem.cpp +++ b/SHADE_Engine/src/UI/SHUISystem.cpp @@ -7,6 +7,7 @@ #include "Camera/SHCameraSystem.h" #include "Editor/EditorWindow/SHEditorWindowManager.h" #include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h" +#include "Editor/SHEditor.h" #include "Resource/SHResourceManager.h" #include "Input/SHInputManager.h" @@ -118,10 +119,26 @@ namespace SHADE void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept { auto cameraSystem = SHSystemManager::GetSystem(); - +#ifdef SHEDITOR + auto editor = SHSystemManager::GetSystem(); + if (editor->editorState != SHEditor::State::PLAY) + { + comp.canvasMatrix = SHMatrix::Identity; + comp.canvasMatrix(0, 0) = cameraSystem->GetEditorCamera()->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f); + comp.canvasMatrix(1, 1) = cameraSystem->GetEditorCamera()->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f); + } + else + { + comp.canvasMatrix = SHMatrix::Identity; + comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f); + comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f); + } + +#else comp.canvasMatrix = SHMatrix::Identity; comp.canvasMatrix(0, 0) = cameraSystem->GetDirector(0)->GetWidth() * 0.5f / (comp.GetCanvasWidth() * 0.5f ); comp.canvasMatrix(1, 1) = cameraSystem->GetDirector(0)->GetHeight() * 0.5f / (comp.GetCanvasHeight() * 0.5f ); +#endif } void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept -- 2.40.1 From ac09007862561b6091b85b7fbeb606d49873a6c2 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 22 Nov 2022 20:59:17 +0800 Subject: [PATCH 7/7] Disabled xmldoc build, admin mode no longer required to build the engine --- SHADE_CSharp/premake5.lua | 15 ++++++++------- SHADE_Managed/premake5.lua | 18 +++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/SHADE_CSharp/premake5.lua b/SHADE_CSharp/premake5.lua index 8844b84c..f735b515 100644 --- a/SHADE_CSharp/premake5.lua +++ b/SHADE_CSharp/premake5.lua @@ -53,15 +53,16 @@ project "SHADE_CSharp" function configElementCS(cfg) _p(2,'Debug;Release;Publish') end - function docsElementCS(cfg) - _p(2,'true') - end - function docsLocationElementCS(cfg) - _p(2,'$(OutDir)') - end + -- function docsElementCS(cfg) + -- _p(2,'true') + -- end + -- function docsLocationElementCS(cfg) + -- _p(2,'$(OutDir)') + -- end premake.override(premake.vstudio.cs2005.elements, "projectProperties", function (oldfn, cfg) return table.join(oldfn(cfg), { - platformsElementCS, configElementCS, docsElementCS, docsLocationElementCS, +-- platformsElementCS, configElementCS, docsElementCS, docsLocationElementCS, + platformsElementCS, configElementCS, }) end) \ No newline at end of file diff --git a/SHADE_Managed/premake5.lua b/SHADE_Managed/premake5.lua index 463e80b8..9253c81b 100644 --- a/SHADE_Managed/premake5.lua +++ b/SHADE_Managed/premake5.lua @@ -119,14 +119,14 @@ project "SHADE_Managed" links{"librttr_core.lib"} links{"fmodstudio_vc.lib", "fmod_vc.lib"} - require "vstudio" + -- require "vstudio" - function docsElementCPP(cfg) - _p(3,'true') - end + -- function docsElementCPP(cfg) + -- _p(3,'true') + -- end - premake.override(premake.vstudio.vc2010.elements, "clCompile", function (oldfn, cfg) - return table.join(oldfn(cfg), { - docsElementCPP, - }) - end) \ No newline at end of file + -- premake.override(premake.vstudio.vc2010.elements, "clCompile", function (oldfn, cfg) + -- return table.join(oldfn(cfg), { + -- docsElementCPP, + -- }) + -- end) \ No newline at end of file -- 2.40.1