Exemple #1
0
        /// <summary>
        /// The game HUD, in screen form
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen GameHUDScreen(Game game)
        {
            Game1 g1 = (Game1)game;
            //TODO: Put any HUD stuff here
            var retVal = new UIScreen(game)
            {
                Purpose = ScreenPurpose.HUD
            };

            retVal.Escape += (sender, e) =>
            {
                //g1.UI.TogglePause();
            };
            var sp = new StackPanel(game)
            {
                HAnchor = HorizontalAnchor.Left,
                VAnchor = VerticalAnchor.Top
            };

            retVal.Children.Add(sp);
            var score = new TextPanel(game)
            {
                Text = "score"
            };

            sp.Children.Add(score);
            score.UpdateEvent += (sender, e) =>
            {
                score.Text = $"Score: {g1.Board.Points}";
            };
            var lvl = new TextPanel(game)
            {
                Text = "lvl"
            };

            sp.Children.Add(lvl);
            lvl.UpdateEvent += (sender, e) =>
            {
                lvl.Text = $"Level: {g1.Board.CurrentLevel}";
            };
            var virus = new TextPanel(game)
            {
                Text = "virus"
            };

            sp.Children.Add(virus);
            virus.UpdateEvent += (sender, e) =>
            {
                virus.Text = $"Viruses: {g1.Board.VirusCount}";
            };
            var speed = new TextPanel(game)
            {
                Text = "0"
            };

            sp.Children.Add(speed);
            sp.Children[^ 1].UpdateEvent += (sender, e) =>
Exemple #2
0
        public static UIScreen GameOverScreen(Game game)
        {
            var retVal = new UIScreen(game)
            {
                ScreenBelowVisible = true
            };

            retVal.Purpose = ScreenPurpose.PauseMenu;
            var spLabel = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };
            var spMenu = new StackPanel(game)
            {
                MainNavigation = true
            };

            retVal.Children.Add(spLabel);
            var go = new TextPanel(game)
            {
                Text             = "Game Over",
                SpriteBackground = false
            };

            spLabel.Children.Add(go);
            var score = new TextPanel(game)
            {
                Text             = $"You scored {((Game1)game).Board.Points} points",
                SpriteBackground = false
            };

            spLabel.Children.Add(score);
            spLabel.Children.Add(spMenu);
            //var ng = new Button(game)
            //{
            //	Text = "New Game"
            //};
            //spMenu.Children.Add(ng);
            //spMenu.Children[^1].OnClick += (snder, e) =>
            //{
            //	if (game is Game1 g1)
            //	{
            //		g1.NewGame();
            //	}
            //};
            var q = new Button(game)
            {
                Text = "Quit"
            };

            spMenu.Children.Add(q);
            spMenu.Children[^ 1].OnClick += (snder, e) =>
        public static UIScreen AllLevelsCompleteScreen(Game game)
        {
            var retVal = new UIScreen(game);

            retVal.Purpose = ScreenPurpose.PauseMenu;
            var spLabel = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };
            var spMenu = new StackPanel(game)
            {
                MainNavigation = true
            };

            retVal.Children.Add(spLabel);
            var go = new TextPanel(game)
            {
                Text             = "Sorry, no more levels",
                SpriteBackground = false
            };

            spLabel.Children.Add(go);
            //var score = new TextPanel(game)
            //{
            //	Text = $"You scored {((Game1)game).Score} points",
            //	SpriteBackground = false
            //};
            //spLabel.Children.Add(score);
            spLabel.Children.Add(spMenu);
            //var ng = new Button(game)
            //{
            //	Text = "Next level"
            //};
            //spMenu.Children.Add(ng);
            //spMenu.Children[^1].OnClick += (snder, e) =>
            //{
            //	if (game is Game1 g1)
            //	{
            //		g1.UI.CloseTopScreen();
            //		g1.EntMan.NextLevel();
            //	}
            //};
            var q = new Button(game)
            {
                Text = "Quit"
            };

            spMenu.Children.Add(q);
            spMenu.Children[^ 1].OnClick += (snder, e) =>
        public static UIScreen HighScoreNameEntryScreen(Game game)
        {
            var retVal = new UIScreen(game)
            {
                ScreenBelowVisible = true
            };

            retVal.Purpose = ScreenPurpose.PauseMenu;
            var spLabel = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };
            var spMenu = new StackPanel(game)
            {
                MainNavigation = true
            };

            retVal.Children.Add(spLabel);
            var go = new TextPanel(game)
            {
                Text             = "Game Over",
                SpriteBackground = false
            };

            spLabel.Children.Add(go);
            var score = new TextPanel(game)
            {
                Text             = $"You scored {((Game1)game).Board.Points} points, it's a new high score!\nEnter your name!",
                Width            = 128,
                SpriteBackground = false
            };

            spLabel.Children.Add(score);
            var name = new TextPanel(game)
            {
                Text  = "",
                Width = 128
            };

            ((Game1)game).Window.TextInput += (sender, e) =>
            {
                if (e.Key == Microsoft.Xna.Framework.Input.Keys.Back)
                {
                    name.Text = name.Text[0..^ 1];
                }
Exemple #5
0
        public static UIScreen UITestPlace(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                SpriteBackground   = false,
                ScreenBelowVisible = true,
                EscapeCloses       = true,
                BackgroundColor    = Color.Black * 0.5f
            };
            var keyThing = new TextPanel(game)
            {
                HAnchor = HorizontalAnchor.Left,
                VAnchor = VerticalAnchor.Top
            };

            keyThing.UpdateEvent += (sender, e) =>
            {
                var k = g1.Input.RecentKey();
                if (k != Microsoft.Xna.Framework.Input.Keys.None)
                {
                    keyThing.Text = k.ToString();
                }
            };
            retVal.Children.Add(keyThing);
            var inputThing = new TextPanel(game)
            {
                HAnchor = HorizontalAnchor.Left,
                VAnchor = VerticalAnchor.Middle
            };

            inputThing.UpdateEvent += (sender, e) =>
            {
                var input = g1.Input.RecentInput();
                if (input.Type != InputTypes.None)
                {
                    inputThing.Text = input.ToString();
                }
            };
            retVal.Children.Add(inputThing);
            //retVal.Children.Add(new UIPanel(game));
            //retVal.Children[^1].HAnchor = HorizontalAnchor.Left;
            //retVal.Children[^1].VAnchor = VerticalAnchor.Top;
            retVal.Children.Add(new Slider(game));
            retVal.Children[^ 1].HAnchor = HorizontalAnchor.Middle;
Exemple #6
0
        public static UIScreen LevelCompleteScreen(Game game)
        {
            var retVal = new UIScreen(game)
            {
                ScreenBelowVisible = true
            };

            retVal.Purpose = ScreenPurpose.PauseMenu;
            var spLabel = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };
            var spMenu = new StackPanel(game)
            {
                MainNavigation = true
            };

            retVal.Children.Add(spLabel);
            var go = new TextPanel(game)
            {
                Text             = "Level complete!",
                SpriteBackground = false
            };

            spLabel.Children.Add(go);
            //var score = new TextPanel(game)
            //{
            //	Text = $"You scored {((Game1)game).Score} points",
            //	SpriteBackground = false
            //};
            //spLabel.Children.Add(score);
            spLabel.Children.Add(spMenu);
            var ng = new Button(game)
            {
                Text = "Next level"
            };

            spMenu.Children.Add(ng);
            spMenu.Children[^ 1].OnClick += (snder, e) =>
Exemple #7
0
        public static UIScreen PauseScreen(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                EscapeCloses    = true,
                BackgroundColor = Color.Black * 0.5f
            };

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

            retVal.Children.Add(spLabel);
            var pLabel = new TextPanel(game)
            {
                Text             = "Pause",
                SpriteBackground = false
            };

            spLabel.Children.Add(pLabel);
            spLabel.Children.Add(spMenu);
            var resume = new Button(game)
            {
                Text = "Resume"
            };

            spMenu.Children.Add(resume);
            spMenu.Children[^ 1].OnClick += (snder, e) =>
        /// <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);
        }
Exemple #9
0
        /// <summary>
        /// A screen for changing keybinds
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen ControllerOptionsScreen(Game game)
        {
            Game1 g1 = (Game1)game;

            g1.Input.SetRevertState();
            var retVal = new UIScreen(game)
            {
                //EscapeCloses = true
            };
            List <KeybindPanel> kbPanels = new List <KeybindPanel>();

            retVal.Escape += (sender, e) =>
            {
                foreach (var item in kbPanels)
                {
                    if (item.Active)
                    {
                        return;
                    }
                }
                if (g1.Input.UnsavedChanges)
                {
                    g1.UI.OpenScreen(CloseKeybindsConfirmationScreen(game));
                }
                else
                {
                    g1.UI.CloseTopScreen();
                }
            };
            var spLabel = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };
            var label = new TextPanel(game)
            {
                Text             = "Controller settings",
                HAnchor          = HorizontalAnchor.Middle,
                SpriteBackground = false
            };

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

            spLabel.Children.Add(spMenu);
            foreach (var action in g1.Input.BindableActions)
            {
                var row = new StackPanel(game)
                {
                    Direction          = LayoutDirection.Horizontal,
                    ChildrenShareFocus = true
                };
                var actionName = new TextPanel(game)
                {
                    Text             = action.ToString(),
                    SpriteBackground = false,
                    Width            = 48
                };
                var keythingy = new KeybindPanel(game)
                {
                    //Input = g1.Input.GetKeybind(action),
                    Action = action,
                    Width  = 80,
                    Filter = new InputTypes[] { InputTypes.Controller }
                };
                keythingy.SetText();
                keythingy.KeyAssigned += (sender, e) =>
                {
                    foreach (var item in kbPanels)
                    {
                        item.SetText();
                    }
                };
                kbPanels.Add(keythingy);
                row.Children.Add(actionName);
                row.Children.Add(keythingy);
                spMenu.Children.Add(row);
            }
            //var moveStickSP = new StackPanel(game)
            //{
            //	Direction = LayoutDirection.Horizontal,
            //	SpriteBackground = false,
            //	ChildrenShareFocus = true
            //};
            //var moveStickLabel = new TextPanel(game)
            //{
            //	Text = "Move stick",
            //	SpriteBackground = false
            //};
            //moveStickSP.Children.Add(moveStickLabel);
            //var moveStickSelect = new SelectBox(game);
            //moveStickSelect.Options.Add(new SelectBoxOption("Left stick", Sticks.Left));
            //moveStickSelect.Options.Add(new SelectBoxOption("Right stick", Sticks.Right));
            //if (g1.Input.MovementStick == Sticks.Left)
            //{
            //	moveStickSelect.Selected = 0;
            //}
            //else
            //{
            //	moveStickSelect.Selected = 1;
            //}
            //moveStickSelect.SelectionChanged += (sender, e) =>
            //{
            //	if (moveStickSelect.SelectedOption.Value is Sticks stick)
            //	{
            //		g1.Input.MovementStick = stick;
            //	}
            //};
            //moveStickSP.Children.Add(moveStickSelect);
            //spMenu.Children.Add(moveStickSP);

            //var aimStickSP = new StackPanel(game)
            //{
            //	Direction = LayoutDirection.Horizontal,
            //	SpriteBackground = false,
            //	ChildrenShareFocus = true
            //};
            //var aimStickLabel = new TextPanel(game)
            //{
            //	Text = "Aim stick",
            //	SpriteBackground = false
            //};
            //aimStickSP.Children.Add(aimStickLabel);
            //var aimStickSelect = new SelectBox(game);
            //aimStickSelect.Options.Add(new SelectBoxOption("Left stick", Sticks.Left));
            //aimStickSelect.Options.Add(new SelectBoxOption("Right stick", Sticks.Right));
            //if (g1.Input.AimStick == Sticks.Left)
            //{
            //	aimStickSelect.Selected = 0;
            //}
            //else
            //{
            //	aimStickSelect.Selected = 1;
            //}
            //aimStickSelect.SelectionChanged += (sender, e) =>
            //{
            //	if (aimStickSelect.SelectedOption.Value is Sticks stick)
            //	{
            //		g1.Input.AimStick = stick;
            //	}
            //};
            //aimStickSP.Children.Add(aimStickSelect);
            //spMenu.Children.Add(aimStickSP);
            var defaultButton = new Button(game)
            {
                Text    = "Use defaults",
                HAnchor = HorizontalAnchor.Right
            };

            defaultButton.OnClick += (sender, e) =>
            {
                g1.Input.SetDefaultKeys();
                foreach (var item in kbPanels)
                {
                    item.SetText();
                }
            };
            spMenu.Children.Add(defaultButton);
            var closeButtons = new StackPanel(game)
            {
                Direction = LayoutDirection.Horizontal
            };
            var saveButton = new Button(game)
            {
                Text = "Save & close"
            };

            saveButton.OnClick += (sender, e) =>
            {
                g1.Input.SaveKeybinds(g1.Config.KeysFilePath);
                g1.UI.CloseTopScreen();
            };
            var dontsaveButton = new Button(game)
            {
                Text = "Close without saving"
            };

            dontsaveButton.OnClick += (sender, e) =>
            {
                g1.Input.RevertChanges();
                g1.UI.CloseTopScreen();
            };
            closeButtons.Children.Add(saveButton);
            closeButtons.Children.Add(dontsaveButton);
            spMenu.Children.Add(closeButtons);
            retVal.Children.Add(spLabel);
            retVal.UpdateLayout(retVal.Bounds);
            return(retVal);
        }
