Example #1
0
        public void MouseMove()
        {
            MouseState ms        = Mouse.GetState();
            Vector2    mousePos  = Vector2.Transform(new Vector2(ms.X, ms.Y), Matrix.Invert(Resolution.ScaleMatrix));
            Rectangle  mouseRect = new Rectangle((int)mousePos.X, (int)mousePos.Y, 1, 1);

            if (currentMenu == MenuTag.MAIN)
            {
                foreach (Button button in menuButtons)
                {
                    if (button.visible)
                    {
                        if (mouseRect.Intersects(button.GetBounds()))
                        {
                            button.Hover(true);
                            if (ms.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
                            {
                                if (button.GetTag() == ButtonTag.LOGIN)
                                {
                                    currentMenu = MenuTag.LOGIN;
                                    userNameBox.changeFocus(true);
                                }
                                else if (button.GetTag() == ButtonTag.QUIT)
                                {
                                    game.Exit();
                                }
                                else if (button.GetTag() == ButtonTag.OPTIONS)
                                {
                                    currentMenu = MenuTag.OPTIONS;
                                }
                            }
                        }
                        else
                        {
                            button.Hover(false);
                        }
                    }
                }
            }
            else if (currentMenu == MenuTag.OPTIONS)
            {
                foreach (Button button in optionsButtons)
                {
                    if (button.visible)
                    {
                        if (mouseRect.Intersects(button.GetBounds()))
                        {
                            button.Hover(true);
                            if (ms.LeftButton == ButtonState.Pressed)
                            {
                                if (lastMouseState.LeftButton == ButtonState.Released)
                                {
                                    if (button.GetTag() == ButtonTag.BACK)
                                    {
                                        currentMenu = MenuTag.MAIN;
                                        game.SaveOptions();
                                    }
                                }
                                if (button.GetTag() == ButtonTag.MUSICUP)
                                {
                                    if (game.gameOptions.MUSIC_VOLUME + 0.005f <= 100)
                                    {
                                        game.gameOptions.MUSIC_VOLUME += 0.005f;
                                        optionsButtons[2].visible      = true;
                                    }
                                    else
                                    {
                                        game.gameOptions.MUSIC_VOLUME = 100;
                                        optionsButtons[2].visible     = false;
                                    }
                                    MediaPlayer.Volume = game.gameOptions.MUSIC_VOLUME;
                                }
                                else if (button.GetTag() == ButtonTag.MUSICDOWN)
                                {
                                    if (game.gameOptions.MUSIC_VOLUME - 0.005f >= 0)
                                    {
                                        game.gameOptions.MUSIC_VOLUME -= 0.005f;
                                        optionsButtons[1].visible      = true;
                                    }
                                    else
                                    {
                                        game.gameOptions.MUSIC_VOLUME = 0;
                                        optionsButtons[1].visible     = false;
                                    }
                                    MediaPlayer.Volume = game.gameOptions.MUSIC_VOLUME;
                                }
                                else if (button.GetTag() == ButtonTag.EFFECTUP)
                                {
                                    if (game.gameOptions.EFFECT_VOLUME + 0.005f <= 100)
                                    {
                                        game.gameOptions.EFFECT_VOLUME += 0.005f;
                                        optionsButtons[4].visible       = true;
                                    }
                                    else
                                    {
                                        game.gameOptions.EFFECT_VOLUME = 100;
                                        optionsButtons[4].visible      = false;
                                    }
                                }
                                else if (button.GetTag() == ButtonTag.EFFECTDOWN)
                                {
                                    if (game.gameOptions.EFFECT_VOLUME - 0.005f >= 0)
                                    {
                                        game.gameOptions.EFFECT_VOLUME -= 0.005f;
                                        optionsButtons[3].visible       = true;
                                    }
                                    else
                                    {
                                        game.gameOptions.EFFECT_VOLUME = 0;
                                        optionsButtons[3].visible      = false;
                                    }
                                }
                                else if (button.GetTag() == ButtonTag.RESOLUTIONUP)
                                {
                                    if (currentResolution == "1920x1080")
                                    {
                                        currentResolution = "1280x720";
                                        game.ReInitializeGraphics(1280, 720);
                                    }
                                    else if (currentResolution == "1280x720")
                                    {
                                        currentResolution = "1920x1080";
                                        game.ReInitializeGraphics(1920, 1080);
                                    }
                                }
                                else if (button.GetTag() == ButtonTag.RESOLUTIONDOWN)
                                {
                                    if (currentResolution == "1920x1080")
                                    {
                                        currentResolution = "1280x720";
                                        game.ReInitializeGraphics(1280, 720);
                                    }
                                    else if (currentResolution == "1280x720")
                                    {
                                        currentResolution = "1920x1080";
                                        game.ReInitializeGraphics(1920, 1080);
                                    }
                                }
                            }
                        }
                        else
                        {
                            button.Hover(false);
                        }
                    }
                }
            }
            else if (currentMenu == MenuTag.LOGIN)
            {
                if (ms.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
                {
                    if (mouseRect.Intersects(userNameBox.GetBounds()))
                    {
                        if (passWordBox.getFocus())
                        {
                            passWordBox.changeFocus(false);
                        }
                        userNameBox.changeFocus(true);
                    }
                    else if (mouseRect.Intersects(passWordBox.GetBounds()))
                    {
                        if (userNameBox.getFocus())
                        {
                            userNameBox.changeFocus(false);
                        }
                        passWordBox.changeFocus(true);
                    }
                }

                foreach (Button button in loginMenu)
                {
                    if (button.visible)
                    {
                        if (mouseRect.Intersects(button.GetBounds()))
                        {
                            button.Hover(true);
                            if (ms.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
                            {
                                if (button.GetTag() == ButtonTag.LOGIN)
                                {
                                    if (AttemptLogin())
                                    {
                                    }
                                }
                                else if (button.GetTag() == ButtonTag.BACK)
                                {
                                    currentMenu = MenuTag.MAIN;
                                    passWordBox.clear();
                                    userNameBox.clear();
                                }
                            }
                        }
                        else
                        {
                            button.Hover(false);
                        }
                    }
                }
            }
            else if (currentMenu == MenuTag.SERVERBROWSER)
            {
                foreach (Button button in serverBrowserButtons)
                {
                    if (mouseRect.Intersects(button.GetBounds()))
                    {
                        button.Hover(true);
                        if (ms.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
                        {
                            if (button.GetTag() == ButtonTag.BACK)
                            {
                                passWordBox.clear();
                                userNameBox.clear();
                                currentMenu = MenuTag.LOGIN;
                            }
                            else if (button.GetTag() == ButtonTag.REFRESH)
                            {
                                serverBrowser.Refresh();
                            }
                        }
                    }
                    else
                    {
                        button.Hover(false);
                    }
                }
            }
            else if (currentMenu == MenuTag.CHARACTERCREATION)
            {
                foreach (Button button in characterCreationButtons)
                {
                    if (mouseRect.Intersects(button.GetBounds()))
                    {
                        button.Hover(true);
                        if (ms.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
                        {
                            if (button.GetTag() == ButtonTag.LEFT)
                            {
                                if (selectedClass == CharacterSelections.characterSelections[0])
                                {
                                    selectedClass    = CharacterSelections.characterSelections[CharacterSelections.characterSelections.Length - 1];
                                    currentSelection = CharacterSelections.characterSelections.Length - 1;
                                }
                                else
                                {
                                    currentSelection--;
                                    selectedClass = CharacterSelections.characterSelections[currentSelection];
                                }
                                //textArea.SetText(ContentChest.Instance.descriptors[selectedClass - 1]);
                                //game.SetScreen(new GameScreen(game, playerName, IP, port, PlayerType.WARRIOR));
                                break;
                            }
                            else if (button.GetTag() == ButtonTag.RIGHT)
                            {
                                if (selectedClass == CharacterSelections.characterSelections[CharacterSelections.characterSelections.Length - 1])
                                {
                                    selectedClass    = CharacterSelections.characterSelections[0];
                                    currentSelection = 0;
                                }
                                else
                                {
                                    currentSelection++;
                                    selectedClass = CharacterSelections.characterSelections[currentSelection];
                                }
                                //textArea.SetText(ContentChest.Instance.descriptors[selectedClass - 1]);
                                break;
                            }
                            else if (button.GetTag() == ButtonTag.START)
                            {
                                game.SetScreen(new GameScreen(game, playerName, IP, port, selectedClass));
                                break;
                            }
                            else if (button.GetTag() == ButtonTag.QUIT)
                            {
                                game.SetScreen(new MenuScreen(game));
                                break;
                            }
                        }
                    }
                    else
                    {
                        button.Hover(false);
                    }
                }
            }

            lastMouseState = ms;
        }