* Add shuttle interior drawing back Just do it per-tile she'll be right, at least it's done with 1 draw call. * Revamp shuttle console * Bunch of cleanup work * Lables sortito * dok * Pixel alignment and colours * Fix a bunch of drawing bugs * Shuttle map drawing * Drawing fixes * Map parallax working finally * weh * Commit all my stuff * mic * deez * Update everything * Xamlify everything * uh * Rudimentary blocker range * My enemies have succeeded * Bunch of changes to FTL * Heaps of cleanup * Fix FTL bugs * FTL * weewoo * FTL fallback * wew * weh * Basic FTL working * FTL working * FTL destination fixes * a * Exclusion zones * Fix drawing / FTL * Beacons working * Coordinates drawing * Fix unknown map names * Dorks beginning * State + docking cleanup start * Basic dock drawing * Bunch of drawing fixes * Batching / color fixes * Cleanup and beacons support * weh * weh * Begin pings * First draft at map objects * Map fixup * Faster drawing * Fix perf + FTL * Cached drawing * Fix drawing * Best I got * strips * Back to lists but with caching * Final optimisation * Fix dock bounds * Docking work * stinker * kobolds * Btns * Docking vis working * Fix docking pre-vis * canasses * Helldivers 2 * a * Array life * Fix * Fix TODOs * liltenhead feature club * dorking * Merge artifacts * Last-minute touchup
184 lines
5.2 KiB
C#
184 lines
5.2 KiB
C#
using System.Linq;
|
|
using System.Numerics;
|
|
using System.Text;
|
|
using Content.Shared.Shuttles.BUIStates;
|
|
using Content.Shared.Shuttles.Systems;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.Shuttles.UI;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class DockingScreen : BoxContainer
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
private readonly SharedShuttleSystem _shuttles;
|
|
|
|
/// <summary>
|
|
/// Stored by GridID then by docks
|
|
/// </summary>
|
|
public Dictionary<NetEntity, List<DockingPortState>> Docks = new();
|
|
|
|
/// <summary>
|
|
/// Store the dock buttons for the side buttons.
|
|
/// </summary>
|
|
private readonly Dictionary<NetEntity, Button> _ourDockButtons = new();
|
|
|
|
public event Action<NetEntity, NetEntity>? DockRequest;
|
|
public event Action<NetEntity>? UndockRequest;
|
|
|
|
public DockingScreen()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
_shuttles = _entManager.System<SharedShuttleSystem>();
|
|
|
|
DockingControl.OnViewDock += OnView;
|
|
DockingControl.DockRequest += (entity, netEntity) =>
|
|
{
|
|
DockRequest?.Invoke(entity, netEntity);
|
|
};
|
|
DockingControl.UndockRequest += entity =>
|
|
{
|
|
UndockRequest?.Invoke(entity);
|
|
};
|
|
}
|
|
|
|
private void OnView(NetEntity obj)
|
|
{
|
|
if (_ourDockButtons.TryGetValue(obj, out var viewed))
|
|
{
|
|
viewed.Pressed = true;
|
|
}
|
|
}
|
|
|
|
public void UpdateState(EntityUid? shuttle, DockingInterfaceState state)
|
|
{
|
|
Docks = state.Docks;
|
|
DockingControl.DockState = state;
|
|
DockingControl.GridEntity = shuttle;
|
|
BuildDocks(shuttle);
|
|
}
|
|
|
|
private void BuildDocks(EntityUid? shuttle)
|
|
{
|
|
DockingControl.BuildDocks(shuttle);
|
|
var currentDock = DockingControl.ViewedDock;
|
|
// DockedWith.DisposeAllChildren();
|
|
DockPorts.DisposeAllChildren();
|
|
_ourDockButtons.Clear();
|
|
|
|
if (shuttle == null)
|
|
{
|
|
DockingControl.SetViewedDock(null);
|
|
return;
|
|
}
|
|
|
|
var shuttleNent = _entManager.GetNetEntity(shuttle.Value);
|
|
|
|
if (!Docks.TryGetValue(shuttleNent, out var shuttleDocks) || shuttleDocks.Count <= 0)
|
|
return;
|
|
|
|
var dockText = new StringBuilder();
|
|
var buttonGroup = new ButtonGroup();
|
|
var idx = 0;
|
|
var selected = false;
|
|
|
|
// Build the dock buttons for our docks.
|
|
foreach (var dock in shuttleDocks)
|
|
{
|
|
idx++;
|
|
dockText.Clear();
|
|
dockText.Append(dock.Name);
|
|
|
|
var button = new Button()
|
|
{
|
|
Text = dockText.ToString(),
|
|
ToggleMode = true,
|
|
Group = buttonGroup,
|
|
Margin = new Thickness(0f, 3f),
|
|
};
|
|
|
|
button.OnMouseEntered += args =>
|
|
{
|
|
DockingControl.HighlightedDock = dock.Entity;
|
|
};
|
|
|
|
button.OnMouseExited += args =>
|
|
{
|
|
DockingControl.HighlightedDock = null;
|
|
};
|
|
|
|
button.Label.Margin = new Thickness(3f);
|
|
|
|
if (currentDock == dock.Entity)
|
|
{
|
|
selected = true;
|
|
button.Pressed = true;
|
|
}
|
|
|
|
button.OnPressed += args =>
|
|
{
|
|
OnDockPress(dock);
|
|
};
|
|
|
|
_ourDockButtons[dock.Entity] = button;
|
|
DockPorts.AddChild(button);
|
|
}
|
|
|
|
// Button group needs one selected so just show the first one.
|
|
if (!selected)
|
|
{
|
|
var buttonOne = shuttleDocks[0];
|
|
OnDockPress(buttonOne);
|
|
}
|
|
|
|
var shuttleContainers = new Dictionary<NetEntity, DockObject>();
|
|
|
|
foreach (var dock in shuttleDocks.OrderBy(x => x.GridDockedWith))
|
|
{
|
|
if (dock.GridDockedWith == null)
|
|
continue;
|
|
|
|
DockObject? dockContainer;
|
|
|
|
if (!shuttleContainers.TryGetValue(dock.GridDockedWith.Value, out dockContainer))
|
|
{
|
|
dockContainer = new DockObject();
|
|
shuttleContainers[dock.GridDockedWith.Value] = dockContainer;
|
|
var dockGrid = _entManager.GetEntity(dock.GridDockedWith);
|
|
string? iffLabel = null;
|
|
|
|
if (_entManager.EntityExists(dockGrid))
|
|
{
|
|
iffLabel = _shuttles.GetIFFLabel(dockGrid.Value);
|
|
}
|
|
|
|
iffLabel ??= Loc.GetString("shuttle-console-unknown");
|
|
dockContainer.SetName(iffLabel);
|
|
// DockedWith.AddChild(dockContainer);
|
|
}
|
|
|
|
dockContainer.AddDock(dock, DockingControl);
|
|
|
|
dockContainer.ViewPressed += () =>
|
|
{
|
|
OnDockPress(dock);
|
|
};
|
|
|
|
dockContainer.UndockPressed += () =>
|
|
{
|
|
UndockRequest?.Invoke(dock.Entity);
|
|
};
|
|
}
|
|
}
|
|
|
|
private void OnDockPress(DockingPortState state)
|
|
{
|
|
DockingControl.SetViewedDock(state);
|
|
}
|
|
}
|