protected void OnWidgetClick(Game game, Widget widget, MouseButton btn, int x, int y) { ButtonWidget button = widget as ButtonWidget; if (btn != MouseButton.Left) { return; } if (widget == widgets[widgets.Length - 1]) { ChangeSetting(); return; } if (button == null) { return; } DisposeExtendedHelp(); int index = Array.IndexOf <Widget>(widgets, button); MenuInputValidator validator = validators[index]; if (validator is BooleanValidator) { string value = button.GetValue(game); button.SetValue(game, value == "yes" ? "no" : "yes"); UpdateDescription(button); return; } else if (validator is EnumValidator) { Type type = ((EnumValidator)validator).EnumType; HandleEnumOption(button, type); return; } targetWidget = selectedWidget; if (input != null) { input.Dispose(); } input = MenuInputWidget.Create(game, 400, 30, button.GetValue(game), regularFont, validator) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 110); input.ShowCaret = true; input.OnClick = InputClick; widgets[widgets.Length - 2] = input; widgets[widgets.Length - 1] = ButtonWidget.Create(game, 40, "OK", titleFont, OnWidgetClick) .SetLocation(Anchor.Centre, Anchor.Centre, 240, 110); InputOpened(); UpdateDescription(targetWidget); }
void SetButtonValue(int index, string text) { ButtonWidget btn = (ButtonWidget)widgets[index]; btn.SetValue(game, text); // need to get btn again here (e.g. changing FPS invalidates all widgets) btn = (ButtonWidget)widgets[index]; btn.Set(btn.OptName + ": " + btn.GetValue(game), titleFont); }
protected void OnBoolClick(Game game, Widget widget) { ButtonWidget button = (ButtonWidget)widget; int index = IndexWidget(widget); SelectExtendedHelp(index); string value = button.GetValue(game); SetButtonValue(index, value == "ON" ? "OFF" : "ON"); }
void SetButtonValue(ButtonWidget btn, string text) { btn.SetValue(game, text); int index = IndexOfWidget(btn); // e.g. changing FPS invalidates all widgets if (index >= 0) { btn.SetText(btn.OptName + ": " + btn.GetValue(game)); } }
protected void OnButtonClick(Game game, Widget widget) { ButtonWidget button = widget as ButtonWidget; if (button == null) { return; } DisposeExtendedHelp(); int index = IndexOfWidget(button); MenuInputValidator validator = validators[index]; if (validator is BooleanValidator) { string value = button.GetValue(game); SetButtonValue(button, value == "ON" ? "OFF" : "ON"); UpdateDescription(button); return; } else if (validator is EnumValidator) { Type type = ((EnumValidator)validator).EnumType; HandleEnumOption(button, type); return; } 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 value = button.GetValue(game); int enumValue = (int)Enum.Parse(type, value, true); enumValue++; // go back to first value if (!Enum.IsDefined(type, enumValue)) { enumValue = 0; } button.SetValue(game, Enum.GetName(type, enumValue)); UpdateDescription(button); }
protected void OnEnumClick(Game game, Widget widget) { ButtonWidget button = (ButtonWidget)widget; int index = IndexWidget(widget); SelectExtendedHelp(index); MenuInputValidator validator = validators[index]; Type type = ((EnumValidator)validator).EnumType; string value = button.GetValue(game); int raw = (int)Enum.Parse(type, value, true) + 1; if (!Enum.IsDefined(type, raw)) { raw = 0; // go back to first value } SetButtonValue(index, Enum.GetName(type, raw)); }
protected void OnInputClick(Game game, Widget widget) { ButtonWidget button = (ButtonWidget)widget; activeI = IndexWidget(button); DisposeExtendedHelp(); DisposeInput(); MenuInputValidator validator = validators[activeI]; input = MenuInputWidget.Create(game, 400, 30, button.GetValue(game), textFont, validator) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 110); input.ShowCaret = true; widgets[widgets.Length - 1] = input; widgets[widgets.Length - 2] = ButtonWidget.Create(game, 40, "OK", titleFont, OKButtonClick) .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); }