コード例 #1
0
        public override void OnChangeData(AppearanceComponent component)
        {
            var sprite = component.Owner.GetComponent <ISpriteComponent>();

            if (!component.TryGetData <int>(FoodContainerVisuals.Current, out var current))
            {
                return;
            }

            if (!component.TryGetData <int>(FoodContainerVisuals.Capacity, out var capacity))
            {
                return;
            }

            int step;

            switch (_mode)
            {
            case FoodContainerVisualMode.Discrete:
                step = Math.Min(_steps - 1, current);
                break;

            case FoodContainerVisualMode.Rounded:
                step = ContentHelpers.RoundToLevels(current, capacity, _steps);
                break;

            default:
                throw new NullReferenceException();
            }

            sprite.LayerSetState(0, $"{_baseState}-{step}");
        }
        public override void OnChangeData(AppearanceComponent component)
        {
            var sprite = component.Owner.GetComponent <ISpriteComponent>();

            component.TryGetData(BallisticMagazineWeaponVisuals.MagazineLoaded, out bool loaded);

            if (loaded)
            {
                if (!component.TryGetData(BallisticMagazineWeaponVisuals.AmmoCapacity, out int capacity))
                {
                    return;
                }
                if (!component.TryGetData(BallisticMagazineWeaponVisuals.AmmoLeft, out int current))
                {
                    return;
                }

                // capacity is - 1 as normally a bullet is chambered so max state is virtually never hit.
                var step = ContentHelpers.RoundToLevels(current, capacity - 1, _steps);
                sprite.LayerSetState(0, $"{_baseState}-{step}");
            }
            else
            {
                sprite.LayerSetState(0, _baseState);
            }
        }
コード例 #3
0
        public override void OnChangeData(AppearanceComponent component)
        {
            base.OnChangeData(component);

            var sprite   = component.Owner.GetComponent <ISpriteComponent>();
            var snapGrid = component.Owner.GetComponent <SnapGridComponent>();
            var lowWall  = FindLowWall(snapGrid);

            if (lowWall == null)
            {
                return;
            }

            if (component.TryGetData(WindowVisuals.Damage, out float fraction))
            {
                var level = Math.Min(ContentHelpers.RoundToLevels(fraction, 1, 7), 5);
                if (level == 0)
                {
                    foreach (WindowDamageLayers val in Enum.GetValues(typeof(WindowDamageLayers)))
                    {
                        sprite.LayerSetVisible(val, false);
                    }
                    return;
                }
                foreach (WindowDamageLayers val in Enum.GetValues(typeof(WindowDamageLayers)))
                {
                    sprite.LayerSetVisible(val, true);
                }

                sprite.LayerSetState(WindowDamageLayers.DamageNE, $"{(int) lowWall.LastCornerNE}_{level}");
                sprite.LayerSetState(WindowDamageLayers.DamageSE, $"{(int) lowWall.LastCornerSE}_{level}");
                sprite.LayerSetState(WindowDamageLayers.DamageSW, $"{(int) lowWall.LastCornerSW}_{level}");
                sprite.LayerSetState(WindowDamageLayers.DamageNW, $"{(int) lowWall.LastCornerNW}_{level}");
            }
        }
コード例 #4
0
        void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
        {
            if (!Owner.TryGetComponent(out IDamageableComponent? damageable) ||
                !Owner.TryGetComponent(out DestructibleComponent? destructible))
            {
                return;
            }

            var           damage  = damageable.TotalDamage;
            DamageTrigger?trigger = null;

            // TODO: Pretend this does not exist until https://github.com/space-wizards/space-station-14/pull/2783 is merged
            foreach (var threshold in destructible.Thresholds)
            {
                if ((trigger = threshold.Trigger as DamageTrigger) != null)
                {
                    break;
                }
            }

            if (trigger == null)
            {
                return;
            }

            var damageThreshold = trigger.Damage;
            var fraction        = damage == 0 || damageThreshold == 0
                ? 0f
                : (float)damage / damageThreshold;
            var level = Math.Min(ContentHelpers.RoundToLevels((double)fraction, 1, 7), 5);

            switch (level)
            {
            case 0:
                message.AddText(Loc.GetString("It looks fully intact."));
                break;

            case 1:
                message.AddText(Loc.GetString("It has a few scratches."));
                break;

            case 2:
                message.AddText(Loc.GetString("It has a few small cracks."));
                break;

            case 3:
                message.AddText(Loc.GetString("It has several big cracks running along its surface."));
                break;

            case 4:
                message.AddText(Loc.GetString("It has deep cracks across multiple layers."));
                break;

            case 5:
                message.AddText(Loc.GetString("It is extremely badly cracked and on the verge of shattering."));
                break;
            }
        }
