From da3a7e47e3cc6747420472f6f6ba861fdd04e718 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Fri, 15 Mar 2019 19:07:29 +0100 Subject: [PATCH] Make HandsGui work on Clyde. --- Content.Client/UserInterface/HandsGui.cs | 82 +++++++++--------------- engine | 2 +- 2 files changed, 30 insertions(+), 54 deletions(-) diff --git a/Content.Client/UserInterface/HandsGui.cs b/Content.Client/UserInterface/HandsGui.cs index 7c4f1af45e..9766ba6ad1 100644 --- a/Content.Client/UserInterface/HandsGui.cs +++ b/Content.Client/UserInterface/HandsGui.cs @@ -34,11 +34,14 @@ namespace Content.Client.UserInterface private StyleBoxTexture handBox; private StyleBoxTexture inactiveHandBox; - private UiHandInfo LeftHand; - private UiHandInfo RightHand; + private IEntity LeftHand; + private IEntity RightHand; private UIBox2i handL; private UIBox2i handR; + private SpriteView LeftSpriteView; + private SpriteView RightSpriteView; + protected override void Initialize() { base.Initialize(); @@ -59,8 +62,17 @@ namespace Content.Client.UserInterface handL = new UIBox2i(0, 0, BOX_SIZE, BOX_SIZE); handR = handL.Translated(new Vector2i(BOX_SIZE + BOX_SPACING, 0)); - SS14.Shared.Log.Logger.Debug($"{handL}, {handR}"); MouseFilter = MouseFilterMode.Stop; + + LeftSpriteView = new SpriteView(); + AddChild(LeftSpriteView); + LeftSpriteView.Size = handL.Size; + LeftSpriteView.Position = handL.TopLeft; + + RightSpriteView = new SpriteView(); + AddChild(RightSpriteView); + RightSpriteView.Size = handR.Size; + RightSpriteView.Position = handR.TopLeft; } protected override Vector2 CalculateMinimumSize() @@ -77,26 +89,6 @@ namespace Content.Client.UserInterface handle.DrawStyleBox(handBox, leftActive ? handL : handR); handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL); - - /* - if (LeftHand.Entity != null && LeftHand.HeldSprite != null) - { - var bounds = LeftHand.HeldSprite.Size; - handle.DrawTextureRect(LeftHand.HeldSprite, - UIBox2i.FromDimensions(handL.Left + (int)(handL.Width / 2f - bounds.X / 2f), - handL.Top + (int)(handL.Height / 2f - bounds.Y / 2f), - (int)bounds.X, (int)bounds.Y), tile: false); - } - - if (RightHand.Entity != null && RightHand.HeldSprite != null) - { - var bounds = RightHand.HeldSprite.Size; - handle.DrawTextureRect(RightHand.HeldSprite, - UIBox2i.FromDimensions(handR.Left + (int)(handR.Width / 2f - bounds.Y / 2f), - handR.Top + (int)(handR.Height / 2f - bounds.Y / 2f), - (int)bounds.X, (int)bounds.Y), tile: false); - } - */ } /// @@ -130,51 +122,41 @@ namespace Content.Client.UserInterface UpdateDraw(); - if (!TryGetHands(out IHandsComponent hands)) + if (!TryGetHands(out var hands)) return; var left = hands.GetEntity("left"); var right = hands.GetEntity("right"); - // I'm naively gonna assume all items are 32x32. - //const float HalfSize = 16; - if (left != null) { - if (left != LeftHand.Entity) + if (left != LeftHand) { - LeftHand.Entity = left; - LeftHand.MirrorHandle?.Dispose(); - LeftHand.MirrorHandle = GetSpriteMirror(left); - LeftHand.MirrorHandle.AttachToControl(this); - LeftHand.MirrorHandle.Offset = new Vector2(handL.Left + (int) (handL.Width / 2f), - handL.Top + (int) (handL.Height / 2f)); + LeftHand = left; + if (LeftHand.TryGetComponent(out ISpriteComponent sprite)) + { + LeftSpriteView.Sprite = sprite; + } } } else { - LeftHand.Entity = null; - LeftHand.MirrorHandle?.Dispose(); - LeftHand.MirrorHandle = null; + LeftHand = null; + LeftSpriteView.Sprite = null; } if (right != null) { - if (right != RightHand.Entity) + RightHand = right; + if (RightHand.TryGetComponent(out ISpriteComponent sprite)) { - RightHand.Entity = right; - RightHand.MirrorHandle?.Dispose(); - RightHand.MirrorHandle = GetSpriteMirror(right); - RightHand.MirrorHandle.AttachToControl(this); - RightHand.MirrorHandle.Offset = new Vector2(handR.Left + (int) (handR.Width / 2f), - handR.Top + (int) (handR.Height / 2f)); + RightSpriteView.Sprite = sprite; } } else { - RightHand.Entity = null; - RightHand.MirrorHandle?.Dispose(); - RightHand.MirrorHandle = null; + RightHand = null; + RightSpriteView.Sprite = null; } } @@ -277,11 +259,5 @@ namespace Content.Client.UserInterface return null; } - - private struct UiHandInfo - { - public IEntity Entity { get; set; } - public ISpriteProxy MirrorHandle { get; set; } - } } } diff --git a/engine b/engine index b2bb711dbb..9fbaf144a6 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit b2bb711dbb8d60f68b718bc2ea76735e19e33069 +Subproject commit 9fbaf144a6ab8378e11e07985c327fbdf784b689