From 89e5f6de779a39e177951123d39fec9ffb9c5de6 Mon Sep 17 00:00:00 2001 From: "Isaac A. Sanch" Date: Fri, 29 Dec 2017 13:10:24 -0500 Subject: [PATCH] Sort prop and tree dropdowns by name. --- NetworkSkins/Props/PropCustomizer.cs | 14 +++++++------- NetworkSkins/Props/UITreeOption.cs | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/NetworkSkins/Props/PropCustomizer.cs b/NetworkSkins/Props/PropCustomizer.cs index aa5dd0e..5663f75 100644 --- a/NetworkSkins/Props/PropCustomizer.cs +++ b/NetworkSkins/Props/PropCustomizer.cs @@ -14,8 +14,8 @@ public class PropCustomizer : LoadingExtensionBase { public static PropCustomizer Instance; - private readonly List _availableTrees = new List(); - private readonly List _availableStreetLights = new List(); + private List _availableTrees = new List(); + private List _availableStreetLights = new List(); public int[] StreetLightPrefabDataIndices; @@ -39,9 +39,6 @@ public void OnUpdateData(SimulationManager.UpdateMode mode) && mode != SimulationManager.UpdateMode.LoadGame && mode != SimulationManager.UpdateMode.NewGameFromMap && mode != SimulationManager.UpdateMode.NewGameFromScenario) return; - // no trees - _availableTrees.Add(null); - for (uint i = 0; i < PrefabCollection.LoadedCount(); i++) { var prefab = PrefabCollection.GetLoaded(i); @@ -51,8 +48,8 @@ public void OnUpdateData(SimulationManager.UpdateMode mode) _availableTrees.Add(prefab); } - // no street lights - _availableStreetLights.Add(null); + _availableTrees = _availableTrees.OrderBy(prefab => UITreeOption.GenerateBeautifiedPrefabName(prefab).ToLowerInvariant().Replace("the ", "")).ToList(); + _availableTrees.Insert(0, null); for (uint i = 0; i < PrefabCollection.LoadedCount(); i++) { @@ -76,6 +73,9 @@ public void OnUpdateData(SimulationManager.UpdateMode mode) } } + _availableStreetLights = _availableStreetLights.OrderBy(prefab => prefab?.GetUncheckedLocalizedTitle().Trim().ToLowerInvariant().Replace("the ", "")).ToList(); + _availableStreetLights.Insert(0, null); + // compile list of data indices for fast check if a prefab is a street light: StreetLightPrefabDataIndices = _availableStreetLights.Where(prop => prop != null).Select(prop => prop.m_prefabDataIndex).ToArray(); } diff --git a/NetworkSkins/Props/UITreeOption.cs b/NetworkSkins/Props/UITreeOption.cs index f3b442d..6e3971c 100644 --- a/NetworkSkins/Props/UITreeOption.cs +++ b/NetworkSkins/Props/UITreeOption.cs @@ -36,8 +36,7 @@ protected override bool PopulateDropDown() foreach (var tree in _availableTrees) { - var itemName = UIUtil.GenerateBeautifiedPrefabName(tree); - itemName = BeautifyNameEvenMore(itemName); + var itemName = GenerateBeautifiedPrefabName(tree); if (tree == defaultTree) itemName += " (Default)"; DropDown.AddItem(itemName); @@ -62,9 +61,11 @@ protected override bool PopulateDropDown() return false; } - private string BeautifyNameEvenMore(string itemName) + public static string GenerateBeautifiedPrefabName(TreeInfo tree) { - switch(itemName) + var itemName = UIUtil.GenerateBeautifiedPrefabName(tree); + + switch (itemName) { case "Cherry Tree01": return "Cherry Tree"; case "Tree with Leaves": return "Small Oak";