Skip to content

Commit

Permalink
Complete rewrite of latejoin window (#2200)
Browse files Browse the repository at this point in the history
* Code cleanup

* Add SeparatorColor for HSeparator

* Add a station or crew choice before join window

* Rig picker windows

* Rename Window to Control for elements

* Add extra station information

* Add ExtraStationInformation component

* use var

* Rename NFLateJoinJobButton to JobButton

* Implement right side section

* Last fixes

* Add descriptions

* Replace hideous lists with a readable class

* Fix job info

* Add detail descriptions and UI tweaks

* Add lobby sort order to be able to arrange stations

* Add isLateJoin property and disable crew button if needed

* wip

* Display large buttons menu in picker window instead

* Move files to own categories

* Update namespaces

* Rename Latejoin to LateJoin

* Interfacing and class refactoring

* Only show ships

* Fix crew button going to station

* Separate ship list item for crew

* Disable positions when not allowed

* Fix not allowed jobs for ships

* Add tooltips

* Fix comments

---------

Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com>
  • Loading branch information
GreaseMonk and dvir001 authored Oct 13, 2024
1 parent 1ac9b2b commit 9eca8c3
Show file tree
Hide file tree
Showing 35 changed files with 1,302 additions and 468 deletions.
44 changes: 38 additions & 6 deletions Content.Client/Administration/UI/CustomControls/HSeparator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,53 @@

namespace Content.Client.Administration.UI.CustomControls;

/**
* FRONTIER CHANGE: Added SeparatorColor so it can be set in the UI.
*/
public sealed class HSeparator : Control
{
private static readonly Color SeparatorColor = Color.FromHex("#3D4059");
private static readonly Color DefaultSeparatorColor = Color.FromHex("#3D4059");

private Color _separatorColor = DefaultSeparatorColor;
public Color SeparatorColor
{
get => _separatorColor;
set
{
_separatorColor = Color.FromHex(value.ToHex());
UpdateSeparatorColor();
}
}

private PanelContainer? _panelContainer = null;

public HSeparator(Color color)
{
AddChild(new PanelContainer
SeparatorColor = color;
Initialize();
}

public HSeparator() : this(DefaultSeparatorColor) { }

private void Initialize()
{
_panelContainer = new PanelContainer
{
PanelOverride = new StyleBoxFlat
{
BackgroundColor = color,
ContentMarginBottomOverride = 2, ContentMarginLeftOverride = 2
BackgroundColor = SeparatorColor,
ContentMarginBottomOverride = 2,
ContentMarginLeftOverride = 2
}
});
};
AddChild(_panelContainer);
}

public HSeparator() : this(SeparatorColor) { }
private void UpdateSeparatorColor()
{
if (_panelContainer?.PanelOverride is StyleBoxFlat styleBox)
{
styleBox.BackgroundColor = SeparatorColor;
}
}
}
37 changes: 16 additions & 21 deletions Content.Client/GameTicking/Managers/ClientGameTicker.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System.Linq;
using Content.Client.Administration.Managers;
using Content.Client.Gameplay;
using Content.Client.Lobby;
using Content.Client.RoundEnd;
using Content.Shared.GameTicking;
using Content.Shared.GameWindow;
using Content.Shared.Roles;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.State;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;