Exemple #10
0
        /// <summary>
        /// A screen for changing keybinds
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen KeybindsScreen(Game game)
        {
            Game1 g1 = (Game1)game;

            g1.Input.SetRevertState();
            var retVal = new UIScreen(game)
            {
                //EscapeCloses = true
            };
            List <KeybindPanel> kbPanels = new List <KeybindPanel>();

            retVal.Escape += (sender, e) =>
            {
                foreach (var item in kbPanels)
                {
                    if (item.Active)
                    {
                        return;
                    }
                }
                if (g1.Input.UnsavedChanges)
                {
                    g1.UI.OpenScreen(CloseKeybindsConfirmationScreen(game));
                }
                else
                {
                    g1.UI.CloseTopScreen();
                }
            };
            var spLabel = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };
            var label = new TextPanel(game)
            {
                Text             = "Keybinds",
                HAnchor          = HorizontalAnchor.Middle,
                SpriteBackground = false
            };

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

            spLabel.Children.Add(spMenu);
            foreach (var action in g1.Input.BindableActions)
            {
                var row = new StackPanel(game)
                {
                    Direction          = LayoutDirection.Horizontal,
                    ChildrenShareFocus = true
                };
                var actionName = new TextPanel(game)
                {
                    Text             = action.ToString(),
                    SpriteBackground = false,
                    Width            = 48
                };
                var keythingy = new KeybindPanel(game)
                {
                    //Input = g1.Input.GetKeybind(action),
                    Action = action,
                    Width  = 80,
                    Filter = new InputTypes[] { InputTypes.Keyboard, InputTypes.Mouse }
                };
                keythingy.SetText();
                keythingy.KeyAssigned += (sender, e) =>
                {
                    foreach (var item in kbPanels)
                    {
                        item.SetText();
                    }
                };
                kbPanels.Add(keythingy);
                row.Children.Add(actionName);
                row.Children.Add(keythingy);
                spMenu.Children.Add(row);
            }
            var defaultButton = new Button(game)
            {
                Text    = "Use defaults",
                HAnchor = HorizontalAnchor.Right
            };

            defaultButton.OnClick += (sender, e) =>
            {
                g1.Input.SetDefaultKeys();
                foreach (var item in kbPanels)
                {
                    item.SetText();
                }
            };
            spMenu.Children.Add(defaultButton);
            var closeButtons = new StackPanel(game)
            {
                Direction = LayoutDirection.Horizontal
            };
            var saveButton = new Button(game)
            {
                Text = "Save & close"
            };

            saveButton.OnClick += (sender, e) =>
            {
                g1.Input.SaveKeybinds(g1.Config.KeysFilePath);
                g1.UI.CloseTopScreen();
            };
            var dontsaveButton = new Button(game)
            {
                Text = "Close without saving"
            };

            dontsaveButton.OnClick += (sender, e) =>
            {
                g1.Input.RevertChanges();
                g1.UI.CloseTopScreen();
            };
            closeButtons.Children.Add(saveButton);
            closeButtons.Children.Add(dontsaveButton);
            spMenu.Children.Add(closeButtons);
            retVal.Children.Add(spLabel);
            retVal.UpdateLayout(retVal.Bounds);
            return(retVal);
        }
