Пример #1
0
 public ChangeInfo ClearIconText()
 {
     if (IconText.Length == 0)
     {
         return(ChangeInfo.None);
     }
     IconText.Clear();
     return(ChangeInfo.IconText);
 }
Пример #2
0
 public ChangeInfo SetIconText(StringBuilder newIconText)
 {
     if (newIconText == null)
     {
         return(ChangeInfo.None);
     }
     if (IconText.CompareTo(newIconText) == 0)
     {
         return(ChangeInfo.None);
     }
     IconText.Clear();
     IconText.AppendStringBuilder(newIconText);
     return(ChangeInfo.IconText);
 }
        public override ChangeInfo Update(MyEntity owner, long playerID = 0)
        {
            bool       thisWeaponIsCurrent    = false;
            bool       shipHasThisWeapon      = false;
            var        character              = MySession.LocalCharacter;
            bool       characterHasThisWeapon = character != null && (character.GetInventory().ContainItems(1, Definition.Id) || !character.WeaponTakesBuilderFromInventory(Definition.Id));
            ChangeInfo changed = ChangeInfo.None;

            if (characterHasThisWeapon)
            {
                var currentWeapon = character.CurrentWeapon;
                if (currentWeapon != null)
                {
                    thisWeaponIsCurrent = (MyDefinitionManager.Static.GetPhysicalItemForHandItem(currentWeapon.DefinitionId).Id == Definition.Id);
                }
                if (thisWeaponIsCurrent && currentWeapon is MyAutomaticRifleGun)
                {
                    int amount = character.CurrentWeapon.GetAmmunitionAmount();
                    if (m_lastAmmoCount != amount)
                    {
                        m_lastAmmoCount = amount;
                        IconText.Clear().AppendInt32(amount);
                        changed |= ChangeInfo.IconText;
                    }
                }
            }

            var shipControler = MySession.ControlledEntity as MyShipController;

            if (shipControler != null && shipControler.GridSelectionSystem.WeaponSystem != null)
            {
                //    var shipWeaponType = shipControler.GetWeaponType(Definition.Id.TypeId);
                //    shipHasThisWeapon = shipWeaponType.HasValue && shipControler.GridSelectionSystem.WeaponSystem.HasGunsOfId(shipWeaponType.Value);
                shipHasThisWeapon = shipControler.GridSelectionSystem.WeaponSystem.HasGunsOfId(Definition.Id);
                if (shipHasThisWeapon)
                {
                    IMyGunObject <MyDeviceBase> gunObject = shipControler.GridSelectionSystem.WeaponSystem.GetGun(Definition.Id);
                    if (gunObject.GunBase is MyGunBase)
                    {
                        int ammo = 0;
                        foreach (var gun in shipControler.GridSelectionSystem.WeaponSystem.GetGunsById(Definition.Id))
                        {
                            ammo += gun.GetAmmunitionAmount();
                        }
                        if (ammo != m_lastAmmoCount)
                        {
                            m_lastAmmoCount = ammo;
                            IconText.Clear().AppendInt32(ammo);
                            changed |= ChangeInfo.IconText;
                        }
                    }
                }

                thisWeaponIsCurrent = shipControler.GridSelectionSystem.GetGunId() == Definition.Id;
            }

            changed               |= SetEnabled(characterHasThisWeapon || shipHasThisWeapon);
            WantsToBeSelected      = thisWeaponIsCurrent;
            m_needsWeaponSwitching = !thisWeaponIsCurrent;
            return(changed);
        }