Исправлен ранний выход при обновлении списка ингредиентов (deleted entity теперь пропускается, а не прерывает весь цикл).
Вынесена логика получения иконки сущности в отдельный helper для обоих BUI. Убраны неиспользуемые поля/using и упрощена обработка выбора времени в MicrowaveBoundUserInterface.
This commit is contained in:
parent
560d78176c
commit
e45d57914c
2 changed files with 47 additions and 54 deletions
|
|
@ -1,11 +1,9 @@
|
|||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Kitchen.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.Kitchen.UI
|
||||
{
|
||||
|
|
@ -18,9 +16,6 @@ namespace Content.Client.Kitchen.UI
|
|||
[ViewVariables]
|
||||
private readonly Dictionary<int, EntityUid> _solids = new();
|
||||
|
||||
[ViewVariables]
|
||||
private readonly Dictionary<int, ReagentQuantity> _reagents = new();
|
||||
|
||||
//Sunrise-Start
|
||||
private readonly string _menuTitle;
|
||||
private readonly string _leftFlavorText;
|
||||
|
|
@ -52,16 +47,13 @@ namespace Content.Client.Kitchen.UI
|
|||
SendPredictedMessage(new MicrowaveEjectSolidIndexedMessage(EntMan.GetNetEntity(_solids[args.ItemIndex])));
|
||||
};
|
||||
|
||||
_menu.OnCookTimeSelected += (args, buttonIndex) =>
|
||||
_menu.OnCookTimeSelected += (args, _) =>
|
||||
{
|
||||
var selectedCookTime = (uint) 0;
|
||||
|
||||
if (args.Button is MicrowaveMenu.MicrowaveCookTimeButton microwaveCookTimeButton)
|
||||
if (args.Button is MicrowaveMenu.MicrowaveCookTimeButton actualButton)
|
||||
{
|
||||
// args.Button is a MicrowaveCookTimeButton
|
||||
var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button;
|
||||
selectedCookTime = actualButton.CookTime == 0 ? 0 : actualButton.CookTime;
|
||||
// SendMessage(new MicrowaveSelectCookTimeMessage((int) selectedCookTime / 5, actualButton.CookTime));
|
||||
selectedCookTime = actualButton.CookTime;
|
||||
SendPredictedMessage(new MicrowaveSelectCookTimeMessage((int) selectedCookTime / 5, actualButton.CookTime));
|
||||
|
||||
_menu.CookTimeInfoLabel.Text = Loc.GetString("microwave-bound-user-interface-cook-time-label",
|
||||
|
|
@ -133,8 +125,6 @@ namespace Content.Client.Kitchen.UI
|
|||
|
||||
private void RefreshContentsDisplay(EntityUid[] containedSolids)
|
||||
{
|
||||
_reagents.Clear();
|
||||
|
||||
if (_menu == null) return;
|
||||
|
||||
_solids.Clear();
|
||||
|
|
@ -142,30 +132,36 @@ namespace Content.Client.Kitchen.UI
|
|||
foreach (var entity in containedSolids)
|
||||
{
|
||||
if (EntMan.Deleted(entity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO just use sprite view
|
||||
|
||||
Texture? texture;
|
||||
if (EntMan.TryGetComponent<IconComponent>(entity, out var iconComponent))
|
||||
{
|
||||
texture = EntMan.System<SpriteSystem>().GetIcon(iconComponent);
|
||||
}
|
||||
else if (EntMan.TryGetComponent<SpriteComponent>(entity, out var spriteComponent))
|
||||
{
|
||||
texture = spriteComponent.Icon?.Default;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!TryGetEntityTexture(entity, out var texture))
|
||||
continue;
|
||||
|
||||
var solidItem = _menu.IngredientsList.AddItem(EntMan.GetComponent<MetaDataComponent>(entity).EntityName, texture);
|
||||
var solidIndex = _menu.IngredientsList.IndexOf(solidItem);
|
||||
_solids.Add(solidIndex, entity);
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryGetEntityTexture(EntityUid entity, out Texture? texture)
|
||||
{
|
||||
// TODO just use sprite view
|
||||
if (EntMan.TryGetComponent<IconComponent>(entity, out var iconComponent))
|
||||
{
|
||||
texture = EntMan.System<SpriteSystem>().GetIcon(iconComponent);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (EntMan.TryGetComponent<SpriteComponent>(entity, out var spriteComponent))
|
||||
{
|
||||
texture = spriteComponent.Icon?.Default;
|
||||
return true;
|
||||
}
|
||||
|
||||
texture = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using Content.Shared._Sunrise.Kitchen.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Kitchen.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
|
@ -17,9 +16,6 @@ namespace Content.Client._Sunrise.Kitchen.UI
|
|||
[ViewVariables]
|
||||
private readonly Dictionary<int, EntityUid> _solids = new();
|
||||
|
||||
[ViewVariables]
|
||||
private readonly Dictionary<int, ReagentQuantity> _reagents = new();
|
||||
|
||||
private readonly string _menuTitle;
|
||||
private readonly string _leftFlavorText;
|
||||
|
||||
|
|
@ -67,9 +63,6 @@ namespace Content.Client._Sunrise.Kitchen.UI
|
|||
// TODO move this to a component state and ensure the net ids.
|
||||
RefreshContentsDisplay(EntMan.GetEntityArray(cState.ContainedSolids));
|
||||
|
||||
//Set the cook time info label
|
||||
var cookTime = cState.CurrentCookTime.ToString();
|
||||
|
||||
_menu.CookTimeInfoLabel.Text = Loc.GetString("assembler-bound-user-interface-insert-ingredients");
|
||||
_menu.StartButton.Disabled = cState.IsMicrowaveBusy || cState.ContainedSolids.Length == 0;
|
||||
_menu.EjectButton.Disabled = cState.IsMicrowaveBusy || cState.ContainedSolids.Length == 0;
|
||||
|
|
@ -87,8 +80,6 @@ namespace Content.Client._Sunrise.Kitchen.UI
|
|||
|
||||
private void RefreshContentsDisplay(EntityUid[] containedSolids)
|
||||
{
|
||||
_reagents.Clear();
|
||||
|
||||
if (_menu == null) return;
|
||||
|
||||
_solids.Clear();
|
||||
|
|
@ -96,30 +87,36 @@ namespace Content.Client._Sunrise.Kitchen.UI
|
|||
foreach (var entity in containedSolids)
|
||||
{
|
||||
if (EntMan.Deleted(entity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO just use sprite view
|
||||
|
||||
Texture? texture;
|
||||
if (EntMan.TryGetComponent<IconComponent>(entity, out var iconComponent))
|
||||
{
|
||||
texture = EntMan.System<SpriteSystem>().GetIcon(iconComponent);
|
||||
}
|
||||
else if (EntMan.TryGetComponent<SpriteComponent>(entity, out var spriteComponent))
|
||||
{
|
||||
texture = spriteComponent.Icon?.Default;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!TryGetEntityTexture(entity, out var texture))
|
||||
continue;
|
||||
|
||||
var solidItem = _menu.IngredientsList.AddItem(EntMan.GetComponent<MetaDataComponent>(entity).EntityName, texture);
|
||||
var solidIndex = _menu.IngredientsList.IndexOf(solidItem);
|
||||
_solids.Add(solidIndex, entity);
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryGetEntityTexture(EntityUid entity, out Texture? texture)
|
||||
{
|
||||
// TODO just use sprite view
|
||||
if (EntMan.TryGetComponent<IconComponent>(entity, out var iconComponent))
|
||||
{
|
||||
texture = EntMan.System<SpriteSystem>().GetIcon(iconComponent);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (EntMan.TryGetComponent<SpriteComponent>(entity, out var spriteComponent))
|
||||
{
|
||||
texture = spriteComponent.Icon?.Default;
|
||||
return true;
|
||||
}
|
||||
|
||||
texture = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue