public override bool HandlesKeyDown(Key key) { if (key == Key.Escape) { game.SetNewScreen(null); } else if (curWidget != null) { int index = Array.IndexOf <Widget>(widgets, curWidget) - 2; KeyBind mapping = Get(index, left, right); KeyMap map = game.InputHandler.Keys; Key oldKey = map[mapping]; string reason; string desc = Get(index, leftDesc, rightDesc); if (!map.IsKeyOkay(oldKey, key, out reason)) { const string format = "&eFailed to change \"{0}\". &c({1})"; statusWidget.SetText(String.Format(format, desc, reason)); } else { const string format = "&e\"{0}\" changed from &7{1} &eto &7{2}&e."; statusWidget.SetText(String.Format(format, desc, oldKey, key)); string text = desc + ": " + keyNames[(int)key]; curWidget.SetText(text); map[mapping] = key; } curWidget = null; } return(key < Key.F1 || key > Key.F35); }
void RemoveOverwrite(Widget widget) { ButtonWidget button = (ButtonWidget)widget; if (button.Metadata == null) { return; } button.Metadata = null; button.SetText("Save"); }
void UpdateReconnectState() { ButtonWidget btn = (ButtonWidget)widgets[2]; double elapsed = (DateTime.UtcNow - initTime).TotalSeconds; int scsLeft = Math.Max(0, (int)(delay - elapsed)); if (lastSecsLeft != scsLeft) { string suffix = scsLeft == 0 ? "" : ".. " + scsLeft; btn.SetText("Try to reconnect" + suffix); } btn.Disabled = scsLeft != 0; }
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; }
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 ButtonWidget MakeOpt(int dir, int y, string text, ClickHandler onClick, Func <Game, string> getter, Action <Game, string> setter) { ButtonWidget widget = ButtonWidget.Create(game, 160 * dir, y, 301, 41, text + ": " + getter(game), Anchor.Centre, Anchor.Centre, titleFont, onClick); widget.Metadata = text; widget.GetValue = getter; widget.SetValue = (g, v) => { setter(g, v); widget.SetText((string)widget.Metadata + ": " + getter(g)); }; return(widget); }
protected ButtonWidget MakeBool(int dir, int y, string text, string optKey, ClickHandler onClick, Func <Game, bool> getter, Action <Game, bool> setter) { string optName = text; text = text + ": " + (getter(game) ? "ON" : "OFF"); ButtonWidget widget = ButtonWidget.Create(game, 160 * dir, y, 301, 41, text, Anchor.Centre, Anchor.Centre, titleFont, onClick); widget.Metadata = optName; widget.GetValue = g => getter(g) ? "yes" : "no"; widget.SetValue = (g, v) => { setter(g, v == "yes"); Options.Set(optKey, v == "yes"); widget.SetText((string)widget.Metadata + ": " + (v == "yes" ? "ON" : "OFF")); }; return(widget); }