diff --git a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs index f23fd6b4a0d..056643422a6 100644 --- a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs @@ -1678,7 +1678,7 @@ public void UpdateTraits(bool? showUnusable = null, bool reload = false) // Reset the whole UI and delete caches if (reload) { - foreach (var tab in TraitsTabs.Tabs) + foreach (var tab in TraitsTabs.TabContainer.Children) TraitsTabs.RemoveTab(tab); _loadoutPreferences.Clear(); } @@ -2004,14 +2004,13 @@ public void UpdateLoadouts(bool? showUnusable = null, bool reload = false) // Reset the whole UI and delete caches if (reload) { - foreach (var tab in LoadoutsTabs.Tabs) + foreach (var tab in LoadoutsTabs.TabContainer.Children) LoadoutsTabs.RemoveTab(tab); foreach (var uid in _dummyLoadouts) _entManager.QueueDeleteEntity(uid.Value); _loadoutPreferences.Clear(); } - // Get the highest priority job to use for loadout filtering var highJob = _controller.GetPreferredJob(Profile ?? HumanoidCharacterProfile.DefaultWithSpecies()); @@ -2031,13 +2030,6 @@ public void UpdateLoadouts(bool? showUnusable = null, bool reload = false) out _ ); _loadouts.Add(loadout, usable); - - var list = _loadoutPreferences.ToList(); - if (list.FindIndex(lps => lps.Loadout.ID == loadout.ID) is not (not -1 and var i)) - continue; - - var selector = list[i]; - UpdateSelector(selector, usable); } if (_loadouts.Count == 0) @@ -2047,7 +2039,6 @@ out _ return; } - var uncategorized = LoadoutsTabs.Contents.FirstOrDefault(c => c.Name == "Uncategorized"); if (uncategorized == null) { @@ -2091,76 +2082,18 @@ out _ categories.Add(key, value); // Create the UI elements for the category tree - CreateCategoryUI(categories, LoadoutsTabs); - - // Fill categories with loadouts - foreach (var (loadout, usable) in _loadouts + var sortedLoadouts = _loadouts .OrderBy(l => l.Key.ID) .ThenBy(l => Loc.GetString($"loadout-name-{l.Key.ID}")) - .ThenBy(l => l.Key.Cost)) - { - if (_loadoutPreferences.Select(lps => lps.Loadout.ID).Contains(loadout.ID)) - { - var first = _loadoutPreferences.First(lps => lps.Loadout.ID == loadout.ID); - var prof = Profile?.LoadoutPreferences.FirstOrDefault(lp => lp.LoadoutName == loadout.ID); - first.Preference = new(loadout.ID, prof?.CustomName, prof?.CustomDescription, prof?.CustomColorTint, prof?.CustomHeirloom); - UpdateSelector(first, usable); - continue; - } - - var selector = new LoadoutPreferenceSelector( - loadout, highJob ?? new JobPrototype(), - Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(), ref _dummyLoadouts, - _entManager, _prototypeManager, _cfgManager, _characterRequirementsSystem, _requirements) - { Preference = new(loadout.ID) }; - UpdateSelector(selector, usable); - AddSelector(selector); - - // Look for an existing category tab - var match = FindCategory(loadout.Category, LoadoutsTabs); - - // If there is no category put it in Uncategorized (this shouldn't happen) - (match ?? uncategorized).Children.First().Children.First().AddChild(selector); - } + .ThenBy(l => l.Key.Cost); + CreateCategoryUI(categories, LoadoutsTabs); - // Hide any empty tabs - HideEmptyTabs(_prototypeManager.EnumeratePrototypes().ToList()); + // Hide any empty tabs //TODO: This is broken + // HideEmptyTabs(_prototypeManager.EnumeratePrototypes().ToList()); UpdateLoadoutPreferences(); return; - - void UpdateSelector(LoadoutPreferenceSelector selector, bool usable) - { - selector.Valid = usable; - selector.ShowUnusable = showUnusable.Value; - - foreach (var item in selector.Loadout.Items) - { - if (_dummyLoadouts.TryGetValue(selector.Loadout.ID + selector.Loadout.Items.IndexOf(item), out var entity) - && _entManager.GetComponent(entity).EntityPrototype!.ID == item) - { - if (!_entManager.HasComponent(entity)) - { - selector.Wearable = true; - continue; - } - selector.Wearable = _characterRequirementsSystem.CanEntityWearItem(PreviewDummy, entity); - continue; - } - - entity = _entManager.SpawnEntity(item, MapCoordinates.Nullspace); - _dummyLoadouts[selector.Loadout.ID + selector.Loadout.Items.IndexOf(item)] = entity; - - if (!_entManager.HasComponent(entity)) - { - selector.Wearable = true; - continue; - } - selector.Wearable = _characterRequirementsSystem.CanEntityWearItem(PreviewDummy, entity); - } - } - void CreateCategoryUI(Dictionary tree, NeoTabContainer parent) { foreach (var (key, value) in tree) @@ -2198,7 +2131,8 @@ void CreateCategoryUI(Dictionary tree, NeoTabContainer parent) }, }; - parent.AddTab(category, Loc.GetString($"loadout-category-{key}")); + var i = parent.AddTab(category, Loc.GetString($"loadout-category-{key}")); + parent.GetTabInfo(i).Initialize = () => LoadCategoryLoadouts(category, key); } // If the value is a dictionary, create a new tab for it and recursively call this function to fill it else @@ -2208,12 +2142,68 @@ void CreateCategoryUI(Dictionary tree, NeoTabContainer parent) Name = key, HorizontalExpand = true, VerticalExpand = true, - SeparatorMargin = new Thickness(0), + SeparatorMargin = new(0), }; - parent.AddTab(category, Loc.GetString($"loadout-category-{key}")); - CreateCategoryUI((Dictionary) value, category); + var i = parent.AddTab(category, Loc.GetString($"loadout-category-{key}")); + parent.GetTabInfo(i).Initialize = () => CreateCategoryUI((Dictionary) value, category); + } + } + } + + void LoadCategoryLoadouts(BoxContainer category, string key) + { + foreach (var (loadout, usable) in sortedLoadouts.Where(l => l.Key.Category == key)) + { + if (_loadoutPreferences.Select(lps => lps.Loadout.ID).Contains(loadout.ID)) + { + var first = _loadoutPreferences.First(lps => lps.Loadout.ID == loadout.ID); + var prof = Profile?.LoadoutPreferences.FirstOrDefault(lp => lp.LoadoutName == loadout.ID); + first.Preference = new(loadout.ID, prof?.CustomName, prof?.CustomDescription, prof?.CustomColorTint, prof?.CustomHeirloom); + UpdateSelector(first, usable); + continue; + } + + var selector = new LoadoutPreferenceSelector( + loadout, highJob ?? new JobPrototype(), + Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(), ref _dummyLoadouts, + _entManager, _prototypeManager, _cfgManager, _characterRequirementsSystem, _requirements) + { Preference = new(loadout.ID), }; + UpdateSelector(selector, usable); + AddSelector(selector); + + category.Children.First().Children.First().AddChild(selector); + } + } + + void UpdateSelector(LoadoutPreferenceSelector selector, bool usable) + { + selector.Valid = usable; + selector.ShowUnusable = showUnusable.Value; + + foreach (var item in selector.Loadout.Items) + { + if (_dummyLoadouts.TryGetValue(selector.Loadout.ID + selector.Loadout.Items.IndexOf(item), out var entity) + && _entManager.GetComponent(entity).EntityPrototype!.ID == item) + { + if (!_entManager.HasComponent(entity)) + { + selector.Wearable = true; + continue; + } + selector.Wearable = _characterRequirementsSystem.CanEntityWearItem(PreviewDummy, entity); + continue; + } + + entity = _entManager.SpawnEntity(item, MapCoordinates.Nullspace); + _dummyLoadouts[selector.Loadout.ID + selector.Loadout.Items.IndexOf(item)] = entity; + + if (!_entManager.HasComponent(entity)) + { + selector.Wearable = true; + continue; } + selector.Wearable = _characterRequirementsSystem.CanEntityWearItem(PreviewDummy, entity); } } diff --git a/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml b/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml index e04fdc1c69b..d77fdb66057 100644 --- a/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml +++ b/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml @@ -8,7 +8,8 @@ Name="PreferenceButton" Access="Public" ToggleMode="True" - VerticalAlignment="Center" /> + VerticalAlignment="Center" + StyleClasses="OpenRight" />