From: ShadowCommander Date: Sun, 12 May 2024 22:14:35 +0000 (-0700) Subject: Fix borg UI regenerating every tick (#27956) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=9c3dab0be3fa2ecc66a21b471e5e78be8fcf43d0;p=space-station-14.git Fix borg UI regenerating every tick (#27956) * Fix UI elements being recreated when they didn't need to be * Fix up comparison --- diff --git a/Content.Client/Silicons/Borgs/BorgMenu.xaml.cs b/Content.Client/Silicons/Borgs/BorgMenu.xaml.cs index 046d8e299f..474a83b453 100644 --- a/Content.Client/Silicons/Borgs/BorgMenu.xaml.cs +++ b/Content.Client/Silicons/Borgs/BorgMenu.xaml.cs @@ -25,6 +25,7 @@ public sealed partial class BorgMenu : FancyWindow public readonly EntityUid Entity; public float AccumulatedTime; private string _lastValidName; + private List _modules = new(); public BorgMenu(EntityUid entity) { @@ -114,7 +115,23 @@ public sealed partial class BorgMenu : FancyWindow ("actual", _chassis.ModuleCount), ("max", _chassis.MaxModules)); + if (_chassis.ModuleContainer.Count == _modules.Count) + { + var isSame = true; + foreach (var module in _chassis.ModuleContainer.ContainedEntities) + { + if (_modules.Contains(module)) + continue; + isSame = false; + break; + } + + if (isSame) + return; + } + ModuleContainer.Children.Clear(); + _modules.Clear(); foreach (var module in _chassis.ModuleContainer.ContainedEntities) { var control = new BorgModuleControl(module, _entity); @@ -123,6 +140,7 @@ public sealed partial class BorgMenu : FancyWindow RemoveModuleButtonPressed?.Invoke(module); }; ModuleContainer.AddChild(control); + _modules.Add(module); } } @@ -162,4 +180,3 @@ public sealed partial class BorgMenu : FancyWindow NameChanged?.Invoke(_lastValidName); } } - diff --git a/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs b/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs index 2aee0a38c0..d150735fa1 100644 --- a/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs +++ b/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs @@ -1,6 +1,7 @@ +using System.Linq; +using Content.Shared.Silicons.Laws; using Content.Shared.Silicons.Laws.Components; using JetBrains.Annotations; -using Robust.Client.GameObjects; namespace Content.Client.Silicons.Laws.Ui; @@ -10,6 +11,7 @@ public sealed class SiliconLawBoundUserInterface : BoundUserInterface [ViewVariables] private SiliconLawMenu? _menu; private EntityUid _owner; + private List? _laws; public SiliconLawBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { @@ -41,6 +43,23 @@ public sealed class SiliconLawBoundUserInterface : BoundUserInterface if (state is not SiliconLawBuiState msg) return; + if (_laws != null && _laws.Count == msg.Laws.Count) + { + var isSame = true; + foreach (var law in msg.Laws) + { + if (_laws.Contains(law)) + continue; + isSame = false; + break; + } + + if (isSame) + return; + } + + _laws = msg.Laws.ToList(); + _menu?.Update(_owner, msg); } } diff --git a/Content.Shared/Silicons/Laws/SiliconLawPrototype.cs b/Content.Shared/Silicons/Laws/SiliconLawPrototype.cs index 5e5df448b3..d10b86c241 100644 --- a/Content.Shared/Silicons/Laws/SiliconLawPrototype.cs +++ b/Content.Shared/Silicons/Laws/SiliconLawPrototype.cs @@ -39,6 +39,13 @@ public partial class SiliconLaw : IComparable return Order.CompareTo(other.Order); } + public bool Equals(SiliconLaw other) + { + return LawString == other.LawString + && Order == other.Order + && LawIdentifierOverride == other.LawIdentifierOverride; + } + /// /// Return a shallow clone of this law. ///