From 1278b8276bd98ba4949f2c0abd11ddaa233463cc Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 19 Jan 2016 22:18:22 +1100 Subject: [PATCH] Create some descriptions for various options (not drawn yet), also reduce some code duplication. --- .../2D/Screens/Menu/EnvSettingsScreen.cs | 9 --- .../2D/Screens/Menu/GuiOptionsScreen.cs | 38 +++++------ .../2D/Screens/Menu/HacksSettingsScreen.cs | 65 +++++++++++-------- .../2D/Screens/Menu/MenuInputScreen.cs | 14 +++- ...{OptionsScreen.cs => MiscOptionsScreen.cs} | 43 ++++++++---- .../2D/Screens/Menu/NostalgiaScreen.cs | 9 --- ClassicalSharp/2D/Screens/Menu/PauseScreen.cs | 2 +- ClassicalSharp/2D/Widgets/ButtonWidget.cs | 2 - ClassicalSharp/ClassicalSharp.csproj | 2 +- 9 files changed, 100 insertions(+), 84 deletions(-) rename ClassicalSharp/2D/Screens/Menu/{OptionsScreen.cs => MiscOptionsScreen.cs} (69%) diff --git a/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs index 788600e72..4773b6d90 100644 --- a/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs @@ -87,15 +87,6 @@ namespace ClassicalSharp { }; } - ButtonWidget Make( int x, int y, string text,Action onClick, - Func getter, Action setter ) { - ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre, - Anchor.Centre, titleFont, onClick ); - widget.GetValue = getter; - widget.SetValue = setter; - return widget; - } - protected override void InputClosed() { if( buttons[defaultIndex] != null ) buttons[defaultIndex].Dispose(); diff --git a/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs index d78a7ed9a..066b777b4 100644 --- a/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs @@ -71,30 +71,11 @@ namespace ClassicalSharp { (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), null, }; - validators = new MenuInputValidator[] { - new BooleanValidator(), - new BooleanValidator(), - new RealValidator( 0.25f, 5f ), - new RealValidator( 0.25f, 5f ), - - new BooleanValidator(), - new BooleanValidator(), - new RealValidator( 0.25f, 5f ), - new IntegerValidator( 1, 30 ), - new BooleanValidator(), - }; + + MakeValidators(); okayIndex = buttons.Length - 1; } - ButtonWidget Make( int x, int y, string text, Action onClick, - Func getter, Action setter ) { - ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre, - Anchor.Centre, titleFont, onClick ); - widget.GetValue = getter; - widget.SetValue = setter; - return widget; - } - void HandleArialChatFont( Game g, string v ) { g.Drawer2D.UseBitmappedChat = v == "no"; Options.Set( OptionsKey.ArialChatFont, v == "yes" ); @@ -110,5 +91,20 @@ namespace ClassicalSharp { g.RefreshHud(); Recreate(); } + + void MakeValidators() { + validators = new MenuInputValidator[] { + new BooleanValidator(), + new BooleanValidator(), + new RealValidator( 0.25f, 5f ), + new RealValidator( 0.25f, 5f ), + + new BooleanValidator(), + new BooleanValidator(), + new RealValidator( 0.25f, 5f ), + new IntegerValidator( 1, 30 ), + new BooleanValidator(), + }; + } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs index d9c050216..fc4c67f5f 100644 --- a/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs @@ -68,6 +68,32 @@ namespace ClassicalSharp { null, }; + MakeValidators(); + MakeDescriptions(); + okayIndex = buttons.Length - 1; + game.Events.HackPermissionsChanged += CheckHacksAllowed; + CheckHacksAllowed( null, null ); + } + + void CheckHacksAllowed( object sender, EventArgs e ) { + for( int i = 0; i < buttons.Length; i++ ) { + if( buttons[i] == null ) continue; + buttons[i].Disabled = false; + } + + LocalPlayer p = game.LocalPlayer; + bool noGlobalHacks = !p.CanAnyHacks || !p.HacksEnabled; + buttons[3].Disabled = noGlobalHacks || !p.CanSpeed; + buttons[4].Disabled = noGlobalHacks || !p.CanSpeed; + buttons[6].Disabled = noGlobalHacks || !p.CanPushbackBlocks; + } + + public override void Dispose() { + base.Dispose(); + game.Events.HackPermissionsChanged -= CheckHacksAllowed; + } + + void MakeValidators() { validators = new MenuInputValidator[] { new BooleanValidator(), new RealValidator( 0.1f, 50 ), @@ -80,35 +106,20 @@ namespace ClassicalSharp { new BooleanValidator(), new IntegerValidator( 1, 150 ), }; - okayIndex = buttons.Length - 1; - game.Events.HackPermissionsChanged += CheckHacksAllowed; - CheckHacksAllowed( null, null ); } - void CheckHacksAllowed( object sender, EventArgs e ) { - for( int i = 0; i < buttons.Length; i++ ) { - if( buttons[i] == null ) continue; - buttons[i].Disabled = false; - } - LocalPlayer p = game.LocalPlayer; - bool noGlobalHacks = !p.CanAnyHacks || !p.HacksEnabled; - buttons[3].Disabled = noGlobalHacks || !p.CanSpeed; - buttons[4].Disabled = noGlobalHacks || !p.CanSpeed; - buttons[6].Disabled = noGlobalHacks || !p.CanPushbackBlocks; - } - - ButtonWidget Make( int x, int y, string text, Action onClick, - Func getter, Action setter ) { - ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre, - Anchor.Centre, titleFont, onClick ); - widget.GetValue = getter; - widget.SetValue = setter; - return widget; - } - - public override void Dispose() { - base.Dispose(); - game.Events.HackPermissionsChanged -= CheckHacksAllowed; + void MakeDescriptions() { + descriptions = new string[buttons.Length][]; + descriptions[5] = new [] { + "&fIf breaking liquids is set to true, then water/lava", + "&fcan be deleted the same way as any regular block.", + }; + descriptions[6] = new [] { + "&aDetermines whether pushback placing mode is active or not.", + "&fWhen this is active, placing blocks that intersect your own position", + "&f cause the block to be placed, and you to be moved out of the way.", + "&fThis is mainly useful for quick pillaring/towering.", + }; } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs b/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs index 806f9fe8f..23ff23ab8 100644 --- a/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs @@ -13,6 +13,7 @@ namespace ClassicalSharp { protected MenuInputValidator[] validators; protected TextWidget descWidget; protected int okayIndex; + protected string[][] descriptions; public override void Render( double delta ) { RenderMenuBounds(); @@ -45,7 +46,7 @@ namespace ClassicalSharp { ChangeSetting(); return true; } - if( inputWidget == null ) + if( inputWidget == null ) return key < Key.F1 || key > Key.F35; return inputWidget.HandlesKeyDown( key ); } @@ -124,7 +125,7 @@ namespace ClassicalSharp { inputWidget.Dispose(); targetWidget = selectedWidget; - inputWidget = MenuInputWidget.Create( game, 0, 150, 400, 25, button.GetValue( game ), Anchor.Centre, + inputWidget = MenuInputWidget.Create( game, 0, 150, 400, 25, button.GetValue( game ), Anchor.Centre, Anchor.Centre, regularFont, titleFont, validator ); buttons[okayIndex] = ButtonWidget.Create( game, 240, 150, 40, 30, "OK", Anchor.Centre, Anchor.Centre, titleFont, OnWidgetClick ); @@ -149,5 +150,14 @@ namespace ClassicalSharp { protected virtual void InputOpened() { } protected virtual void InputClosed() { } + + protected virtual ButtonWidget Make( int x, int y, string text, Action onClick, + Func getter, Action setter ) { + ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre, + Anchor.Centre, titleFont, onClick ); + widget.GetValue = getter; + widget.SetValue = setter; + return widget; + } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/MiscOptionsScreen.cs similarity index 69% rename from ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs rename to ClassicalSharp/2D/Screens/Menu/MiscOptionsScreen.cs index dbf4dbb5f..f7be6a1da 100644 --- a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/MiscOptionsScreen.cs @@ -4,9 +4,9 @@ using ClassicalSharp.Singleplayer; namespace ClassicalSharp { - public class OptionsScreen : MenuInputScreen { + public class MiscOptionsScreen : MenuInputScreen { - public OptionsScreen( Game game ) : base( game ) { + public MiscOptionsScreen( Game game ) : base( game ) { } public override void Init() { @@ -82,9 +82,15 @@ namespace ClassicalSharp { }; buttons[2].Metadata = typeof(NameMode); buttons[3].Metadata = typeof(FpsLimitMethod); - + MakeValidators(); + MakeDescriptions(); + okayIndex = buttons.Length - 1; + } + + void MakeValidators() { + INetworkProcessor network = game.Network; validators = new MenuInputValidator[] { - network.IsSinglePlayer ? new RealValidator(1, 1024) : null, + network.IsSinglePlayer ? new RealValidator( 1, 1024 ) : null, new BooleanValidator(), new EnumValidator(), new EnumValidator(), @@ -97,16 +103,29 @@ namespace ClassicalSharp { new BooleanValidator(), new IntegerValidator( 1, 100 ), }; - okayIndex = buttons.Length - 1; } - ButtonWidget Make( int x, int y, string text, Action onClick, - Func getter, Action setter ) { - ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre, - Anchor.Centre, titleFont, onClick ); - widget.GetValue = getter; - widget.SetValue = setter; - return widget; + void MakeDescriptions() { + descriptions = new string[buttons.Length][]; + descriptions[0] = new[] { + "&aControls how far away you can place/delete blocks.", + "&eThe default click distance is 5 blocks.", + }; + descriptions[2] = new[] { + "&aDetermines how the names of other players/entities are drawn.", + "&eNoNames: &fNo player names are drawn.", + "&eHoveredOnly: &fThe name of the player you are looking at is drawn without depth testing.", + "&eAllNames: &fAll names are drawn without depth testing.", + "&eAllNamesAndHovered: &fThe name of the player you are looking at is drawn without depth testing,", + "&f all other player names are drawn with depth testing.", + }; + descriptions[3] = new[] { + "&aDetermines the method used to limit the number of frames rendered each second.", + "&eVSync: &fNumber of frames rendered is equal to the refresh rate of the monitor.", + "&e30/60/120 FPS: &f30/60/120 frames are rendered at most each second.", + "&eNoLimit: &Renders as many frames as the GPU can handle each second.", + "&cUsing NoLimit mode is strongly discouraged for general usage.", + }; } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/NostalgiaScreen.cs b/ClassicalSharp/2D/Screens/Menu/NostalgiaScreen.cs index 121e46613..184cc9edc 100644 --- a/ClassicalSharp/2D/Screens/Menu/NostalgiaScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/NostalgiaScreen.cs @@ -81,14 +81,5 @@ namespace ClassicalSharp { base.Dispose(); infoWidget.Dispose(); } - - ButtonWidget Make( int x, int y, string text, Action onClick, - Func getter, Action setter ) { - ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre, - Anchor.Centre, titleFont, onClick ); - widget.GetValue = getter; - widget.SetValue = setter; - return widget; - } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs index 60c529ded..76f13d0d5 100644 --- a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs @@ -22,7 +22,7 @@ namespace ClassicalSharp { buttons = new ButtonWidget[] { // Column 1 Make( -140, -150, "Misc options", Anchor.Centre, - (g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ), + (g, w) => g.SetNewScreen( new MiscOptionsScreen( g ) ) ), Make( -140, -100, "Gui options", Anchor.Centre, (g, w) => g.SetNewScreen( new GuiOptionsScreen( g ) ) ), Make( -140, -50, "Hacks settings", Anchor.Centre, diff --git a/ClassicalSharp/2D/Widgets/ButtonWidget.cs b/ClassicalSharp/2D/Widgets/ButtonWidget.cs index 725b6e1a9..3bcf7a1c2 100644 --- a/ClassicalSharp/2D/Widgets/ButtonWidget.cs +++ b/ClassicalSharp/2D/Widgets/ButtonWidget.cs @@ -31,8 +31,6 @@ namespace ClassicalSharp { int defaultHeight; readonly Font font; - public string[] Description; - public override void Init() { DrawTextArgs args = new DrawTextArgs( "I", font, true ); defaultHeight = game.Drawer2D.MeasureSize( ref args ).Height; diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 5b46a490d..66e80394c 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -105,7 +105,7 @@ - +