From 7a843fa830fda8e0485b724379960c46b900daf3 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sat, 27 Nov 2021 19:43:19 +1300 Subject: [PATCH] fix cigar case visuals (#5570) * fix cigar * newline --- .../Storage/ClientStorageComponent.cs | 34 +---------------- .../Components/ServerStorageComponent.cs | 37 +++++++++++++------ .../Components/SharedBagOpenVisuals.cs | 2 +- 3 files changed, 27 insertions(+), 46 deletions(-) diff --git a/Content.Client/Storage/ClientStorageComponent.cs b/Content.Client/Storage/ClientStorageComponent.cs index fe8d9c9c62..ffefa476c3 100644 --- a/Content.Client/Storage/ClientStorageComponent.cs +++ b/Content.Client/Storage/ClientStorageComponent.cs @@ -7,9 +7,7 @@ using Content.Client.Items.Managers; using Content.Client.Items.Components; using Content.Client.UserInterface.Controls; using Content.Shared.DragDrop; -using Content.Shared.Stacks; using Content.Shared.Storage; -using Content.Shared.Storage.Components; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.Player; @@ -43,14 +41,6 @@ namespace Content.Client.Storage public override IReadOnlyList StoredEntities => _storedEntities; - protected override void Initialize() - { - base.Initialize(); - - // Hide stackVisualizer on start - ChangeStorageVisualization(SharedBagState.Close); - } - protected override void OnAdd() { base.OnAdd(); @@ -142,36 +132,14 @@ namespace Content.Client.Storage if (_window == null) return; if (_window.IsOpen) - { _window.Close(); - ChangeStorageVisualization(SharedBagState.Close); - } else - { _window.OpenCentered(); - ChangeStorageVisualization(SharedBagState.Open); - } } private void CloseUI() { - if (_window == null) return; - - _window.Close(); - ChangeStorageVisualization(SharedBagState.Close); - - } - - private void ChangeStorageVisualization(SharedBagState state) - { - if (Owner.TryGetComponent(out var appearanceComponent)) - { - appearanceComponent.SetData(SharedBagOpenVisuals.BagState, state); - if (Owner.HasComponent()) - { - appearanceComponent.SetData(StackVisuals.Hide, state == SharedBagState.Close); - } - } + _window?.Close(); } /// diff --git a/Content.Server/Storage/Components/ServerStorageComponent.cs b/Content.Server/Storage/Components/ServerStorageComponent.cs index 2ee1f1e2ce..54fa795d79 100644 --- a/Content.Server/Storage/Components/ServerStorageComponent.cs +++ b/Content.Server/Storage/Components/ServerStorageComponent.cs @@ -14,7 +14,9 @@ using Content.Shared.Item; using Content.Shared.Placeable; using Content.Shared.Popups; using Content.Shared.Sound; +using Content.Shared.Stacks; using Content.Shared.Storage; +using Content.Shared.Storage.Components; using Content.Shared.Whitelist; using Robust.Server.GameObjects; using Robust.Server.Player; @@ -41,6 +43,8 @@ namespace Content.Server.Storage.Components [ComponentReference(typeof(IStorageComponent))] public class ServerStorageComponent : SharedStorageComponent, IInteractUsing, IUse, IActivate, IStorageComponent, IDestroyAct, IExAct, IAfterInteract { + [Dependency] private readonly IEntityManager _entityManager = default!; + private const string LoggerName = "Storage"; private Container? _storage; @@ -86,6 +90,20 @@ namespace Content.Server.Storage.Components } } + private void UpdateStorageVisualization() + { + if (!_entityManager.TryGetComponent(OwnerUid, out AppearanceComponent appearance)) + return; + + bool open = SubscribedSessions.Count != 0; + + appearance.SetData(StorageVisuals.Open, open); + appearance.SetData(SharedBagOpenVisuals.BagState, open ? SharedBagState.Open : SharedBagState.Closed); + + if (_entityManager.HasComponent(OwnerUid)) + appearance.SetData(StackVisuals.Hide, !open); + } + private void EnsureInitialCalculated() { if (_storageInitialCalculated) @@ -341,9 +359,10 @@ namespace Content.Server.Storage.Components session.PlayerStatusChanged += HandlePlayerSessionChangeEvent; SubscribedSessions.Add(session); - - UpdateDoorState(); } + + if (SubscribedSessions.Count == 1) + UpdateStorageVisualization(); } /// @@ -360,9 +379,10 @@ namespace Content.Server.Storage.Components #pragma warning disable 618 SendNetworkMessage(new CloseStorageUIMessage(), session.ConnectedClient); #pragma warning restore 618 - - UpdateDoorState(); } + + if (SubscribedSessions.Count == 0) + UpdateStorageVisualization(); } private void HandlePlayerSessionChangeEvent(object? obj, SessionStatusEventArgs sessionStatus) @@ -375,14 +395,6 @@ namespace Content.Server.Storage.Components } } - private void UpdateDoorState() - { - if (Owner.TryGetComponent(out AppearanceComponent? appearance)) - { - appearance.SetData(StorageVisuals.Open, SubscribedSessions.Count != 0); - } - } - protected override void Initialize() { base.Initialize(); @@ -390,6 +402,7 @@ namespace Content.Server.Storage.Components // ReSharper disable once StringLiteralTypo _storage = Owner.EnsureContainer("storagebase"); _storage.OccludesLight = _occludesLight; + UpdateStorageVisualization(); } [Obsolete("Component Messages are deprecated, use Entity Events instead.")] diff --git a/Content.Shared/Storage/Components/SharedBagOpenVisuals.cs b/Content.Shared/Storage/Components/SharedBagOpenVisuals.cs index fd8111402a..7712a8ceb6 100644 --- a/Content.Shared/Storage/Components/SharedBagOpenVisuals.cs +++ b/Content.Shared/Storage/Components/SharedBagOpenVisuals.cs @@ -13,6 +13,6 @@ namespace Content.Shared.Storage.Components public enum SharedBagState : byte { Open, - Close, + Closed, } }