redesign menu options, all menu options with input now have a default value

This commit is contained in:
UnknownShadow200 2018-04-16 16:14:29 +10:00
parent 28f4bb3e97
commit 41a8f97a88
8 changed files with 215 additions and 303 deletions

View File

@ -15,7 +15,10 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() { public override void Init() {
base.Init(); base.Init();
ContextRecreated(); ContextRecreated();
MakeValidators();
validators = new MenuInputValidator[widgets.Length];
validators[2] = new EnumValidator(typeof(ViewDist));
validators[7] = new EnumValidator(typeof(FpsLimitMethod));
} }
protected override void ContextRecreated() { protected override void ContextRecreated() {
@ -38,7 +41,6 @@ namespace ClassicalSharp.Gui.Screens {
ButtonWidget.Create(game, 400, "Controls...", titleFont, SwitchClassic) ButtonWidget.Create(game, 400, "Controls...", titleFont, SwitchClassic)
.SetLocation(Anchor.Centre, Anchor.Max, 0, 95), .SetLocation(Anchor.Centre, Anchor.Max, 0, 95),
MakeBack(400, "Done", 25, titleFont, SwitchPause), MakeBack(400, "Done", 25, titleFont, SwitchPause),
null, null,
}; };
} }
@ -90,21 +92,5 @@ namespace ClassicalSharp.Gui.Screens {
} }
static void SwitchClassic(Game g, Widget w) { g.Gui.SetNewScreen(new ClassicKeyBindingsScreen(g)); } static void SwitchClassic(Game g, Widget w) { g.Gui.SetNewScreen(new ClassicKeyBindingsScreen(g)); }
void MakeValidators() {
IServerConnection network = game.Server;
validators = new MenuInputValidator[] {
null,
null,
new EnumValidator(typeof(ViewDist)),
null,
null,
null,
null,
new EnumValidator(typeof(FpsLimitMethod)),
null,
};
}
} }
} }

View File

