Only 6 lambdas left to remove

This commit is contained in:
UnknownShadow200 2017-09-15 14:05:53 +10:00
parent 4413fc69e6
commit 7303e8c2e4
8 changed files with 54 additions and 57 deletions

View File

@ -43,48 +43,48 @@ namespace ClassicalSharp.Gui.Screens {
btn.SetValue = SetFPSLimitMethod;
}
static bool GetMusic(Game g) { return g.MusicVolume > 0; }
static string GetMusic(Game g) { return GetBool(g.MusicVolume > 0); }
static void SetMusic(Game g, bool v) { g.MusicVolume = v ? 100 : 0; g.AudioPlayer.SetMusic(g.MusicVolume); }
static bool GetInvert(Game g) { return g.InvertMouse; }
static string GetInvert(Game g) { return GetBool(g.InvertMouse); }
static void SetInvert(Game g, bool v) { g.InvertMouse = v; }
static string GetViewDist(Game g) { return g.ViewDistance.ToString(); }
static void SetViewDist(Game g, string v) { g.SetViewDistance(Int32.Parse(v), true); }
static bool GetPhysics(Game g) { return ((SinglePlayerServer)g.Server).physics.Enabled; }
static string GetPhysics(Game g) { return GetBool(((SinglePlayerServer)g.Server).physics.Enabled); }
static void SetPhysics(Game g, bool v) { ((SinglePlayerServer)g.Server).physics.Enabled = v; }
static bool GetSounds(Game g) { return g.SoundsVolume > 0; }
static string GetSounds(Game g) { return GetBool(g.SoundsVolume > 0); }
static void SetSounds(Game g, bool v) { g.SoundsVolume = v ? 100 : 0; g.AudioPlayer.SetSounds(g.SoundsVolume); }
static bool GetShowFPS(Game g) { return g.ShowFPS; }
static string GetShowFPS(Game g) { return GetBool(g.ShowFPS); }
static void SetShowFPS(Game g, bool v) { g.ShowFPS = v; }
static bool GetViewBob(Game g) { return g.ViewBobbing; }
static string GetViewBob(Game g) { return GetBool(g.ViewBobbing); }
static void SetViewBob(Game g, bool v) { g.ViewBobbing = v; }
static string GetFPS(Game g) { return g.FpsLimit.ToString(); }
static void SetFPS(Game g, string v) { }
static bool GetHacks(Game g) { return g.LocalPlayer.Hacks.Enabled; }
static string GetHacks(Game g) { return GetBool(g.LocalPlayer.Hacks.Enabled); }
static void SetHacks(Game g, bool v) { g.LocalPlayer.Hacks.Enabled = v; g.LocalPlayer.CheckHacksConsistency(); }
static void SwitchClassic(Game g, Widget w) { g.Gui.SetNewScreen(new ClassicKeyBindingsScreen(g)); }
ButtonWidget MakeVolumeBool(int dir, int y, string text, string optKey,
ButtonBoolGetter getter, ButtonBoolSetter setter) {
ButtonValueGetter getter, ButtonBoolSetter setter) {
string optName = text;
text = text + ": " + (getter(game) ? "ON" : "OFF");
text = text + ": " + getter;
ButtonWidget widget = ButtonWidget.Create(game, 300, text, titleFont, OnWidgetClick)
.SetLocation(Anchor.Centre, Anchor.Centre, 160 * dir, y);
widget.OptName = optName;
widget.GetValue = g => getter(g) ? "yes" : "no";
widget.GetValue = getter;
widget.SetValue = (g, v) => {
setter(g, v == "yes");
Options.Set(optKey, v == "yes" ? 100 : 0);
widget.SetText(widget.OptName + ": " + (v == "yes" ? "ON" : "OFF"));
setter(g, v == "ON");
Options.Set(optKey, v == "ON" ? 100 : 0);
widget.SetText(widget.OptName + ": " + v);
};
return widget;
}

View File

