Add make ghost role verb (#3204)

This commit is contained in:
DrSmugleaf
2021-02-16 09:51:27 +01:00
committed by GitHub
parent 6a3072e4fd
commit 78afc2db0f
19 changed files with 388 additions and 20 deletions

View File

@@ -0,0 +1,9 @@
<uic:VBoxContainer
xmlns:uic="clr-namespace:Robust.Client.UserInterface.Controls;assembly=Robust.Client">
<uic:RichTextLabel Name="Title" />
<uic:HBoxContainer SeparationOverride="10">
<uic:RichTextLabel Name="Description" SizeFlagsHorizontal="FillExpand" />
<uic:Button Name="RequestButton" Text="Request" TextAlign="Center" SizeFlagsHorizontal="ShrinkEnd" />
</uic:HBoxContainer>
</uic:VBoxContainer>

View File

@@ -0,0 +1,22 @@
using System;
using Content.Shared.GameObjects.Components.Observer;
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
{
[GenerateTypedNameReferences]
public partial class GhostRolesEntry : VBoxContainer
{
public GhostRolesEntry(GhostRoleInfo info, Action<BaseButton.ButtonEventArgs> requestAction)
{
RobustXamlLoader.Load(this);
Title.SetMessage(info.Name);
Description.SetMessage(info.Description);
RequestButton.OnPressed += requestAction;
}
}
}

View File

@@ -0,0 +1,55 @@
using Content.Client.Eui;
using Content.Shared.Eui;
using Content.Shared.GameObjects.Components.Observer;
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
using JetBrains.Annotations;
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
{
[UsedImplicitly]
public class GhostRolesEui : BaseEui
{
private readonly GhostRolesWindow _window;
public GhostRolesEui()
{
_window = new GhostRolesWindow();
_window.RoleRequested += id =>
{
SendMessage(new GhostRoleTakeoverRequestMessage(id));
};
_window.OnClose += () =>
{
SendMessage(new GhostRoleWindowCloseMessage());
};
}
public override void Opened()
{
base.Opened();
_window.OpenCentered();
}
public override void Closed()
{
base.Closed();
_window.Close();
}
public override void HandleState(EuiStateBase state)
{
base.HandleState(state);
if (state is not GhostRolesEuiState ghostState) return;
_window.ClearEntries();
foreach (var info in ghostState.GhostRoles)
{
_window.AddEntry(info);
}
}
}
}

View File

@@ -0,0 +1,12 @@
<cc:SS14Window Title="Ghost Roles"
xmlns:cc="clr-namespace:Robust.Client.UserInterface.CustomControls;assembly=Robust.Client"
xmlns:uic="clr-namespace:Robust.Client.UserInterface.Controls;assembly=Robust.Client">
<uic:CenterContainer Name="NoRolesMessage" SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="FillExpand">
<uic:Label Text="There are currently no available ghost roles."/>
</uic:CenterContainer>
<uic:ScrollContainer SizeFlagsHorizontal="FillExpand" SizeFlagsVertical="FillExpand">
<uic:VBoxContainer Name="EntryContainer" SizeFlagsHorizontal="FillExpand" SizeFlagsVertical="FillExpand" />
</uic:ScrollContainer>
</cc:SS14Window>

View File

@@ -0,0 +1,29 @@
using System;
using Content.Shared.GameObjects.Components.Observer;
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Maths;
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
{
[GenerateTypedNameReferences]
public partial class GhostRolesWindow : SS14Window
{
public event Action<uint> RoleRequested;
protected override Vector2 CalculateMinimumSize() => (350, 275);
public void ClearEntries()
{
EntryContainer.DisposeAllChildren();
NoRolesMessage.Visible = true;
}
public void AddEntry(GhostRoleInfo info)
{
NoRolesMessage.Visible = false;
EntryContainer.AddChild(new GhostRolesEntry(info, _ => RoleRequested?.Invoke(info.Identifier)));
}
}
}

View File

@@ -0,0 +1,76 @@
using Content.Client.Eui;
using Content.Shared.Eui;
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
using JetBrains.Annotations;
using Robust.Client.Console;
using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
{
[UsedImplicitly]
public class MakeGhostRoleEui : BaseEui
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
private readonly MakeGhostRoleWindow _window;
public MakeGhostRoleEui()
{
_window = new MakeGhostRoleWindow();
_window.OnClose += OnClose;
_window.OnMake += OnMake;
}
public override void HandleState(EuiStateBase state)
{
if (state is not MakeGhostRoleEuiState uiState)
{
return;
}
_window.SetEntity(uiState.EntityUid);
}
public override void Opened()
{
base.Opened();
_window.OpenCentered();
}
private void OnMake(EntityUid uid, string name, string description, bool makeSentient)
{
var player = _playerManager.LocalPlayer;
if (player == null)
{
return;
}
var makeGhostRoleCommand =
$"makeghostrole " +
$"\"{CommandParsing.Escape(uid.ToString())}\" " +
$"\"{CommandParsing.Escape(name)}\" " +
$"\"{CommandParsing.Escape(description)}\"";
_consoleHost.ExecuteCommand(player.Session, makeGhostRoleCommand);
if (makeSentient)
{
var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(uid.ToString())}\"";
_consoleHost.ExecuteCommand(player.Session, makeSentientCommand);
}
_window.Close();
}
private void OnClose()
{
base.Closed();
SendMessage(new MakeGhostRoleWindowClosedMessage());
}
}
}

