Machine Linking Overhaul (#7160)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.MachineLinking;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Client.Graphics;
|
||||
|
||||
namespace Content.Client.MachineLinking.UI
|
||||
{
|
||||
@@ -11,25 +12,67 @@ namespace Content.Client.MachineLinking.UI
|
||||
public sealed partial class SignalPortSelectorMenu : DefaultWindow
|
||||
{
|
||||
private SignalPortSelectorBoundUserInterface _bui;
|
||||
private LinksRender links;
|
||||
|
||||
private ButtonGroup buttonGroup = new();
|
||||
|
||||
public SignalPortSelectorMenu(SignalPortSelectorBoundUserInterface boundUserInterface)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
_bui = boundUserInterface;
|
||||
links = new(ButtonContainerLeft, ButtonContainerRight);
|
||||
ContainerMiddle.AddChild(links);
|
||||
ButtonClear.OnPressed += _ => _bui.OnClearPressed();
|
||||
ButtonLinkDefault.OnPressed += _ => _bui.OnLinkDefaultPressed();
|
||||
}
|
||||
|
||||
public void UpdateState(SignalPortsState state)
|
||||
{
|
||||
ButtonContainer.Clear();
|
||||
foreach (var port in state.Ports)
|
||||
HeaderLeft.SetMessage(state.TransmitterName);
|
||||
ButtonContainerLeft.DisposeAllChildren();
|
||||
foreach (var port in state.TransmitterPorts)
|
||||
{
|
||||
var portBtn = new ItemList.Item(ButtonContainer)
|
||||
var portButton = new Button() { Text = port, ToggleMode = true, Group = buttonGroup };
|
||||
portButton.OnPressed += _ => _bui.OnTransmitterPortSelected(port);
|
||||
ButtonContainerLeft.AddChild(portButton);
|
||||
}
|
||||
|
||||
HeaderRight.SetMessage(state.ReceiverName);
|
||||
ButtonContainerRight.DisposeAllChildren();
|
||||
foreach (var port in state.ReceiverPorts)
|
||||
{
|
||||
var portButton = new Button() { Text = port, ToggleMode = true, Group = buttonGroup };
|
||||
portButton.OnPressed += _ => _bui.OnReceiverPortSelected(port);
|
||||
ButtonContainerRight.AddChild(portButton);
|
||||
}
|
||||
|
||||
links.Links = state.Links;
|
||||
}
|
||||
|
||||
private sealed class LinksRender : Control
|
||||
{
|
||||
public List<(int, int)> Links = new();
|
||||
public BoxContainer LeftButton;
|
||||
public BoxContainer RightButton;
|
||||
|
||||
public LinksRender(BoxContainer leftButton, BoxContainer rightButton)
|
||||
{
|
||||
LeftButton = leftButton;
|
||||
RightButton = rightButton;
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
var leftOffset = LeftButton.PixelPosition.Y;
|
||||
var rightOffset = RightButton.PixelPosition.Y;
|
||||
foreach (var (left, right) in Links)
|
||||
{
|
||||
Text = port.Key,
|
||||
Disabled = !port.Value
|
||||
};
|
||||
portBtn.OnSelected += _ => _bui.OnPortSelected(port.Key);
|
||||
ButtonContainer.Add(portBtn);
|
||||
var leftChild = LeftButton.GetChild(left);
|
||||
var rightChild = RightButton.GetChild(right);
|
||||
var y1 = leftChild.PixelPosition.Y + leftChild.PixelHeight / 2 + leftOffset;
|
||||
var y2 = rightChild.PixelPosition.Y + rightChild.PixelHeight / 2 + rightOffset;
|
||||
handle.DrawLine((0, y1), (PixelWidth, y2), Color.Cyan);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user