Flatpacker Tweaks (#23552)

* flatpacker nerf

* stuff
This commit is contained in:
Nemanja
2024-01-05 00:01:24 -05:00
committed by GitHub
parent bb2a9eac45
commit a2cdbda019
5 changed files with 41 additions and 24 deletions

View File

@@ -27,6 +27,9 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
private readonly EntityUid _owner;
[ValidatePrototypeId<EntityPrototype>]
public const string NoBoardEffectId = "FlatpackerNoBoardEffect";
private EntityUid? _currentBoard = EntityUid.Invalid;
private EntityUid? _machinePreview;
@@ -47,6 +50,7 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
PackButton.OnPressed += _ => PackButtonPressed?.Invoke();
MaterialStorageControl.SetOwner(uid);
InsertLabel.SetMarkup(Loc.GetString("flatpacker-ui-insert-board"));
}
protected override void FrameUpdate(FrameEventArgs args)
@@ -63,15 +67,15 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
!_itemSlots.TryGetSlot(_owner, flatpacker.SlotId, out var itemSlot))
return;
MachineBoardComponent? machineBoardComp = null;
if (flatpacker.Packing)
{
PackButton.Disabled = true;
}
else if (_currentBoard != null)
{
//todo double trycomp is kinda stinky.
Dictionary<string, int> cost;
if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoardComp) &&
if (_entityManager.TryGetComponent(_currentBoard, out machineBoardComp) &&
machineBoardComp.Prototype is not null)
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoardComp));
else
@@ -88,16 +92,17 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
_currentBoard = itemSlot.Item;
CostHeaderLabel.Visible = _currentBoard != null;
InsertLabel.Visible = _currentBoard == null;
if (_currentBoard is not null)
{
string? prototype = null;
Dictionary<string, int>? cost = null;
if (_entityManager.TryGetComponent<MachineBoardComponent>(_currentBoard, out var machineBoard))
if (machineBoardComp != null || _entityManager.TryGetComponent(_currentBoard, out machineBoardComp))
{
prototype = machineBoard.Prototype;
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoard));
prototype = machineBoardComp.Prototype;
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoardComp));
}
else if (_entityManager.TryGetComponent<ComputerBoardComponent>(_currentBoard, out var computerBoard))
{
@@ -116,22 +121,23 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
}
else
{
_machinePreview = null;
MachineNameLabel.SetMessage(" ");
_machinePreview = _entityManager.Spawn(NoBoardEffectId);
CostLabel.SetMessage(Loc.GetString("flatpacker-ui-no-board-label"));
MachineNameLabel.SetMessage(" ");
PackButton.Disabled = true;
}
MachineSprite.SetEntity(_machinePreview);
}
//todo beautify
private string GetCostString(Dictionary<string, int> costs)
{
var orderedCosts = costs.OrderBy(p => p.Value);
var orderedCosts = costs.OrderBy(p => p.Value).ToArray();
var msg = new FormattedMessage();
foreach (var (mat, amount) in orderedCosts)
for (var i = 0; i < orderedCosts.Length; i++)
{
var (mat, amount) = orderedCosts[i];
var matProto = _prototypeManager.Index<MaterialPrototype>(mat);
var sheetVolume = _materialStorage.GetSheetVolume(matProto);
@@ -144,9 +150,10 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
("material", Loc.GetString(matProto.Name)));
msg.AddMarkup(text);
msg.PushNewline();
if (i != orderedCosts.Length - 1)
msg.PushNewline();
}
msg.Pop();
return msg.ToMarkup();
}