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

Loadouts #45

Merged
merged 21 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
13 changes: 10 additions & 3 deletions Content.Client/Lobby/UI/LobbyCharacterPreviewPanel.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Linq;
using System.Numerics;
using Content.Client.Alerts;
using Content.Client.Humanoid;
using Content.Client.Inventory;
using Content.Client.Preferences;
using Content.Client.UserInterface.Controls;
using Content.Shared.Clothing.Loadouts.Systems;
using Content.Shared.GameTicking;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Inventory;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Map;
Expand Down Expand Up @@ -126,6 +124,7 @@ public void UpdateUI()
_summaryLabel.Text = selectedCharacter.Summary;
_entityManager.System<HumanoidAppearanceSystem>().LoadProfile(_previewDummy.Value, selectedCharacter);
GiveDummyJobClothes(_previewDummy.Value, selectedCharacter);
GiveDummyLoadoutItems(_previewDummy.Value, selectedCharacter);
}
}
}
Expand Down Expand Up @@ -162,5 +161,13 @@ public static void GiveDummyJobClothes(EntityUid dummy, HumanoidCharacterProfile
}
}
}

public static void GiveDummyLoadoutItems(EntityUid dummy, HumanoidCharacterProfile profile)
{
var highPriorityJobId = profile.JobPriorities.FirstOrDefault(j => j.Value == JobPriority.High).Key;
var highPriorityJob = IoCManager.Resolve<IPrototypeManager>().Index<JobPrototype>(highPriorityJobId ?? SharedGameTicker.FallbackOverflowJob);

EntitySystem.Get<LoadoutSystem>().ApplyCharacterLoadout(dummy, highPriorityJob, profile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed partial class JobRequirementsManager
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;

private readonly Dictionary<string, TimeSpan> _roles = new();
public readonly Dictionary<string, TimeSpan> PlayTimes = new();
private readonly List<string> _roleBans = new();

private ISawmill _sawmill = default!;
Expand All @@ -45,7 +45,7 @@ private void ClientOnRunLevelChanged(object? sender, RunLevelChangedEventArgs e)
if (e.NewLevel == ClientRunLevel.Initialize)
{
// Reset on disconnect, just in case.
_roles.Clear();
PlayTimes.Clear();
}
}

Expand All @@ -63,12 +63,12 @@ private void RxRoleBans(MsgRoleBans message)

private void RxPlayTime(MsgPlayTime message)
{
_roles.Clear();
PlayTimes.Clear();

// NOTE: do not assign _roles = message.Trackers due to implicit data sharing in integration tests.
foreach (var (tracker, time) in message.Trackers)
{
_roles[tracker] = time;
PlayTimes[tracker] = time;
}

/*var sawmill = Logger.GetSawmill("play_time");
Expand Down Expand Up @@ -96,7 +96,7 @@ public bool IsAllowed(JobPrototype job, [NotNullWhen(false)] out FormattedMessag
return CheckRoleTime(job.Requirements, out reason);
}

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

Expand All @@ -106,7 +106,7 @@ public bool CheckRoleTime(HashSet<JobRequirement>? requirements, [NotNullWhen(fa
var reasons = new List<string>();
foreach (var requirement in requirements)
{
if (JobRequirements.TryRequirementMet(requirement, _roles, out var jobReason, _entManager, _prototypes, _whitelisted))
if (JobRequirements.TryRequirementMet(requirement, PlayTimes, out var jobReason, _entManager, _prototypes, _whitelisted, localePrefix))
continue;

reasons.Add(jobReason.ToMarkup());
Expand All @@ -118,7 +118,7 @@ public bool CheckRoleTime(HashSet<JobRequirement>? requirements, [NotNullWhen(fa

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

public IEnumerable<KeyValuePair<string, TimeSpan>> FetchPlaytimeByRoles()
Expand All @@ -127,7 +127,7 @@ public IEnumerable<KeyValuePair<string, TimeSpan>> FetchPlaytimeByRoles()

foreach (var job in jobsToMap)
{
if (_roles.TryGetValue(job.PlayTimeTracker, out var locJobName))
if (PlayTimes.TryGetValue(job.PlayTimeTracker, out var locJobName))
{
yield return new KeyValuePair<string, TimeSpan>(job.Name, locJobName);
}
Expand Down
3 changes: 1 addition & 2 deletions Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public CharacterPickerButton(
if (humanoid != null)
{
LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, humanoid);
LobbyCharacterPreviewPanel.GiveDummyLoadoutItems(_previewDummy, humanoid);
}

var isSelectedCharacter = profile == preferencesManager.Preferences?.SelectedCharacter;
Expand Down Expand Up @@ -229,10 +230,8 @@ public CharacterPickerButton(
};
deleteButton.OnPressed += _ =>
{

deleteButton.Visible = false;
confirmDeleteButton.Visible = true;

};

var internalHBox = new BoxContainer
Expand Down
15 changes: 15 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
<Control HorizontalExpand="True"/>
<Button Name="ShowClothes" Pressed="True" ToggleMode="True" Text="{Loc 'humanoid-profile-editor-clothing-show'}" HorizontalAlignment="Right" />
</BoxContainer>
<!-- Show loadouts -->
<BoxContainer HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-loadouts'}" />
<Control HorizontalExpand="True"/>
<Button Name="ShowLoadouts" Pressed="True" ToggleMode="True" Text="{Loc 'Show'}" HorizontalAlignment="Right" />
</BoxContainer>
<!-- Clothing -->
<BoxContainer HorizontalExpand="True">
<Label Text="{Loc 'humanoid-profile-editor-clothing-label'}" />
Expand Down Expand Up @@ -142,6 +148,15 @@
<BoxContainer Name="CTraitsList" Orientation="Vertical" />
</ScrollContainer>
</BoxContainer>
<BoxContainer Name="CLoadoutsTab" Orientation="Vertical" Margin="10">
<!-- Loadouts -->
<Label Name="LoadoutPointsLabel" HorizontalAlignment="Stretch" Align="Center" />
<ProgressBar Name="LoadoutPointsBar" MaxValue="1" Value="1" MaxHeight="8" Margin="0 5" />

<Button Name="CHideShowUnusableButton" Text="{Loc 'humanoid-profile-editor-loadouts-show-unusable-button'}" ToolTip="{Loc 'humanoid-profile-editor-loadouts-show-unusable-button-tooltip'}" ToggleMode="True" Margin="0 0 0 5" />

<TabContainer Name="CLoadoutsTabs" VerticalExpand="True" />
</BoxContainer>
<BoxContainer Name="CMarkingsTab" Orientation="Vertical" Margin="10">
<!-- Markings -->
<ScrollContainer VerticalExpand="True">
Expand Down
Loading
Loading