]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix borg UI regenerating every tick (#27956)
authorShadowCommander <shadowjjt@gmail.com>
Sun, 12 May 2024 22:14:35 +0000 (15:14 -0700)
committerGitHub <noreply@github.com>
Sun, 12 May 2024 22:14:35 +0000 (18:14 -0400)
* Fix UI elements being recreated when they didn't need to be

* Fix up comparison

Content.Client/Silicons/Borgs/BorgMenu.xaml.cs
Content.Client/Silicons/Laws/Ui/SiliconLawBoundUserInterface.cs
Content.Shared/Silicons/Laws/SiliconLawPrototype.cs

index 046d8e299fe2a5a4a4250161c8907e8cdfbbed7d..474a83b453093afe4fb09a930b305799a9555547 100644 (file)
@@ -25,6 +25,7 @@ public sealed partial class BorgMenu : FancyWindow
     public readonly EntityUid Entity;
     public float AccumulatedTime;
     private string _lastValidName;
+    private List<EntityUid> _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);
     }
 }
-
index 2aee0a38c0fd17cf5096138ecb6f513fbf18683a..d150735fa110ab975bcc726ccc931e583fa28a54 100644 (file)
@@ -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<SiliconLaw>? _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);
     }
 }
index 5e5df448b33d9e9304eda7e7489347e52706142c..d10b86c2417d997231751ccfc06c0ff1c0bd502b 100644 (file)
@@ -39,6 +39,13 @@ public partial class SiliconLaw : IComparable<SiliconLaw>
         return Order.CompareTo(other.Order);
     }
 
+    public bool Equals(SiliconLaw other)
+    {
+        return LawString == other.LawString
+               && Order == other.Order
+               && LawIdentifierOverride == other.LawIdentifierOverride;
+    }
+
     /// <summary>
     /// Return a shallow clone of this law.
     /// </summary>