@ -7,19 +7,38 @@ using ClassicalSharp.Renderers;
using OpenTK.Input; using OpenTK.Input;
namespace ClassicalSharp.Gui.Screens { namespace ClassicalSharp.Gui.Screens {
public class EnvSettingsScreen : MenuOptionsScreen { public class EnvSettingsScreen : ExtMenuOptionsScreen {
public EnvSettingsScreen(Game game) : base(game) { public EnvSettingsScreen(Game game) : base(game) {
} }
string[] defaultValues;
int defaultIndex;
public override void Init() { public override void Init() {
base.Init(); base.Init();
ContextRecreated(); ContextRecreated();
MakeDefaultValues(); validators = new MenuInputValidator[widgets.Length];
MakeValidators(); defaultValues = new string[widgets.Length];
validators = new MenuInputValidator[widgets.Length];
validators[0] = new HexColourValidator();
defaultValues[0] = WorldEnv.DefaultCloudsColour.ToRGBHexString();
validators[1] = new HexColourValidator();
defaultValues[1] = WorldEnv.DefaultSkyColour.ToRGBHexString();
validators[2] = new HexColourValidator();
defaultValues[2] = WorldEnv.DefaultFogColour.ToRGBHexString();
validators[3] = new RealValidator(0, 1000);
defaultValues[3] = "1";
validators[4] = new IntegerValidator(-10000, 10000);
defaultValues[4] = (game.World.Height + 2).ToString();
validators[5] = new HexColourValidator();
defaultValues[5] = WorldEnv.DefaultSunlight.ToRGBHexString();
validators[6] = new HexColourValidator();
defaultValues[6] = WorldEnv.DefaultShadowlight.ToRGBHexString();
validators[7] = new EnumValidator(typeof(Weather));
validators[8] = new RealValidator(-100, 100);
defaultValues[8] = "1";
validators[9] = new IntegerValidator(-2048, 2048);
defaultValues[9] = (game.World.Height / 2).ToString();
} }
protected override void ContextRecreated() { protected override void ContextRecreated() {
@ -73,58 +92,5 @@ namespace ClassicalSharp.Gui.Screens {
static string GetEdgeHeight(Game g) { return g.World.Env.EdgeHeight.ToString(); } static string GetEdgeHeight(Game g) { return g.World.Env.EdgeHeight.ToString(); }
static void SetEdgeHeight(Game g, string v) { g.World.Env.SetEdgeLevel(Int32.Parse(v)); } static void SetEdgeHeight(Game g, string v) { g.World.Env.SetEdgeLevel(Int32.Parse(v)); }
void MakeDefaultValues() {
defaultIndex = widgets.Length - 3;
defaultValues = new string[] {
WorldEnv.DefaultCloudsColour.ToRGBHexString(),
WorldEnv.DefaultSkyColour.ToRGBHexString(),
WorldEnv.DefaultFogColour.ToRGBHexString(),
(1).ToString(),
(game.World.Height + 2).ToString(),
WorldEnv.DefaultSunlight.ToRGBHexString(),
WorldEnv.DefaultShadowlight.ToRGBHexString(),
null,
(1).ToString(),
(game.World.Height / 2).ToString(),
};
}
void MakeValidators() {
validators = new MenuInputValidator[] {
new HexColourValidator(),
new HexColourValidator(),
new HexColourValidator(),
new RealValidator(0, 1000),
new IntegerValidator(-10000, 10000),
new HexColourValidator(),
new HexColourValidator(),
new EnumValidator(typeof(Weather)),
new RealValidator(-100, 100),
new IntegerValidator(-2048, 2048),
};
}
protected override void InputClosed() {
base.InputClosed();
if (widgets[defaultIndex] != null)
widgets[defaultIndex].Dispose();
widgets[defaultIndex] = null;
}
protected override void InputOpened() {
widgets[defaultIndex] = ButtonWidget.Create(game, 200, "Default value", titleFont, DefaultButtonClick)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 150);
}
void DefaultButtonClick(Game game, Widget widget) {
int index = IndexOfWidget(activeButton);
string defValue = defaultValues[index];
input.Clear();
input.Append(defValue);
}
} }
} }

View File

@ -6,7 +6,7 @@ using ClassicalSharp.Gui.Widgets;
using ClassicalSharp.Textures; using ClassicalSharp.Textures;
namespace ClassicalSharp.Gui.Screens { namespace ClassicalSharp.Gui.Screens {
public class GraphicsOptionsScreen : MenuOptionsScreen { public class GraphicsOptionsScreen : ExtMenuOptionsScreen {
public GraphicsOptionsScreen(Game game) : base(game) { public GraphicsOptionsScreen(Game game) : base(game) {
} }
@ -14,7 +14,14 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() { public override void Init() {
base.Init(); base.Init();
ContextRecreated(); ContextRecreated();
MakeValidators();
validators = new MenuInputValidator[widgets.Length];
defaultValues = new string[widgets.Length];
validators[0] = new EnumValidator(typeof(FpsLimitMethod));
validators[1] = new IntegerValidator(8, 4096);
defaultValues[1] = "512";
validators[3] = new EnumValidator(typeof(NameMode));
validators[4] = new EnumValidator(typeof(EntityShadow));
MakeDescriptions(); MakeDescriptions();
} }
@ -33,7 +40,7 @@ namespace ClassicalSharp.Gui.Screens {
MakeOpt(1, 50, "Mipmaps", onBool, GetMipmaps, SetMipmaps), MakeOpt(1, 50, "Mipmaps", onBool, GetMipmaps, SetMipmaps),
MakeBack(false, titleFont, SwitchOptions), MakeBack(false, titleFont, SwitchOptions),
null, null, null, null, null,
}; };
} }
@ -85,18 +92,6 @@ namespace ClassicalSharp.Gui.Screens {
} }
} }
void MakeValidators() {
validators = new MenuInputValidator[] {
new EnumValidator(typeof(FpsLimitMethod)),
new IntegerValidator(8, 4096),
null,
new EnumValidator(typeof(NameMode)),
new EnumValidator(typeof(EntityShadow)),
null,
};
}
void MakeDescriptions() { void MakeDescriptions() {
descriptions = new string[widgets.Length][]; descriptions = new string[widgets.Length][];
descriptions[0] = new string[] { descriptions[0] = new string[] {

View File

@ -3,7 +3,7 @@ using System;
using ClassicalSharp.Gui.Widgets; using ClassicalSharp.Gui.Widgets;
namespace ClassicalSharp.Gui.Screens { namespace ClassicalSharp.Gui.Screens {
public class GuiOptionsScreen : MenuOptionsScreen { public class GuiOptionsScreen : ExtMenuOptionsScreen {
public GuiOptionsScreen(Game game) : base(game) { public GuiOptionsScreen(Game game) : base(game) {
} }
@ -11,7 +11,19 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() { public override void Init() {
base.Init(); base.Init();
ContextRecreated(); ContextRecreated();
MakeValidators(); validators = new MenuInputValidator[widgets.Length];
defaultValues = new string[widgets.Length];
validators[2] = new RealValidator(0.25f, 4f);
defaultValues[2] = "1";
validators[3] = new RealValidator(0.25f, 4f);
defaultValues[3] = "1";
validators[6] = new RealValidator(0.25f, 4f);
defaultValues[6] = "1";
validators[7] = new IntegerValidator(0, 30);
defaultValues[7] = "10";
validators[9] = new StringValidator();
defaultValues[9] = "Arial";
} }
protected override void ContextRecreated() { protected override void ContextRecreated() {
@ -32,7 +44,7 @@ namespace ClassicalSharp.Gui.Screens {
MakeOpt(1, 50, "Font", onClick, GetFont, SetFont), MakeOpt(1, 50, "Font", onClick, GetFont, SetFont),
MakeBack(false, titleFont, SwitchOptions), MakeBack(false, titleFont, SwitchOptions),
null, null, null, null, null,
}; };
} }
@ -93,21 +105,5 @@ namespace ClassicalSharp.Gui.Screens {
selectedI = -1; selectedI = -1;
HandlesMouseMove(game.Mouse.X, game.Mouse.Y); HandlesMouseMove(game.Mouse.X, game.Mouse.Y);
} }
void MakeValidators() {
validators = new MenuInputValidator[] {
null,
null,
new RealValidator(0.25f, 4f),
new RealValidator(0.25f, 4f),
null,
null,
new RealValidator(0.25f, 4f),
new IntegerValidator(0, 30),
null,
new StringValidator(),
};
}
} }
} }

View File

@ -7,22 +7,44 @@ using ClassicalSharp.Singleplayer;
using OpenTK.Input; using OpenTK.Input;
namespace ClassicalSharp.Gui.Screens { namespace ClassicalSharp.Gui.Screens {
public class HacksSettingsScreen : MenuOptionsScreen { public class HacksSettingsScreen : ExtMenuOptionsScreen {
public HacksSettingsScreen(Game game) : base(game) { public HacksSettingsScreen(Game game) : base(game) {
} }
string[] defaultValues;
int defaultIndex;
public override void Init() { public override void Init() {
base.Init(); base.Init();
ContextRecreated(); ContextRecreated();
MakeDefaultValues();
MakeValidators();
MakeDescriptions();
game.Events.HackPermissionsChanged += CheckHacksAllowed; game.Events.HackPermissionsChanged += CheckHacksAllowed;
MakeDescriptions();
validators = new MenuInputValidator[widgets.Length];
defaultValues = new string[widgets.Length];
validators[1] = new RealValidator(0.1f, 50);
defaultValues[1] = "10";
validators[3] = new RealValidator(0.1f, 2048f);
defaultValues[3] = (1.233f).ToString();
validators[9] = new IntegerValidator(1, 150);
defaultValues[9] = "70";
}
public override void Dispose() {
base.Dispose();
game.Events.HackPermissionsChanged -= CheckHacksAllowed;
}
void CheckHacksAllowed(object sender, EventArgs e) {
for (int i = 0; i < widgets.Length; i++) {
if (widgets[i] == null) continue;
widgets[i].Disabled = false;
}
LocalPlayer p = game.LocalPlayer;
bool noGlobalHacks = !p.Hacks.CanAnyHacks || !p.Hacks.Enabled;
widgets[3].Disabled = noGlobalHacks || !p.Hacks.CanSpeed;
widgets[4].Disabled = noGlobalHacks || !p.Hacks.CanSpeed;
widgets[5].Disabled = noGlobalHacks || !p.Hacks.CanSpeed;
widgets[7].Disabled = noGlobalHacks || !p.Hacks.CanPushbackBlocks;
} }
protected override void ContextRecreated() { protected override void ContextRecreated() {
@ -42,9 +64,8 @@ namespace ClassicalSharp.Gui.Screens {
MakeOpt(1, 0, "Noclip slide", onBool, GetSlide, SetSlide), MakeOpt(1, 0, "Noclip slide", onBool, GetSlide, SetSlide),
MakeOpt(1, 50, "Field of view", onClick, GetFOV, SetFOV), MakeOpt(1, 50, "Field of view", onClick, GetFOV, SetFOV),
null,
MakeBack(false, titleFont, SwitchOptions), MakeBack(false, titleFont, SwitchOptions),
null, null, null, null, null,
}; };
CheckHacksAllowed(null, null); CheckHacksAllowed(null, null);
} }
@ -107,92 +128,30 @@ namespace ClassicalSharp.Gui.Screens {
g.UpdateProjection(); g.UpdateProjection();
} }
void CheckHacksAllowed(object sender, EventArgs e) {
for (int i = 0; i < widgets.Length; i++) {
if (widgets[i] == null) continue;
widgets[i].Disabled = false;
}
LocalPlayer p = game.LocalPlayer;
bool noGlobalHacks = !p.Hacks.CanAnyHacks || !p.Hacks.Enabled;
widgets[3].Disabled = noGlobalHacks || !p.Hacks.CanSpeed;
widgets[4].Disabled = noGlobalHacks || !p.Hacks.CanSpeed;
widgets[5].Disabled = noGlobalHacks || !p.Hacks.CanSpeed;
widgets[7].Disabled = noGlobalHacks || !p.Hacks.CanPushbackBlocks;
}
public override void Dispose() {
base.Dispose();
game.Events.HackPermissionsChanged -= CheckHacksAllowed;
}
void MakeDefaultValues() {
defaultIndex = widgets.Length - 4;
defaultValues = new string[widgets.Length];
defaultValues[1] = "10";
defaultValues[3] = (1.233f).ToString();
defaultValues[9] = "70";
}
void MakeValidators() {
validators = new MenuInputValidator[] {
null,
new RealValidator(0.1f, 50),
null,
new RealValidator(0.1f, 2048f),
null,
null,
null,
null,
null,
new IntegerValidator(1, 150),
};
}
void MakeDescriptions() { void MakeDescriptions() {
descriptions = new string[widgets.Length][]; string[][] descs = new string[widgets.Length][];
descriptions[2] = new string[] { descs[2] = new string[] {
"&eIf &fON&e, then the third person cameras will limit", "&eIf &fON&e, then the third person cameras will limit",
"&etheir zoom distance if they hit a solid block.", "&etheir zoom distance if they hit a solid block.",
}; };
descriptions[3] = new string[] { descs[3] = new string[] {
"&eSets how many blocks high you can jump up.", "&eSets how many blocks high you can jump up.",
"&eNote: You jump much higher when holding down the Speed key binding.", "&eNote: You jump much higher when holding down the Speed key binding.",
}; };
descriptions[6] = new string[] { descs[6] = new string[] {
"&eIf &fON&e, then water/lava can be placed and", "&eIf &fON&e, then water/lava can be placed and",
"&edeleted the same way as any other block.", "&edeleted the same way as any other block.",
}; };
descriptions[7] = new string[] { descs[7] = new string[] {
"&eIf &fON&e, placing blocks that intersect your own position cause", "&eIf &fON&e, placing blocks that intersect your own position cause",
"&ethe block to be placed, and you to be moved out of the way.", "&ethe block to be placed, and you to be moved out of the way.",
"&fThis is mainly useful for quick pillaring/towering.", "&fThis is mainly useful for quick pillaring/towering.",
}; };
descriptions[8] = new string[] { descs[8] = new string[] {
"&eIf &fOFF&e, you will immediately stop when in noclip", "&eIf &fOFF&e, you will immediately stop when in noclip",
"&emode and no movement keys are held down.", "&emode and no movement keys are held down.",
}; };
} descriptions = descs;
protected override void InputClosed() {
base.InputClosed();
if (widgets[defaultIndex] != null)
widgets[defaultIndex].Dispose();
widgets[defaultIndex] = null;
}
protected override void InputOpened() {
widgets[defaultIndex] = ButtonWidget.Create(game, 200, "Default value", titleFont, DefaultButtonClick)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 150);
}
void DefaultButtonClick(Game game, Widget widget) {
int index = IndexOfWidget(activeButton);
string defValue = defaultValues[index];
input.Clear();
input.Append(defValue);
} }
} }
} }