コード例 #5
0
        void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
        {
            if (!Owner.TryGetComponent(out IDamageableComponent? damageable) ||
                !Owner.TryGetComponent(out DestructibleComponent? destructible))
            {
                return;
            }

            var           damage  = damageable.TotalDamage;
            DamageTrigger?trigger = null;

            // TODO: Pretend this does not exist until https://github.com/space-wizards/space-station-14/pull/2783 is merged
            foreach (var threshold in destructible.Thresholds)
            {
                if ((trigger = threshold.Trigger as DamageTrigger) != null)
                {
                    break;
                }
            }

            if (trigger == null)
            {
                return;
            }

            var damageThreshold = trigger.Damage;
            var fraction        = damage == 0 || damageThreshold == 0
                ? 0f
                : (float)damage / damageThreshold;
            var level = Math.Min(ContentHelpers.RoundToLevels((double)fraction, 1, 7), 5);

            switch (level)
            {
            case 0:
                message.AddText(Loc.GetString("comp-window-damaged-1"));
                break;

            case 1:
                message.AddText(Loc.GetString("comp-window-damaged-2"));
                break;

            case 2:
                message.AddText(Loc.GetString("comp-window-damaged-3"));
                break;

            case 3:
                message.AddText(Loc.GetString("comp-window-damaged-4"));
                break;

            case 4:
                message.AddText(Loc.GetString("comp-window-damaged-5"));
                break;

            case 5:
                message.AddText(Loc.GetString("comp-window-damaged-6"));
                break;
            }
        }
コード例 #6
0
        private int GetNewChargeLevel()
        {
            if (!Owner.TryGetComponent(out BatteryComponent? battery))
            {
                return(0);
            }

            return(ContentHelpers.RoundToLevels(battery.CurrentCharge, battery.MaxCharge, 6));
        }
コード例 #7
0
        public override void OnChangeData(AppearanceComponent component)
        {
            base.OnChangeData(component);

            var sprite = component.Owner.GetComponent <ISpriteComponent>();

            if (component.TryGetData(PowerCellVisuals.ChargeLevel, out float fraction))
            {
                sprite.LayerSetState(Layers.Charge, $"{_prefix}_{ContentHelpers.RoundToLevels(fraction, 1, 5) * 25}");
            }
        }
コード例 #8
0
        public override void OnChangeData(AppearanceComponent component)
        {
            base.OnChangeData(component);

            var sprite = component.Owner.GetComponent <ISpriteComponent>();

            if (!component.Owner.Transform.Anchored)
            {
                return;
            }

            var lowWall = FindLowWall(IoCManager.Resolve <IMapManager>(), component.Owner.Transform);

            if (lowWall == null)
            {
                return;
            }

            if (component.TryGetData(WindowVisuals.Damage, out float fraction))
            {
                var level = Math.Min(ContentHelpers.RoundToLevels(fraction, 1, 7), 5);
                if (level == 0)
                {
                    foreach (var val in Enum.GetValues(typeof(WindowDamageLayers)))
                    {
                        if (val == null)
                        {
                            continue;
                        }
                        sprite.LayerSetVisible((WindowDamageLayers)val, false);
                    }
                    return;
                }
                foreach (var val in Enum.GetValues(typeof(WindowDamageLayers)))
                {
                    if (val == null)
                    {
                        continue;
                    }
                    sprite.LayerSetVisible((WindowDamageLayers)val, true);
                }

                sprite.LayerSetState(WindowDamageLayers.DamageNE, $"{(int) lowWall.LastCornerNE}_{level}");
                sprite.LayerSetState(WindowDamageLayers.DamageSE, $"{(int) lowWall.LastCornerSE}_{level}");
                sprite.LayerSetState(WindowDamageLayers.DamageSW, $"{(int) lowWall.LastCornerSW}_{level}");
                sprite.LayerSetState(WindowDamageLayers.DamageNW, $"{(int) lowWall.LastCornerNW}_{level}");
            }
        }
        public override void OnChangeData(AppearanceComponent component)
        {
            var sprite = component.Owner.GetComponent <ISpriteComponent>();

            if (!component.TryGetData(BallisticMagazineVisuals.AmmoCapacity, out int capacity))
            {
                return;
            }
            if (!component.TryGetData(BallisticMagazineVisuals.AmmoLeft, out int current))
            {
                return;
            }

            var step = ContentHelpers.RoundToLevels(current, capacity, _steps);

            sprite.LayerSetState(0, $"{_baseState}-{step}");
        }
