Various item status fixes/tweaks (#27267)

* Always display item status panel fully

Initial feedback from the UI changes seems to be that a lot of people go "why is there empty space" so let's fix that.

* Fix item status middle hand being on the wrong side

I think I switched this around when fixing the left/right being inverted in the UI code.

* Minor status panel UI tweaks

Bottom-align contents now that the panel itself doesn't dynamically expand, prevent weird gaps.

Clip contents for panel

* Fix clipping on implanters and network configurators.

Made them take less space. For implanters the name has to be cut off, which I did by adding a new ClipControl to achieve that in rich text.

* Update visibility of item status panels based on whether you have hands at all.

This avoids UI for borgs looking silly.

Added a new "HandUILocation" enum that doesn't have middle hands to avoid confusion in UI code.

* Use BulletRender for laser guns too.

Provides all the benefits like fixing layout overflow and allowing multi-line stuff. Looks great now.

This involved generalizing BulletRender a bit so it can be used for not-just-bullets.

* Fix geiger word wrapping if you're really fucked
This commit is contained in:
Pieter-Jan Briers
2024-04-24 16:01:31 +02:00
committed by GitHub
parent 38f490e5eb
commit 7b90c08a2c
16 changed files with 338 additions and 185 deletions

View File

@@ -0,0 +1,55 @@
using System.Numerics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.UserInterface.Controls;
/// <summary>
/// Pretends to child controls that there's infinite space.
/// This can be used to make something like a <see cref="RichTextLabel"/> clip instead of wrapping.
/// </summary>
public sealed class ClipControl : Control
{
private bool _clipHorizontal = true;
private bool _clipVertical = true;
public bool ClipHorizontal
{
get => _clipHorizontal;
set
{
_clipHorizontal = value;
InvalidateMeasure();
}
}
public bool ClipVertical
{
get => _clipVertical;
set
{
_clipVertical = value;
InvalidateMeasure();
}
}
protected override Vector2 MeasureOverride(Vector2 availableSize)
{
if (ClipHorizontal)
availableSize = availableSize with { X = float.PositiveInfinity };
if (ClipVertical)
availableSize = availableSize with { Y = float.PositiveInfinity };
return base.MeasureOverride(availableSize);
}
protected override Vector2 ArrangeOverride(Vector2 finalSize)
{
foreach (var child in Children)
{
child.Arrange(UIBox2.FromDimensions(Vector2.Zero, child.DesiredSize));
}
return finalSize;
}
}

View File

@@ -5,8 +5,11 @@ namespace Content.Client.UserInterface.Systems.Hands.Controls;
public sealed class HandButton : SlotControl
{
public HandLocation HandLocation { get; }
public HandButton(string handName, HandLocation handLocation)
{
HandLocation = handLocation;
Name = "hand_" + handName;
SlotName = handName;
SetBackground(handLocation);

View File

@@ -256,7 +256,8 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
_player.LocalSession?.AttachedEntity is { } playerEntity &&
_handsSystem.TryGetHand(playerEntity, handName, out var hand, _playerHandsComponent))
{
if (hand.Location == HandLocation.Left)
var foldedLocation = hand.Location.GetUILocation();
if (foldedLocation == HandUILocation.Left)
{
_statusHandLeft = handControl;
HandsGui.UpdatePanelEntityLeft(hand.HeldEntity);
@@ -268,7 +269,7 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
HandsGui.UpdatePanelEntityRight(hand.HeldEntity);
}
HandsGui.SetHighlightHand(hand.Location);
HandsGui.SetHighlightHand(foldedLocation);
}
}
@@ -299,11 +300,13 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
// If we don't have a status for this hand type yet, set it.
// This means we have status filled by default in most scenarios,
// otherwise the user'd need to switch hands to "activate" the hands the first time.
if (location == HandLocation.Left)
if (location.GetUILocation() == HandUILocation.Left)
_statusHandLeft ??= button;
else
_statusHandRight ??= button;
UpdateVisibleStatusPanels();
return button;
}
@@ -369,9 +372,30 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
_handLookup.Remove(handName);
handButton.Dispose();
UpdateVisibleStatusPanels();
return true;
}
private void UpdateVisibleStatusPanels()
{
var leftVisible = false;
var rightVisible = false;
foreach (var hand in _handLookup.Values)
{
if (hand.HandLocation.GetUILocation() == HandUILocation.Left)
{
leftVisible = true;
}
else
{
rightVisible = true;
}
}
HandsGui?.UpdateStatusVisibility(leftVisible, rightVisible);
}
public string RegisterHandContainer(HandsContainer handContainer)
{
var name = "HandContainer_" + _backupSuffix;

View File

@@ -32,7 +32,7 @@
Name="StatusPanelRight"
HorizontalAlignment="Center" Margin="0 0 -2 2"
SetWidth="125"
MaxHeight="60"/>
SetHeight="60"/>
<hands:HandsContainer
Name="HandContainer"
Access="Public"
@@ -43,7 +43,7 @@
Name="StatusPanelLeft"
HorizontalAlignment="Center" Margin="-2 0 0 2"
SetWidth="125"
MaxHeight="60"/>
SetHeight="60"/>
<inventory:ItemSlotButtonContainer
Name="MainHotbar"
SlotGroup="MainHotbar"

View File

@@ -11,8 +11,8 @@ public sealed partial class HotbarGui : UIWidget
public HotbarGui()
{
RobustXamlLoader.Load(this);
StatusPanelRight.SetSide(HandLocation.Right);
StatusPanelLeft.SetSide(HandLocation.Left);
StatusPanelRight.SetSide(HandUILocation.Right);
StatusPanelLeft.SetSide(HandUILocation.Left);
var hotbarController = UserInterfaceManager.GetUIController<HotbarUIController>();
hotbarController.Setup(HandContainer, StoragePanel);
@@ -29,9 +29,15 @@ public sealed partial class HotbarGui : UIWidget
StatusPanelRight.Update(entity);
}
public void SetHighlightHand(HandLocation? hand)
public void SetHighlightHand(HandUILocation? hand)
{
StatusPanelLeft.UpdateHighlight(hand is HandLocation.Left);
StatusPanelRight.UpdateHighlight(hand is HandLocation.Middle or HandLocation.Right);
StatusPanelLeft.UpdateHighlight(hand is HandUILocation.Left);
StatusPanelRight.UpdateHighlight(hand is HandUILocation.Right);
}
public void UpdateStatusVisibility(bool left, bool right)
{
StatusPanelLeft.Visible = left;
StatusPanelRight.Visible = right;
}
}