View File

@ -10,7 +10,6 @@ namespace ClassicalSharp.Gui.Screens {
public MenuOptionsScreen(Game game) : base(game) { public MenuOptionsScreen(Game game) : base(game) {
} }
protected InputWidget input;
protected MenuInputValidator[] validators; protected MenuInputValidator[] validators;
protected string[][] descriptions; protected string[][] descriptions;
protected TextGroupWidget extendedHelp; protected TextGroupWidget extendedHelp;
@ -33,31 +32,6 @@ namespace ClassicalSharp.Gui.Screens {
game.Graphics.Texturing = false; game.Graphics.Texturing = false;
} }
public override void Init() {
base.Init();
game.Keyboard.KeyRepeat = true;
}
public override bool HandlesKeyPress(char key) {
if (input == null) return true;
return input.HandlesKeyPress(key);
}
public override bool HandlesKeyDown(Key key) {
if (input != null) {
if (input.HandlesKeyDown(key)) return true;
if (key == Key.Enter || key == Key.KeypadEnter) {
ChangeSetting(); return true;
}
}
return base.HandlesKeyDown(key);
}
public override bool HandlesKeyUp(Key key) {
if (input == null) return true;
return input.HandlesKeyUp(key);
}
public override void OnResize(int width, int height) { public override void OnResize(int width, int height) {
base.OnResize(width, height); base.OnResize(width, height);
if (extendedHelp == null) return; if (extendedHelp == null) return;
@ -69,15 +43,9 @@ namespace ClassicalSharp.Gui.Screens {
protected override void ContextLost() { protected override void ContextLost() {
base.ContextLost(); base.ContextLost();
InputClosed();
DisposeExtendedHelp(); DisposeExtendedHelp();
} }
public override void Dispose() {
game.Keyboard.KeyRepeat = false;
base.Dispose();
}
protected ButtonWidget activeButton; protected ButtonWidget activeButton;
protected int selectedI = -1; protected int selectedI = -1;
@ -100,18 +68,6 @@ namespace ClassicalSharp.Gui.Screens {
ShowExtendedHelp(); ShowExtendedHelp();
} }
protected virtual void InputOpened() { }
protected virtual void InputClosed() {
if (input != null) input.Dispose();
widgets[widgets.Length - 2] = null;
input = null;
int okIndex = widgets.Length - 1;
if (widgets[okIndex] != null) widgets[okIndex].Dispose();
widgets[okIndex] = null;
}
protected ButtonWidget MakeOpt(int dir, int y, string optName, ClickHandler onClick, protected ButtonWidget MakeOpt(int dir, int y, string optName, ClickHandler onClick,
ButtonValueGetter getter, ButtonValueSetter setter) { ButtonValueGetter getter, ButtonValueSetter setter) {
ButtonWidget btn = ButtonWidget.Create(game, 300, optName + ": " + getter(game), titleFont, onClick) ButtonWidget btn = ButtonWidget.Create(game, 300, optName + ": " + getter(game), titleFont, onClick)
@ -128,9 +84,8 @@ namespace ClassicalSharp.Gui.Screens {
return v == "ON"; return v == "ON";
} }
void ShowExtendedHelp() { protected virtual void ShowExtendedHelp() {
if (input != null || descriptions == null) return; if (descriptions == null || selectedI < 0 || selectedI >= descriptions.Length) return;
if (selectedI < 0 || selectedI >= descriptions.Length) return;
string[] desc = descriptions[selectedI]; string[] desc = descriptions[selectedI];
if (desc == null) return; if (desc == null) return;
@ -152,16 +107,12 @@ namespace ClassicalSharp.Gui.Screens {
extendedHelp.Reposition(); extendedHelp.Reposition();
} }
void DisposeExtendedHelp() { protected void DisposeExtendedHelp() {
if (extendedHelp == null) return; if (extendedHelp == null) return;
extendedHelp.Dispose(); extendedHelp.Dispose();
extendedHelp = null; extendedHelp = null;
} }
void OnOKButtonClick(Game game, Widget widget) {
ChangeSetting();
}
protected void OnBoolClick(Game game, Widget widget) { protected void OnBoolClick(Game game, Widget widget) {
ButtonWidget button = (ButtonWidget)widget; ButtonWidget button = (ButtonWidget)widget;
DisposeExtendedHelp(); DisposeExtendedHelp();
@ -178,34 +129,9 @@ namespace ClassicalSharp.Gui.Screens {
int index = IndexOfWidget(button); int index = IndexOfWidget(button);
MenuInputValidator validator = validators[index]; MenuInputValidator validator = validators[index];
Type type = ((EnumValidator)validator).EnumType; Type type = ((EnumValidator)validator).EnumType;
HandleEnumOption(button, type);
}
protected void OnButtonClick(Game game, Widget widget) {
ButtonWidget button = (ButtonWidget)widget;
DisposeExtendedHelp();
int index = IndexOfWidget(button);
MenuInputValidator validator = validators[index];
activeButton = button;
InputClosed();
input = MenuInputWidget.Create(game, 400, 30, button.GetValue(game), textFont, validator)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 110);
input.ShowCaret = true;
widgets[widgets.Length - 2] = input;
widgets[widgets.Length - 1] = ButtonWidget.Create(game, 40, "OK", titleFont, OnOKButtonClick)
.SetLocation(Anchor.Centre, Anchor.Centre, 240, 110);
InputOpened();
UpdateDescription(activeButton);
}
void HandleEnumOption(ButtonWidget button, Type type) {
string rawName = button.GetValue(game); string rawName = button.GetValue(game);
int value = (int)Enum.Parse(type, rawName, true); int value = (int)Enum.Parse(type, rawName, true) + 1;
value++;
// go back to first value // go back to first value
if (!Enum.IsDefined(type, value)) value = 0; if (!Enum.IsDefined(type, value)) value = 0;
@ -213,18 +139,7 @@ namespace ClassicalSharp.Gui.Screens {
UpdateDescription(button); UpdateDescription(button);
} }
void ChangeSetting() { protected void SetButtonValue(ButtonWidget btn, string text) {
string text = input.Text.ToString();
if (((MenuInputWidget)input).Validator.IsValidValue(text)) {
SetButtonValue(activeButton, text);
}
UpdateDescription(activeButton);
activeButton = null;
InputClosed();
}
void SetButtonValue(ButtonWidget btn, string text) {
btn.SetValue(game, text); btn.SetValue(game, text);
int index = IndexOfWidget(btn); int index = IndexOfWidget(btn);
// e.g. changing FPS invalidates all widgets // e.g. changing FPS invalidates all widgets
@ -238,4 +153,105 @@ namespace ClassicalSharp.Gui.Screens {
Options.Set(OptionsKey.FpsLimit, v); Options.Set(OptionsKey.FpsLimit, v);
} }
} }
public abstract class ExtMenuOptionsScreen : MenuOptionsScreen {
public ExtMenuOptionsScreen(Game game) : base(game) {
}
protected InputWidget input;
protected string[] defaultValues;
public override void Init() {
base.Init();
game.Keyboard.KeyRepeat = true;
}
public override bool HandlesKeyPress(char key) {
if (input == null) return true;
return input.HandlesKeyPress(key);
}
public override bool HandlesKeyDown(Key key) {
if (input != null) {
if (input.HandlesKeyDown(key)) return true;
if (key == Key.Enter || key == Key.KeypadEnter) {
EnterInput(); return true;
}
}
return base.HandlesKeyDown(key);
}
public override bool HandlesKeyUp(Key key) {
if (input == null) return true;
return input.HandlesKeyUp(key);
}
protected override void ContextLost() {
base.ContextLost();
input = null;
}
public override void Dispose() {
game.Keyboard.KeyRepeat = false;
base.Dispose();
}
protected void DisposeInput() {
if (input == null) return;
input = null;
for (int i = widgets.Length - 3; i < widgets.Length; i++) {
widgets[i].Dispose();
widgets[i] = null;
}
}
void OnOKButtonClick(Game game, Widget widget) { EnterInput(); }
protected void OnButtonClick(Game game, Widget widget) {
ButtonWidget button = (ButtonWidget)widget;
DisposeExtendedHelp();
int index = IndexOfWidget(button);
MenuInputValidator validator = validators[index];
activeButton = button;
DisposeInput();
input = MenuInputWidget.Create(game, 400, 30, button.GetValue(game), textFont, validator)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 110);
input.ShowCaret = true;
widgets[widgets.Length - 2] = input;
widgets[widgets.Length - 1] = ButtonWidget.Create(game, 40, "OK", titleFont, OnOKButtonClick)
.SetLocation(Anchor.Centre, Anchor.Centre, 240, 110);
widgets[widgets.Length - 3] = ButtonWidget.Create(game, 200, "Default value", titleFont, DefaultButtonClick)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 150);
UpdateDescription(activeButton);
}
void DefaultButtonClick(Game game, Widget widget) {
int index = IndexOfWidget(activeButton);
string defValue = defaultValues[index];
input.Clear();
input.Append(defValue);
}
void EnterInput() {
string text = input.Text.ToString();
if (((MenuInputWidget)input).Validator.IsValidValue(text)) {
SetButtonValue(activeButton, text);
}
UpdateDescription(activeButton);
activeButton = null;
DisposeInput();
}
protected override void ShowExtendedHelp() {
if (input == null) base.ShowExtendedHelp();
}
}
} }

