Flatpacker fixes (#28417)
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" VerticalExpand="True" Margin="10">
|
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" VerticalExpand="True" Margin="10">
|
||||||
<BoxContainer SizeFlagsStretchRatio="2" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
|
<BoxContainer SizeFlagsStretchRatio="2" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
|
||||||
<BoxContainer Orientation="Vertical">
|
<BoxContainer Orientation="Vertical">
|
||||||
<SpriteView Name="MachineSprite" Scale="4 4" HorizontalAlignment="Center" VerticalExpand="True" MinSize="128 128"/>
|
<EntityPrototypeView Name="MachineSprite" Scale="4 4" HorizontalAlignment="Center" VerticalExpand="True" MinSize="128 128"/>
|
||||||
<RichTextLabel Name="MachineNameLabel" HorizontalAlignment="Center" StyleClasses="LabelKeyText"/>
|
<RichTextLabel Name="MachineNameLabel" HorizontalAlignment="Center" StyleClasses="LabelKeyText"/>
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
<Control MinHeight="10"/>
|
<Control MinHeight="10"/>
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
private readonly ItemSlotsSystem _itemSlots;
|
private readonly ItemSlotsSystem _itemSlots;
|
||||||
private readonly FlatpackSystem _flatpack;
|
private readonly FlatpackSystem _flatpack;
|
||||||
private readonly MaterialStorageSystem _materialStorage;
|
private readonly MaterialStorageSystem _materialStorage;
|
||||||
private readonly SpriteSystem _spriteSystem;
|
|
||||||
|
|
||||||
private readonly EntityUid _owner;
|
private readonly EntityUid _owner;
|
||||||
|
|
||||||
@@ -31,7 +30,6 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
public const string NoBoardEffectId = "FlatpackerNoBoardEffect";
|
public const string NoBoardEffectId = "FlatpackerNoBoardEffect";
|
||||||
|
|
||||||
private EntityUid? _currentBoard = EntityUid.Invalid;
|
private EntityUid? _currentBoard = EntityUid.Invalid;
|
||||||
private EntityUid? _machinePreview;
|
|
||||||
|
|
||||||
public event Action? PackButtonPressed;
|
public event Action? PackButtonPressed;
|
||||||
|
|
||||||
@@ -43,7 +41,6 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
_itemSlots = _entityManager.System<ItemSlotsSystem>();
|
_itemSlots = _entityManager.System<ItemSlotsSystem>();
|
||||||
_flatpack = _entityManager.System<FlatpackSystem>();
|
_flatpack = _entityManager.System<FlatpackSystem>();
|
||||||
_materialStorage = _entityManager.System<MaterialStorageSystem>();
|
_materialStorage = _entityManager.System<MaterialStorageSystem>();
|
||||||
_spriteSystem = _entityManager.System<SpriteSystem>();
|
|
||||||
|
|
||||||
_owner = uid;
|
_owner = uid;
|
||||||
|
|
||||||
@@ -57,17 +54,10 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
{
|
{
|
||||||
base.FrameUpdate(args);
|
base.FrameUpdate(args);
|
||||||
|
|
||||||
if (_machinePreview is not { } && _entityManager.Deleted(_machinePreview))
|
|
||||||
{
|
|
||||||
_machinePreview = null;
|
|
||||||
MachineSprite.SetEntity(_machinePreview);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_entityManager.TryGetComponent<FlatpackCreatorComponent>(_owner, out var flatpacker) ||
|
if (!_entityManager.TryGetComponent<FlatpackCreatorComponent>(_owner, out var flatpacker) ||
|
||||||
!_itemSlots.TryGetSlot(_owner, flatpacker.SlotId, out var itemSlot))
|
!_itemSlots.TryGetSlot(_owner, flatpacker.SlotId, out var itemSlot))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MachineBoardComponent? machineBoardComp = null;
|
|
||||||
if (flatpacker.Packing)
|
if (flatpacker.Packing)
|
||||||
{
|
{
|
||||||
PackButton.Disabled = true;
|
PackButton.Disabled = true;
|
||||||
@@ -75,7 +65,7 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
else if (_currentBoard != null)
|
else if (_currentBoard != null)
|
||||||
{
|
{
|
||||||
Dictionary<string, int> cost;
|
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));
|
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoardComp));
|
||||||
else
|
else
|
||||||
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker));
|
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker));
|
||||||
@@ -86,9 +76,6 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
if (_currentBoard == itemSlot.Item)
|
if (_currentBoard == itemSlot.Item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_machinePreview != null)
|
|
||||||
_entityManager.DeleteEntity(_machinePreview);
|
|
||||||
|
|
||||||
_currentBoard = itemSlot.Item;
|
_currentBoard = itemSlot.Item;
|
||||||
CostHeaderLabel.Visible = _currentBoard != null;
|
CostHeaderLabel.Visible = _currentBoard != null;
|
||||||
InsertLabel.Visible = _currentBoard == null;
|
InsertLabel.Visible = _currentBoard == null;
|
||||||
@@ -98,10 +85,10 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
string? prototype = null;
|
string? prototype = null;
|
||||||
Dictionary<string, int>? cost = 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;
|
prototype = newMachineBoardComp.Prototype;
|
||||||
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, machineBoardComp));
|
cost = _flatpack.GetFlatpackCreationCost((_owner, flatpacker), (_currentBoard.Value, newMachineBoardComp));
|
||||||
}
|
}
|
||||||
else if (_entityManager.TryGetComponent<ComputerBoardComponent>(_currentBoard, out var computerBoard))
|
else if (_entityManager.TryGetComponent<ComputerBoardComponent>(_currentBoard, out var computerBoard))
|
||||||
{
|
{
|
||||||
@@ -112,21 +99,18 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
if (prototype is not null && cost is not null)
|
if (prototype is not null && cost is not null)
|
||||||
{
|
{
|
||||||
var proto = _prototypeManager.Index<EntityPrototype>(prototype);
|
var proto = _prototypeManager.Index<EntityPrototype>(prototype);
|
||||||
_machinePreview = _entityManager.Spawn(proto.ID);
|
MachineSprite.SetPrototype(prototype);
|
||||||
_spriteSystem.ForceUpdate(_machinePreview.Value);
|
|
||||||
MachineNameLabel.SetMessage(proto.Name);
|
MachineNameLabel.SetMessage(proto.Name);
|
||||||
CostLabel.SetMarkup(GetCostString(cost));
|
CostLabel.SetMarkup(GetCostString(cost));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_machinePreview = _entityManager.Spawn(NoBoardEffectId);
|
MachineSprite.SetPrototype(NoBoardEffectId);
|
||||||
CostLabel.SetMessage(Loc.GetString("flatpacker-ui-no-board-label"));
|
CostLabel.SetMessage(Loc.GetString("flatpacker-ui-no-board-label"));
|
||||||
MachineNameLabel.SetMessage(" ");
|
MachineNameLabel.SetMessage(" ");
|
||||||
PackButton.Disabled = true;
|
PackButton.Disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineSprite.SetEntity(_machinePreview);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetCostString(Dictionary<string, int> costs)
|
private string GetCostString(Dictionary<string, int> costs)
|
||||||
@@ -148,7 +132,7 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
("amount", amountText),
|
("amount", amountText),
|
||||||
("material", Loc.GetString(matProto.Name)));
|
("material", Loc.GetString(matProto.Name)));
|
||||||
|
|
||||||
msg.AddMarkup(text);
|
msg.TryAddMarkup(text, out _);
|
||||||
|
|
||||||
if (i != orderedCosts.Length - 1)
|
if (i != orderedCosts.Length - 1)
|
||||||
msg.PushNewline();
|
msg.PushNewline();
|
||||||
@@ -156,12 +140,4 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
|
|||||||
|
|
||||||
return msg.ToMarkup();
|
return msg.ToMarkup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Close()
|
|
||||||
{
|
|
||||||
base.Close();
|
|
||||||
|
|
||||||
_entityManager.DeleteEntity(_machinePreview);
|
|
||||||
_machinePreview = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user