Make two inventories not dance around as much when opening/closing them (#35041)
* Make two inventories not dance around as much when opening/closing them * Use .Any
This commit is contained in:
committed by
GitHub
parent
c813891342
commit
8e24308714
@@ -9,12 +9,32 @@
|
||||
Orientation="Vertical"
|
||||
HorizontalAlignment="Center">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Name="StorageContainer"
|
||||
<BoxContainer Name="SingleStorageContainer"
|
||||
Access="Public"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalExpand="True"
|
||||
Margin="10">
|
||||
</BoxContainer>
|
||||
<BoxContainer Name="DoubleStorageContainer"
|
||||
Access="Public"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalExpand="True"
|
||||
Margin="10">
|
||||
<BoxContainer Name="LeftStorageContainer"
|
||||
Access="Public"
|
||||
HorizontalAlignment="Left"
|
||||
HorizontalExpand="True"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="10">
|
||||
</BoxContainer>
|
||||
<BoxContainer Name="RightStorageContainer"
|
||||
Access="Public"
|
||||
HorizontalAlignment="Right"
|
||||
HorizontalExpand="True"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="10">
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" Name="Hotbar" HorizontalAlignment="Center">
|
||||
<inventory:ItemSlotButtonContainer
|
||||
Name="SecondHotbar"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.Examine;
|
||||
using Content.Client.Hands.Systems;
|
||||
@@ -48,6 +49,7 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
|
||||
public Angle DraggingRotation = Angle.Zero;
|
||||
public bool StaticStorageUIEnabled;
|
||||
public bool OpaqueStorageWindow;
|
||||
private int _openStorageLimit = -1;
|
||||
|
||||
public bool IsDragging => _menuDragHelper.IsDragging;
|
||||
public ItemGridPiece? CurrentlyDragging => _menuDragHelper.Dragged;
|
||||
@@ -66,6 +68,12 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
|
||||
_configuration.OnValueChanged(CCVars.StaticStorageUI, OnStaticStorageChanged, true);
|
||||
_configuration.OnValueChanged(CCVars.OpaqueStorageWindow, OnOpaqueWindowChanged, true);
|
||||
_configuration.OnValueChanged(CCVars.StorageWindowTitle, OnStorageWindowTitle, true);
|
||||
_configuration.OnValueChanged(CCVars.StorageLimit, OnStorageLimitChanged, true);
|
||||
}
|
||||
|
||||
private void OnStorageLimitChanged(int obj)
|
||||
{
|
||||
_openStorageLimit = obj;
|
||||
}
|
||||
|
||||
private void OnStorageWindowTitle(bool obj)
|
||||
@@ -99,7 +107,43 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
|
||||
|
||||
if (StaticStorageUIEnabled)
|
||||
{
|
||||
UIManager.GetActiveUIWidgetOrNull<HotbarGui>()?.StorageContainer.AddChild(window);
|
||||
var hotbar = UIManager.GetActiveUIWidgetOrNull<HotbarGui>();
|
||||
// this lambda handles the nested storage case
|
||||
// during nested storage, a parent window hides and a child window is
|
||||
// immediately inserted to the end of the list
|
||||
// we can reorder the newly inserted to the same index as the invisible
|
||||
// window in order to prevent an invisible window from being replaced
|
||||
// with a visible one in a different position
|
||||
Action<Control?, Control> reorder = (parent, child) =>
|
||||
{
|
||||
if (parent is null)
|
||||
return;
|
||||
|
||||
var parentChildren = parent.Children.ToList();
|
||||
var invisibleIndex = parentChildren.FindIndex(c => c.Visible == false);
|
||||
if (invisibleIndex == -1)
|
||||
return;
|
||||
child.SetPositionInParent(invisibleIndex);
|
||||
};
|
||||
|
||||
if (_openStorageLimit == 2)
|
||||
{
|
||||
if (hotbar?.LeftStorageContainer.Children.Any(c => c.Visible) == false) // we're comparing booleans because it's bool? and not bool from the optional chaining
|
||||
{
|
||||
hotbar?.LeftStorageContainer.AddChild(window);
|
||||
reorder(hotbar?.LeftStorageContainer, window);
|
||||
}
|
||||
else
|
||||
{
|
||||
hotbar?.RightStorageContainer.AddChild(window);
|
||||
reorder(hotbar?.RightStorageContainer, window);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hotbar?.SingleStorageContainer.AddChild(window);
|
||||
reorder(hotbar?.SingleStorageContainer, window);
|
||||
}
|
||||
_closeRecentWindowUIController.SetMostRecentlyInteractedWindow(window);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -81,7 +81,7 @@ public sealed class StorageInteractionTest : InteractionTest
|
||||
{
|
||||
var uid = ToClient(target);
|
||||
var hotbar = GetWidget<HotbarGui>();
|
||||
var storageContainer = GetControlFromField<Control>(nameof(HotbarGui.StorageContainer), hotbar);
|
||||
var storageContainer = GetControlFromField<Control>(nameof(HotbarGui.SingleStorageContainer), hotbar);
|
||||
return GetControlFromChildren<ItemGridPiece>(c => c.Entity == uid, storageContainer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user