diff --git a/Code/Legacy/CryCommon/ISystem.h b/Code/Legacy/CryCommon/ISystem.h index 6fdc8b52fe..14b78fd155 100644 --- a/Code/Legacy/CryCommon/ISystem.h +++ b/Code/Legacy/CryCommon/ISystem.h @@ -614,7 +614,6 @@ struct SSystemGlobalEnvironment ISystem* pSystem = nullptr; ILog* pLog; IMovieSystem* pMovieSystem; - ILyShine* pLyShine; SharedEnvironmentInstance* pSharedEnvironment; #if defined(AZ_RESTRICTED_PLATFORM) diff --git a/Gems/LyShine/Code/Editor/CommandCanvasPropertiesChange.cpp b/Gems/LyShine/Code/Editor/CommandCanvasPropertiesChange.cpp index 30a716b142..e90252e54a 100644 --- a/Gems/LyShine/Code/Editor/CommandCanvasPropertiesChange.cpp +++ b/Gems/LyShine/Code/Editor/CommandCanvasPropertiesChange.cpp @@ -64,7 +64,7 @@ void CommandCanvasPropertiesChange::Recreate(bool isUndo) // Create a new canvas from the XML and release the old canvas, use the new entity context for // the new canvas const AZStd::string& xml = isUndo ? m_undoXml : m_redoXml; - gEnv->pLyShine->ReloadCanvasFromXml(xml, newEntityContext); + AZ::Interface::Get()->ReloadCanvasFromXml(xml, newEntityContext); // Tell the editor window to use the new entity context m_editorWindow->ReplaceEntityContext(newEntityContext); diff --git a/Gems/LyShine/Code/Editor/EditorWindow.cpp b/Gems/LyShine/Code/Editor/EditorWindow.cpp index 7b60474ed5..8f1d574ae5 100644 --- a/Gems/LyShine/Code/Editor/EditorWindow.cpp +++ b/Gems/LyShine/Code/Editor/EditorWindow.cpp @@ -315,7 +315,7 @@ EditorWindow::~EditorWindow() // unload the preview mode canvas if it exists (e.g. if we close the editor window while in preview mode) if (m_previewModeCanvasEntityId.IsValid()) { - gEnv->pLyShine->ReleaseCanvas(m_previewModeCanvasEntityId, false); + AZ::Interface::Get()->ReleaseCanvas(m_previewModeCanvasEntityId, false); } delete m_sliceLibraryTree; @@ -564,7 +564,7 @@ bool EditorWindow::OnPreWarning(const char* /*window*/, const char* /*fileName*/ void EditorWindow::DestroyCanvas(const UiCanvasMetadata& canvasMetadata) { - gEnv->pLyShine->ReleaseCanvas(canvasMetadata.m_canvasEntityId, true); + AZ::Interface::Get()->ReleaseCanvas(canvasMetadata.m_canvasEntityId, true); } bool EditorWindow::IsCanvasTabMetadataValidForTabIndex(int index) @@ -950,14 +950,14 @@ bool EditorWindow::LoadCanvas(const QString& canvasFilename, bool autoLoad, bool bool errorsOnLoad = false; if (canvasFilename.isEmpty()) { - canvasEntityId = gEnv->pLyShine->CreateCanvasInEditor(entityContext); + canvasEntityId = AZ::Interface::Get()->CreateCanvasInEditor(entityContext); } else { // Collect errors and warnings during the canvas load AZ::Debug::TraceMessageBus::Handler::BusConnect(); - canvasEntityId = gEnv->pLyShine->LoadCanvasInEditor(assetIdPathname.c_str(), sourceAssetPathName.c_str(), entityContext); + canvasEntityId = AZ::Interface::Get()->LoadCanvasInEditor(assetIdPathname.c_str(), sourceAssetPathName.c_str(), entityContext); // Stop receiving error and warning events AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); @@ -1603,7 +1603,7 @@ void EditorWindow::ToggleEditorMode() EBUS_EVENT_RESULT(entity, AZ::ComponentApplicationBus, FindEntity, m_previewModeCanvasEntityId); if (entity) { - gEnv->pLyShine->ReleaseCanvas(m_previewModeCanvasEntityId, false); + AZ::Interface::Get()->ReleaseCanvas(m_previewModeCanvasEntityId, false); } m_previewModeCanvasEntityId.SetInvalid(); } diff --git a/Gems/LyShine/Code/Editor/LyShineEditorSystemComponent.cpp b/Gems/LyShine/Code/Editor/LyShineEditorSystemComponent.cpp index 229101d4c0..3ec6980cfb 100644 --- a/Gems/LyShine/Code/Editor/LyShineEditorSystemComponent.cpp +++ b/Gems/LyShine/Code/Editor/LyShineEditorSystemComponent.cpp @@ -211,9 +211,9 @@ namespace LyShineEditor void LyShineEditorSystemComponent::OnStopPlayInEditor() { // reset UI system - if (gEnv->pLyShine) + if (AZ::Interface::Get()) { - gEnv->pLyShine->Reset(); + AZ::Interface::Get()->Reset(); } } } diff --git a/Gems/LyShine/Code/Editor/SpriteBorderEditor.cpp b/Gems/LyShine/Code/Editor/SpriteBorderEditor.cpp index 93d77bd174..b9ca4cd32c 100644 --- a/Gems/LyShine/Code/Editor/SpriteBorderEditor.cpp +++ b/Gems/LyShine/Code/Editor/SpriteBorderEditor.cpp @@ -7,6 +7,7 @@ */ #include "SpriteBorderEditorCommon.h" +#include #include #include #include @@ -35,7 +36,7 @@ SpriteBorderEditor::SpriteBorderEditor(const char* path, QWidget* parent) setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint); // Make sure the sprite can load and be displayed before continuing - m_sprite = gEnv->pLyShine->LoadSprite(m_spritePath.toLatin1().constData()); + m_sprite = AZ::Interface::Get()->LoadSprite(m_spritePath.toLatin1().constData()); QString fullPath = Path::GamePathToFullPath(m_sprite->GetTexturePathname().c_str()); const bool imageWontLoad = !m_sprite || QPixmap(fullPath).isNull(); if (imageWontLoad) diff --git a/Gems/LyShine/Code/Editor/ViewportWidget.cpp b/Gems/LyShine/Code/Editor/ViewportWidget.cpp index eb5625ac31..32231058bf 100644 --- a/Gems/LyShine/Code/Editor/ViewportWidget.cpp +++ b/Gems/LyShine/Code/Editor/ViewportWidget.cpp @@ -181,7 +181,7 @@ namespace EBUS_EVENT_ID_RESULT(handled, canvasEntityId, UiCanvasBus, HandleInputEvent, inputSnapshot, viewportPos, activeModifierKeys); // Execute events that have been queued during the input event handler - gEnv->pLyShine->ExecuteQueuedEvents(); + AZ::Interface::Get()->ExecuteQueuedEvents(); return handled; } @@ -192,7 +192,7 @@ namespace EBUS_EVENT_ID_RESULT(handled, canvasEntityId, UiCanvasBus, HandleTextEvent, textUTF8); // Execute events that have been queued during the input event handler - gEnv->pLyShine->ExecuteQueuedEvents(); + AZ::Interface::Get()->ExecuteQueuedEvents(); return handled; } @@ -265,7 +265,7 @@ ViewportWidget::~ViewportWidget() // Notify LyShine that this is no longer a valid UiRenderer. // Only one viewport/renderer is currently supported in the UI Editor - CLyShine* lyShine = static_cast(gEnv->pLyShine); + CLyShine* lyShine = static_cast(AZ::Interface::Get()); lyShine->SetUiRendererForEditor(nullptr); } @@ -276,7 +276,7 @@ void ViewportWidget::InitUiRenderer() // Notify LyShine that this is the UiRenderer to be used for rendering // UI canvases that are loaded in the UI Editor. // Only one viewport/renderer is currently supported in the UI Editor - CLyShine* lyShine = static_cast(gEnv->pLyShine); + CLyShine* lyShine = static_cast(AZ::Interface::Get()); lyShine->SetUiRendererForEditor(m_uiRenderer); m_draw2d = AZStd::make_shared(GetViewportContext()); @@ -1123,7 +1123,7 @@ void ViewportWidget::UpdatePreviewMode(float deltaTime) EBUS_EVENT_ID(canvasEntityId, UiEditorCanvasBus, UpdateCanvasInEditorViewport, deltaTime, true); // Execute events that have been queued during the canvas update - gEnv->pLyShine->ExecuteQueuedEvents(); + AZ::Interface::Get()->ExecuteQueuedEvents(); } } diff --git a/Gems/LyShine/Code/Include/LyShine/IDraw2d.h b/Gems/LyShine/Code/Include/LyShine/IDraw2d.h index 77dc5ac601..e880ca54a7 100644 --- a/Gems/LyShine/Code/Include/LyShine/IDraw2d.h +++ b/Gems/LyShine/Code/Include/LyShine/IDraw2d.h @@ -473,9 +473,9 @@ public: // static member functions //! Helper to get the default IDraw2d interface static IDraw2d* GetDefaultDraw2d() { - if (gEnv && gEnv->pLyShine) // [LYSHINE_ATOM_TODO][GHI #3569] Remove LyShine global interface pointer from legacy global environment + if (AZ::Interface::Get()) { - IDraw2d* draw2d = gEnv->pLyShine->GetDraw2d(); + IDraw2d* draw2d = AZ::Interface::Get()->GetDraw2d(); return reinterpret_cast(draw2d); } @@ -485,9 +485,9 @@ public: // static member functions //! Helper to load a texture static AZ::Data::Instance LoadTexture(const AZStd::string& pathName) { - if (gEnv && gEnv->pLyShine) // [LYSHINE_ATOM_TODO][GHI #3569] Remove LyShine global interface pointer from legacy global environment + if (AZ::Interface::Get()) { - return gEnv->pLyShine->LoadTexture(pathName); + return AZ::Interface::Get()->LoadTexture(pathName); } return nullptr; diff --git a/Gems/LyShine/Code/Include/LyShine/ILyShine.h b/Gems/LyShine/Code/Include/LyShine/ILyShine.h index 71ca6ec074..d05e105c87 100644 --- a/Gems/LyShine/Code/Include/LyShine/ILyShine.h +++ b/Gems/LyShine/Code/Include/LyShine/ILyShine.h @@ -38,7 +38,10 @@ namespace AZ::RPI class ILyShine { public: - virtual ~ILyShine(){} + AZ_RTTI(ILyShine, "{652ED9D7-0782-44E8-BCE7-65DD38C90907}"); + + ILyShine() = default; + virtual ~ILyShine() = default; //! Delete this object virtual void Release() = 0; diff --git a/Gems/LyShine/Code/Source/LyShine.cpp b/Gems/LyShine/Code/Source/LyShine.cpp index b362ed2106..df26a905ad 100644 --- a/Gems/LyShine/Code/Source/LyShine.cpp +++ b/Gems/LyShine/Code/Source/LyShine.cpp @@ -124,7 +124,7 @@ AllocateConstIntCVar(CLyShine, CV_ui_RunUnitTestsOnStartup); #endif //////////////////////////////////////////////////////////////////////////////////////////////////// -CLyShine::CLyShine([[maybe_unused]] ISystem* system) +CLyShine::CLyShine() : AzFramework::InputChannelEventListener(AzFramework::InputChannelEventListener::GetPriorityUI()) , AzFramework::InputTextEventListener(AzFramework::InputTextEventListener::GetPriorityUI()) , m_draw2d(new CDraw2d) @@ -386,8 +386,8 @@ void CLyShine::Update(float deltaTimeInSeconds) } // Tell the UI system the size of the viewport we are rendering to - this drives the - // canvas size for full screen UI canvases. It needs to be set before either pLyShine->Update or - // pLyShine->Render are called. It must match the viewport size that the input system is using. + // canvas size for full screen UI canvases. It needs to be set before either lyShine->Update or + // lyShine->Render are called. It must match the viewport size that the input system is using. SetViewportSize(m_uiRenderer->GetViewportSize()); // Guard against nested updates. This can occur if a canvas update below triggers the load screen component's @@ -708,10 +708,10 @@ void CLyShine::RenderUiCursor() //////////////////////////////////////////////////////////////////////////////////////////////////// void CLyShine::DebugReportDrawCalls(IConsoleCmdArgs* cmdArgs) { - if (gEnv->pLyShine) + if (AZ::Interface::Get()) { // We want to use an internal-only non-static function so downcast to CLyShine - CLyShine* pLyShine = static_cast(gEnv->pLyShine); + CLyShine* lyShine = static_cast(AZ::Interface::Get()); // There is an optional parameter which is a name to include in the output filename AZStd::string name; @@ -721,7 +721,7 @@ void CLyShine::DebugReportDrawCalls(IConsoleCmdArgs* cmdArgs) } // Use the canvas manager to access all the loaded canvases - pLyShine->m_uiCanvasManager->DebugReportDrawCalls(name); + lyShine->m_uiCanvasManager->DebugReportDrawCalls(name); } } #endif @@ -742,7 +742,7 @@ void CLyShine::RunUnitTests(IConsoleCmdArgs* cmdArgs) return; } - CLyShine* lyShine = static_cast(gEnv->pLyShine); + CLyShine* lyShine = static_cast(AZ::Interface::Get()); AZ_Assert(lyShine, "Attempting to run unit-tests prior to LyShine initialization!"); TextMarkup::UnitTest(cmdArgs); diff --git a/Gems/LyShine/Code/Source/LyShine.h b/Gems/LyShine/Code/Source/LyShine.h index eab52258c1..2fd0f80210 100644 --- a/Gems/LyShine/Code/Source/LyShine.h +++ b/Gems/LyShine/Code/Source/LyShine.h @@ -48,7 +48,7 @@ class CLyShine public: //! Create the LyShine object, the given system pointer is stored internally - CLyShine(ISystem* system); + CLyShine(); // ILyShine diff --git a/Gems/LyShine/Code/Source/LyShineDebug.cpp b/Gems/LyShine/Code/Source/LyShineDebug.cpp index 7e99652f45..3502699525 100644 --- a/Gems/LyShine/Code/Source/LyShineDebug.cpp +++ b/Gems/LyShine/Code/Source/LyShineDebug.cpp @@ -997,7 +997,7 @@ static AZ::Entity* CreateButton(const char* name, bool atRoot, AZ::EntityId pare EBUS_EVENT_ID(buttonId, UiInteractableStatesBus, SetStateAlpha, UiInteractableStatesInterface::StatePressed, buttonId, pressedColor.GetA()); AZStd::string pathname = "Textures/Basic/Button_Sliced_Normal.sprite"; - ISprite* sprite = gEnv->pLyShine->LoadSprite(pathname); + ISprite* sprite = AZ::Interface::Get()->LoadSprite(pathname); EBUS_EVENT_ID(buttonId, UiImageBus, SetSprite, sprite); EBUS_EVENT_ID(buttonId, UiImageBus, SetImageType, UiImageInterface::ImageType::Sliced); @@ -1096,7 +1096,7 @@ static AZ::Entity* CreateTextInput(const char* name, bool atRoot, AZ::EntityId p EBUS_EVENT_ID(textInputId, UiInteractableStatesBus, SetStateAlpha, UiInteractableStatesInterface::StatePressed, textInputId, pressedColor.GetA()); AZStd::string pathname = "Textures/Basic/Button_Sliced_Normal.sprite"; - ISprite* sprite = gEnv->pLyShine->LoadSprite(pathname); + ISprite* sprite = AZ::Interface::Get()->LoadSprite(pathname); EBUS_EVENT_ID(textInputId, UiImageBus, SetSprite, sprite); EBUS_EVENT_ID(textInputId, UiImageBus, SetImageType, UiImageInterface::ImageType::Sliced); @@ -1192,7 +1192,7 @@ static void DestroyTestCanvas() delete g_testActionListener2; g_testActionListener2 = nullptr; - gEnv->pLyShine->ReleaseCanvas(g_testCanvasId, false); + AZ::Interface::Get()->ReleaseCanvas(g_testCanvasId, false); g_testCanvasId.SetInvalid(); } } @@ -1216,7 +1216,7 @@ static void TestCanvasCreate ([[maybe_unused]] IConsoleCmdArgs* Cmd) DestroyTestCanvas(); // test creation of canvas and some simple elements - AZ::EntityId canvasEntityId = gEnv->pLyShine->CreateCanvas(); + AZ::EntityId canvasEntityId = AZ::Interface::Get()->CreateCanvas(); UiCanvasInterface* canvas = UiCanvasBus::FindFirstHandler(canvasEntityId); if (!canvas) { diff --git a/Gems/LyShine/Code/Source/LyShineLoadScreen.cpp b/Gems/LyShine/Code/Source/LyShineLoadScreen.cpp index c59cb5cb34..e0916d43b2 100644 --- a/Gems/LyShine/Code/Source/LyShineLoadScreen.cpp +++ b/Gems/LyShine/Code/Source/LyShineLoadScreen.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -63,7 +64,7 @@ namespace LyShine AZ_ErrorOnce(nullptr, false, "NotifyGameLoadStart needs to be removed/ported to use Atom"); return false; #if 0 - if (!gEnv || gEnv->pRenderer || !gEnv->pLyShine) + if (!gEnv || gEnv->pRenderer || !AZ::Interface::Get()) { return false; } @@ -103,7 +104,7 @@ namespace LyShine return false; //TODO: gEnv->pRenderer is always null, fix the logic below #if 0 - if (!gEnv || gEnv->pRenderer || !gEnv->pLyShine) + if (!gEnv || gEnv->pRenderer || !AZ::Interface::Get()) { return false; } @@ -140,22 +141,22 @@ namespace LyShine void LyShineLoadScreenComponent::UpdateAndRender([[maybe_unused]] float deltaTimeInSeconds) { AZ_Assert(m_isPlaying, "LyShineLoadScreenComponent should not be connected to LoadScreenUpdateNotificationBus while not playing"); - AZ_ErrorOnce(nullptr, m_isPlaying && gEnv && gEnv->pLyShine, "UpdateAndRender needs to be removed/ported to use Atom"); + AZ_ErrorOnce(nullptr, m_isPlaying && AZ::Interface::Get(), "UpdateAndRender needs to be removed/ported to use Atom"); //TODO: gEnv->pRenderer is always null, fix the logic below #if 0 - if (m_isPlaying && gEnv && gEnv->pLyShine && gEnv->pRenderer) + if (m_isPlaying && gEnv && AZ::Interface::Get() && gEnv->pRenderer) { AZ_Assert(GetCurrentThreadId() == gEnv->mMainThreadId, "UpdateAndRender should only be called from the main thread"); // update the animation system - gEnv->pLyShine->Update(deltaTimeInSeconds); + AZ::Interface::Get()->Update(deltaTimeInSeconds); // Render. gEnv->pRenderer->SetViewport(0, 0, gEnv->pRenderer->GetOverlayWidth(), gEnv->pRenderer->GetOverlayHeight()); gEnv->pRenderer->BeginFrame(); - gEnv->pLyShine->Render(); + AZ::Interface::Get()->Render(); gEnv->pRenderer->EndFrame(); } #endif @@ -177,7 +178,7 @@ namespace LyShine m_isPlaying = false; - if (gEnv && gEnv->pLyShine) + if (AZ::Interface::Get()) { AZ::Entity* canvasEntity = nullptr; @@ -187,8 +188,8 @@ namespace LyShine EBUS_EVENT_RESULT(canvasEntity, AZ::ComponentApplicationBus, FindEntity, m_gameCanvasEntityId); if (canvasEntity) { - gEnv->pLyShine->ReleaseCanvas(m_gameCanvasEntityId, false); - gEnv->pLyShine->OnLoadScreenUnloaded(); + AZ::Interface::Get()->ReleaseCanvas(m_gameCanvasEntityId, false); + AZ::Interface::Get()->OnLoadScreenUnloaded(); } } @@ -198,8 +199,8 @@ namespace LyShine EBUS_EVENT_RESULT(canvasEntity, AZ::ComponentApplicationBus, FindEntity, m_levelCanvasEntityId); if (canvasEntity) { - gEnv->pLyShine->ReleaseCanvas(m_levelCanvasEntityId, false); - gEnv->pLyShine->OnLoadScreenUnloaded(); + AZ::Interface::Get()->ReleaseCanvas(m_levelCanvasEntityId, false); + AZ::Interface::Get()->OnLoadScreenUnloaded(); } } } @@ -234,7 +235,7 @@ namespace LyShine return AZ::EntityId(); } - AZ::EntityId canvasId = gEnv->pLyShine->LoadCanvas(path); + AZ::EntityId canvasId = AZ::Interface::Get()->LoadCanvas(path); AZ_Warning("LoadScreenComponent", canvasId.IsValid(), "Can't load canvas: %s", path.c_str()); if (!canvasId.IsValid()) { diff --git a/Gems/LyShine/Code/Source/LyShineSystemComponent.cpp b/Gems/LyShine/Code/Source/LyShineSystemComponent.cpp index 787797e462..7253935c2d 100644 --- a/Gems/LyShine/Code/Source/LyShineSystemComponent.cpp +++ b/Gems/LyShine/Code/Source/LyShineSystemComponent.cpp @@ -384,16 +384,16 @@ namespace LyShine // When module is linked statically, we'll share the application's gEnv pointer. gEnv = system.GetGlobalEnvironment(); #endif - m_pLyShine = new CLyShine(gEnv->pSystem); - gEnv->pLyShine = m_pLyShine; + m_lyShine = AZStd::make_unique(); + AZ::Interface::Register(m_lyShine.get()); system.GetILevelSystem()->AddListener(this); BroadcastCursorImagePathname(); - if (gEnv->pLyShine) + if (AZ::Interface::Get()) { - gEnv->pLyShine->PostInit(); + AZ::Interface::Get()->PostInit(); } } @@ -402,18 +402,20 @@ namespace LyShine { system.GetILevelSystem()->RemoveListener(this); - gEnv->pLyShine = nullptr; - delete m_pLyShine; - m_pLyShine = nullptr; + if (m_lyShine) + { + AZ::Interface::Unregister(m_lyShine.get()); + m_lyShine.reset(); + } } //////////////////////////////////////////////////////////////////////// void LyShineSystemComponent::OnUnloadComplete([[maybe_unused]] const char* levelName) { // Perform level unload procedures for the LyShine UI system - if (gEnv && gEnv->pLyShine) + if (AZ::Interface::Get()) { - gEnv->pLyShine->OnLevelUnload(); + AZ::Interface::Get()->OnLevelUnload(); } } diff --git a/Gems/LyShine/Code/Source/LyShineSystemComponent.h b/Gems/LyShine/Code/Source/LyShineSystemComponent.h index d2cdcf6761..001ddd6fab 100644 --- a/Gems/LyShine/Code/Source/LyShineSystemComponent.h +++ b/Gems/LyShine/Code/Source/LyShineSystemComponent.h @@ -107,7 +107,7 @@ namespace LyShine protected: // data - CLyShine* m_pLyShine = nullptr; + AZStd::unique_ptr m_lyShine; AzFramework::SimpleAssetReference m_cursorImagePathname; diff --git a/Gems/LyShine/Code/Source/Script/UiCanvasLuaBus.cpp b/Gems/LyShine/Code/Source/Script/UiCanvasLuaBus.cpp index 4b0ff56241..679f13b333 100644 --- a/Gems/LyShine/Code/Source/Script/UiCanvasLuaBus.cpp +++ b/Gems/LyShine/Code/Source/Script/UiCanvasLuaBus.cpp @@ -114,7 +114,7 @@ AZ::EntityId UiCanvasLuaProxy::LoadCanvas(const char* canvasFilename) CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "UiCanvasLuaProxy:LoadCanvas is deprecated. Please use UiCanvasManagerBus:LoadCanvas instead\n"); - return gEnv->pLyShine->LoadCanvas(canvasFilename); + return AZ::Interface::Get()->LoadCanvas(canvasFilename); } void UiCanvasLuaProxy::UnloadCanvas(AZ::EntityId canvasEntityId) @@ -130,7 +130,7 @@ void UiCanvasLuaProxy::UnloadCanvas(AZ::EntityId canvasEntityId) UiCanvasComponent* canvasComponent = canvasEntity->FindComponent(); if (canvasComponent) { - gEnv->pLyShine->ReleaseCanvas(canvasEntityId, false); + AZ::Interface::Get()->ReleaseCanvas(canvasEntityId, false); } else { diff --git a/Gems/LyShine/Code/Source/UiCanvasComponent.cpp b/Gems/LyShine/Code/Source/UiCanvasComponent.cpp index ea6e3681a3..0a7161ecb3 100644 --- a/Gems/LyShine/Code/Source/UiCanvasComponent.cpp +++ b/Gems/LyShine/Code/Source/UiCanvasComponent.cpp @@ -254,9 +254,9 @@ namespace UiRenderer* GetUiRendererForGame() { - if (gEnv && gEnv->pLyShine) + if (AZ::Interface::Get()) { - CLyShine* lyShine = static_cast(gEnv->pLyShine); + CLyShine* lyShine = static_cast(AZ::Interface::Get()); return lyShine->GetUiRenderer(); } return nullptr; @@ -264,9 +264,9 @@ namespace UiRenderer* GetUiRendererForEditor() { - if (gEnv && gEnv->pLyShine) + if (AZ::Interface::Get()) { - CLyShine* lyShine = static_cast(gEnv->pLyShine); + CLyShine* lyShine = static_cast(AZ::Interface::Get()); return lyShine->GetUiRendererForEditor(); } return nullptr; diff --git a/Gems/LyShine/Code/Source/UiImageComponent.cpp b/Gems/LyShine/Code/Source/UiImageComponent.cpp index a8b4210d6b..d412695ac3 100644 --- a/Gems/LyShine/Code/Source/UiImageComponent.cpp +++ b/Gems/LyShine/Code/Source/UiImageComponent.cpp @@ -588,7 +588,7 @@ void UiImageComponent::SetSpritePathname(AZStd::string spritePath) //////////////////////////////////////////////////////////////////////////////////////////////////// bool UiImageComponent::SetSpritePathnameIfExists(AZStd::string spritePath) { - if (gEnv->pLyShine->DoesSpriteTextureAssetExist(spritePath)) + if (AZ::Interface::Get()->DoesSpriteTextureAssetExist(spritePath)) { SetSpritePathname(spritePath); return true; @@ -1179,7 +1179,7 @@ void UiImageComponent::Init() // If this is called from RC.exe for example these pointers will not be set. In that case // we only need to be able to load, init and save the component. It will never be // activated. - if (!(gEnv && gEnv->pLyShine)) + if (!AZ::Interface::Get()) { return; } @@ -1192,14 +1192,14 @@ void UiImageComponent::Init() { if (!m_spritePathname.GetAssetPath().empty()) { - m_sprite = gEnv->pLyShine->LoadSprite(m_spritePathname.GetAssetPath().c_str()); + m_sprite = AZ::Interface::Get()->LoadSprite(m_spritePathname.GetAssetPath().c_str()); } } else if (m_spriteType == UiImageInterface::SpriteType::RenderTarget) { if (!m_renderTargetName.empty()) { - m_sprite = gEnv->pLyShine->CreateSprite(m_renderTargetName.c_str()); + m_sprite = AZ::Interface::Get()->CreateSprite(m_renderTargetName.c_str()); } } else @@ -2527,7 +2527,7 @@ void UiImageComponent::OnSpritePathnameChange() if (!m_spritePathname.GetAssetPath().empty()) { // Load the new texture. - newSprite = gEnv->pLyShine->LoadSprite(m_spritePathname.GetAssetPath().c_str()); + newSprite = AZ::Interface::Get()->LoadSprite(m_spritePathname.GetAssetPath().c_str()); } // if listening for notifications from a current sprite then disconnect @@ -2557,7 +2557,7 @@ void UiImageComponent::OnSpriteRenderTargetNameChange() if (!m_renderTargetName.empty()) { - newSprite = gEnv->pLyShine->CreateSprite(m_renderTargetName.c_str()); + newSprite = AZ::Interface::Get()->CreateSprite(m_renderTargetName.c_str()); } SAFE_RELEASE(m_sprite); diff --git a/Gems/LyShine/Code/Source/UiImageSequenceComponent.cpp b/Gems/LyShine/Code/Source/UiImageSequenceComponent.cpp index 3559dc6306..3981777f2d 100644 --- a/Gems/LyShine/Code/Source/UiImageSequenceComponent.cpp +++ b/Gems/LyShine/Code/Source/UiImageSequenceComponent.cpp @@ -52,7 +52,7 @@ namespace spriteList.reserve(imageList.size()); for (auto& textureAssetRef : imageList) { - ISprite* sprite = gEnv->pLyShine->LoadSprite(textureAssetRef.GetAssetPath().c_str()); + ISprite* sprite = AZ::Interface::Get()->LoadSprite(textureAssetRef.GetAssetPath().c_str()); if (sprite) { spriteList.push_back(sprite); @@ -383,7 +383,7 @@ void UiImageSequenceComponent::Init() // If this is called from RC.exe for example these pointers will not be set. In that case // we only need to be able to load, init and save the component. It will never be // activated. - if (!(gEnv && gEnv->pLyShine)) + if (!AZ::Interface::Get()) { return; } diff --git a/Gems/LyShine/Code/Source/UiInteractableState.cpp b/Gems/LyShine/Code/Source/UiInteractableState.cpp index d2c09201c6..18bacb3a9f 100644 --- a/Gems/LyShine/Code/Source/UiInteractableState.cpp +++ b/Gems/LyShine/Code/Source/UiInteractableState.cpp @@ -274,7 +274,7 @@ UiInteractableStateSprite::UiInteractableStateSprite(AZ::EntityId target, const if (!m_spritePathname.GetAssetPath().empty()) { - m_sprite = gEnv->pLyShine->LoadSprite(m_spritePathname.GetAssetPath().c_str()); + m_sprite = AZ::Interface::Get()->LoadSprite(m_spritePathname.GetAssetPath().c_str()); } } @@ -297,7 +297,7 @@ void UiInteractableStateSprite::Init(AZ::EntityId interactableEntityId) // If this is called from RC.exe for example these pointers will not be set. In that case // we only need to be able to load, init and save the component. It will never be // activated. - if (!(gEnv && gEnv->pLyShine)) + if (!AZ::Interface::Get()) { return; } @@ -306,7 +306,7 @@ void UiInteractableStateSprite::Init(AZ::EntityId interactableEntityId) // are not loaded then load them if (!m_sprite && !m_spritePathname.GetAssetPath().empty()) { - m_sprite = gEnv->pLyShine->LoadSprite(m_spritePathname.GetAssetPath().c_str()); + m_sprite = AZ::Interface::Get()->LoadSprite(m_spritePathname.GetAssetPath().c_str()); } if (!m_sprite) @@ -366,7 +366,7 @@ void UiInteractableStateSprite::OnSpritePathnameChange() if (!m_spritePathname.GetAssetPath().empty()) { // Load the new texture. - newSprite = gEnv->pLyShine->LoadSprite(m_spritePathname.GetAssetPath().c_str()); + newSprite = AZ::Interface::Get()->LoadSprite(m_spritePathname.GetAssetPath().c_str()); } SAFE_RELEASE(m_sprite); diff --git a/Gems/LyShine/Code/Source/UiParticleEmitterComponent.cpp b/Gems/LyShine/Code/Source/UiParticleEmitterComponent.cpp index b999480940..b9f986c14a 100644 --- a/Gems/LyShine/Code/Source/UiParticleEmitterComponent.cpp +++ b/Gems/LyShine/Code/Source/UiParticleEmitterComponent.cpp @@ -1429,14 +1429,14 @@ void UiParticleEmitterComponent::Init() // If this is called from RC.exe for example these pointers will not be set. In that case // we only need to be able to load, init and save the component. It will never be // activated. - if (!(gEnv && gEnv->pLyShine)) + if (!AZ::Interface::Get()) { return; } if (!m_sprite && !m_spritePathname.GetAssetPath().empty()) { - m_sprite = gEnv->pLyShine->LoadSprite(m_spritePathname.GetAssetPath().c_str()); + m_sprite = AZ::Interface::Get()->LoadSprite(m_spritePathname.GetAssetPath().c_str()); } m_currentAspectRatio = m_particleSize.GetX() / m_particleSize.GetY(); @@ -1927,7 +1927,7 @@ void UiParticleEmitterComponent::OnSpritePathnameChange() if (!m_spritePathname.GetAssetPath().empty()) { // Load the new texture. - newSprite = gEnv->pLyShine->LoadSprite(m_spritePathname.GetAssetPath().c_str()); + newSprite = AZ::Interface::Get()->LoadSprite(m_spritePathname.GetAssetPath().c_str()); } SAFE_RELEASE(m_sprite); diff --git a/Gems/LyShine/Code/Source/World/UiCanvasAssetRefComponent.cpp b/Gems/LyShine/Code/Source/World/UiCanvasAssetRefComponent.cpp index 933cca424a..e186e1158d 100644 --- a/Gems/LyShine/Code/Source/World/UiCanvasAssetRefComponent.cpp +++ b/Gems/LyShine/Code/Source/World/UiCanvasAssetRefComponent.cpp @@ -8,6 +8,7 @@ #include "UiCanvasAssetRefComponent.h" #include #include +#include #include #include #include @@ -106,11 +107,11 @@ AZ::EntityId UiCanvasAssetRefComponent::LoadCanvas() // Check if we already have a referenced UI canvas, if so release it if (m_canvasEntityId.IsValid()) { - gEnv->pLyShine->ReleaseCanvasDeferred(m_canvasEntityId); + AZ::Interface::Get()->ReleaseCanvasDeferred(m_canvasEntityId); m_canvasEntityId.SetInvalid(); } - m_canvasEntityId = gEnv->pLyShine->LoadCanvas(canvasPath.c_str()); + m_canvasEntityId = AZ::Interface::Get()->LoadCanvas(canvasPath.c_str()); EBUS_EVENT_ID(GetEntityId(), UiCanvasAssetRefNotificationBus, OnCanvasLoadedIntoEntity, m_canvasEntityId); EBUS_EVENT_ID(GetEntityId(), UiCanvasRefNotificationBus, OnCanvasRefChanged, GetEntityId(), m_canvasEntityId); @@ -124,7 +125,7 @@ void UiCanvasAssetRefComponent::UnloadCanvas() { if (m_canvasEntityId.IsValid()) { - gEnv->pLyShine->ReleaseCanvasDeferred(m_canvasEntityId); + AZ::Interface::Get()->ReleaseCanvasDeferred(m_canvasEntityId); m_canvasEntityId.SetInvalid(); EBUS_EVENT_ID(GetEntityId(), UiCanvasRefNotificationBus, OnCanvasRefChanged, GetEntityId(), m_canvasEntityId); @@ -243,7 +244,7 @@ void UiCanvasAssetRefComponent::Deactivate() { if (m_canvasEntityId.IsValid()) { - gEnv->pLyShine->ReleaseCanvasDeferred(m_canvasEntityId); + AZ::Interface::Get()->ReleaseCanvasDeferred(m_canvasEntityId); m_canvasEntityId.SetInvalid(); } diff --git a/Gems/LyShine/Code/Tests/UiTooltipComponentTest.cpp b/Gems/LyShine/Code/Tests/UiTooltipComponentTest.cpp index 8a3d9f2af6..652cec3c0f 100644 --- a/Gems/LyShine/Code/Tests/UiTooltipComponentTest.cpp +++ b/Gems/LyShine/Code/Tests/UiTooltipComponentTest.cpp @@ -144,7 +144,6 @@ namespace UnitTest SSystemGlobalEnvironment env; SSystemGlobalEnvironment* prevEnv = gEnv; gEnv = &env; - gEnv->pLyShine = nullptr; auto [uiCanvasComponent, uiTooltipDisplayComponent, uiTooltipComponent] = CreateUiCanvasWithTooltip(); uiTooltipDisplayComponent->SetTriggerMode(UiTooltipDisplayInterface::TriggerMode::OnHover); @@ -170,7 +169,6 @@ namespace UnitTest SSystemGlobalEnvironment env; SSystemGlobalEnvironment* prevEnv = gEnv; gEnv = &env; - gEnv->pLyShine = nullptr; auto [uiCanvasComponent, uiTooltipDisplayComponent, uiTooltipComponent] = CreateUiCanvasWithTooltip(); uiTooltipDisplayComponent->SetTriggerMode(UiTooltipDisplayInterface::TriggerMode::OnHover); @@ -194,7 +192,6 @@ namespace UnitTest SSystemGlobalEnvironment env; SSystemGlobalEnvironment* prevEnv = gEnv; gEnv = &env; - gEnv->pLyShine = nullptr; auto [uiCanvasComponent, uiTooltipDisplayComponent, uiTooltipComponent] = CreateUiCanvasWithTooltip(); uiTooltipDisplayComponent->SetTriggerMode(UiTooltipDisplayInterface::TriggerMode::OnPress); @@ -218,7 +215,6 @@ namespace UnitTest SSystemGlobalEnvironment env; SSystemGlobalEnvironment* prevEnv = gEnv; gEnv = &env; - gEnv->pLyShine = nullptr; auto [uiCanvasComponent, uiTooltipDisplayComponent, uiTooltipComponent] = CreateUiCanvasWithTooltip(); uiTooltipDisplayComponent->SetTriggerMode(UiTooltipDisplayInterface::TriggerMode::OnPress); @@ -242,7 +238,6 @@ namespace UnitTest SSystemGlobalEnvironment env; SSystemGlobalEnvironment* prevEnv = gEnv; gEnv = &env; - gEnv->pLyShine = nullptr; auto [uiCanvasComponent, uiTooltipDisplayComponent, uiTooltipComponent] = CreateUiCanvasWithTooltip(); uiTooltipDisplayComponent->SetTriggerMode(UiTooltipDisplayInterface::TriggerMode::OnClick); diff --git a/Gems/LyShineExamples/Code/Source/LyShineExamplesCppExample.cpp b/Gems/LyShineExamples/Code/Source/LyShineExamplesCppExample.cpp index f2da79fa99..7619764fbc 100644 --- a/Gems/LyShineExamples/Code/Source/LyShineExamplesCppExample.cpp +++ b/Gems/LyShineExamples/Code/Source/LyShineExamplesCppExample.cpp @@ -47,7 +47,7 @@ namespace LyShineExamples // Remove the existing example canvas if it exists DestroyCanvas(); - AZ::EntityId canvasEntityId = gEnv->pLyShine->CreateCanvas(); + AZ::EntityId canvasEntityId = AZ::Interface::Get()->CreateCanvas(); if (!canvasEntityId.IsValid()) { return; @@ -90,7 +90,7 @@ namespace LyShineExamples m_healthBar.SetInvalid(); - gEnv->pLyShine->ReleaseCanvas(m_canvasId, false); + AZ::Interface::Get()->ReleaseCanvas(m_canvasId, false); m_canvasId.SetInvalid(); } } diff --git a/Gems/LyShineExamples/Code/Source/UiCustomImageComponent.cpp b/Gems/LyShineExamples/Code/Source/UiCustomImageComponent.cpp index e8b0e4370a..c228176b4f 100644 --- a/Gems/LyShineExamples/Code/Source/UiCustomImageComponent.cpp +++ b/Gems/LyShineExamples/Code/Source/UiCustomImageComponent.cpp @@ -284,7 +284,7 @@ namespace LyShineExamples // If this is called from RC.exe for example these pointers will not be set. In that case // we only need to be able to load, init and save the component. It will never be // activated. - if (!(gEnv && gEnv->pLyShine)) + if (!AZ::Interface::Get()) { return; } @@ -294,7 +294,7 @@ namespace LyShineExamples { if (!m_spritePathname.GetAssetPath().empty()) { - m_sprite = gEnv->pLyShine->LoadSprite(m_spritePathname.GetAssetPath().c_str()); + m_sprite = AZ::Interface::Get()->LoadSprite(m_spritePathname.GetAssetPath().c_str()); } } @@ -399,7 +399,7 @@ namespace LyShineExamples if (!m_spritePathname.GetAssetPath().empty()) { // Load the new texture. - newSprite = gEnv->pLyShine->LoadSprite(m_spritePathname.GetAssetPath().c_str()); + newSprite = AZ::Interface::Get()->LoadSprite(m_spritePathname.GetAssetPath().c_str()); } SAFE_RELEASE(m_sprite); diff --git a/Gems/MessagePopup/Code/Source/LyShineMessagePopup.cpp b/Gems/MessagePopup/Code/Source/LyShineMessagePopup.cpp index 40fed3448b..de54bef4eb 100644 --- a/Gems/MessagePopup/Code/Source/LyShineMessagePopup.cpp +++ b/Gems/MessagePopup/Code/Source/LyShineMessagePopup.cpp @@ -127,21 +127,21 @@ namespace MessagePopup switch (_buttons) { case EPopupButtons::EPopupButtons_NoButtons: - canvasEntityId = gEnv->pLyShine->LoadCanvas("@products@/ui/canvases/defaultmessagepopup.uicanvas"); + canvasEntityId = AZ::Interface::Get()->LoadCanvas("@products@/ui/canvases/defaultmessagepopup.uicanvas"); break; case EPopupButtons::EPopupButtons_Confirm: - canvasEntityId = gEnv->pLyShine->LoadCanvas("@products@/ui/canvases/defaultmessagepopup_confirm.uicanvas"); + canvasEntityId = AZ::Interface::Get()->LoadCanvas("@products@/ui/canvases/defaultmessagepopup_confirm.uicanvas"); isNavigationSupported = true; break; case EPopupButtons::EPopupButtons_YesNo: - canvasEntityId = gEnv->pLyShine->LoadCanvas("@products@/ui/canvases/defaultmessagepopup_yesno.uicanvas"); + canvasEntityId = AZ::Interface::Get()->LoadCanvas("@products@/ui/canvases/defaultmessagepopup_yesno.uicanvas"); isNavigationSupported = true; break; } } else if (_kind == EPopupKind_Toaster) { - canvasEntityId = gEnv->pLyShine->LoadCanvas("@products@/ui/canvases/toaster.uicanvas"); + canvasEntityId = AZ::Interface::Get()->LoadCanvas("@products@/ui/canvases/toaster.uicanvas"); } if (canvasEntityId.IsValid()) @@ -183,7 +183,7 @@ namespace MessagePopup { // get the canvas ID in the clientdata LyShine::CanvasId canvasId = *((LyShine::CanvasId*)&_popupInfo.m_clientData); - AZ::EntityId canvasEntityId = gEnv->pLyShine->FindCanvasById(canvasId); + AZ::EntityId canvasEntityId = AZ::Interface::Get()->FindCanvasById(canvasId); if (canvasEntityId.IsValid()) { // Hide the cursor if it was shown in LyShineMessagePopup::OnShowPopup @@ -197,7 +197,7 @@ namespace MessagePopup // Disable the popup EBUS_EVENT_ID(canvasEntityId, UiCanvasBus, SetEnabled, false); - gEnv->pLyShine->ReleaseCanvas(canvasEntityId, false); + AZ::Interface::Get()->ReleaseCanvas(canvasEntityId, false); UiCanvasNotificationBus::MultiHandler::BusDisconnect(canvasEntityId); m_activePopupIdsByCanvasId.erase(canvasEntityId);