Ejemplo n.º 1
0
 public MenuStateMenuItemSelectedEventArgs(MenuStateMenuItem _Element) : base(_Element)
 {
 }
Ejemplo n.º 2
0
 public MenuStateEventArgs(MenuStateMenuItem _Element)
 {
     MenuElement = _Element;
 }
Ejemplo n.º 3
0
 public MenuStateMenuItemActivatedEventArgs(MenuStateMenuItem _Element) : base(_Element)
 {
 }
Ejemplo n.º 4
0
        public override void HandleGameKey(IStateOwner pOwner, GameKeys g)
        {
            //handle up and down to change the currently selected menu item.
            //Other game keys we pass on to the currently selected item itself for additional handling.
            bool triggered     = false;
            var  OriginalIndex = SelectedIndex;

            if (g == GameKeys.GameKey_Down)
            {
                if (ActivatedItem != null)
                {
                    ActivatedItem.ProcessGameKey(pOwner, g);
                }
                else
                {
                    //move selected index upwards.

                    SelectedIndex = GetNextIndex(SelectedIndex);
                    while (!MenuElements[SelectedIndex].GetSelectable())
                    {
                        SelectedIndex = GetNextIndex(SelectedIndex);
                    }
                }
                triggered = true;
                //should also skip if disabled...
            }
            else if (g == GameKeys.GameKey_Drop)
            {
                if (ActivatedItem != null)
                {
                    ActivatedItem.ProcessGameKey(pOwner, g);
                }
                else
                { //move selected index downwards.
                    SelectedIndex = GetPreviousIndex(SelectedIndex);

                    while (!MenuElements[SelectedIndex].GetSelectable())
                    {
                        SelectedIndex = GetPreviousIndex(SelectedIndex);
                    }
                }
                triggered = true;
            }

            if (g == GameKeys.GameKey_RotateCW || g == GameKeys.GameKey_MenuActivate || g == GameKeys.GameKey_Pause)
            {
                if (ActivatedItem != null)
                {
                    TetrisGame.Soundman.PlaySound(pOwner.AudioThemeMan.MenuItemActivated.Key, pOwner.Settings.std.EffectVolume);
                    ActivatedItem.OnDeactivated();
                    ActivatedItem = null;
                }
                else
                {
                    //Activate the currently selected item.
                    var currentitem = MenuElements[SelectedIndex];
                    TetrisGame.Soundman.PlaySound(pOwner.AudioThemeMan.MenuItemActivated.Key, pOwner.Settings.std.EffectVolume);
                    ActivatedItem = currentitem;
                    MenuItemActivated?.Invoke(this, new MenuStateMenuItemActivatedEventArgs(currentitem));

                    currentitem.OnActivated();
                }
                triggered = true;
            }

            else if (OriginalIndex != SelectedIndex)
            {
                TetrisGame.Soundman.PlaySound(pOwner.AudioThemeMan.MenuItemSelected.Key, pOwner.Settings.std.EffectVolume);
                var previousitem = MenuElements[OriginalIndex];
                var currentitem  = MenuElements[SelectedIndex];
                MenuItemDeselected?.Invoke(this, new MenuStateMenuItemSelectedEventArgs(previousitem));
                MenuItemSelected?.Invoke(this, new MenuStateMenuItemSelectedEventArgs(currentitem));
                previousitem.OnDeselected();
                currentitem.OnSelected();
            }

            if (!triggered)
            {
                var currentitem = MenuElements[SelectedIndex];
                currentitem.ProcessGameKey(pOwner, g);
            }
            //throw new NotImplementedException();
        }