Create some descriptions for various options (not drawn yet), also reduce some code duplication.

This commit is contained in:
UnknownShadow200 2016-01-19 22:18:22 +11:00
parent c39b58bbd0
commit 1278b8276b
9 changed files with 100 additions and 84 deletions

View File

@ -87,15 +87,6 @@ namespace ClassicalSharp {
};
}
ButtonWidget Make( int x, int y, string text,Action<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> 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();

View File

@ -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<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> 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(),
};
}
}
}

View File

@ -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<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> 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.",
};
}
}
}

View File

@ -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<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> 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;
}
}
}

View File

@ -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<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> 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.",
};
}
}
}

View File

@ -81,14 +81,5 @@ namespace ClassicalSharp {
base.Dispose();
infoWidget.Dispose();
}
ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> 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;
}
}
}

View File

@ -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,

View File

@ -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;

View File

@ -105,7 +105,7 @@
<Compile Include="2D\Screens\Menu\MenuScreen.cs" />
<Compile Include="2D\Screens\Menu\NostalgiaScreen.cs" />
<Compile Include="2D\Screens\Menu\PauseScreen.cs" />
<Compile Include="2D\Screens\Menu\OptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\MiscOptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\SaveLevelScreen.cs" />
<Compile Include="2D\Screens\Menu\TexturePackScreen.cs" />
<Compile Include="2D\Screens\HudScreen.cs" />