diff --git a/Content.Client/Lobby/LobbyUIController.cs b/Content.Client/Lobby/LobbyUIController.cs index 26643cb603..7f3ad60c3d 100644 --- a/Content.Client/Lobby/LobbyUIController.cs +++ b/Content.Client/Lobby/LobbyUIController.cs @@ -41,7 +41,7 @@ public sealed class LobbyUIController : UIController, IOnStateEntered() - .LoadProfileEntity(humanoid, true); + .LoadProfileEntity(humanoid, true, true); var highPriorityJob = humanoid.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key; if (highPriorityJob != null) diff --git a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs index c4e1e1fc13..f23fd6b4a0 100644 --- a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs @@ -11,6 +11,7 @@ using Content.Shared.CCVar; using Content.Shared.Clothing.Components; using Content.Shared.Clothing.Loadouts.Prototypes; +using Content.Shared.Clothing.Loadouts.Systems; using Content.Shared.Customization.Systems; using Content.Shared.GameTicking; using Content.Shared.Humanoid; @@ -76,7 +77,7 @@ public sealed partial class HumanoidProfileEditor : BoxContainer private Dictionary _confirmationData = new(); private List _traitPreferences = new(); private int _traitCount; - private List _loadoutPreferences = new(); + private HashSet _loadoutPreferences = new(); private Direction _previewRotation = Direction.North; private ColorSelectorSliders _rgbSkinColorSelector; @@ -427,7 +428,7 @@ public HumanoidProfileEditor( // Set up the loadouts tab LoadoutsTab.Orphan(); CTabContainer.AddTab(LoadoutsTab, Loc.GetString("humanoid-profile-editor-loadouts-tab")); - _loadoutPreferences = new List(); + _loadoutPreferences = new(); // Show/Hide the loadouts tab if they ever get enabled/disabled var loadoutsEnabled = cfgManager.GetCVar(CCVars.GameLoadoutsEnabled); @@ -473,7 +474,8 @@ public HumanoidProfileEditor( #endregion Left - ShowClothes.OnToggled += args => { ReloadProfilePreview(); }; + ShowClothes.OnToggled += _ => { SetProfile(Profile, CharacterSlot); }; + ShowLoadouts.OnToggled += _ => { SetProfile(Profile, CharacterSlot); }; SpeciesInfoButton.OnPressed += OnSpeciesInfoButtonPressed; UpdateSpeciesGuidebookIcon(); @@ -614,7 +616,7 @@ private void ReloadPreview() if (Profile == null || !_prototypeManager.HasIndex(Profile.Species)) return; - PreviewDummy = _controller.LoadProfileEntity(Profile, ShowClothes.Pressed); + PreviewDummy = _controller.LoadProfileEntity(Profile, ShowClothes.Pressed, ShowLoadouts.Pressed); SpriteView.SetEntity(PreviewDummy); } @@ -823,20 +825,6 @@ public void RefreshJobs() UpdateJobPriorities(); } - private void ToggleClothes(BaseButton.ButtonEventArgs _) - { - //TODO: Optimization - // _controller.ShowClothes = ShowClothes.Pressed; - // _controller.UpdateCharacterUI(); - } - - private void ToggleLoadouts(BaseButton.ButtonEventArgs _) - { - //TODO: Optimization - // _controller.ShowLoadouts = ShowLoadouts.Pressed; - // _controller.UpdateCharacterUI(); - } - private void UpdateRoleRequirements() { JobList.DisposeAllChildren(); @@ -959,7 +947,7 @@ private void UpdateRoleRequirements() Profile = Profile?.WithJobPriority(job.ID, (JobPriority) priority); ReloadPreview(); SetDirty(); - UpdateCharacterRequired(); + SetProfile(Profile, CharacterSlot); }; _jobPriorities.Add((job.ID, selector)); @@ -1610,7 +1598,7 @@ private async void ExportProfile() } catch (Exception exc) { - Logger.Error($"Error when exporting profile\n{exc.StackTrace}"); + Logger.Error($"Error when exporting profile: {exc.Message}\n{exc.StackTrace}"); } finally { @@ -1882,7 +1870,7 @@ void AddSelector(TraitPreferenceSelector selector) Profile = Profile?.WithTraitPreference(selector.Trait.ID, preference); IsDirty = true; UpdateTraitPreferences(); - UpdateCharacterRequired(); + SetProfile(Profile, CharacterSlot); }; } @@ -1969,11 +1957,18 @@ private void UpdateLoadoutPreferences() foreach (var preferenceSelector in _loadoutPreferences) { var loadoutId = preferenceSelector.Loadout.ID; - var preference = Profile?.LoadoutPreferences.Contains(loadoutId) ?? false; + var loadoutPreference = Profile?.LoadoutPreferences.FirstOrDefault(l => l.LoadoutName == loadoutId) ?? preferenceSelector.Preference; + var preference = new LoadoutPreference( + loadoutPreference.LoadoutName, + loadoutPreference.CustomName, + loadoutPreference.CustomDescription, + loadoutPreference.CustomColorTint, + loadoutPreference.CustomHeirloom) + { Selected = loadoutPreference.Selected }; preferenceSelector.Preference = preference; - if (preference) + if (preference.Selected) { points -= preferenceSelector.Loadout.Cost; LoadoutPointsBar.Value = points; @@ -1985,14 +1980,12 @@ private void UpdateLoadoutPreferences() LoadoutsRemoveUnusableButton.Text = Loc.GetString("humanoid-profile-editor-loadouts-remove-unusable-button", ("count", _loadouts .Where(l => _loadoutPreferences - .Where(lps => lps.Preference).Select(lps => lps.Loadout).Contains(l.Key)) + .Where(lps => lps.Preference.Selected).Select(lps => lps.Loadout).Contains(l.Key)) .Count(l => !l.Value - || !_loadoutPreferences.Find(lps => lps.Loadout == l.Key)!.Wearable))); + || !_loadoutPreferences.First(lps => lps.Loadout == l.Key).Wearable))); AdminUIHelpers.RemoveConfirm(LoadoutsRemoveUnusableButton, _confirmationData); IsDirty = true; - //TODO: Optimization - // _controller.UpdateClothes = true; ReloadProfilePreview(); } @@ -2039,10 +2032,11 @@ out _ ); _loadouts.Add(loadout, usable); - if (_loadoutPreferences.FindIndex(lps => lps.Loadout.ID == loadout.ID) is not (not -1 and var i)) + var list = _loadoutPreferences.ToList(); + if (list.FindIndex(lps => lps.Loadout.ID == loadout.ID) is not (not -1 and var i)) continue; - var selector = _loadoutPreferences[i]; + var selector = list[i]; UpdateSelector(selector, usable); } @@ -2108,6 +2102,8 @@ out _ 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; } @@ -2115,7 +2111,8 @@ out _ var selector = new LoadoutPreferenceSelector( loadout, highJob ?? new JobPrototype(), Profile ?? HumanoidCharacterProfile.DefaultWithSpecies(), ref _dummyLoadouts, - _entManager, _prototypeManager, _cfgManager, _characterRequirementsSystem, _requirements); + _entManager, _prototypeManager, _cfgManager, _characterRequirementsSystem, _requirements) + { Preference = new(loadout.ID) }; UpdateSelector(selector, usable); AddSelector(selector); @@ -2226,13 +2223,21 @@ void AddSelector(LoadoutPreferenceSelector selector) selector.PreferenceChanged += preference => { // Make sure they have enough loadout points - preference = preference ? CheckPoints(-selector.Loadout.Cost, preference) : CheckPoints(selector.Loadout.Cost, preference); + var selected = preference.Selected + ? CheckPoints(-selector.Loadout.Cost, preference.Selected) + : CheckPoints(selector.Loadout.Cost, preference.Selected); // Update Preferences - Profile = Profile?.WithLoadoutPreference(selector.Loadout.ID, preference); + Profile = Profile?.WithLoadoutPreference( + selector.Loadout.ID, + selected, + preference.CustomName, + preference.CustomDescription, + preference.CustomColorTint, + preference.CustomHeirloom); IsDirty = true; UpdateLoadoutPreferences(); - UpdateCharacterRequired(); + SetProfile(Profile, CharacterSlot); }; } @@ -2320,7 +2325,7 @@ private void TryRemoveUnusableLoadouts() // Remove unusable and unwearable loadouts foreach (var (loadout, _) in _loadouts.Where(l => - !l.Value || !_loadoutPreferences.Find(lps => lps.Loadout.ID == l.Key.ID)!.Wearable).ToList()) + !l.Value || !_loadoutPreferences.First(lps => lps.Loadout.ID == l.Key.ID).Wearable).ToList()) Profile = Profile?.WithLoadoutPreference(loadout.ID, false); UpdateCharacterRequired(); } diff --git a/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml b/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml index a6fbf162bc..e04fdc1c69 100644 --- a/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml +++ b/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml @@ -1,10 +1,77 @@ - - + + + + +