Skip to content

Commit

Permalink
Merge pull request #57 from VMSolidus/VMSolidus-Upstream-Merge-8-2-2024
Browse files Browse the repository at this point in the history
Vm solidus upstream merge 8 2 2024
  • Loading branch information
VMSolidus authored Aug 2, 2024
2 parents efc50b9 + 9d3f3ab commit ee17259
Show file tree
Hide file tree
Showing 308 changed files with 6,321 additions and 2,470 deletions.
24 changes: 21 additions & 3 deletions Content.Client/LateJoin/LateJoinGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
using Content.Client.GameTicking.Managers;
using Content.Client.UserInterface.Controls;
using Content.Client.Players.PlayTimeTracking;
using Content.Client.Preferences;
using Content.Shared.CCVar;
using Content.Shared.Customization.Systems;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.StatusIcon;
using Microsoft.Win32.SafeHandles;
using Robust.Client.Console;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
Expand All @@ -26,12 +30,15 @@ public sealed class LateJoinGui : DefaultWindow
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
[Dependency] private readonly JobRequirementsManager _jobRequirements = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IClientPreferencesManager _prefs = default!;

public event Action<(NetEntity, string)> SelectedId;

private readonly ClientGameTicker _gameTicker;
private readonly SpriteSystem _sprites;
private readonly CrewManifestSystem _crewManifest;
private readonly CharacterRequirementsSystem _characterRequirements;

private readonly Dictionary<NetEntity, Dictionary<string, List<JobButton>>> _jobButtons = new();
private readonly Dictionary<NetEntity, Dictionary<string, BoxContainer>> _jobCategories = new();
Expand All @@ -46,6 +53,7 @@ public LateJoinGui()
_sprites = _entitySystem.GetEntitySystem<SpriteSystem>();
_crewManifest = _entitySystem.GetEntitySystem<CrewManifestSystem>();
_gameTicker = _entitySystem.GetEntitySystem<ClientGameTicker>();
_characterRequirements = _entitySystem.GetEntitySystem<CharacterRequirementsSystem>();

Title = Loc.GetString("late-join-gui-title");

Expand Down Expand Up @@ -254,14 +262,24 @@ private void RebuildUI()

jobButton.OnPressed += _ => SelectedId.Invoke((id, jobButton.JobId));

