Added changing texture of buttons
This commit is contained in:
parent
02ba0c6dc9
commit
a41354f2ce
|
@ -1,4 +1,4 @@
|
||||||
Start in Fullscreen: false
|
Start in Fullscreen: false
|
||||||
Starting Scene ID: 97158628
|
Starting Scene ID: 87244611
|
||||||
Window Size: {x: 1920, y: 1080}
|
Window Size: {x: 1920, y: 1080}
|
||||||
Window Title: SHADE Engine
|
Window Title: SHADE Engine
|
|
@ -14,7 +14,7 @@
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
Transform Component:
|
Transform Component:
|
||||||
Translate: {x: -3.5999999, y: 3.0999999, z: 0}
|
Translate: {x: 0, y: 0, z: 0}
|
||||||
Rotate: {x: 0, y: 0, z: 0}
|
Rotate: {x: 0, y: 0, z: 0}
|
||||||
Scale: {x: 1, y: 1, z: 1}
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
|
|
|
@ -32,8 +32,10 @@ namespace SHADE
|
||||||
|
|
||||||
friend class SHUISystem;
|
friend class SHUISystem;
|
||||||
private:
|
private:
|
||||||
|
//Set to true when mouse is hovering over the button.
|
||||||
bool isHovered;
|
bool isHovered;
|
||||||
|
//This is set to true when the mouse clicks down, and set back to false when mouse releases.
|
||||||
|
//The event for the button click will be broadcasted when mouse release.
|
||||||
bool isClicked;
|
bool isClicked;
|
||||||
AssetID defaultTexture;
|
AssetID defaultTexture;
|
||||||
AssetID hoveredTexture;
|
AssetID hoveredTexture;
|
||||||
|
|
|
@ -33,7 +33,10 @@ namespace SHADE
|
||||||
friend class SHUISystem;
|
friend class SHUISystem;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
//Set to true when mouse is hovering over the button.
|
||||||
bool isHovered;
|
bool isHovered;
|
||||||
|
//This is set to true when the mouse clicks down, and set back to false when mouse releases.
|
||||||
|
//The event for the button click will be broadcasted when mouse release.
|
||||||
bool isClicked;
|
bool isClicked;
|
||||||
bool value;
|
bool value;
|
||||||
AssetID defaultTexture;
|
AssetID defaultTexture;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h"
|
#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h"
|
||||||
#include "Editor/SHEditor.h"
|
#include "Editor/SHEditor.h"
|
||||||
#include "Resource/SHResourceManager.h"
|
#include "Resource/SHResourceManager.h"
|
||||||
|
#include "Assets/SHAssetManager.h"
|
||||||
#include "Input/SHInputManager.h"
|
#include "Input/SHInputManager.h"
|
||||||
#include "SHUIComponent.h"
|
#include "SHUIComponent.h"
|
||||||
#include "SHButtonComponent.h"
|
#include "SHButtonComponent.h"
|
||||||
|
@ -168,9 +169,9 @@ namespace SHADE
|
||||||
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable;
|
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable;
|
||||||
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
|
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
|
||||||
//mousePos.y = windowSize.y - mousePos.y;
|
//mousePos.y = windowSize.y - mousePos.y;
|
||||||
SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y)
|
//SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y)
|
||||||
mousePos /= windowSize;
|
mousePos /= windowSize;
|
||||||
SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y)
|
//SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,29 +194,23 @@ namespace SHADE
|
||||||
//SHLOG_INFO("TopExtent: {}, {} Btm Extent: {}, {}", topExtent.x, topExtent.y, btmExtent.x, btmExtent.y)
|
//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::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
||||||
{
|
{
|
||||||
comp.isClicked = true;
|
comp.isClicked = true;
|
||||||
SHButtonClickEvent clickEvent;
|
|
||||||
clickEvent.EID = comp.GetEID();
|
|
||||||
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
||||||
{
|
{
|
||||||
comp.isClicked = true;
|
comp.isClicked = true;
|
||||||
SHButtonClickEvent clickEvent;
|
|
||||||
clickEvent.EID = comp.GetEID();
|
|
||||||
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -226,15 +221,46 @@ namespace SHADE
|
||||||
comp.isHovered = false;
|
comp.isHovered = false;
|
||||||
//SHLOG_INFO("NOT HOVERED")
|
//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()))
|
if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID()))
|
||||||
{
|
{
|
||||||
/*auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
||||||
auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
|
auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
|
||||||
|
|
||||||
auto material = renderable->GetModifiableMaterial();
|
auto material = renderable->GetModifiableMaterial();
|
||||||
material->SetProperty("texture", comp.GetDefaultTexture());*/
|
if(!comp.isHovered && !comp.isClicked)
|
||||||
|
if (SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE)
|
||||||
|
{
|
||||||
|
material->SetProperty("data.textureIndex", comp.GetDefaultTexture());
|
||||||
|
//SHLOG_INFO("SETTING DEFAULT TEXTURE")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comp.isHovered)
|
||||||
|
{
|
||||||
|
if (SHAssetManager::GetType(comp.GetHoveredTexture()) == AssetType::TEXTURE)
|
||||||
|
{
|
||||||
|
material->SetProperty("data.textureIndex", comp.GetHoveredTexture());
|
||||||
|
//SHLOG_INFO("SETTING HOVERED TEXTURE")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (SHAssetManager::GetType(comp.GetClickedTexture()) == AssetType::TEXTURE)
|
||||||
|
{
|
||||||
|
material->SetProperty("data.textureIndex", comp.GetClickedTexture());
|
||||||
|
SHLOG_INFO("SETTING CLICKED TEXTURE")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,9 +288,9 @@ namespace SHADE
|
||||||
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable;
|
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->beginContentRegionAvailable;
|
||||||
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
|
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
|
||||||
//mousePos.y = windowSize.y - mousePos.y;
|
//mousePos.y = windowSize.y - mousePos.y;
|
||||||
SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y)
|
//SHLOG_INFO("mouse pos: {}, {}", mousePos.x, mousePos.y)
|
||||||
mousePos /= windowSize;
|
mousePos /= windowSize;
|
||||||
SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y)
|
//SHLOG_INFO("mouse pos normalized: {}, {}", mousePos.x, mousePos.y)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -296,25 +322,15 @@ namespace SHADE
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
if (SHSystemManager::GetSystem<SHEditor>()->editorState == SHEditor::State::PLAY)
|
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.isClicked = true;
|
||||||
comp.value = !comp.value;
|
|
||||||
SHButtonClickEvent clickEvent;
|
|
||||||
clickEvent.EID = comp.GetEID();
|
|
||||||
clickEvent.value = comp.value;
|
|
||||||
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_CLICK_EVENT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LMB))
|
||||||
{
|
{
|
||||||
comp.isClicked = true;
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -324,13 +340,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()))
|
if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID()))
|
||||||
{
|
{
|
||||||
/*auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
|
||||||
auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
|
auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
|
||||||
|
|
||||||
auto material = renderable->GetModifiableMaterial();
|
auto material = renderable->GetModifiableMaterial();
|
||||||
material->SetProperty("texture", comp.GetDefaultTexture());*/
|
if (comp.GetValue() == false)
|
||||||
|
{
|
||||||
|
if (SHAssetManager::GetType(comp.GetDefaultTexture()) == AssetType::TEXTURE)
|
||||||
|
{
|
||||||
|
material->SetProperty("data.textureIndex", comp.GetDefaultTexture());
|
||||||
|
//SHLOG_INFO("SETTING DEFAULT TEXTURE")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (SHAssetManager::GetType(comp.GetToggledTexture()) == AssetType::TEXTURE)
|
||||||
|
{
|
||||||
|
material->SetProperty("data.textureIndex", comp.GetToggledTexture());
|
||||||
|
//SHLOG_INFO("SETTING DEFAULT TEXTURE")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue