Пример #1
0
 public Choice(Game1.ACTION act, Vector2 pos, string k, Game1.SCREEN destination = Game1.SCREEN.NULL)
 {
     action    = act;
     position  = pos;
     key       = k;
     fontColor = Color.White;
 }
Пример #2
0
        public Game1.ACTION Update(Game1.SCREEN scr)
        {
            Game1.ACTION action       = Game1.ACTION.NULL;
            bool         preventInput = false;

            if (curScreen != scr)
            {
                preventInput = true;
                iconPosition = 0;
                curScreen    = scr;
                switch (scr)
                {
                case Game1.SCREEN.MAIN:
                    title          = "MAIN MENU";
                    currentChoices = mainChoices;
                    break;

                case Game1.SCREEN.HIGH_SCORES:
                    title          = "HIGH SCORES";
                    currentChoices = subscreenChoices;
                    break;

                case Game1.SCREEN.CONTROLS:
                    title          = "CONTROL CONFIGURATION";
                    currentChoices = controlChoices;
                    break;

                case Game1.SCREEN.CREDITS:
                    title          = "CREDITS";
                    currentChoices = subscreenChoices;
                    break;

                case Game1.SCREEN.PLAY:
                    title          = "";
                    currentChoices = new Choice[0];
                    break;

                case Game1.SCREEN.QUIT:
                    title          = "ARE YOU SURE YOU WANT TO QUIT?";
                    currentChoices = quitChoices;
                    break;

                case Game1.SCREEN.LOSE:
                    title          = "MISSION FAILED";
                    currentChoices = lossChoices;
                    break;
                }
            }
            else
            {
                preventInput = false;
            }

            if (!preventInput && !stopFunction)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    action = Game1.ACTION.QUIT;
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.Enter) && scr != Game1.SCREEN.PLAY)
                {
                    action       = currentChoices[iconPosition].action;
                    stopFunction = true;
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.Down))
                {
                    iconPosition += (iconPosition + 1) > currentChoices.Length - 1 ? 0 : 1;
                    stopFunction  = true;
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.Up))
                {
                    iconPosition -= (iconPosition - 1) < 0 ? 0 : 1;
                    stopFunction  = true;
                }

                //Mouse Control
                MouseState mouseState = Mouse.GetState();
                if (mouseState.X > defaultPositionX[1])
                {
                    if (currentChoices.Length >= 1)
                    {
                        if (mouseState.Y > defaultPositionsY[1] && mouseState.Y < defaultPositionsY[2])
                        {
                            currentChoices[0].fontColor = fontColorActive;
                        }
                        else
                        {
                            currentChoices[0].fontColor = fontColorInactive;
                        }
                    }
                    if (currentChoices.Length >= 2)
                    {
                        if (mouseState.Y > defaultPositionsY[2] && mouseState.Y < defaultPositionsY[3])
                        {
                            currentChoices[1].fontColor = fontColorActive;
                        }
                        else
                        {
                            currentChoices[1].fontColor = fontColorInactive;
                        }
                    }
                    if (currentChoices.Length >= 3)
                    {
                        if (mouseState.Y > defaultPositionsY[3] && mouseState.Y < defaultPositionsY[4])
                        {
                            currentChoices[2].fontColor = fontColorActive;
                        }
                        else
                        {
                            currentChoices[2].fontColor = fontColorInactive;
                        }
                    }
                    if (currentChoices.Length >= 4)
                    {
                        if (mouseState.Y > defaultPositionsY[4] && mouseState.Y < defaultPositionsY[5])
                        {
                            currentChoices[3].fontColor = fontColorActive;
                        }
                        else
                        {
                            currentChoices[3].fontColor = fontColorInactive;
                        }
                    }
                    if (currentChoices.Length >= 5)
                    {
                        if (mouseState.Y > defaultPositionsY[5] && mouseState.Y < defaultPositionsY[6])
                        {
                            currentChoices[4].fontColor = fontColorActive;
                        }
                        else
                        {
                            currentChoices[4].fontColor = fontColorInactive;
                        }
                    }
                    if (currentChoices.Length >= 6)
                    {
                        if (mouseState.Y > defaultPositionsY[6] && mouseState.Y < defaultPositionsY[7])
                        {
                            currentChoices[5].fontColor = fontColorActive;
                        }
                        else
                        {
                            currentChoices[5].fontColor = fontColorInactive;
                        }
                    }
                    if (currentChoices.Length >= 7)
                    {
                        if (mouseState.Y > defaultPositionsY[7] && mouseState.Y < defaultPositionsY[8])
                        {
                            currentChoices[6].fontColor = fontColorActive;
                        }
                        else
                        {
                            currentChoices[6].fontColor = fontColorInactive;
                        }
                    }
                }

                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    for (int i = 0; i < currentChoices.Length; i++)
                    {
                        if (mouseState.X > defaultPositionX[1])
                        {
                            if (mouseState.Y > defaultPositionsY[i + 1] && mouseState.Y < defaultPositionsY[i + 2])
                            {
                                action       = currentChoices[i].action;
                                stopFunction = true;
                            }
                        }
                    }
                }
            }
            if (Keyboard.GetState().GetPressedKeyCount() == 0 && Mouse.GetState().LeftButton != ButtonState.Pressed)
            {
                stopFunction = false;
            }

            return(action);
        }