<BoxContainer Orientation="Horizontal" HorizontalExpand="True" VerticalExpand="True" Margin="10">
<BoxContainer SizeFlagsStretchRatio="2" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Vertical">
- <SpriteView Name="MachineSprite" Scale="4 4" HorizontalAlignment="Center" MinSize="128 128"/>
+ <SpriteView Name="MachineSprite" Scale="4 4" HorizontalAlignment="Center" VerticalExpand="True" MinSize="128 128"/>
<RichTextLabel Name="MachineNameLabel" HorizontalAlignment="Center" StyleClasses="LabelKeyText"/>
</BoxContainer>
<Control MinHeight="10"/>
<Button Name="PackButton" Text="{Loc 'flatpacker-ui-pack-button'}" MaxWidth="150" Margin="0 0 0 10"/>
- <BoxContainer Orientation="Vertical" VerticalExpand="True">
+ <BoxContainer Orientation="Vertical" VerticalExpand="True" RectClipContent="True">
<Label Name="CostHeaderLabel" Text="{Loc 'flatpacker-ui-cost-label'}" HorizontalAlignment="Left"/>
<PanelContainer VerticalExpand="True"
HorizontalExpand="True">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
- <BoxContainer Orientation="Vertical" VerticalExpand="True">
- <RichTextLabel Name="CostLabel" HorizontalAlignment="Center"/>
+ <BoxContainer Orientation="Vertical" VerticalAlignment="Center">
+ <RichTextLabel Name="CostLabel" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+ <RichTextLabel Name="InsertLabel" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</BoxContainer>
</PanelContainer>
</BoxContainer>
private readonly EntityUid _owner;
+ [ValidatePrototypeId<EntityPrototype>]
+ public const string NoBoardEffectId = "FlatpackerNoBoardEffect";
+
private EntityUid? _currentBoard = EntityUid.Invalid;
private EntityUid? _machinePreview;
PackButton.OnPressed += _ => PackButtonPressed?.Invoke();
MaterialStorageControl.SetOwner(uid);
+ InsertLabel.SetMarkup(Loc.GetString("flatpacker-ui-insert-board"));
}
protected override void FrameUpdate(FrameEventArgs args)
!_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
_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))
{
}
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);
("material", Loc.GetString(matProto.Name)));
msg.AddMarkup(text);
- msg.PushNewline();
+
+ if (i != orderedCosts.Length - 1)
+ msg.PushNewline();
}
- msg.Pop();
return msg.ToMarkup();
}
using Content.Shared.Construction.Components;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Timing;
-using YamlDotNet.Serialization.NodeTypeResolvers;
namespace Content.Server.Construction;
Dictionary<string, int>? cost = null;
if (TryComp<MachineBoardComponent>(machineBoard, out var machineBoardComponent))
cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent));
- if (TryComp<ComputerBoardComponent>(machineBoard, out var computerBoardComponent))
+ if (HasComp<ComputerBoardComponent>(machineBoard))
cost = GetFlatpackCreationCost(ent);
if (cost is null)
Dictionary<string, int>? cost = null;
if (TryComp<MachineBoardComponent>(machineBoard, out var machineBoardComponent))
cost = GetFlatpackCreationCost(ent, (machineBoard, machineBoardComponent));
- if (TryComp<ComputerBoardComponent>(machineBoard, out var computerBoardComponent))
+ if (HasComp<ComputerBoardComponent>(machineBoard))
cost = GetFlatpackCreationCost(ent);
if (cost is null)
var flatpack = Spawn(comp.BaseFlatpackPrototype, Transform(ent).Coordinates);
SetupFlatpack(flatpack, machineBoard);
+ Del(machineBoard);
}
public override void Update(float frameTime)