Пример #1
0
        /// <summary>
        /// Update the scene
        /// </summary>
        /// <param name="time"></param>
        /// <param name="hasFocus"></param>
        /// <param name="isCovered"></param>
        public override void Update(GameTime time, bool hasFocus, bool isCovered)
        {
            // Go back to the main menu
            if (Keyboard.IsNewKeyPress(Keys.Escape))
            {
                ScreenManager.AddScreen(new MainMenu());
                ExitScreen();
            }


            switch (CurrentState)
            {
                #region Select hero
            case CharGenStates.SelectHero:
                if (Mouse.IsButtonDown(MouseButtons.Left))
                {
                    for (int id = 0; id < 4; id++)
                    {
                        if (HeroeBoxes[id].Contains(Mouse.Location))
                        {
                            HeroID = id;

                            // Create a new hero or remove it
                            if (Heroes[id] == null)
                            {
                                Heroes[id] = new Hero();

                                CurrentState = CharGenStates.SelectRace;
                            }
                            else
                            {
                                CurrentState = CharGenStates.Delete;
                            }
                        }
                    }
                }
                break;
                #endregion

                #region Select race
            case CharGenStates.SelectRace:
            {
                Point point = new Point(302, 160);
                for (int i = 0; i < 12; i++)
                {
                    if (new Rectangle(point.X, point.Y, 324, 16).Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))
                    {
                        CurrentHero.Race   = (HeroRace)Enum.GetValues(typeof(HeroRace)).GetValue(i / 2);
                        CurrentHero.Gender = (HeroGender)(i % 2);
                        CurrentState       = CharGenStates.SelectClass;
                    }

                    point.Y += 18;
                }
            }
            break;
                #endregion

                #region Select class
            case CharGenStates.SelectClass:
            {
                Point point = new Point(304, 0);

                var currentAllowedClasses = AllowedClass[CurrentHero.Race];
                for (int i = 0; i < currentAllowedClasses.Count(); i++)
                {
                    point.Y = 160 + i * 18;
                    if (new Rectangle(point.X, point.Y, 324, 16).Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))
                    {
                        CurrentHero.Professions.Clear();
                        foreach (HeroClass cls in Enum.GetValues(typeof(HeroClass)))
                        {
                            if ((currentAllowedClasses[i] & cls) != 0)
                            {
                                CurrentHero.Professions.Add(new Profession(0, currentAllowedClasses[i]));
                            }
                        }
                        CurrentState = CharGenStates.SelectAlignment;
                    }

                    // Back
                    if (BackButton.Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))
                    {
                        CurrentState = CharGenStates.SelectRace;
                    }
                }
            }
            break;
                #endregion

                #region Select alignment
            case CharGenStates.SelectAlignment:
            {
                Point point = new Point(304, 0);
                for (int i = 0; i < 9; i++)
                {
                    point.Y = 176 + i * 18;
                    if (new Rectangle(point.X, point.Y, 324, 16).Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))
                    {
                        EntityAlignment[] alignments = new EntityAlignment[]
                        {
                            EntityAlignment.LawfulGood,
                            EntityAlignment.NeutralGood,
                            EntityAlignment.ChaoticGood,
                            EntityAlignment.LawfulNeutral,
                            EntityAlignment.TrueNeutral,
                            EntityAlignment.ChaoticNeutral,
                            EntityAlignment.LawfulEvil,
                            EntityAlignment.NeutralEvil,
                            EntityAlignment.ChaoticEvil,
                        };

                        CurrentHero.Alignment = alignments[i];
                        CurrentHero.RollAbilities();
                        CurrentState = CharGenStates.SelectFace;
                    }
                }

                // Back
                if (BackButton.Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))
                {
                    CurrentState = CharGenStates.SelectClass;
                }
            }
            break;
                #endregion

                #region Select face
            case CharGenStates.SelectFace:
            {
                if (Mouse.IsNewButtonDown(MouseButtons.Left))
                {
                    if (new Rectangle(288, 132, 64, 32).Contains(Mouse.Location))
                    {
                        FaceOffset--;
                    }

                    if (new Rectangle(288, 164, 64, 32).Contains(Mouse.Location))
                    {
                        FaceOffset++;
                    }

                    // Select a face
                    for (int x = 0; x < 4; x++)
                    {
                        if (new Rectangle(352 + x * 64, 132, 64, 64).Contains(Mouse.Location))
                        {
                            CurrentHero.Head = FaceOffset + x;
                            CurrentState     = CharGenStates.Confirm;
                            break;
                        }
                    }
                }


                // Limit value
                if (CurrentHero.Gender == HeroGender.Male)
                {
                    if (FaceOffset < 0)
                    {
                        FaceOffset = 0;
                    }

                    if (FaceOffset > 25)
                    {
                        FaceOffset = 25;
                    }
                }
                else
                {
                    if (FaceOffset < 29)
                    {
                        FaceOffset = 29;
                    }

                    if (FaceOffset > 40)
                    {
                        FaceOffset = 40;
                    }
                }

                // Back
                if (BackButton.Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))
                {
                    CurrentState = CharGenStates.SelectAlignment;
                }
            }
            break;
                #endregion

                #region Confirm
            case CharGenStates.Confirm:
            {
                if (Mouse.IsNewButtonDown(MouseButtons.Left))
                {
                    // Reroll
                    if (new Rectangle(448, 318, 76, 32).Contains(Mouse.Location))
                    {
                        CurrentHero.RollAbilities();
                    }

                    // Faces
                    if (new Rectangle(448, 350, 76, 32).Contains(Mouse.Location))
                    {
                        CurrentHero.Head = -1;
                        CurrentState     = CharGenStates.SelectFace;
                    }

                    // Modify
                    if (new Rectangle(528, 316, 76, 32).Contains(Mouse.Location))
                    {
                    }

                    // Keep
                    if (new Rectangle(528, 350, 76, 32).Contains(Mouse.Location))
                    {
                        CurrentState      = CharGenStates.SelectName;
                        CurrentHero.Name  = GetRandomName(CurrentHero.Race, CurrentHero.Gender);
                        Keyboard.KeyDown += new EventHandler <PreviewKeyDownEventArgs>(Keyboard_OnKeyDown);
                    }
                }
            }
            break;
                #endregion

                #region Select name
            case CharGenStates.SelectName:
            {
                // Back
                //if (BackButton.Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))
                if (new Rectangle(448, 350, 80, 32).Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))
                {
                    CurrentState      = CharGenStates.Confirm;
                    Keyboard.KeyDown -= Keyboard_OnKeyDown;
                }

                // OK
                if (new Rectangle(528, 350, 80, 32).Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))
                {
                    Keyboard.KeyDown -= new EventHandler <PreviewKeyDownEventArgs>(Keyboard_OnKeyDown);
                    CurrentState      = CharGenStates.SelectHero;
                }
            }
            break;
                #endregion

                #region Delete hero
            case CharGenStates.Delete:
            {
                if (Mouse.IsNewButtonDown(MouseButtons.Left))
                {
                    // Delete
                    if (new Rectangle(448, 344, 76, 32).Contains(Mouse.Location))
                    {
                        Heroes[HeroID] = null;
                        CurrentState   = CharGenStates.SelectHero;
                    }

                    // Ok
                    if (new Rectangle(528, 344, 76, 32).Contains(Mouse.Location))
                    {
                        CurrentState = CharGenStates.SelectHero;
                    }
                }
            }
            break;
                #endregion
            }

            // Update anim
            if (Anims != null)
            {
                Anims.Update(time);
            }


            // If the team is ready, let's go !
            if (PlayButton.Rectangle.Contains(Mouse.Location) && Mouse.IsNewButtonDown(MouseButtons.Left))            // && IsTeamReadyToPlay)
            {
                PrepareTeam();
                PlayButton.OnSelectEntry();
            }
        }