Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port "Centered UI" from Emberfall #2622

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public DefaultGameScreen()
SetAnchorPreset(ViewportContainer, LayoutPreset.Wide);
SetAnchorAndMarginPreset(TopLeft, LayoutPreset.TopLeft, margin: 10);
SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80);
SetAnchorAndMarginPreset(Inventory, LayoutPreset.BottomLeft, margin: 5);
SetAnchorAndMarginPreset(Inventory, LayoutPreset.BottomWide, margin: 75); // Emberfall
SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);
SetAnchorAndMarginPreset(Chat, LayoutPreset.TopRight, margin: 10);
SetAnchorAndMarginPreset(Alerts, LayoutPreset.TopRight, margin: 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public SeparatedChatGameScreen()
SetAnchorPreset(ScreenContainer, LayoutPreset.Wide);
SetAnchorPreset(ViewportContainer, LayoutPreset.Wide);
SetAnchorPreset(MainViewport, LayoutPreset.Wide);
SetAnchorAndMarginPreset(Inventory, LayoutPreset.BottomLeft, margin: 5);
SetAnchorAndMarginPreset(Inventory, LayoutPreset.BottomWide, margin: 75); // Emberfall
SetAnchorAndMarginPreset(TopLeftContainer, LayoutPreset.TopLeft, margin: 10);
SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80);
SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,26 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
private StrippingWindow? _strippingWindow;
private ItemSlotButtonContainer? _inventoryHotbar;
private SlotButton? _inventoryButton;
private MenuButton? InventoryButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.InventoryButton; // Emberfall

private SlotControl? _lastHovered;

public override void Initialize()
{
base.Initialize();

var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
gameplayStateLoad.OnScreenLoad += OnScreenLoad;
}

private void OnScreenLoad()
{
if (UIManager.ActiveScreen == null)
return;

if (UIManager.GetActiveUIWidgetOrNull<InventoryGui>() is { } inventoryGui)
RegisterInventoryButton(inventoryGui.InventoryButton);
}
// public override void Initialize()
// {
// base.Initialize();
//
// var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
// gameplayStateLoad.OnScreenLoad += OnScreenLoad;
// }

// private void OnScreenLoad()
// {
// if (UIManager.ActiveScreen == null)
// return;
//
// if (UIManager.GetActiveUIWidgetOrNull<InventoryGui>() is { } inventoryGui)
// RegisterInventoryButton(inventoryGui.InventoryButton);
// }

public void OnStateEntered(GameplayState state)
{
Expand All @@ -75,6 +76,29 @@ public void OnStateEntered(GameplayState state)
.Register<ClientInventorySystem>();
}

// Begin Emberfall changes
public void UnloadButton()
{
if (InventoryButton == null)
return;

InventoryButton.OnPressed -= ActionButtonPressed;
}

public void LoadButton()
{
if (InventoryButton == null)
return;

InventoryButton.OnPressed += ActionButtonPressed;
}

private void ActionButtonPressed(BaseButton.ButtonEventArgs args)
{
ToggleInventoryBar();
}
// End Emberfall

public void OnStateExited(GameplayState state)
{
if (_strippingWindow != null)
Expand Down Expand Up @@ -171,35 +195,20 @@ private void UpdateInventoryHotbar(InventorySlotsComponent? clientInv)
_inventoryHotbar.RemoveChild(child);
}

var maxWidth = clothing.Max(p => p.Value.ButtonOffset.X) + 1;
var maxIndex = clothing.Select(p => GetIndex(p.Value.ButtonOffset)).Max();

_inventoryHotbar.MaxColumns = maxWidth;
_inventoryHotbar.Columns = maxWidth;

for (var i = 0; i <= maxIndex; i++)
foreach (var (key, data) in clothing) // Begin Emberfall
{
var index = i;
if (clothing.FirstOrNull(p => GetIndex(p.Value.ButtonOffset) == index) is { } pair)
{
if (_inventoryHotbar.TryGetButton(pair.Key, out var slot))
slot.SetPositionLast();
}
else
if (!_inventoryHotbar.TryGetButton(key, out var slot))
{
_inventoryHotbar.AddChild(new Control
{
MinSize = new Vector2(64, 64)
});
slot = CreateSlotButton(data);
_inventoryHotbar.AddButton(slot);
}
}

