Browse Source

Don't hide cursor in the Editor when not in game mode.

Signed-off-by: Alex Peterson <[email protected]>
Alex Peterson 2 years ago
parent
commit
45f0973872
2 changed files with 4 additions and 10 deletions
  1. 4 9
      Gems/ImGui/Code/Source/ImGuiManager.cpp
  2. 0 1
      Gems/ImGui/Code/Source/ImGuiManager.h

+ 4 - 9
Gems/ImGui/Code/Source/ImGuiManager.cpp

@@ -684,7 +684,6 @@ void ImGuiManager::ToggleThroughImGuiVisibleState()
                 // Disable discrete input in edit mode because the user has to click in the viewport to navigate,
                 // so there's no concern about ImGui mouse movements also navigating the camera.
                 m_enableDiscreteInputMode = false;
-                m_previousSystemCursorStateInGame = false;
             }
             else
             {
@@ -695,7 +694,6 @@ void ImGuiManager::ToggleThroughImGuiVisibleState()
                 // During gameplay, the mouse usually affects the camera, so we want the discrete mode to be available by default,
                 // so the user can easily turn off gameplay input while interacting with ImGui.
                 m_enableDiscreteInputMode = true;
-                m_previousSystemCursorStateInGame = true;
             }
 
             // Fetch old cursor state
@@ -715,14 +713,11 @@ void ImGuiManager::ToggleThroughImGuiVisibleState()
         case DisplayState::Visible:
             m_clientMenuBarState = DisplayState::Hidden;
 
+            // Avoid hiding the cursor when in the Editor and not in game mode
             const bool inGame = !gEnv->IsEditor() || gEnv->IsEditorGameMode(); 
-
-            // Restore old cursor state if the "In Game" state hasn't changed.
-            // This prevents incorrectly hiding the cursor when a user is in
-            // game mode, opens the console, exits game mode, and then hides the
-            // console resulting in the cursor being restored to what it was
-            // in game mode, usually making the cursor hidden in the editor.
-            if (m_previousSystemCursorStateInGame == inGame)
+            const bool cursorWasVisible = m_previousSystemCursorState == AzFramework::SystemCursorState::ConstrainedAndVisible ||
+                                          m_previousSystemCursorState == AzFramework::SystemCursorState::UnconstrainedAndVisible;
+            if (inGame || cursorWasVisible)
             {
                 AzFramework::InputSystemCursorRequestBus::Event(AzFramework::InputDeviceMouse::Id,
                     &AzFramework::InputSystemCursorRequests::SetSystemCursorState,

+ 0 - 1
Gems/ImGui/Code/Source/ImGuiManager.h

@@ -108,7 +108,6 @@ namespace ImGui
 
         bool m_hardwardeMouseConnected = false;
         bool m_enableDiscreteInputMode = false;
-        bool m_previousSystemCursorStateInGame = false;
         AzFramework::SystemCursorState m_previousSystemCursorState = AzFramework::SystemCursorState::Unknown;
         ImGuiControllerModeFlags::FlagType m_controllerModeFlags = 0;
         float m_controllerMouseSensitivity = 4.0f;