forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* SmartCringe * JustCringe
- Loading branch information
Showing
10 changed files
with
608 additions
and
20 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
Content.Client/_CorvaxNext/Medical/SmartFridge/SmartFridgeBoundUserInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Content.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface; | ||
using Robust.Shared.Input; | ||
using System.Linq; | ||
using Content.Shared._CorvaxNext.Medical.SmartFridge; | ||
using SmartFridgeMenu = Content.Client._CorvaxNext.Medical.SmartFridge.UI.SmartFridgeMenu; | ||
|
||
namespace Content.Client._CorvaxNext.Medical.SmartFridge; | ||
|
||
public sealed class SmartFridgeBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey) | ||
{ | ||
[ViewVariables] | ||
private SmartFridgeMenu? _menu; | ||
|
||
[ViewVariables] | ||
private List<SmartFridgeInventoryItem> _cachedInventory = []; | ||
|
||
protected override void Open() | ||
{ | ||
base.Open(); | ||
|
||
_menu = this.CreateWindow<SmartFridgeMenu>(); | ||
_menu.OpenCenteredLeft(); | ||
_menu.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName; | ||
_menu.OnItemSelected += OnItemSelected; | ||
Refresh(); | ||
} | ||
|
||
public void Refresh() | ||
{ | ||
var system = EntMan.System<SmartFridgeSystem>(); | ||
_cachedInventory = system.GetInventoryClient(Owner); | ||
|
||
_menu?.Populate(_cachedInventory); | ||
} | ||
|
||
private void OnItemSelected(GUIBoundKeyEventArgs args, ListData data) | ||
{ | ||
if (args.Function != EngineKeyFunctions.UIClick) | ||
return; | ||
|
||
if (data is not VendorItemsListData { ItemIndex: var itemIndex }) | ||
return; | ||
|
||
if (_cachedInventory.Count == 0) | ||
return; | ||
|
||
var selectedItem = _cachedInventory.ElementAtOrDefault(itemIndex); | ||
|
||
if (selectedItem == null) | ||
return; | ||
|
||
SendMessage(new SmartFridgeEjectMessage(selectedItem.StorageSlotId)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Content.Client/_CorvaxNext/Medical/SmartFridge/SmartFridgeSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Content.Shared._CorvaxNext.Medical.SmartFridge; | ||
using SmartFridgeComponent = Content.Shared._CorvaxNext.Medical.SmartFridge.SmartFridgeComponent; | ||
|
||
namespace Content.Client._CorvaxNext.Medical.SmartFridge; | ||
|
||
public sealed class SmartFridgeSystem : SharedSmartFridgeSystem | ||
{ | ||
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<SmartFridgeComponent, AfterAutoHandleStateEvent>(OnVendingAfterState); | ||
} | ||
|
||
private void OnVendingAfterState(EntityUid uid, SmartFridgeComponent component, ref AfterAutoHandleStateEvent args) | ||
{ | ||
if (_uiSystem.TryGetOpenUi<SmartFridgeBoundUserInterface>(uid, SmartFridgeUiKey.Key, out var bui)) | ||
{ | ||
bui.Refresh(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Content.Client/_CorvaxNext/Medical/SmartFridge/UI/SmartFridgeMenu.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<controls:FancyWindow | ||
xmlns="https://spacestation14.io" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
xmlns:co="clr-namespace:Content.Client.UserInterface.Controls" | ||
MinSize="350,300" | ||
SetSize="400,400" | ||
Title="{Loc 'smart-fridge-title'}"> | ||
|
||
<PanelContainer StyleClasses="WindowPanel"> | ||
<BoxContainer Name="MainContainer" Orientation="Vertical" Margin="10"> | ||
<BoxContainer Orientation="Vertical" Margin="0 0 0 8"> | ||
<Label Text="{Loc 'smart-fridge-search'}:" Margin="0 0 0 5" HorizontalAlignment="Center"/> | ||
<LineEdit Name="SearchBar" PlaceHolder="{Loc 'vending-machine-component-search-filter'}" HorizontalExpand="True"/> | ||
</BoxContainer> | ||
|
||
<PanelContainer StyleClasses="WindowPanelInner" Margin="0 0 0 8" VerticalExpand="True"> | ||
<BoxContainer Orientation="Vertical" Name="ContentPanel" Margin="10" VerticalExpand="True"> | ||
<co:SearchListContainer Name="VendingContents" VerticalExpand="True"/> | ||
<Label Name="OutOfStockLabel" | ||
Text="{Loc 'vending-machine-component-try-eject-out-of-stock'}" | ||
Margin="4" | ||
HorizontalExpand="True" | ||
HorizontalAlignment="Center" | ||
Visible="False"/> | ||
</BoxContainer> | ||
</PanelContainer> | ||
|
||
<PanelContainer StyleClasses="LowDivider" Margin="0 8 0 0"/> | ||
<BoxContainer Orientation="Horizontal" Margin="0 4 0 0" VerticalAlignment="Bottom"> | ||
<Label Text="{Loc 'vending-machine-flavor-left'}" StyleClasses="WindowFooterText" Margin="0 0 10 0"/> | ||
<Label Text="{Loc 'vending-machine-flavor-right'}" StyleClasses="WindowFooterText" | ||
HorizontalAlignment="Right" HorizontalExpand="True" Margin="0 0 5 0"/> | ||
<TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered" | ||
VerticalAlignment="Center" HorizontalAlignment="Right" SetSize="24 24"/> | ||
</BoxContainer> | ||
</BoxContainer> | ||
</PanelContainer> | ||
</controls:FancyWindow> |
86 changes: 86 additions & 0 deletions
86
Content.Client/_CorvaxNext/Medical/SmartFridge/UI/SmartFridgeMenu.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System.Numerics; | ||
using Content.Client.UserInterface.Controls; | ||
using Content.Client.VendingMachines.UI; | ||
using Content.Shared._CorvaxNext.Medical.SmartFridge; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Client.UserInterface; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Client._CorvaxNext.Medical.SmartFridge.UI; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class SmartFridgeMenu : FancyWindow | ||
{ | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
[Dependency] private readonly IEntityManager _entityManager = default!; | ||
|
||
private readonly Dictionary<EntProtoId, EntityUid> _dummies = []; | ||
|
||
public event Action<GUIBoundKeyEventArgs, ListData>? OnItemSelected; | ||
|
||
public SmartFridgeMenu() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
|
||
VendingContents.SearchBar = SearchBar; | ||
VendingContents.DataFilterCondition += DataFilterCondition; | ||
VendingContents.GenerateItem += GenerateButton; | ||
VendingContents.ItemKeyBindDown += (args, data) => OnItemSelected?.Invoke(args, data); | ||
} | ||
|
||
private static bool DataFilterCondition(string filter, ListData data) | ||
{ | ||
if (data is not VendorItemsListData { ItemText: var text }) | ||
return false; | ||
|
||
return string.IsNullOrEmpty(filter) || text.Contains(filter, StringComparison.CurrentCultureIgnoreCase); | ||
} | ||
|
||
private void GenerateButton(ListData data, ListContainerButton button) | ||
{ | ||
if (data is not VendorItemsListData { ItemProtoID: var protoId, ItemText: var text }) | ||
return; | ||
|
||
button.AddChild(new VendingMachineItem(protoId, text)); | ||
button.ToolTip = text; | ||
} | ||
|
||
public void Populate(List<SmartFridgeInventoryItem> inventory) | ||
{ | ||
if (inventory.Count == 0) | ||
{ | ||
SearchBar.Visible = false; | ||
VendingContents.Visible = false; | ||
OutOfStockLabel.Visible = true; | ||
return; | ||
} | ||
|
||
SearchBar.Visible = true; | ||
VendingContents.Visible = true; | ||
OutOfStockLabel.Visible = false; | ||
|
||
var listData = new List<VendorItemsListData>(); | ||
|
||
for (var i = 0; i < inventory.Count; i++) | ||
{ | ||
var entry = inventory[i]; | ||
|
||
if (!_prototypeManager.TryIndex(entry.Id, out var prototype)) | ||
continue; | ||
|
||
if (!_dummies.TryGetValue(entry.Id, out var dummy)) | ||
{ | ||
dummy = _entityManager.Spawn(entry.Id); | ||
_dummies.Add(entry.Id, dummy); | ||
} | ||
|
||
var itemText = $"{entry.ItemName} [{entry.Quantity}]"; | ||
listData.Add(new VendorItemsListData(prototype.ID, itemText, i)); | ||
} | ||
|
||
VendingContents.PopulateList(listData); | ||
} | ||
} |
Oops, something went wrong.