@ -71,7 +71,7 @@ namespace ClassicalSharp.Gui.Screens {
protected override void ContextRecreated() {
string flags = HotkeyListScreen.MakeFlagsString(curHotkey.Flags);
if (curHotkey.Text == null) curHotkey.Text = "";
string staysOpen = curHotkey.StaysOpen ? "yes" : "no";
string staysOpen = curHotkey.StaysOpen ? "ON" : "OFF";
bool existed = origHotkey.BaseKey != Key.Unknown;
widgets = new Widget[] {
@ -111,7 +111,7 @@ namespace ClassicalSharp.Gui.Screens {
void LeaveOpenClick(Game game, Widget widget) {
LostFocus();
curHotkey.StaysOpen = !curHotkey.StaysOpen;
string staysOpen = curHotkey.StaysOpen ? "yes" : "no";
string staysOpen = curHotkey.StaysOpen ? "ON" : "OFF";
staysOpen = "Input stays open: " + staysOpen;
SetButton(widgets[3], staysOpen);
}

View File

@ -46,7 +46,7 @@ namespace ClassicalSharp.Gui.Screens {
static string GetViewDist(Game g) { return g.ViewDistance.ToString(); }
static void SetViewDist(Game g, string v) { g.SetViewDistance(Int32.Parse(v), true); }
static bool GetSmooth(Game g) { return g.SmoothLighting; }
static string GetSmooth(Game g) { return GetBool(g.SmoothLighting); }
static void SetSmooth(Game g, bool v) {
g.SmoothLighting = v;
ChunkMeshBuilder builder = g.MapRenderer.DefaultMeshBuilder();
@ -68,7 +68,7 @@ namespace ClassicalSharp.Gui.Screens {
Options.Set(OptionsKey.EntityShadow, v);
}
static bool GetMipmaps(Game g) { return g.Graphics.Mipmaps; }
static string GetMipmaps(Game g) { return GetBool(g.Graphics.Mipmaps); }
static void SetMipmaps(Game g, bool v) {
g.Graphics.Mipmaps = v;

View File

@ -35,10 +35,10 @@ namespace ClassicalSharp.Gui.Screens {
};
}
static bool GetShadows(Game g) { return g.Drawer2D.BlackTextShadows; }
static string GetShadows(Game g) { return GetBool(g.Drawer2D.BlackTextShadows); }
void SetShadows(Game g, bool v) { g.Drawer2D.BlackTextShadows = v; HandleFontChange(); }
static bool GetShowFPS(Game g) { return g.ShowFPS; }
static string GetShowFPS(Game g) { return GetBool(g.ShowFPS); }
static void SetShowFPS(Game g, bool v) { g.ShowFPS = v; }
static void SetScale(Game g, string v, ref float target, string optKey) {
@ -53,10 +53,10 @@ namespace ClassicalSharp.Gui.Screens {
static string GetInventory(Game g) { return g.InventoryScale.ToString("F1"); }
static void SetInventory(Game g, string v) { SetScale(g, v, ref g.InventoryScale, OptionsKey.InventoryScale); }
static bool GetTabAuto(Game g) { return g.TabAutocomplete; }
static string GetTabAuto(Game g) { return GetBool(g.TabAutocomplete); }
void SetTabAuto(Game g, bool v) { g.TabAutocomplete = v; }
static bool GetClickable(Game g) { return g.ClickableChat; }
static string GetClickable(Game g) { return GetBool(g.ClickableChat); }
void SetClickable(Game g, bool v) { g.ClickableChat = v; }
static string GetChatScale(Game g) { return g.ChatScale.ToString("F1"); }
@ -69,7 +69,7 @@ namespace ClassicalSharp.Gui.Screens {
g.Gui.RefreshHud();
}
static bool GetUseFont(Game g) { return !g.Drawer2D.UseBitmappedChat; }
static string GetUseFont(Game g) { return GetBool(!g.Drawer2D.UseBitmappedChat); }
void SetUseFont(Game g, bool v) { g.Drawer2D.UseBitmappedChat = !v; HandleFontChange(); }
static string GetFont(Game g) { return g.FontName; }

View File

@ -47,7 +47,7 @@ namespace ClassicalSharp.Gui.Screens {
CheckHacksAllowed(null, null);
}
static bool GetHacks(Game g) { return g.LocalPlayer.Hacks.Enabled; }
static string GetHacks(Game g) { return GetBool(g.LocalPlayer.Hacks.Enabled); }
static void SetHacks(Game g, bool v) {
g.LocalPlayer.Hacks.Enabled = v; g.LocalPlayer.CheckHacksConsistency();
}
@ -57,7 +57,7 @@ namespace ClassicalSharp.Gui.Screens {
g.LocalPlayer.Hacks.SpeedMultiplier = Utils.ParseDecimal(v); Options.Set(OptionsKey.Speed, v);
}
static bool GetCameraClip(Game g) { return g.CameraClipping; }
static string GetCameraClip(Game g) { return GetBool(g.CameraClipping); }
static void SetCameraClip(Game g, bool v) { g.CameraClipping = v; }
static string GetJump(Game g) { return g.LocalPlayer.JumpHeight.ToString("F3"); }
@ -65,19 +65,19 @@ namespace ClassicalSharp.Gui.Screens {
g.LocalPlayer.physics.CalculateJumpVelocity(true, Utils.ParseDecimal(v));
}
static bool GetWOMHacks(Game g) { return g.LocalPlayer.Hacks.WOMStyleHacks; }
static string GetWOMHacks(Game g) { return GetBool(g.LocalPlayer.Hacks.WOMStyleHacks); }
static void SetWOMHacks(Game g, bool v) { g.LocalPlayer.Hacks.WOMStyleHacks = v; }
static bool GetFullStep(Game g) { return g.LocalPlayer.Hacks.FullBlockStep; }
static string GetFullStep(Game g) { return GetBool(g.LocalPlayer.Hacks.FullBlockStep); }
static void SetFullStep(Game g, bool v) { g.LocalPlayer.Hacks.FullBlockStep = v; }
static bool GetPushback(Game g) { return g.LocalPlayer.Hacks.PushbackPlacing; }
static string GetPushback(Game g) { return GetBool(g.LocalPlayer.Hacks.PushbackPlacing); }
static void SetPushback(Game g, bool v) { g.LocalPlayer.Hacks.PushbackPlacing = v; }
static bool GetLiquids(Game g) { return g.ModifiableLiquids; }
static string GetLiquids(Game g) { return GetBool(g.ModifiableLiquids); }
static void SetLiquids(Game g, bool v) { g.ModifiableLiquids = v; }
static bool GetNoclipSlide(Game g) { return g.LocalPlayer.Hacks.NoclipSlide; }
static string GetNoclipSlide(Game g) { return GetBool(g.LocalPlayer.Hacks.NoclipSlide); }
static void SetNoclipSlide(Game g, bool v) { g.LocalPlayer.Hacks.NoclipSlide = v; }
static string GetFOV(Game g) { return g.Fov.ToString(); }

View File

@ -122,27 +122,28 @@ namespace ClassicalSharp.Gui.Screens {
}
protected ButtonWidget MakeBool(int dir, int y, string text, string optKey,
ClickHandler onClick, ButtonBoolGetter getter, ButtonBoolSetter setter) {
ClickHandler onClick, ButtonValueGetter getter, ButtonBoolSetter setter) {
return MakeBool(dir, y, text, optKey, false, onClick, getter, setter);
}
protected ButtonWidget MakeBool(int dir, int y, string text, string optKey, bool invert,
ClickHandler onClick, ButtonBoolGetter getter, ButtonBoolSetter setter) {
ClickHandler onClick, ButtonValueGetter getter, ButtonBoolSetter setter) {
string optName = text;
text = text + ": " + (getter(game) ? "ON" : "OFF");
text = text + ": " + getter(game);
ButtonWidget widget = ButtonWidget.Create(game, 300, text, titleFont, onClick)
.SetLocation(Anchor.Centre, Anchor.Centre, 160 * dir, y);
widget.OptName = optName;
widget.GetValue = g => getter(g) ? "yes" : "no";
string target = invert ? "no" : "yes";
widget.GetValue = getter;
string target = invert ? "OFF" : "ON";
widget.SetValue = (g, v) => {
setter(g, v == "yes");
setter(g, v == "ON");
Options.Set(optKey, v == target);
widget.SetText(widget.OptName + ": " + (v == "yes" ? "ON" : "OFF"));
widget.SetText(widget.OptName + ": " + v);
};
return widget;
}
protected static string GetBool(bool v) { return v ? "ON" : "OFF"; }
void ShowExtendedHelp() {
bool canShow = input == null && selectedWidget != null && descriptions != null;
@ -189,7 +190,7 @@ namespace ClassicalSharp.Gui.Screens {
MenuInputValidator validator = validators[index];
if (validator is BooleanValidator) {
string value = button.GetValue(game);
button.SetValue(game, value == "yes" ? "no" : "yes");
button.SetValue(game, value == "ON" ? "OFF" : "ON");
UpdateDescription(button);
return;
} else if (validator is EnumValidator) {
@ -234,8 +235,9 @@ namespace ClassicalSharp.Gui.Screens {
void ChangeSetting() {
string text = input.Text.ToString();
if (((MenuInputWidget)input).Validator.IsValidValue(text))
if (((MenuInputWidget)input).Validator.IsValidValue(text)) {
targetWidget.SetValue(game, text);
}
DisposeWidgets();
UpdateDescription(targetWidget);

View File

@ -53,16 +53,16 @@ namespace ClassicalSharp.Gui.Screens {
g.AudioPlayer.SetSounds(g.SoundsVolume);
}
static bool GetViewBob(Game g) { return g.ViewBobbing; }
static string GetViewBob(Game g) { return GetBool(g.ViewBobbing); }
static void SetViewBob(Game g, bool v) { g.ViewBobbing = v; }
static bool GetPhysics(Game g) { return ((SinglePlayerServer)g.Server).physics.Enabled; }
static string GetPhysics(Game g) { return GetBool(((SinglePlayerServer)g.Server).physics.Enabled); }
static void SetPhysics(Game g, bool v) { ((SinglePlayerServer)g.Server).physics.Enabled = v; }
static bool GetAutoClose(Game g) { return Options.GetBool(OptionsKey.AutoCloseLauncher, false); }
static string GetAutoClose(Game g) { return GetBool(Options.GetBool(OptionsKey.AutoCloseLauncher, false)); }
static void SetAutoClose(Game g, bool v) { Options.Set(OptionsKey.AutoCloseLauncher, v); }
static bool GetInvert(Game g) { return g.InvertMouse; }
static string GetInvert(Game g) { return GetBool(g.InvertMouse); }
static void SetInvert(Game g, bool v) { g.InvertMouse = v; }
static string GetSensitivity(Game g) { return g.MouseSensitivity.ToString(); }

View File

@ -29,6 +29,7 @@ namespace ClassicalSharp.Gui.Screens {
protected override void ContextRecreated() {
ClickHandler onClick = OnWidgetClick;
bool classic = game.UseClassicOptions;
widgets = new Widget[] {
MakeBool(-1, -150, "Classic hand model", OptionsKey.ClassicArmModel, onClick, GetHand, SetHand),
MakeBool(-1, -100, "Classic walk anim", OptionsKey.SimpleArmsAnim, true, onClick, GetAnim, SetAnim),
@ -42,39 +43,33 @@ namespace ClassicalSharp.Gui.Screens {
TextWidget.Create(game, "&eButtons on the right require a client restart", regularFont)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 100),
MakeBack(false, titleFont,
(g, w) => g.Gui.SetNewScreen(PreviousScreen())),
classic ? MakeBack(false, titleFont, SwitchPause) : MakeBack(false, titleFont, SwitchOptions),
null, null,
};
}
static bool GetHand(Game g) { return g.ClassicArmModel; }
static string GetHand(Game g) { return GetBool(g.ClassicArmModel); }
static void SetHand(Game g, bool v) { g.ClassicArmModel = v; }
static bool GetAnim(Game g) { return !g.SimpleArmsAnim; }
static string GetAnim(Game g) { return GetBool(!g.SimpleArmsAnim); }
static void SetAnim(Game g, bool v) { g.SimpleArmsAnim = !v; }
static bool GetGui(Game g) { return g.UseClassicGui; }
static string GetGui(Game g) { return GetBool(g.UseClassicGui); }
static void SetGui(Game g, bool v) { g.UseClassicGui = v; }
static bool GetList(Game g) { return g.UseClassicTabList; }
static string GetList(Game g) { return GetBool(g.UseClassicTabList); }
static void SetList(Game g, bool v) { g.UseClassicTabList = v; }
static bool GetOpts(Game g) { return g.UseClassicOptions; }
static string GetOpts(Game g) { return GetBool(g.UseClassicOptions); }
static void SetOpts(Game g, bool v) { g.UseClassicOptions = v; }
static bool GetCustom(Game g) { return g.UseCustomBlocks; }
static string GetCustom(Game g) { return GetBool(g.UseCustomBlocks); }
static void SetCustom(Game g, bool v) { g.UseCustomBlocks = v; }
static bool GetCPE(Game g) { return g.UseCPE; }
static string GetCPE(Game g) { return GetBool(g.UseCPE); }
static void SetCPE(Game g, bool v) { g.UseCPE = v; }
static bool GetTexs(Game g) { return g.AllowServerTextures; }
static string GetTexs(Game g) { return GetBool(g.AllowServerTextures); }
static void SetTexs(Game g, bool v) { g.AllowServerTextures = v; }
Screen PreviousScreen() {
if (game.UseClassicOptions) return new PauseScreen(game);
return new OptionsGroupScreen(game);
}
}
}