소스 검색

Merge pull request #245 from aws-lumberyard-dev/MergeGameJamIntoStab

Merge GameJam into Stabilization
mcphedar 2 년 전
부모
커밋
955cc0e94e

+ 6 - 0
Gem/Code/Source/Components/NetworkMatchComponent.cpp

@@ -25,6 +25,7 @@
 #include "Multiplayer/GemSpawnerComponent.h"
 #include <Multiplayer/Components/ISimplePlayerSpawner.h>
 
+
 #if AZ_TRAIT_CLIENT
 #   include <AzFramework/Input/Buses/Requests/InputSystemCursorRequestBus.h>
 #   include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
@@ -145,6 +146,11 @@ namespace MultiplayerSample
         RoundNumberAddEvent(handler);
     }
 
+    void NetworkMatchComponent::AddRoundTimeRemainingEventHandler(AZ::Event<RoundTimeSec>::Handler& handler)
+    {
+        RoundTimeAddEvent(handler);
+    }
+
     void NetworkMatchComponent::AddRoundRestTimeRemainingEventHandler(AZ::Event<RoundTimeSec>::Handler& handler)
     {
         RoundRestTimeRemainingAddEvent(handler);

+ 5 - 0
Gem/Code/Source/Components/NetworkMatchComponent.h

@@ -52,6 +52,10 @@ namespace MultiplayerSample
         //! @param handler the handler to add the the requested component event
         virtual void AddRoundNumberEventHandler(AZ::Event<uint16_t>::Handler& handler) = 0;
 
+        //! Adds an event handler to the round time remaining AZ::Event
+        //! @param handler the handler to add the the requested component event
+        virtual void AddRoundTimeRemainingEventHandler(AZ::Event<RoundTimeSec>::Handler& handler) = 0;
+
         //! Adds an event handler to the round number rest remaining AZ::Event
         //! @param handler the handler to add the the requested component event
         virtual void AddRoundRestTimeRemainingEventHandler(AZ::Event<RoundTimeSec>::Handler& handler) = 0;
@@ -90,6 +94,7 @@ namespace MultiplayerSample
         int32_t GetTotalRoundCount() const override;
         int32_t GetTotalPlayerCount() const override;
         void AddRoundNumberEventHandler(AZ::Event<uint16_t>::Handler& handler) override;
+        void AddRoundTimeRemainingEventHandler(AZ::Event<RoundTimeSec>::Handler& handler) override;
         void AddRoundRestTimeRemainingEventHandler(AZ::Event<RoundTimeSec>::Handler& handler) override;
         //! @}
 

+ 38 - 66
Gem/Code/Source/Components/UI/HUDComponent.cpp

@@ -7,44 +7,24 @@
  */
 
 #include <Source/Components/UI/HUDComponent.h>
-#include <Source/Components/NetworkMatchComponent.h>
 
 #include <AzCore/Serialization/SerializeContext.h>
 #include <AzCore/Serialization/EditContext.h>
 
-#if AZ_TRAIT_CLIENT
-#include <LyShine/Bus/UiCanvasBus.h>
+#include <LyShine/Bus/UiElementBus.h>
 #include <LyShine/Bus/UiTextBus.h>
-#endif
+
 
 namespace MultiplayerSample
 {
     void HUDComponent::Activate()
     {
-#if AZ_TRAIT_CLIENT
-        UiCanvasRefBus::EventResult(m_uiCanvasId, GetEntityId(), &UiCanvasRefBus::Events::GetCanvas);
-        if (!m_uiCanvasId.IsValid())
-        {
-            UiCanvasAssetRefNotificationBus::Handler::BusConnect(GetEntityId());
-        }
-
-        if (NetworkMatchComponent* netMatchComponent = GetEntity()->FindComponent<NetworkMatchComponent>())
-        {
-            SetRoundNumberText(netMatchComponent->GetRoundNumber());
-            m_roundNumberHandler = AZ::EventHandler<uint16_t>([this](uint16_t value) { SetRoundNumberText(value); });
-            netMatchComponent->RoundNumberAddEvent(m_roundNumberHandler);
-
-            m_roundTimerHandler = AZ::EventHandler<RoundTimeSec>([this](RoundTimeSec value) { SetRoundTimerText(value); });
-            netMatchComponent->RoundTimeAddEvent(m_roundTimerHandler);
-        }
-#endif
+        m_waitForActiveNetworkMatchComponent.Enqueue(AZ::TimeMs{ 1000 }, true);
     }
 
     void HUDComponent::Deactivate()
     {
-#if AZ_TRAIT_CLIENT
-        UiCanvasAssetRefNotificationBus::Handler::BusDisconnect(GetEntityId());
-#endif
+        m_waitForActiveNetworkMatchComponent.RemoveFromQueue();
     }
 
     void HUDComponent::Reflect(AZ::ReflectContext* context)
@@ -54,9 +34,10 @@ namespace MultiplayerSample
             serializeContext->Class<HUDComponent, AZ::Component>()
                 ->Version(1)
                 ->Field("RoundNumberText", &HUDComponent::m_roundNumberText)
-                ->Field("RoundNumberId", &HUDComponent::m_roundNumberId)
+                ->Field("RoundNumberId", &HUDComponent::m_roundNumberUi)
                 ->Field("RoundTimerText", &HUDComponent::m_roundTimerText)
-                ->Field("RoundTimerId", &HUDComponent::m_roundTimerId)
+                ->Field("RoundTimerId", &HUDComponent::m_roundTimerUi)
+                ->Field("RoundSecondsRemaining", &HUDComponent::m_roundSecondsRemainingUiParent)
                 ;
 
             if (AZ::EditContext* editContext = serializeContext->GetEditContext())
@@ -65,63 +46,54 @@ namespace MultiplayerSample
                     ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
                     ->Attribute(AZ::Edit::Attributes::Category, "Multiplayer Sample UI")
                     ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg")
-                    ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
+                    ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("CanvasUI"))
 
-                    ->DataElement(AZ::Edit::UIHandlers::Default, &HUDComponent::m_roundNumberId, "Round Number UIElement Id", "The element id of the textbox you want to change. (Find the id inside the ui canvas)")
-                    ->DataElement(AZ::Edit::UIHandlers::Default, &HUDComponent::m_roundTimerId, "Round Time UIElement Id", "The element id of the textbox you want to change. (Find the id inside the ui canvas)")
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &HUDComponent::m_roundNumberUi, "Round Number Textbox", "The ui textbox for displaying the current round number.")
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &HUDComponent::m_roundTimerUi, "Round Time Textbox", "The ui textbox for displaying the time remaining in the round.")
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &HUDComponent::m_roundSecondsRemainingUiParent, "Round Seconds Remaining UI Elements", "The parent ui element containing all the ui images to display the seconds remaining.")
                     ;
             }
         }
     }
