Check CursorVisible in the game property instead of manually getting it beforehand. (Less error prone)

This commit is contained in:
UnknownShadow200 2016-03-31 16:33:36 +11:00
parent 1e19178b88
commit 27ff9d3e44
5 changed files with 15 additions and 15 deletions

View File

@ -246,8 +246,7 @@ namespace ClassicalSharp.Gui {
public override void Dispose() { public override void Dispose() {
if( HandlesAllInput ) { if( HandlesAllInput ) {
game.chatInInputBuffer = textInput.chatInputText.ToString(); game.chatInInputBuffer = textInput.chatInputText.ToString();
if( game.CursorVisible ) game.CursorVisible = false;
game.CursorVisible = false;
} else { } else {
game.chatInInputBuffer = null; game.chatInInputBuffer = null;
} }
@ -316,8 +315,7 @@ namespace ClassicalSharp.Gui {
} }
public void OpenTextInputBar( string initialText ) { public void OpenTextInputBar( string initialText ) {
if( !game.CursorVisible ) game.CursorVisible = true;
game.CursorVisible = true;
suppressNextPress = true; suppressNextPress = true;
HandlesAllInput = true; HandlesAllInput = true;
game.Keyboard.KeyRepeat = true; game.Keyboard.KeyRepeat = true;
@ -339,8 +337,7 @@ namespace ClassicalSharp.Gui {
if( key == game.Mapping( KeyBinding.SendChat ) || key == Key.KeypadEnter if( key == game.Mapping( KeyBinding.SendChat ) || key == Key.KeypadEnter
|| key == game.Mapping( KeyBinding.PauseOrExit ) ) { || key == game.Mapping( KeyBinding.PauseOrExit ) ) {
HandlesAllInput = false; HandlesAllInput = false;
if( game.CursorVisible ) game.CursorVisible = false;
game.CursorVisible = false;
game.Camera.RegrabMouse(); game.Camera.RegrabMouse();
game.Keyboard.KeyRepeat = false; game.Keyboard.KeyRepeat = false;

View File

@ -66,16 +66,14 @@ namespace ClassicalSharp.Gui {
} }
public void GainFocus() { public void GainFocus() {
if( game.CursorVisible ) game.CursorVisible = false;
game.CursorVisible = false;
game.Camera.RegrabMouse(); game.Camera.RegrabMouse();
} }
public void LoseFocus() { public void LoseFocus() {
if( playerList != null ) if( playerList != null )
playerList.Dispose(); playerList.Dispose();
if( !game.CursorVisible ) game.CursorVisible = true;
game.CursorVisible = true;
} }
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) { public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {

View File

@ -69,8 +69,7 @@ namespace ClassicalSharp.Gui {
game.activeScreen = game.WarningScreens[0]; game.activeScreen = game.WarningScreens[0];
} else { } else {
game.activeScreen = lastScreen; game.activeScreen = lastScreen;
if( game.CursorVisible != wasCursorVisible ) game.CursorVisible = wasCursorVisible;
game.CursorVisible = wasCursorVisible;
if( game.activeScreen == null && game.CursorVisible ) if( game.activeScreen == null && game.CursorVisible )
game.CursorVisible = false; game.CursorVisible = false;
} }

View File

@ -213,9 +213,15 @@ namespace ClassicalSharp {
set { window.VSync = value; } set { window.VSync = value; }
} }
bool visible = true;
public bool CursorVisible { public bool CursorVisible {
get { return window.CursorVisible; } get { return visible; }
set { window.CursorVisible = value; } set {
// Only set the value when it has changes.
if( visible == value ) return;
window.CursorVisible = value;
visible = value;
}
} }
public Point DesktopCursorPos { public Point DesktopCursorPos {

View File

@ -399,7 +399,7 @@ namespace ClassicalSharp {
activeScreen = screen; activeScreen = screen;
screen.wasCursorVisible = CursorVisible; screen.wasCursorVisible = CursorVisible;
if( !CursorVisible ) CursorVisible = true; CursorVisible = true;
} else { } else {
screen.wasCursorVisible = WarningScreens[0].wasCursorVisible; screen.wasCursorVisible = WarningScreens[0].wasCursorVisible;
} }