return;

int GetIndex(Vector2i position)
{
return position.Y * maxWidth + position.X;
var showStorage = _entities.HasComponent<StorageComponent>(data.HeldEntity);
var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage);
SpriteUpdated(update);
}

_inventoryHotbar.Columns = clothing.Count; // end Emberfall
}

private void UpdateStrippingWindow(InventorySlotsComponent? clientInv)
Expand Down Expand Up @@ -251,6 +260,7 @@ public void ToggleInventoryBar()
var shouldBeVisible = !_inventoryHotbar.Visible;
_inventoryHotbar.Visible = shouldBeVisible;

InventoryButton?.SetClickPressed(shouldBeVisible); // Emberfall
}

// Neuron Activation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
<widgets:InventoryGui
xmlns="https://spacestation14.io"
xmlns:inventory="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Controls"
xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Widgets"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Name="InventoryInterface"
VerticalExpand="True"
VerticalAlignment="Bottom"
Orientation="Horizontal"
HorizontalAlignment="Center">
<Control HorizontalAlignment="Center">
<!-- Needs to default to invisible because if we attach to a non-slots entity this will never get unset -->
<controls:SlotButton
Name="InventoryButton"
Access="Public"
Visible="False"
VerticalAlignment="Bottom"
HorizontalExpand="False"
VerticalExpand="False"
ButtonTexturePath="Slots/toggle"/>
<inventory:ItemSlotButtonContainer
Name="InventoryHotbar"
Access="Public"
Visible="False"
MaxColumns="3"
SlotGroup="Default"
ExpandBackwards="True"
VerticalExpand="True"
HorizontalAlignment="Center"
/>
</Control>
xmlns="https://spacestation14.io"
xmlns:inventory="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Controls"
xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Widgets"
Name="InventoryInterface"
VerticalExpand="True"
VerticalAlignment="Bottom"
Orientation="Horizontal"
HorizontalAlignment="Center">
<inventory:ItemSlotButtonContainer
Name="InventoryHotbar"
Access="Public"
Visible="False"
Columns="12"
MaxColumns="12"
SlotGroup="Default"
VerticalExpand="False"
HorizontalExpand="True"
HorizontalAlignment="Center"
/>
</widgets:InventoryGui>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Client.UserInterface.Systems.EscapeMenu;
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Client.UserInterface.Systems.Guidebook;
using Content.Client.UserInterface.Systems.Inventory; // Emberfall
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.Client.UserInterface.Systems.Sandbox;
using Robust.Client.UserInterface.Controllers;
Expand All @@ -24,6 +25,7 @@ public sealed class GameTopMenuBarUIController : UIController
[Dependency] private readonly SandboxUIController _sandbox = default!;
[Dependency] private readonly GuidebookUIController _guidebook = default!;
[Dependency] private readonly EmotesUIController _emotes = default!;
[Dependency] private readonly InventoryUIController _inventory = default!; // Emberfall

private GameTopMenuBar? GameTopMenuBar => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>();

Expand All @@ -47,6 +49,7 @@ public void UnloadButtons()
_action.UnloadButton();
_sandbox.UnloadButton();
_emotes.UnloadButton();
_inventory.UnloadButton(); // Emberfall
}

public void LoadButtons()
Expand All @@ -60,5 +63,6 @@ public void LoadButtons()
_action.LoadButton();
_sandbox.LoadButton();
_emotes.LoadButton();
_inventory.LoadButton(); // Emberfall
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
/>
<!-- Emberfall - Bring back the old UI -->
<ui:MenuButton
Name="InventoryButton"
Access="Internal"
Icon="{xe:Tex '/Textures/Interface/inventory.svg.192dpi.png'}"
ToolTip="{Loc 'game-hud-open-inventory-menu-button-tooltip'}"
BoundKey = "{x:Static is:ContentKeyFunctions.OpenInventoryMenu}"
MinSize="42 64"
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"/>
<ui:MenuButton
Name="EmotesButton"
Access="Internal"
Expand Down
Loading