-    
-    void HUDComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
-    {
-        required.push_back(AZ_CRC("UiCanvasRefService"));
-        required.push_back(AZ_CRC("NetworkMatchComponent"));
-    }
-
-#if AZ_TRAIT_CLIENT
-    void HUDComponent::OnCanvasLoadedIntoEntity(AZ::EntityId uiCanvasEntity)
-    {
-        m_uiCanvasId = uiCanvasEntity;
-    }
 
     void HUDComponent::SetRoundNumberText(uint16_t round)
     {
-        if (m_uiCanvasId.IsValid())
+        if (const INetworkMatch* netMatchComponent = AZ::Interface<INetworkMatch>::Get())
         {
-            AZ::Entity* textBoxEntity = nullptr;
-            UiCanvasBus::EventResult(textBoxEntity, m_uiCanvasId, &UiCanvasBus::Events::FindElementById, m_roundNumberId);
-
-            if (textBoxEntity != nullptr)
-            {
-                if (const NetworkMatchComponent* netMatchComponent = GetEntity()->FindComponent<NetworkMatchComponent>())
-                {
-                    m_roundNumberText = AZStd::string::format("%d of %d", round, netMatchComponent->GetTotalRounds());
-                    UiTextBus::Event(textBoxEntity->GetId(), &UiTextBus::Events::SetText, m_roundNumberText);
-                }
-            }
+            // Display the current round number.
+            // The end of match can push the round count over the max round count, so cap it.
+            const uint16_t totalRounds = aznumeric_cast<uint16_t>(netMatchComponent->GetTotalRoundCount());
+            m_roundNumberText = AZStd::string::format("%d of %d", AZStd::min(round, totalRounds), totalRounds);
+            UiTextBus::Event(m_roundNumberUi, &UiTextBus::Events::SetText, m_roundNumberText);
         }
     }
 
     void HUDComponent::SetRoundTimerText(RoundTimeSec time)
     {
-        if (m_uiCanvasId.IsValid())
-        {
-            AZ::Entity* textBoxEntity;
-            UiCanvasBus::EventResult(textBoxEntity, m_uiCanvasId, &UiCanvasBus::Events::FindElementById, m_roundTimerId);
+        // Display a clock with the time remaining
+        auto duration = AZStd::chrono::seconds(time);
+        auto minutes = AZStd::chrono::duration_cast<AZStd::chrono::minutes>(duration);
+        auto seconds = AZStd::chrono::duration_cast<AZStd::chrono::seconds>(duration - minutes);
 
-            if (textBoxEntity != nullptr)
-            {
-                auto duration = AZStd::chrono::seconds(time);
-                auto minutes = AZStd::chrono::duration_cast<AZStd::chrono::minutes>(duration);
-                auto seconds = AZStd::chrono::duration_cast<AZStd::chrono::seconds>(duration - minutes);
+        m_roundTimerText = AZStd::string::format("%02i:%02i", static_cast<int>(minutes.count()), static_cast<int>(seconds.count()));
 
-                m_roundTimerText = AZStd::string::format("%02i:%02i", static_cast<int>(minutes.count()), static_cast<int>(seconds.count()));
+        UiTextBus::Event(m_roundTimerUi, &UiTextBus::Events::SetText, m_roundTimerText);
 
-                UiTextBus::Event(textBoxEntity->GetId(), &UiTextBus::Events::SetText, m_roundTimerText);
+        // Display a countdown of custom UI when the round is close to finishing
+        if (duration.count() > 0 && duration.count() <= 10)
+        {
+            UiElementBus::Event(m_roundSecondsRemainingUiParent, &UiElementBus::Events::SetIsEnabled, true);
+
+            AZStd::vector<AZ::EntityId> uiSecondsRemainingUIElements;
+            UiElementBus::EventResult(uiSecondsRemainingUIElements, m_roundSecondsRemainingUiParent, &UiElementBus::Events::GetChildEntityIds);
+            for (int i = 0; i < uiSecondsRemainingUIElements.size(); ++i)
+            {
+                UiElementBus::Event(uiSecondsRemainingUIElements[i], &UiElementBus::Events::SetIsEnabled, i == aznumeric_cast<int>(duration.count()));
             }
         }
+        else
+        {
+            UiElementBus::Event(m_roundSecondsRemainingUiParent, &UiElementBus::Events::SetIsEnabled, false);
+        }
     }
-#endif
-} // namespace MultiplayerSample
+} // namespace MultiplayerSample

