/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include // Forward declarations class ISprite; //////////////////////////////////////////////////////////////////////////////////////////////////// // Base class for all interactable state actions // Interactable state actions are properties that are set while in that interactable state // (e.g. color override) or things that happen when entering that state (e.g. playing an animation) class UiInteractableStateAction { public: // member functions AZ_CLASS_ALLOCATOR(UiInteractableStateAction, AZ::SystemAllocator, 0); AZ_RTTI(UiInteractableStateAction, "{D86C82E1-E027-453F-A43B-BD801CF88391}"); virtual ~UiInteractableStateAction() {} //! Called from the Init of the UiInteractableComponent virtual void Init(AZ::EntityId); //! Apply state or do action virtual void ApplyState() = 0; virtual void SetInteractableEntity(AZ::EntityId interactableEntityId); virtual AZ::EntityId GetTargetEntity() { return AZ::EntityId(); } using EntityComboBoxVec = AZStd::vector< AZStd::pair< AZ::EntityId, AZStd::string > >; EntityComboBoxVec PopulateTargetEntityList(); protected: // data //! The interactable entity that this state belongs to. AZ::EntityId m_interactableEntity; }; //////////////////////////////////////////////////////////////////////////////////////////////////// class UiInteractableStateColor : public UiInteractableStateAction { public: // member functions AZ_CLASS_ALLOCATOR(UiInteractableStateColor, AZ::SystemAllocator, 0); AZ_RTTI(UiInteractableStateColor, "{D7978A94-592F-4E1A-86EF-E34A819A55FB}", UiInteractableStateAction); UiInteractableStateColor(); UiInteractableStateColor(AZ::EntityId target, AZ::Color color); // UiInteractableStateAction void Init(AZ::EntityId) override; void ApplyState() override; void SetInteractableEntity(AZ::EntityId interactableEntityId) override; AZ::EntityId GetTargetEntity() override { return m_targetEntity; } // ~UiInteractableStateAction AZ::Color GetColor() { return m_color; } void SetColor(AZ::Color color) { m_color = color; } EntityComboBoxVec PopulateTargetEntityList(); public: // static member functions static void Reflect(AZ::ReflectContext* context); private: // static member functions static bool VersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement); protected: // data AZ::EntityId m_targetEntity; AZ::Color m_color; }; //////////////////////////////////////////////////////////////////////////////////////////////////// class UiInteractableStateAlpha : public UiInteractableStateAction { public: // member functions AZ_CLASS_ALLOCATOR(UiInteractableStateAlpha, AZ::SystemAllocator, 0); AZ_RTTI(UiInteractableStateAlpha, "{ABCD5D45-CC47-4C17-8D21-9471032618F6}", UiInteractableStateAction); UiInteractableStateAlpha(); UiInteractableStateAlpha(AZ::EntityId target, float alpha); // UiInteractableStateAction void Init(AZ::EntityId) override; void ApplyState() override; void SetInteractableEntity(AZ::EntityId interactableEntityId) override; AZ::EntityId GetTargetEntity() override { return m_targetEntity; } // ~UiInteractableStateAction float GetAlpha() { return m_alpha; } void SetAlpha(float alpha) { m_alpha = alpha; } EntityComboBoxVec PopulateTargetEntityList(); public: // static member functions static void Reflect(AZ::ReflectContext* context); protected: // data AZ::EntityId m_targetEntity; float m_alpha; }; //////////////////////////////////////////////////////////////////////////////////////////////////// class UiInteractableStateSprite : public UiInteractableStateAction { public: // member functions AZ_CLASS_ALLOCATOR(UiInteractableStateSprite, AZ::SystemAllocator, 0); AZ_RTTI(UiInteractableStateSprite, "{89294558-CF45-4AA8-9EAA-A1D81BAB92A7}", UiInteractableStateAction); UiInteractableStateSprite(); UiInteractableStateSprite(AZ::EntityId target, ISprite* sprite); UiInteractableStateSprite(AZ::EntityId target, const AZStd::string& spritePath); ~UiInteractableStateSprite() override; // UiInteractableStateAction void Init(AZ::EntityId) override; void ApplyState() override; void SetInteractableEntity(AZ::EntityId interactableEntityId) override; AZ::EntityId GetTargetEntity() override { return m_targetEntity; } // ~UiInteractableStateAction ISprite* GetSprite() { return m_sprite; } void SetSprite(ISprite* sprite); AZStd::string GetSpritePathname(); void SetSpritePathname(const AZStd::string& spritePath); EntityComboBoxVec PopulateTargetEntityList(); void OnSpritePathnameChange(); public: // static member functions static void Reflect(AZ::ReflectContext* context); protected: // member functions bool IsSpriteSheet(); void OnTargetElementChange(); void LoadSpriteFromTargetElement(); using AZu32ComboBoxVec = AZStd::vector >; //! Returns a string representation of the indices used to index sprite-sheet types. AZu32ComboBoxVec PopulateIndexStringList() const; protected: // data AZ::EntityId m_targetEntity; AzFramework::SimpleAssetReference m_spritePathname; ISprite* m_sprite = nullptr; AZ::u32 m_spriteSheetCellIndex = 0; }; //////////////////////////////////////////////////////////////////////////////////////////////////// class UiInteractableStateFont : public UiInteractableStateAction , public FontNotificationBus::Handler { public: // types using FontEffectComboBoxVec = AZStd::vector < AZStd::pair >; public: // member functions AZ_CLASS_ALLOCATOR(UiInteractableStateFont, AZ::SystemAllocator, 0); AZ_RTTI(UiInteractableStateFont, "{0E39A3BC-CEF5-4385-9D06-BFEE189E77E1}", UiInteractableStateAction); UiInteractableStateFont(); UiInteractableStateFont(AZ::EntityId target, const AZStd::string& pathname, unsigned int fontEffectIndex); ~UiInteractableStateFont() override; // UiInteractableStateAction void Init(AZ::EntityId) override; void ApplyState() override; void SetInteractableEntity(AZ::EntityId interactableEntityId) override; AZ::EntityId GetTargetEntity() override { return m_targetEntity; } // ~UiInteractableStateAction // FontNotifications void OnFontsReloaded() override; // ~FontNotifications const AZStd::string& GetFontPathname() { return m_fontFilename.GetAssetPath(); } void SetFontPathname(const AZStd::string& pathname); const unsigned int GetFontEffectIndex() { return m_fontEffectIndex; } void SetFontEffectIndex(unsigned int index) { m_fontEffectIndex = index; } EntityComboBoxVec PopulateTargetEntityList(); //! Populate the list for the font effect combo box in the properties pane FontEffectComboBoxVec PopulateFontEffectList(); void OnFontPathnameChange(); public: // static member functions static void Reflect(AZ::ReflectContext* context); protected: // member functions void InitCommon(const AZStd::string& fontPathname); protected: // data AZ::EntityId m_targetEntity; AzFramework::SimpleAssetReference m_fontFilename; FontFamilyPtr m_fontFamily; unsigned int m_fontEffectIndex; };