Role ban UI updates (#16736)

This commit is contained in:
metalgearsloth
2023-05-27 14:22:22 +10:00
committed by GitHub
parent 4f678e0f25
commit be14380520
11 changed files with 255 additions and 120 deletions

View File

@@ -53,6 +53,7 @@ namespace Content.Client.Preferences.UI
private readonly IEntityManager _entMan;
private readonly IConfigurationManager _configurationManager;
private readonly MarkingManager _markingManager;
private readonly JobRequirementsManager _requirements;
private LineEdit _ageEdit => CAgeEdit;
private LineEdit _nameEdit => CNameEdit;
@@ -377,96 +378,9 @@ namespace Content.Client.Preferences.UI
_jobPriorities = new List<JobPrioritySelector>();
_jobCategories = new Dictionary<string, BoxContainer>();
var firstCategory = true;
var playTime = IoCManager.Resolve<PlayTimeTrackingManager>();
foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
{
var departmentName = Loc.GetString($"department-{department.ID}");
if (!_jobCategories.TryGetValue(department.ID, out var category))
{
category = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
Name = department.ID,
ToolTip = Loc.GetString("humanoid-profile-editor-jobs-amount-in-department-tooltip",
("departmentName", departmentName))
};
if (firstCategory)
{
firstCategory = false;
}
else
{
category.AddChild(new Control
{
MinSize = new Vector2(0, 23),
});
}
category.AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.FromHex("#464966")},
Children =
{
new Label
{
Text = Loc.GetString("humanoid-profile-editor-department-jobs-label",
("departmentName", departmentName)),
Margin = new Thickness(5f, 0, 0, 0)
}
}
});
_jobCategories[department.ID] = category;
_jobList.AddChild(category);
}
var jobs = department.Roles.Select(o => _prototypeManager.Index<JobPrototype>(o)).Where(o => o.SetPreference).ToList();
jobs.Sort((x, y) => -string.Compare(x.LocalizedName, y.LocalizedName, StringComparison.CurrentCultureIgnoreCase));
foreach (var job in jobs)
{
var selector = new JobPrioritySelector(job);
if (!playTime.IsAllowed(job, out var reason))
{
selector.LockRequirements(reason);
}
category.AddChild(selector);
_jobPriorities.Add(selector);
selector.PriorityChanged += priority =>
{
Profile = Profile?.WithJobPriority(job.ID, priority);
IsDirty = true;
foreach (var jobSelector in _jobPriorities)
{
// Sync other selectors with the same job in case of multiple department jobs
if (jobSelector.Job == selector.Job)
{
jobSelector.Priority = priority;
}
// Lower any other high priorities to medium.
if (priority == JobPriority.High)
{
if (jobSelector.Job != selector.Job && jobSelector.Priority == JobPriority.High)
{
jobSelector.Priority = JobPriority.Medium;
Profile = Profile?.WithJobPriority(jobSelector.Job.ID, JobPriority.Medium);
}
}
}
};
}
}
_requirements = IoCManager.Resolve<JobRequirementsManager>();
_requirements.Updated += UpdateRoleRequirements;
UpdateRoleRequirements();
#endregion Jobs
@@ -603,6 +517,101 @@ namespace Content.Client.Preferences.UI
IsDirty = false;
}
private void UpdateRoleRequirements()
{
_jobList.DisposeAllChildren();
_jobPriorities.Clear();
_jobCategories.Clear();
var firstCategory = true;
foreach (var department in _prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
{
var departmentName = Loc.GetString($"department-{department.ID}");
if (!_jobCategories.TryGetValue(department.ID, out var category))
{
category = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
Name = department.ID,
ToolTip = Loc.GetString("humanoid-profile-editor-jobs-amount-in-department-tooltip",
("departmentName", departmentName))
};
if (firstCategory)
{
firstCategory = false;
}
else
{
category.AddChild(new Control
{
MinSize = new Vector2(0, 23),
});
}
category.AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.FromHex("#464966")},
Children =
{
new Label
{
Text = Loc.GetString("humanoid-profile-editor-department-jobs-label",
("departmentName", departmentName)),
Margin = new Thickness(5f, 0, 0, 0)
}
}
});
_jobCategories[department.ID] = category;
_jobList.AddChild(category);
}
var jobs = department.Roles.Select(o => _prototypeManager.Index<JobPrototype>(o)).Where(o => o.SetPreference).ToList();
jobs.Sort((x, y) => -string.Compare(x.LocalizedName, y.LocalizedName, StringComparison.CurrentCultureIgnoreCase));
foreach (var job in jobs)
{
var selector = new JobPrioritySelector(job);
if (!_requirements.IsAllowed(job, out var reason))
{
selector.LockRequirements(reason);
}
category.AddChild(selector);
_jobPriorities.Add(selector);
selector.PriorityChanged += priority =>
{
Profile = Profile?.WithJobPriority(job.ID, priority);
IsDirty = true;
foreach (var jobSelector in _jobPriorities)
{
// Sync other selectors with the same job in case of multiple department jobs
if (jobSelector.Job == selector.Job)
{
jobSelector.Priority = priority;
}
// Lower any other high priorities to medium.
if (priority == JobPriority.High)
{
if (jobSelector.Job != selector.Job && jobSelector.Priority == JobPriority.High)
{
jobSelector.Priority = JobPriority.Medium;
Profile = Profile?.WithJobPriority(jobSelector.Job.ID, JobPriority.Medium);
}
}
}
};
}
}
}
private void OnFlavorTextChange(string content)
{
if (Profile is null)
@@ -694,6 +703,8 @@ namespace Content.Client.Preferences.UI
if (_previewDummy != null)
_entMan.DeleteEntity(_previewDummy.Value);
var playTime = IoCManager.Resolve<JobRequirementsManager>();
playTime.Updated -= UpdateRoleRequirements;
_preferencesManager.OnServerDataLoaded -= LoadServerData;
}