Enable nullability in Content.Client (#3257)

* Enable nullability in Content.Client

* Remove #nullable enable

* Merge fixes

* Remove Debug.Assert

* Merge fixes

* Fix build

* Fix build
This commit is contained in:
DrSmugleaf
2021-03-10 14:48:29 +01:00
committed by GitHub
parent 4f9bd4e802
commit 902aa128c2
270 changed files with 1774 additions and 1550 deletions

View File

@@ -13,9 +13,9 @@ using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Enums;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -61,8 +61,9 @@ namespace Content.Client.UserInterface
private bool _isDirty;
public int CharacterSlot;
public HumanoidCharacterProfile Profile;
public event Action<HumanoidCharacterProfile, int> OnProfileChanged;
public HumanoidCharacterProfile? Profile;
public event Action<HumanoidCharacterProfile, int>? OnProfileChanged;
public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager,
IEntityManager entityManager)
@@ -175,7 +176,7 @@ namespace Content.Client.UserInterface
_sexMaleButton.OnPressed += args =>
{
SetSex(Sex.Male);
if (Profile.Gender == Gender.Female)
if (Profile?.Gender == Gender.Female)
{
SetGender(Gender.Male);
UpdateGenderControls();
@@ -187,10 +188,11 @@ namespace Content.Client.UserInterface
Text = Loc.GetString("Female"),
Group = sexButtonGroup
};
_sexFemaleButton.OnPressed += args =>
_sexFemaleButton.OnPressed += _ =>
{
SetSex(Sex.Female);
if (Profile.Gender == Gender.Male)
if (Profile?.Gender == Gender.Male)
{
SetGender(Gender.Female);
UpdateGenderControls();
@@ -419,7 +421,7 @@ namespace Content.Client.UserInterface
{
_preferenceUnavailableButton.SelectId(args.Id);
Profile = Profile.WithPreferenceUnavailable((PreferenceUnavailableMode) args.Id);
Profile = Profile?.WithPreferenceUnavailable((PreferenceUnavailableMode) args.Id);
IsDirty = true;
};
@@ -474,7 +476,7 @@ namespace Content.Client.UserInterface
selector.PriorityChanged += priority =>
{
Profile = Profile.WithJobPriority(job.ID, priority);
Profile = Profile?.WithJobPriority(job.ID, priority);
IsDirty = true;
foreach (var jobSelector in _jobPriorities)
@@ -491,7 +493,7 @@ namespace Content.Client.UserInterface
if (jobSelector.Job != selector.Job && jobSelector.Priority == JobPriority.High)
{
jobSelector.Priority = JobPriority.Medium;
Profile = Profile.WithJobPriority(jobSelector.Job.ID, JobPriority.Medium);
Profile = Profile?.WithJobPriority(jobSelector.Job.ID, JobPriority.Medium);
}
}
}
@@ -539,7 +541,7 @@ namespace Content.Client.UserInterface
selector.PreferenceChanged += preference =>
{
Profile = Profile.WithAntagPreference(antag.ID, preference);
Profile = Profile?.WithAntagPreference(antag.ID, preference);
IsDirty = true;
};
}
@@ -664,7 +666,7 @@ namespace Content.Client.UserInterface
private void LoadServerData()
{
Profile = (HumanoidCharacterProfile) _preferencesManager.Preferences.SelectedCharacter;
Profile = (HumanoidCharacterProfile) _preferencesManager.Preferences!.SelectedCharacter;
CharacterSlot = _preferencesManager.Preferences.SelectedCharacterIndex;
UpdateControls();
}
@@ -708,8 +710,12 @@ namespace Content.Client.UserInterface
public void Save()
{
IsDirty = false;
_preferencesManager.UpdateCharacter(Profile, CharacterSlot);
OnProfileChanged?.Invoke(Profile, CharacterSlot);
if (Profile != null)
{
_preferencesManager.UpdateCharacter(Profile, CharacterSlot);
OnProfileChanged?.Invoke(Profile, CharacterSlot);
}
}
private bool IsDirty
@@ -733,17 +739,17 @@ namespace Content.Client.UserInterface
private void UpdateNameEdit()
{
_nameEdit.Text = Profile.Name;
_nameEdit.Text = Profile?.Name ?? "";
}
private void UpdateAgeEdit()
{
_ageEdit.Text = Profile.Age.ToString();
_ageEdit.Text = Profile?.Age.ToString() ?? "";
}
private void UpdateSexControls()
{
if (Profile.Sex == Sex.Male)
if (Profile?.Sex == Sex.Male)
_sexMaleButton.Pressed = true;
else
_sexFemaleButton.Pressed = true;
@@ -751,21 +757,41 @@ namespace Content.Client.UserInterface
private void UpdateGenderControls()
{
if (Profile == null)
{
return;
}
_genderButton.SelectId((int) Profile.Gender);
}
private void UpdateClothingControls()
{
if (Profile == null)
{
return;
}
_clothingButton.SelectId((int) Profile.Clothing);
}
private void UpdateBackpackControls()
{
if (Profile == null)
{
return;
}
_backpackButton.SelectId((int) Profile.Backpack);
}
private void UpdateHairPickers()
{
if (Profile == null)
{
return;
}
_hairPicker.SetData(
Profile.Appearance.HairColor,
Profile.Appearance.HairStyleName);
@@ -776,6 +802,11 @@ namespace Content.Client.UserInterface
private void UpdateEyePickers()
{
if (Profile == null)
{
return;
}
_eyesPicker.SetData(Profile.Appearance.EyeColor);
}
@@ -819,7 +850,7 @@ namespace Content.Client.UserInterface
{
var jobId = prioritySelector.Job.ID;
var priority = Profile.JobPriorities.GetValueOrDefault(jobId, JobPriority.Never);
var priority = Profile?.JobPriorities.GetValueOrDefault(jobId, JobPriority.Never) ?? JobPriority.Never;
prioritySelector.Priority = priority;
}
@@ -836,17 +867,18 @@ namespace Content.Client.UserInterface
set => _optionButton.SelectByValue((int) value);
}
public event Action<JobPriority> PriorityChanged;
public event Action<JobPriority>? PriorityChanged;
public JobPrioritySelector(JobPrototype job)
{
Job = job;
_optionButton = new RadioOptions<int>(RadioOptionsLayout.Horizontal);
_optionButton.FirstButtonStyle = StyleBase.ButtonOpenRight;
_optionButton.ButtonStyle = StyleBase.ButtonOpenBoth;
_optionButton.LastButtonStyle = StyleBase.ButtonOpenLeft;
_optionButton = new RadioOptions<int>(RadioOptionsLayout.Horizontal)
{
FirstButtonStyle = StyleBase.ButtonOpenRight,
ButtonStyle = StyleBase.ButtonOpenBoth,
LastButtonStyle = StyleBase.ButtonOpenLeft
};
// Text, Value
_optionButton.AddItem(Loc.GetString("High"), (int) JobPriority.High);
@@ -890,8 +922,7 @@ namespace Content.Client.UserInterface
foreach (var preferenceSelector in _antagPreferences)
{
var antagId = preferenceSelector.Antag.ID;
var preference = Profile.AntagPreferences.Contains(antagId);
var preference = Profile?.AntagPreferences.Contains(antagId) ?? false;
preferenceSelector.Preference = preference;
}
@@ -908,7 +939,7 @@ namespace Content.Client.UserInterface
set => _checkBox.Pressed = value;
}
public event Action<bool> PreferenceChanged;
public event Action<bool>? PreferenceChanged;
public AntagPreferenceSelector(AntagPrototype antag)
{