示例#1
0
        /// <summary>
        /// A screen for changing the options
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen OptionsScreen(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                Purpose = ScreenPurpose.Options
            };

            retVal.Escape += (sender, e) =>
            {
                if (g1.Config.UnappliedChanges)
                {
                    g1.UI.OpenScreen(CloseOptionsConfirmationScreen(game));
                }
                else
                {
                    g1.UI.CloseTopScreen();
                }
            };
            var spLabel = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };

            retVal.Children.Add(spLabel);
            var optionsLabel = new TextPanel(game)
            {
                Text             = "Options",
                Width            = 128,
                SpriteBackground = false
            };

            spLabel.Children.Add(optionsLabel);
            var spMenu = new StackPanel(game)
            {
                HAnchor        = HorizontalAnchor.Middle,
                VAnchor        = VerticalAnchor.Middle,
                MainNavigation = true
            };

            spLabel.Children.Add(spMenu);
            var volume = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Middle,
                ChildrenShareFocus = true,
                SpriteBackground   = true,
                Border             = 4
            };

            spMenu.Children.Add(volume);
            var volLabel = new TextPanel(game)
            {
                Text             = "Volume",
                Width            = 32,
                SpriteBackground = false
            };

            volume.Children.Add(volLabel);
            var volSlide = new Slider(game)
            {
                Value = g1.Config.Config.Volume,
                InputRepeatInterval = 1f / 40f
            };

            volSlide.ValueChanged += (sender, e) =>
            {
                g1.Config.NewConfig.Volume = (int)volSlide.Value;
            };
            volume.Children.Add(volSlide);
            // resolution
            var res = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Middle,
                ChildrenShareFocus = true,
            };

            spMenu.Children.Add(res);
            var resLabel = new TextPanel(game)
            {
                Text             = "Resolution",
                SpriteBackground = false
            };

            res.Children.Add(resLabel);
            var resolutionSelect = new SelectBox(game);
            var dispModes        = GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.ToList();

            for (int i = 0; i < dispModes.Count; i++)
            {
                resolutionSelect.Options.Add(new SelectBoxOption($"{dispModes[i].Width}x{dispModes[i].Height}", dispModes[i]));
                if (((Game1)game).Config.Config.Resolution == dispModes[i])
                {
                    resolutionSelect.Selected = i;
                }
            }
            resolutionSelect.SelectionChanged += (sender, e) =>
            {
                if (resolutionSelect.SelectedOption.Value is DisplayMode newRes)
                {
                    g1.Config.NewConfig.Resolution = newRes;
                }
            };
            res.Children.Add(resolutionSelect);
            // fullscreen mode select
            var fullscreen = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Middle,
                ChildrenShareFocus = true
            };

            spMenu.Children.Add(fullscreen);
            var fullLabel = new TextPanel(game)
            {
                Text             = "Fullscreen",
                SpriteBackground = false
            };

            fullscreen.Children.Add(fullLabel);
            var fullscreenSelect = new SelectBox(game);

            fullscreenSelect.Options.Add(new SelectBoxOption("Full screen", WindowMode.Fullscreen));
            fullscreenSelect.Options.Add(new SelectBoxOption("Window", WindowMode.Windowed));
            fullscreenSelect.Options.Add(new SelectBoxOption("Borderless window", WindowMode.BorderlessWindow));
            fullscreenSelect.SelectionChanged += (sender, e) =>
            {
                if (fullscreenSelect.SelectedOption.Value is WindowMode newWindMode)
                {
                    g1.Config.NewConfig.WindowMode = newWindMode;
                }
            };
            var windMode = g1.Config.Config.WindowMode;

            switch (windMode)
            {
            case WindowMode.Fullscreen:
                fullscreenSelect.Selected = 0;
                break;

            case WindowMode.Windowed:
                fullscreenSelect.Selected = 1;
                break;

            case WindowMode.BorderlessWindow:
                fullscreenSelect.Selected = 2;
                break;

            default:
                break;
            }
            fullscreen.Children.Add(fullscreenSelect);
            //
            var keys = new Button(game)
            {
                Text    = "Mouse & Keyboard",
                HAnchor = HorizontalAnchor.Middle,
                Width   = 128
            };

            keys.OnClick += (sender, e) =>
            {
                g1.UI.OpenScreen(KeybindsScreen(game));
            };
            spMenu.Children.Add(keys);
            var controller = new Button(game)
            {
                Text    = "Controller",
                HAnchor = HorizontalAnchor.Middle,
                Width   = 128
            };

            controller.OnClick += (sender, e) =>
            {
                g1.UI.OpenScreen(ControllerOptionsScreen(game));
            };
            spMenu.Children.Add(controller);
            //
            var okCancelRow = new StackPanel(game)
            {
                HAnchor   = HorizontalAnchor.Middle,
                Direction = LayoutDirection.Horizontal
            };

            spMenu.Children.Add(okCancelRow);
            var apply = new Button(game)
            {
                Text = "Apply"
            };

            apply.OnClick += (snder, e) =>
            {
                //apply
                g1.Config.Save();
                g1.ApplyGraphicsConfig();
                //g1.Input.SaveKeybinds(g1.Config.KeysPath);
            };
            okCancelRow.Children.Add(apply);
            var cancel = new Button(game)
            {
                Text = "Back"
            };

            okCancelRow.Children.Add(cancel);
            cancel.OnClick += (snder, e) =>
            {
                retVal.InvokeEscape();
            };
            retVal.UpdateLayout(retVal.Bounds);
            return(retVal);
        }
        /// <summary>
        /// A screen for changing the options
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen DifficultySelectScreen(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                Purpose = ScreenPurpose.Options
            };

            retVal.Escape += (sender, e) =>
            {
                g1.UI.CloseTopScreen();
            };
            var spLabel = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };

            retVal.Children.Add(spLabel);
            var optionsLabel = new TextPanel(game)
            {
                Text             = "New game",
                Width            = 128,
                SpriteBackground = false
            };

            spLabel.Children.Add(optionsLabel);
            var spMenu = new StackPanel(game)
            {
                HAnchor        = HorizontalAnchor.Middle,
                VAnchor        = VerticalAnchor.Middle,
                MainNavigation = true
            };

            spLabel.Children.Add(spMenu);
            var difficulty = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Middle,
                ChildrenShareFocus = true,
                SpriteBackground   = true,
                Border             = 4
            };

            spMenu.Children.Add(difficulty);
            var diffLabel = new TextPanel(game)
            {
                Text             = "Difficulty",
                Width            = 32,
                SpriteBackground = false
            };

            difficulty.Children.Add(diffLabel);
            var diffSlide = new Slider(game)
            {
                Value         = 0,
                Minimum       = 0,
                Maximum       = 20,
                IncrementSize = 1
            };

            diffSlide.ValueChanged += (sender, e) =>
            {
            };
            difficulty.Children.Add(diffSlide);
            //
            var speed = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Left,
                ChildrenShareFocus = true,
                SpriteBackground   = true,
                Border             = 4,
                Width = 128
            };

            spMenu.Children.Add(speed);
            var speedLabel = new TextPanel(game)
            {
                Text             = "Speed",
                Width            = 32,
                SpriteBackground = false
            };

            speed.Children.Add(speedLabel);
            var speedSlide = new Slider(game)
            {
                Width         = 32,
                Value         = 1,
                Minimum       = 1,
                Maximum       = 3,
                IncrementSize = 1
            };

            speedSlide.ValueChanged += (sender, e) =>
            {
            };
            speed.Children.Add(speedSlide);
            //
            var okCancelRow = new StackPanel(game)
            {
                HAnchor   = HorizontalAnchor.Middle,
                Direction = LayoutDirection.Horizontal
            };

            spMenu.Children.Add(okCancelRow);
            var cancel = new Button(game)
            {
                Text = "Back"
            };

            okCancelRow.Children.Add(cancel);
            cancel.OnClick += (snder, e) =>
            {
                retVal.InvokeEscape();
            };
            var newGame = new Button(game)
            {
                Text = "New Game"
            };

            newGame.OnClick += (snder, e) =>
            {
                g1.NewGame((int)diffSlide.Value, (int)speedSlide.Value);
            };
            okCancelRow.Children.Add(newGame);
            retVal.UpdateLayout(retVal.Bounds);
            return(retVal);
        }
