private readonly ItemSlotsSystem _itemSlots;
private readonly FlatpackSystem _flatpack;
private readonly MaterialStorageSystem _materialStorage;
- private readonly SpriteSystem _spriteSystem;
private readonly EntityUid _owner;
public const string NoBoardEffectId = "FlatpackerNoBoardEffect";
private EntityUid? _currentBoard = EntityUid.Invalid;
- private EntityUid? _machinePreview;
public event Action? PackButtonPressed;
_itemSlots = _entityManager.System<ItemSlotsSystem>();
_flatpack = _entityManager.System<FlatpackSystem>();
_materialStorage = _entityManager.System<MaterialStorageSystem>();
- _spriteSystem = _entityManager.System<SpriteSystem>();
_owner = uid;
{
base.FrameUpdate(args);
- if (_machinePreview is not { } && _entityManager.Deleted(_machinePreview))
- {
- _machinePreview = null;
- MachineSprite.SetEntity(_machinePreview);
- }
-
if (!_entityManager.TryGetComponent<FlatpackCreatorComponent>(_owner, out var flatpacker) ||
!_itemSlots.TryGetSlot(_owner, flatpacker.SlotId, out var itemSlot))
return;
- MachineBoardComponent? machineBoardComp = null;
if (flatpacker.Packing)
{
PackButton.Disabled = true;
else if (_currentBoard != null)
{
Dictionary<string, int> cost;
- if (_entityManager.TryGetComponent(_currentBoard, out machineBoardComp))
+ if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoardComp))
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoardComp));
else
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker));
if (_currentBoard == itemSlot.Item)
return;
- if (_machinePreview != null)
- _entityManager.DeleteEntity(_machinePreview);
-
_currentBoard = itemSlot.Item;
CostHeaderLabel.Visible = _currentBoard != null;
InsertLabel.Visible = _currentBoard == null;
string? prototype = null;
Dictionary<string, int>? cost = null;
- if (machineBoardComp != null || _entityManager.TryGetComponent(_currentBoard, out machineBoardComp))
+ if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var newMachineBoardComp))
{
- prototype = machineBoardComp.Prototype;
- cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoardComp));
+ prototype = newMachineBoardComp.Prototype;
+ cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, newMachineBoardComp));
}
else if (_entityManager.TryGetComponent<ComputerBoardComponent>(_currentBoard, out var computerBoard))
{
if (prototype is not null && cost is not null)
{
var proto = _prototypeManager.Index<EntityPrototype>(prototype);
- _machinePreview = _entityManager.Spawn(proto.ID);
- _spriteSystem.ForceUpdate(_machinePreview.Value);
+ MachineSprite.SetPrototype(prototype);
MachineNameLabel.SetMessage(proto.Name);
CostLabel.SetMarkup(GetCostString(cost));
}
}
else
{
- _machinePreview = _entityManager.Spawn(NoBoardEffectId);
+ MachineSprite.SetPrototype(NoBoardEffectId);
CostLabel.SetMessage(Loc.GetString("flatpacker-ui-no-board-label"));
MachineNameLabel.SetMessage(" ");
PackButton.Disabled = true;
}
-
- MachineSprite.SetEntity(_machinePreview);
}
private string GetCostString(Dictionary<string, int> costs)
("amount", amountText),
("material", Loc.GetString(matProto.Name)));
- msg.AddMarkup(text);
+ msg.TryAddMarkup(text, out _);
if (i != orderedCosts.Length - 1)
msg.PushNewline();
return msg.ToMarkup();
}
-
- public override void Close()
- {
- base.Close();
-
- _entityManager.DeleteEntity(_machinePreview);
- _machinePreview = null;
- }
}