From 27ff9d3e44c608d686115a908a4b45e5765d9649 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 31 Mar 2016 16:33:36 +1100 Subject: [PATCH] Check CursorVisible in the game property instead of manually getting it beforehand. (Less error prone) --- ClassicalSharp/2D/Screens/ChatScreen.cs | 9 +++------ ClassicalSharp/2D/Screens/HudScreen.cs | 6 ++---- ClassicalSharp/2D/Screens/WarningScreen.cs | 3 +-- ClassicalSharp/Game/Game.Properties.cs | 10 ++++++++-- ClassicalSharp/Game/Game.cs | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index 5ff296ce7..3beb21f9f 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -246,8 +246,7 @@ namespace ClassicalSharp.Gui { public override void Dispose() { if( HandlesAllInput ) { game.chatInInputBuffer = textInput.chatInputText.ToString(); - if( game.CursorVisible ) - game.CursorVisible = false; + game.CursorVisible = false; } else { game.chatInInputBuffer = null; } @@ -316,8 +315,7 @@ namespace ClassicalSharp.Gui { } public void OpenTextInputBar( string initialText ) { - if( !game.CursorVisible ) - game.CursorVisible = true; + game.CursorVisible = true; suppressNextPress = true; HandlesAllInput = true; game.Keyboard.KeyRepeat = true; @@ -339,8 +337,7 @@ namespace ClassicalSharp.Gui { if( key == game.Mapping( KeyBinding.SendChat ) || key == Key.KeypadEnter || key == game.Mapping( KeyBinding.PauseOrExit ) ) { HandlesAllInput = false; - if( game.CursorVisible ) - game.CursorVisible = false; + game.CursorVisible = false; game.Camera.RegrabMouse(); game.Keyboard.KeyRepeat = false; diff --git a/ClassicalSharp/2D/Screens/HudScreen.cs b/ClassicalSharp/2D/Screens/HudScreen.cs index b8418181c..2cfe863d8 100644 --- a/ClassicalSharp/2D/Screens/HudScreen.cs +++ b/ClassicalSharp/2D/Screens/HudScreen.cs @@ -66,16 +66,14 @@ namespace ClassicalSharp.Gui { } public void GainFocus() { - if( game.CursorVisible ) - game.CursorVisible = false; + game.CursorVisible = false; game.Camera.RegrabMouse(); } public void LoseFocus() { if( playerList != null ) playerList.Dispose(); - if( !game.CursorVisible ) - game.CursorVisible = true; + game.CursorVisible = true; } public override void OnResize( int oldWidth, int oldHeight, int width, int height ) { diff --git a/ClassicalSharp/2D/Screens/WarningScreen.cs b/ClassicalSharp/2D/Screens/WarningScreen.cs index 42f89f14c..a155940ef 100644 --- a/ClassicalSharp/2D/Screens/WarningScreen.cs +++ b/ClassicalSharp/2D/Screens/WarningScreen.cs @@ -69,8 +69,7 @@ namespace ClassicalSharp.Gui { game.activeScreen = game.WarningScreens[0]; } else { game.activeScreen = lastScreen; - if( game.CursorVisible != wasCursorVisible ) - game.CursorVisible = wasCursorVisible; + game.CursorVisible = wasCursorVisible; if( game.activeScreen == null && game.CursorVisible ) game.CursorVisible = false; } diff --git a/ClassicalSharp/Game/Game.Properties.cs b/ClassicalSharp/Game/Game.Properties.cs index 655ab16f8..8c513f9b6 100644 --- a/ClassicalSharp/Game/Game.Properties.cs +++ b/ClassicalSharp/Game/Game.Properties.cs @@ -213,9 +213,15 @@ namespace ClassicalSharp { set { window.VSync = value; } } + bool visible = true; public bool CursorVisible { - get { return window.CursorVisible; } - set { window.CursorVisible = value; } + get { return visible; } + set { + // Only set the value when it has changes. + if( visible == value ) return; + window.CursorVisible = value; + visible = value; + } } public Point DesktopCursorPos { diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index 57478d468..8770a5fc6 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -399,7 +399,7 @@ namespace ClassicalSharp { activeScreen = screen; screen.wasCursorVisible = CursorVisible; - if( !CursorVisible ) CursorVisible = true; + CursorVisible = true; } else { screen.wasCursorVisible = WarningScreens[0].wasCursorVisible; }