diff --git a/Content.Client/Anomaly/Ui/AnomalyGeneratorWindow.xaml.cs b/Content.Client/Anomaly/Ui/AnomalyGeneratorWindow.xaml.cs index 6da7a4e339..ca8682e72d 100644 --- a/Content.Client/Anomaly/Ui/AnomalyGeneratorWindow.xaml.cs +++ b/Content.Client/Anomaly/Ui/AnomalyGeneratorWindow.xaml.cs @@ -24,7 +24,7 @@ public sealed partial class AnomalyGeneratorWindow : FancyWindow RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); - EntityView.Sprite = _entityManager.GetComponent(gen); + EntityView.SetEntity(gen); EntityView.SpriteOffset = false; GenerateButton.OnPressed += _ => OnGenerateButtonPressed?.Invoke(); diff --git a/Content.Client/CharacterInfo/CharacterInfoSystem.cs b/Content.Client/CharacterInfo/CharacterInfoSystem.cs index 8521bb6797..d2f4f64285 100644 --- a/Content.Client/CharacterInfo/CharacterInfoSystem.cs +++ b/Content.Client/CharacterInfo/CharacterInfoSystem.cs @@ -42,17 +42,16 @@ public sealed class CharacterInfoSystem : EntitySystem private void OnCharacterInfoEvent(CharacterInfoEvent msg, EntitySessionEventArgs args) { - var sprite = CompOrNull(msg.EntityUid); - var data = new CharacterData(msg.JobTitle, msg.Objectives, msg.Briefing, sprite, Name(msg.EntityUid)); + var data = new CharacterData(msg.EntityUid, msg.JobTitle, msg.Objectives, msg.Briefing, Name(msg.EntityUid)); OnCharacterUpdate?.Invoke(data); } public readonly record struct CharacterData( + EntityUid Entity, string Job, Dictionary> Objectives, string Briefing, - SpriteComponent? Sprite, string EntityName ); } diff --git a/Content.Client/ContextMenu/UI/EntityMenuElement.cs b/Content.Client/ContextMenu/UI/EntityMenuElement.cs index 74934724ff..b16559b58f 100644 --- a/Content.Client/ContextMenu/UI/EntityMenuElement.cs +++ b/Content.Client/ContextMenu/UI/EntityMenuElement.cs @@ -107,12 +107,12 @@ namespace Content.Client.ContextMenu.UI // _entityManager.Deleted() implicitly checks all of these. if (_entityManager.Deleted(entity)) { - Icon.Sprite = null; + Icon.SetEntity(null); Text = string.Empty; } else { - Icon.Sprite = _entityManager.GetComponentOrNull(entity); + Icon.SetEntity(entity); Text = GetEntityDescription(entity.Value); } } diff --git a/Content.Client/Examine/ExamineSystem.cs b/Content.Client/Examine/ExamineSystem.cs index 89a9486483..9b55b62281 100644 --- a/Content.Client/Examine/ExamineSystem.cs +++ b/Content.Client/Examine/ExamineSystem.cs @@ -222,14 +222,16 @@ namespace Content.Client.Examine vBox.AddChild(hBox); - if (EntityManager.TryGetComponent(target, out SpriteComponent? sprite)) + if (EntityManager.HasComponent(target)) { - hBox.AddChild(new SpriteView + var spriteView = new SpriteView { - Sprite = sprite, OverrideDirection = Direction.South, + OverrideDirection = Direction.South, SetSize = new Vector2(32, 32), Margin = new Thickness(2, 0, 2, 0), - }); + }; + spriteView.SetEntity(target); + hBox.AddChild(spriteView); } if (knowTarget) diff --git a/Content.Client/Guidebook/Controls/GuideEntityEmbed.xaml.cs b/Content.Client/Guidebook/Controls/GuideEntityEmbed.xaml.cs index ee8b46efb0..8fd11dc19e 100644 --- a/Content.Client/Guidebook/Controls/GuideEntityEmbed.xaml.cs +++ b/Content.Client/Guidebook/Controls/GuideEntityEmbed.xaml.cs @@ -37,11 +37,7 @@ public sealed partial class GuideEntityEmbed : BoxContainer, IDocumentTag public bool Interactive; - public SpriteComponent? Sprite - { - get => View.Sprite; - set => View.Sprite = value; - } + public SpriteComponent? Sprite => View.Sprite; public Vector2 Scale { @@ -64,7 +60,7 @@ public sealed partial class GuideEntityEmbed : BoxContainer, IDocumentTag Interactive = interactive; var ent = _entityManager.SpawnEntity(proto, MapCoordinates.Nullspace); - Sprite = _entityManager.GetComponent(ent); + View.SetEntity(ent); if (caption) Caption.Text = _entityManager.GetComponent(ent).EntityName; @@ -146,7 +142,7 @@ public sealed partial class GuideEntityEmbed : BoxContainer, IDocumentTag var ent = _entityManager.SpawnEntity(proto, MapCoordinates.Nullspace); _tagSystem.AddTag(ent, GuidebookSystem.GuideEmbedTag); - Sprite = _entityManager.GetComponent(ent); + View.SetEntity(ent); if (!args.TryGetValue("Caption", out var caption)) caption = _entityManager.GetComponent(ent).EntityName; diff --git a/Content.Client/Inventory/ClientInventorySystem.cs b/Content.Client/Inventory/ClientInventorySystem.cs index b454ad27a3..5813d69524 100644 --- a/Content.Client/Inventory/ClientInventorySystem.cs +++ b/Content.Client/Inventory/ClientInventorySystem.cs @@ -91,7 +91,7 @@ namespace Content.Client.Inventory UpdateSlot(args.Equipee, component, args.Slot); if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity) return; - var update = new SlotSpriteUpdate(args.SlotGroup, args.Slot, null, false); + var update = new SlotSpriteUpdate(null, args.SlotGroup, args.Slot, false); OnSpriteUpdate?.Invoke(update); } @@ -100,8 +100,7 @@ namespace Content.Client.Inventory UpdateSlot(args.Equipee, component, args.Slot); if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity) return; - var sprite = EntityManager.GetComponentOrNull(args.Equipment); - var update = new SlotSpriteUpdate(args.SlotGroup, args.Slot, sprite, + var update = new SlotSpriteUpdate(args.Equipment, args.SlotGroup, args.Slot, HasComp(args.Equipment)); OnSpriteUpdate?.Invoke(update); } @@ -340,9 +339,9 @@ namespace Content.Client.Inventory } public readonly record struct SlotSpriteUpdate( + EntityUid? Entity, string Group, string Name, - SpriteComponent? Sprite, bool ShowStorage ); } diff --git a/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs b/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs index ff33bbadba..a319c1a4f1 100644 --- a/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs +++ b/Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs @@ -94,12 +94,14 @@ namespace Content.Client.Lobby.UI private SpriteView MakeSpriteView(EntityUid entity, Direction direction) { - return new() + var spriteView = new SpriteView { - Sprite = _entityManager.GetComponent(entity), OverrideDirection = direction, - Scale = new Vector2(2, 2) + Scale = new Vector2(2, 2), }; + + spriteView.SetEntity(entity); + return spriteView; } public void UpdateUI() diff --git a/Content.Client/Mech/Ui/MechEquipmentControl.xaml.cs b/Content.Client/Mech/Ui/MechEquipmentControl.xaml.cs index 1253890473..9b3bfaa25c 100644 --- a/Content.Client/Mech/Ui/MechEquipmentControl.xaml.cs +++ b/Content.Client/Mech/Ui/MechEquipmentControl.xaml.cs @@ -10,11 +10,11 @@ public sealed partial class MechEquipmentControl : Control { public event Action? OnRemoveButtonPressed; - public MechEquipmentControl(string itemName, SpriteComponent? sprite, Control? fragment) + public MechEquipmentControl(EntityUid entity, string itemName, Control? fragment) { RobustXamlLoader.Load(this); EquipmentName.SetMessage(itemName); - EquipmentView.Sprite = sprite; + EquipmentView.SetEntity(entity); RemoveButton.TexturePath = "/Textures/Interface/Nano/cross.svg.png"; if (fragment != null) diff --git a/Content.Client/Mech/Ui/MechMenu.xaml.cs b/Content.Client/Mech/Ui/MechMenu.xaml.cs index 1bb59e07e9..8d1d936031 100644 --- a/Content.Client/Mech/Ui/MechMenu.xaml.cs +++ b/Content.Client/Mech/Ui/MechMenu.xaml.cs @@ -23,10 +23,7 @@ public sealed partial class MechMenu : FancyWindow _mech = mech; - if (!_ent.TryGetComponent(mech, out var sprite)) - return; - - MechView.Sprite = sprite; + MechView.SetEntity(mech); } public void UpdateMechStats() @@ -54,14 +51,13 @@ public sealed partial class MechMenu : FancyWindow EquipmentControlContainer.Children.Clear(); foreach (var ent in mechComp.EquipmentContainer.ContainedEntities) { - if (!_ent.TryGetComponent(ent, out var sprite) || - !_ent.TryGetComponent(ent, out var metaData)) + if (!_ent.TryGetComponent(ent, out var metaData)) continue; var uicomp = _ent.GetComponentOrNull(ent); var ui = uicomp?.Ui?.GetUIFragmentRoot(); - var control = new MechEquipmentControl(metaData.EntityName, sprite, ui); + var control = new MechEquipmentControl(ent, metaData.EntityName, ui); control.OnRemoveButtonPressed += () => OnRemoveButtonPressed?.Invoke(ent); diff --git a/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs b/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs index f3c3241b7e..e63a811f0e 100644 --- a/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs +++ b/Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs @@ -186,10 +186,10 @@ namespace Content.Client.Preferences.UI var view = new SpriteView { - Sprite = entityManager.GetComponent(_previewDummy), Scale = new Vector2(2, 2), OverrideDirection = Direction.South }; + view.SetEntity(_previewDummy); var description = profile.Name; diff --git a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs index 371b34c89c..6d1d808905 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs @@ -485,26 +485,25 @@ namespace Content.Client.Preferences.UI _previewDummy = _entMan.SpawnEntity(dollProto, MapCoordinates.Nullspace); _lastSpecies = species; - var sprite = _entMan.GetComponent(_previewDummy!.Value); _previewSprite = new SpriteView { - Sprite = sprite, Scale = new Vector2(6, 6), OverrideDirection = Direction.South, VerticalAlignment = VAlignment.Center, SizeFlagsStretchRatio = 1 }; + _previewSprite.SetEntity(_previewDummy.Value); _previewSpriteControl.AddChild(_previewSprite); _previewSpriteSide = new SpriteView { - Sprite = sprite, Scale = new Vector2(6, 6), OverrideDirection = Direction.East, VerticalAlignment = VAlignment.Center, SizeFlagsStretchRatio = 1 }; + _previewSpriteSide.SetEntity(_previewDummy.Value); _previewSpriteSideControl.AddChild(_previewSpriteSide); #endregion Dummy @@ -726,14 +725,12 @@ namespace Content.Client.Preferences.UI _previewDummy = _entMan.SpawnEntity(dollProto, MapCoordinates.Nullspace); _lastSpecies = species; - var sprite = _entMan.GetComponent(_previewDummy!.Value); if (_previewSprite == null) { // Front _previewSprite = new SpriteView { - Sprite = sprite, Scale = new Vector2(6, 6), OverrideDirection = Direction.South, VerticalAlignment = VAlignment.Center, @@ -741,16 +738,12 @@ namespace Content.Client.Preferences.UI }; _previewSpriteControl.AddChild(_previewSprite); } - else - { - _previewSprite.SetEntity(_previewDummy.Value); - } + _previewSprite.SetEntity(_previewDummy.Value); if (_previewSpriteSide == null) { _previewSpriteSide = new SpriteView { - Sprite = sprite, Scale = new Vector2(6, 6), OverrideDirection = Direction.East, VerticalAlignment = VAlignment.Center, @@ -758,10 +751,8 @@ namespace Content.Client.Preferences.UI }; _previewSpriteSideControl.AddChild(_previewSpriteSide); } - else - { - _previewSpriteSide.SetEntity(_previewDummy.Value); - } + _previewSpriteSide.SetEntity(_previewDummy.Value); + _needUpdatePreview = true; } diff --git a/Content.Client/RoundEnd/RoundEndSummaryWindow.cs b/Content.Client/RoundEnd/RoundEndSummaryWindow.cs index 93212013a9..454027597c 100644 --- a/Content.Client/RoundEnd/RoundEndSummaryWindow.cs +++ b/Content.Client/RoundEnd/RoundEndSummaryWindow.cs @@ -125,16 +125,17 @@ namespace Content.Client.RoundEnd VerticalExpand = true, }; - if (_entityManager.TryGetComponent(playerInfo.PlayerEntityUid, out SpriteComponent? sprite)) + if (_entityManager.HasComponent(playerInfo.PlayerEntityUid)) { - hBox.AddChild(new SpriteView + var spriteView = new SpriteView { - Sprite = sprite, OverrideDirection = Direction.South, VerticalAlignment = VAlignment.Center, SetSize = new Vector2(32, 32), VerticalExpand = true, - }); + }; + spriteView.SetEntity(playerInfo.PlayerEntityUid); + hBox.AddChild(spriteView); } if (playerInfo.PlayerICName != null) diff --git a/Content.Client/Storage/UI/StorageWindow.cs b/Content.Client/Storage/UI/StorageWindow.cs index 83ad6a8e80..521d1cf590 100644 --- a/Content.Client/Storage/UI/StorageWindow.cs +++ b/Content.Client/Storage/UI/StorageWindow.cs @@ -113,26 +113,26 @@ namespace Content.Client.Storage.UI || !_entityManager.EntityExists(entity)) return; - _entityManager.TryGetComponent(entity, out SpriteComponent? sprite); _entityManager.TryGetComponent(entity, out ItemComponent? item); _entityManager.TryGetComponent(entity, out StackComponent? stack); var count = stack?.Count ?? 1; var size = item?.Size; + var spriteView = new SpriteView + { + HorizontalAlignment = HAlignment.Left, + VerticalAlignment = VAlignment.Center, + SetSize = new Vector2(32.0f, 32.0f), + OverrideDirection = Direction.South, + }; + spriteView.SetEntity(entity); button.AddChild(new BoxContainer { Orientation = LayoutOrientation.Horizontal, SeparationOverride = 2, Children = { - new SpriteView - { - HorizontalAlignment = HAlignment.Left, - VerticalAlignment = VAlignment.Center, - SetSize = new Vector2(32.0f, 32.0f), - OverrideDirection = Direction.South, - Sprite = sprite - }, + spriteView, new Label { HorizontalExpand = true, diff --git a/Content.Client/UserInterface/Controls/SlotControl.cs b/Content.Client/UserInterface/Controls/SlotControl.cs index 193a9908d0..bfc517dea4 100644 --- a/Content.Client/UserInterface/Controls/SlotControl.cs +++ b/Content.Client/UserInterface/Controls/SlotControl.cs @@ -195,7 +195,7 @@ namespace Content.Client.UserInterface.Controls IoCManager.Resolve().DeleteEntity(tempQualifier.Owner); } - HoverSpriteView.Sprite = null; + HoverSpriteView.SetEntity(null); } private void OnButtonPressed(GUIBoundKeyEventArgs args) diff --git a/Content.Client/UserInterface/Systems/Actions/Controls/ActionButton.cs b/Content.Client/UserInterface/Systems/Actions/Controls/ActionButton.cs index 4030326420..1b2dcdb89c 100644 --- a/Content.Client/UserInterface/Systems/Actions/Controls/ActionButton.cs +++ b/Content.Client/UserInterface/Systems/Actions/Controls/ActionButton.cs @@ -203,13 +203,12 @@ public sealed class ActionButton : Control return; } - if (Action?.EntityIcon == null || - !entityManager.TryGetComponent(Action.EntityIcon.Value, out SpriteComponent? sprite)) + if (Action?.EntityIcon is not { } entity || !entityManager.HasComponent(entity)) { _bigItemSpriteView.Visible = false; - _bigItemSpriteView.Sprite = null; + _bigItemSpriteView.SetEntity(null); _smallItemSpriteView.Visible = false; - _smallItemSpriteView.Sprite = null; + _smallItemSpriteView.SetEntity(null); } else { @@ -217,24 +216,21 @@ public sealed class ActionButton : Control { case ItemActionIconStyle.BigItem: _bigItemSpriteView.Visible = true; - _bigItemSpriteView.Sprite = sprite; + _bigItemSpriteView.SetEntity(entity); _smallItemSpriteView.Visible = false; - _smallItemSpriteView.Sprite = null; + _smallItemSpriteView.SetEntity(null); break; case ItemActionIconStyle.BigAction: - _bigItemSpriteView.Visible = false; - _bigItemSpriteView.Sprite = null; + _bigItemSpriteView.SetEntity(null); _smallItemSpriteView.Visible = true; - _smallItemSpriteView.Sprite = sprite; + _smallItemSpriteView.SetEntity(entity); break; - case ItemActionIconStyle.NoItem: - _bigItemSpriteView.Visible = false; - _bigItemSpriteView.Sprite = null; + _bigItemSpriteView.SetEntity(null); _smallItemSpriteView.Visible = false; - _smallItemSpriteView.Sprite = null; + _smallItemSpriteView.SetEntity(null); break; } } diff --git a/Content.Client/UserInterface/Systems/Character/CharacterUIController.cs b/Content.Client/UserInterface/Systems/Character/CharacterUIController.cs index cea15721cb..6f245dfc7b 100644 --- a/Content.Client/UserInterface/Systems/Character/CharacterUIController.cs +++ b/Content.Client/UserInterface/Systems/Character/CharacterUIController.cs @@ -101,7 +101,7 @@ public sealed class CharacterUIController : UIController, IOnStateEntered(virt.BlockingEntity); + handButton.SpriteView.SetEntity(virt.BlockingEntity); handButton.Blocked = true; } else { - handButton.SpriteView.Sprite = _entities.GetComponentOrNull(hand.HeldEntity); + handButton.SpriteView.SetEntity(hand.HeldEntity); handButton.Blocked = false; } } @@ -171,12 +171,12 @@ public sealed class HandsUIController : UIController, IOnStateEntered(virt.BlockingEntity); + hand.SpriteView.SetEntity(virt.BlockingEntity); hand.Blocked = true; } else { - hand.SpriteView.Sprite = _entities.GetComponentOrNull(entity); + hand.SpriteView.SetEntity(entity); hand.Blocked = false; } @@ -190,7 +190,7 @@ public sealed class HandsUIController : UIController, IOnStateEntered(data.HeldEntity); var showStorage = _entities.HasComponent(data.HeldEntity); - var update = new SlotSpriteUpdate(data.SlotGroup, data.SlotName, sprite, showStorage); + var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage); SpriteUpdated(update); } } @@ -151,9 +150,8 @@ public sealed class InventoryUIController : UIController, IOnStateEntered(data.HeldEntity); var showStorage = _entities.HasComponent(data.HeldEntity); - var update = new SlotSpriteUpdate(data.SlotGroup, data.SlotName, sprite, showStorage); + var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage); SpriteUpdated(update); } } @@ -288,7 +286,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered(verb.IconEntity.Value) }; + spriteView.SetEntity(verb.IconEntity.Value); Icon.AddChild(spriteView); return; diff --git a/Content.Client/Xenoarchaeology/Ui/AnalysisConsoleMenu.xaml.cs b/Content.Client/Xenoarchaeology/Ui/AnalysisConsoleMenu.xaml.cs index 344df37a00..75ba43df2f 100644 --- a/Content.Client/Xenoarchaeology/Ui/AnalysisConsoleMenu.xaml.cs +++ b/Content.Client/Xenoarchaeology/Ui/AnalysisConsoleMenu.xaml.cs @@ -56,10 +56,7 @@ public sealed partial class AnalysisConsoleMenu : FancyWindow } ArtifactDisplay.Visible = true; - if (!_ent.TryGetComponent(uid, out var sprite)) - return; - - ArtifactDisplay.Sprite = sprite; + ArtifactDisplay.SetEntity(uid); } public void UpdateInformationDisplay(AnalysisConsoleScanUpdateState state)