+ 19 - 24
Gem/Code/Source/Components/UI/HUDComponent.h

@@ -9,11 +9,8 @@
 #pragma once
 
 #include <AzCore/Component/Component.h>
-
-#if AZ_TRAIT_CLIENT
 #include <AzCore/EBus/Event.h>
-#include <LyShine/Bus/World/UiCanvasRefBus.h>
-#endif
+#include <Source/Components/NetworkMatchComponent.h>
 
 #include "MultiplayerSampleTypes.h"
 
@@ -21,9 +18,6 @@ namespace MultiplayerSample
 {
     class HUDComponent
         : public AZ::Component
-#if AZ_TRAIT_CLIENT
-        , UiCanvasAssetRefNotificationBus::Handler
-#endif
     {
     public:
         AZ_COMPONENT(MultiplayerSample::HUDComponent, "{8061E5D2-A1F7-4B40-9AAC-8FF14BD094FC}");
@@ -32,36 +26,37 @@ namespace MultiplayerSample
         * Reflects component data into the reflection contexts, including the serialization, edit, and behavior contexts.
         */
         static void Reflect(AZ::ReflectContext* context);
-        
-        /*
-        * Specifies the services that this component requires.
-        * The system activates the required services before it activates this component.
-        * It also deactivates the required services after it deactivates this component.
-        * If a required service is missing before this component is activated, the system
-        * returns an error and does not activate this component.
-        */
-        static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
-    
+
     protected:
         void Activate() override;
         void Deactivate() override;
 
     private:
-#if AZ_TRAIT_CLIENT
-        // UiCanvasAssetRefNotificationBus overrides ...
-        void OnCanvasLoadedIntoEntity(AZ::EntityId uiCanvasEntity) override;
+        // Wait for NetworkMatchComponent to activate so we can begin listening for NetworkMatch events
+        AZ::ScheduledEvent m_waitForActiveNetworkMatchComponent = AZ::ScheduledEvent([this]
+            {
+                if (const auto networkMatchComponent = AZ::Interface<INetworkMatch>::Get())
+                {
+                    SetRoundNumberText(aznumeric_cast<uint16_t>(networkMatchComponent->GetCurrentRoundNumber()));
+                    m_roundNumberHandler = AZ::EventHandler<uint16_t>([this](uint16_t value) { SetRoundNumberText(value); });
+                    networkMatchComponent->AddRoundNumberEventHandler(m_roundNumberHandler);
+
+                    m_roundTimerHandler = AZ::EventHandler<RoundTimeSec>([this](RoundTimeSec value) { SetRoundTimerText(value); });
+                    networkMatchComponent->AddRoundTimeRemainingEventHandler(m_roundTimerHandler);
+                    m_waitForActiveNetworkMatchComponent.RemoveFromQueue();
+                }
+            }, AZ::Name("HUDComponent Wait For Active NetworkMatchComponent"));
 
         void SetRoundNumberText(uint16_t round);
         void SetRoundTimerText(RoundTimeSec time);
     
-        AZ::EntityId m_uiCanvasId;
         AZ::EventHandler<uint16_t> m_roundNumberHandler; 
         AZ::EventHandler<RoundTimeSec> m_roundTimerHandler;
-#endif
 
-        int m_roundNumberId = 0;
-        int m_roundTimerId = 0;
+        AZ::EntityId m_roundNumberUi;
+        AZ::EntityId m_roundTimerUi;
         AZStd::string m_roundNumberText;
         AZStd::string m_roundTimerText;
+        AZ::EntityId m_roundSecondsRemainingUiParent;
     };
 } // namespace MultiplayerSample

