Example #1
0
        protected ButtonWidget MakeTitle(int dir, int y, string text, ClickHandler onClick)
        {
            ButtonWidget widget = ButtonWidget.Create(game, 160 * dir, y, 301, 41, text, Anchor.Centre,
                                                      Anchor.Centre, titleFont, onClick);

            return(widget);
        }
Example #2
0
        public override void Init()
        {
            game.Keyboard.KeyRepeat = true;
            base.Init();
            titleFont   = new Font(game.FontName, 16, FontStyle.Bold);
            regularFont = new Font(game.FontName, 16, FontStyle.Regular);

            inputs = new [] {
                MakeInput(-80, false, game.World.Width.ToString()),
                MakeInput(-40, false, game.World.Height.ToString()),
                MakeInput(0, false, game.World.Length.ToString()),
                MakeInput(40, true, "")
            };
            labels = new [] {
                MakeLabel(-150, -80, "Width:"), MakeLabel(-150, -40, "Height:"),
                MakeLabel(-150, 0, "Length:"), MakeLabel(-140, 40, "Seed:"),
                ChatTextWidget.Create(game, 0, -130, "Generate new level",
                                      Anchor.Centre, Anchor.Centre, regularFont),
            };
            widgets = new [] {
                ButtonWidget.Create(game, -120, 100, 201, 40, "Flatgrass", Anchor.Centre,
                                    Anchor.Centre, titleFont, GenFlatgrassClick),
                ButtonWidget.Create(game, 120, 100, 201, 40, "Vanilla", Anchor.Centre,
                                    Anchor.Centre, titleFont, GenNotchyClick),
                MakeBack(false, titleFont,
                         (g, w) => g.SetNewScreen(new PauseScreen(g))),
            };
        }
        void Make(string desc, KeyBind bind, int x, ref int y)
        {
            string text = desc + ": " + keyNames[(int)game.Mapping(bind)];

            widgets[index++] = ButtonWidget.Create(game, x, y, btnWidth, btnHeight, text,
                                                   Anchor.Centre, Anchor.Centre, keyFont, OnBindingClick);
            y += btnDistance;
        }
 public override void Init()
 {
     api.ClearColour(new FastColour(65, 31, 31));
     widgets = new Widget[] {
         ChatTextWidget.Create(game, 0, -30, title, Anchor.Centre, Anchor.Centre, titleFont),
         ChatTextWidget.Create(game, 0, 10, message, Anchor.Centre, Anchor.Centre, messageFont),
         ButtonWidget.Create(game, 0, 80, 301, 40, "Try to reconnect.. " + delay,
                             Anchor.Centre, Anchor.Centre, titleFont, ReconnectClick),
     };
     initTime     = DateTime.UtcNow;
     lastSecsLeft = delay;
 }
        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);
        }
Example #6
0
        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)
            {
                Type type = ((EnumValidator)validator).EnumType;
                HandleEnumOption(button, type);
                return;
            }

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

            targetWidget = selectedWidget;
            inputWidget  = MenuInputWidget.Create(game, 0, 110, 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, 110, 40, 30, "OK",
                                                              Anchor.Centre, Anchor.Centre, titleFont, OnWidgetClick);
            InputOpened();
            UpdateDescription(targetWidget);
        }
Example #7
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, 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);
        }
        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);
        }
Example #9
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 MakePages(int origin)
        {
            if (leftPage == null && rightPage == null)
            {
                return;
            }
            int btnY = origin + btnDistance * (left.Length / 2);

            widgets[index++] = ButtonWidget.Create(game, -btnWidth - 35, btnY, btnHeight, btnHeight, "<",
                                                   Anchor.Centre, Anchor.Centre, keyFont, LeftOnly(leftPage));
            widgets[index++] = ButtonWidget.Create(game, btnWidth + 35, btnY, btnHeight, btnHeight, ">",
                                                   Anchor.Centre, Anchor.Centre, keyFont, LeftOnly(rightPage));
            if (leftPage == null)
            {
                widgets[index - 2].Disabled = true;
            }
            if (rightPage == null)
            {
                widgets[index - 1].Disabled = true;
            }
        }
Example #11
0
        public override void Init()
        {
            game.Keyboard.KeyRepeat = true;
            base.Init();
            regularFont = new Font(game.FontName, 16, FontStyle.Regular);

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

            widgets = new Widget[] {
                ButtonWidget.Create(game, 0, 20, 301, 40, "Save", Anchor.Centre,
                                    Anchor.Centre, titleFont, SaveClassic),
                ButtonWidget.Create(game, -150, 120, 201, 40, "Save schematic", Anchor.Centre,
                                    Anchor.Centre, titleFont, SaveSchematic),
                ChatTextWidget.Create(game, 110, 120, "&eCan be imported into MCEdit", Anchor.Centre,
                                      Anchor.Centre, regularFont),
                null,
                MakeBack(false, titleFont,
                         (g, w) => g.SetNewScreen(new PauseScreen(g))),
            };
        }
        void MakeNormal()
        {
            widgets = new Widget[] {
                Make(-1, -50, "Options",
                     (g, w) => g.SetNewScreen(new OptionsGroupScreen(g))),
                Make(1, -50, "Generate level",
                     (g, w) => g.SetNewScreen(new GenLevelScreen(g))),
                Make(1, 0, "Load level",
                     (g, w) => g.SetNewScreen(new LoadLevelScreen(g))),
                Make(1, 50, "Save level",
                     (g, w) => g.SetNewScreen(new SaveLevelScreen(g))),
                Make(-1, 0, "Select texture pack",
                     (g, w) => g.SetNewScreen(new TexturePackScreen(g))),
                Make(-1, 50, "Hotkeys",
                     (g, w) => g.SetNewScreen(new HotkeyListScreen(g))),

                // Other
                ButtonWidget.Create(game, 5, 5, 120, 40, "Quit game",
                                    Anchor.BottomOrRight, Anchor.BottomOrRight,
                                    titleFont, LeftOnly((g, w) => g.Exit())),
                MakeBack(true, titleFont, (g, w) => g.SetNewScreen(null)),
            };
        }
Example #13
0
 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)));
 }
 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)));
 }
Example #15
0
 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)));
 }
Example #16
0
 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);
 }