Exemple #11
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 that asks if you want to save changes when closing the keybinds screen.
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen CloseKeybindsConfirmationScreen(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                EscapeCloses = true
            };
            var sp = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };

            retVal.Children.Add(sp);
            var label1 = new TextPanel(game)
            {
                Text             = "Keybinds changed",
                SpriteBackground = false
            };

            sp.Children.Add(label1);
            var label2 = new TextPanel(game)
            {
                Text             = "Save changes?",
                SpriteBackground = false
            };

            sp.Children.Add(label2);
            var buttonRow = new StackPanel(game)
            {
                Direction      = LayoutDirection.Horizontal,
                MainNavigation = true
            };

            sp.Children.Add(buttonRow);
            var saveButton = new Button(game)
            {
                Text  = "Save",
                Width = 48
            };

            saveButton.OnClick += (snder, e) =>
            {
                g1.Input.SaveKeybinds(g1.Config.KeysFilePath);
                g1.UI.CloseTopScreen();
                g1.UI.CloseTopScreen();
            };
            buttonRow.Children.Add(saveButton);
            var discardButton = new Button(game)
            {
                Text  = "Discard",
                Width = 48
            };

            discardButton.OnClick += (snder, e) =>
            {
                g1.Input.RevertChanges();
                g1.UI.CloseTopScreen();
                g1.UI.CloseTopScreen();
            };
            buttonRow.Children.Add(discardButton);
            var cancelButton = new Button(game)
            {
                Text  = "Cancel",
                Width = 48
            };

            cancelButton.OnClick += (snder, e) =>
            {
                g1.UI.CloseTopScreen();
            };
            buttonRow.Children.Add(cancelButton);

            retVal.UpdateLayout(retVal.Bounds);
            return(retVal);
        }