if (!_jobRequirements.IsAllowed(prototype, out var reason))
if (!_characterRequirements.CheckRequirementsValid(
prototype.Requirements ?? new(),
prototype,
(HumanoidCharacterProfile) (_prefs.Preferences?.SelectedCharacter
?? HumanoidCharacterProfile.DefaultWithSpecies()),
_jobRequirements.GetRawPlayTimeTrackers(),
_jobRequirements.IsWhitelisted(),
_entityManager,
_prototypeManager,
_configManager,
out var reasons))
{
jobButton.Disabled = true;

if (!reason.IsEmpty)
if (reasons.Count > 0)
{
var tooltip = new Tooltip();
tooltip.SetMessage(reason);
tooltip.SetMessage(_characterRequirements.GetRequirementsText(reasons));
jobButton.TooltipSupplier = _ => tooltip;
}

Expand Down
70 changes: 39 additions & 31 deletions Content.Client/Lobby/LobbyUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using Content.Client.Humanoid;
using Content.Client.Inventory;
using Content.Client.Lobby.UI;
using Content.Client.Players.PlayTimeTracking;
using Content.Client.Preferences;
using Content.Client.Preferences.UI;
using Content.Shared.Clothing.Loadouts.Systems;
using Content.Shared.GameTicking;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
using Content.Shared.Roles;
Expand All @@ -22,6 +24,7 @@ public sealed class LobbyUIController : UIController, IOnStateEntered<LobbyState
[Dependency] private readonly IClientPreferencesManager _preferencesManager = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly JobRequirementsManager _jobRequirements = default!;
[UISystemDependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[UISystemDependency] private readonly ClientInventorySystem _inventory = default!;
[UISystemDependency] private readonly LoadoutSystem _loadouts = default!;
Expand Down Expand Up @@ -98,41 +101,51 @@ public void UpdateCharacterUI()
return;
}

if (_previewDummy == null)
var maybeProfile = _profileEditor?.Profile ?? (HumanoidCharacterProfile) _preferencesManager.Preferences!.SelectedCharacter;

if (_previewDummy == null
|| maybeProfile.Species != EntityManager.GetComponent<HumanoidAppearanceComponent>(_previewDummy.Value).Species)
{
_previewDummy =
EntityManager.SpawnEntity(
_prototypeManager.Index<SpeciesPrototype>(HumanoidCharacterProfile.DefaultWithSpecies().Species)
.DollPrototype, MapCoordinates.Nullspace);
_previewPanel?.SetSprite(_previewDummy.Value);
RespawnDummy(maybeProfile);
_previewPanel?.SetSprite(_previewDummy!.Value);
}

_previewPanel?.SetLoaded(true);

if (_preferencesManager.Preferences?.SelectedCharacter is not HumanoidCharacterProfile selectedCharacter)
_previewPanel?.SetSummaryText(string.Empty);
else if (_previewDummy != null)
if (_previewDummy == null)
return;

_previewPanel?.SetSummaryText(maybeProfile.Summary);
_humanoid.LoadProfile(_previewDummy.Value, maybeProfile);


if (UpdateClothes)
{
var maybeProfile = _profileEditor?.Profile ?? selectedCharacter;
_previewPanel?.SetSummaryText(maybeProfile.Summary);
_humanoid.LoadProfile(_previewDummy.Value, maybeProfile);


if (UpdateClothes)
{
RemoveDummyClothes(_previewDummy.Value);
if (ShowClothes)
GiveDummyJobClothes(_previewDummy.Value, GetPreferredJob(maybeProfile), maybeProfile);
if (ShowLoadouts)
GiveDummyLoadouts(_previewDummy.Value, GetPreferredJob(maybeProfile), maybeProfile);
UpdateClothes = false;
}

PreviewDummyUpdated?.Invoke(_previewDummy.Value);
RemoveDummyClothes(_previewDummy.Value);
if (ShowClothes)
GiveDummyJobClothes(_previewDummy.Value, GetPreferredJob(maybeProfile), maybeProfile);
if (ShowLoadouts)
_loadouts.ApplyCharacterLoadout(_previewDummy.Value, GetPreferredJob(maybeProfile), maybeProfile,
_jobRequirements.GetRawPlayTimeTrackers(), _jobRequirements.IsWhitelisted());
UpdateClothes = false;
}

PreviewDummyUpdated?.Invoke(_previewDummy.Value);
}


public void RespawnDummy(HumanoidCharacterProfile profile)
{
if (_previewDummy != null)
RemoveDummyClothes(_previewDummy.Value);

EntityManager.DeleteEntity(_previewDummy);
_previewDummy = EntityManager.SpawnEntity(
_prototypeManager.Index<SpeciesPrototype>(profile.Species).DollPrototype, MapCoordinates.Nullspace);

UpdateClothes = true;
}

