Item status!

This commit is contained in:
Pieter-Jan Briers
2020-01-09 00:27:52 +01:00
parent e984fc24b6
commit 411c23c46e
36 changed files with 1248 additions and 128 deletions

View File

@@ -214,11 +214,6 @@ namespace Content.Client.UserInterface
SizeFlagsVertical = Control.SizeFlags.ShrinkEnd
};
HandsContainer = new MarginContainer
{
SizeFlagsVertical = Control.SizeFlags.ShrinkEnd
};
_combatPanelContainer = new VBoxContainer
{
Children =
@@ -235,9 +230,20 @@ namespace Content.Client.UserInterface
_combatModeButton.OnToggled += args => OnCombatModeChanged?.Invoke(args.Pressed);
_targetingDoll.OnZoneChanged += args => OnTargetingZoneChanged?.Invoke(args);
inventoryContainer.Children.Add(HandsContainer);
inventoryContainer.Children.Add(InventoryQuickButtonContainer);
inventoryContainer.Children.Add(_combatPanelContainer);
HandsContainer = new MarginContainer
{
SizeFlagsVertical = Control.SizeFlags.ShrinkEnd
};
RootControl.AddChild(HandsContainer);
LayoutContainer.SetAnchorAndMarginPreset(HandsContainer, LayoutContainer.LayoutPreset.CenterBottom);
LayoutContainer.SetGrowHorizontal(HandsContainer, LayoutContainer.GrowDirection.Both);
LayoutContainer.SetGrowVertical(HandsContainer, LayoutContainer.GrowDirection.Begin);
}
private void ButtonTutorialOnOnToggled()

View File

