예제 #1
0
        void CreateEditingWidgets()
        {
            DisposeEditingWidgets();

            widgets[8] = Make(-140, 55, "Key: " + curHotkey.BaseKey,
                              250, 35, textFont, BaseKeyClick);
            widgets[9] = Make(140, 55, "Modifiers: " + MakeFlagsString(curHotkey.Flags),
                              250, 35, textFont, ModifiersClick);
            widgets[10] = Make(-10, 120, curHotkey.MoreInput ? "yes" : "no",
                               50, 25, textFont, LeaveOpenClick);
            widgets[11] = Make(-120, 160, "Save changes",
                               180, 35, textFont, SaveChangesClick);
            widgets[12] = Make(120, 160, "Remove hotkey",
                               180, 35, textFont, RemoveHotkeyClick);

            currentAction = MenuInputWidget.Create(
                game, 0, 90, 600, 30, "", Anchor.Centre, Anchor.Centre,
                regularFont, titleFont, 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);
        }
        MenuInputWidget MakeInput(int y)
        {
            MenuInputWidget widget = MenuInputWidget.Create(
                game, 0, y, 200, 25, "", Anchor.Centre, Anchor.Centre,
                regularFont, titleFont, new IntegerValidator(1, 8192));

            widget.Active  = false;
            widget.OnClick = InputClick;
            return(widget);
        }
예제 #3
0
        MenuInputWidget MakeInput(int y, bool seed, string value)
        {
            MenuInputValidator validator = seed ? new SeedValidator() : new IntegerValidator(1, 8192);
            MenuInputWidget    widget    = MenuInputWidget.Create(
                game, 0, y, 200, 30, value, Anchor.Centre, Anchor.Centre,
                regularFont, titleFont, validator);

            widget.Active  = false;
            widget.OnClick = InputClick;
            return(widget);
        }
        protected void OnWidgetClick(Game game, Widget widget)
        {
            if (widget == buttons[okayIndex])
            {
                ChangeSetting();
                return;
            }
            ButtonWidget button = (ButtonWidget)widget;

            int index = Array.IndexOf <ButtonWidget>(buttons, 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)
            {
                string value     = button.GetValue(game);
                Type   type      = (Type)button.Metadata;
                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);
                return;
            }

            if (inputWidget != null)
            {
                inputWidget.Dispose();
            }

            targetWidget = selectedWidget;
            inputWidget  = MenuInputWidget.Create(game, 0, 150, 400, 25, button.GetValue(game), Anchor.Centre,
                                                  Anchor.Centre, regularFont, titleFont, validator);
            buttons[okayIndex] = ButtonWidget.Create(game, 240, 150, 40, 30, "OK",
                                                     Anchor.Centre, Anchor.Centre, titleFont, OnWidgetClick);
            InputOpened();
            UpdateDescription(targetWidget);
        }
        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)
            {
                HandleEnumOption(button);
                return;
            }

            if (inputWidget != null)
            {
                inputWidget.Dispose();
            }

            targetWidget = selectedWidget;
            inputWidget  = MenuInputWidget.Create(game, 0, 150, 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, 150, 40, 30, "OK",
                                                              Anchor.Centre, Anchor.Centre, titleFont, OnWidgetClick);
            InputOpened();
            UpdateDescription(targetWidget);
        }
        public override void Init()
        {
            game.Keyboard.KeyRepeat = true;
            base.Init();
            regularFont = new Font("Arial", 16, FontStyle.Regular);

            inputWidget = MenuInputWidget.Create(
                game, -30, 50, 500, 25, "", Anchor.Centre, Anchor.Centre,
                regularFont, titleFont, new PathValidator());

            buttons = new [] {
                ButtonWidget.Create(game, 260, 50, 60, 30, "Save", Anchor.Centre,
                                    Anchor.Centre, titleFont, OkButtonClick),
                null,
                MakeBack(false, titleFont,
                         (g, w) => g.SetNewScreen(new PauseScreen(g))),
            };
        }