|
|
|
@ -9,6 +9,7 @@
|
|
|
|
|
#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h"
|
|
|
|
|
#include "Editor/SHEditor.h"
|
|
|
|
|
#include "Resource/SHResourceManager.h"
|
|
|
|
|
#include "Assets/SHAssetManager.h"
|
|
|
|
|
#include "Input/SHInputManager.h"
|
|
|
|
|
#include "SHUIComponent.h"
|
|
|
|
|
#include "SHButtonComponent.h"
|
|
|
|
@ -168,9 +169,9 @@ namespace SHADE
|
|
|
|
|
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable;
|
|
|
|
|
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
|
|
|
|
|
//mousePos.y = windowSize.y - mousePos.y;
|
|
|
|
|
SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
//SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
mousePos /= windowSize;
|
|
|
|
|
SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
//SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -193,31 +194,25 @@ namespace SHADE
|
|
|
|
|
//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
|
|
|
|
|
&& mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y)
|
|
|
|
|
{
|
|
|
|
|
comp.isHovered = true;
|
|
|
|
|
#ifdef SHEDITOR
|
|
|
|
|
if (SHSystemManager::GetSystem<SHEditor>()->editorState == SHEditor::State::PLAY)
|
|
|
|
|
#ifdef SHEDITOR
|
|
|
|
|
//if (SHSystemManager::GetSystem<SHEditor>()->editorState == SHEditor::State::PLAY)
|
|
|
|
|
{
|
|
|
|
|
if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = true;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = comp.GetEID();
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
#else
|
|
|
|
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = true;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = comp.GetEID();
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//SHLOG_INFO("HOVERED")
|
|
|
|
|
}
|
|
|
|
@ -226,15 +221,45 @@ namespace SHADE
|
|
|
|
|
comp.isHovered = false;
|
|
|
|
|
//SHLOG_INFO("NOT HOVERED")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = false;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = comp.GetEID();
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID()))
|
|
|
|
|
{
|
|
|
|
|
/*auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
|
|
|
|
auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
|
|
|
|
|
auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
|
|
|
|
//auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
|
|
|
|
|
|
|
|
|
|
auto material = renderable->GetModifiableMaterial();
|
|
|
|
|
material->SetProperty("texture", comp.GetDefaultTexture());*/
|
|
|
|
|
if(!comp.isHovered && !comp.isClicked)
|
|
|
|
|
if (comp.GetDefaultTexture() != 0 && SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE)
|
|
|
|
|
{
|
|
|
|
|
material->SetProperty("data.textureIndex", comp.GetDefaultTexture());
|
|
|
|
|
//SHLOG_INFO("SETTING DEFAULT TEXTURE")
|
|
|
|
|
}
|
|
|
|
|
else if (comp.isClicked)
|
|
|
|
|
{
|
|
|
|
|
if (comp.GetClickedTexture() != 0 && SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE)
|
|
|
|
|
{
|
|
|
|
|
material->SetProperty("data.textureIndex", comp.GetClickedTexture());
|
|
|
|
|
//SHLOG_INFO("SETTING CLICKED TEXTURE")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (comp.GetHoveredTexture() != 0 && SHAssetManager::GetType(comp.GetHoveredTexture()) == AssetType::TEXTURE)
|
|
|
|
|
{
|
|
|
|
|
material->SetProperty("data.textureIndex", comp.GetHoveredTexture());
|
|
|
|
|
//SHLOG_INFO("SETTING HOVERED TEXTURE")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -262,9 +287,9 @@ namespace SHADE
|
|
|
|
|
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable;
|
|
|
|
|
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
|
|
|
|
|
//mousePos.y = windowSize.y - mousePos.y;
|
|
|
|
|
SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
//SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
mousePos /= windowSize;
|
|
|
|
|
SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
//SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -296,25 +321,15 @@ namespace SHADE
|
|
|
|
|
#ifdef SHEDITOR
|
|
|
|
|
if (SHSystemManager::GetSystem<SHEditor>()->editorState == SHEditor::State::PLAY)
|
|
|
|
|
{
|
|
|
|
|
if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = true;
|
|
|
|
|
comp.value = !comp.value;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = comp.GetEID();
|
|
|
|
|
clickEvent.value = comp.value;
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = true;
|
|
|
|
|
comp.value = !comp.value;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = comp.GetEID();
|
|
|
|
|
clickEvent.value = comp.value;
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
@ -324,13 +339,39 @@ namespace SHADE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (comp.isClicked && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
|
|
|
|
{
|
|
|
|
|
comp.isClicked = false;
|
|
|
|
|
comp.value = !comp.value;
|
|
|
|
|
SHButtonClickEvent clickEvent;
|
|
|
|
|
clickEvent.EID = comp.GetEID();
|
|
|
|
|
clickEvent.value = comp.value;
|
|
|
|
|
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID()))
|
|
|
|
|
{
|
|
|
|
|
/*auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
|
|
|
|
auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
|
|
|
|
|
auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
|
|
|
|
//auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
|
|
|
|
|
|
|
|
|
|
auto material = renderable->GetModifiableMaterial();
|
|
|
|
|
material->SetProperty("texture", comp.GetDefaultTexture());*/
|
|
|
|
|
if (comp.GetValue() == false)
|
|
|
|
|
{
|
|
|
|
|
if (comp.GetDefaultTexture()!= 0 && SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE)
|
|
|
|
|
{
|
|
|
|
|
material->SetProperty("data.textureIndex", comp.GetDefaultTexture());
|
|
|
|
|
//SHLOG_INFO("SETTING DEFAULT TEXTURE")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (comp.GetToggledTexture() != 0 && SHAssetManager::GetType(comp.GetToggledTexture()) == AssetType::TEXTURE)
|
|
|
|
|
{
|
|
|
|
|
material->SetProperty("data.textureIndex", comp.GetToggledTexture());
|
|
|
|
|
//SHLOG_INFO("SETTING DEFAULT TEXTURE")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|