Skip to content

Commit

Permalink
EE Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisfiregamer1 committed Nov 25, 2024
2 parents dc4f27b + 57917a7 commit e5271a0
Show file tree
Hide file tree
Showing 78 changed files with 9,028 additions and 280 deletions.
24 changes: 11 additions & 13 deletions Content.Client/Lobby/LobbyUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public sealed class LobbyUIController : UIController, IOnStateEntered<LobbyState
[Dependency] private readonly JobRequirementsManager _jobRequirements = default!;
[UISystemDependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[UISystemDependency] private readonly ClientInventorySystem _inventory = default!;
[UISystemDependency] private readonly LoadoutSystem _loadouts = default!;
[UISystemDependency] private readonly SharedLoadoutSystem _loadouts = default!;

private CharacterSetupGui? _characterSetup;
private HumanoidProfileEditor? _profileEditor;
Expand Down Expand Up @@ -159,7 +159,7 @@ private void RefreshLobbyPreview()
return;
}

var dummy = LoadProfileEntity(humanoid, true);
var dummy = LoadProfileEntity(humanoid, true, true);
PreviewPanel.SetSprite(dummy);
PreviewPanel.SetSummaryText(humanoid.Summary);
}
Expand Down Expand Up @@ -262,14 +262,6 @@ public void RemoveDummyClothes(EntityUid dummy)
EntityManager.DeleteEntity(unequippedItem.Value);
}

/// Applies the highest priority job's clothes and loadouts to the dummy.
public void GiveDummyJobClothesLoadout(EntityUid dummy, HumanoidCharacterProfile profile)
{
var job = GetPreferredJob(profile);
GiveDummyJobClothes(dummy, job, profile);
_loadouts.ApplyCharacterLoadout(dummy, job, profile, _jobRequirements.GetRawPlayTimeTrackers(), _jobRequirements.IsWhitelisted());
}

/// Applies the specified job's clothes to the dummy.
public void GiveDummyJobClothes(EntityUid dummy, JobPrototype job, HumanoidCharacterProfile profile)
{
Expand All @@ -295,7 +287,7 @@ public void GiveDummyJobClothes(EntityUid dummy, JobPrototype job, HumanoidChara
}

/// Loads the profile onto a dummy entity
public EntityUid LoadProfileEntity(HumanoidCharacterProfile? humanoid, bool jobClothes)
public EntityUid LoadProfileEntity(HumanoidCharacterProfile? humanoid, bool jobClothes, bool loadouts)
{
EntityUid dummyEnt;

Expand All @@ -311,8 +303,14 @@ public EntityUid LoadProfileEntity(HumanoidCharacterProfile? humanoid, bool jobC

_humanoid.LoadProfile(dummyEnt, humanoid);

if (humanoid != null && jobClothes)
GiveDummyJobClothesLoadout(dummyEnt, humanoid);
if (humanoid != null)
{
var job = GetPreferredJob(humanoid);
if (jobClothes)
GiveDummyJobClothes(dummyEnt, job, humanoid);
if (loadouts)
_loadouts.ApplyCharacterLoadout(dummyEnt, job, humanoid, _jobRequirements.GetRawPlayTimeTrackers(), _jobRequirements.IsWhitelisted(), out _);
}

return dummyEnt;
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Lobby/UI/CharacterPickerButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public CharacterPickerButton(
else
{
_previewDummy = UserInterfaceManager.GetUIController<LobbyUIController>()
.LoadProfileEntity(humanoid, true);
.LoadProfileEntity(humanoid, true, true);

var highPriorityJob = humanoid.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key;
if (highPriorityJob != null)
Expand Down
73 changes: 39 additions & 34 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,7 +77,7 @@ public sealed partial class HumanoidProfileEditor : BoxContainer
private Dictionary<Button, ConfirmationData> _confirmationData = new();
private List<TraitPreferenceSelector> _traitPreferences = new();
private int _traitCount;
private List<LoadoutPreferenceSelector> _loadoutPreferences = new();
private HashSet<LoadoutPreferenceSelector> _loadoutPreferences = new();

private Direction _previewRotation = Direction.North;
private ColorSelectorSliders _rgbSkinColorSelector;
Expand Down Expand Up @@ -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<LoadoutPreferenceSelector>();
_loadoutPreferences = new();

// Show/Hide the loadouts tab if they ever get enabled/disabled
var loadoutsEnabled = cfgManager.GetCVar(CCVars.GameLoadoutsEnabled);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -614,7 +616,7 @@ private void ReloadPreview()
if (Profile == null || !_prototypeManager.HasIndex<SpeciesPrototype>(Profile.Species))
return;

PreviewDummy = _controller.LoadProfileEntity(Profile, ShowClothes.Pressed);
PreviewDummy = _controller.LoadProfileEntity(Profile, ShowClothes.Pressed, ShowLoadouts.Pressed);
SpriteView.SetEntity(PreviewDummy);
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -1882,7 +1870,7 @@ void AddSelector(TraitPreferenceSelector selector)
Profile = Profile?.WithTraitPreference(selector.Trait.ID, preference);
IsDirty = true;
UpdateTraitPreferences();
UpdateCharacterRequired();
SetProfile(Profile, CharacterSlot);
};
}

Expand Down Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -2108,14 +2102,17 @@ 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;
}

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

Expand Down Expand Up @@ -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);
};
}