Exemple #13
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);
        }
Exemple #14
0
        /// <summary>
        /// The main menu
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen MainMenuScreen(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                Purpose = ScreenPurpose.MainMenu
            };
            var spFull = new StackPanel(game)
            {
                HAnchor = HorizontalAnchor.Middle,
                VAnchor = VerticalAnchor.Middle,
            };
            var title = new TextPanel(game)
            {
                Text = "Puzzle Game"
            };

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

            spFull.Children.Add(spMenu);
            retVal.Children.Add(spFull);
            var ng = new Button(game)
            {
                Text = "New game"
            };

            ng.OnClick += (sender, e) =>
            {
                g1.UI.OpenScreen(DifficultySelectScreen(game));
            };
            spMenu.Children.Add(ng);
            //
            var hs = new Button(game)
            {
                Text = "High scores"
            };

            hs.OnClick += (sender, e) =>
            {
                g1.UI.OpenScreen(HighScoreScreen(game));
            };
            spMenu.Children.Add(hs);
            var opt = new Button(game)
            {
                Text = "Options"
            };

            opt.OnClick += (sender, e) =>
            {
                g1.UI.OpenScreen(OptionsScreen(game));
            };
            spMenu.Children.Add(opt);

            var q = new Button(game)
            {
                Text = "Quit"
            };

            spMenu.Children.Add(q);
            spMenu.Children[^ 1].OnClick += (sender, e) =>
