public static MenuInputWidget Create( Game game, int x, int y, int width, int height, string text, Anchor horizontal, Anchor vertical, Font font, Font tildeFont, Font hintFont, MenuInputValidator validator) { MenuInputWidget widget = new MenuInputWidget( game, font, tildeFont, hintFont ); widget.HorizontalAnchor = horizontal; widget.VerticalAnchor = vertical; widget.XOffset = x; widget.YOffset = y; widget.DesiredMaxWidth = width; widget.DesiredMaxHeight = height; widget.chatInputText.Append( 0, text ); widget.Validator = validator; widget.Init(); return widget; }
public override void Init() { game.Keyboard.KeyRepeat = true; titleFont = new Font( "Arial", 16, FontStyle.Bold ); regularFont = new Font( "Arial", 16, FontStyle.Regular ); hintFont = new Font( "Arial", 14, FontStyle.Italic ); inputWidget = MenuInputWidget.Create( game, -30, 50, 500, 25, "", Anchor.Centre, Anchor.Centre, regularFont, titleFont, hintFont, new PathValidator() ); buttons = new [] { ButtonWidget.Create( game, 260, 50, 60, 30, "Save", Anchor.Centre, Anchor.Centre, titleFont, OkButtonClick ), ButtonWidget.Create( game, 0, 5, 240, 35, "Back to menu", Anchor.Centre, Anchor.BottomOrRight, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), }; }
void DisposeEditingWidgets() { if (currentAction != null) { currentAction.Dispose(); currentAction = null; } for (int i = 8; i < widgets.Length - 1; i++) { if (widgets[i] != null) { widgets[i].Dispose(); widgets[i] = null; } } focusWidget = null; }
protected void OnWidgetClick( Game game, ButtonWidget widget ) { if( widget == buttons[okayIndex] ) { ChangeSetting(); return; } int index = Array.IndexOf<ButtonWidget>( buttons, widget ); MenuInputValidator validator = validators[index]; if( validator is BooleanValidator ) { string value = widget.GetValue( game ); widget.SetValue( game, value == "yes" ? "no" : "yes" ); UpdateDescription( widget ); return; } if( inputWidget != null ) inputWidget.Dispose(); targetWidget = selectedWidget; inputWidget = MenuInputWidget.Create( game, 0, 150, 400, 25, widget.GetValue( game ), Anchor.Centre, Anchor.Centre, regularFont, titleFont, hintFont, validator ); buttons[okayIndex] = ButtonWidget.Create( game, 240, 150, 30, 30, "OK", Anchor.Centre, Anchor.Centre, titleFont, OnWidgetClick ); UpdateDescription( targetWidget ); }
void ChangeSetting() { string text = inputWidget.GetText(); if( inputWidget.Validator.IsValidValue( text ) ) targetWidget.SetValue( game, text ); inputWidget.Dispose(); inputWidget = null; UpdateDescription( targetWidget ); targetWidget = null; buttons[okayIndex].Dispose(); buttons[okayIndex] = null; }
void DisposeEditingWidgets() { if( currentAction != null ) { currentAction.Dispose(); currentAction = null; } for( int i = 8; i < buttons.Length - 1; i++ ) { if( buttons[i] != null ) { buttons[i].Dispose(); buttons[i] = null; } } focusWidget = null; }
void CreateEditingWidgets() { DisposeEditingWidgets(); buttons[8] = Make( -140, 60, "Key: " + curHotkey.BaseKey, 250, 30, textFont, BaseKeyClick ); buttons[9] = Make( 140, 60, "Modifiers: " + MakeFlagsString( curHotkey.Flags ), 250, 30, textFont, ModifiersClick ); buttons[10] = Make( -10, 120, curHotkey.MoreInput ? "yes" : "no", 50, 25, textFont, LeaveOpenClick ); buttons[11] = Make( -100, 160, "Save changes", 160, 30, textFont, SaveChangesClick ); buttons[12] = Make( 100, 160, "Remove hotkey", 160, 30, textFont, RemoveHotkeyClick ); currentAction = MenuInputWidget.Create( game, 0, 90, 600, 25, "", Anchor.Centre, Anchor.Centre, regularFont, titleFont, hintFont, new StringValidator( 64 ) ); currentMoreInputLabel = TextWidget.Create( game, -170, 120, "Keep input bar open:", Anchor.Centre, Anchor.Centre, textFont ); if( curHotkey.Text == null ) curHotkey.Text = ""; currentAction.SetText( curHotkey.Text ); }