public override bool HandlesKeyDown( Key key ) { if( key == Key.Escape ) { game.SetNewScreen( null ); } else if( curWidget != null ) { int index = Array.IndexOf<Widget>( widgets, curWidget ); KeyBinding mapping = (KeyBinding)(index + (int)originKey); KeyMap map = game.InputHandler.Keys; Key oldKey = map[mapping]; string reason; if( !map.IsKeyOkay( oldKey, key, out reason ) ) { const string format = "&eFailed to change mapping \"{0}\". &c({1})"; statusWidget.SetText( String.Format( format, descriptions[index], reason ) ); } else { const string format = "&eChanged mapping \"{0}\" from &7{1} &eto &7{2}&e."; statusWidget.SetText( String.Format( format, descriptions[index], oldKey, key ) ); string text = descriptions[index] + ": " + keyNames[(int)key]; curWidget.SetText( text ); map[mapping] = key; } curWidget = null; } return key < Key.F1 || key > Key.F35; }
public static ButtonWidget Create( Game game, int x, int y, int width, int height, string text, Anchor horizontal, Anchor vertical, Font font, ClickHandler onClick) { ButtonWidget widget = new ButtonWidget( game, font ); widget.Init(); widget.HorizontalAnchor = horizontal; widget.VerticalAnchor = vertical; widget.XOffset = x; widget.YOffset = y; widget.DesiredMaxWidth = width; widget.DesiredMaxHeight = height; widget.SetText( text ); widget.OnClick = onClick; return widget; }
protected override void WidgetSelected( Widget widget ) { ButtonWidget button = widget as ButtonWidget; if( selectedWidget == widget || button == null || button == widgets[widgets.Length - 1] ) return; selectedWidget = button; if( descWidget != null ) descWidget.Dispose(); if( button == null ) return; string text = descriptions[Array.IndexOf<Widget>(widgets, button)]; descWidget = ChatTextWidget.Create( game, 0, 100, text, Anchor.Centre, Anchor.Centre, regularFont ); }
void InitStandardButtons() { widgets = new ButtonWidget[showAlways ? 4 : 2]; widgets[0] = ButtonWidget.Create( game, -110, 30, 160, 35, "Yes", Anchor.Centre, Anchor.Centre, titleFont, OnYesClick ); widgets[1] = ButtonWidget.Create( game, 110, 30, 160, 35, "No", Anchor.Centre, Anchor.Centre, titleFont, OnNoClick ); if( !showAlways ) return; widgets[2] = ButtonWidget.Create( game, -110, 80, 160, 35, "Always yes", Anchor.Centre, Anchor.Centre, titleFont, OnYesAlwaysClick ); widgets[3] = ButtonWidget.Create( game, 110, 80, 160, 35, "Always no", Anchor.Centre, Anchor.Centre, titleFont, OnNoAlwaysClick ); }
void InitConfirmButtons( bool always ) { ClickHandler noHandler = always ? (ClickHandler)OnNoAlwaysClick: (ClickHandler)OnNoClick; widgets = new ButtonWidget[] { ButtonWidget.Create( game, -110, 30, 160, 35, "I'm sure", Anchor.Centre, Anchor.Centre, titleFont, noHandler ), ButtonWidget.Create( game, 110, 30, 160, 35, "Go back", Anchor.Centre, Anchor.Centre, titleFont, GoBackClick ), }; confirmMode = true; SetText( lastTitle, lastBody ); }
ButtonWidget Make(int x, int y, string text, Action <Game, Widget> onClick) { return(ButtonWidget.Create(game, x, y, 41, 40, text, Anchor.Centre, Anchor.Centre, arrowFont, LeftOnly(onClick))); }
ButtonWidget MakeText(int x, int y, string text) { return(ButtonWidget.Create(game, x, y, 301, 40, text, Anchor.Centre, Anchor.Centre, textFont, TextButtonClick)); }
protected override void InputOpened() { widgets[defaultIndex] = ButtonWidget.Create( game, 0, 150, 201, 40, "Default value", Anchor.Centre, Anchor.Centre, titleFont, DefaultButtonClick); }
void OnBindingClick( Game game, Widget widget, MouseButton mouseBtn ) { if( mouseBtn == MouseButton.Right && (curWidget == null || curWidget == widget) ) { curWidget = (ButtonWidget)widget; int index = Array.IndexOf<Widget>( widgets, curWidget ); KeyBinding mapping = (KeyBinding)(index + (int)originKey); HandlesKeyDown( game.InputHandler.Keys.GetDefault( mapping ) ); } if( mouseBtn != MouseButton.Left ) return; if( curWidget == widget ) { curWidget = null; statusWidget.SetText( "" ); } else { curWidget = (ButtonWidget)widget; int index = Array.IndexOf<Widget>( widgets, curWidget ); string text = "&ePress new key binding for " + descriptions[index] + ":"; statusWidget.SetText( text ); } }
ButtonWidget Make(int x, int y, string text, int width, int height, Font font, Action <Game, Widget> onClick) { return(ButtonWidget.Create(game, x, y, width, height, text, Anchor.Centre, Anchor.Centre, font, LeftOnly(onClick))); }
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 override void WidgetSelected( Widget widget ) { ButtonWidget button = widget as ButtonWidget; if( selectedWidget == button || button == null || button == widgets[widgets.Length - 2] ) return; selectedWidget = button; if( targetWidget != null ) return; UpdateDescription( selectedWidget ); }
protected void UpdateDescription( ButtonWidget widget ) { DisposeExtendedHelp(); if( widget == null || widget.GetValue == null ) return; ShowExtendedHelp(); }
ButtonWidget Make(int dir, int y, string text, Action <Game, Widget> onClick) { return(ButtonWidget.Create(game, dir * 160, y, 301, 40, text, Anchor.Centre, Anchor.Centre, titleFont, LeftOnly(onClick))); }