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); }
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 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 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); }