/// <summary>
/// Gets the highest priority job for the profile.
/// </summary>
Expand Down Expand Up @@ -160,12 +173,7 @@ public void GiveDummyJobClothesLoadout(EntityUid dummy, HumanoidCharacterProfile
{
var job = GetPreferredJob(profile);
GiveDummyJobClothes(dummy, job, profile);
GiveDummyLoadouts(dummy, job, profile);
}

public void GiveDummyLoadouts(EntityUid dummy, JobPrototype job, HumanoidCharacterProfile profile)
{
_loadouts.ApplyCharacterLoadout(dummy, job, profile);
_loadouts.ApplyCharacterLoadout(dummy, job, profile, _jobRequirements.GetRawPlayTimeTrackers(), _jobRequirements.IsWhitelisted());
}

/// <summary>
Expand Down
63 changes: 15 additions & 48 deletions Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.CCVar;
using Content.Shared.Customization.Systems;
using Content.Shared.Players;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Roles;
Expand All @@ -17,9 +18,6 @@ public sealed partial class JobRequirementsManager : ISharedPlaytimeManager
{
[Dependency] private readonly IBaseClient _client = default!;
[Dependency] private readonly IClientNetManager _net = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;

private readonly Dictionary<string, TimeSpan> _roles = new();
Expand Down Expand Up @@ -80,64 +78,33 @@ private void RxPlayTime(MsgPlayTime message)
Updated?.Invoke();
}

public bool IsAllowed(JobPrototype job, [NotNullWhen(false)] out FormattedMessage? reason)
{
reason = null;

if (_roleBans.Contains($"Job:{job.ID}"))
{
reason = FormattedMessage.FromUnformatted(Loc.GetString("role-ban"));
return false;
}

var player = _playerManager.LocalSession;
if (player == null)
return true;

return CheckRoleTime(job.Requirements, out reason);
}

public bool CheckRoleTime(HashSet<JobRequirement>? requirements, [NotNullWhen(false)] out FormattedMessage? reason, string? localePrefix = "role-timer-")
{
reason = null;

if (requirements == null || !_cfg.GetCVar(CCVars.GameRoleTimers))
return true;

var reasons = new List<string>();
foreach (var requirement in requirements)
{
if (JobRequirements.TryRequirementMet(requirement, _roles, out var jobReason, _entManager, _prototypes, _whitelisted, localePrefix))
continue;

reasons.Add(jobReason.ToMarkup());
}

reason = reasons.Count == 0 ? null : FormattedMessage.FromMarkup(string.Join('\n', reasons));
return reason == null;
}

public TimeSpan FetchOverallPlaytime()
{
return _roles.TryGetValue("Overall", out var overallPlaytime) ? overallPlaytime : TimeSpan.Zero;
}

public IEnumerable<KeyValuePair<string, TimeSpan>> FetchPlaytimeByRoles()
public Dictionary<string, TimeSpan> FetchPlaytimeByRoles()
{
var jobsToMap = _prototypes.EnumeratePrototypes<JobPrototype>();
var ret = new Dictionary<string, TimeSpan>();

foreach (var job in jobsToMap)
{
if (_roles.TryGetValue(job.PlayTimeTracker, out var locJobName))
{
yield return new KeyValuePair<string, TimeSpan>(job.Name, locJobName);
}
}
ret.Add(job.Name, locJobName);

return ret;
}


public IReadOnlyDictionary<string, TimeSpan> GetPlayTimes(ICommonSession session)
public Dictionary<string, TimeSpan> GetPlayTimes()
{
var dict = FetchPlaytimeByRoles();
dict.Add(PlayTimeTrackingShared.TrackerOverall, FetchOverallPlaytime());
return dict;
}

public Dictionary<string, TimeSpan> GetRawPlayTimeTrackers()
{
return session != _playerManager.LocalSession ? new Dictionary<string, TimeSpan>() : _roles;
return _roles;
}
}
26 changes: 23 additions & 3 deletions Content.Client/Preferences/UI/AntagPreferenceSelector.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Content.Client.Players.PlayTimeTracking;
using Content.Shared.Customization.Systems;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;

namespace Content.Client.Preferences.UI;

Expand All @@ -14,7 +18,7 @@ public bool Preference

public event Action<bool>? PreferenceChanged;

public AntagPreferenceSelector(AntagPrototype proto) : base(proto)
public AntagPreferenceSelector(AntagPrototype proto, JobPrototype highJob) : base(proto, highJob)
{
Options.OnItemSelected += _ => PreferenceChanged?.Invoke(Preference);

Expand All @@ -30,7 +34,23 @@ public AntagPreferenceSelector(AntagPrototype proto) : base(proto)
// Immediately lock requirements if they aren't met.
// Another function checks Disabled after creating the selector so this has to be done now
var requirements = IoCManager.Resolve<JobRequirementsManager>();
if (proto.Requirements != null && !requirements.CheckRoleTime(proto.Requirements, out var reason))
LockRequirements(reason);
var prefs = IoCManager.Resolve<IClientPreferencesManager>();
var entMan = IoCManager.Resolve<IEntityManager>();
var characterReqs = entMan.System<CharacterRequirementsSystem>();
var protoMan = IoCManager.Resolve<IPrototypeManager>();
var configMan = IoCManager.Resolve<IConfigurationManager>();

if (proto.Requirements != null
&& !characterReqs.CheckRequirementsValid(
proto.Requirements,
highJob,
(HumanoidCharacterProfile) (prefs.Preferences?.SelectedCharacter ?? HumanoidCharacterProfile.DefaultWithSpecies()),
requirements.GetRawPlayTimeTrackers(),
requirements.IsWhitelisted(),
entMan,
protoMan,
configMan,
out var reasons))
LockRequirements(characterReqs.GetRequirementsText(reasons));
}
}
Loading

0 comments on commit ee17259

Please sign in to comment.