1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
395 lines
13 KiB
C++
395 lines
13 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include "UiStateActionManager.h"
|
|
|
|
#include <LyShine/Bus/UiVisualBus.h>
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
UiStateActionManager::UiStateActionManager()
|
|
{
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
UiStateActionManager::~UiStateActionManager()
|
|
{
|
|
ClearStates();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::SetStateColor(int state, AZ::EntityId target, const AZ::Color& color)
|
|
{
|
|
UiInteractableStateColor* stateColor = GetStateAction<UiInteractableStateColor>(state, target);
|
|
if (stateColor)
|
|
{
|
|
stateColor->SetColor(color);
|
|
}
|
|
else
|
|
{
|
|
StateActions* stateActions = GetStateActions(state);
|
|
if (stateActions)
|
|
{
|
|
stateActions->push_back(new UiInteractableStateColor(target, color));
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
AZ::Color UiStateActionManager::GetStateColor(int state, AZ::EntityId target)
|
|
{
|
|
AZ::Color color(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
UiInteractableStateColor* stateColor = GetStateAction<UiInteractableStateColor>(state, target);
|
|
if (stateColor)
|
|
{
|
|
color = stateColor->GetColor();
|
|
}
|
|
else
|
|
{
|
|
CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING,
|
|
"GetStateColor: Couldn't find color action for state/target combination");
|
|
}
|
|
|
|
return color;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
bool UiStateActionManager::HasStateColor(int state, AZ::EntityId target)
|
|
{
|
|
UiInteractableStateColor* stateColor = GetStateAction<UiInteractableStateColor>(state, target);
|
|
return stateColor ? true : false;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::SetStateAlpha(int state, AZ::EntityId target, float alpha)
|
|
{
|
|
UiInteractableStateAlpha* stateAlpha = GetStateAction<UiInteractableStateAlpha>(state, target);
|
|
if (stateAlpha)
|
|
{
|
|
stateAlpha->SetAlpha(alpha);
|
|
}
|
|
else
|
|
{
|
|
StateActions* stateActions = GetStateActions(state);
|
|
if (stateActions)
|
|
{
|
|
stateActions->push_back(new UiInteractableStateAlpha(target, alpha));
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
float UiStateActionManager::GetStateAlpha(int state, AZ::EntityId target)
|
|
{
|
|
float alpha = 1.0f;
|
|
|
|
UiInteractableStateAlpha* stateAlpha = GetStateAction<UiInteractableStateAlpha>(state, target);
|
|
if (stateAlpha)
|
|
{
|
|
alpha = stateAlpha->GetAlpha();
|
|
}
|
|
else
|
|
{
|
|
CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING,
|
|
"GetStateAlpha: Couldn't find alpha action for state/target combination");
|
|
}
|
|
|
|
return alpha;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
bool UiStateActionManager::HasStateAlpha(int state, AZ::EntityId target)
|
|
{
|
|
UiInteractableStateAlpha* stateAlpha = GetStateAction<UiInteractableStateAlpha>(state, target);
|
|
return stateAlpha ? true : false;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::SetStateSprite(int state, AZ::EntityId target, ISprite* sprite)
|
|
{
|
|
UiInteractableStateSprite* stateSprite = GetStateAction<UiInteractableStateSprite>(state, target);
|
|
if (stateSprite)
|
|
{
|
|
stateSprite->SetSprite(sprite);
|
|
}
|
|
else
|
|
{
|
|
StateActions* stateActions = GetStateActions(state);
|
|
if (stateActions)
|
|
{
|
|
stateActions->push_back(new UiInteractableStateSprite(target, sprite));
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
ISprite* UiStateActionManager::GetStateSprite(int state, AZ::EntityId target)
|
|
{
|
|
ISprite* sprite = nullptr;
|
|
|
|
UiInteractableStateSprite* stateSprite = GetStateAction<UiInteractableStateSprite>(state, target);
|
|
if (stateSprite)
|
|
{
|
|
sprite = stateSprite->GetSprite();
|
|
}
|
|
else
|
|
{
|
|
CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING,
|
|
"GetStateSprite: Couldn't find sprite action for state/target combination");
|
|
}
|
|
|
|
return sprite;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::SetStateSpritePathname(int state, AZ::EntityId target, const AZStd::string& spritePath)
|
|
{
|
|
UiInteractableStateSprite* stateSprite = GetStateAction<UiInteractableStateSprite>(state, target);
|
|
if (stateSprite)
|
|
{
|
|
stateSprite->SetSpritePathname(spritePath);
|
|
}
|
|
else
|
|
{
|
|
StateActions* stateActions = GetStateActions(state);
|
|
if (stateActions)
|
|
{
|
|
stateActions->push_back(new UiInteractableStateSprite(target, spritePath));
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
AZStd::string UiStateActionManager::GetStateSpritePathname(int state, AZ::EntityId target)
|
|
{
|
|
AZStd::string spritePath;
|
|
|
|
UiInteractableStateSprite* stateSprite = GetStateAction<UiInteractableStateSprite>(state, target);
|
|
if (stateSprite)
|
|
{
|
|
spritePath = stateSprite->GetSpritePathname();
|
|
}
|
|
else
|
|
{
|
|
CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING,
|
|
"GetStateSpritePathname: Couldn't find sprite action for state/target combination");
|
|
}
|
|
|
|
return spritePath;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
bool UiStateActionManager::HasStateSprite(int state, AZ::EntityId target)
|
|
{
|
|
UiInteractableStateSprite* stateSprite = GetStateAction<UiInteractableStateSprite>(state, target);
|
|
return stateSprite ? true : false;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::SetStateFont(
|
|
int state,
|
|
AZ::EntityId target,
|
|
const AZStd::string& fontPathname,
|
|
unsigned int fontEffectIndex)
|
|
{
|
|
UiInteractableStateFont* stateFont = GetStateAction<UiInteractableStateFont>(state, target);
|
|
if (stateFont)
|
|
{
|
|
stateFont->SetFontPathname(fontPathname);
|
|
stateFont->SetFontEffectIndex(fontEffectIndex);
|
|
}
|
|
else
|
|
{
|
|
StateActions* stateActions = GetStateActions(state);
|
|
if (stateActions)
|
|
{
|
|
stateActions->push_back(new UiInteractableStateFont(target, fontPathname, fontEffectIndex));
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
AZStd::string UiStateActionManager::GetStateFontPathname(int state, AZ::EntityId target)
|
|
{
|
|
AZStd::string fontPath;
|
|
|
|
UiInteractableStateFont* stateFont = GetStateAction<UiInteractableStateFont>(state, target);
|
|
if (stateFont)
|
|
{
|
|
fontPath = stateFont->GetFontPathname();
|
|
}
|
|
else
|
|
{
|
|
CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING,
|
|
"GetStateFontPathname: Couldn't find font action for state/target combination");
|
|
}
|
|
|
|
return fontPath;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
unsigned int UiStateActionManager::GetStateFontEffectIndex(int state, AZ::EntityId target)
|
|
{
|
|
unsigned int fontEffectIndex = 0;
|
|
|
|
UiInteractableStateFont* stateFont = GetStateAction<UiInteractableStateFont>(state, target);
|
|
if (stateFont)
|
|
{
|
|
fontEffectIndex = stateFont->GetFontEffectIndex();
|
|
}
|
|
else
|
|
{
|
|
CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING,
|
|
"GetStateFontEffectIndex: Couldn't find font action for state/target combination");
|
|
}
|
|
|
|
return fontEffectIndex;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
bool UiStateActionManager::HasStateFont(int state, AZ::EntityId target)
|
|
{
|
|
UiInteractableStateFont* stateFont = GetStateAction<UiInteractableStateFont>(state, target);
|
|
return stateFont ? true : false;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::Init(AZ::EntityId entityId)
|
|
{
|
|
m_entityId = entityId;
|
|
InitStateActions();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::Activate()
|
|
{
|
|
UiInteractableStatesBus::Handler::BusConnect(m_entityId);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::Deactivate()
|
|
{
|
|
UiInteractableStatesBus::Handler::BusDisconnect();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::AddState(StateActions* stateActions)
|
|
{
|
|
m_states.push_back(stateActions);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::ResetAllOverrides()
|
|
{
|
|
AZStd::vector<AZ::EntityId> entityIdList = GetTargetEntitiesInAllStates();
|
|
for (auto targetEntityId : entityIdList)
|
|
{
|
|
EBUS_EVENT_ID(targetEntityId, UiVisualBus, ResetOverrides);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::ApplyStateActions(int state)
|
|
{
|
|
// Get the actions for the state (if any) and apply them
|
|
StateActions* stateActions = m_states[state];
|
|
if (stateActions)
|
|
{
|
|
for (UiInteractableStateAction* stateAction : (*stateActions))
|
|
{
|
|
stateAction->ApplyState();
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::InitInteractableEntityForStateActions(StateActions& stateActions)
|
|
{
|
|
for (auto stateAction : stateActions)
|
|
{
|
|
stateAction->SetInteractableEntity(m_entityId);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::ClearStates()
|
|
{
|
|
for (StateActions* stateActions : m_states)
|
|
{
|
|
if (stateActions)
|
|
{
|
|
for (UiInteractableStateAction* stateAction : * stateActions)
|
|
{
|
|
delete stateAction;
|
|
}
|
|
}
|
|
}
|
|
|
|
m_states.clear();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// PUBLIC STATIC MEMBER FUNCTIONS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// PROTECTED MEMBER FUNCTIONS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiStateActionManager::InitStateActions()
|
|
{
|
|
for (StateActions* stateActions : m_states)
|
|
{
|
|
if (stateActions)
|
|
{
|
|
for (UiInteractableStateAction* stateAction : * stateActions)
|
|
{
|
|
stateAction->Init(m_entityId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
AZStd::vector<AZ::EntityId> UiStateActionManager::GetTargetEntitiesInAllStates()
|
|
{
|
|
AZStd::vector<AZ::EntityId> result;
|
|
|
|
for (StateActions* stateActions : m_states)
|
|
{
|
|
if (stateActions)
|
|
{
|
|
for (auto stateAction : (*stateActions))
|
|
{
|
|
AZ::EntityId targetEntity = stateAction->GetTargetEntity();
|
|
|
|
// if this state action has a target entity and it is not already in the list then add it
|
|
if (targetEntity.IsValid() && AZStd::find(result.begin(), result.end(), targetEntity) == result.end())
|
|
{
|
|
result.push_back(targetEntity);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
UiStateActionManager::StateActions* UiStateActionManager::GetStateActions(int state)
|
|
{
|
|
if (state >= 0 && state < m_states.size())
|
|
{
|
|
return m_states[state];
|
|
}
|
|
|
|
return nullptr;
|
|
}
|