Re-organize all projects (#4166)
This commit is contained in:
144
Content.Client/Ghost/GhostComponent.cs
Normal file
144
Content.Client/Ghost/GhostComponent.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.Chat.Managers;
|
||||
using Content.Client.HUD;
|
||||
using Content.Shared.Ghost;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Ghost
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class GhostComponent : SharedGhostComponent
|
||||
{
|
||||
[Dependency] private readonly IGameHud _gameHud = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IComponentManager _componentManager = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
|
||||
public List<string> WarpNames = new();
|
||||
public Dictionary<EntityUid,string> PlayerNames = new();
|
||||
|
||||
private GhostGui? _gui ;
|
||||
|
||||
[ViewVariables(VVAccess.ReadOnly)] public bool CanReturnToBody { get; private set; } = true;
|
||||
|
||||
private bool _isAttached;
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
_gui?.Dispose();
|
||||
|
||||
// PlayerDetachedMsg might not fire due to deletion order so...
|
||||
if (_isAttached)
|
||||
{
|
||||
SetGhostVisibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetGhostVisibility(bool visibility)
|
||||
{
|
||||
foreach (var ghost in _componentManager.GetAllComponents(typeof(GhostComponent), true))
|
||||
{
|
||||
if (ghost.Owner.TryGetComponent(out SpriteComponent? component))
|
||||
{
|
||||
component.Visible = visibility;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (Owner.TryGetComponent(out SpriteComponent? component))
|
||||
{
|
||||
component.Visible =
|
||||
_playerManager.LocalPlayer?.ControlledEntity?.HasComponent<GhostComponent>() ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case PlayerAttachedMsg _:
|
||||
if (_gui == null)
|
||||
{
|
||||
_gui = new GhostGui(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
_gui.Orphan();
|
||||
}
|
||||
|
||||
_gameHud.HandsContainer.AddChild(_gui);
|
||||
SetGhostVisibility(true);
|
||||
_isAttached = true;
|
||||
|
||||
break;
|
||||
|
||||
case PlayerDetachedMsg _:
|
||||
_gui!.Parent?.RemoveChild(_gui);
|
||||
SetGhostVisibility(false);
|
||||
_isAttached = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SendReturnToBodyMessage() => SendNetworkMessage(new ReturnToBodyComponentMessage());
|
||||
|
||||
public void SendGhostWarpRequestMessage(string warpName) => SendNetworkMessage(new GhostWarpToLocationRequestMessage(warpName));
|
||||
|
||||
public void SendGhostWarpRequestMessage(EntityUid target) => SendNetworkMessage(new GhostWarpToTargetRequestMessage(target));
|
||||
|
||||
public void GhostRequestWarpPoint() => SendNetworkMessage(new GhostRequestWarpPointData());
|
||||
|
||||
public void GhostRequestPlayerNames() => SendNetworkMessage(new GhostRequestPlayerNameData());
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not GhostComponentState state) return;
|
||||
|
||||
CanReturnToBody = state.CanReturnToBody;
|
||||
|
||||
if (Owner == _playerManager.LocalPlayer!.ControlledEntity)
|
||||
{
|
||||
_gui?.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
|
||||
{
|
||||
base.HandleNetworkMessage(message, netChannel, session);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case GhostReplyWarpPointData data:
|
||||
WarpNames = new List<string>();
|
||||
foreach (var names in data.WarpName)
|
||||
{
|
||||
WarpNames.Add(names);
|
||||
}
|
||||
break;
|
||||
case GhostReplyPlayerNameData data:
|
||||
PlayerNames = new Dictionary<EntityUid, string>();
|
||||
foreach (var (key, value) in data.PlayerNames)
|
||||
{
|
||||
PlayerNames.Add(key,value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
140
Content.Client/Ghost/GhostGui.cs
Normal file
140
Content.Client/Ghost/GhostGui.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
#nullable enable
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Client.Ghost
|
||||
{
|
||||
public class GhostGui : Control
|
||||
{
|
||||
private readonly Button _returnToBody = new() {Text = Loc.GetString("Return to body")};
|
||||
private readonly Button _ghostWarp = new() {Text = Loc.GetString("Ghost Warp")};
|
||||
private readonly Button _ghostRoles = new() {Text = Loc.GetString("Ghost Roles")};
|
||||
private readonly GhostComponent _owner;
|
||||
|
||||
public GhostTargetWindow? TargetWindow { get; }
|
||||
|
||||
public GhostGui(GhostComponent owner)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_owner = owner;
|
||||
|
||||
TargetWindow = new GhostTargetWindow(owner);
|
||||
|
||||
MouseFilter = MouseFilterMode.Ignore;
|
||||
|
||||
_ghostWarp.OnPressed += _ => TargetWindow.Populate();
|
||||
_returnToBody.OnPressed += _ => owner.SendReturnToBodyMessage();
|
||||
_ghostRoles.OnPressed += _ => IoCManager.Resolve<IClientConsoleHost>().RemoteExecuteCommand(null, "ghostroles");
|
||||
|
||||
AddChild(new HBoxContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
_returnToBody,
|
||||
_ghostWarp,
|
||||
_ghostRoles,
|
||||
}
|
||||
});
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
_returnToBody.Disabled = !_owner.CanReturnToBody;
|
||||
}
|
||||
}
|
||||
|
||||
public class GhostTargetWindow : SS14Window
|
||||
{
|
||||
private readonly GhostComponent _owner;
|
||||
private readonly VBoxContainer _buttonContainer;
|
||||
|
||||
public GhostTargetWindow(GhostComponent owner)
|
||||
{
|
||||
MinSize = SetSize = (300, 450);
|
||||
Title = "Ghost Warp";
|
||||
_owner = owner;
|
||||
_owner.GhostRequestWarpPoint();
|
||||
_owner.GhostRequestPlayerNames();
|
||||
|
||||
_buttonContainer = new VBoxContainer()
|
||||
{
|
||||
VerticalExpand = true,
|
||||
SeparationOverride = 5,
|
||||
|
||||
};
|
||||
|
||||
var scrollBarContainer = new ScrollContainer()
|
||||
{
|
||||
VerticalExpand = true,
|
||||
HorizontalExpand = true
|
||||
};
|
||||
|
||||
scrollBarContainer.AddChild(_buttonContainer);
|
||||
|
||||
Contents.AddChild(scrollBarContainer);
|
||||
}
|
||||
|
||||
public void Populate()
|
||||
{
|
||||
_buttonContainer.DisposeAllChildren();
|
||||
AddButtonPlayers();
|
||||
AddButtonLocations();
|
||||
OpenCentered();
|
||||
}
|
||||
|
||||
private void AddButtonPlayers()
|
||||
{
|
||||
foreach (var (key, value) in _owner.PlayerNames)
|
||||
{
|
||||
var currentButtonRef = new Button
|
||||
{
|
||||
Text = value,
|
||||
TextAlign = Label.AlignMode.Right,
|
||||
HorizontalAlignment = HAlignment.Center,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
MinSize = (230, 20),
|
||||
ClipText = true,
|
||||
};
|
||||
|
||||
currentButtonRef.OnPressed += (_) =>
|
||||
{
|
||||
_owner.SendGhostWarpRequestMessage(key);
|
||||
};
|
||||
|
||||
_buttonContainer.AddChild(currentButtonRef);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButtonLocations()
|
||||
{
|
||||
foreach (var name in _owner.WarpNames)
|
||||
{
|
||||
var currentButtonRef = new Button
|
||||
{
|
||||
Text = $"Warp: {name}",
|
||||
TextAlign = Label.AlignMode.Right,
|
||||
HorizontalAlignment = HAlignment.Center,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
MinSize = (230,20),
|
||||
ClipText = true,
|
||||
};
|
||||
|
||||
currentButtonRef.OnPressed += (_) =>
|
||||
{
|
||||
_owner.SendGhostWarpRequestMessage(name);
|
||||
};
|
||||
|
||||
_buttonContainer.AddChild(currentButtonRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Content.Client/Ghost/Roles/UI/GhostRoleWindow.cs
Normal file
12
Content.Client/Ghost/Roles/UI/GhostRoleWindow.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
|
||||
namespace Content.Client.Ghost.Roles.UI
|
||||
{
|
||||
public class GhostRoleWindow : SS14Window
|
||||
{
|
||||
protected override void Opened()
|
||||
{
|
||||
base.Opened();
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Content.Client/Ghost/Roles/UI/GhostRolesEntry.xaml
Normal file
9
Content.Client/Ghost/Roles/UI/GhostRolesEntry.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<VBoxContainer
|
||||
xmlns="https://spacestation14.io">
|
||||
|
||||
<RichTextLabel Name="Title" />
|
||||
<HBoxContainer SeparationOverride="10">
|
||||
<RichTextLabel Name="Description" HorizontalExpand="True" />
|
||||
<Button Name="RequestButton" Text="Request" TextAlign="Center" SizeFlagsHorizontal="ShrinkEnd" />
|
||||
</HBoxContainer>
|
||||
</VBoxContainer>
|
||||
21
Content.Client/Ghost/Roles/UI/GhostRolesEntry.xaml.cs
Normal file
21
Content.Client/Ghost/Roles/UI/GhostRolesEntry.xaml.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using Content.Shared.Ghost.Roles;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Ghost.Roles.UI
|
||||
{
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
Content.Client/Ghost/Roles/UI/GhostRolesEui.cs
Normal file
54
Content.Client/Ghost/Roles/UI/GhostRolesEui.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Content.Client.Eui;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.Ghost.Roles;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Client.Ghost.Roles.UI
|
||||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Content.Client/Ghost/Roles/UI/GhostRolesWindow.xaml
Normal file
10
Content.Client/Ghost/Roles/UI/GhostRolesWindow.xaml
Normal file
@@ -0,0 +1,10 @@
|
||||
<SS14Window Title="Ghost Roles"
|
||||
xmlns="https://spacestation14.io" MinSize="350 275">
|
||||
<CenterContainer Name="NoRolesMessage" VerticalExpand="True" HorizontalExpand="True">
|
||||
<Label Text="There are currently no available ghost roles." />
|
||||
</CenterContainer>
|
||||
<ScrollContainer HorizontalExpand="True" VerticalExpand="True">
|
||||
<VBoxContainer Name="EntryContainer" HorizontalExpand="True" VerticalExpand="True" />
|
||||
</ScrollContainer>
|
||||
|
||||
</SS14Window>
|
||||
25
Content.Client/Ghost/Roles/UI/GhostRolesWindow.xaml.cs
Normal file
25
Content.Client/Ghost/Roles/UI/GhostRolesWindow.xaml.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using Content.Shared.Ghost.Roles;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
|
||||
namespace Content.Client.Ghost.Roles.UI
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class GhostRolesWindow : SS14Window
|
||||
{
|
||||
public event Action<uint>? RoleRequested;
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
76
Content.Client/Ghost/Roles/UI/MakeGhostRoleEui.cs
Normal file
76
Content.Client/Ghost/Roles/UI/MakeGhostRoleEui.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Content.Client.Eui;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.Ghost.Roles;
|
||||
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.Ghost.Roles.UI
|
||||
{
|
||||
[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());
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Content.Client/Ghost/Roles/UI/MakeGhostRoleWindow.xaml
Normal file
26
Content.Client/Ghost/Roles/UI/MakeGhostRoleWindow.xaml
Normal file
@@ -0,0 +1,26 @@
|
||||
<SS14Window Title="Make Ghost Role"
|
||||
xmlns="https://spacestation14.io">
|
||||
|
||||
<VBoxContainer>
|
||||
<HBoxContainer>
|
||||
<Label Name="RoleEntityLabel" Text="Entity" />
|
||||
<Label Name="RoleEntity" Text="" />
|
||||
</HBoxContainer>
|
||||
<HBoxContainer>
|
||||
<Label Name="RoleNameLabel" Text="Role Name" />
|
||||
<LineEdit Name="RoleName" HorizontalExpand="True" />
|
||||
</HBoxContainer>
|
||||
<HBoxContainer>
|
||||
<Label Name="RoleDescriptionLabel" Text="Role Description" />
|
||||
<LineEdit Name="RoleDescription" HorizontalExpand="True" />
|
||||
</HBoxContainer>
|
||||
<HBoxContainer>
|
||||
<Label Name="MakeSentientLabel" Text="Make Sentient" />
|
||||
<CheckBox Name="MakeSentientCheckbox" />
|
||||
</HBoxContainer>
|
||||
<HBoxContainer>
|
||||
<Button Name="MakeButton" Text="Make" />
|
||||
</HBoxContainer>
|
||||
</VBoxContainer>
|
||||
|
||||
</SS14Window>
|
||||
49
Content.Client/Ghost/Roles/UI/MakeGhostRoleWindow.xaml.cs
Normal file
49
Content.Client/Ghost/Roles/UI/MakeGhostRoleWindow.xaml.cs
Normal 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.Ghost.Roles.UI
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class MakeGhostRoleWindow : SS14Window
|
||||
{
|
||||
public delegate void MakeRole(EntityUid uid, string name, string description, bool makeSentient);
|
||||
|
||||
public MakeGhostRoleWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
MakeSentientLabel.MinSize = (150, 0);
|
||||
RoleEntityLabel.MinSize = (150, 0);
|
||||
RoleNameLabel.MinSize = (150, 0);
|
||||
RoleName.MinSize = (300, 0);
|
||||
RoleDescriptionLabel.MinSize = (150, 0);
|
||||
RoleDescription.MinSize = (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user