Grouped ghost roles and jump button (#7300)

This commit is contained in:
Alex Evgrashin
2022-04-03 01:06:29 +03:00
committed by GitHub
parent 31a9cc0acb
commit bf89483e09
10 changed files with 91 additions and 21 deletions

View File

@@ -0,0 +1,13 @@
<BoxContainer xmlns="https://spacestation14.io"
Orientation="Horizontal">
<Button Name="RequestButton"
Access="Public"
Text="{Loc 'ghost-roles-window-request-role-button'}"
StyleClasses="OpenRight"
HorizontalAlignment="Left"/>
<Button Name="FollowButton"
Access="Public"
Text="{Loc 'ghost-roles-window-follow-role-button'}"
StyleClasses="OpenLeft"
HorizontalAlignment="Right"/>
</BoxContainer>

View File

@@ -0,0 +1,9 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Ghost.Roles.UI;
[GenerateTypedNameReferences]
public sealed partial class GhostRoleEntryButtons : BoxContainer
{
}

View File

@@ -7,7 +7,10 @@
<PanelContainer StyleClasses="HighDivider" />
<RichTextLabel Name="Description"
Margin="0 4"/>
<Button Name="RequestButton"
Text="{Loc 'ghost-roles-window-request-role-button'}"
HorizontalAlignment="Left"/>
<BoxContainer Name="Buttons"
HorizontalAlignment="Left"
Orientation="Vertical"
SeparationOverride="5">
<!-- Buttons are added here by code -->
</BoxContainer>
</BoxContainer>

View File

@@ -9,13 +9,24 @@ namespace Content.Client.Ghost.Roles.UI
[GenerateTypedNameReferences]
public sealed partial class GhostRolesEntry : BoxContainer
{
public GhostRolesEntry(GhostRoleInfo info, Action<BaseButton.ButtonEventArgs> requestAction)
public event Action<GhostRoleInfo>? OnRoleSelected;
public event Action<GhostRoleInfo>? OnRoleFollow;
public GhostRolesEntry(string name, string description, IEnumerable<GhostRoleInfo> roles)
{
RobustXamlLoader.Load(this);
Title.Text = info.Name;
Description.SetMessage(info.Description);
RequestButton.OnPressed += requestAction;
Title.Text = name;
Description.SetMessage(description);
foreach (var role in roles)
{
var button = new GhostRoleEntryButtons();
button.RequestButton.OnPressed += _ => OnRoleSelected?.Invoke(role);
button.FollowButton.OnPressed += _ => OnRoleFollow?.Invoke(role);
Buttons.AddChild(button);
}
}
}
}

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Content.Client.Eui;
using Content.Shared.Eui;
using Content.Shared.Ghost.Roles;
@@ -16,7 +17,7 @@ namespace Content.Client.Ghost.Roles.UI
{
_window = new GhostRolesWindow();
_window.RoleRequested += info =>
_window.OnRoleRequested += info =>
{
if (_windowRules != null)
_windowRules.Close();
@@ -32,6 +33,11 @@ namespace Content.Client.Ghost.Roles.UI
_windowRules.OpenCentered();
};
_window.OnRoleFollow += info =>
{
SendMessage(new GhostRoleFollowRequestMessage(info.Identifier));
};
_window.OnClose += () =>
{
SendMessage(new GhostRoleWindowCloseMessage());
@@ -56,20 +62,19 @@ namespace Content.Client.Ghost.Roles.UI
base.HandleState(state);
if (state is not GhostRolesEuiState ghostState) return;
var closeRulesWindow = true;
_window.ClearEntries();
foreach (var info in ghostState.GhostRoles)
var groupedRoles = ghostState.GhostRoles.GroupBy(
role => (role.Name, role.Description));
foreach (var group in groupedRoles)
{
_window.AddEntry(info);
if (info.Identifier == _windowRulesId)
{
closeRulesWindow = false;
}
var name = group.Key.Name;
var description = group.Key.Description;
_window.AddEntry(name, description, group);
}
var closeRulesWindow = ghostState.GhostRoles.All(role => role.Identifier != _windowRulesId);
if (closeRulesWindow)
{
_windowRules?.Close();

View File

@@ -8,7 +8,8 @@ namespace Content.Client.Ghost.Roles.UI
[GenerateTypedNameReferences]
public sealed partial class GhostRolesWindow : DefaultWindow
{
public event Action<GhostRoleInfo>? RoleRequested;
public event Action<GhostRoleInfo>? OnRoleRequested;
public event Action<GhostRoleInfo>? OnRoleFollow;
public void ClearEntries()
{
@@ -16,10 +17,14 @@ namespace Content.Client.Ghost.Roles.UI
EntryContainer.DisposeAllChildren();
}
public void AddEntry(GhostRoleInfo info)
public void AddEntry(string name, string description, IEnumerable<GhostRoleInfo> roles)
{
NoRolesMessage.Visible = false;
EntryContainer.AddChild(new GhostRolesEntry(info, _ => RoleRequested?.Invoke(info)));
var entry = new GhostRolesEntry(name, description, roles);
entry.OnRoleSelected += OnRoleRequested;
entry.OnRoleFollow += OnRoleFollow;
EntryContainer.AddChild(entry);
}
}
}

View File

@@ -10,6 +10,7 @@ using Content.Server.MobState.States;
using Content.Server.Players;
using Content.Shared.Administration;
using Content.Shared.Database;
using Content.Shared.Follower;
using Content.Shared.GameTicking;
using Content.Shared.Ghost;
using Content.Shared.Ghost.Roles;
@@ -32,6 +33,7 @@ namespace Content.Server.Ghost.Roles
[Dependency] private readonly EuiManager _euiManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly AdminLogSystem _adminLogSystem = default!;
[Dependency] private readonly FollowerSystem _followerSystem = default!;
private uint _nextRoleIdentifier;
private bool _needsUpdateGhostRoleCount = true;
@@ -188,6 +190,14 @@ namespace Content.Server.Ghost.Roles
CloseEui(player);
}
public void Follow(IPlayerSession player, uint identifier)
{
if (!_ghostRoles.TryGetValue(identifier, out var role)) return;
if (player.AttachedEntity == null) return;
_followerSystem.StartFollowingEntity(player.AttachedEntity.Value, role.Owner);
}
public void GhostRoleInternalCreateMindAndTransfer(IPlayerSession player, EntityUid roleUid, EntityUid mob, GhostRoleComponent? role = null)
{
if (!Resolve(roleUid, ref role)) return;

View File

@@ -21,7 +21,9 @@ namespace Content.Server.Ghost.Roles.UI
case GhostRoleTakeoverRequestMessage req:
EntitySystem.Get<GhostRoleSystem>().Takeover(Player, req.Identifier);
break;
case GhostRoleFollowRequestMessage req:
EntitySystem.Get<GhostRoleSystem>().Follow(Player, req.Identifier);
break;
case GhostRoleWindowCloseMessage _:
Closed();
break;

View File

@@ -35,6 +35,17 @@ namespace Content.Shared.Ghost.Roles
}
}
[NetSerializable, Serializable]
public sealed class GhostRoleFollowRequestMessage : EuiMessageBase
{
public uint Identifier { get; }
public GhostRoleFollowRequestMessage(uint identifier)
{
Identifier = identifier;
}
}
[NetSerializable, Serializable]
public sealed class GhostRoleWindowCloseMessage : EuiMessageBase
{

View File

@@ -7,6 +7,7 @@ ghost-target-window-current-button = Warp: {$name}
ghost-roles-window-title = Ghost Roles
ghost-roles-window-request-role-button = Request
ghost-roles-window-follow-role-button = Follow
ghost-roles-window-no-roles-available-label = There are currently no available ghost roles.
ghost-roles-window-rules-footer = The button will enable after 5 seconds (this delay is to make sure you read the rules).