Fix borg UI regenerating every tick (#27956)

* Fix UI elements being recreated when they didn't need to be

* Fix up comparison
This commit is contained in:
ShadowCommander
2024-05-12 15:14:35 -07:00
committed by GitHub
parent cfee7e3fdc
commit 9c3dab0be3
3 changed files with 45 additions and 2 deletions

View 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);
}
}

View 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);
}
}

View 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>