View File

@@ -0,0 +1,27 @@
<cc:SS14Window Title="Make Ghost Role"
xmlns:cc="clr-namespace:Robust.Client.UserInterface.CustomControls;assembly=Robust.Client"
xmlns:c="clr-namespace:Robust.Client.UserInterface.Controls;assembly=Robust.Client">
<c:VBoxContainer>
<c:HBoxContainer>
<c:Label Name="RoleEntityLabel" Text="Entity" />
<c:Label Name="RoleEntity" Text="" />
</c:HBoxContainer>
<c:HBoxContainer>
<c:Label Name="RoleNameLabel" Text="Role Name" />
<c:LineEdit Name="RoleName" SizeFlagsHorizontal="FillExpand"/>
</c:HBoxContainer>
<c:HBoxContainer>
<c:Label Name="RoleDescriptionLabel" Text="Role Description" />
<c:LineEdit Name="RoleDescription" SizeFlagsHorizontal="FillExpand"/>
</c:HBoxContainer>
<c:HBoxContainer>
<c:Label Name="MakeSentientLabel" Text="Make Sentient" />
<c:CheckBox Name="MakeSentientCheckbox" />
</c:HBoxContainer>
<c:HBoxContainer>
<c:Button Name="MakeButton" Text="Make" />
</c:HBoxContainer>
</c:VBoxContainer>
</cc:SS14Window>

View File

@@ -0,0 +1,49 @@
#nullable enable
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.GameObjects;
using static Robust.Client.UserInterface.Controls.BaseButton;
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
{
[GenerateTypedNameReferences]
public partial class MakeGhostRoleWindow : SS14Window
{
public delegate void MakeRole(EntityUid uid, string name, string description, bool makeSentient);
public MakeGhostRoleWindow()
{
RobustXamlLoader.Load(this);
MakeSentientLabel.CustomMinimumSize = (150, 0);
RoleEntityLabel.CustomMinimumSize = (150, 0);
RoleNameLabel.CustomMinimumSize = (150, 0);
RoleName.CustomMinimumSize = (300, 0);
RoleDescriptionLabel.CustomMinimumSize = (150, 0);
RoleDescription.CustomMinimumSize = (300, 0);
MakeButton.OnPressed += OnPressed;
}
private EntityUid? EntityUid { get; set; }
public event MakeRole? OnMake;
public void SetEntity(EntityUid uid)
{
EntityUid = uid;
RoleEntity.Text = $"{uid}";
}
private void OnPressed(ButtonEventArgs args)
{
if (EntityUid == null)
{
return;
}
OnMake?.Invoke(EntityUid.Value, RoleName.Text, RoleDescription.Text, MakeSentientCheckbox.Pressed);
}
}
}