namespace Content.Client.GameTicking.Managers
{
Expand All @@ -21,8 +20,7 @@ public sealed class ClientGameTicker : SharedGameTicker
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;

private Dictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>> _jobsAvailable = new();
private Dictionary<NetEntity, string> _stationNames = new();
private Dictionary<NetEntity, StationJobInformation> _stationJobInformationList = new();

[ViewVariables] public bool AreWeReady { get; private set; }
[ViewVariables] public bool IsGameStarted { get; private set; }
Expand All @@ -33,13 +31,21 @@ public sealed class ClientGameTicker : SharedGameTicker
[ViewVariables] public TimeSpan StartTime { get; private set; }
[ViewVariables] public new bool Paused { get; private set; }

[ViewVariables] public IReadOnlyDictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>> JobsAvailable => _jobsAvailable;
[ViewVariables] public IReadOnlyDictionary<NetEntity, string> StationNames => _stationNames;
[ViewVariables] public IReadOnlyDictionary<NetEntity, StationJobInformation> StationJobInformationList => _stationJobInformationList;

// Frontier addition
// Replaced StationNames with a getter that uses _stationJobInformationList
[ViewVariables]
public IReadOnlyDictionary<NetEntity, string> StationNames =>
_stationJobInformationList.ToDictionary(
kvp => kvp.Key,
kvp => kvp.Value.StationName
);

public event Action? InfoBlobUpdated;
public event Action? LobbyStatusUpdated;
public event Action? LobbyLateJoinStatusUpdated;
public event Action<IReadOnlyDictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>>>? LobbyJobsAvailableUpdated;
public event Action<IReadOnlyDictionary<NetEntity, StationJobInformation>>? LobbyJobsAvailableUpdated;

public override void Initialize()
{
Expand Down Expand Up @@ -87,20 +93,9 @@ private void LateJoinStatus(TickerLateJoinStatusEvent message)

private void UpdateJobsAvailable(TickerJobsAvailableEvent message)
{
_jobsAvailable.Clear();

foreach (var (job, data) in message.JobsAvailableByStation)
{
_jobsAvailable[job] = data;
}

_stationNames.Clear();
foreach (var weh in message.StationNames)
{
_stationNames[weh.Key] = weh.Value;
}

LobbyJobsAvailableUpdated?.Invoke(JobsAvailable);
_stationJobInformationList.Clear();
_stationJobInformationList = message.StationJobList;
LobbyJobsAvailableUpdated?.Invoke(StationJobInformationList);
}

private void JoinLobby(TickerJoinLobbyEvent message)
Expand Down
42 changes: 20 additions & 22 deletions Content.Client/LateJoin/LateJoinGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Client.UserInterface.Controls;
using Content.Client.Players.PlayTimeTracking;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.StatusIcon;
Expand Down Expand Up @@ -171,12 +172,12 @@ private void RebuildUI()
{
var departmentName = Loc.GetString($"department-{department.ID}");
_jobCategories[id] = new Dictionary<string, BoxContainer>();
var stationAvailable = _gameTicker.JobsAvailable[id];
var stationAvailable = _gameTicker.StationJobInformationList[id];
var jobsAvailable = new List<JobPrototype>();

foreach (var jobId in department.Roles)
{
if (!stationAvailable.ContainsKey(jobId))
if (!stationAvailable.JobsAvailable.ContainsKey(jobId))
continue;

jobsAvailable.Add(_prototypeManager.Index<JobPrototype>(jobId));
Expand Down Expand Up @@ -225,7 +226,8 @@ private void RebuildUI()

foreach (var prototype in jobsAvailable)
{
var value = stationAvailable[prototype.ID];
// Frontier: stationAvailable[prototype.ID]; -> stationAvailable.JobsAvailable[prototype.ID];
var value = stationAvailable.JobsAvailable[prototype.ID];

var jobLabel = new Label
{
Expand Down Expand Up @@ -292,29 +294,25 @@ private void RebuildUI()
}
}

private void JobsAvailableUpdated(IReadOnlyDictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>> updatedJobs)
private void JobsAvailableUpdated(IReadOnlyDictionary<NetEntity, StationJobInformation> updatedJobs)
{
foreach (var stationEntries in updatedJobs)
// Frontier: Made this more readable with simplified comparisons and LINQ expressions.
// Feel free to replace this with upstream code whenever, just mind that
// updatedJobs is now a dictionary of NetEntity to StationJobInformation.
// I changed this: jobInformation.TryGetValue to this: jobInformation.JobsAvailable.TryGetValue
// Godspeed.
foreach (var (stationNetEntity, jobInformation) in updatedJobs)
{
if (_jobButtons.ContainsKey(stationEntries.Key))
if (!_jobButtons.TryGetValue(stationNetEntity, out var existingJobEntries))
continue;
foreach (var existingJobEntry in existingJobEntries)
{
var jobsAvailable = stationEntries.Value;

var existingJobEntries = _jobButtons[stationEntries.Key];
foreach (var existingJobEntry in existingJobEntries)
if (!jobInformation.JobsAvailable.TryGetValue(existingJobEntry.Key, out var updatedJobValue))
continue;
foreach (var matchingJobButton in existingJobEntry.Value.Where(matchingJobButton => matchingJobButton.Amount != updatedJobValue))
{
if (jobsAvailable.ContainsKey(existingJobEntry.Key))
{
var updatedJobValue = jobsAvailable[existingJobEntry.Key];
foreach (var matchingJobButton in existingJobEntry.Value)
{
if (matchingJobButton.Amount != updatedJobValue)
{
matchingJobButton.RefreshLabel(updatedJobValue);
matchingJobButton.Disabled |= matchingJobButton.Amount == 0;
}
}
}
matchingJobButton.RefreshLabel(updatedJobValue);
matchingJobButton.Disabled |= matchingJobButton.Amount == 0;
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions Content.Client/Lobby/LobbyState.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Content.Client._NF.Latejoin;
using Content.Client.Chat.Managers;
using Content.Client._NF.LateJoin;
using Content.Client.Audio;
using Content.Client.Eui;
using Content.Client.GameTicking.Managers;
using Content.Client.LateJoin;
using Content.Client.Lobby.UI;
using Content.Client.Message;
using Content.Client.UserInterface.Systems.Chat;
Expand All @@ -13,6 +12,7 @@
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
using PickerWindow = Content.Client._NF.LateJoin.Windows.PickerWindow;


namespace Content.Client.Lobby
Expand All @@ -33,6 +33,9 @@ public sealed class LobbyState : Robust.Client.State.State
protected override Type? LinkedScreenType { get; } = typeof(LobbyGui);
public LobbyGui? Lobby;

// Frontier - save pickerwindow so it opens only once
private PickerWindow? _pickerWindow = null;

protected override void Startup()
{
if (_userInterfaceManager.ActiveScreen == null)
Expand Down Expand Up @@ -99,8 +102,10 @@ private void OnReadyPressed(BaseButton.ButtonEventArgs args)
{
return;
}

new NFLateJoinGui().OpenCentered();
// Frontier to downstream: if you want to skip the first window and go straight to station picker,
// simply change the enum to station or crew in the PickerWindow constructor.
_pickerWindow ??= new PickerWindow();
_pickerWindow.OpenCentered();
}

private void OnReadyToggled(BaseButton.ButtonToggledEventArgs args)
Expand Down
66 changes: 66 additions & 0 deletions Content.Client/_NF/LateJoin/Controls/CrewPickerControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<controls:CrewPickerControl xmlns="https://spacestation14.io"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client._NF.LateJoin.Controls"
Access="Public"
HorizontalExpand="True"
VerticalExpand="True">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True"
VerticalExpand="True">
<PanelContainer VerticalExpand="True" SetWidth="380">
<PanelContainer.PanelOverride>
<!-- Using PanelBackgroundLight adds padding left and right, so we manually set background color -->
<graphics:StyleBoxFlat BackgroundColor="#2F2F3B" />
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True">
<ScrollContainer HorizontalExpand="True"
VerticalExpand="True"
VScrollEnabled="True">
<BoxContainer Name="StationItemList"
Orientation="Vertical"
HorizontalExpand="True"
MinSize="50 50">
</BoxContainer>
</ScrollContainer>
</BoxContainer>
</PanelContainer>

<PanelContainer VerticalExpand="True" HorizontalExpand="True">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#25252a" />
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True">
<BoxContainer Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True"
Margin="20">
<Label Name="StationName"
HorizontalExpand="True"
StyleClasses="FancyWindowTitle" />

<RichTextLabel Name="StationDescription" />
</BoxContainer>

<Label Text="{Loc 'frontier-lobby-available-jobs'}"
Margin="20 4 0 4"
StyleClasses="FancyWindowTitle" />
<ScrollContainer HorizontalExpand="True"
VerticalExpand="True"
VScrollEnabled="True">


<BoxContainer Name="StationJobItemList"
Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True"
MinSize="50 50"
Margin="4">
</BoxContainer>
</ScrollContainer>
</BoxContainer>
</PanelContainer>
</BoxContainer>
</controls:CrewPickerControl>
Loading

0 comments on commit 9eca8c3

Please sign in to comment.