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"
|
Orientation="Vertical"
|
||||||
HorizontalAlignment="Center">
|
HorizontalAlignment="Center">
|
||||||
<BoxContainer Orientation="Vertical">
|
<BoxContainer Orientation="Vertical">
|
||||||
<BoxContainer Name="StorageContainer"
|
<BoxContainer Name="SingleStorageContainer"
|
||||||
Access="Public"
|
Access="Public"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
HorizontalExpand="True"
|
HorizontalExpand="True"
|
||||||
Margin="10">
|
Margin="10">
|
||||||
</BoxContainer>
|
</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">
|
<BoxContainer Orientation="Horizontal" Name="Hotbar" HorizontalAlignment="Center">
|
||||||
<inventory:ItemSlotButtonContainer
|
<inventory:ItemSlotButtonContainer
|
||||||
Name="SecondHotbar"
|
Name="SecondHotbar"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Content.Client.Examine;
|
using Content.Client.Examine;
|
||||||
using Content.Client.Hands.Systems;
|
using Content.Client.Hands.Systems;
|
||||||
@@ -48,6 +49,7 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
|
|||||||
public Angle DraggingRotation = Angle.Zero;
|
public Angle DraggingRotation = Angle.Zero;
|
||||||
public bool StaticStorageUIEnabled;
|
public bool StaticStorageUIEnabled;
|
||||||
public bool OpaqueStorageWindow;
|
public bool OpaqueStorageWindow;
|
||||||
|
private int _openStorageLimit = -1;
|
||||||
|
|
||||||
public bool IsDragging => _menuDragHelper.IsDragging;
|
public bool IsDragging => _menuDragHelper.IsDragging;
|
||||||
public ItemGridPiece? CurrentlyDragging => _menuDragHelper.Dragged;
|
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.StaticStorageUI, OnStaticStorageChanged, true);
|
||||||
_configuration.OnValueChanged(CCVars.OpaqueStorageWindow, OnOpaqueWindowChanged, true);
|
_configuration.OnValueChanged(CCVars.OpaqueStorageWindow, OnOpaqueWindowChanged, true);
|
||||||
_configuration.OnValueChanged(CCVars.StorageWindowTitle, OnStorageWindowTitle, 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)
|
private void OnStorageWindowTitle(bool obj)
|
||||||
@@ -99,7 +107,43 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
|
|||||||
|
|
||||||
if (StaticStorageUIEnabled)
|
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);
|
_closeRecentWindowUIController.SetMostRecentlyInteractedWindow(window);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public sealed class StorageInteractionTest : InteractionTest
|
|||||||
{
|
{
|
||||||
var uid = ToClient(target);
|
var uid = ToClient(target);
|
||||||
var hotbar = GetWidget<HotbarGui>();
|
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);
|
return GetControlFromChildren<ItemGridPiece>(c => c.Entity == uid, storageContainer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user