示例#3
0
        /// <summary>
        /// A screen for viewing high scores
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen HighScoreScreen(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                Purpose = ScreenPurpose.Options
            };

            retVal.Escape += (sender, e) =>
            {
                g1.UI.CloseTopScreen();
            };
            var mainsp = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };

            retVal.Children.Add(mainsp);
            var scoreLabel = new TextPanel(game)
            {
                Text             = "High score",
                Width            = 128,
                SpriteBackground = false
            };

            mainsp.Children.Add(scoreLabel);
            int rank = 0;

            foreach (var item in g1.Score.Scores)
            {
                rank++;
                var scoresp = new StackPanel(game)
                {
                    Direction = LayoutDirection.Horizontal
                };
                mainsp.Children.Add(scoresp);
                var rankText = new TextPanel(game)
                {
                    Text             = rank.ToString(),
                    Height           = 8,
                    Width            = 8,
                    SpriteBackground = false
                };
                scoresp.Children.Add(rankText);
                var name = new TextPanel(game)
                {
                    Text             = item.Item1,
                    SpriteBackground = false,
                    Height           = 8
                };
                scoresp.Children.Add(name);
                var score = new TextPanel(game)
                {
                    Text             = item.Item2.ToString(),
                    SpriteBackground = false,
                    Height           = 8
                };
                scoresp.Children.Add(score);
            }
            //
            var buttonRow = new StackPanel(game)
            {
                Direction      = LayoutDirection.Vertical,
                MainNavigation = true
            };

            mainsp.Children.Add(buttonRow);
            var back = new Button(game)
            {
                Text = "Back"
            };

            buttonRow.Children.Add(back);
            back.OnClick += (snder, e) =>
            {
                retVal.InvokeEscape();
            };
            retVal.UpdateLayout(retVal.Bounds);
            return(retVal);
        }