Ghost UI to XAML and minor cleanup (#4637)
* Remove unused class, clean up XAML * Move GhostGui.cs into UI folder and namespace * GhostTargetWindow to seperate file * GhostTargetWindow to XAML * Center request button * Improve UI, localisation
This commit is contained in:
73
Content.Client/Ghost/UI/GhostGui.cs
Normal file
73
Content.Client/Ghost/UI/GhostGui.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Content.Shared.Ghost;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Ghost.UI
|
||||
{
|
||||
public class GhostGui : Control
|
||||
{
|
||||
private readonly Button _returnToBody = new() {Text = Loc.GetString("ghost-gui-return-to-body-button") };
|
||||
private readonly Button _ghostWarp = new() {Text = Loc.GetString("ghost-gui-ghost-warp-button") };
|
||||
private readonly Button _ghostRoles = new() {Text = Loc.GetString("ghost-gui-ghost-roles-button") };
|
||||
private readonly GhostComponent _owner;
|
||||
|
||||
public GhostTargetWindow? TargetWindow { get; }
|
||||
|
||||
public GhostGui(GhostComponent owner, IEntityNetworkManager eventBus)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_owner = owner;
|
||||
|
||||
TargetWindow = new GhostTargetWindow(eventBus);
|
||||
|
||||
MouseFilter = MouseFilterMode.Ignore;
|
||||
|
||||
_ghostWarp.OnPressed += _ =>
|
||||
{
|
||||
eventBus.SendSystemNetworkMessage(new GhostWarpsRequestEvent());
|
||||
TargetWindow.Populate();
|
||||
TargetWindow.OpenCentered();
|
||||
};
|
||||
_returnToBody.OnPressed += _ =>
|
||||
{
|
||||
var msg = new GhostReturnToBodyRequest();
|
||||
eventBus.SendSystemNetworkMessage(msg);
|
||||
};
|
||||
_ghostRoles.OnPressed += _ => IoCManager.Resolve<IClientConsoleHost>()
|
||||
.RemoteExecuteCommand(null, "ghostroles");
|
||||
|
||||
AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
_returnToBody,
|
||||
_ghostWarp,
|
||||
_ghostRoles,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
_returnToBody.Disabled = !_owner.CanReturnToBody;
|
||||
TargetWindow?.Populate();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
TargetWindow?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Content.Client/Ghost/UI/GhostTargetWindow.xaml
Normal file
14
Content.Client/Ghost/UI/GhostTargetWindow.xaml
Normal file
@@ -0,0 +1,14 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'ghost-target-window-title'}"
|
||||
MinSize="300 450"
|
||||
SetSize="300 450">
|
||||
<ScrollContainer VerticalExpand="True"
|
||||
HorizontalExpand="True">
|
||||
<BoxContainer Name="ButtonContainer"
|
||||
Orientation="Vertical"
|
||||
VerticalExpand="True"
|
||||
SeparationOverride="5">
|
||||
<!-- Target buttons get added here by code -->
|
||||
</BoxContainer>
|
||||
</ScrollContainer>
|
||||
</SS14Window>
|
||||
85
Content.Client/Ghost/UI/GhostTargetWindow.xaml.cs
Normal file
85
Content.Client/Ghost/UI/GhostTargetWindow.xaml.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Ghost;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Client.Ghost.UI
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class GhostTargetWindow : SS14Window
|
||||
{
|
||||
private readonly IEntityNetworkManager _netManager;
|
||||
|
||||
public List<string> Locations { get; set; } = new();
|
||||
|
||||
public Dictionary<EntityUid, string> Players { get; set; } = new();
|
||||
|
||||
public GhostTargetWindow(IEntityNetworkManager netManager)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
_netManager = netManager;
|
||||
}
|
||||
|
||||
public void Populate()
|
||||
{
|
||||
ButtonContainer.DisposeAllChildren();
|
||||
AddButtonPlayers();
|
||||
AddButtonLocations();
|
||||
}
|
||||
|
||||
private void AddButtonPlayers()
|
||||
{
|
||||
foreach (var (key, value) in Players)
|
||||
{
|
||||
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 += (_) =>
|
||||
{
|
||||
var msg = new GhostWarpToTargetRequestEvent(key);
|
||||
_netManager.SendSystemNetworkMessage(msg);
|
||||
};
|
||||
|
||||
ButtonContainer.AddChild(currentButtonRef);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButtonLocations()
|
||||
{
|
||||
foreach (var name in Locations)
|
||||
{
|
||||
var currentButtonRef = new Button
|
||||
{
|
||||
Text = Loc.GetString("ghost-target-window-current-button", ("name", name)),
|
||||
TextAlign = Label.AlignMode.Right,
|
||||
HorizontalAlignment = HAlignment.Center,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
MinSize = (230, 20),
|
||||
ClipText = true,
|
||||
};
|
||||
|
||||
currentButtonRef.OnPressed += _ =>
|
||||
{
|
||||
var msg = new GhostWarpToLocationRequestEvent(name);
|
||||
_netManager.SendSystemNetworkMessage(msg);
|
||||
};
|
||||
|
||||
ButtonContainer.AddChild(currentButtonRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user