Adds a link limit and UI to device list (#11017)

* adds a link limit to device list

* locale strings

* uhhh what's efcore doing there

* adds a UI for device list on the device

* merge conflict fixing
This commit is contained in:
Flipp Syder
2022-09-05 18:22:39 -07:00
committed by GitHub
parent 8cbcf2d640
commit c3d7ecace6
12 changed files with 156 additions and 63 deletions

View File

@@ -75,8 +75,15 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
{
base.UpdateState(state);
var castState = (NetworkConfiguratorUserInterfaceState) state;
_listMenu?.UpdateState(castState);
switch (state)
{
case NetworkConfiguratorUserInterfaceState configState:
_listMenu?.UpdateState(configState);
break;
case DeviceListUserInterfaceState listState:
_configurationMenu?.UpdateState(listState);
break;
}
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message)

View File

@@ -1,7 +1,9 @@
<ui:FancyWindow xmlns="https://spacestation14.io"
xmlns:ui="clr-namespace:Content.Client.UserInterface"
xmlns:networkConfigurator="clr-namespace:Content.Client.NetworkConfigurator"
Title="Network Configurator" MinSize="350 100">
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True">
<networkConfigurator:NetworkConfiguratorDeviceList Name="DeviceList" MinHeight="500" />
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="8 8 8 1">
<Button Name="Set" Text="Set" Access="Public" ToolTip="{Loc 'network-configurator-tooltip-set'}" HorizontalExpand="True" StyleClasses="ButtonSquare"/>
<Button Name="Add" Text="Add" Access="Public" ToolTip="{Loc 'network-configurator-tooltip-add'}" HorizontalExpand="True" StyleClasses="ButtonSquare"/>
@@ -13,5 +15,6 @@
<Button Name="Copy" Text="Copy" Access="Public" ToolTip="{Loc 'network-configurator-tooltip-copy'}" HorizontalExpand="True" StyleClasses="OpenRight"/>
<Button Name="Show" Text="Show" Access="Public" ToggleMode="True" ToolTip="{Loc 'network-configurator-tooltip-show'}" HorizontalExpand="True" StyleClasses="ButtonSquare"/>
</BoxContainer>
<Label Name="Count" HorizontalAlignment="Right" />
</BoxContainer>
</ui:FancyWindow>

View File

@@ -1,5 +1,6 @@
using Content.Client.Stylesheets;
using Content.Client.UserInterface;
using Content.Shared.DeviceNetwork;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
@@ -11,7 +12,6 @@ namespace Content.Client.NetworkConfigurator;
[GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorConfigurationMenu : FancyWindow
{
public NetworkConfiguratorConfigurationMenu()
{
RobustXamlLoader.Load(this);
@@ -19,4 +19,11 @@ public sealed partial class NetworkConfiguratorConfigurationMenu : FancyWindow
Clear.StyleClasses.Add(StyleBase.ButtonOpenLeft);
Clear.StyleClasses.Add(StyleNano.StyleClassButtonColorRed);
}
public void UpdateState(DeviceListUserInterfaceState state)
{
DeviceList.UpdateState(null, state.DeviceList);
Count.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count));
}
}

View File

@@ -0,0 +1,9 @@
<ScrollContainer xmlns="https://spacestation14.io"
HorizontalExpand="True"
VerticalExpand="True">
<Control VerticalExpand="True">
<PanelContainer StyleClasses="PanelBackgroundBaseDark"></PanelContainer>
<BoxContainer Orientation="Vertical" Name="DeviceList" VerticalExpand="True" SeparationOverride="4">
</BoxContainer>
</Control>
</ScrollContainer>

View File

@@ -0,0 +1,58 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.NetworkConfigurator;
[GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorDeviceList : ScrollContainer
{
public void UpdateState(NetworkConfiguratorBoundUserInterface? ui, HashSet<(string address, string name)> devices)
{
DeviceList.RemoveAllChildren();
foreach (var device in devices)
{
DeviceList.AddChild(BuildDeviceListRow(ui, device));
}
}
private static BoxContainer BuildDeviceListRow(NetworkConfiguratorBoundUserInterface? ui, (string address, string name) savedDevice)
{
var row = new BoxContainer()
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
Margin = new Thickness(8)
};
var name = new Label()
{
Text = savedDevice.name[..Math.Min(11, savedDevice.name.Length)],
SetWidth = 84
};
var address = new Label()
{
Text = savedDevice.address,
HorizontalExpand = true,
Align = Label.AlignMode.Center
};
var removeButton = new TextureButton()
{
StyleClasses = { "CrossButtonRed" },
VerticalAlignment = VAlignment.Center,
Scale = new Vector2(0.5f, 0.5f)
};
row.AddChild(name);
row.AddChild(address);
if (ui != null)
{
row.AddChild(removeButton);
removeButton.OnPressed += _ => ui.OnRemoveButtonPressed(savedDevice.address);
}
return row;
}
}

View File

@@ -1,14 +1,9 @@
<ui:FancyWindow xmlns="https://spacestation14.io"
xmlns:ui="clr-namespace:Content.Client.UserInterface"
xmlns:networkConfigurator="clr-namespace:Content.Client.NetworkConfigurator"
Title="Network Configurator" MinSize="220 400">
<BoxContainer Orientation="Vertical" VerticalExpand="True">
<ScrollContainer HorizontalExpand="True" VerticalExpand="True">
<Control VerticalExpand="True">
<PanelContainer StyleClasses="PanelBackgroundBaseDark"></PanelContainer>
<BoxContainer Orientation="Vertical" Name="DeviceList" VerticalExpand="True" SeparationOverride="4">
</BoxContainer>
</Control>
</ScrollContainer>
<networkConfigurator:NetworkConfiguratorDeviceList Name="DeviceList" />
<BoxContainer Orientation="Horizontal" Margin="8 8 8 8">
<Label Name="DeviceCountLabel" Margin="16 0 0 0" MaxWidth="64"></Label>
<Control HorizontalExpand="True" />

View File

@@ -20,48 +20,6 @@ public sealed partial class NetworkConfiguratorListMenu : FancyWindow
public void UpdateState(NetworkConfiguratorUserInterfaceState state)
{
DeviceCountLabel.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count));
DeviceList.RemoveAllChildren();
foreach (var savedDevice in state.DeviceList)
{
DeviceList.AddChild(BuildDeviceListRow(savedDevice));
}
}
private BoxContainer BuildDeviceListRow((string address, string name) savedDevice)
{
var row = new BoxContainer()
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
Margin = new Thickness(8)
};
var name = new Label()
{
Text = savedDevice.name[..Math.Min(11, savedDevice.name.Length)],
SetWidth = 84
};
var address = new Label()
{
Text = savedDevice.address,
HorizontalExpand = true,
Align = Label.AlignMode.Center
};
var removeButton = new TextureButton()
{
StyleClasses = { "CrossButtonRed" },
VerticalAlignment = VAlignment.Center,
Scale = new Vector2(0.5f, 0.5f)
};
removeButton.OnPressed += _ => _ui.OnRemoveButtonPressed(savedDevice.address);
row.AddChild(name);
row.AddChild(address);
row.AddChild(removeButton);
return row;
DeviceList.UpdateState(_ui, state.DeviceList);
}
}