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

View File

@@ -9,13 +9,24 @@ namespace Content.Client.Ghost.Roles.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class GhostRolesEntry : BoxContainer 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); RobustXamlLoader.Load(this);
Title.Text = info.Name; Title.Text = name;
Description.SetMessage(info.Description); Description.SetMessage(description);
RequestButton.OnPressed += requestAction;
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.Client.Eui;
using Content.Shared.Eui; using Content.Shared.Eui;
using Content.Shared.Ghost.Roles; using Content.Shared.Ghost.Roles;
@@ -16,7 +17,7 @@ namespace Content.Client.Ghost.Roles.UI
{ {
_window = new GhostRolesWindow(); _window = new GhostRolesWindow();
_window.RoleRequested += info => _window.OnRoleRequested += info =>
{ {
if (_windowRules != null) if (_windowRules != null)
_windowRules.Close(); _windowRules.Close();
@@ -32,6 +33,11 @@ namespace Content.Client.Ghost.Roles.UI
_windowRules.OpenCentered(); _windowRules.OpenCentered();
}; };
_window.OnRoleFollow += info =>
{
SendMessage(new GhostRoleFollowRequestMessage(info.Identifier));
};
_window.OnClose += () => _window.OnClose += () =>
{ {
SendMessage(new GhostRoleWindowCloseMessage()); SendMessage(new GhostRoleWindowCloseMessage());
@@ -56,20 +62,19 @@ namespace Content.Client.Ghost.Roles.UI
base.HandleState(state); base.HandleState(state);
if (state is not GhostRolesEuiState ghostState) return; if (state is not GhostRolesEuiState ghostState) return;
var closeRulesWindow = true;
_window.ClearEntries(); _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); var name = group.Key.Name;
if (info.Identifier == _windowRulesId) var description = group.Key.Description;
{
closeRulesWindow = false; _window.AddEntry(name, description, group);
}
} }
var closeRulesWindow = ghostState.GhostRoles.All(role => role.Identifier != _windowRulesId);
if (closeRulesWindow) if (closeRulesWindow)
{ {
_windowRules?.Close(); _windowRules?.Close();

View File

@@ -8,7 +8,8 @@ namespace Content.Client.Ghost.Roles.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class GhostRolesWindow : DefaultWindow public sealed partial class GhostRolesWindow : DefaultWindow
{ {
public event Action<GhostRoleInfo>? RoleRequested; public event Action<GhostRoleInfo>? OnRoleRequested;
public event Action<GhostRoleInfo>? OnRoleFollow;
public void ClearEntries() public void ClearEntries()
{ {
@@ -16,10 +17,14 @@ namespace Content.Client.Ghost.Roles.UI
EntryContainer.DisposeAllChildren(); EntryContainer.DisposeAllChildren();
} }
public void AddEntry(GhostRoleInfo info) public void AddEntry(string name, string description, IEnumerable<GhostRoleInfo> roles)
{ {
NoRolesMessage.Visible = false; 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.Server.Players;
using Content.Shared.Administration; using Content.Shared.Administration;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Follower;
using Content.Shared.GameTicking; using Content.Shared.GameTicking;
using Content.Shared.Ghost; using Content.Shared.Ghost;
using Content.Shared.Ghost.Roles; using Content.Shared.Ghost.Roles;
@@ -32,6 +33,7 @@ namespace Content.Server.Ghost.Roles
[Dependency] private readonly EuiManager _euiManager = default!; [Dependency] private readonly EuiManager _euiManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly AdminLogSystem _adminLogSystem = default!; [Dependency] private readonly AdminLogSystem _adminLogSystem = default!;
[Dependency] private readonly FollowerSystem _followerSystem = default!;
private uint _nextRoleIdentifier; private uint _nextRoleIdentifier;
private bool _needsUpdateGhostRoleCount = true; private bool _needsUpdateGhostRoleCount = true;
@@ -188,6 +190,14 @@ namespace Content.Server.Ghost.Roles
CloseEui(player); 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) public void GhostRoleInternalCreateMindAndTransfer(IPlayerSession player, EntityUid roleUid, EntityUid mob, GhostRoleComponent? role = null)
{ {
if (!Resolve(roleUid, ref role)) return; if (!Resolve(roleUid, ref role)) return;

View File

@@ -21,7 +21,9 @@ namespace Content.Server.Ghost.Roles.UI
case GhostRoleTakeoverRequestMessage req: case GhostRoleTakeoverRequestMessage req:
EntitySystem.Get<GhostRoleSystem>().Takeover(Player, req.Identifier); EntitySystem.Get<GhostRoleSystem>().Takeover(Player, req.Identifier);
break; break;
case GhostRoleFollowRequestMessage req:
EntitySystem.Get<GhostRoleSystem>().Follow(Player, req.Identifier);
break;
case GhostRoleWindowCloseMessage _: case GhostRoleWindowCloseMessage _:
Closed(); Closed();
break; 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] [NetSerializable, Serializable]
public sealed class GhostRoleWindowCloseMessage : EuiMessageBase 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-title = Ghost Roles
ghost-roles-window-request-role-button = Request 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-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). ghost-roles-window-rules-footer = The button will enable after 5 seconds (this delay is to make sure you read the rules).