mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description the adding AI is now up to y'all because i'm not touching loadout code for name datasets, but it shouldn't be too bad from here --------- Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> Signed-off-by: SolStar <44028047+ewokswagger@users.noreply.github.com> Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: themias <89101928+themias@users.noreply.github.com> Co-authored-by: Verm <32827189+Vermidia@users.noreply.github.com> Co-authored-by: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com> Co-authored-by: Sphiral <145869023+SphiraI@users.noreply.github.com> Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Alzore <140123969+Blackern5000@users.noreply.github.com> Co-authored-by: ravage <142820619+ravage123321@users.noreply.github.com> Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Co-authored-by: Intoxicating-Innocence <188202277+Intoxicating-Innocence@users.noreply.github.com> Co-authored-by: Saphire <lattice@saphi.re> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Errant <35878406+Errant-4@users.noreply.github.com> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: CaasGit <87243814+CaasGit@users.noreply.github.com> Co-authored-by: BramvanZijp <56019239+BramvanZijp@users.noreply.github.com> Co-authored-by: Boaz1111 <149967078+Boaz1111@users.noreply.github.com> Co-authored-by: NakataRin <45946146+NakataRin@users.noreply.github.com> Co-authored-by: Kara <lunarautomaton6@gmail.com> Co-authored-by: Plykiya <58439124+Plykiya@users.noreply.github.com> Co-authored-by: SlamBamActionman <slambamactionman@gmail.com> Co-authored-by: Doomsdrayk <robotdoughnut@comcast.net> Co-authored-by: Brandon Hu <103440971+Brandon-Huu@users.noreply.github.com> Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Co-authored-by: ElectroJr <leonsfriedrich@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Julian Giebel <juliangiebel@live.de> Co-authored-by: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com> Co-authored-by: Repo <47093363+Titian3@users.noreply.github.com> Co-authored-by: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com> Co-authored-by: icekot8 <93311212+icekot8@users.noreply.github.com> Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: no <165581243+pissdemon@users.noreply.github.com> Co-authored-by: Tornado Tech <54727692+Tornado-Technology@users.noreply.github.com> Co-authored-by: osjarw <62134478+osjarw@users.noreply.github.com> Co-authored-by: Simon <63975668+Simyon264@users.noreply.github.com> Co-authored-by: TGRCDev <tgrc@tgrc.dev> Co-authored-by: Milon <milonpl.git@proton.me> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Co-authored-by: Fildrance <fildrance@gmail.com> Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru> Co-authored-by: chavonadelal <156101927+chavonadelal@users.noreply.github.com> Co-authored-by: SolStar <44028047+ewokswagger@users.noreply.github.com> Co-authored-by: K-Dynamic <20566341+K-Dynamic@users.noreply.github.com> Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com> Co-authored-by: ArchRBX <5040911+ArchRBX@users.noreply.github.com> Co-authored-by: archrbx <punk.gear5260@fastmail.com> Co-authored-by: Radezolid <snappednexus@gmail.com> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Co-authored-by: EmoGarbage404 <retron404@gmail.com> Co-authored-by: MilenVolf <63782763+MilenVolf@users.noreply.github.com> Co-authored-by: Velcroboy <107660393+IamVelcroboy@users.noreply.github.com> Co-authored-by: Velcroboy <velcroboy333@hotmail.com> Co-authored-by: neuPanda <chriseparton@gmail.com> Co-authored-by: neuPanda <spainman0@yahoo.com> Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com> Co-authored-by: Whatstone <whatston3@gmail.com> Co-authored-by: VideoKompany <135313844+VlaDOS1408@users.noreply.github.com> (cherry picked from commit 93ed70acfeda357133a701f637d3faeec02749bb)
223 lines
7.5 KiB
C#
223 lines
7.5 KiB
C#
using System.Numerics;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.DeviceLinking;
|
|
using Content.Shared.DeviceNetwork;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.NetworkConfigurator;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class NetworkConfiguratorLinkMenu : FancyWindow
|
|
{
|
|
private const string PanelBgColor = "#202023";
|
|
|
|
private readonly LinksRender _links;
|
|
|
|
private readonly List<SourcePortPrototype> _sources = new();
|
|
|
|
private readonly List<SinkPortPrototype> _sinks = new();
|
|
|
|
private (ButtonPosition position, string id, int index)? _selectedButton;
|
|
|
|
private List<(string left, string right)>? _defaults;
|
|
|
|
public event Action? OnClearLinks;
|
|
public event Action<string, string>? OnToggleLink;
|
|
public event Action<List<(string left, string right)>>? OnLinkDefaults;
|
|
|
|
public NetworkConfiguratorLinkMenu()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
|
|
var footerStyleBox = new StyleBoxFlat()
|
|
{
|
|
BorderThickness = new Thickness(0, 2, 0, 0),
|
|
BorderColor = Color.FromHex("#5A5A5A")
|
|
};
|
|
|
|
FooterPanel.PanelOverride = footerStyleBox;
|
|
MainPanel.PanelOverride = new StyleBoxFlat(Color.FromHex(PanelBgColor));
|
|
|
|
ButtonClear.AddStyleClass("ButtonColorRed");
|
|
ButtonLinkDefault.Disabled = true;
|
|
|
|
_links = new LinksRender(ButtonContainerLeft, ButtonContainerRight);
|
|
_links.VerticalExpand = true;
|
|
MiddleContainer.AddChild(_links);
|
|
|
|
ButtonOk.OnPressed += _ => Close();
|
|
ButtonLinkDefault.OnPressed += _ => LinkDefaults();
|
|
ButtonClear.OnPressed += _ => OnClearLinks?.Invoke();
|
|
}
|
|
|
|
public void UpdateState(DeviceLinkUserInterfaceState linkState)
|
|
{
|
|
ButtonContainerLeft.RemoveAllChildren();
|
|
ButtonContainerRight.RemoveAllChildren();
|
|
|
|
_sources.Clear();
|
|
_sources.AddRange(linkState.Sources);
|
|
_links.SourceButtons.Clear();
|
|
var i = 0;
|
|
foreach (var source in _sources)
|
|
{
|
|
var button = CreateButton(ButtonPosition.Left, source.Name, source.Description, source.ID, i);
|
|
ButtonContainerLeft.AddChild(button);
|
|
_links.SourceButtons.Add(source.ID, button);
|
|
i++;
|
|
}
|
|
|
|
_sinks.Clear();
|
|
_sinks.AddRange(linkState.Sinks);
|
|
_links.SinkButtons.Clear();
|
|
i = 0;
|
|
foreach (var sink in _sinks)
|
|
{
|
|
var button = CreateButton(ButtonPosition.Right, sink.Name, sink.Description, sink.ID, i);
|
|
ButtonContainerRight.AddChild(button);
|
|
_links.SinkButtons.Add(sink.ID, button);
|
|
i++;
|
|
}
|
|
|
|
_links.Links.Clear();
|
|
_links.Links.AddRange(linkState.Links);
|
|
_defaults = linkState.Defaults;
|
|
|
|
ButtonLinkDefault.Disabled = _defaults == default;
|
|
FromAddressLabel.Text = linkState.SourceAddress;
|
|
ToAddressLabel.Text = linkState.SinkAddress;
|
|
}
|
|
|
|
private void LinkDefaults()
|
|
{
|
|
if (_defaults == default)
|
|
return;
|
|
|
|
OnLinkDefaults?.Invoke(_defaults);
|
|
}
|
|
|
|
private Button CreateButton(ButtonPosition position, string name, string description, string id, int index)
|
|
{
|
|
var button = new Button();
|
|
button.AddStyleClass("OpenBoth");
|
|
button.Text = Loc.GetString(name);
|
|
button.ToolTip = Loc.GetString(description);
|
|
button.ToggleMode = true;
|
|
button.OnPressed += args => OnButtonPressed(args, position, id, index);
|
|
return button;
|
|
}
|
|
|
|
private void OnButtonPressed(BaseButton.ButtonEventArgs args, ButtonPosition position, string id, int index)
|
|
{
|
|
var key = (position, id, index);
|
|
if (_selectedButton == key)
|
|
{
|
|
args.Button.Pressed = false;
|
|
_selectedButton = null;
|
|
return;
|
|
}
|
|
|
|
if (!_selectedButton.HasValue)
|
|
{
|
|
args.Button.Pressed = true;
|
|
_selectedButton = key;
|
|
return;
|
|
}
|
|
|
|
if (_selectedButton.Value.position == position)
|
|
{
|
|
args.Button.Pressed = false;
|
|
return;
|
|
}
|
|
|
|
var left = _selectedButton.Value.position == ButtonPosition.Left ? _selectedButton.Value.id : id;
|
|
var right = _selectedButton.Value.position == ButtonPosition.Left ? id : _selectedButton.Value.id;
|
|
|
|
OnToggleLink?.Invoke(left, right);
|
|
|
|
args.Button.Pressed = false;
|
|
|
|
var container = _selectedButton.Value.position == ButtonPosition.Left ? ButtonContainerLeft : ButtonContainerRight;
|
|
if (container.GetChild(_selectedButton.Value.index) is Button button)
|
|
button.Pressed = false;
|
|
|
|
_selectedButton = null;
|
|
}
|
|
|
|
private enum ButtonPosition
|
|
{
|
|
Left,
|
|
Right
|
|
}
|
|
|
|
/// <summary>
|
|
/// Draws lines between linked ports using bezier curve calculated with polynomial coefficients
|
|
/// See: https://youtu.be/jvPPXbo87ds?t=351
|
|
/// </summary>
|
|
private sealed class LinksRender : Control
|
|
{
|
|
public readonly List<(ProtoId<SourcePortPrototype>, ProtoId<SinkPortPrototype>)> Links = new();
|
|
public readonly Dictionary<string, Button> SourceButtons = new();
|
|
public readonly Dictionary<string, Button> SinkButtons = new();
|
|
private readonly BoxContainer _leftButtonContainer;
|
|
private readonly BoxContainer _rightButtonContainer;
|
|
|
|
public LinksRender(BoxContainer leftButtonContainer, BoxContainer rightButtonContainer)
|
|
{
|
|
_leftButtonContainer = leftButtonContainer;
|
|
_rightButtonContainer = rightButtonContainer;
|
|
}
|
|
|
|
protected override void Draw(DrawingHandleScreen handle)
|
|
{
|
|
foreach (var (left, right) in Links)
|
|
{
|
|
if (!SourceButtons.TryGetValue(left, out var leftChild) || !SinkButtons.TryGetValue(right, out var rightChild))
|
|
continue;
|
|
|
|
var leftOffset = _leftButtonContainer.PixelPosition.Y;
|
|
var rightOffset = _rightButtonContainer.PixelPosition.Y;
|
|
|
|
var y1 = leftChild.PixelPosition.Y + leftChild.PixelHeight / 2 + leftOffset;
|
|
var y2 = rightChild.PixelPosition.Y + rightChild.PixelHeight / 2 + rightOffset;
|
|
|
|
if (left == right)
|
|
{
|
|
handle.DrawLine(new Vector2(0, y1), new Vector2(PixelWidth, y2), Color.Cyan);
|
|
continue;
|
|
}
|
|
|
|
var controls = new List<Vector2>
|
|
{
|
|
new(0, y1),
|
|
new(30, y1),
|
|
new(PixelWidth - 30, y2),
|
|
new(PixelWidth, y2),
|
|
};
|
|
|
|
//Calculate coefficients
|
|
var c0 = controls[0];
|
|
var c1 = controls[0] * -3 + controls[1] * 3;
|
|
var c2 = controls[0] * 3 + controls[1] * -6 + controls[2] * 3;
|
|
var c3 = controls[0] * -1 + controls[1] * 3 + controls[2] * -3 + controls[3];
|
|
|
|
var points = new List<Vector2>();
|
|
|
|
//Calculate points using coefficients
|
|
for (float t = 0; t <= 1; t += 0.0001f)
|
|
{
|
|
var point = c0 + c1 * t + c2 * (t * t) + c3 * (t * t * t);
|
|
points.Add(point);
|
|
}
|
|
|
|
handle.DrawPrimitives(DrawPrimitiveTopology.LineStrip, points.ToArray(), Color.Cyan);
|
|
}
|
|
}
|
|
}
|
|
}
|