Adds preference unavailable setting to profiles.
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Client.GameObjects.Components;
|
using Content.Client.GameObjects.Components;
|
||||||
using Content.Client.Interfaces;
|
using Content.Client.Interfaces;
|
||||||
|
using Content.Shared;
|
||||||
using Content.Shared.Jobs;
|
using Content.Shared.Jobs;
|
||||||
using Content.Shared.Preferences;
|
using Content.Shared.Preferences;
|
||||||
using Content.Shared.Text;
|
using Content.Shared.Text;
|
||||||
@@ -39,6 +40,7 @@ namespace Content.Client.UserInterface
|
|||||||
private readonly HairStylePicker _hairPicker;
|
private readonly HairStylePicker _hairPicker;
|
||||||
private readonly FacialHairStylePicker _facialHairPicker;
|
private readonly FacialHairStylePicker _facialHairPicker;
|
||||||
private readonly List<JobPrioritySelector> _jobPriorities;
|
private readonly List<JobPrioritySelector> _jobPriorities;
|
||||||
|
private readonly OptionButton _preferenceUnavailableButton;
|
||||||
|
|
||||||
private bool _isDirty;
|
private bool _isDirty;
|
||||||
public int CharacterSlot;
|
public int CharacterSlot;
|
||||||
@@ -109,10 +111,7 @@ namespace Content.Client.UserInterface
|
|||||||
CustomMinimumSize = (270, 0),
|
CustomMinimumSize = (270, 0),
|
||||||
SizeFlagsVertical = SizeFlags.ShrinkCenter
|
SizeFlagsVertical = SizeFlags.ShrinkCenter
|
||||||
};
|
};
|
||||||
_nameEdit.OnTextChanged += args =>
|
_nameEdit.OnTextChanged += args => { NameChanged(args.Text); };
|
||||||
{
|
|
||||||
NameChanged(args.Text);
|
|
||||||
};
|
|
||||||
var nameRandomButton = new Button
|
var nameRandomButton = new Button
|
||||||
{
|
{
|
||||||
Text = localization.GetString("Randomize"),
|
Text = localization.GetString("Randomize"),
|
||||||
@@ -280,13 +279,42 @@ namespace Content.Client.UserInterface
|
|||||||
{
|
{
|
||||||
var jobList = new VBoxContainer();
|
var jobList = new VBoxContainer();
|
||||||
|
|
||||||
tabContainer.AddChild(new ScrollContainer
|
var jobVBox = new VBoxContainer
|
||||||
{
|
{
|
||||||
Children = {jobList}
|
Children =
|
||||||
});
|
{
|
||||||
|
(_preferenceUnavailableButton = new OptionButton()),
|
||||||
|
new ScrollContainer
|
||||||
|
{
|
||||||
|
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||||
|
Children =
|
||||||
|
{
|
||||||
|
jobList
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
tabContainer.AddChild(jobVBox);
|
||||||
|
|
||||||
tabContainer.SetTabTitle(1, Loc.GetString("Jobs"));
|
tabContainer.SetTabTitle(1, Loc.GetString("Jobs"));
|
||||||
|
|
||||||
|
_preferenceUnavailableButton.AddItem(
|
||||||
|
Loc.GetString("Stay in lobby if preference unavailable."),
|
||||||
|
(int) PreferenceUnavailableMode.StayInLobby);
|
||||||
|
_preferenceUnavailableButton.AddItem(
|
||||||
|
Loc.GetString("Be an {0} if preference unavailable.",
|
||||||
|
Loc.GetString(SharedGameTicker.OverflowJobName)),
|
||||||
|
(int) PreferenceUnavailableMode.SpawnAsOverflow);
|
||||||
|
|
||||||
|
_preferenceUnavailableButton.OnItemSelected += args =>
|
||||||
|
{
|
||||||
|
_preferenceUnavailableButton.SelectId(args.Id);
|
||||||
|
|
||||||
|
Profile = Profile.WithPreferenceUnavailable((PreferenceUnavailableMode) args.Id);
|
||||||
|
IsDirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
_jobPriorities = new List<JobPrioritySelector>();
|
_jobPriorities = new List<JobPrioritySelector>();
|
||||||
|
|
||||||
foreach (var job in prototypeManager.EnumeratePrototypes<JobPrototype>().OrderBy(j => j.Name))
|
foreach (var job in prototypeManager.EnumeratePrototypes<JobPrototype>().OrderBy(j => j.Name))
|
||||||
@@ -423,6 +451,8 @@ namespace Content.Client.UserInterface
|
|||||||
UpdateHairPickers();
|
UpdateHairPickers();
|
||||||
UpdateSaveButton();
|
UpdateSaveButton();
|
||||||
UpdateJobPriorities();
|
UpdateJobPriorities();
|
||||||
|
|
||||||
|
_preferenceUnavailableButton.SelectId((int) Profile.PreferenceUnavailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateJobPriorities()
|
private void UpdateJobPriorities()
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ namespace Content.Server.Database.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("PreferenceUnavailable")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<int>("PrefsId")
|
b.Property<int>("PrefsId")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ namespace Content.Server.Database
|
|||||||
public string EyeColor { get; set; } = null!;
|
public string EyeColor { get; set; } = null!;
|
||||||
public string SkinColor { get; set; } = null!;
|
public string SkinColor { get; set; } = null!;
|
||||||
public List<Job> Jobs { get; } = new List<Job>();
|
public List<Job> Jobs { get; } = new List<Job>();
|
||||||
|
public DbPreferenceUnavailableMode PreferenceUnavailable { get; set; }
|
||||||
|
|
||||||
public int PrefsId { get; set; }
|
public int PrefsId { get; set; }
|
||||||
public Prefs Prefs { get; set; } = null!;
|
public Prefs Prefs { get; set; } = null!;
|
||||||
@@ -70,4 +71,11 @@ namespace Content.Server.Database
|
|||||||
Medium = 2,
|
Medium = 2,
|
||||||
High = 3
|
High = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DbPreferenceUnavailableMode
|
||||||
|
{
|
||||||
|
// These enum values HAVE to match the ones in PreferenceUnavailableMode in Shared.
|
||||||
|
StayInLobby = 0,
|
||||||
|
SpawnAsOverflow,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ namespace Content.Server.Preferences
|
|||||||
Color.FromHex(profile.EyeColor),
|
Color.FromHex(profile.EyeColor),
|
||||||
Color.FromHex(profile.SkinColor)
|
Color.FromHex(profile.SkinColor)
|
||||||
),
|
),
|
||||||
jobs
|
jobs,
|
||||||
|
(PreferenceUnavailableMode) profile.PreferenceUnavailable
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +89,8 @@ namespace Content.Server.Preferences
|
|||||||
FacialHairColor = appearance.FacialHairColor.ToHex(),
|
FacialHairColor = appearance.FacialHairColor.ToHex(),
|
||||||
EyeColor = appearance.EyeColor.ToHex(),
|
EyeColor = appearance.EyeColor.ToHex(),
|
||||||
SkinColor = appearance.SkinColor.ToHex(),
|
SkinColor = appearance.SkinColor.ToHex(),
|
||||||
Slot = slot
|
Slot = slot,
|
||||||
|
PreferenceUnavailable = (DbPreferenceUnavailableMode) humanoid.PreferenceUnavailable
|
||||||
};
|
};
|
||||||
entity.Jobs.AddRange(
|
entity.Jobs.AddRange(
|
||||||
humanoid.JobPriorities
|
humanoid.JobPriorities
|
||||||
|
|||||||
@@ -10,32 +10,41 @@ namespace Content.Shared.Preferences
|
|||||||
{
|
{
|
||||||
private readonly Dictionary<string, JobPriority> _jobPriorities;
|
private readonly Dictionary<string, JobPriority> _jobPriorities;
|
||||||
|
|
||||||
private HumanoidCharacterProfile(string name,
|
private HumanoidCharacterProfile(
|
||||||
|
string name,
|
||||||
int age,
|
int age,
|
||||||
Sex sex,
|
Sex sex,
|
||||||
HumanoidCharacterAppearance appearance,
|
HumanoidCharacterAppearance appearance,
|
||||||
Dictionary<string, JobPriority> jobPriorities)
|
Dictionary<string, JobPriority> jobPriorities,
|
||||||
|
PreferenceUnavailableMode preferenceUnavailable)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Age = age;
|
Age = age;
|
||||||
Sex = sex;
|
Sex = sex;
|
||||||
Appearance = appearance;
|
Appearance = appearance;
|
||||||
_jobPriorities = jobPriorities;
|
_jobPriorities = jobPriorities;
|
||||||
|
PreferenceUnavailable = preferenceUnavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HumanoidCharacterProfile(string name,
|
public HumanoidCharacterProfile(
|
||||||
|
string name,
|
||||||
int age,
|
int age,
|
||||||
Sex sex,
|
Sex sex,
|
||||||
HumanoidCharacterAppearance appearance,
|
HumanoidCharacterAppearance appearance,
|
||||||
IReadOnlyDictionary<string, JobPriority> jobPriorities)
|
IReadOnlyDictionary<string, JobPriority> jobPriorities,
|
||||||
: this(name, age, sex, appearance, new Dictionary<string, JobPriority>(jobPriorities))
|
PreferenceUnavailableMode preferenceUnavailable)
|
||||||
|
: this(name, age, sex, appearance, new Dictionary<string, JobPriority>(jobPriorities),
|
||||||
|
preferenceUnavailable)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HumanoidCharacterProfile Default()
|
public static HumanoidCharacterProfile Default()
|
||||||
{
|
{
|
||||||
return new HumanoidCharacterProfile("John Doe", 18, Sex.Male, HumanoidCharacterAppearance.Default(),
|
return new HumanoidCharacterProfile("John Doe", 18, Sex.Male, HumanoidCharacterAppearance.Default(),
|
||||||
new Dictionary<string, JobPriority>());
|
new Dictionary<string, JobPriority>
|
||||||
|
{
|
||||||
|
{SharedGameTicker.OverflowJob, JobPriority.High}
|
||||||
|
}, PreferenceUnavailableMode.StayInLobby);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
@@ -44,30 +53,37 @@ namespace Content.Shared.Preferences
|
|||||||
public ICharacterAppearance CharacterAppearance => Appearance;
|
public ICharacterAppearance CharacterAppearance => Appearance;
|
||||||
public HumanoidCharacterAppearance Appearance { get; }
|
public HumanoidCharacterAppearance Appearance { get; }
|
||||||
public IReadOnlyDictionary<string, JobPriority> JobPriorities => _jobPriorities;
|
public IReadOnlyDictionary<string, JobPriority> JobPriorities => _jobPriorities;
|
||||||
|
public PreferenceUnavailableMode PreferenceUnavailable { get; }
|
||||||
|
|
||||||
public HumanoidCharacterProfile WithName(string name)
|
public HumanoidCharacterProfile WithName(string name)
|
||||||
{
|
{
|
||||||
return new HumanoidCharacterProfile(name, Age, Sex, Appearance, _jobPriorities);
|
return new HumanoidCharacterProfile(name, Age, Sex, Appearance, _jobPriorities, PreferenceUnavailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HumanoidCharacterProfile WithAge(int age)
|
public HumanoidCharacterProfile WithAge(int age)
|
||||||
{
|
{
|
||||||
return new HumanoidCharacterProfile(Name, age, Sex, Appearance, _jobPriorities);
|
return new HumanoidCharacterProfile(Name, age, Sex, Appearance, _jobPriorities, PreferenceUnavailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HumanoidCharacterProfile WithSex(Sex sex)
|
public HumanoidCharacterProfile WithSex(Sex sex)
|
||||||
{
|
{
|
||||||
return new HumanoidCharacterProfile(Name, Age, sex, Appearance, _jobPriorities);
|
return new HumanoidCharacterProfile(Name, Age, sex, Appearance, _jobPriorities, PreferenceUnavailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HumanoidCharacterProfile WithCharacterAppearance(HumanoidCharacterAppearance appearance)
|
public HumanoidCharacterProfile WithCharacterAppearance(HumanoidCharacterAppearance appearance)
|
||||||
{
|
{
|
||||||
return new HumanoidCharacterProfile(Name, Age, Sex, appearance, _jobPriorities);
|
return new HumanoidCharacterProfile(Name, Age, Sex, appearance, _jobPriorities, PreferenceUnavailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HumanoidCharacterProfile WithJobPriorities(IReadOnlyDictionary<string, JobPriority> jobPriorities)
|
public HumanoidCharacterProfile WithJobPriorities(IReadOnlyDictionary<string, JobPriority> jobPriorities)
|
||||||
{
|
{
|
||||||
return new HumanoidCharacterProfile(Name, Age, Sex, Appearance, new Dictionary<string, JobPriority>(jobPriorities));
|
return new HumanoidCharacterProfile(
|
||||||
|
Name,
|
||||||
|
Age,
|
||||||
|
Sex,
|
||||||
|
Appearance,
|
||||||
|
new Dictionary<string, JobPriority>(jobPriorities),
|
||||||
|
PreferenceUnavailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HumanoidCharacterProfile WithJobPriority(string jobId, JobPriority priority)
|
public HumanoidCharacterProfile WithJobPriority(string jobId, JobPriority priority)
|
||||||
@@ -82,7 +98,12 @@ namespace Content.Shared.Preferences
|
|||||||
dictionary[jobId] = priority;
|
dictionary[jobId] = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new HumanoidCharacterProfile(Name, Age, Sex, Appearance, dictionary);
|
return new HumanoidCharacterProfile(Name, Age, Sex, Appearance, dictionary, PreferenceUnavailable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HumanoidCharacterProfile WithPreferenceUnavailable(PreferenceUnavailableMode mode)
|
||||||
|
{
|
||||||
|
return new HumanoidCharacterProfile(Name, Age, Sex, Appearance, _jobPriorities, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Summary =>
|
public string Summary =>
|
||||||
@@ -94,6 +115,7 @@ namespace Content.Shared.Preferences
|
|||||||
if (Name != other.Name) return false;
|
if (Name != other.Name) return false;
|
||||||
if (Age != other.Age) return false;
|
if (Age != other.Age) return false;
|
||||||
if (Sex != other.Sex) return false;
|
if (Sex != other.Sex) return false;
|
||||||
|
if (PreferenceUnavailable != other.PreferenceUnavailable) return false;
|
||||||
if (!_jobPriorities.SequenceEqual(other._jobPriorities)) return false;
|
if (!_jobPriorities.SequenceEqual(other._jobPriorities)) return false;
|
||||||
return Appearance.MemberwiseEquals(other.Appearance);
|
return Appearance.MemberwiseEquals(other.Appearance);
|
||||||
}
|
}
|
||||||
|
|||||||
20
Content.Shared/Preferences/PreferenceUnavailableMode.cs
Normal file
20
Content.Shared/Preferences/PreferenceUnavailableMode.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
namespace Content.Shared.Preferences
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies behavior when none of the jobs you want are available at round start.
|
||||||
|
/// </summary>
|
||||||
|
public enum PreferenceUnavailableMode
|
||||||
|
{
|
||||||
|
// These enum values HAVE to match the ones in DbPreferenceUnavailableMode in Server.Database.
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stay in the lobby (if the lobby is enabled).
|
||||||
|
/// </summary>
|
||||||
|
StayInLobby = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Spawn as overflow role if preference unavailable.
|
||||||
|
/// </summary>
|
||||||
|
SpawnAsOverflow,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.Preferences;
|
using Content.Server.Preferences;
|
||||||
|
using Content.Shared;
|
||||||
using Content.Shared.Preferences;
|
using Content.Shared.Preferences;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
@@ -30,8 +31,9 @@ namespace Content.Tests.Server.Preferences
|
|||||||
),
|
),
|
||||||
new Dictionary<string, JobPriority>
|
new Dictionary<string, JobPriority>
|
||||||
{
|
{
|
||||||
{"Assistant", JobPriority.High}
|
{SharedGameTicker.OverflowJob, JobPriority.High}
|
||||||
}
|
},
|
||||||
|
PreferenceUnavailableMode.StayInLobby
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user