Use EntityUID for all ghost warps (#11113)

This commit is contained in:
Illiux
2022-09-10 14:47:17 -07:00
committed by GitHub
parent 4cc5fa239e
commit acd24bed4d
4 changed files with 77 additions and 138 deletions

View File

@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
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
{
@@ -17,9 +12,7 @@ namespace Content.Client.Ghost.UI
{
private readonly IEntityNetworkManager _netManager;
public List<string> Locations { get; set; } = new();
public Dictionary<EntityUid, string> Players { get; set; } = new();
private List<(string, EntityUid)> _warps = new();
public GhostTargetWindow(IEntityNetworkManager netManager)
{
@@ -28,58 +21,37 @@ namespace Content.Client.Ghost.UI
_netManager = netManager;
}
public void UpdateWarps(IEnumerable<GhostWarp> warps)
{
// Server COULD send these sorted but how about we just use the client to do it instead
_warps = warps
.OrderBy(w => w.IsWarpPoint)
.ThenBy(w => w.DisplayName, Comparer<string>.Create(
(x, y) => string.Compare(x, y, StringComparison.Ordinal)))
.Select(w =>
{
var name = w.IsWarpPoint
? Loc.GetString("ghost-target-window-current-button", ("name", w.DisplayName))
: w.DisplayName;
return (name, w.Entity);
})
.ToList();
}
public void Populate()
{
ButtonContainer.DisposeAllChildren();
AddButtonPlayers();
AddButtonLocations();
AddButtons();
}
private void AddButtonPlayers()
private void AddButtons()
{
var sortedPlayers = new List<(string, EntityUid)>(Players.Count);
foreach (var (key, player) in Players)
{
sortedPlayers.Add((player, key));
}
sortedPlayers.Sort((x, y) => string.Compare(x.Item1, y.Item1, StringComparison.Ordinal));
foreach (var (key, player) in sortedPlayers)
foreach (var (name, warp) in _warps)
{
var currentButtonRef = new Button
{
Text = key,
TextAlign = Label.AlignMode.Right,
HorizontalAlignment = HAlignment.Center,
VerticalAlignment = VAlignment.Center,
SizeFlagsStretchRatio = 1,
MinSize = (340, 20),
ClipText = true,
};
currentButtonRef.OnPressed += (_) =>
{
var msg = new GhostWarpToTargetRequestEvent(player);
_netManager.SendSystemNetworkMessage(msg);
};
ButtonContainer.AddChild(currentButtonRef);
}
}
private void AddButtonLocations()
{
// Server COULD send these sorted but how about we just use the client to do it instead.
var sortedLocations = new List<string>(Locations);
sortedLocations.Sort((x, y) => string.Compare(x, y, StringComparison.Ordinal));
foreach (var name in sortedLocations)
{
var currentButtonRef = new Button
{
Text = Loc.GetString("ghost-target-window-current-button", ("name", name)),
Text = name,
TextAlign = Label.AlignMode.Right,
HorizontalAlignment = HAlignment.Center,
VerticalAlignment = VAlignment.Center,
@@ -90,7 +62,7 @@ namespace Content.Client.Ghost.UI
currentButtonRef.OnPressed += _ =>
{
var msg = new GhostWarpToLocationRequestEvent(name);
var msg = new GhostWarpToTargetRequestEvent(warp);
_netManager.SendSystemNetworkMessage(msg);
};