Moved UIRoutines call order. Call FinalizeChanges. Fixed UI Button Events. #359

Merged
maverickdgg merged 8 commits from SP3-20-UI-System into main 2023-02-23 14:00:51 +08:00
4 changed files with 16 additions and 5 deletions
Showing only changes of commit 1b865b129b - Show all commits

View File

@ -11,13 +11,14 @@ public class ChangeSceneButton : Script
UIElement ui = GetComponent<UIElement>(); UIElement ui = GetComponent<UIElement>();
if (ui != null) if (ui != null)
{ {
ui.OnClick.RegisterAction(() => ui.OnHoverEnter.RegisterAction(() =>
{ {
Debug.Log("C# Hover Enter");
if (sceneID != 0) if (sceneID != 0)
{ {
Audio.PlaySFXOnce2D("event:/UI/success"); //Audio.PlaySFXOnce2D("event:/UI/success");
SceneManager.ChangeScene(sceneID); //SceneManager.ChangeScene(sceneID);
Audio.StopAllSounds(); //Audio.StopAllSounds();
} }
}); });
} }

View File

@ -204,6 +204,7 @@ namespace SHADE
SHButtonClickEvent clickEvent; SHButtonClickEvent clickEvent;
clickEvent.EID = comp.GetEID(); clickEvent.EID = comp.GetEID();
SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_ENTER_EVENT); SHEventManager::BroadcastEvent(clickEvent, SH_BUTTON_HOVER_ENTER_EVENT);
SHLOG_INFO("C++ BROADCASTED HOVER ENTER EVENT EID: {}", clickEvent.EID);
} }
comp.isHovered = true; comp.isHovered = true;
@ -313,6 +314,7 @@ namespace SHADE
auto material = renderable->GetModifiableMaterial(); auto material = renderable->GetModifiableMaterial();
comp.currentTexture = textureID; comp.currentTexture = textureID;
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID)); material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID));
loadTexture = true;
} }
@ -367,6 +369,7 @@ namespace SHADE
auto material = renderable->GetModifiableMaterial(); auto material = renderable->GetModifiableMaterial();
comp.currentTexture = textureID; comp.currentTexture = textureID;
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID)); material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID));
loadTexture = true;
} }
@ -390,6 +393,11 @@ namespace SHADE
if (SHSceneManager::CheckNodeAndComponentsActive<SHToggleButtonComponent>(comp.GetEID())) if (SHSceneManager::CheckNodeAndComponentsActive<SHToggleButtonComponent>(comp.GetEID()))
system->UpdateToggleButtonComponent(comp); system->UpdateToggleButtonComponent(comp);
} }
if (system->loadTexture == true)
{
system->loadTexture = false;
SHResourceManager::FinaliseChanges();
}
} }
SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept

View File

@ -68,6 +68,8 @@ namespace SHADE
private: private:
bool loadTexture{false};
void UpdateUIComponent(SHUIComponent& comp) noexcept; void UpdateUIComponent(SHUIComponent& comp) noexcept;
void UpdateButtonComponent(SHButtonComponent& comp) noexcept; void UpdateButtonComponent(SHButtonComponent& comp) noexcept;
void UpdateToggleButtonComponent(SHToggleButtonComponent& comp) noexcept; void UpdateToggleButtonComponent(SHToggleButtonComponent& comp) noexcept;

View File

@ -63,7 +63,7 @@ namespace SHADE
} }
// Return the event // Return the event
return onClickEventMap[owner.EntityId]; return onReleasedEventMap[owner.EntityId];
} }
CallbackEvent^ UIElement::OnHoverEnter::get() CallbackEvent^ UIElement::OnHoverEnter::get()
{ {