+ 2 - 2
Gem/Code/Source/MultiplayerSampleModule.cpp

@@ -11,11 +11,11 @@
 #include <Components/PerfTest/NetworkPrefabSpawnerComponent.h>
 #include <Components/PerfTest/NetworkRandomImpulseComponent.h>
 #include <Components/PerfTest/NetworkTestSpawnerComponent.h>
-#include <Components/UI/HUDComponent.h>
 #include <Components/UI/UiCoinCountComponent.h>
 #include <Components/UI/UiGameOverComponent.h>
 #include <Components/UI/UiPlayerArmorComponent.h>
 #if AZ_TRAIT_CLIENT
+    #include <Components/UI/HUDComponent.h>
     #include <Components/UI/UiMatchPlayerCoinCountsComponent.h>
     #include <Components/UI/UiRestBetweenRoundsComponent.h>
 #endif
@@ -40,10 +40,10 @@ namespace MultiplayerSample
             m_descriptors.insert(m_descriptors.end(), {
                 MultiplayerSampleSystemComponent::CreateDescriptor(),
                 ExampleFilteredEntityComponent::CreateDescriptor(),
-                HUDComponent::CreateDescriptor(),
                 NetworkPrefabSpawnerComponent::CreateDescriptor(),
                 UiCoinCountComponent::CreateDescriptor(),
                 #if AZ_TRAIT_CLIENT
+                    HUDComponent::CreateDescriptor(),
                     UiGameOverComponent::CreateDescriptor(),
                     UiPlayerArmorComponent::CreateDescriptor(),
                     UiMatchPlayerCoinCountsComponent::CreateDescriptor(),

+ 2 - 0
Gem/Code/multiplayersample_client_files.cmake

@@ -8,6 +8,8 @@
 set(FILES
     Source/Components/UI/UiGameOverComponent.cpp
     Source/Components/UI/UiGameOverComponent.h
+    Source/Components/UI/HUDComponent.cpp
+    Source/Components/UI/HUDComponent.h
     Source/Components/UI/UiMatchPlayerCoinCountsComponent.cpp
     Source/Components/UI/UiMatchPlayerCoinCountsComponent.h
     Source/Components/UI/UiPlayerArmorComponent.cpp

+ 0 - 2
Gem/Code/multiplayersample_files.cmake

@@ -50,8 +50,6 @@ set(FILES
     Source/Components/NetworkPlayerMovementComponent.cpp
     Source/Components/NetworkPlayerMovementComponent.h
 
-    Source/Components/UI/HUDComponent.cpp
-    Source/Components/UI/HUDComponent.h
     Source/Components/UI/UiCoinCountComponent.cpp
     Source/Components/UI/UiCoinCountComponent.h
     Source/Components/Multiplayer/GameplayEffectsComponent.cpp

+ 0 - 9
Levels/GameplayTest/GameplayTest.prefab

@@ -10553,15 +10553,6 @@
                     "$type": "EditorDisabledCompositionComponent",
                     "Id": 17083415778652839230
                 },
-                "Component_[17163718511096577681]": {
-                    "$type": "GenericComponentWrapper",
-                    "Id": 17163718511096577681,
-                    "m_template": {
-                        "$type": "MultiplayerSample::HUDComponent",
-                        "RoundNumberId": 8,
-                        "RoundTimerId": 4
-                    }
-                },
                 "Component_[17414909752872705959]": {
                     "$type": "GenericComponentWrapper",
                     "Id": 17414909752872705959,

+ 1 - 1
Prefabs/GamePlay_Effects.prefab

@@ -121,7 +121,7 @@
                         "PlayerKnockedDown": "play_sx_player_knockdown",
                         "ArmorBreaking": "play_sx_player_armor_breaking",
                         "ArmorMend": "play_sx_player_armor_mend",
-                        "PlayerOuch": "play_sx_wpn_bubblegun_impact",
+                        "PlayerOuch": "play_sx_player_pain",
                         "LadderClimb": "play_sx_player_ladder_climb",
                         "ShutDown": "play_sx_ui_game_shutdown",
                         "CountDown": "play_sx_ui_game_countdown",

+ 0 - 9
Prefabs/MatchController.prefab

@@ -2134,15 +2134,6 @@
                     "$type": "EditorDisabledCompositionComponent",
                     "Id": 17083415778652839230
                 },
-                "Component_[17163718511096577681]": {
-                    "$type": "GenericComponentWrapper",
-                    "Id": 17163718511096577681,
-                    "m_template": {
-                        "$type": "MultiplayerSample::HUDComponent",
-                        "RoundNumberId": 8,
-                        "RoundTimerId": 4
-                    }
-                },
                 "Component_[17414909752872705959]": {
                     "$type": "GenericComponentWrapper",
                     "Id": 17414909752872705959,

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 251 - 305
UICanvases/BasicHUD.uicanvas


이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.