Beispiel #1
0
        internal virtual void ChoiceMenu(NaviState naviState, GameTime gameTime)
        {
            List <SpriteBase> tempList = new List <SpriteBase>();

            for (int i = 0; i < box.buttons.Count; i++)
            {
                tempList.Add(box.buttons[i]);
            }

            MenuUpdateReturn temp = naviState.MenuUpdate(tempList, index);

            index = temp.index;

            naviState.pointer.UpperLeft = new Vector2(box.buttons[index].UpperLeft.X + box.buttons[index].frameWidth + 15,
                                                      box.buttons[index].UpperLeft.Y + 5);
            naviState.pointer.isAlive = true;

            if (temp.activate)
            {
                EventButton tempButton = (EventButton)box.buttons[index];
                tempButton.action.Invoke(naviState, gameTime);
            }
        }
Beispiel #2
0
        internal MenuUpdateReturn MenuUpdate(List <SpriteBase> list, int index, List <SpriteBase> extraList)
        {
            if (index >= list.Count)
            {
                index = list.Count - 1;
            }

            pointer.isAlive = true;

            Rectangle buttonRect = new Rectangle((int)list[index].UpperLeft.X,
                                                 (int)list[index].UpperLeft.Y,
                                                 list[index].frameWidth,
                                                 list[index].frameHeight);

            if (mouseMoving)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].isAlive)
                    {
                        buttonRect = new Rectangle((int)list[i].UpperLeft.X,
                                                   (int)list[i].UpperLeft.Y,
                                                   list[i].frameWidth,
                                                   list[i].frameHeight);

                        if (buttonRect.Contains(mousePosition))
                        {
                            index = i;
                        }
                    }
                }
            }

            Rectangle extraButtonRect;

            if (extraList != null)
            {
                extraPointer.isAlive = true;

                extraButtonRect = new Rectangle((int)extraList[index].UpperLeft.X,
                                                (int)extraList[index].UpperLeft.Y,
                                                extraList[index].frameWidth,
                                                extraList[index].frameHeight);

                if (mouseMoving)
                {
                    for (int i = 0; i < extraList.Count; i++)
                    {
                        if (list[i].isAlive)
                        {
                            extraButtonRect = new Rectangle((int)extraList[i].UpperLeft.X,
                                                            (int)extraList[i].UpperLeft.Y,
                                                            extraList[i].frameWidth,
                                                            extraList[i].frameHeight);

                            if (extraButtonRect.Contains(mousePosition))
                            {
                                index = i;
                            }
                        }
                    }
                }
            }
            else
            {
                extraButtonRect = new Rectangle(0, 0, 0, 0);
            }

            if (!list[index].isAlive)
            {
                bool complete = false;

                for (int i = index; i >= 0; i--)
                {
                    if (list[i].isAlive)
                    {
                        index = i;

                        complete = true;

                        break;
                    }
                }

                if (!complete)
                {
                    for (int i = index; i < list.Count; i++)
                    {
                        if (list[i].isAlive)
                        {
                            index = i;

                            complete = true;

                            break;
                        }
                    }
                }
            }

            if (upInput.inputState == Input.inputStates.pressed)
            {
                index -= 1;

                if (index < 0)
                {
                    index = list.Count - 1;
                }

                while (!list[index].isAlive)
                {
                    index -= 1;

                    if (index < 0)
                    {
                        index = list.Count - 1;
                    }
                }
            }
            if (downInput.inputState == Input.inputStates.pressed)
            {
                index += 1;

                if (index > list.Count - 1)
                {
                    index = 0;
                }

                while (!list[index].isAlive)
                {
                    index += 1;

                    if (index > list.Count - 1)
                    {
                        index = 0;
                    }
                }
            }

            if (index < 0)
            {
                index = list.Count - 1;
            }
            if (index > list.Count - 1)
            {
                index = 0;
            }

            MenuUpdateReturn returnValue = new MenuUpdateReturn();

            returnValue.index = index;

            if (activateInput.inputState == Input.inputStates.pressed)
            {
                if (activateInput.inputType != Input.inputTypes.mouse | (buttonRect.Contains(mousePosition) || extraButtonRect.Contains(mousePosition)))
                {
                    returnValue.activate = true;
                }
            }
            else
            {
                returnValue.activate = false;
            }

            if (menuInput.inputState == Input.inputStates.pressed)
            {
                returnValue.menu = true;
            }
            else
            {
                returnValue.menu = false;
            }

            if (activateInput.inputState == Input.inputStates.pressed)
            {
                if (activateInput.inputType != Input.inputTypes.mouse | buttonRect.Contains(mousePosition))
                {
                    returnValue.activate = true;
                }
            }
            else
            {
                returnValue.activate = false;
            }

            return(returnValue);
        }