コード例 #10
0
        public override void OnChangeData(AppearanceComponent component)
        {
            var sprite = component.Owner.GetComponent <ISpriteComponent>();

            if (!component.TryGetData <int>(SharedFoodComponent.FoodVisuals.MaxUses, out var maxUses))
            {
                return;
            }

            if (component.TryGetData <int>(SharedFoodComponent.FoodVisuals.Visual, out var usesLeft))
            {
                var step = ContentHelpers.RoundToLevels(usesLeft, maxUses, _steps);
                sprite.LayerSetState(0, $"icon-{step}");
            }
            else
            {
                sprite.LayerSetState(0, "icon-0");
            }
        }
コード例 #11
0
        protected void UpdateFillIcon()
        {
            if (string.IsNullOrEmpty(_fillInitState))
            {
                return;
            }

            var percentage = (CurrentVolume / MaxVolume).Double();
            var level      = ContentHelpers.RoundToLevels(percentage * 100, 100, _fillInitSteps);

            //Transformed glass uses special fancy sprites so we don't bother
            if (level == 0 || (Owner.TryGetComponent <TransformableContainerComponent>(out var transformComp) && transformComp.Transformed))
            {
                _spriteComponent.LayerSetColor(1, Color.Transparent);
                return;
            }

            _fillSprite = new SpriteSpecifier.Rsi(_fillPath, _fillInitState + level);
            _spriteComponent.LayerSetSprite(1, _fillSprite);
            _spriteComponent.LayerSetColor(1, SubstanceColor);
        }
コード例 #12
0
        void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
        {
            var damage = Owner.GetComponentOrNull <IDamageableComponent>()?.TotalDamage;

            if (damage == null)
            {
                return;
            }
            var fraction = ((damage == 0 || _maxDamage == 0)
                ? 0f
                : (float)damage / _maxDamage);
            var level = Math.Min(ContentHelpers.RoundToLevels(fraction, 1, 7), 5);

            switch (level)
            {
            case 0:
                message.AddText(Loc.GetString("It looks fully intact."));
                break;

            case 1:
                message.AddText(Loc.GetString("It has a few scratches."));
                break;

            case 2:
                message.AddText(Loc.GetString("It has a few small cracks."));
                break;

            case 3:
                message.AddText(Loc.GetString("It has several big cracks running along its surface."));
                break;

            case 4:
                message.AddText(Loc.GetString("It has deep cracks across multiple layers."));
                break;

            case 5:
                message.AddText(Loc.GetString("It is extremely badly cracked and on the verge of shattering."));
                break;
            }
        }