@@ -23,9 +23,10 @@ namespace Content.Client.UserInterface
{
public class HandsGui : Control
{
private const string HandNameLeft = "left";
private const string HandNameRight = "right";
private const int CooldownLevels = 8;
private const int BoxSpacing = 0;
private const int BoxSize = 64;
#pragma warning disable 0649
[Dependency] private readonly IPlayerManager _playerManager;
@@ -40,8 +41,6 @@ namespace Content.Client.UserInterface
private IEntity LeftHand;
private IEntity RightHand;
private UIBox2i _handL;
private UIBox2i _handR;
private readonly SpriteView LeftSpriteView;
private readonly SpriteView RightSpriteView;
@@ -53,13 +52,13 @@ namespace Content.Client.UserInterface
private readonly Control _leftContainer;
private readonly Control _rightContainer;
private readonly ItemStatusPanel _rightStatusPanel;
private readonly ItemStatusPanel _leftStatusPanel;
public HandsGui()
{
IoCManager.InjectDependencies(this);
_handR = new UIBox2i(0, 0, BoxSize, BoxSize);
_handL = _handR.Translated((BoxSize + BoxSpacing, 0));
MouseFilter = MouseFilterMode.Stop;
TextureHandLeft = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/hand_l.png");
@@ -73,30 +72,37 @@ namespace Content.Client.UserInterface
_resourceCache.GetTexture($"/Textures/UserInterface/Inventory/cooldown-{i}.png");
}
_rightStatusPanel = new ItemStatusPanel(true);
_leftStatusPanel = new ItemStatusPanel(false);
_leftContainer = new Control {MouseFilter = MouseFilterMode.Ignore};
_rightContainer = new Control {MouseFilter = MouseFilterMode.Ignore};
var hBox = new HBoxContainer
{
SeparationOverride = 0,
Children = {_rightContainer, _leftContainer},
Children = {_rightStatusPanel, _rightContainer, _leftContainer, _leftStatusPanel},
MouseFilter = MouseFilterMode.Ignore
};
AddChild(hBox);
_leftContainer.AddChild(new TextureRect
var textureLeft = new TextureRect
{
MouseFilter = MouseFilterMode.Ignore,
Texture = TextureHandLeft,
TextureScale = (2, 2)
});
};
textureLeft.OnKeyBindDown += args => HandKeyBindDown(args, HandNameLeft);
_rightContainer.AddChild(new TextureRect
_leftContainer.AddChild(textureLeft);
var textureRight = new TextureRect
{
MouseFilter = MouseFilterMode.Ignore,
Texture = TextureHandRight,
TextureScale = (2, 2)
});
};
textureRight.OnKeyBindDown += args => HandKeyBindDown(args, HandNameRight);
_rightContainer.AddChild(textureRight);
_leftContainer.AddChild(ActiveHandRect = new TextureRect
{
@@ -127,6 +133,7 @@ namespace Content.Client.UserInterface
SizeFlagsHorizontal = SizeFlags.ShrinkCenter,
SizeFlagsVertical = SizeFlags.ShrinkCenter,
MouseFilter = MouseFilterMode.Ignore,
Stretch = TextureRect.StretchMode.KeepCentered,
TextureScale = (2, 2),
Visible = false,
});
@@ -136,6 +143,7 @@ namespace Content.Client.UserInterface
SizeFlagsHorizontal = SizeFlags.ShrinkCenter,
SizeFlagsVertical = SizeFlags.ShrinkCenter,
MouseFilter = MouseFilterMode.Ignore,
Stretch = TextureRect.StretchMode.KeepCentered,
TextureScale = (2, 2),
Visible = false
});
@@ -166,12 +174,13 @@ namespace Content.Client.UserInterface
if (!TryGetHands(out var hands))
return;
var left = hands.GetEntity("left");
var right = hands.GetEntity("right");
var left = hands.GetEntity(HandNameLeft);
var right = hands.GetEntity(HandNameRight);
ActiveHandRect.Parent.RemoveChild(ActiveHandRect);
var parent = hands.ActiveIndex == "left" ? _leftContainer : _rightContainer;
var parent = hands.ActiveIndex == HandNameLeft ? _leftContainer : _rightContainer;
parent.AddChild(ActiveHandRect);
ActiveHandRect.SetPositionInParent(1);
if (left != null)
{
@@ -230,43 +239,13 @@ namespace Content.Client.UserInterface
hands.AttackByInHand(hand);
}
protected override bool HasPoint(Vector2 point)
private void HandKeyBindDown(GUIBoundKeyEventArgs args, string handIndex)
{
return _handL.Contains((Vector2i) point) || _handR.Contains((Vector2i) point);
}
protected override void KeyBindDown(GUIBoundKeyEventArgs args)
{
base.KeyBindDown(args);
if (!args.CanFocus)
{
return;
}
var leftHandContains = _handL.Contains((Vector2i) args.RelativePosition);
var rightHandContains = _handR.Contains((Vector2i) args.RelativePosition);
string handIndex;
if (leftHandContains)
{
handIndex = "left";
}
else if (rightHandContains)
{
handIndex = "right";
}
else
{
return;
}
if (args.Function == EngineKeyFunctions.Use)
{
if (!TryGetHands(out var hands))
return;
if (hands.ActiveIndex == handIndex)
{
UseActiveHand();
@@ -276,21 +255,18 @@ namespace Content.Client.UserInterface
AttackByInHand(handIndex);
}
}
else if (args.Function == ContentKeyFunctions.ExamineEntity)
{
var examine = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ExamineSystem>();
if (leftHandContains)
if (handIndex == HandNameLeft)
examine.DoExamine(LeftHand);
else if (rightHandContains)
else if (handIndex == HandNameRight)
examine.DoExamine(RightHand);
}
else if (args.Function == ContentKeyFunctions.MouseMiddle)
{
SendSwitchHandTo(handIndex);
}
else if (args.Function == ContentKeyFunctions.OpenContextMenu)
{
if (!TryGetHands(out var hands))
@@ -316,6 +292,9 @@ namespace Content.Client.UserInterface
UpdateCooldown(CooldownCircleLeft, LeftHand);
UpdateCooldown(CooldownCircleRight, RightHand);
_rightStatusPanel.Update(RightHand);
_leftStatusPanel.Update(LeftHand);
}
private void UpdateCooldown(TextureRect cooldownTexture, IEntity entity)

View File

@@ -0,0 +1,121 @@
using System.Collections.Generic;
using Content.Client.GameObjects.Components;
using Content.Client.Utility;
using Robust.Client.Graphics.Drawing;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using static Content.Client.StaticIoC;
namespace Content.Client.UserInterface
{
public class ItemStatusPanel : Control
{
[ViewVariables]
private readonly List<(IItemStatus, Control)> _activeStatusComponents = new List<(IItemStatus, Control)>();
[ViewVariables]
private readonly Label _itemNameLabel;
[ViewVariables]
private readonly VBoxContainer _statusContents;
[ViewVariables]
private readonly PanelContainer _panel;
[ViewVariables]
private IEntity _entity;
public ItemStatusPanel(bool isRightHand)
{
// isRightHand means on the LEFT of the screen.
// Keep that in mind.
var panel = new StyleBoxTexture
{
Texture = ResC.GetTexture(isRightHand
? "/Nano/item_status_right.svg.96dpi.png"
: "/Nano/item_status_left.svg.96dpi.png")
};
panel.SetContentMarginOverride(StyleBox.Margin.Vertical, 4);
panel.SetContentMarginOverride(StyleBox.Margin.Horizontal, 6);
panel.SetPatchMargin((isRightHand ? StyleBox.Margin.Left : StyleBox.Margin.Right) | StyleBox.Margin.Top,
13);
AddChild(_panel = new PanelContainer
{
PanelOverride = panel,
ModulateSelfOverride = Color.White.WithAlpha(0.9f),
Children =
{
new VBoxContainer
{
SeparationOverride = 0,
Children =
{
(_statusContents = new VBoxContainer()),
(_itemNameLabel = new Label
{
ClipText = true,
StyleClasses = {NanoStyle.StyleClassItemStatus}
})
}
}
}
});
SizeFlagsVertical = SizeFlags.ShrinkEnd;
}
public void Update(IEntity entity)
{
if (entity == null)
{
ClearOldStatus();
_entity = null;
_panel.Visible = false;
return;
}
if (entity != _entity)
{
_entity = entity;
BuildNewEntityStatus();
}
_panel.Visible = true;
_itemNameLabel.Text = entity.Name;
}
private void ClearOldStatus()
{
_statusContents.RemoveAllChildren();
foreach (var (itemStatus, control) in _activeStatusComponents)
{
itemStatus.DestroyControl(control);
}
_activeStatusComponents.Clear();
}
private void BuildNewEntityStatus()
{
DebugTools.AssertNotNull(_entity);
ClearOldStatus();
foreach (var statusComponent in _entity.GetAllComponents<IItemStatus>())
{
var control = statusComponent.MakeControl();
_statusContents.AddChild(control);
_activeStatusComponents.Add((statusComponent, control));
}
}
protected override Vector2 CalculateMinimumSize()
{
return Vector2.ComponentMax(base.CalculateMinimumSize(), (150, 00));
}
}
}

View File

@@ -30,11 +30,14 @@ namespace Content.Client.UserInterface
public const string StyleClassPowerStateLow = "PowerStateLow";
public const string StyleClassPowerStateGood = "PowerStateGood";
public const string StyleClassItemStatus = "ItemStatus";
public Stylesheet Stylesheet { get; }
public NanoStyle()
{
var resCache = IoCManager.Resolve<IResourceCache>();
var notoSans8 = resCache.GetFont("/Nano/NotoSans/NotoSans-Regular.ttf", 8);
var notoSans10 = resCache.GetFont("/Nano/NotoSans/NotoSans-Regular.ttf", 10);
var notoSans12 = resCache.GetFont("/Nano/NotoSans/NotoSans-Regular.ttf", 12);
var notoSansBold12 = resCache.GetFont("/Nano/NotoSans/NotoSans-Bold.ttf", 12);
@@ -108,7 +111,8 @@ namespace Content.Client.UserInterface
var vScrollBarGrabberNormal = new StyleBoxFlat
{
BackgroundColor = Color.Gray.WithAlpha(0.35f), ContentMarginLeftOverride = 10, ContentMarginTopOverride = 10
BackgroundColor = Color.Gray.WithAlpha(0.35f), ContentMarginLeftOverride = 10,
ContentMarginTopOverride = 10
};
var vScrollBarGrabberHover = new StyleBoxFlat
{
@@ -175,7 +179,7 @@ namespace Content.Client.UserInterface
var itemListItemBackground = new StyleBoxFlat {BackgroundColor = new Color(55, 55, 68)};
itemListItemBackground.SetContentMarginOverride(StyleBox.Margin.Vertical, 2);
itemListItemBackground.SetContentMarginOverride(StyleBox.Margin.Horizontal, 4);
var itemListItemBackgroundTransparent = new StyleBoxFlat { BackgroundColor = Color.Transparent };
var itemListItemBackgroundTransparent = new StyleBoxFlat {BackgroundColor = Color.Transparent};
itemListItemBackgroundTransparent.SetContentMarginOverride(StyleBox.Margin.Vertical, 2);
itemListItemBackgroundTransparent.SetContentMarginOverride(StyleBox.Margin.Horizontal, 4);
@@ -437,7 +441,7 @@ namespace Content.Client.UserInterface
itemListBackgroundSelected)
}),
new StyleRule(new SelectorElement(typeof(ItemList), new []{"transparentItemList"}, null, null), new[]
new StyleRule(new SelectorElement(typeof(ItemList), new[] {"transparentItemList"}, null, null), new[]
{
new StyleProperty(ItemList.StylePropertyBackground,
new StyleBoxFlat {BackgroundColor = Color.Transparent}),
@@ -482,11 +486,12 @@ namespace Content.Client.UserInterface
}),
// Bigger Label
new StyleRule(new SelectorElement(typeof(Label), new[] {StyleClassLabelHeadingBigger}, null, null), new[]
{
new StyleProperty(Label.StylePropertyFont, notoSansBold20),
new StyleProperty(Label.StylePropertyFontColor, NanoGold),
}),
new StyleRule(new SelectorElement(typeof(Label), new[] {StyleClassLabelHeadingBigger}, null, null),
new[]
{
new StyleProperty(Label.StylePropertyFont, notoSansBold20),
new StyleProperty(Label.StylePropertyFontColor, NanoGold),
}),
// Small Label
new StyleRule(new SelectorElement(typeof(Label), new[] {StyleClassLabelSubText}, null, null), new[]
@@ -496,17 +501,18 @@ namespace Content.Client.UserInterface
}),
// Label Key
new StyleRule(new SelectorElement(typeof(Label), new []{StyleClassLabelKeyText}, null, null), new []
new StyleRule(new SelectorElement(typeof(Label), new[] {StyleClassLabelKeyText}, null, null), new[]
{
new StyleProperty(Label.StylePropertyFont, notoSansBold12),
new StyleProperty(Label.StylePropertyFontColor, NanoGold)
}),
new StyleRule(new SelectorElement(typeof(Label), new[] {StyleClassLabelSecondaryColor}, null, null), new[]
{
new StyleProperty(Label.StylePropertyFont, notoSans12),
new StyleProperty(Label.StylePropertyFontColor, Color.DarkGray),
}),
new StyleRule(new SelectorElement(typeof(Label), new[] {StyleClassLabelSecondaryColor}, null, null),
new[]
{
new StyleProperty(Label.StylePropertyFont, notoSans12),
new StyleProperty(Label.StylePropertyFontColor, Color.DarkGray),
}),
// Big Button
new StyleRule(new SelectorElement(typeof(Button), new[] {StyleClassButtonBig}, null, null), new[]
@@ -596,7 +602,7 @@ namespace Content.Client.UserInterface
// StripeBack
new StyleRule(
SelectorElement.Type(typeof(StripeBack)),
new []
new[]
{
new StyleProperty(StripeBack.StylePropertyBackground, stripeBack),
}),
@@ -604,10 +610,16 @@ namespace Content.Client.UserInterface
// StyleClassLabelBig
new StyleRule(
SelectorElement.Class(StyleClassLabelBig),
new []
new[]
{
new StyleProperty("font", notoSans16),
}),
// StyleClassItemStatus
new StyleRule(SelectorElement.Class(StyleClassItemStatus), new[]
{
new StyleProperty("font", notoSans10),
}),
});
}
}