Ver Fonte

Merge pull request #249 from aws-lumberyard-dev/mbalfour/freeze_camera_in_esc_menu

Freeze camera in esc menu
Mike Balfour há 2 anos atrás
pai
commit
1a302393fb

+ 28 - 24
Gem/Code/Source/Components/NetworkMatchComponent.cpp

@@ -5,6 +5,8 @@
  *
  */
 
+#include <AzCore/Preprocessor/EnumReflectUtils.h>
+
 #include <GameplayEffectsNotificationBus.h>
 #include <MultiplayerSampleTypes.h>
 #include <UiGameOverBus.h>
@@ -34,6 +36,8 @@
 
 namespace MultiplayerSample
 {
+    AZ_ENUM_DEFINE_REFLECT_UTILITIES(AllowedPlayerActions);
+
     void NetworkMatchComponent::Reflect(AZ::ReflectContext* context)
     {
         AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
@@ -50,7 +54,7 @@ namespace MultiplayerSample
                 ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
                 ->Attribute(AZ::Script::Attributes::Module, "multiplayersample")
                 ->Attribute(AZ::Script::Attributes::Category, "MultiplayerSample")
-                ->Event("Is player action allowed", &MultiplayerSample::NetworkMatchComponentRequestBus::Events::IsPlayerActionAllowed)
+                ->Event("Get the allowable player actions", &MultiplayerSample::NetworkMatchComponentRequestBus::Events::PlayerActionsAllowed)
                 ->Event("Get roundtime remaining in seconds", &MultiplayerSample::NetworkMatchComponentRequestBus::Events::GetRoundTimeRemainingSec)
                 ->Event("Get total roundtime in seconds", &MultiplayerSample::NetworkMatchComponentRequestBus::Events::GetTotalRoundTimeSec)
                 ->Event("Get current round number", &MultiplayerSample::NetworkMatchComponentRequestBus::Events::GetCurrentRoundNumber)
@@ -84,36 +88,36 @@ namespace MultiplayerSample
         #endif
     }
 
-    bool NetworkMatchComponent::IsPlayerActionAllowed() const
+    AllowedPlayerActions NetworkMatchComponent::PlayerActionsAllowed() const
     {
-        // Disable player actions between rounds (rest period)
-        if (GetRoundTime() <= 0 && GetRoundRestTimeRemaining() > 0)
+#if AZ_TRAIT_CLIENT
+        // Don't allow player movement if the UI cursor is visible
+        bool isCursorVisible = false;
+        UiCursorBus::BroadcastResult(isCursorVisible, &UiCursorInterface::IsUiCursorVisible);
+        if (isCursorVisible)
         {
-            return false;
+            return AllowedPlayerActions::None;
         }
 
-        #if AZ_TRAIT_CLIENT
-            // Don't allow player movement if the system cursor is visible
-            AzFramework::SystemCursorState systemCursorState{ AzFramework::SystemCursorState::Unknown };
-            AzFramework::InputSystemCursorRequestBus::EventResult(systemCursorState, AzFramework::InputDeviceMouse::Id,
-                &AzFramework::InputSystemCursorRequests::GetSystemCursorState);
-            if ((systemCursorState == AzFramework::SystemCursorState::UnconstrainedAndVisible) ||
-                (systemCursorState == AzFramework::SystemCursorState::ConstrainedAndVisible))
-            {
-                return false;
-            }
+        // Don't allow player movement if the system cursor is visible
+        AzFramework::SystemCursorState systemCursorState{ AzFramework::SystemCursorState::Unknown };
+        AzFramework::InputSystemCursorRequestBus::EventResult(systemCursorState, AzFramework::InputDeviceMouse::Id,
+            &AzFramework::InputSystemCursorRequests::GetSystemCursorState);
+        if ((systemCursorState == AzFramework::SystemCursorState::UnconstrainedAndVisible) ||
+            (systemCursorState == AzFramework::SystemCursorState::ConstrainedAndVisible))
+        {
+            return AllowedPlayerActions::None;
+        }
 
-            // Don't allow player movement if the UI cursor is visible
-            bool isCursorVisible = false;
-            UiCursorBus::BroadcastResult(isCursorVisible, &UiCursorInterface::IsUiCursorVisible);
-            if (isCursorVisible)
-            {
-                return false;
-            }
+#endif
 
-        #endif
+        // Disable player actions between rounds (rest period)
+        if (GetRoundTime() <= 0 && GetRoundRestTimeRemaining() > 0)
+        {
+            return AllowedPlayerActions::RotationOnly;
+        }
 
-        return true;
+        return AllowedPlayerActions::All;
     }
 
     float NetworkMatchComponent::GetRoundTimeRemainingSec() const

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

@@ -15,6 +15,12 @@
 
 namespace MultiplayerSample
 {
+    AZ_ENUM_CLASS(AllowedPlayerActions,
+        None,
+        RotationOnly,
+        All
+    );
+
     class INetworkMatch
     {
     public:
@@ -23,10 +29,10 @@ namespace MultiplayerSample
         INetworkMatch() = default;
         virtual ~INetworkMatch() = default;
 
-        //! Checks if the current game state allows player action.
-        //! For example, in between rounds the player shouldn't be able to move around.
-        //! @result true if the player is currently allowed to run, jump, shoot, etc; otherwise false.
-        virtual bool IsPlayerActionAllowed() const = 0;
+        //! Returns which player actions (if any) the current game state allows.
+        //! For example, in between rounds the player shouldn't be able to move around, but they can still rotate.
+        //! @result The type of player actions that are allowed 
+        virtual AllowedPlayerActions PlayerActionsAllowed() const = 0;
 
         //! Returns the time in seconds until the current round ends.
         //! @result the time in seconds until the current round ends
@@ -87,7 +93,7 @@ namespace MultiplayerSample
 
         //! INetworkMatch interface
         //! @{
-        bool IsPlayerActionAllowed() const override;
+        AllowedPlayerActions PlayerActionsAllowed() const override;
         float GetRoundTimeRemainingSec() const override;
         float GetTotalRoundTimeSec() const override;
         int32_t GetCurrentRoundNumber() const override;
@@ -175,3 +181,8 @@ namespace MultiplayerSample
         void FindWinner(MatchResultsSummary& results, const AZStd::vector<PlayerState>& potentialWinners);
     };
 }
+
+namespace AZ
+{
+    AZ_TYPE_INFO_SPECIALIZE(MultiplayerSample::AllowedPlayerActions, "{D8EB0533-D50C-4C04-B462-BA0BD1607FA8}");
+} // namespace AZ

+ 10 - 7
Gem/Code/Source/Components/NetworkPlayerMovementComponent.cpp

@@ -137,18 +137,21 @@ namespace MultiplayerSample
         // Inputs for your own component always exist
         NetworkPlayerMovementComponentNetworkInput* playerInput = input.FindComponentInput<NetworkPlayerMovementComponentNetworkInput>();
 
-        // View Axis are clamped and brought into the -1,1 range for transport across the network.
-        // These are set regardless of whether or not any other player actions are allowed.
-        playerInput->m_viewYaw = MouseAxis(AZStd::clamp<float>(m_viewYaw, -cl_MaxMouseDelta, cl_MaxMouseDelta) / cl_MaxMouseDelta);
-        playerInput->m_viewPitch = MouseAxis(AZStd::clamp<float>(m_viewPitch, -cl_MaxMouseDelta, cl_MaxMouseDelta) / cl_MaxMouseDelta);
+        // Check current game-play state
+        INetworkMatch* networkMatchComponent = AZ::Interface<INetworkMatch>::Get();
+        if (networkMatchComponent && (networkMatchComponent->PlayerActionsAllowed() != AllowedPlayerActions::None))
+        {
+            // View Axis are clamped and brought into the -1,1 range for transport across the network.
+            // These are set if the player actions allow for rotation and/or all movement.
+            playerInput->m_viewYaw = MouseAxis(AZStd::clamp<float>(m_viewYaw, -cl_MaxMouseDelta, cl_MaxMouseDelta) / cl_MaxMouseDelta);
+            playerInput->m_viewPitch = MouseAxis(AZStd::clamp<float>(m_viewPitch, -cl_MaxMouseDelta, cl_MaxMouseDelta) / cl_MaxMouseDelta);
+        }
 
         // reset accumulated amounts
         m_viewYaw = 0.f;
         m_viewPitch = 0.f;
 
-        // Check current game-play state
-        INetworkMatch* networkMatchComponent = AZ::Interface<INetworkMatch>::Get();
-        if (networkMatchComponent && networkMatchComponent->IsPlayerActionAllowed())
+        if (networkMatchComponent && (networkMatchComponent->PlayerActionsAllowed() == AllowedPlayerActions::All))
         {
             // Movement axis
             // Since we're on a keyboard, this adds a touch of an acceleration curve to the keyboard inputs

+ 1 - 1
Gem/Code/Source/Components/NetworkWeaponsComponent.cpp

@@ -425,7 +425,7 @@ namespace MultiplayerSample
     void NetworkWeaponsComponentController::CreateInput(Multiplayer::NetworkInput& input, [[maybe_unused]] float deltaTime)
     {
         INetworkMatch* networkMatchComponent = AZ::Interface<INetworkMatch>::Get();
-        if (!networkMatchComponent || !networkMatchComponent->IsPlayerActionAllowed())
+        if (!networkMatchComponent || (networkMatchComponent->PlayerActionsAllowed() != AllowedPlayerActions::All))
         {
             m_weaponDrawn = false;
             m_weaponFiring = false;