View File

@ -5,7 +5,7 @@ using ClassicalSharp.Gui.Widgets;
using ClassicalSharp.Singleplayer; using ClassicalSharp.Singleplayer;
namespace ClassicalSharp.Gui.Screens { namespace ClassicalSharp.Gui.Screens {
public class MiscOptionsScreen : MenuOptionsScreen { public class MiscOptionsScreen : ExtMenuOptionsScreen {
public MiscOptionsScreen(Game game) : base(game) { public MiscOptionsScreen(Game game) : base(game) {
} }
@ -13,7 +13,17 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() { public override void Init() {
base.Init(); base.Init();
ContextRecreated(); ContextRecreated();
MakeValidators(); validators = new MenuInputValidator[widgets.Length];
defaultValues = new string[widgets.Length];
validators[0] = new RealValidator(1, 1024);
defaultValues[0] = "5";
validators[1] = new IntegerValidator(0, 100);
defaultValues[1] = "0";
validators[2] = new IntegerValidator(0, 100);
defaultValues[2] = "0";
validators[7] = new IntegerValidator(1, 200);
defaultValues[7] = "30";
} }
protected override void ContextRecreated() { protected override void ContextRecreated() {
@ -33,7 +43,7 @@ namespace ClassicalSharp.Gui.Screens {
MakeOpt(1, 50, "Mouse sensitivity", onClick, GetSensitivity, SetSensitivity), MakeOpt(1, 50, "Mouse sensitivity", onClick, GetSensitivity, SetSensitivity),
MakeBack(false, titleFont, SwitchOptions), MakeBack(false, titleFont, SwitchOptions),
null, null, null, null, null,
}; };
} }
@ -73,20 +83,5 @@ namespace ClassicalSharp.Gui.Screens {
g.MouseSensitivity = Int32.Parse(v); g.MouseSensitivity = Int32.Parse(v);
Options.Set(OptionsKey.Sensitivity, v); Options.Set(OptionsKey.Sensitivity, v);
} }
void MakeValidators() {
IServerConnection network = game.Server;
validators = new MenuInputValidator[] {
network.IsSinglePlayer ? new RealValidator(1, 1024) : null,
new IntegerValidator(0, 100),
new IntegerValidator(0, 100),
null,
null,
null,
null,
new IntegerValidator(1, 200),
};
}
} }
} }

View File

@ -32,7 +32,6 @@ namespace ClassicalSharp.Gui.Screens {
TextWidget.Create(game, "&eButtons on the right require restarting game", textFont) TextWidget.Create(game, "&eButtons on the right require restarting game", textFont)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 100), .SetLocation(Anchor.Centre, Anchor.Centre, 0, 100),
MakeBack(false, titleFont, SwitchBack), MakeBack(false, titleFont, SwitchBack),
null, null,
}; };
} }