コード例 #13
0
        public override void OnChangeData(AppearanceComponent component)
        {
            base.OnChangeData(component);

            // tl;dr
            // 1.If no mag then hide it OR
            // 2. If step 0 isn't visible then hide it (mag or unshaded)
            // 3. Otherwise just do mag / unshaded as is
            var sprite = component.Owner.GetComponent <ISpriteComponent>();

            component.TryGetData(MagazineBarrelVisuals.MagLoaded, out _magLoaded);

            if (_magLoaded)
            {
                if (!component.TryGetData(AmmoVisuals.AmmoMax, out int capacity))
                {
                    return;
                }
                if (!component.TryGetData(AmmoVisuals.AmmoCount, out int current))
                {
                    return;
                }

                var step = ContentHelpers.RoundToLevels(current, capacity, _magSteps);

                if (step == 0 && !_zeroVisible)
                {
                    if (sprite.LayerMapTryGet(RangedBarrelVisualLayers.Mag, out _))
                    {
                        sprite.LayerSetVisible(RangedBarrelVisualLayers.Mag, false);
                    }

                    if (sprite.LayerMapTryGet(RangedBarrelVisualLayers.MagUnshaded, out _))
                    {
                        sprite.LayerSetVisible(RangedBarrelVisualLayers.MagUnshaded, false);
                    }

                    return;
                }

                if (sprite.LayerMapTryGet(RangedBarrelVisualLayers.Mag, out _))
                {
                    sprite.LayerSetVisible(RangedBarrelVisualLayers.Mag, true);
                    sprite.LayerSetState(RangedBarrelVisualLayers.Mag, $"{_magState}-{step}");
                }

                if (sprite.LayerMapTryGet(RangedBarrelVisualLayers.MagUnshaded, out _))
                {
                    sprite.LayerSetVisible(RangedBarrelVisualLayers.MagUnshaded, true);
                    sprite.LayerSetState(RangedBarrelVisualLayers.MagUnshaded, $"{_magState}-unshaded-{step}");
                }
            }
            else
            {
                if (sprite.LayerMapTryGet(RangedBarrelVisualLayers.Mag, out _))
                {
                    sprite.LayerSetVisible(RangedBarrelVisualLayers.Mag, false);
                }

                if (sprite.LayerMapTryGet(RangedBarrelVisualLayers.MagUnshaded, out _))
                {
                    sprite.LayerSetVisible(RangedBarrelVisualLayers.MagUnshaded, false);
                }
            }
        }
コード例 #14
0
 private int GetNewChargeLevel()
 {
     return(ContentHelpers.RoundToLevels(_battery.CurrentCharge, _battery.MaxCharge, 6));
 }
コード例 #15
0
 int CalcChargeLevel()
 {
     return(ContentHelpers.RoundToLevels(Storage.Charge, Storage.Capacity, 6));
 }
コード例 #16
0
    private void OnMagazineVisualsChange(EntityUid uid, MagazineVisualsComponent component, ref AppearanceChangeEvent args)
    {
        // tl;dr
        // 1.If no mag then hide it OR
        // 2. If step 0 isn't visible then hide it (mag or unshaded)
        // 3. Otherwise just do mag / unshaded as is
        var sprite = args.Sprite;

        if (sprite == null)
        {
            return;
        }

        if (!args.AppearanceData.TryGetValue(AmmoVisuals.MagLoaded, out var magloaded) ||
            magloaded is true)
        {
            if (!args.AppearanceData.TryGetValue(AmmoVisuals.AmmoMax, out var capacity))
            {
                capacity = component.MagSteps;
            }

            if (!args.AppearanceData.TryGetValue(AmmoVisuals.AmmoCount, out var current))
            {
                current = component.MagSteps;
            }

            var step = ContentHelpers.RoundToLevels((int)current, (int)capacity, component.MagSteps);

            if (step == 0 && !component.ZeroVisible)
            {
                if (sprite.LayerMapTryGet(GunVisualLayers.Mag, out _))
                {
                    sprite.LayerSetVisible(GunVisualLayers.Mag, false);
                }

                if (sprite.LayerMapTryGet(GunVisualLayers.MagUnshaded, out _))
                {
                    sprite.LayerSetVisible(GunVisualLayers.MagUnshaded, false);
                }

                return;
            }

            if (sprite.LayerMapTryGet(GunVisualLayers.Mag, out _))
            {
                sprite.LayerSetVisible(GunVisualLayers.Mag, true);
                sprite.LayerSetState(GunVisualLayers.Mag, $"{component.MagState}-{step}");
            }

            if (sprite.LayerMapTryGet(GunVisualLayers.MagUnshaded, out _))
            {
                sprite.LayerSetVisible(GunVisualLayers.MagUnshaded, true);
                sprite.LayerSetState(GunVisualLayers.MagUnshaded, $"{component.MagState}-unshaded-{step}");
            }
        }
        else
        {
            if (sprite.LayerMapTryGet(GunVisualLayers.Mag, out _))
            {
                sprite.LayerSetVisible(GunVisualLayers.Mag, false);
            }

            if (sprite.LayerMapTryGet(GunVisualLayers.MagUnshaded, out _))
            {
                sprite.LayerSetVisible(GunVisualLayers.MagUnshaded, false);
            }
        }
    }