Exemplo n.º 1
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            //If this control is not enable, do nothing
            if (!IsEnabled)
            {
                return(false);
            }

            bool isKeyPress = false;
            bool backwardSelectDirection = input.IsKeyPress(Keys.LeftShift) || input.IsKeyPress(Keys.RightShift);
            int  deltaWheelPos           = input.PreviousMouseScrollWheelValue() - input.MouseScrollWheelValue();

            if (deltaWheelPos != 0) // determine just direction
            {
                deltaWheelPos /= Math.Abs(deltaWheelPos);
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_BULLET))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.Bullet;
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_MISSILE))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.Missile;
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_CANNON))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.Cannon;
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_UNIVERSAL_LAUNCHER_FRONT))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.UniversalLauncherFront;
            }

            if (input.IsNewGameControlPressed(MyGameControlEnums.SELECT_AMMO_UNIVERSAL_LAUNCHER_BACK))
            {
                isKeyPress      = true;
                m_selectedGroup = MyMwcObjectBuilder_AmmoGroupEnum.UniversalLauncherBack;
            }

            // in case of wheel direction modify flags to run correct code
            if (deltaWheelPos > 0 && Visible && IsEnabled)
            {
                isKeyPress = true;
                backwardSelectDirection = false;
            }
            // in case of wheel direction modify flags to run correct code
            if (deltaWheelPos < 0 && Visible && IsEnabled)
            {
                isKeyPress = true;
                backwardSelectDirection = true;
            }

            if (isKeyPress)
            {
                if (Visible == false)
                {
                    //I am here when the menu opens
                    LoadAmmoFromShip();
                    //If player change fire commands during game play, we need to show actual buttons names.
                    //ReloadControlText();
                    MyGuiSmallShipHelperAmmo.ResetDescription();
                }
                else
                {
                    if (m_selectedGroup == m_selectedGroupLast)
                    {
                        // if (!MyFakes.MW25D)
                        {
                            if (!backwardSelectDirection)
                            {
                                m_selectedIndex++;
                            }
                            else
                            {
                                m_selectedIndex--;
                            }
                        }
                        // else
                        //   m_selectedIndex = 0;
                    }
                    else
                    {
                        //I am here when category is changed
                        LoadAmmoFromShip();
                        MyGuiSmallShipHelperAmmo.ResetDescription();
                    }

                    if (m_selectedIndex >= m_ammoTypesAmounts.Count)
                    {
                        m_selectedIndex = 0;
                    }
                    if (m_selectedIndex < 0)
                    {
                        m_selectedIndex = m_ammoTypesAmounts.Count - 1;
                    }
                }

                Visible             = true;
                m_selectedGroupLast = m_selectedGroup;
                if (m_selectedIndex < m_ammoTypesAmounts.Count && m_selectedIndex >= 0)
                {
                    m_selectedAmmo = m_ammoTypesAmounts[m_selectedIndex].Type;
                }

                MyAudio.AddCue2D(MySoundCuesEnum.SfxHudWeaponScroll);
            }


            //Because I do not want the gun fired before I made the choice, the menu disappears after the release of key (not press)
            if (Visible)
            {
                if (!MySession.Is25DSector)
                {
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_SECONDARY) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Secondary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_THIRD) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Third, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FOURTH) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Fourth, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FIFTH) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Fifth, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }

                    if (input.IsNewKeyPress(Keys.Escape))
                    {
                        Visible = false;
                    }
                }
                else
                {  //MyFakes.MW25D
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_SECONDARY) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_THIRD) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FOURTH) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }
                    if (input.IsGameControlPressed(MyGameControlEnums.FIRE_FIFTH) && m_selectedAmmo != 0)
                    {
                        MySession.PlayerShip.Weapons.AmmoAssignments.AssignAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, m_selectedGroup, m_selectedAmmo);
                        m_isPressLast = true;
                    }

                    if (input.IsNewKeyPress(Keys.Escape))
                    {
                        Visible = false;
                    }
                }

                for (int i = m_ammoTypesAmounts.Count - 1; i >= 0; i--)
                {
                    int itemsPerColumn = 7;

                    int orderX = (int)m_selectedGroup + i / itemsPerColumn;
                    int orderY = i % itemsPerColumn;

                    /*
                     * Vector2 mousePos = MyGuiManager.MouseCursorPosition;
                     * if (MyVideoModeManager.IsTripleHead() == true)
                     *  mousePos += new Vector2(-1, 0);
                     *
                     * if (MyGuiSmallShipHelpers.GetMyGuiSmallShipHelperAmmo(m_ammoTypesAmounts[i].Type).IsPointInMyArea(mousePos))
                     * {
                     * }
                     */
                    //if (MyGuiSmallShipHelpers.GetMyGuiSmallShipHelperAmmo(m_ammoTypesAmounts[i].Type).IsPointInMyArea(MyGuiManager.MouseCursorPosition))
                    MyGuiSmallShipHelperAmmo ammoHelper =
                        MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.SmallShip_Ammo, (int)m_ammoTypesAmounts[i].Type) as MyGuiSmallShipHelperAmmo;
                    if (ammoHelper.IsPointInMyArea(MyGuiManager.MouseCursorPosition))
                    {
                        if (m_selectedIndex != i || m_selectedAmmo != m_ammoTypesAmounts[m_selectedIndex].Type)
                        {
                            MyAudio.AddCue2D(MySoundCuesEnum.SfxHudWeaponScroll);
                        }
                        m_selectedIndex = i;
                        m_selectedAmmo  = m_ammoTypesAmounts[m_selectedIndex].Type;
                    }
                }

                //if (!MyFakes.MW25D)
                {
                    if (m_isPressLast &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_SECONDARY) &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_THIRD) &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_FOURTH) &&
                        !input.IsGameControlPressed(MyGameControlEnums.FIRE_FIFTH))
                    {
                        //I am here when the menu closes
                        m_isPressLast = false;
                        Visible       = false;
                        MyAudio.AddCue2D(MySoundCuesEnum.SfxHudWeaponSelect);
                    }
                }

                /*  else
                 * {
                 *    if (isKeyPress)
                 *        MyAudio.AddCue2D(MySoundCuesEnum.SfxHudWeaponSelect);
                 * } */
            }

            /*
             * if (MyFakes.MW25D)
             * {
             * return false;
             * }   */

            return(base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate));
        }