Beispiel #1
0
 public void AddTextBoxWithLabel(TextBox ctrl1, Label label)
 {
     ControlsList.Add(ctrl1);
     label.Position = new Rectangle(((TextBox)ctrl1).Position.X, ((TextBox)ctrl1).Position.Y - 26, label.Position.Width, label.Position.Height);
     ControlsList.Add(label);
 }
Beispiel #2
0
        public OptionsScreen()
        {
            Button doneButton = new Button(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width / 2 - (WidgetsMap.EnabledButton.RegionWidth),
                    MainGame.GlobalGraphicsDevice.Viewport.Height - 50, WidgetsMap.EnabledButton.RegionWidth * 2, WidgetsMap.EnabledButton.RegionHeight * 2), "Done", true);

            doneButton.Clicked += () =>
            {
                Control f = ControlsList.Find(x => x.Name == "usrnametb");
                if(f != null)
                {
                    if(!String.IsNullOrEmpty(((TextBox)f).Content))
                        MainGame.GameOptions.Username = ((TextBox)f).Content.Trim();
                    else if(String.IsNullOrEmpty(MainGame.GameOptions.Username))
                    {
                        MainGame.GameOptions.Username = $"Player{MainGame.RandomGenerator.Next(1000, 9000)}";
                    }

                }
                MainGame.manager.PushScreen(GameScreens.MAIN);
            };

            #region Key mapping
            Button MoveLeftMod = new Button(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width - 580,
                    MainGame.GlobalGraphicsDevice.Viewport.Height - 440, (WidgetsMap.EnabledButton.RegionWidth * 2) - 256, WidgetsMap.EnabledButton.RegionHeight * 2), MainGame.GameOptions.MoveLeft.ToString());
            MoveLeftMod.Clicked += () =>
            {
                new Thread(()=>
                {
                    while (MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys().Length == 0)
                    {
                        MoveLeftMod.ButtonText = "<waiting>";
                    }
                    if (MainGame.GlobalInputHelper.CurrentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
                        MainGame.GameOptions.MoveLeft = Microsoft.Xna.Framework.Input.Keys.None;
                    else
                    {
                        MainGame.GameOptions.MoveLeft = MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys()[0];
                    }
                    MoveLeftMod.ButtonText = MainGame.GameOptions.MoveLeft.ToString();
                }).Start();
            };

            Button MoveRightMod = new Button(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width - 380,
                    MainGame.GlobalGraphicsDevice.Viewport.Height - 440, (WidgetsMap.EnabledButton.RegionWidth * 2) - 256, WidgetsMap.EnabledButton.RegionHeight * 2), MainGame.GameOptions.MoveRight.ToString());
            MoveRightMod.Clicked += () =>
            {
                new Thread(() =>
                {
                    while (MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys().Length == 0)
                    {
                        MoveRightMod.ButtonText = "<waiting>";
                    }
                    if (MainGame.GlobalInputHelper.CurrentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
                        MainGame.GameOptions.MoveRight = Microsoft.Xna.Framework.Input.Keys.None;
                    else
                    {
                        MainGame.GameOptions.MoveRight = MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys()[0];
                    }
                    MoveRightMod.ButtonText = MainGame.GameOptions.MoveRight.ToString();
                }).Start();
            };

            Button MoveDownMod = new Button(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width - 580,
                    MainGame.GlobalGraphicsDevice.Viewport.Height - 370, (WidgetsMap.EnabledButton.RegionWidth * 2) - 256, WidgetsMap.EnabledButton.RegionHeight * 2), MainGame.GameOptions.MoveDown.ToString());
            MoveDownMod.Clicked += () =>
            {
                new Thread(() =>
                {
                    while (MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys().Length == 0)
                    {
                        MoveDownMod.ButtonText = "<waiting>";
                    }
                    if (MainGame.GlobalInputHelper.CurrentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
                        MainGame.GameOptions.MoveDown = Microsoft.Xna.Framework.Input.Keys.None;
                    else
                    {
                        MainGame.GameOptions.MoveDown = MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys()[0];
                    }
                    MoveDownMod.ButtonText = MainGame.GameOptions.MoveDown.ToString();
                }).Start();
            };

            Button MoveUpMod = new Button(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width - 380,
                    MainGame.GlobalGraphicsDevice.Viewport.Height - 370, (WidgetsMap.EnabledButton.RegionWidth * 2) - 256, WidgetsMap.EnabledButton.RegionHeight * 2), MainGame.GameOptions.MoveUp.ToString());
            MoveUpMod.Clicked += () =>
            {
                new Thread(() =>
                {
                    while (MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys().Length == 0)
                    {
                        MoveUpMod.ButtonText = "<waiting>";
                    }
                    if (MainGame.GlobalInputHelper.CurrentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
                        MainGame.GameOptions.MoveUp = Microsoft.Xna.Framework.Input.Keys.None;
                    else
                    {
                        MainGame.GameOptions.MoveUp = MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys()[0];
                    }
                    MoveUpMod.ButtonText = MainGame.GameOptions.MoveUp.ToString();
                }).Start();
            };

            Button JumpMod = new Button(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width - 470,
                    MainGame.GlobalGraphicsDevice.Viewport.Height - 300, (WidgetsMap.EnabledButton.RegionWidth * 2) - 256, WidgetsMap.EnabledButton.RegionHeight * 2), MainGame.GameOptions.JumpKey.ToString());
            JumpMod.Clicked += () =>
            {
                new Thread(() =>
                {
                    while (MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys().Length == 0)
                    {
                        JumpMod.ButtonText = "<waiting>";
                    }
                    if (MainGame.GlobalInputHelper.CurrentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
                        MainGame.GameOptions.JumpKey = Microsoft.Xna.Framework.Input.Keys.None;
                    else
                    {
                        MainGame.GameOptions.JumpKey = MainGame.GlobalInputHelper.CurrentKeyboardState.GetPressedKeys()[0];
                    }
                    JumpMod.ButtonText = MainGame.GameOptions.JumpKey.ToString();
                }).Start();
            };
            #endregion

            TextBox usernameTextBox = new TextBox(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width - 580, MainGame.GlobalGraphicsDevice.Viewport.Height - 230, 32 * 11, 32), true);
            usernameTextBox.Content = MainGame.GameOptions.Username;
            usernameTextBox.Name = "usrnametb";

            Button FullscreenButton = new Button(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width - 580,
                    MainGame.GlobalGraphicsDevice.Viewport.Height - (230 - 70), (WidgetsMap.EnabledButton.RegionWidth * 2) - 256, WidgetsMap.EnabledButton.RegionHeight * 2), MainGame.GameOptions.Fullscreen.ToString());
            //MainGame.GlobalGraphicsDevice.Viewport.Width - 580
            //Button FullscreenButton = new Button(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width - 470,
            //        MainGame.GlobalGraphicsDevice.Viewport.Height - (230 - 70), (WidgetsMap.EnabledButton.RegionWidth * 2) - 256, WidgetsMap.EnabledButton.RegionHeight * 2), MainGame.GameOptions.Fullscreen.ToString());
            FullscreenButton.Clicked += () =>
            {
                MainGame.GlobalGraphicsDeviceManager.IsFullScreen = !MainGame.GlobalGraphicsDeviceManager.IsFullScreen;
                MainGame.GlobalGraphicsDeviceManager.ApplyChanges();
                MainGame.GameOptions.Fullscreen = MainGame.GlobalGraphicsDeviceManager.IsFullScreen;

                FullscreenButton.ButtonText = MainGame.GameOptions.Fullscreen.ToString();
            };

            //MainGame.GlobalGraphicsDevice.Viewport.Width - 380
            Button DiscordButton = new Button(new Rectangle(MainGame.GlobalGraphicsDevice.Viewport.Width - 380,
                    MainGame.GlobalGraphicsDevice.Viewport.Height - (230 - 70), (WidgetsMap.EnabledButton.RegionWidth * 2) - 256, WidgetsMap.EnabledButton.RegionHeight * 2), "Discord");
            DiscordButton.Enabled = false;
            DiscordButton.Clicked += ()=>
            {
                usernameTextBox.IsPasswordField = !usernameTextBox.IsPasswordField;
            };

            AddControl(doneButton);
            AddButtonWithLabel(MoveLeftMod, new Label(name: "lbl", text: "Move Left", pos: Vector2.Zero, tnt: Color.Gray));
            AddButtonWithLabel(MoveRightMod, new Label(name: "lbl", text: "Move Right", pos: Vector2.Zero, tnt: Color.Gray));
            AddButtonWithLabel(MoveUpMod, new Label(name: "lbl", text: "Move Up", pos: Vector2.Zero, tnt: Color.Gray));
            AddButtonWithLabel(MoveDownMod, new Label(name: "lbl", text: "Move Down", pos: Vector2.Zero, tnt: Color.Gray));
            AddButtonWithLabel(JumpMod, new Label(name: "lbl", text: "Jump", pos: Vector2.Zero, tnt: Color.Gray));
            AddButtonWithLabel(FullscreenButton, new Label(name: "lbl", text: "Fullscreen", pos: Vector2.Zero, tnt: Color.Gray));
            AddButtonWithLabel(DiscordButton, new Label(name: "lbl", text: "Coming soon!", pos: Vector2.Zero, tnt: Color.Gray));
            AddTextBoxWithLabel(usernameTextBox, new Label(name: "lbl", text: "Username", pos: Vector2.Zero, tnt: Color.Gray));
        }