private void TurnOff( AppearanceComponent component, EnergySwordStatus status, IEntityManager entManager, SpriteComponent?spriteComponent = null) { if (entManager.TryGetComponent(component.Owner, out SharedItemComponent? itemComponent)) { itemComponent.EquippedPrefix = "off"; } if ((status & EnergySwordStatus.Hacked) != 0x0) { spriteComponent?.LayerSetState(0, "e_sword"); } else { spriteComponent?.LayerSetVisible(1, false); } if (entManager.TryGetComponent(component.Owner, out PointLightComponent? pointLightComponent)) { pointLightComponent.Enabled = false; } }
private void TurnOn( AppearanceComponent component, EnergySwordStatus status, Color color, IEntityManager entManager, SpriteComponent?spriteComponent = null) { if ((status & EnergySwordStatus.Hacked) != 0x0) { if (entManager.TryGetComponent(component.Owner, out SharedItemComponent? itemComponent)) { itemComponent.EquippedPrefix = "on-rainbow"; } //todo: figure out how to use the RGBLightControllerSystem to phase out the rainbow sprite AND add lights. spriteComponent?.LayerSetColor(1, Color.White); spriteComponent?.LayerSetVisible(1, false); spriteComponent?.LayerSetState(0, "e_sword_rainbow_on"); } else { if (entManager.TryGetComponent(component.Owner, out SharedItemComponent? itemComponent)) { itemComponent.EquippedPrefix = "on"; itemComponent.Color = color; } spriteComponent?.LayerSetColor(1, color); spriteComponent?.LayerSetVisible(1, true); if (entManager.TryGetComponent(component.Owner, out PointLightComponent? pointLightComponent)) { pointLightComponent.Color = color; pointLightComponent.Enabled = true; } } }
public void SetMultipleTool(EntityUid uid, MultipleToolComponent?multiple = null, ToolComponent?tool = null, SpriteComponent?sprite = null) { if (!Resolve(uid, ref multiple, ref tool)) { return; } // Sprite is optional. Resolve(uid, ref sprite); if (multiple.Entries.Length == 0) { multiple.CurrentQualityName = Loc.GetString("multiple-tool-component-no-behavior"); multiple.Dirty(); return; } var current = multiple.Entries[multiple.CurrentEntry]; tool.UseSound = current.Sound; tool.Qualities = current.Behavior; if (_prototypeManager.TryIndex(current.Behavior.First(), out ToolQualityPrototype? quality)) { multiple.CurrentQualityName = Loc.GetString(quality.Name); } multiple.Dirty(); if (current.Sprite == null || sprite == null) { return; } sprite.LayerSetSprite(0, current.Sprite); }
public void SetCurrentSide(EntityUid uid, int side, DiceComponent?die = null, SpriteComponent?sprite = null) { if (!Resolve(uid, ref die, ref sprite)) { return; } side = Math.Min(Math.Max(side, 1), die.Sides); side += side % die.Step; die.CurrentSide = side; // TODO DICE: Use a visualizer instead. sprite.LayerSetState(0, $"d{die.Sides}{die.CurrentSide}"); }
private void ResetOriginalColors(EntityUid uid, RgbLightControllerComponent?rgb = null, PointLightComponent?light = null, SpriteComponent?sprite = null) { if (!Resolve(uid, ref rgb, ref sprite, ref light)) { return; } light.Color = rgb.OriginalLightColor; if (rgb.Layers == null || rgb.OriginalLayerColors == null) { return; } foreach (var(layer, color) in rgb.OriginalLayerColors) { sprite.LayerSetColor(layer, color); } }
private void GetOriginalColors(EntityUid uid, RgbLightControllerComponent?rgb = null, PointLightComponent?light = null, SpriteComponent?sprite = null) { if (!Resolve(uid, ref rgb, ref sprite, ref light)) { return; } rgb.OriginalLightColor = light.Color; rgb.OriginalLayerColors = new(); var layerCount = sprite.AllLayers.Count(); // if layers is null, get unshaded layers if (rgb.Layers == null) { rgb.Layers = new(); for (var i = 0; i < layerCount; i++) { if (sprite[i] is Layer layer && layer.ShaderPrototype == "unshaded") { rgb.Layers.Add(i); rgb.OriginalLayerColors[i] = layer.Color; } } return; } foreach (var index in rgb.Layers.ToArray()) { if (index < layerCount) { rgb.OriginalLayerColors[index] = sprite[index].Color; } else { // admeme f**k-ups or bad yaml? Logger.Warning($"RGB light attempted to use invalid sprite index {index} on entity {ToPrettyString(uid)}"); rgb.Layers.Remove(index); } } }
private void GetOriginalSpriteColors(EntityUid uid, RgbLightControllerComponent?rgb = null, SpriteComponent?sprite = null) { if (!Resolve(uid, ref rgb, ref sprite)) { return; } if (rgb.Layers == null) { rgb.OriginalSpriteColor = sprite.Color; rgb.OriginalLayerColors = null; return; } var spriteLayerCount = sprite.AllLayers.Count(); rgb.OriginalLayerColors = new(rgb.Layers.Count); foreach (var layer in rgb.Layers.ToArray()) { if (layer < spriteLayerCount) { rgb.OriginalLayerColors[layer] = sprite[layer].Color; } else { rgb.Layers.Remove(layer); } } }
protected override void Initialize() { base.Initialize(); _sprite = _entMan.GetComponent <SpriteComponent>(Owner); }
public override void Initialize() { base.Initialize(); _sprite = Owner.GetComponent <SpriteComponent>(); }
/// <summary> /// Update the players sprite with new in-hand visuals. /// </summary> private void UpdateHandVisuals(EntityUid uid, EntityUid held, Hand hand, HandsComponent?handComp = null, SpriteComponent?sprite = null) { if (!Resolve(uid, ref handComp, ref sprite, false)) { return; } if (uid == _playerManager.LocalPlayer?.ControlledEntity) { UpdateGui(); } if (!handComp.ShowInHands) { return; } // Remove old layers. We could also just set them to invisible, but as items may add arbitrary layers, this // may eventually bloat the player with lots of layers. if (handComp.RevealedLayers.TryGetValue(hand.Location, out var revealedLayers)) { foreach (var key in revealedLayers) { sprite.RemoveLayer(key); } revealedLayers.Clear(); } else { revealedLayers = new(); handComp.RevealedLayers[hand.Location] = revealedLayers; } if (hand.HeldEntity == null) { // the held item was removed. RaiseLocalEvent(held, new HeldVisualsUpdatedEvent(uid, revealedLayers)); return; } var ev = new GetInhandVisualsEvent(uid, hand.Location); RaiseLocalEvent(held, ev, false); if (ev.Layers.Count == 0) { RaiseLocalEvent(held, new HeldVisualsUpdatedEvent(uid, revealedLayers)); return; } // add the new layers foreach (var(key, layerData) in ev.Layers) { if (!revealedLayers.Add(key)) { Logger.Warning($"Duplicate key for in-hand visuals: {key}. Are multiple components attempting to modify the same layer? Entity: {ToPrettyString(held)}"); continue; } var index = sprite.LayerMapReserveBlank(key); // In case no RSI is given, use the item's base RSI as a default. This cuts down on a lot of unnecessary yaml entries. if (layerData.RsiPath == null && layerData.TexturePath == null && sprite[index].Rsi == null && TryComp(held, out SpriteComponent? clothingSprite)) { sprite.LayerSetRSI(index, clothingSprite.BaseRSI); } sprite.LayerSetData(index, layerData); } RaiseLocalEvent(held, new HeldVisualsUpdatedEvent(uid, revealedLayers)); }
private void OnChangeData(EntityUid uid, TriggerOnProximityComponent component, AppearanceComponent appearance, SpriteComponent?spriteComponent = null) { if (!Resolve(uid, ref spriteComponent)) { return; } TryComp <AnimationPlayerComponent>(component.Owner, out var player); appearance.TryGetData(ProximityTriggerVisualState.State, out ProximityTriggerVisuals state); switch (state) { case ProximityTriggerVisuals.Inactive: // Don't interrupt the flash animation if (_player.HasRunningAnimation(uid, player, AnimKey)) { return; } _player.Stop(uid, player, AnimKey); spriteComponent.LayerSetState(ProximityTriggerVisualLayers.Base, "on"); break; case ProximityTriggerVisuals.Active: if (_player.HasRunningAnimation(uid, player, AnimKey)) { return; } _player.Play(uid, player, _flasherAnimation, AnimKey); break; case ProximityTriggerVisuals.Off: default: _player.Stop(uid, player, AnimKey); spriteComponent.LayerSetState(ProximityTriggerVisualLayers.Base, "off"); break; } }