void OnBindingClick(Game game, Widget widget, MouseButton btn, int x, int y)
        {
            int index = 0;

            if (btn == MouseButton.Right && (curWidget == null || curWidget == widget))
            {
                curWidget = (ButtonWidget)widget;
                index     = IndexOfWidget(curWidget) - 2;
                KeyBind mapping = binds[index];
                HandlesKeyDown(game.Input.Keys.GetDefault(mapping));
            }
            if (btn != MouseButton.Left)
            {
                return;
            }

            if (curWidget != null)
            {
                index = IndexOfWidget(curWidget) - 2;
                curWidget.SetText(ButtonText(index));
                curWidget = null;
            }

            index = IndexOfWidget(widget) - 2;
            string text = ButtonText(index);

            curWidget = (ButtonWidget)widget;
            curWidget.SetText("> " + text + " <");
        }
        void HandleFontChange()
        {
            int selIndex = IndexOfWidget(selectedWidget);

            game.Events.RaiseChatFontChanged();
            base.Dispose();
            base.Init();
            game.Gui.RefreshHud();

            for (int i = 0; i < widgets.Length; i++)
            {
                if (widgets[i] == null || !(widgets[i] is ButtonWidget))
                {
                    widgets[i] = null; continue;
                }

                ButtonWidget btn = widgets[i] as ButtonWidget;
                btn.font = titleFont;
                btn.SetText(btn.Text);
            }

            if (selIndex >= 0)
            {
                selectedWidget = (ButtonWidget)widgets[selIndex];
            }
        }
        void DoSave(Widget widget, string ext)
        {
            string text = input.Text.ToString();

            if (text.Length == 0)
            {
                MakeDescWidget("&ePlease enter a filename"); return;
            }
            string file = Path.ChangeExtension(text, ext);

            text = Path.Combine(Program.AppDirectory, "maps");
            text = Path.Combine(text, file);

            ButtonWidget btn = (ButtonWidget)widget;

            if (File.Exists(text) && btn.OptName == null)
            {
                btn.SetText("&cOverwrite existing?");
                btn.OptName = "O";
            }
            else
            {
                // NOTE: We don't immediately save here, because otherwise the 'saving...'
                // will not be rendered in time because saving is done on the main thread.
                MakeDescWidget("Saving..");
                textPath = text;
                RemoveOverwrites();
            }
        }
        void OnBindingClick(Game game, Widget widget)
        {
            int index = 0;

            if (curWidget != null)
            {
                index = IndexOfWidget(curWidget) - 2;
                curWidget.SetText(ButtonText(index));
                curWidget = null;
            }

            index = IndexOfWidget(widget) - 2;
            string text = ButtonText(index);

            curWidget = (ButtonWidget)widget;
            curWidget.SetText("> " + text + " <");
        }
Beispiel #5
0
        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.SetText(btn.OptName + ": " + btn.GetValue(game));
        }
        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));
            }
        }
        void RemoveOverwrite(Widget widget)
        {
            ButtonWidget button = (ButtonWidget)widget;

            if (button.Metadata == null)
            {
                return;
            }
            button.Metadata = null;
            button.SetText("Save");
        }
        void RemoveOverwrite(Widget widget, string defaultText)
        {
            ButtonWidget button = (ButtonWidget)widget;

            if (button.OptName == null)
            {
                return;
            }

            button.OptName = null;
            button.SetText(defaultText);
        }
        void OnBindingClick(Game game, Widget widget)
        {
            if (curI >= 0)
            {
                ButtonWidget curButton = (ButtonWidget)widgets[curI];
                curButton.SetText(ButtonText(curI));
            }

            curI = IndexWidget(widget);
            string text = ButtonText(curI);

            ((ButtonWidget)widget).SetText("> " + text + " <");
        }
Beispiel #10
0
        protected ButtonWidget MakeOpt(int dir, int y, string text, ClickHandler onClick,
                                       Func <Game, string> getter, Action <Game, string> setter)
        {
            ButtonWidget widget = ButtonWidget.Create(game, 300, text + ": " + getter(game), titleFont, onClick)
                                  .SetLocation(Anchor.Centre, Anchor.Centre, 160 * dir, y);

            widget.Metadata = text;
            widget.GetValue = getter;
            widget.SetValue = (g, v) => {
                setter(g, v);
                widget.SetText((string)widget.Metadata + ": " + getter(g));
            };
            return(widget);
        }
        void UpdateDelayLeft(double delta)
        {
            double elapsed  = (DateTime.UtcNow - initTime).TotalSeconds;
            int    secsLeft = Math.Max(0, (int)(delay - elapsed));

            if (lastSecsLeft == secsLeft && reconnect.Active == lastActive)
            {
                return;
            }

            reconnect.SetText(ReconnectMessage());
            reconnect.Disabled = secsLeft != 0;

            Redraw(delta);
            lastSecsLeft = secsLeft;
            lastActive   = reconnect.Active;
            clearTime    = DateTime.UtcNow.AddSeconds(0.5);
        }
Beispiel #12
0
        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);
        }
        void UpdateDelayLeft(double delta)
        {
            ButtonWidget btn      = (ButtonWidget)widgets[2];
            double       elapsed  = (DateTime.UtcNow - initTime).TotalSeconds;
            int          secsLeft = Math.Max(0, (int)(delay - elapsed));

            if (lastSecsLeft == secsLeft && btn.Active == lastActive)
            {
                return;
            }

            btn.SetText(ReconnectMessage());
            btn.Disabled = secsLeft != 0;

            Redraw(delta);
            lastSecsLeft = secsLeft;
            lastActive   = btn.Active;
            clearTime    = DateTime.UtcNow.AddSeconds(0.5);
        }
        public override bool HandlesKeyDown(Key key)
        {
            if (curI == -1)
            {
                return(base.HandlesKeyDown(key));
            }
            KeyBind bind = binds[curI];

            if (key == Key.Escape)
            {
                key = game.Input.Keys.GetDefault(bind);
            }
            game.Input.Keys[bind] = key;

            ButtonWidget curButton = (ButtonWidget)widgets[curI];

            curButton.SetText(ButtonText(curI));
            curI = -1;
            return(true);
        }
Beispiel #15
0
 protected virtual void UpdateEntry(ButtonWidget widget, string text)
 {
     widget.SetText(text);
 }