Expand Down Expand Up @@ -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();
}
Expand Down
81 changes: 74 additions & 7 deletions Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,77 @@
<Control xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BoxContainer Name="Container" Orientation="Horizontal">
<Button
Name="PreferenceButton"
ToggleMode="True"
VerticalAlignment="Center"
StyleClasses="OpenLeft" />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls">
<BoxContainer Name="Container" Orientation="Vertical" HorizontalExpand="True">
<controls:StyledButtonGroup Name="ButtonGroup" Orientation="Horizontal" HorizontalExpand="True">
<Button
Name="PreferenceButton"
Access="Public"
ToggleMode="True"
VerticalAlignment="Center" />

<Button
Name="HeirloomButton"
Access="Public"
Text="{Loc 'humanoid-profile-editor-loadouts-heirloom'}"
ToolTip="{Loc 'humanoid-profile-editor-loadouts-heirloom-tooltip'}"
ToggleMode="True"
VerticalAlignment="Center" />

<!-- Yes I know I can use a TextureButton, but I'm doing this for style -->
<Button
Name="GuidebookButton"
ToolTip="{Loc 'humanoid-profile-editor-loadouts-guidebook-button-tooltip'}"
VerticalAlignment="Center"
StyleClasses="OpenLeft">
<TextureRect
Name="GuidebookButtonIcon"
TexturePath="/Textures/Interface/VerbIcons/information.svg.192dpi.png"
TextureScale="0.4 0.4"
VerticalAlignment="Center"
Margin="5" />
</Button>
</controls:StyledButtonGroup>


<Collapsible Name="SpecialMenu" HorizontalExpand="True">
<Button Name="HeadingButton" Text="{Loc 'humanoid-profile-editor-loadouts-customize'}" ToggleMode="True" />

<CollapsibleBody HorizontalExpand="True" Margin="0 0 0 5">
<PanelContainer HorizontalExpand="True">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#2f2f2f" BorderColor="#2f2f2faf" BorderThickness="1" />
</PanelContainer.PanelOverride>

<BoxContainer Orientation="Vertical" Margin="3" HorizontalExpand="True">
<BoxContainer Name="SpecialName" Orientation="Vertical" HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-loadouts-customize-name'}" />
<LineEdit Name="NameEdit" HorizontalExpand="True" />
</BoxContainer>

<BoxContainer Name="SpecialDescription" Orientation="Vertical" HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-loadouts-customize-description'}" />
<PanelContainer HorizontalExpand="True">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#222222" />
</PanelContainer.PanelOverride>

<controls:ResizableControl
AllowedResizeDirection="Vertical"
HorizontalExpand="True"
MinSize="128 64">
<TextEdit Name="DescriptionEdit" HorizontalExpand="True" VerticalExpand="True" Margin="3" />
</controls:ResizableControl>
</PanelContainer>
</BoxContainer>

<Button Name="SpecialColorTintToggle" Text="{Loc 'humanoid-profile-editor-loadouts-customize-color'}" ToggleMode="True" Margin="0 3 0 0" StyleClasses="OpenBoth" />
<ColorSelectorSliders Name="ColorEdit" Color="#fff" HorizontalExpand="True" />

<Button Name="SaveButton" Text="{Loc 'humanoid-profile-editor-loadouts-customize-save'}" HorizontalExpand="True" Margin="0 3 0 0" StyleClasses="OpenBoth" />
</BoxContainer>
</PanelContainer>
</CollapsibleBody>
</Collapsible>
</BoxContainer>
</Control>
Loading

0 comments on commit e5271a0

Please sign in to comment.