Fix crash when changing FPS limit mode

This commit is contained in:
UnknownShadow200 2017-02-11 21:30:57 +11:00
parent d798322db4
commit bf1cdfddf1
2 changed files with 28 additions and 17 deletions

View File

@ -19,37 +19,47 @@ namespace ClassicalSharp.Gui.Screens {
} }
protected override void ContextRecreated() { protected override void ContextRecreated() {
widgets = new Widget[] { widgets = new Widget[] {
MakeOpt(-1, -50, "FPS mode", OnWidgetClick, MakeOpt(-1, -50, "FPS mode", OnWidgetClick,
g => g.FpsLimit.ToString(), g => g.FpsLimit.ToString(),
(g, v) => { object raw = Enum.Parse(typeof(FpsLimitMethod), v); (g, v) => { }),
g.SetFpsLimitMethod((FpsLimitMethod)raw);
Options.Set(OptionsKey.FpsLimit, v); }),
MakeOpt(-1, 0, "View distance", OnWidgetClick, MakeOpt(-1, 0, "View distance", OnWidgetClick,
g => g.ViewDistance.ToString(), g => g.ViewDistance.ToString(),
(g, v) => g.SetViewDistance(Int32.Parse(v), true)), (g, v) => g.SetViewDistance(Int32.Parse(v), true)),
MakeBool(-1, 50, "Advanced lighting", OptionsKey.SmoothLighting, MakeBool(-1, 50, "Advanced lighting", OptionsKey.SmoothLighting,
OnWidgetClick, g => g.SmoothLighting, SetSmoothLighting), OnWidgetClick, g => g.SmoothLighting, SetSmoothLighting),
MakeOpt(1, -50, "Names", OnWidgetClick, MakeOpt(1, -50, "Names", OnWidgetClick,
g => g.Entities.NamesMode.ToString(), g => g.Entities.NamesMode.ToString(),
(g, v) => { object raw = Enum.Parse(typeof(NameMode), v); (g, v) => {
g.Entities.NamesMode = (NameMode)raw; object rawNames = Enum.Parse(typeof(NameMode), v);
Options.Set(OptionsKey.NamesMode, v); }), g.Entities.NamesMode = (NameMode)rawNames;
Options.Set(OptionsKey.NamesMode, v);
}),
MakeOpt(1, 0, "Shadows", OnWidgetClick, MakeOpt(1, 0, "Shadows", OnWidgetClick,
g => g.Entities.ShadowMode.ToString(), g => g.Entities.ShadowMode.ToString(),
(g, v) => { object raw = Enum.Parse(typeof(EntityShadow), v); (g, v) => {
g.Entities.ShadowMode = (EntityShadow)raw; object rawShadows = Enum.Parse(typeof(EntityShadow), v);
Options.Set(OptionsKey.EntityShadow, v); }), g.Entities.ShadowMode = (EntityShadow)rawShadows;
Options.Set(OptionsKey.EntityShadow, v);
}),
MakeBack(false, titleFont, MakeBack(false, titleFont,
(g, w) => g.Gui.SetNewScreen(new OptionsGroupScreen(g))), (g, w) => g.Gui.SetNewScreen(new OptionsGroupScreen(g))),
null, null, null, null,
}; };
// NOTE: we need to override the default setter here, because it recreates the graphics context
ButtonWidget btn = (ButtonWidget)widgets[0];
btn.SetValue = (g, v) => {
object rawFps = Enum.Parse(typeof(FpsLimitMethod), v);
g.SetFpsLimitMethod((FpsLimitMethod)rawFps);
Options.Set(OptionsKey.FpsLimit, v);
};
} }
void SetSmoothLighting(Game g, bool v) { void SetSmoothLighting(Game g, bool v) {
@ -86,7 +96,7 @@ namespace ClassicalSharp.Gui.Screens {
"&eAll: &fAll player names are drawn normally.", "&eAll: &fAll player names are drawn normally.",
"&eAllAndHovered: &fName of the targeted player is drawn see-through.", "&eAllAndHovered: &fName of the targeted player is drawn see-through.",
"&f All other player names are drawn normally.", "&f All other player names are drawn normally.",
}; };
descriptions[4] = new string[] { descriptions[4] = new string[] {
"&eNone: &fNo entity shadows are drawn.", "&eNone: &fNo entity shadows are drawn.",
"&eSnapToBlock: &fA square shadow is shown on block you are directly above.", "&eSnapToBlock: &fA square shadow is shown on block you are directly above.",

View File

@ -224,6 +224,7 @@ namespace ClassicalSharp.Gui.Screens {
string value = button.GetValue(game); string value = button.GetValue(game);
int enumValue = (int)Enum.Parse(type, value, true); int enumValue = (int)Enum.Parse(type, value, true);
enumValue++; enumValue++;
// go back to first value // go back to first value
if (!Enum.IsDefined(type, enumValue)) if (!Enum.IsDefined(type, enumValue))
enumValue = 0; enumValue = 0;