54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using Content.Client.GameTicking.Managers;
|
|
using Content.Shared.Roles;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Client.Utility;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client._Sunrise.Latejoin;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class SRLateJoinJobButton : Button
|
|
{
|
|
private readonly IPrototypeManager _prototypeManager;
|
|
private readonly ClientGameTicker _gameTicker;
|
|
private readonly NetEntity _station;
|
|
private readonly string _jobId;
|
|
|
|
public SRLateJoinJobButton(NetEntity station, string jobId, ClientGameTicker gameTicker, IPrototypeManager prototypeManager)
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
_prototypeManager = prototypeManager;
|
|
_gameTicker = gameTicker;
|
|
_station = station;
|
|
_jobId = jobId;
|
|
|
|
_gameTicker.LobbyJobsAvailableUpdated += UpdateButton;
|
|
UpdateButton(_gameTicker.JobsAvailable);
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
_gameTicker.LobbyJobsAvailableUpdated -= UpdateButton;
|
|
}
|
|
|
|
private void UpdateButton(IReadOnlyDictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>> obj)
|
|
{
|
|
if (!obj.ContainsKey(_station) || !obj[_station].ContainsKey(_jobId))
|
|
{
|
|
Visible = false;
|
|
return;
|
|
}
|
|
|
|
var prototype = _prototypeManager.Index<JobPrototype>(_jobId);
|
|
|
|
var jobIcon = _prototypeManager.Index(prototype.Icon);
|
|
JobIcon.Texture = jobIcon.Icon.Frame0();
|
|
|
|
JobText.Text = $"{prototype.LocalizedName} ({obj[_station][_jobId]?.ToString() ?? "Unlimited"})";
|
|
|
|
Disabled = obj[_station][_jobId] == 0;
|
|
}
|
|
}
|