Esempio n. 1
0
        /// <summary>
        /// Update logic
        /// </summary>
        /// <param name="time"></param>
        /// <param name="hasFocus"></param>
        /// <param name="isCovered"></param>
        public override void Update(GameTime time, bool hasFocus, bool isCovered)
        {
            // No focus byebye
            if (!hasFocus)
            {
                return;
            }

            // Play sound
            //	if (Theme.State != AudioSourceState.Playing)
            //		Theme.Play();

            if (Keyboard.IsNewKeyPress(System.Windows.Forms.Keys.S))
            {
                Theme.Stop();
            }

            if (Keyboard.IsNewKeyPress(System.Windows.Forms.Keys.P))
            {
                Theme.Play();
            }


            // Does the default language changed ?
            if (Game.LanguageName != StringTable.LanguageName)
            {
                StringTable.LanguageName = Game.LanguageName;

                for (int id = 0; id < Buttons.Count; id++)
                {
                    Buttons[id].Text = StringTable.GetString(id + 1);
                }
            }


            // Mouse interaction
            Point mousePos = Mouse.Location;


            if (LoadGame == null)
            #region Main menu
            {
                for (int id = 0; id < Buttons.Count; id++)
                {
                    ScreenButton button = Buttons[id];

                    // Mouse over ?
                    if (button.Rectangle.Contains(mousePos))
                    {
                        //button.TextColor = Color.FromArgb(255, 85, 85);
                        MenuID = id;
                        if (Mouse.IsNewButtonDown(System.Windows.Forms.MouseButtons.Left))
                        {
                            button.OnSelectEntry();
                        }
                    }
                }

                // Bye bye
                if (Keyboard.IsNewKeyPress(System.Windows.Forms.Keys.Escape))
                {
                    Game.Exit();
                }

                // Run intro
                if (Keyboard.IsNewKeyPress(System.Windows.Forms.Keys.I))
                {
                    ScreenManager.AddScreen(new IntroScreen());
                }


                // Key up
                if (Keyboard.IsNewKeyPress(System.Windows.Forms.Keys.Up))
                {
                    MenuID--;
                    if (MenuID < 0)
                    {
                        MenuID = Buttons.Count - 1;
                    }
                }
                // Key down
                else if (Keyboard.IsNewKeyPress(System.Windows.Forms.Keys.Down))
                {
                    MenuID++;
                    if (MenuID >= Buttons.Count)
                    {
                        MenuID = 0;
                    }
                }
                // Enter
                else if (Keyboard.IsNewKeyPress(System.Windows.Forms.Keys.Enter))
                {
                    Buttons[MenuID].OnSelectEntry();
                }
            }
            #endregion
            else
            #region Load game
            {
                // Load a game
                LoadGame.Update(time);

                // A slot is selected
                if (LoadGame.SelectedSlot != -1)
                {
                    // close window
                    LoadGame.Close();

                    // Run the game
                    GameScreen scr = new GameScreen();
                    ScreenManager.AddScreen(scr);

                    // Load saved game
                    scr.LoadGameSlot(LoadGame.SelectedSlot);
                }


                // Close the window
                if (LoadGame.Closing)
                {
                    LoadGame = null;
                }
            }
            #endregion
        }