Disable job buttons when they aren't available or late join is disallowed (#2251)
* Disable job buttons when they aren't available In real time too, the technology is overwhelming * Jobs are all unavailable when late join is disallowed. * Better ToggleDisallowLateJoin command parsing * Add togglelatejoin to groups. Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es>
This commit is contained in:
@@ -22,6 +22,7 @@ namespace Content.Client.GameTicking
|
||||
[Dependency] private readonly IStateManager _stateManager = default!;
|
||||
|
||||
[ViewVariables] private bool _initialized;
|
||||
private readonly List<string> _jobsAvailable = new List<string>();
|
||||
|
||||
[ViewVariables] public bool AreWeReady { get; private set; }
|
||||
[ViewVariables] public bool IsGameStarted { get; private set; }
|
||||
@@ -30,11 +31,13 @@ namespace Content.Client.GameTicking
|
||||
[ViewVariables] public DateTime StartTime { get; private set; }
|
||||
[ViewVariables] public bool Paused { get; private set; }
|
||||
[ViewVariables] public Dictionary<NetUserId, PlayerStatus> Status { get; private set; }
|
||||
[ViewVariables] public IReadOnlyList<string> JobsAvailable => _jobsAvailable;
|
||||
|
||||
public event Action InfoBlobUpdated;
|
||||
public event Action LobbyStatusUpdated;
|
||||
public event Action LobbyReadyUpdated;
|
||||
public event Action LobbyLateJoinStatusUpdated;
|
||||
public event Action<IReadOnlyList<string>> LobbyJobsAvailableUpdated;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -52,6 +55,7 @@ namespace Content.Client.GameTicking
|
||||
IoCManager.Resolve<IClyde>().RequestWindowAttention();
|
||||
});
|
||||
_netManager.RegisterNetMessage<MsgTickerLateJoinStatus>(nameof(MsgTickerLateJoinStatus), LateJoinStatus);
|
||||
_netManager.RegisterNetMessage<MsgTickerJobsAvailable>(nameof(MsgTickerJobsAvailable), UpdateJobsAvailable);
|
||||
|
||||
Status = new Dictionary<NetUserId, PlayerStatus>();
|
||||
_initialized = true;
|
||||
@@ -63,6 +67,12 @@ namespace Content.Client.GameTicking
|
||||
LobbyLateJoinStatusUpdated?.Invoke();
|
||||
}
|
||||
|
||||
private void UpdateJobsAvailable(MsgTickerJobsAvailable message)
|
||||
{
|
||||
_jobsAvailable.Clear();
|
||||
_jobsAvailable.AddRange(message.JobsAvailable);
|
||||
LobbyJobsAvailableUpdated?.Invoke(JobsAvailable);
|
||||
}
|
||||
|
||||
private void JoinLobby(MsgTickerJoinLobby message)
|
||||
{
|
||||
|
||||
@@ -14,11 +14,13 @@ namespace Content.Client.Interfaces
|
||||
DateTime StartTime { get; }
|
||||
bool Paused { get; }
|
||||
Dictionary<NetUserId, PlayerStatus> Status { get; }
|
||||
IReadOnlyList<string> JobsAvailable { get; }
|
||||
|
||||
void Initialize();
|
||||
event Action InfoBlobUpdated;
|
||||
event Action LobbyStatusUpdated;
|
||||
event Action LobbyReadyUpdated;
|
||||
event Action LobbyLateJoinStatusUpdated;
|
||||
event Action<IReadOnlyList<string>> LobbyJobsAvailableUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Client.Interfaces;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
@@ -18,11 +20,14 @@ namespace Content.Client.UserInterface
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IClientConsole _console = default!;
|
||||
[Dependency] private readonly IClientGameTicker _gameTicker = default!;
|
||||
|
||||
protected override Vector2? CustomSize => (360, 560);
|
||||
|
||||
public event Action<string> SelectedId;
|
||||
|
||||
private Dictionary<string, JobButton> JobButtons = new Dictionary<string, JobButton>();
|
||||
|
||||
public LateJoinGui()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
@@ -84,6 +89,13 @@ namespace Content.Client.UserInterface
|
||||
{
|
||||
SelectedId?.Invoke(jobButton.JobId);
|
||||
};
|
||||
|
||||
if (!_gameTicker.JobsAvailable.Contains(job.ID))
|
||||
{
|
||||
jobButton.Disabled = true;
|
||||
}
|
||||
|
||||
JobButtons[job.ID] = jobButton;
|
||||
}
|
||||
|
||||
SelectedId += jobId =>
|
||||
@@ -93,7 +105,7 @@ namespace Content.Client.UserInterface
|
||||
Close();
|
||||
};
|
||||
|
||||
|
||||
_gameTicker.LobbyJobsAvailableUpdated += JobsAvailableUpdated;
|
||||
}
|
||||
|
||||
public string ReturnId()
|
||||
@@ -101,7 +113,26 @@ namespace Content.Client.UserInterface
|
||||
return SelectedId.ToString();
|
||||
}
|
||||
|
||||
private void JobsAvailableUpdated(IReadOnlyList<string> jobs)
|
||||
{
|
||||
foreach (var (id, button) in JobButtons)
|
||||
{
|
||||
button.Disabled = !jobs.Contains(id);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
_gameTicker.LobbyJobsAvailableUpdated -= JobsAvailableUpdated;
|
||||
JobButtons.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JobButton : ContainerButton
|
||||
{
|
||||
public string JobId { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user