Local Material Silo (#36492)
* Material Silo * fix board, fix copyright * a bit of review.... for the vibe.... * a tiny bit of review * 4 spaced * sloths no good very tiny nitpick * fix ui flickers * oops * slightly lower range * Sloth Review --------- Co-authored-by: ScarKy0 <scarky0@onet.eu>
This commit is contained in:
@@ -127,12 +127,17 @@
|
||||
HorizontalExpand="True"
|
||||
Orientation="Vertical">
|
||||
<Label Text="{Loc 'lathe-menu-materials-title'}" Margin="5 5 5 5" HorizontalAlignment="Center"/>
|
||||
<BoxContainer
|
||||
Orientation="Vertical"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True">
|
||||
<ui:MaterialStorageControl Name="MaterialsList" SizeFlagsStretchRatio="8"/>
|
||||
</BoxContainer>
|
||||
<PanelContainer VerticalExpand="True">
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
|
||||
</PanelContainer.PanelOverride>
|
||||
<BoxContainer
|
||||
Orientation="Vertical"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True">
|
||||
<ui:MaterialStorageControl Name="MaterialsList" SizeFlagsStretchRatio="8"/>
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
|
||||
|
||||
6
Content.Client/Materials/OreSiloSystem.cs
Normal file
6
Content.Client/Materials/OreSiloSystem.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using Content.Shared.Materials.OreSilo;
|
||||
|
||||
namespace Content.Client.Materials;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public sealed class OreSiloSystem : SharedOreSiloSystem;
|
||||
@@ -2,7 +2,10 @@
|
||||
SizeFlagsStretchRatio="8"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
<BoxContainer Name="MaterialList" Orientation="Vertical">
|
||||
<Label Name="NoMatsLabel" Text="{Loc 'lathe-menu-no-materials-message'}" Align="Center"/>
|
||||
<BoxContainer Orientation="Vertical" VerticalExpand="True">
|
||||
<BoxContainer Name="MaterialList" Orientation="Vertical" VerticalExpand="True">
|
||||
<Label Name="NoMatsLabel" Text="{Loc 'lathe-menu-no-materials-message'}" HorizontalAlignment="Center" VerticalAlignment="Center" VerticalExpand="True"/>
|
||||
</BoxContainer>
|
||||
<Label Name="SiloLinkedLabel" Text="{Loc 'lathe-menu-silo-linked-message'}" StyleClasses="LabelSubText" Visible="False" HorizontalAlignment="Center"/>
|
||||
</BoxContainer>
|
||||
</ScrollContainer>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Materials;
|
||||
using Content.Shared.Materials.OreSilo;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
@@ -15,6 +16,7 @@ namespace Content.Client.Materials.UI;
|
||||
public sealed partial class MaterialStorageControl : ScrollContainer
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
private readonly MaterialStorageSystem _materialStorage;
|
||||
|
||||
private EntityUid? _owner;
|
||||
|
||||
@@ -24,6 +26,8 @@ public sealed partial class MaterialStorageControl : ScrollContainer
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_materialStorage = _entityManager.System<MaterialStorageSystem>();
|
||||
}
|
||||
|
||||
public void SetOwner(EntityUid owner)
|
||||
@@ -45,7 +49,8 @@ public sealed partial class MaterialStorageControl : ScrollContainer
|
||||
}
|
||||
|
||||
var canEject = materialStorage.CanEjectStoredMaterials;
|
||||
var mats = materialStorage.Storage;
|
||||
var mats = _materialStorage.GetStoredMaterials((_owner.Value, materialStorage));
|
||||
|
||||
if (_currentMaterials.Equals(mats))
|
||||
return;
|
||||
|
||||
@@ -89,5 +94,6 @@ public sealed partial class MaterialStorageControl : ScrollContainer
|
||||
|
||||
_currentMaterials = mats;
|
||||
NoMatsLabel.Visible = MaterialList.ChildCount == 1;
|
||||
SiloLinkedLabel.Visible = _entityManager.TryGetComponent<OreSiloClientComponent>(_owner.Value, out var client) && client.Silo != null;
|
||||
}
|
||||
}
|
||||
|
||||
34
Content.Client/Materials/UI/OreSiloBoundUserInterface.cs
Normal file
34
Content.Client/Materials/UI/OreSiloBoundUserInterface.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Content.Shared.Materials.OreSilo;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.Materials.UI;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class OreSiloBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
|
||||
{
|
||||
[ViewVariables]
|
||||
private OreSiloMenu? _menu;
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_menu = this.CreateWindow<OreSiloMenu>();
|
||||
_menu.SetEntity(Owner);
|
||||
|
||||
_menu.OnClientEntryPressed += netEnt =>
|
||||
{
|
||||
SendPredictedMessage(new ToggleOreSiloClientMessage(netEnt));
|
||||
};
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (state is not OreSiloBuiState msg)
|
||||
return;
|
||||
_menu?.Update(msg);
|
||||
}
|
||||
}
|
||||
42
Content.Client/Materials/UI/OreSiloMenu.xaml
Normal file
42
Content.Client/Materials/UI/OreSiloMenu.xaml
Normal file
@@ -0,0 +1,42 @@
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
xmlns:ui="clr-namespace:Content.Client.Materials.UI"
|
||||
Title="{Loc 'ore-silo-ui-title'}"
|
||||
MinSize="400 260"
|
||||
SetSize="400 460">
|
||||
<BoxContainer Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True"
|
||||
Margin="10 10 10 10">
|
||||
<BoxContainer VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
Orientation="Vertical"
|
||||
SizeFlagsStretchRatio="3">
|
||||
<Label Text="{Loc 'ore-silo-ui-label-clients'}" Margin="5 5 5 5" HorizontalAlignment="Center" StyleClasses="LabelKeyText"/>
|
||||
<PanelContainer VerticalExpand="True">
|
||||
<PanelContainer.PanelOverride>
|
||||
<graphics:StyleBoxFlat BackgroundColor="#1B1B1E" />
|
||||
</PanelContainer.PanelOverride>
|
||||
<ItemList Name="ClientList" SelectMode="Button" VerticalExpand="True"/>
|
||||
</PanelContainer>
|
||||
</BoxContainer>
|
||||
<BoxContainer VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
Orientation="Vertical"
|
||||
SizeFlagsStretchRatio="2">
|
||||
<Label Text="{Loc 'ore-silo-ui-label-mats'}" Margin="5 5 5 5" HorizontalAlignment="Center" StyleClasses="LabelKeyText"/>
|
||||
<PanelContainer VerticalExpand="True">
|
||||
<PanelContainer.PanelOverride>
|
||||
<graphics:StyleBoxFlat BackgroundColor="#1B1B1E" />
|
||||
</PanelContainer.PanelOverride>
|
||||
<BoxContainer
|
||||
Orientation="Vertical"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True">
|
||||
<ui:MaterialStorageControl Name="Materials"/>
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</controls:FancyWindow>
|
||||
64
Content.Client/Materials/UI/OreSiloMenu.xaml.cs
Normal file
64
Content.Client/Materials/UI/OreSiloMenu.xaml.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Linq;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Materials.OreSilo;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Materials.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class OreSiloMenu : FancyWindow
|
||||
{
|
||||
public event Action<NetEntity>? OnClientEntryPressed;
|
||||
|
||||
public OreSiloMenu()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
ClientList.OnItemSelected += args =>
|
||||
{
|
||||
var item = ClientList[args.ItemIndex];
|
||||
// a little bit of null suppression makes me feel great! :-)
|
||||
OnClientEntryPressed?.Invoke((NetEntity) item.Metadata!);
|
||||
};
|
||||
}
|
||||
|
||||
public void SetEntity(EntityUid uid)
|
||||
{
|
||||
Materials.SetOwner(uid);
|
||||
}
|
||||
|
||||
public void Update(OreSiloBuiState state)
|
||||
{
|
||||
var items = new List<ItemList.Item>();
|
||||
var orderedClients = state.Clients.OrderBy(t => t.Item3).ThenBy(t => t.Item1.Id);
|
||||
foreach (var (ent, _, _) in orderedClients)
|
||||
{
|
||||
items.Add(new ItemList.Item(ClientList)
|
||||
{
|
||||
Metadata = ent
|
||||
});
|
||||
}
|
||||
|
||||
ClientList.SetItems(items,
|
||||
(item1, item2) =>
|
||||
{
|
||||
var ent1 = (NetEntity) item1.Metadata!;
|
||||
var ent2 = (NetEntity) item2.Metadata!;
|
||||
return ent1.CompareTo(ent2);
|
||||
});
|
||||
|
||||
var entTextDict = state.Clients.Select(t => (t.Item1, t.Item2)).ToDictionary();
|
||||
using var enumerator = ClientList.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
if (enumerator.Current.Metadata is not NetEntity ent)
|
||||
continue;
|
||||
|
||||
if (entTextDict.TryGetValue(ent, out var text))
|
||||
enumerator.Current.Text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user