]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix UI issues with Camera Monitor (#31809)
authoreoineoineoin <helloworld@eoinrul.es>
Thu, 17 Apr 2025 10:15:35 +0000 (11:15 +0100)
committerGitHub <noreply@github.com>
Thu, 17 Apr 2025 10:15:35 +0000 (20:15 +1000)
* Fix jumpy camera monitor UI

Basically copy-pasted same solution from #30292

* Remove duplicate code; use shared ItemList method to sync items

Content.Client/CriminalRecords/CriminalRecordsConsoleWindow.xaml.cs
Content.Client/SurveillanceCamera/UI/SurveillanceCameraMonitorWindow.xaml.cs

index 85d65020c629b9a4e89bf92abc0c8f7dd7dfef0f..5eaed770414e85dfa84f8eeaf448e656169d45d0 100644 (file)
@@ -213,52 +213,14 @@ public sealed partial class CriminalRecordsConsoleWindow : FancyWindow
             return;
         }
 
-        var entries = listing.ToList();
-        entries.Sort((a, b) => string.Compare(a.Value, b.Value, StringComparison.Ordinal));
-        // `entries` now contains the definitive list of items which should be in
-        // our list of records and is in the order we want to present those items.
-
-        // Walk through the existing items in RecordListing and in the updated listing
-        // in parallel to synchronize the items in RecordListing with `entries`.
-        int i = RecordListing.Count - 1;
-        int j = entries.Count - 1;
-        while (i >= 0 && j >= 0)
-        {
-            var strcmp = string.Compare(RecordListing[i].Text, entries[j].Value, StringComparison.Ordinal);
-            if (strcmp == 0)
-            {
-                // This item exists in both RecordListing and `entries`. Nothing to do.
-                i--;
-                j--;
-            }
-            else if (strcmp > 0)
-            {
-                // Item exists in RecordListing, but not in `entries`. Remove it.
-                RecordListing.RemoveAt(i);
-                i--;
-            }
-            else if (strcmp < 0)
-            {
-                // A new entry which doesn't exist in RecordListing. Create it.
-                RecordListing.Insert(i + 1, new ItemList.Item(RecordListing){Text = entries[j].Value, Metadata = entries[j].Key});
-                j--;
-            }
-        }
-
-        // Any remaining items in RecordListing don't exist in `entries`, so remove them
-        while (i >= 0)
-        {
-            RecordListing.RemoveAt(i);
-            i--;
-        }
-
-        // And finally, any remaining items in `entries`, don't exist in RecordListing. Create them.
-        while (j >= 0)
-        {
-            RecordListing.Insert(0, new ItemList.Item(RecordListing){ Text = entries[j].Value, Metadata = entries[j].Key });
-            j--;
-        }
+        var entries = listing.Select(i => new ItemList.Item(RecordListing) {
+                Text = i.Value,
+                Metadata = i.Key
+        }).ToList();
+        entries.Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.Ordinal));
+        RecordListing.SetItems(entries, (a,b) => string.Compare(a.Text, b.Text));
     }
+
     private void PopulateRecordContainer(GeneralStationRecord stationRecord, CriminalRecord criminalRecord)
     {
         var specifier = new SpriteSpecifier.Rsi(new ResPath("Interface/Misc/job_icons.rsi"), "Unknown");
index 59ac435acf10d694edb6801655c29249f9c49517..0fbaf858da4ae95d95adb0343a537eee17b8e3f3 100644 (file)
@@ -125,14 +125,12 @@ public sealed partial class SurveillanceCameraMonitorWindow : DefaultWindow
 
     private void PopulateCameraList(Dictionary<string, string> cameras)
     {
-        SubnetList.Clear();
-
-        foreach (var (address, name) in cameras)
-        {
-            AddCameraToList(name, address);
-        }
-
-        SubnetList.SortItemsByText();
+        var entries = cameras.Select(i => new ItemList.Item(SubnetList) {
+            Text = $"{i.Value}: {i.Key}",
+            Metadata = i.Key
+        }).ToList();
+        entries.Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.Ordinal));
+        SubnetList.SetItems(entries, (a,b) => string.Compare(a.Text, b.Text));
     }
 
     private void SetCameraView(IEye? eye)
@@ -187,12 +185,6 @@ public sealed partial class SurveillanceCameraMonitorWindow : DefaultWindow
         return SubnetSelector.ItemCount - 1;
     }
 
-    private void AddCameraToList(string name, string address)
-    {
-        var item = SubnetList.AddItem($"{name}: {address}");
-        item.Metadata = address;
-    }
-
     private void OnSubnetListSelect(ItemList.ItemListSelectedEventArgs args)
     {
         CameraSelected!((string) SubnetList[args.ItemIndex].Metadata!);