Przeglądaj źródła

Merge pull request #250 from aws-lumberyard-dev/AutoShowScoreScreenBetweenRounds

Automatically Show Score Between Rounds
Gene Walters 2 lat temu
rodzic
commit
ea50792ce8

+ 2 - 0
Gem/Code/Source/Components/UI/HUDComponent.cpp

@@ -25,6 +25,8 @@ namespace MultiplayerSample
     void HUDComponent::Deactivate()
     {
         m_waitForActiveNetworkMatchComponent.RemoveFromQueue();
+        m_roundNumberHandler.Disconnect();
+        m_roundTimerHandler.Disconnect();
     }
 
     void HUDComponent::Reflect(AZ::ReflectContext* context)

+ 23 - 5
Gem/Code/Source/Components/UI/UiMatchPlayerCoinCountsComponent.cpp

@@ -26,12 +26,15 @@ namespace MultiplayerSample
 
     void UiMatchPlayerCoinCountsComponent::Activate()
     {
+        m_waitForActiveNetworkMatchComponent.Enqueue(AZ::TimeMs{ 1000 }, true);
         StartingPointInput::InputEventNotificationBus::MultiHandler::BusConnect(ShowPlayerCoinCountsEventId);
     }
 
     void UiMatchPlayerCoinCountsComponent::Deactivate()
     {
         StartingPointInput::InputEventNotificationBus::MultiHandler::BusDisconnect();
+        m_waitForActiveNetworkMatchComponent.RemoveFromQueue();
+        m_roundTimerHandler.Disconnect();
     }
 
     void UiMatchPlayerCoinCountsComponent::UpdatePlayerScoreUI()
@@ -93,6 +96,24 @@ namespace MultiplayerSample
         }
     }
 
+    void UiMatchPlayerCoinCountsComponent::EnableUI(bool enable)
+    {
+        UiElementBus::Event(m_rootElementId, &UiElementBus::Events::SetIsEnabled, enable);
+
+        if (enable)
+        {
+            if (!m_onPlayerScoreChanged.IsConnected())
+            {
+                AZ::Interface<MatchPlayerCoinsComponent>::Get()->CoinsPerPlayerAddEvent(m_onPlayerScoreChanged);
+            }
+            UpdatePlayerScoreUI();
+        }
+        else
+        {
+            m_onPlayerScoreChanged.Disconnect();
+        }
+    }
+
     void UiMatchPlayerCoinCountsComponent::OnPressed([[maybe_unused]] float value)
     {
         const StartingPointInput::InputEventNotificationId* inputId = StartingPointInput::InputEventNotificationBus::GetCurrentBusId();
@@ -104,9 +125,7 @@ namespace MultiplayerSample
 
         if (*inputId == ShowPlayerCoinCountsEventId)
         {
-            UiElementBus::Event(m_rootElementId, &UiElementBus::Events::SetIsEnabled, true);
-            AZ::Interface<MatchPlayerCoinsComponent>::Get()->CoinsPerPlayerAddEvent(m_onPlayerScoreChanged);
-            UpdatePlayerScoreUI();
+            EnableUI(true);
         }
     }
 
@@ -121,8 +140,7 @@ namespace MultiplayerSample
 
         if (*inputId == ShowPlayerCoinCountsEventId)
         {
-            m_onPlayerScoreChanged.Disconnect();
-            UiElementBus::Event(m_rootElementId, &UiElementBus::Events::SetIsEnabled, false);
+            EnableUI(false);
         }
     }
 

+ 40 - 0
Gem/Code/Source/Components/UI/UiMatchPlayerCoinCountsComponent.h

@@ -19,6 +19,8 @@ namespace MultiplayerSample
         , public StartingPointInput::InputEventNotificationBus::MultiHandler
     {
     public:
+        static constexpr float SecondsBeforeNewRoundToHideUI = 3.0f;
+
         AZ_COMPONENT(UiMatchPlayerCoinCountsComponent, "{529b9b3b-bea2-4120-9089-c4451438e4c0}");
 
         static void Reflect(AZ::ReflectContext* context);
@@ -32,6 +34,9 @@ namespace MultiplayerSample
         void OnReleased(float value) override;
         //! @}
 
+        //! Show or hide the player score menu
+        //! @param enable true will display the menu; false will hide the menu. 
+        void EnableUI(bool enable);
 
     private:
         AZ::EntityId m_rootElementId;
@@ -45,5 +50,40 @@ namespace MultiplayerSample
             UpdatePlayerScoreUI();
         } };
 
+        // Wait for NetworkMatchComponent to activate so we can begin listening for NetworkMatch events
+        // For example: when the round resets to 1 we know the new match has started.
+        AZ::ScheduledEvent m_waitForActiveNetworkMatchComponent = AZ::ScheduledEvent([this]
+            {
+                if (const auto networkMatchComponent = AZ::Interface<INetworkMatch>::Get())
+                {
+                    networkMatchComponent->AddRoundTimeRemainingEventHandler(m_roundTimerHandler);
+                    m_waitForActiveNetworkMatchComponent.RemoveFromQueue();
+                }
+            }, AZ::Name("GameOverUI Wait For Active NetworkMatchComponent"));
+
+        // Listen for rest time between rounds coming to an end
+        // Automatically close the player score menu when the round is about to start
+        AZ::Event<RoundTimeSec>::Handler m_restTimerHandler{ [this](RoundTimeSec secondsRemaining)
+        {
+            if (secondsRemaining <= SecondsBeforeNewRoundToHideUI)
+            {
+                EnableUI(false);
+                m_restTimerHandler.Disconnect();
+            }
+        } };
+
+        // Listen for the round coming to an end
+        // Automatically open up the player score menu in between rounds
+        AZ::Event<RoundTimeSec>::Handler m_roundTimerHandler{ [this](RoundTimeSec secondsRemaining)
+        {
+            const auto networkMatch = AZ::Interface<INetworkMatch>::Get();
+            if (secondsRemaining <= 0 && 
+                networkMatch->GetCurrentRoundNumber() <= networkMatch->GetTotalRoundCount())
+            {
+                EnableUI(true);
+                networkMatch->AddRoundRestTimeRemainingEventHandler(m_restTimerHandler);
+            }
+        } };
+
     };
 } // namespace MultiplayerSample

Plik diff jest za duży
+ 353 - 248
UICanvases/BasicHUD.uicanvas


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików