From c047f19fdce947a5ade709b8a59267e451ab876d Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:59:16 -0500 Subject: [PATCH] Inventory sprite rotation (#22201) --- .../Systems/Storage/Controls/ItemGridPiece.cs | 40 ++++++++++++++---- Content.Shared/Item/ItemComponent.cs | 13 ++++++ .../Entities/Objects/Tools/tools.yml | 11 +++++ .../Objects/Tools/crowbar.rsi/meta.json | 8 +++- .../Objects/Tools/crowbar.rsi/red-storage.png | Bin 0 -> 371 bytes .../Objects/Tools/crowbar.rsi/storage.png | Bin 0 -> 334 bytes .../Objects/Tools/wrench.rsi/meta.json | 5 ++- .../Objects/Tools/wrench.rsi/storage.png | Bin 0 -> 408 bytes 8 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 Resources/Textures/Objects/Tools/crowbar.rsi/red-storage.png create mode 100644 Resources/Textures/Objects/Tools/crowbar.rsi/storage.png create mode 100644 Resources/Textures/Objects/Tools/wrench.rsi/storage.png diff --git a/Content.Client/UserInterface/Systems/Storage/Controls/ItemGridPiece.cs b/Content.Client/UserInterface/Systems/Storage/Controls/ItemGridPiece.cs index e4f3506baa..1441681e68 100644 --- a/Content.Client/UserInterface/Systems/Storage/Controls/ItemGridPiece.cs +++ b/Content.Client/UserInterface/Systems/Storage/Controls/ItemGridPiece.cs @@ -78,7 +78,7 @@ public sealed class ItemGridPiece : Control base.Draw(handle); // really just an "oh shit" catch. - if (!_entityManager.EntityExists(Entity)) + if (!_entityManager.EntityExists(Entity) || !_entityManager.TryGetComponent(Entity, out var itemComponent)) { Dispose(); return; @@ -87,7 +87,7 @@ public sealed class ItemGridPiece : Control if (_storageController.IsDragging && _storageController.CurrentlyDragging == this) return; - var adjustedShape = _entityManager.System().GetAdjustedItemShape((Entity, null), Location.Rotation, Vector2i.Zero); + var adjustedShape = _entityManager.System().GetAdjustedItemShape((Entity, itemComponent), Location.Rotation, Vector2i.Zero); var boundingGrid = adjustedShape.GetBoundingBox(); var size = _centerTexture!.Size * 2 * UIScale; @@ -130,15 +130,37 @@ public sealed class ItemGridPiece : Control } // typically you'd divide by two, but since the textures are half a tile, this is done implicitly - var iconOffset = new Vector2((boundingGrid.Width + 1) * size.X , + var iconPosition = new Vector2((boundingGrid.Width + 1) * size.X , (boundingGrid.Height + 1) * size.Y); + var iconRotation = Location.Rotation + Angle.FromDegrees(itemComponent.StoredRotation); - _entityManager.System().ForceUpdate(Entity); - handle.DrawEntity(Entity, - PixelPosition + iconOffset, - Vector2.One * 2 * UIScale, - Angle.Zero, - overrideDirection: Direction.South); + if (itemComponent.StoredSprite is { } storageSprite) + { + var scale = 2 * UIScale; + var offset = (((Box2) boundingGrid).Size - Vector2.One) * size; + var sprite = _entityManager.System().Frame0(storageSprite); + + var spriteBox = new Box2Rotated(new Box2(0f, sprite.Height * scale, sprite.Width * scale, 0f), -iconRotation, Vector2.Zero); + var root = spriteBox.CalcBoundingBox().BottomLeft; + var pos = PixelPosition * 2 + + (Parent?.GlobalPixelPosition ?? Vector2.Zero) + + offset; + + handle.SetTransform(pos, iconRotation); + var box = new UIBox2(root, root + sprite.Size * scale); + handle.DrawTextureRect(sprite, box); + handle.SetTransform(Matrix3.Identity); + } + else + { + _entityManager.System().ForceUpdate(Entity); + handle.DrawEntity(Entity, + PixelPosition + iconPosition, + Vector2.One * 2 * UIScale, + Angle.Zero, + eyeRotation: iconRotation, + overrideDirection: Direction.South); + } } protected override bool HasPoint(Vector2 point) diff --git a/Content.Shared/Item/ItemComponent.cs b/Content.Shared/Item/ItemComponent.cs index 21926882a0..1cb51b6ea0 100644 --- a/Content.Shared/Item/ItemComponent.cs +++ b/Content.Shared/Item/ItemComponent.cs @@ -2,6 +2,7 @@ using Content.Shared.Hands.Components; using Robust.Shared.GameStates; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Utility; namespace Content.Shared.Item; @@ -41,6 +42,18 @@ public sealed partial class ItemComponent : Component /// [DataField, AutoNetworkedField] public List? Shape; + + /// + /// A sprite used to depict this entity specifically when it is displayed in the storage UI. + /// + [DataField, AutoNetworkedField] + public SpriteSpecifier? StoredSprite; + + /// + /// An additional angle offset, in degrees, applied to the visual depiction of the item when displayed in the storage UI. + /// + [DataField, AutoNetworkedField] + public float StoredRotation = 0; } [Serializable, NetSerializable] diff --git a/Resources/Prototypes/Entities/Objects/Tools/tools.yml b/Resources/Prototypes/Entities/Objects/Tools/tools.yml index 566c72dafd..54200f10e8 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/tools.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/tools.yml @@ -37,6 +37,7 @@ cutters: Rainbow - type: Item sprite: Objects/Tools/wirecutters.rsi + storedRotation: -90 - type: LatticeCutting - type: PhysicalComposition materialComposition: @@ -64,6 +65,7 @@ - state: screwdriver-screwybits - type: Item sprite: Objects/Tools/screwdriver.rsi + storedRotation: -90 - type: ItemCooldown - type: MeleeWeapon wideAnimationRotation: -90 @@ -105,6 +107,9 @@ state: icon - type: Item sprite: Objects/Tools/wrench.rsi + storedSprite: + sprite: Objects/Tools/wrench.rsi + state: storage - type: ItemCooldown - type: MeleeWeapon wideAnimationRotation: 135 @@ -141,6 +146,9 @@ - type: Item sprite: Objects/Tools/crowbar.rsi size: Small + storedSprite: + sprite: Objects/Tools/crowbar.rsi + state: storage - type: ItemCooldown - type: MeleeWeapon wideAnimationRotation: -135 @@ -174,6 +182,9 @@ state: red-icon - type: Item heldPrefix: red + storedSprite: + sprite: Objects/Tools/crowbar.rsi + state: red-storage - type: entity name: multitool diff --git a/Resources/Textures/Objects/Tools/crowbar.rsi/meta.json b/Resources/Textures/Objects/Tools/crowbar.rsi/meta.json index 1778efa00c..d4cab89f8e 100644 --- a/Resources/Textures/Objects/Tools/crowbar.rsi/meta.json +++ b/Resources/Textures/Objects/Tools/crowbar.rsi/meta.json @@ -1,7 +1,7 @@ { "version": 1, "license": "CC-BY-SA-3.0", - "copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/commit/eea0599511b088fdab9d43e562210cdbd51c6a98", + "copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/commit/eea0599511b088fdab9d43e562210cdbd51c6a98, storage and red-storage by Flareguy", "size": { "x": 32, "y": 32 @@ -36,6 +36,12 @@ { "name": "red-equipped-BELT", "directions": 4 + }, + { + "name": "storage" + }, + { + "name": "red-storage" } ] } diff --git a/Resources/Textures/Objects/Tools/crowbar.rsi/red-storage.png b/Resources/Textures/Objects/Tools/crowbar.rsi/red-storage.png new file mode 100644 index 0000000000000000000000000000000000000000..11aa1e058f288b1a5ebe595a7cfc2bbc684e85de GIT binary patch literal 371 zcmV-(0gV2MP)Px$ElET{R9J=WmoajKFc3vQaVSU^-yj#z8Gtgi&)|~7Q1~9cfYAj^p$;{vXflJ{ z#RUa!41)aqK9ioJ{NK0NV0>zq#He3Aqr- zMF;>do`+*6#(4wS0PmX(wq=P-h^yLY@5WHEQt(lh-(nndHh?X2Ho%+fS}|t>^rc`@ z0Gl#S!7Ko?rNFe{i~+hoq{#us&_BTa1DF=3l^u{$vO!n?`}G>1t5q+^r~rR`h(>Qn zep}&VG$i$*q;APg%>iIBbYPmMRTu=w^Be$B6a~8zZi_U55TZGd+AzNfodLl7h(kAz R&OHDC002ovPDHLkV1m&cm#P2& literal 0 HcmV?d00001 diff --git a/Resources/Textures/Objects/Tools/crowbar.rsi/storage.png b/Resources/Textures/Objects/Tools/crowbar.rsi/storage.png new file mode 100644 index 0000000000000000000000000000000000000000..268c5bd881fba381121d4335109eded701ea722c GIT binary patch literal 334 zcmV-U0kQsxP)Px$2uVaiR9J=Wmp=}JAQZ+w+b+1(gLnq@Kpw^eRZrl+CcC4$)zL1M5MmSGgNjZ1 zO$3zh7vCQN2&{jrIh6TZd~&s&$pHrDg+6@Hh<1Drf~!S+>-?Fc@o5h zVs2_R@03EPlm?+{H^3+Js;VL>Wz;Ek9Du1T%k=nB*W^SbCm{gDLSVAyI28bR_yVqC z=Ri;ZQ+9P60uT$K$7T{925_nn1OYHZ5CkAt2wW4+8NjvVoB_U}Kfvz;1o;J(9bc1Hg6fgKgU`MV_PYdjP;N4D6GzDbfaM gn(7Ow5A###1yhcFlOBDm(*OVf07*qoM6N<$f>>&Y1poj5 literal 0 HcmV?d00001 diff --git a/Resources/Textures/Objects/Tools/wrench.rsi/meta.json b/Resources/Textures/Objects/Tools/wrench.rsi/meta.json index 9f7b9badd5..a2c8f06819 100644 --- a/Resources/Textures/Objects/Tools/wrench.rsi/meta.json +++ b/Resources/Textures/Objects/Tools/wrench.rsi/meta.json @@ -1,7 +1,7 @@ { "version": 1, "license": "CC-BY-SA-3.0", - "copyright": "Taken from vgstation at commit https://github.com/vgstation-coders/vgstation13/commit/1cdfb0230cc96d0ba751fa002d04f8aa2f25ad7d", + "copyright": "Taken from vgstation at commit https://github.com/vgstation-coders/vgstation13/commit/1cdfb0230cc96d0ba751fa002d04f8aa2f25ad7d, storage by EmoGarbage404 (github)", "size": { "x": 32, "y": 32 @@ -21,6 +21,9 @@ { "name": "equipped-BELT", "directions": 4 + }, + { + "name": "storage" } ] } diff --git a/Resources/Textures/Objects/Tools/wrench.rsi/storage.png b/Resources/Textures/Objects/Tools/wrench.rsi/storage.png new file mode 100644 index 0000000000000000000000000000000000000000..54d1d9b28e97ee22145171a9335ec41e5c4d35ee GIT binary patch literal 408 zcmV;J0cZY+P)Px$Qb|NXR9J=WmoaXGFc?N3RR@+RtX3){7Aq4|_K@zJhJjn;069Z$5UEjCPC!^9 zK_j-r6$hY06(ou(VbiLMzs=?s?_nG912&qGQnpgc_NTFKo^;_+6d{D@=7bO=NrI__ zmH@!*b{otc4hIu90M6J#Aw=&9XR}%Fdebxj)O9`jo&e7}#c>?>#^>`HfXn5=cDn^2 zP1Ck4%h3{}3)ky)Ti11O{{imzJ4z{nAn0WNL;x5ZG}m>JQUZ`=8GsfXG!J1>6iyUH z6h+~