-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ports #987
Ports #987
Changes from all commits
60b9bff
9b48013
657b154
88a7642
d7cc749
97187a6
df65820
e540400
4cb71ca
ee2638c
e8bb962
99771cb
ff7ba06
63299a4
f31fa76
cc32f29
f36b0e7
f1266f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.Backmen.Medical.SmartFridge; | ||||||||||||||||||||||||||||||||||||||||
using SmartFridgeMenu = Content.Client.Backmen.Medical.SmartFridge.UI.SmartFridgeMenu; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
namespace Content.Client.Backmen.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(); | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Отписка от события OnItemSelected Необходимо отписаться от события при закрытии интерфейса во избежание утечек памяти. protected override void Open()
{
base.Open();
_menu = this.CreateWindow<SmartFridgeMenu>();
_menu.OpenCenteredLeft();
_menu.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
_menu.OnItemSelected += OnItemSelected;
Refresh();
}
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+ if (_menu != null)
+ {
+ _menu.OnItemSelected -= OnItemSelected;
+ }
+ } 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
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)); | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Content.Shared.Backmen.Medical.SmartFridge; | ||
using SmartFridgeComponent = Content.Shared.Backmen.Medical.SmartFridge.SmartFridgeComponent; | ||
|
||
namespace Content.Client.Backmen.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(); | ||
} | ||
} | ||
} |
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> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||||||||||||||||||||||||||||
using Content.Client.UserInterface.Controls; | ||||||||||||||||||||||||||||||||
using Content.Client.VendingMachines.UI; | ||||||||||||||||||||||||||||||||
using Content.Shared.Backmen.Medical.SmartFridge; | ||||||||||||||||||||||||||||||||
using Robust.Client.UserInterface.XAML; | ||||||||||||||||||||||||||||||||
using Robust.Client.UserInterface; | ||||||||||||||||||||||||||||||||
using Robust.Shared.Prototypes; | ||||||||||||||||||||||||||||||||
using Robust.Client.AutoGenerated; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
namespace Content.Client.Backmen.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 = []; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Очистка dummy-сущностей Необходимо реализовать очистку dummy-сущностей при уничтожении окна. private readonly Dictionary<EntProtoId, EntityUid> _dummies = [];
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+ if (disposing)
+ {
+ foreach (var dummy in _dummies.Values)
+ {
+ _entityManager.DeleteEntity(dummy);
+ }
+ _dummies.Clear();
+ }
+ } 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
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); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Добавить обработку ошибок при создании сущностей Необходимо добавить обработку ошибок при создании dummy-сущностей. -dummy = _entityManager.Spawn(entry.Id);
-_dummies.Add(entry.Id, dummy);
+try
+{
+ dummy = _entityManager.Spawn(entry.Id);
+ _dummies.Add(entry.Id, dummy);
+}
+catch (Exception ex)
+{
+ Logger.ErrorS("smartfridge", ex, $"Failed to spawn dummy entity for {entry.Id}");
+ continue;
+} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
var itemText = $"{entry.ItemName} [{entry.Quantity}]"; | ||||||||||||||||||||||||||||||||
listData.Add(new VendorItemsListData(prototype.ID, itemText, i)); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
VendingContents.PopulateList(listData); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Необходимо очистить кэш при закрытии интерфейса
Кэшированный инвентарь может привести к утечке памяти, так как список никогда не очищается.