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

Alternate job titles #74

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static void GiveDummyJobClothes(EntityUid dummy, HumanoidCharacterProfile
{
var protoMan = IoCManager.Resolve<IPrototypeManager>();
var entMan = IoCManager.Resolve<IEntityManager>();
var siriMan = IoCManager.Resolve<ISerializationManager>(); // funi var
var siriMan = IoCManager.Resolve<ISerializationManager>();
var invSystem = EntitySystem.Get<ClientInventorySystem>();

var highPriorityJob = profile.JobPriorities.FirstOrDefault(p => p.Value == JobPriority.High).Key;
Expand Down
12 changes: 9 additions & 3 deletions Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,16 @@ public CharacterPickerButton(
var description = profile.Name;

var highPriorityJob = humanoid?.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key;
if (highPriorityJob != null)
if (humanoid != null && highPriorityJob != null)
{
var jobName = IoCManager.Resolve<IPrototypeManager>().Index<JobPrototype>(highPriorityJob).LocalizedName;
description = $"{description}\n{jobName}";
// var jobName = IoCManager.Resolve<IPrototypeManager>().Index<JobPrototype>(highPriorityJob).LocalizedName;
// description = $"{description}\n{jobName}";
if (IoCManager.Resolve<IPrototypeManager>().TryIndex(highPriorityJob, out JobPrototype? job))
{
description = humanoid.JobCustomNames.TryGetValue(highPriorityJob, out var customName)
? $"{description}\n{Loc.GetString(customName)}"
: $"{description}\n{job.LocalizedName}";
}
}

var descriptionLabel = new Label
Expand Down
83 changes: 68 additions & 15 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IProt
}
};

selector.AltNameChanged += altName =>
{
Profile = Profile?.WithJobCustomName(job.ID, altName);
IsDirty = true;
};
}
}

Expand Down Expand Up @@ -1380,23 +1385,34 @@ private void UpdateJobPriorities()
var jobId = prioritySelector.Job.ID;

var priority = Profile?.JobPriorities.GetValueOrDefault(jobId, JobPriority.Never) ?? JobPriority.Never;

prioritySelector.Priority = priority;

var altName = Profile?.JobCustomNames.GetValueOrDefault(jobId, "default") ?? "default";
prioritySelector.AltName = altName;
}
}

private sealed class JobPrioritySelector : Control
{
public JobPrototype Job { get; }
private readonly RadioOptions<int> _optionButton;
private readonly OptionButton _altNamesButton;

public JobPriority Priority
{
get => (JobPriority) _optionButton.SelectedValue;
set => _optionButton.SelectByValue((int) value);
}

public readonly Dictionary<int, string> AltNames;
public string AltName
{
get => AltNames[_altNamesButton.SelectedId];
set => _altNamesButton.SelectId(AltNames.FirstOrDefault(x => x.Value == value).Key);
}

public event Action<JobPriority>? PriorityChanged;
public event Action<string>? AltNameChanged;

private StripeBack _lockStripe;
private Label _requirementsLabel;
Expand All @@ -1406,6 +1422,20 @@ public JobPrioritySelector(JobPrototype job)
{
Job = job;

_jobTitle = new Label()
{
Margin = new Thickness(5f,0,5f,0),
Text = job.LocalizedName,
MinSize = (180, 0),
MouseFilter = MouseFilterMode.Stop
};

if (job.LocalizedDescription != null)
{
_jobTitle.ToolTip = job.LocalizedDescription;
_jobTitle.TooltipDelay = 0.2f;
}

_optionButton = new RadioOptions<int>(RadioOptionsLayout.Horizontal)
{
FirstButtonStyle = StyleBase.ButtonOpenRight,
Expand All @@ -1426,6 +1456,42 @@ public JobPrioritySelector(JobPrototype job)
PriorityChanged?.Invoke(Priority);
};


_altNamesButton = new OptionButton
{
Margin = new Thickness(5f, 0, 5f, 0),
MinSize = (180, 0),
Visible = false,
};

AltNames = new Dictionary<int, string>();
AltNames.Add(0, "default");
_altNamesButton.AddItem(job.LocalizedName, 0);

_altNamesButton.OnItemSelected += args =>
{
_altNamesButton.Select(args.Id);
AltNameChanged?.Invoke(AltName);
};

if (Job.AltNames is { Length: > 0 })
{
_altNamesButton.Visible = true;
_jobTitle.Visible = false;

foreach (var alt in Job.AltNames)
{
AltNames.Add(AltNames.Count, alt);
_altNamesButton.AddItem(Loc.GetString(alt), AltNames.Count - 1);
}
}
else
{
_altNamesButton.Visible = false;
_jobTitle.Visible = true;
}


var icon = new TextureRect
{
TextureScale = (2, 2),
Expand Down Expand Up @@ -1459,27 +1525,14 @@ public JobPrioritySelector(JobPrototype job)
}
};

_jobTitle = new Label()
{
Margin = new Thickness(5f,0,5f,0),
Text = job.LocalizedName,
MinSize = (180, 0),
MouseFilter = MouseFilterMode.Stop
};

if (job.LocalizedDescription != null)
{
_jobTitle.ToolTip = job.LocalizedDescription;
_jobTitle.TooltipDelay = 0.2f;
}

AddChild(new BoxContainer
{
Orientation = LayoutOrientation.Horizontal,
Children =
{
icon,
_jobTitle,
_altNamesButton,
_optionButton,
_lockStripe,
}
Expand Down
Loading