From df986441f86bf5e34b1db53d3df6242e1244b24c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 24 Jun 2016 20:21:33 +1000 Subject: [PATCH] Make 'Back to X' buttons same as classic. (Thanks FrostFox) --- ClassicalSharp/2D/Screens/ClickableScreen.cs | 8 +++- .../2D/Screens/Menu/ClassicOptionsScreen.cs | 43 ++++++++++--------- ClassicalSharp/2D/Screens/Menu/PauseScreen.cs | 2 +- ClassicalSharp/2D/Utils/FastBitmap.cs | 2 +- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/ClassicalSharp/2D/Screens/ClickableScreen.cs b/ClassicalSharp/2D/Screens/ClickableScreen.cs index 3bf59da77..122886262 100644 --- a/ClassicalSharp/2D/Screens/ClickableScreen.cs +++ b/ClassicalSharp/2D/Screens/ClickableScreen.cs @@ -50,12 +50,16 @@ namespace ClassicalSharp.Gui { } protected ButtonWidget MakeBack( bool toGame, Font font, Action onClick ) { - return MakeBack( toGame ? "Back to game" : "Back to menu", 25, font, onClick ); + return MakeBack( 201, toGame ? "Back to game" : "Back to menu", 25, font, onClick ); } protected ButtonWidget MakeBack( string text, int y, Font font, Action onClick ) { + return MakeBack( 201, text, y, font, onClick ); + } + + protected ButtonWidget MakeBack( int width, string text, int y, Font font, Action onClick ) { return ButtonWidget.Create( - game, 0, y, 201, 40, text, + game, 0, y, width, 40, text, Anchor.Centre, Anchor.BottomOrRight, font, LeftOnly( onClick ) ); } } diff --git a/ClassicalSharp/2D/Screens/Menu/ClassicOptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/ClassicOptionsScreen.cs index 7eb2db7b2..292ff4599 100644 --- a/ClassicalSharp/2D/Screens/Menu/ClassicOptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/ClassicOptionsScreen.cs @@ -17,48 +17,49 @@ namespace ClassicalSharp.Gui { widgets = new Widget[] { // Column 1 MakeBool( -1, -150, "Music", OptionsKey.UseMusic, - OnWidgetClick, g => g.UseMusic, - (g, v) => { g.UseMusic = v; g.AudioPlayer.SetMusic( g.UseMusic ); }), + OnWidgetClick, g => g.UseMusic, + (g, v) => { g.UseMusic = v; g.AudioPlayer.SetMusic( g.UseMusic ); }), MakeBool( -1, -100, "Invert mouse", OptionsKey.InvertMouse, OnWidgetClick, g => g.InvertMouse, (g, v) => g.InvertMouse = v ), MakeOpt( -1, -50, "View distance", OnWidgetClick, - g => g.ViewDistance.ToString(), - (g, v) => g.SetViewDistance( Int32.Parse( v ), true ) ), + g => g.ViewDistance.ToString(), + (g, v) => g.SetViewDistance( Int32.Parse( v ), true ) ), !network.IsSinglePlayer ? null : MakeBool( -1, 0, "Block physics", OptionsKey.SingleplayerPhysics, OnWidgetClick, - g => ((SinglePlayerServer)network).physics.Enabled, - (g, v) => ((SinglePlayerServer)network).physics.Enabled = v), + g => ((SinglePlayerServer)network).physics.Enabled, + (g, v) => ((SinglePlayerServer)network).physics.Enabled = v), // Column 2 MakeBool( 1, -150, "Sound", OptionsKey.UseSound, - OnWidgetClick, g => g.UseSound, - (g, v) => { g.UseSound = v; g.AudioPlayer.SetSound( g.UseSound ); }), + OnWidgetClick, g => g.UseSound, + (g, v) => { g.UseSound = v; g.AudioPlayer.SetSound( g.UseSound ); }), MakeBool( 1, -100, "Show FPS", OptionsKey.ShowFPS, - OnWidgetClick, g => g.ShowFPS, (g, v) => g.ShowFPS = v ), + OnWidgetClick, g => g.ShowFPS, (g, v) => g.ShowFPS = v ), MakeBool( 1, -50, "View bobbing", OptionsKey.ViewBobbing, - OnWidgetClick, g => g.ViewBobbing, (g, v) => g.ViewBobbing = v ), + OnWidgetClick, g => g.ViewBobbing, (g, v) => g.ViewBobbing = v ), MakeOpt( 1, 0, "FPS mode", OnWidgetClick, - g => g.FpsLimit.ToString(), - (g, v) => { object raw = Enum.Parse( typeof(FpsLimitMethod), v ); - g.SetFpsLimitMethod( (FpsLimitMethod)raw ); - Options.Set( OptionsKey.FpsLimit, v ); } ), + g => g.FpsLimit.ToString(), + (g, v) => { object raw = Enum.Parse( typeof(FpsLimitMethod), v ); + g.SetFpsLimitMethod( (FpsLimitMethod)raw ); + Options.Set( OptionsKey.FpsLimit, v ); } ), !game.ClassicHacks ? null : MakeBool( 0, 60, "Hacks enabled", OptionsKey.HacksEnabled, - OnWidgetClick, g => g.LocalPlayer.Hacks.Enabled, - (g, v) => { g.LocalPlayer.Hacks.Enabled = v; - g.LocalPlayer.CheckHacksConsistency(); } ), + OnWidgetClick, g => g.LocalPlayer.Hacks.Enabled, + (g, v) => { g.LocalPlayer.Hacks.Enabled = v; + g.LocalPlayer.CheckHacksConsistency(); } ), - MakeTitle( 0, 110, "Controls", LeftOnly( - (g, w) => g.SetNewScreen( new ClassicKeyBindingsScreen( g ) ) ) ), + ButtonWidget.Create( game, 0, 95, 401, 41, "Controls", Anchor.Centre, + Anchor.BottomOrRight, titleFont, + LeftOnly( (g, w) => g.SetNewScreen( new ClassicKeyBindingsScreen( g ) ) ) ), - MakeBack( "Done", 25, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), + MakeBack( 401, "Done", 22, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), null, null, }; MakeValidators(); @@ -70,7 +71,7 @@ namespace ClassicalSharp.Gui { new BooleanValidator(), new BooleanValidator(), new IntegerValidator( 16, 4096 ), - network.IsSinglePlayer ? new BooleanValidator() : null, + network.IsSinglePlayer ? new BooleanValidator() : null, new BooleanValidator(), new BooleanValidator(), diff --git a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs index 8913c06cd..14d71e4c4 100644 --- a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs @@ -65,7 +65,7 @@ namespace ClassicalSharp.Gui { MakeClassic( 0, 50, "Save level", (g, w) => g.SetNewScreen( new SaveLevelScreen( g ) ) ), - MakeBack( true, titleFont, (g, w) => g.SetNewScreen( null ) ), + MakeBack( 401, "Back to game", 22, titleFont, (g, w) => g.SetNewScreen( null ) ), game.ClassicMode ? null : MakeClassic( 0, 150, "Nostalgia options", diff --git a/ClassicalSharp/2D/Utils/FastBitmap.cs b/ClassicalSharp/2D/Utils/FastBitmap.cs index 3abf75e62..cd55c77e6 100644 --- a/ClassicalSharp/2D/Utils/FastBitmap.cs +++ b/ClassicalSharp/2D/Utils/FastBitmap.cs @@ -88,7 +88,7 @@ namespace ClassicalSharp { Rectangle rec = new Rectangle( 0, 0, Bitmap.Width, Bitmap.Height ); data = Bitmap.LockBits( rec, ImageLockMode.ReadWrite, format ); Scan0 = data.Scan0; - scan0Byte = (byte*)Scan0; + scan0Byte = (byte*)Scan0; Stride = data.Stride; Width = data.Width; Height = data.Height;