Exemple #15
0
        /// <summary>
        /// A screen for changing the options
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen GlobalVarsScreen(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                Purpose      = ScreenPurpose.Options,
                EscapeCloses = true
            };

            retVal.Escape += (sender, e) =>
            {
            };
            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             = "stuff",
                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 move = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Middle,
                ChildrenShareFocus = true,
                SpriteBackground   = true,
                Border             = 4
            };

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

            move.Children.Add(moveLabel);
            var moveSlide = new Slider(game)
            {
                Value   = GlobalVarsHolder.PlayerRunSpeed,
                Minimum = 50,
                Maximum = 1000
            };

            moveSlide.ValueChanged += (sender, e) =>
            {
                GlobalVarsHolder.PlayerRunSpeed = moveSlide.Value;
            };
            move.Children.Add(moveSlide);

            var jump = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Middle,
                ChildrenShareFocus = true,
                SpriteBackground   = true,
                Border             = 4
            };

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

            jump.Children.Add(jumpLabel);
            var jumpSlide = new Slider(game)
            {
                Value   = -GlobalVarsHolder.PlayerJump,
                Minimum = 50,
                Maximum = 1000
            };

            jumpSlide.ValueChanged += (sender, e) =>
            {
                GlobalVarsHolder.PlayerJump = -jumpSlide.Value;
            };
            jump.Children.Add(jumpSlide);

            var gravity = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Middle,
                ChildrenShareFocus = true,
                SpriteBackground   = true,
                Border             = 4
            };

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

            gravity.Children.Add(gravityLabel);
            var gravitySlide = new Slider(game)
            {
                Value         = GlobalVarsHolder.Gravity,
                Minimum       = 100,
                Maximum       = 2000,
                IncrementSize = 50
            };

            gravitySlide.ValueChanged += (sender, e) =>
            {
                GlobalVarsHolder.Gravity = gravitySlide.Value;
            };
            gravity.Children.Add(gravitySlide);

            var terminalVelocity = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Middle,
                ChildrenShareFocus = true,
                SpriteBackground   = true,
                Border             = 4
            };

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

            terminalVelocity.Children.Add(terminalVelocityLabel);
            var terminalVelocitySlide = new Slider(game)
            {
                Value   = GlobalVarsHolder.TerminalVelocity,
                Minimum = 500,
                Maximum = 1000
            };

            terminalVelocitySlide.ValueChanged += (sender, e) =>
            {
                GlobalVarsHolder.TerminalVelocity = terminalVelocitySlide.Value;
            };
            terminalVelocity.Children.Add(terminalVelocitySlide);

            var foo3000 = new StackPanel(game)
            {
                Direction          = LayoutDirection.Horizontal,
                HAnchor            = HorizontalAnchor.Middle,
                ChildrenShareFocus = true,
                SpriteBackground   = true,
                Border             = 4
            };

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

            foo3000.Children.Add(foo3000Label);
            var foo3000Slide = new Slider(game)
            {
                Value   = 50,
                Minimum = -100,
                Maximum = 100
            };

            foo3000Slide.ValueChanged += (sender, e) =>
            {
                //GlobalVarsHolder.TerminalVelocity = foo3000Slide.Value;
            };
            foo3000.Children.Add(foo3000Slide);

            retVal.UpdateLayout(retVal.Bounds);
            return(retVal);
        }