Roundstart antag role restrictions revival (#20108)

Co-authored-by: Ray <vigersray@gmail.com>
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-09-20 08:54:53 +01:00
committed by GitHub
parent 35246963c7
commit 4fbebb6917
14 changed files with 229 additions and 150 deletions

View File

@@ -4,10 +4,12 @@
Access="Public"
Text="{Loc 'ghost-roles-window-request-role-button'}"
StyleClasses="OpenRight"
HorizontalAlignment="Left"/>
HorizontalAlignment="Left"
SetWidth="150"/>
<Button Name="FollowButton"
Access="Public"
Text="{Loc 'ghost-roles-window-follow-role-button'}"
StyleClasses="OpenLeft"
HorizontalAlignment="Right"/>
HorizontalAlignment="Right"
SetWidth="150"/>
</BoxContainer>

View File

@@ -1,5 +1,7 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'ghost-roles-window-title'}">
Title="{Loc 'ghost-roles-window-title'}"
MinSize="500 300"
SetSize="500 300">
<BoxContainer Orientation="Vertical"
HorizontalExpand="True">
<RichTextLabel Name="TopBanner" VerticalExpand="True"/>

View File

@@ -1,19 +1,25 @@
using System.Numerics;
using Content.Shared.Ghost.Roles;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
{
[GenerateTypedNameReferences]
public sealed partial class GhostRolesEntry : BoxContainer
{
private SpriteSystem _spriteSystem;
public event Action<GhostRoleInfo>? OnRoleSelected;
public event Action<GhostRoleInfo>? OnRoleFollow;
public GhostRolesEntry(string name, string description, IEnumerable<GhostRoleInfo> roles)
public GhostRolesEntry(string name, string description, bool hasAccess, FormattedMessage? reason, IEnumerable<GhostRoleInfo> roles, SpriteSystem spriteSystem)
{
RobustXamlLoader.Load(this);
_spriteSystem = spriteSystem;
Title.Text = name;
Description.SetMessage(description);
@@ -24,6 +30,27 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
button.RequestButton.OnPressed += _ => OnRoleSelected?.Invoke(role);
button.FollowButton.OnPressed += _ => OnRoleFollow?.Invoke(role);
if (!hasAccess)
{
button.RequestButton.Disabled = true;
if (reason != null && !reason.IsEmpty)
{
var tooltip = new Tooltip();
tooltip.SetMessage(reason);
button.RequestButton.TooltipSupplier = _ => tooltip;
}
button.RequestButton.AddChild(new TextureRect
{
TextureScale = new Vector2(0.4f, 0.4f),
Stretch = TextureRect.StretchMode.KeepCentered,
Texture = _spriteSystem.Frame0(new SpriteSpecifier.Texture(new ("/Textures/Interface/Nano/lock.svg.192dpi.png"))),
HorizontalExpand = true,
HorizontalAlignment = HAlignment.Right,
});
}
Buttons.AddChild(button);
}
}

View File

@@ -1,8 +1,11 @@
using System.Linq;
using Content.Client.Eui;
using Content.Client.Players.PlayTimeTracking;
using Content.Shared.Eui;
using Content.Shared.Ghost.Roles;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
{
@@ -64,14 +67,26 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
if (state is not GhostRolesEuiState ghostState) return;
_window.ClearEntries();
var entityManager = IoCManager.Resolve<IEntityManager>();
var sysManager = entityManager.EntitySysManager;
var spriteSystem = sysManager.GetEntitySystem<SpriteSystem>();
var requirementsManager = IoCManager.Resolve<JobRequirementsManager>();
var groupedRoles = ghostState.GhostRoles.GroupBy(
role => (role.Name, role.Description));
role => (role.Name, role.Description, role.Requirements));
foreach (var group in groupedRoles)
{
var name = group.Key.Name;
var description = group.Key.Description;
bool hasAccess = true;
FormattedMessage? reason;
_window.AddEntry(name, description, group);
if (!requirementsManager.CheckRoleTime(group.Key.Requirements, out reason))
{
hasAccess = false;
}
_window.AddEntry(name, description, hasAccess, reason, group, spriteSystem);
}
var closeRulesWindow = ghostState.GhostRoles.All(role => role.Identifier != _windowRulesId);

View File

@@ -1,6 +1,7 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'ghost-roles-window-title'}"
MinSize="375 275">
MinSize="450 400"
SetSize="400 500">
<Label Name="NoRolesMessage"
Text="{Loc 'ghost-roles-window-no-roles-available-label'}"
VerticalAlignment="Top" />

View File

@@ -1,6 +1,8 @@
using Content.Shared.Ghost.Roles;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
{
@@ -16,11 +18,11 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
EntryContainer.DisposeAllChildren();
}
public void AddEntry(string name, string description, IEnumerable<GhostRoleInfo> roles)
public void AddEntry(string name, string description, bool hasAccess, FormattedMessage? reason, IEnumerable<GhostRoleInfo> roles, SpriteSystem spriteSystem)
{
NoRolesMessage.Visible = false;
var entry = new GhostRolesEntry(name, description, roles);
var entry = new GhostRolesEntry(name, description, hasAccess, reason, roles, spriteSystem);
entry.OnRoleSelected += OnRoleRequested;
entry.OnRoleFollow += OnRoleFollow;
EntryContainer.AddChild(entry);