From b968a422575dacbf89e496bfa330c2c1534ea97b Mon Sep 17 00:00:00 2001 From: ShadowCommander Date: Mon, 13 May 2024 01:14:35 +0300 Subject: [PATCH] Fix borg UI regenerating every tick (#27956) * Fix UI elements being recreated when they didn't need to be * Fix up comparison (cherry picked from commit 9c3dab0be3fa2ecc66a21b471e5e78be8fcf43d0) --- .../Laws/Ui/SiliconLawBoundUserInterface.cs | 20 +++++++++++++++++++ .../Silicons/Laws/SiliconLawPrototype.cs | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs b/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs index 93349794b8..56216b9184 100644 --- a/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs +++ b/Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs @@ -1,3 +1,5 @@ +using System.Linq; +using Content.Shared.Silicons.Laws; using Content.Shared.Silicons.Laws.Components; using JetBrains.Annotations; using Robust.Client.UserInterface; @@ -10,6 +12,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) { @@ -30,6 +33,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. ///