protected void OnWidgetClick(Game game, Widget widget, MouseButton mouseBtn) { ButtonWidget button = widget as ButtonWidget; if (mouseBtn != 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; } if (inputWidget != null) { inputWidget.Dispose(); } targetWidget = selectedWidget; inputWidget = MenuInputWidget.Create(game, 0, 110, 400, 30, button.GetValue(game), Anchor.Centre, Anchor.Centre, regularFont, titleFont, validator); widgets[widgets.Length - 2] = inputWidget; widgets[widgets.Length - 1] = ButtonWidget.Create(game, 240, 110, 40, 30, "OK", Anchor.Centre, Anchor.Centre, titleFont, OnWidgetClick); 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); }
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 ); }