Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player Customization #1626

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Content.Client/Humanoid/HumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ public override void LoadProfile(EntityUid uid, HumanoidCharacterProfile? profil
humanoid.CustomBaseLayers = customBaseLayers;
humanoid.Sex = profile.Sex;
humanoid.Gender = profile.Gender;
humanoid.DisplayPronouns = profile.DisplayPronouns;
humanoid.StationAiName = profile.StationAiName;
humanoid.CyborgName = profile.CyborgName;
humanoid.Age = profile.Age;
humanoid.Species = profile.Species;
humanoid.SkinColor = profile.Appearance.SkinColor;
Expand Down
5 changes: 4 additions & 1 deletion Content.Client/Lobby/LobbyUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using static Content.Shared.Humanoid.SharedHumanoidAppearanceSystem;
using CharacterSetupGui = Content.Client.Lobby.UI.CharacterSetupGui;
Expand All @@ -38,6 +39,7 @@ public sealed class LobbyUIController : UIController, IOnStateEntered<LobbyState
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly JobRequirementsManager _requirements = default!;
[Dependency] private readonly MarkingManager _markings = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly JobRequirementsManager _jobRequirements = default!;
[UISystemDependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[UISystemDependency] private readonly ClientInventorySystem _inventory = default!;
Expand Down Expand Up @@ -202,7 +204,8 @@ private void SaveProfile()
_playerManager,
_prototypeManager,
_requirements,
_markings);
_markings,
_random);

_characterSetup = new CharacterSetupGui(EntityManager, _prototypeManager, _resourceCache, _preferencesManager, _profileEditor);

Expand Down
18 changes: 18 additions & 0 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@
<Control HorizontalExpand="True"/>
<OptionButton Name="PronounsButton" HorizontalAlignment="Right" />
</BoxContainer>
<!-- Customizable, cosmetic pronouns -->
<BoxContainer Name="CosmeticPronousContainer" HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-display-pronouns-label'}" />
<Control HorizontalExpand="True"/>
<LineEdit Name="CosmeticPronounsNameEdit" MinSize="270 0" HorizontalAlignment="Right" />
</BoxContainer>
<!-- Station AI name -->
<BoxContainer Name="StationAiNameContainer" HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-station-ai-name-label'}" />
<Control HorizontalExpand="True"/>
<LineEdit Name="StationAINameEdit" MinSize="270 0" HorizontalAlignment="Right" />
</BoxContainer>
<!-- Cyborg name -->
<BoxContainer Name="CyborgNameContainer" HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-cyborg-name-label'}" />
<Control HorizontalExpand="True"/>
<LineEdit Name="CyborgNameEdit" MinSize="270 0" HorizontalAlignment="Right" />
</BoxContainer>
<!-- Show clothing -->
<BoxContainer HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-clothing'}" />
Expand Down
156 changes: 153 additions & 3 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Content.Shared.Clothing.Loadouts.Prototypes;
using Content.Shared.Clothing.Loadouts.Systems;
using Content.Shared.Customization.Systems;
using Content.Shared.Dataset;
using Content.Shared.GameTicking;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
Expand All @@ -33,6 +34,7 @@
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using Direction = Robust.Shared.Maths.Direction;

Expand All @@ -51,6 +53,8 @@ public sealed partial class HumanoidProfileEditor : BoxContainer
private readonly JobRequirementsManager _requirements;
private readonly CharacterRequirementsSystem _characterRequirementsSystem;
private readonly LobbyUIController _controller;
private readonly IRobustRandom _random;

private FlavorText.FlavorText? _flavorText;
private BoxContainer _ccustomspecienamecontainerEdit => CCustomSpecieName;
private LineEdit _customspecienameEdit => CCustomSpecieNameEdit;
Expand Down Expand Up @@ -82,11 +86,21 @@ public sealed partial class HumanoidProfileEditor : BoxContainer
private Direction _previewRotation = Direction.North;
private ColorSelectorSliders _rgbSkinColorSelector;

private bool _customizePronouns;
private bool _customizeStationAiName;
private bool _customizeBorgName;

public event Action<HumanoidCharacterProfile, int>? OnProfileChanged;

[ValidatePrototypeId<GuideEntryPrototype>]
private const string DefaultSpeciesGuidebook = "Species";

[ValidatePrototypeId<LocalizedDatasetPrototype>]
private const string StationAiNames = "NamesAI";

[ValidatePrototypeId<DatasetPrototype>]
private const string CyborgNames = "names_borg";

