Example #1
0
        private void handleKeyboard()
        {
            if (InputManager.KeyPressed(Keys.Up))
            {
                m_ActiveMenuItemIndex = (m_ActiveMenuItemIndex - 1) >= 0 ? (m_ActiveMenuItemIndex - 1) : (Menu.Count - 1);
            }
            else if (InputManager.KeyPressed(Keys.Down))
            {
                m_ActiveMenuItemIndex = (m_ActiveMenuItemIndex + 1) <= (Menu.Count - 1) ? (m_ActiveMenuItemIndex + 1) : 0;
            }
            else if (InputManager.KeyPressed(Keys.Enter))
            {
                if (m_ActiveMenuItemIndex >= 0)
                {
                    m_Menu[m_ActiveMenuItemIndex].RunMethod(Keys.Enter);
                }
            }

            if (m_ActiveMenuItemIndex > -1)
            {
                activateCurrentMenuItem();
                ToggleMenuItem toggleItem = m_Menu[m_ActiveMenuItemIndex] as ToggleMenuItem;
                if (toggleItem != null)
                {
                    if (InputManager.KeyPressed(toggleItem.ToggleRightMethod.ActivateKey))
                    {
                        toggleItem.ToggleRight();
                    }
                    else if (InputManager.KeyPressed(toggleItem.ToggleLeftMethod.ActivateKey))
                    {
                        toggleItem.ToggleLeft();
                    }
                }
                else
                {
                    RangeMenuItem rangeItem = m_Menu[m_ActiveMenuItemIndex] as RangeMenuItem;
                    if (rangeItem != null)
                    {
                        if (InputManager.KeyPressed(rangeItem.DecreaseMethod.ActivateKey))
                        {
                            rangeItem.DecreaseJump();
                        }
                        else if (InputManager.KeyPressed(rangeItem.IncreaseMethod.ActivateKey))
                        {
                            rangeItem.IncreaseJump();
                        }
                    }
                }
            }
        }
Example #2
0
        public SoundSettingsScreen(Game i_Game) : base(i_Game, "Sound Settings")
        {
            ToggleMenuItem toggleSound = new ToggleMenuItem(i_Game, "Toggle sound: ", new Vector2(100, 100), m_GameSettings.Muted, "Off", "On", m_ActiveMenuItemColor, m_InactiveMenuItemColor);

            toggleSound.ValueChanged += new Action <bool>((i_Value) => m_GameSettings.ToggleSound());
            AddMenuItem(toggleSound);
            RangeMenuItem backgroundMusicVol = new RangeMenuItem(i_Game, "Background Music Volume: ", new Vector2(100, 120), 100, 0, (int)(m_GameSettings.BackgroundMusicVol * 100), 10, m_ActiveMenuItemColor, m_InactiveMenuItemColor);

            backgroundMusicVol.ValueChanged += new Action <int>((i_Value) => m_GameSettings.BackgroundMusicVol = ((float)i_Value) / 100);
            AddMenuItem(backgroundMusicVol);
            RangeMenuItem soundEffectsVol = new RangeMenuItem(i_Game, "Sound Effects Volume: ", new Vector2(100, 140), 100, 0, (int)(m_GameSettings.SoundsEffectsVol * 100), 10, m_ActiveMenuItemColor, m_InactiveMenuItemColor);

            soundEffectsVol.ValueChanged += new Action <int>((i_Value) => m_GameSettings.SoundsEffectsVol = ((float)i_Value) / 100);
            AddMenuItem(soundEffectsVol);
            AddMenuItem(new ActionMenuItem(i_Game, "Done", new Vector2(100, 160), new Action(() => ExitScreen()), m_ActiveMenuItemColor, m_InactiveMenuItemColor));
        }
        protected override void InitMenuItems()
        {
            ToggleMenuItem toggleSoundItem = new ToggleMenuItem(
                "Toggle Sound:", this, m_SpaceInvadersSoundsManager.SoundStatus, new List <string>()
            {
                "On", "Off"
            }, Keys.Enter, new MethodKey()
            {
                MethodToRun = m_SpaceInvadersSoundsManager.Mute, ActivateKey = Microsoft.Xna.Framework.Input.Keys.PageDown
            }, new MethodKey()
            {
                MethodToRun = m_SpaceInvadersSoundsManager.Play, ActivateKey = Microsoft.Xna.Framework.Input.Keys.PageUp
            });
            RangeMenuItem backgroundVolumeItem = new RangeMenuItem(
                "Background Music Vol:", this, (int)(m_SpaceInvadersSoundsManager.BackgroundSound.Volume * 100), 0, 100, 10, new MethodKey()
            {
                MethodToRun = m_SpaceInvadersSoundsManager.DecreaseBackgroundMusic, ActivateKey = Keys.PageDown
            }, new MethodKey()
            {
                MethodToRun = m_SpaceInvadersSoundsManager.IncreaseBackgroundMusic, ActivateKey = Keys.PageUp
            });
            RangeMenuItem soundsEffectsVolumeItem = new RangeMenuItem(
                "Sounds Effects Vol:", this, (int)(m_SpaceInvadersSoundsManager.SoundEffect.Volume * 100), 0, 100, 10, new MethodKey()
            {
                MethodToRun = m_SpaceInvadersSoundsManager.DecreaseSoundEffect, ActivateKey = Keys.PageDown
            }, new MethodKey()
            {
                MethodToRun = m_SpaceInvadersSoundsManager.IncreaseSoundEffect, ActivateKey = Keys.PageUp
            });
            TextMenuItem doneItem = new TextMenuItem(
                "Done", this, new MethodKey()
            {
                MethodToRun = done, ActivateKey = Keys.Enter
            });

            AddMenuItems(toggleSoundItem, backgroundVolumeItem, soundsEffectsVolumeItem, doneItem);
        }
Example #4
0
        private void handleMouse()
        {
            bool isMouseHover = isMouseHoverMenuItem();

            if (isMouseHover && InputManager.MouseState.LeftButton == ButtonState.Pressed && m_LastBTNState == ButtonState.Released)
            {
                runMenuItemMethod();
            }
            else if (m_ActiveMenuItemIndex > -1)
            {
                GameMenuItem item = Menu[m_ActiveMenuItemIndex] as GameMenuItem;
                if (isMouseHover && !item.IsActive)
                {
                    activateCurrentMenuItem();
                }
                else if (isMouseHover)
                {
                    RangeMenuItem rangeItem = m_Menu[m_ActiveMenuItemIndex] as RangeMenuItem;
                    if (rangeItem != null)
                    {
                        if (InputManager.MouseState.ScrollWheelValue > m_LastMouseWheelValue)
                        {
                            rangeItem.IncreaseJump();
                        }
                        else if (InputManager.MouseState.ScrollWheelValue < m_LastMouseWheelValue)
                        {
                            rangeItem.DecreaseJump();
                        }

                        m_LastMouseWheelValue = InputManager.MouseState.ScrollWheelValue;
                    }
                }
            }

            m_LastBTNState = InputManager.MouseState.LeftButton;
        }