View File

@@ -4,25 +4,26 @@
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
VerticalAlignment="Bottom"
HorizontalAlignment="Center">
<Control Name="VisWrapper" Visible="False">
<PanelContainer Name="Panel">
<PanelContainer.PanelOverride>
<graphics:StyleBoxTexture
PatchMarginBottom="4"
PatchMarginTop="6"
TextureScale="2 2"
Mode="Tile"/>
</PanelContainer.PanelOverride>
</PanelContainer>
<PanelContainer Name="HighlightPanel">
<PanelContainer.PanelOverride>
<graphics:StyleBoxTexture PatchMarginBottom="4" PatchMarginTop="6" TextureScale="2 2">
</graphics:StyleBoxTexture>
</PanelContainer.PanelOverride>
</PanelContainer>
<BoxContainer Name="Contents" Orientation="Vertical" Margin="0 6 0 4">
<BoxContainer Name="StatusContents" Orientation="Vertical" />
<Label Name="ItemNameLabel" ClipText="True" StyleClasses="ItemStatus" Align="Left" />
</BoxContainer>
</Control>
<PanelContainer Name="Panel">
<PanelContainer.PanelOverride>
<graphics:StyleBoxTexture
PatchMarginBottom="4"
PatchMarginTop="6"
TextureScale="2 2"
Mode="Tile"/>
</PanelContainer.PanelOverride>
</PanelContainer>
<PanelContainer Name="HighlightPanel">
<PanelContainer.PanelOverride>
<graphics:StyleBoxTexture PatchMarginBottom="4" PatchMarginTop="6" TextureScale="2 2">
</graphics:StyleBoxTexture>
</PanelContainer.PanelOverride>
</PanelContainer>
<BoxContainer Name="Contents" Orientation="Vertical" Margin="0 6 0 4" RectClipContent="True">
<BoxContainer Name="StatusContents" Orientation="Vertical" VerticalExpand="True" VerticalAlignment="Bottom" />
<Control>
<Label Name="NoItemLabel" ClipText="True" StyleClasses="ItemStatusNotHeld" Align="Left" Text="{Loc 'item-status-not-held'}" />
<Label Name="ItemNameLabel" ClipText="True" StyleClasses="ItemStatus" Align="Left" Visible="False" />
</Control>
</BoxContainer>
</controls:ItemStatusPanel>

View File

@@ -1,17 +1,13 @@
using System.Numerics;
using Content.Client.Items;
using Content.Client.Resources;
using Content.Shared.Hands.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Inventory.VirtualItem;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using static Content.Client.IoC.StaticIoC;
namespace Content.Client.UserInterface.Systems.Inventory.Controls;
@@ -23,17 +19,15 @@ public sealed partial class ItemStatusPanel : Control
[ViewVariables] private EntityUid? _entity;
// Tracked so we can re-run SetSide() if the theme changes.
private HandLocation _side;
private HandUILocation _side;
public ItemStatusPanel()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
SetSide(HandLocation.Middle);
}
public void SetSide(HandLocation location)
public void SetSide(HandUILocation location)
{
// AN IMPORTANT REMINDER ABOUT THIS CODE:
// In the UI, the RIGHT hand is on the LEFT on the screen.
@@ -47,15 +41,14 @@ public sealed partial class ItemStatusPanel : Control
switch (location)
{
case HandLocation.Right:
case HandUILocation.Right:
texture = Theme.ResolveTexture("item_status_right");
textureHighlight = Theme.ResolveTexture("item_status_right_highlight");
cutOut = StyleBox.Margin.Left;
flat = StyleBox.Margin.Right;
contentMargin = MarginFromThemeColor("_itemstatus_content_margin_right");
break;
case HandLocation.Middle:
case HandLocation.Left:
case HandUILocation.Left:
texture = Theme.ResolveTexture("item_status_left");
textureHighlight = Theme.ResolveTexture("item_status_left_highlight");
cutOut = StyleBox.Margin.Right;
@@ -104,11 +97,14 @@ public sealed partial class ItemStatusPanel : Control
public void Update(EntityUid? entity)
{
ItemNameLabel.Visible = entity != null;
NoItemLabel.Visible = entity == null;
if (entity == null)
{
ItemNameLabel.Text = "";
ClearOldStatus();
_entity = null;
VisWrapper.Visible = false;
return;
}
@@ -119,8 +115,6 @@ public sealed partial class ItemStatusPanel : Control
UpdateItemName();
}
VisWrapper.Visible = true;
}
public void UpdateHighlight(bool highlight)