public HumanoidProfileEditor(
IClientPreferencesManager preferencesManager,
IConfigurationManager cfgManager,
Expand All @@ -95,7 +109,8 @@ public HumanoidProfileEditor(
IPlayerManager playerManager,
IPrototypeManager prototypeManager,
JobRequirementsManager requirements,
MarkingManager markings
MarkingManager markings,
IRobustRandom random
)
{
RobustXamlLoader.Load(this);
Expand All @@ -107,6 +122,8 @@ MarkingManager markings
_markingManager = markings;
_preferencesManager = preferencesManager;
_requirements = requirements;
_random = random;

_characterRequirementsSystem = _entManager.System<CharacterRequirementsSystem>();
_controller = UserInterfaceManager.GetUIController<LobbyUIController>();

Expand All @@ -131,11 +148,11 @@ MarkingManager markings

#endregion Name

#region Custom Specie Name
#region Custom Species Name

_customspecienameEdit.OnTextChanged += args => { SetCustomSpecieName(args.Text); };

#endregion CustomSpecieName
#endregion Custom Species Name

#region Appearance

Expand Down Expand Up @@ -175,10 +192,44 @@ MarkingManager markings
{
PronounsButton.SelectId(args.Id);
SetGender((Gender) args.Id);

if (Profile?.DisplayPronouns == null)
UpdateDisplayPronounsControls();
};

#endregion Gender

#region Cosmetic Pronouns

_customizePronouns = _cfgManager.GetCVar(CCVars.AllowCosmeticPronouns);
_cfgManager.OnValueChanged(CCVars.AllowCosmeticPronouns, OnCosmeticPronounsValueChanged);

CosmeticPronounsNameEdit.OnTextChanged += args => { SetDisplayPronouns(args.Text); };

if (CosmeticPronousContainer.Visible != _customizePronouns)
CosmeticPronousContainer.Visible = _customizePronouns;

#endregion Cosmetic Pronouns

#region Custom Names

_customizeStationAiName = _cfgManager.GetCVar(CCVars.AllowCustomStationAiName);
_customizeBorgName = _cfgManager.GetCVar(CCVars.AllowCustomCyborgName);

_cfgManager.OnValueChanged(CCVars.AllowCustomStationAiName, OnChangedStationAiNameCustomizationValue);
_cfgManager.OnValueChanged(CCVars.AllowCustomCyborgName, OnChangedCyborgNameCustomizationValue);

StationAINameEdit.OnTextChanged += args => { SetStationAiName(args.Text); };
CyborgNameEdit.OnTextChanged += args => { SetCyborgName(args.Text); };

if (StationAiNameContainer.Visible != _customizeStationAiName)
StationAiNameContainer.Visible = _customizeStationAiName;

if (CyborgNameContainer.Visible != _customizeBorgName)
CyborgNameContainer.Visible = _customizeBorgName;

#endregion

#region Species

RefreshSpecies();
Expand Down Expand Up @@ -512,6 +563,24 @@ public void RefreshFlavorText()
}
}

private void OnCosmeticPronounsValueChanged(bool newValue)
{
_customizePronouns = newValue;
CosmeticPronousContainer.Visible = newValue;
}

private void OnChangedStationAiNameCustomizationValue(bool newValue)
{
_customizeStationAiName = newValue;
StationAiNameContainer.Visible = newValue;
}

private void OnChangedCyborgNameCustomizationValue(bool newValue)
{
_customizeBorgName = newValue;
CyborgNameContainer.Visible = newValue;
}

/// Refreshes the species selector
public void RefreshSpecies()
{
Expand Down Expand Up @@ -640,6 +709,9 @@ public void SetProfile(HumanoidCharacterProfile? profile, int? slot)
UpdateNameEdit();
UpdateSexControls();
UpdateGenderControls();
UpdateDisplayPronounsControls();
UpdateStationAiControls();
UpdateCyborgControls();
UpdateSkinColor();
UpdateSpawnPriorityControls();
UpdateFlavorTextEdit();
Expand Down Expand Up @@ -1146,6 +1218,40 @@ private void SetGender(Gender newGender)
IsDirty = true;
}

private void SetDisplayPronouns(string? displayPronouns)
{
if (displayPronouns == GetFormattedPronounsFromGender())
displayPronouns = null;

Profile = Profile?.WithDisplayPronouns(displayPronouns);
ReloadPreview();
IsDirty = true;
}

private void SetStationAiName(string? stationAiName)
{
Profile = Profile?.WithStationAiName(stationAiName);
ReloadPreview();
IsDirty = true;
}

private void SetCyborgName(string? cyborgName)
{
Profile = Profile?.WithCyborgName(cyborgName);
ReloadPreview();
IsDirty = true;
}

private string GetFormattedPronounsFromGender()
{
if (Profile == null)
return "they/them";

var genderName = Enum.GetName(typeof(Gender), Profile.Gender) ?? "Epicene";
var label = Loc.GetString($"humanoid-profile-editor-pronouns-{genderName.ToLower()}-text");
return label.Replace(" ", string.Empty).ToLower();
}

private void SetSpecies(string newSpecies)
{
Profile = Profile?.WithSpecies(newSpecies);
Expand Down Expand Up @@ -1357,6 +1463,50 @@ private void UpdateGenderControls()
PronounsButton.SelectId((int) Profile.Gender);
}

private void UpdateDisplayPronounsControls()
{
if (Profile == null)
return;

var label = GetFormattedPronounsFromGender();
CosmeticPronounsNameEdit.PlaceHolder = label;

if (Profile.DisplayPronouns == null)
CosmeticPronounsNameEdit.Text = string.Empty;
else
CosmeticPronounsNameEdit.Text = Profile.DisplayPronouns;
}

private void UpdateStationAiControls()
{
if (Profile == null)
return;

StationAINameEdit.Text = Profile.StationAiName ?? string.Empty;

if (StationAINameEdit.Text != string.Empty)
return;

var stationAiNames = _prototypeManager.Index<LocalizedDatasetPrototype>(StationAiNames);
var randomName = _random.Pick(stationAiNames.Values);
StationAINameEdit.PlaceHolder = Loc.GetString(randomName);
}

private void UpdateCyborgControls()
{
if (Profile == null)
return;

CyborgNameEdit.Text = Profile.CyborgName ?? string.Empty;

if (CyborgNameEdit.Text != string.Empty)
return;

var borgNames = _prototypeManager.Index<DatasetPrototype>(CyborgNames);
var randomName = _random.Pick(borgNames.Values);
CyborgNameEdit.PlaceHolder = Loc.GetString(randomName);
}

private void UpdateSpawnPriorityControls()
{
if (Profile == null)
Expand Down
Loading
Loading