2022-04-03 01:06:29 +03:00
|
|
|
using System.Linq;
|
2021-02-12 04:35:56 +01:00
|
|
|
using Content.Client.Eui;
|
2023-09-20 08:54:53 +01:00
|
|
|
using Content.Client.Players.PlayTimeTracking;
|
2021-02-12 04:35:56 +01:00
|
|
|
using Content.Shared.Eui;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Ghost.Roles;
|
2021-02-12 04:35:56 +01:00
|
|
|
using JetBrains.Annotations;
|
2023-09-20 08:54:53 +01:00
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
using Robust.Shared.Utility;
|
2021-02-12 04:35:56 +01:00
|
|
|
|
2022-09-11 20:42:12 -07:00
|
|
|
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
2021-02-12 04:35:56 +01:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class GhostRolesEui : BaseEui
|
2021-02-12 04:35:56 +01:00
|
|
|
{
|
|
|
|
|
private readonly GhostRolesWindow _window;
|
2021-11-02 00:42:04 +00:00
|
|
|
private GhostRoleRulesWindow? _windowRules = null;
|
|
|
|
|
private uint _windowRulesId = 0;
|
2021-02-12 04:35:56 +01:00
|
|
|
|
|
|
|
|
public GhostRolesEui()
|
|
|
|
|
{
|
|
|
|
|
_window = new GhostRolesWindow();
|
|
|
|
|
|
2022-04-03 01:06:29 +03:00
|
|
|
_window.OnRoleRequested += info =>
|
2021-02-12 04:35:56 +01:00
|
|
|
{
|
2021-11-02 00:42:04 +00:00
|
|
|
if (_windowRules != null)
|
|
|
|
|
_windowRules.Close();
|
|
|
|
|
_windowRules = new GhostRoleRulesWindow(info.Rules, _ =>
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new GhostRoleTakeoverRequestMessage(info.Identifier));
|
|
|
|
|
});
|
|
|
|
|
_windowRulesId = info.Identifier;
|
|
|
|
|
_windowRules.OnClose += () =>
|
|
|
|
|
{
|
|
|
|
|
_windowRules = null;
|
|
|
|
|
};
|
|
|
|
|
_windowRules.OpenCentered();
|
2021-02-12 04:35:56 +01:00
|
|
|
};
|
|
|
|
|
|
2022-04-03 01:06:29 +03:00
|
|
|
_window.OnRoleFollow += info =>
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new GhostRoleFollowRequestMessage(info.Identifier));
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-12 04:35:56 +01:00
|
|
|
_window.OnClose += () =>
|
|
|
|
|
{
|
2023-04-29 15:16:24 +12:00
|
|
|
SendMessage(new CloseEuiMessage());
|
2021-02-12 04:35:56 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Opened()
|
|
|
|
|
{
|
|
|
|
|
base.Opened();
|
|
|
|
|
_window.OpenCentered();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Closed()
|
|
|
|
|
{
|
|
|
|
|
base.Closed();
|
|
|
|
|
_window.Close();
|
2021-11-02 00:42:04 +00:00
|
|
|
_windowRules?.Close();
|
2021-02-12 04:35:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void HandleState(EuiStateBase state)
|
|
|
|
|
{
|
|
|
|
|
base.HandleState(state);
|
|
|
|
|
|
|
|
|
|
if (state is not GhostRolesEuiState ghostState) return;
|
|
|
|
|
_window.ClearEntries();
|
|
|
|
|
|
2023-09-20 08:54:53 +01:00
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
var sysManager = entityManager.EntitySysManager;
|
|
|
|
|
var spriteSystem = sysManager.GetEntitySystem<SpriteSystem>();
|
|
|
|
|
var requirementsManager = IoCManager.Resolve<JobRequirementsManager>();
|
|
|
|
|
|
2022-04-03 01:06:29 +03:00
|
|
|
var groupedRoles = ghostState.GhostRoles.GroupBy(
|
2023-09-20 08:54:53 +01:00
|
|
|
role => (role.Name, role.Description, role.Requirements));
|
2022-04-03 01:06:29 +03:00
|
|
|
foreach (var group in groupedRoles)
|
2021-02-12 04:35:56 +01:00
|
|
|
{
|
2022-04-03 01:06:29 +03:00
|
|
|
var name = group.Key.Name;
|
|
|
|
|
var description = group.Key.Description;
|
2023-09-20 08:54:53 +01:00
|
|
|
bool hasAccess = true;
|
|
|
|
|
FormattedMessage? reason;
|
|
|
|
|
|
|
|
|
|
if (!requirementsManager.CheckRoleTime(group.Key.Requirements, out reason))
|
|
|
|
|
{
|
|
|
|
|
hasAccess = false;
|
|
|
|
|
}
|
2022-04-03 01:06:29 +03:00
|
|
|
|
2023-09-20 08:54:53 +01:00
|
|
|
_window.AddEntry(name, description, hasAccess, reason, group, spriteSystem);
|
2021-11-02 00:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-03 01:06:29 +03:00
|
|
|
var closeRulesWindow = ghostState.GhostRoles.All(role => role.Identifier != _windowRulesId);
|
2021-11-02 00:42:04 +00:00
|
|
|
if (closeRulesWindow)
|
|
|
|
|
{
|
|
|
|
|
_windowRules?.Close();
|
2021-02-12 04:35:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|