Add CreateComponentSparseSet and bug fix for togglebutton nt triggering

This commit is contained in:
maverickdgg 2023-02-01 12:42:51 +08:00
parent 4854e35e75
commit 2dfaa75ab3
1 changed files with 15 additions and 13 deletions

View File

@ -28,6 +28,8 @@ namespace SHADE
SHComponentManager::CreateComponentSparseSet<SHCanvasComponent>(); SHComponentManager::CreateComponentSparseSet<SHCanvasComponent>();
SHComponentManager::CreateComponentSparseSet<SHUIComponent>(); SHComponentManager::CreateComponentSparseSet<SHUIComponent>();
SHComponentManager::CreateComponentSparseSet<SHButtonComponent>(); SHComponentManager::CreateComponentSparseSet<SHButtonComponent>();
SHComponentManager::CreateComponentSparseSet<SHToggleButtonComponent>();
SHComponentManager::CreateComponentSparseSet<SHSliderComponent>();
} }
void SHUISystem::Exit() void SHUISystem::Exit()
@ -272,6 +274,7 @@ namespace SHADE
} }
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>(); auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
auto uiComp = SHComponentManager::GetComponent<SHUIComponent>(comp.GetEID()); auto uiComp = SHComponentManager::GetComponent<SHUIComponent>(comp.GetEID());
//auto canvasComp = SHComponentManager::GetComponent_s<SHCanvasComponent>(uiComp->canvasID);
SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); SHVec4 topExtent4 = SHMatrix::Translate(-comp.size.x * 0.5f, comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f);
SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f); SHVec4 btmExtent4 = SHMatrix::Translate(comp.size.x * 0.5f, -comp.size.y * 0.5f, 0.0f) * uiComp->GetMatrix() * SHVec4(0.0f, 0.0f, 0.0f, 1.0f);
@ -280,9 +283,9 @@ namespace SHADE
SHVec2 topExtent{ topExtent4.x,topExtent4.y }; SHVec2 topExtent{ topExtent4.x,topExtent4.y };
SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y }; SHVec2 btmExtent{ btmExtent4.x,btmExtent4.y };
SHVec2 mousePos; SHVec2 mousePos;
SHVec2 windowSize; SHVec2 windowSize;
#ifdef SHEDITOR #ifdef SHEDITOR
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable; windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable;
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos; mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
@ -305,21 +308,20 @@ namespace SHADE
#endif #endif
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) }; SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0) };
//SHLOG_INFO("TopExtent: {}, {}", topExtent.x, topExtent.y)
topExtent = CanvasToScreenPoint(topExtent, true);
topExtent = CanvasToScreenPoint(topExtent,true);
btmExtent = CanvasToScreenPoint(btmExtent, true); btmExtent = CanvasToScreenPoint(btmExtent, true);
//SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y)
//comp.isClicked = false;
comp.isClicked = false;
if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x
&& mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y) && mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y)
{ {
comp.isHovered = true; comp.isHovered = true;
#ifdef SHEDITOR #ifdef SHEDITOR
if (SHSystemManager::GetSystem<SHEditor>()->editorState == SHEditor::State::PLAY) //if (SHSystemManager::GetSystem<SHEditor>()->editorState == SHEditor::State::PLAY)
{ {
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB)) if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
{ {
@ -332,20 +334,20 @@ namespace SHADE
comp.isClicked = true; comp.isClicked = true;
} }
#endif #endif
//SHLOG_INFO("HOVERED")
} }
else else
{ {
comp.isHovered = false; comp.isHovered = false;
//SHLOG_INFO("NOT HOVERED")
} }
if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
{ {
comp.isClicked = false; comp.isClicked = false;
comp.value = !comp.value; comp.value = !comp.value;
SHButtonClickEvent clickEvent; SHButtonClickEvent clickEvent;
clickEvent.EID = comp.GetEID(); clickEvent.EID = comp.GetEID();
clickEvent.value = comp.value;
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT); SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
} }