Fixed button click state not resetting bug #398

Merged
maverickdgg merged 4 commits from SP3-20-UI-System into main 2023-03-05 14:46:18 +08:00
6 changed files with 16 additions and 7 deletions

View File

@ -5193,6 +5193,7 @@
Default Texture: 63979907
Hovered Texture: 51379325
Clicked Texture: 66788278
current texture: 0
IsActive: true
UI Component:
Canvas ID: 458
@ -5226,6 +5227,7 @@
Default Texture: 61602036
Hovered Texture: 58910810
Clicked Texture: 57786063
current texture: 0
IsActive: true
UI Component:
Canvas ID: 458
@ -5259,6 +5261,7 @@
Default Texture: 64806384
Hovered Texture: 58347825
Clicked Texture: 63234380
current texture: 0
IsActive: true
UI Component:
Canvas ID: 458

View File

@ -119,7 +119,7 @@ namespace SHADE_Scripting.UI
return;
if (tweening == true && thread != null)
{
Debug.Log("Tweening value " + thread.GetValue());
transform.LocalScale = defaultScale * thread.GetValue();
currentScale = thread.GetValue();
if (thread.IsCompleted())

View File

@ -37,7 +37,7 @@ public class PauseMenu : Script
UIElement resume = resumeBtn.GetComponent<UIElement>();
if (resume != null)
{
resume.OnClick.RegisterAction(() =>
resume.OnRelease.RegisterAction(() =>
{
if (GameManager.Instance.GamePause)
{
@ -61,7 +61,7 @@ public class PauseMenu : Script
UIElement retry = retryBtn.GetComponent<UIElement>();
if (retry != null)
{
retry.OnClick.RegisterAction(() =>
retry.OnRelease.RegisterAction(() =>
{
Audio.StopAllSounds();
SceneManager.RestartScene();
@ -75,7 +75,7 @@ public class PauseMenu : Script
UIElement quit = quitBtn.GetComponent<UIElement>();
if (quit != null)
{
quit.OnClick.RegisterAction(() =>
quit.OnRelease.RegisterAction(() =>
{
Audio.StopAllSounds();
//go to main menu

View File

@ -58,6 +58,7 @@ RTTR_REGISTRATION
.property("Default Texture", &SHButtonComponent::GetDefaultTexture, &SHButtonComponent::SetDefaultTexture)
.property("Hovered Texture", &SHButtonComponent::GetHoveredTexture, &SHButtonComponent::SetHoveredTexture)
.property("Clicked Texture", &SHButtonComponent::GetClickedTexture, &SHButtonComponent::SetClickedTexture)
.property("current texture", &SHButtonComponent::currentTexture)
;

View File

@ -26,7 +26,7 @@ namespace SHADE
void SetHoveredTexture(AssetID texture) noexcept;
void SetClickedTexture(AssetID texture) noexcept;
AssetID currentTexture;
friend class SHUISystem;
private:
@ -35,7 +35,7 @@ namespace SHADE
AssetID hoveredTexture;
AssetID clickedTexture;
AssetID currentTexture;
RTTR_ENABLE()

View File

@ -263,6 +263,11 @@ namespace SHADE
return true;
}
//In case the UI was clicked but the mouse is not held down and the key up frame was missed because of active state.
if (comp.isClicked && !SHInputManager::GetKey(SHInputManager::SH_KEYCODE::LMB))
{
comp.isClicked = false;
}
return false;
@ -318,7 +323,7 @@ namespace SHADE
//SHLOG_INFO("SETTING HOVERED TEXTURE")
}
}
if (textureID != 0 && textureID != comp.currentTexture)
if (textureID != 0 && comp.currentTexture != textureID)
{
auto material = renderable->GetModifiableMaterial();
comp.currentTexture = textureID;