From 9aa114e293c93aaa08f9a23d78ecfd1348c7691d Mon Sep 17 00:00:00 2001 From: NotLe0n Date: Wed, 21 Apr 2021 22:41:00 +0200 Subject: [PATCH] v1.1 --- build.txt | 2 +- description.txt | 2 + src/BetterChests.cs | 19 +++++++ src/ILEdits.cs | 25 +++++++++ src/{ => UIElements}/UIBetterTextBox.cs | 2 +- src/{ => UIElements}/UITextOption.cs | 2 +- src/UIStates/ChestHoverUI.cs | 70 +++++++++++++++++++++++++ src/{ => UIStates}/ConfirmationUI.cs | 5 +- src/{ => UIStates}/SortOptionsUI.cs | 5 +- 9 files changed, 125 insertions(+), 7 deletions(-) rename src/{ => UIElements}/UIBetterTextBox.cs (98%) rename src/{ => UIElements}/UITextOption.cs (97%) create mode 100644 src/UIStates/ChestHoverUI.cs rename src/{ => UIStates}/ConfirmationUI.cs (90%) rename src/{ => UIStates}/SortOptionsUI.cs (97%) diff --git a/build.txt b/build.txt index 6cf4375..73acf8a 100644 --- a/build.txt +++ b/build.txt @@ -1,6 +1,6 @@ displayName = Better Chests author = NotLe0n -version = 1.0 +version = 1.1 hideCode = false hideResources = false includeSource = false diff --git a/description.txt b/description.txt index fb0963c..f1aeef5 100644 --- a/description.txt +++ b/description.txt @@ -6,6 +6,7 @@ Contact [c/66EEFF:NotLe0n#7696] on discord if you have any problems. Special Thanks to: [c/66EEFF:direwolf420, darthmorf and jopojelly for a UIElement] +[c/66EEFF:Trivaxy] for providing his item drawing code _________________________ @@ -14,6 +15,7 @@ _________________________ - "Deposit All" and "Loot all" have a confirmation button now. - Clicking on "Sort Items" will open a menu with more sort options to the right and a search bar below the chest UI. +- Hovering over a chest shows its contents _________________________ diff --git a/src/BetterChests.cs b/src/BetterChests.cs index 8349b9d..e06c6e9 100644 --- a/src/BetterChests.cs +++ b/src/BetterChests.cs @@ -1,3 +1,4 @@ +using BetterChests.src.UIStates; using Microsoft.Xna.Framework; using System.Collections.Generic; using Terraria; @@ -10,6 +11,7 @@ public class BetterChests : Mod { internal UserInterface SortUserInterface; internal UserInterface ConfirmationUserInterface; + internal UserInterface ChestHoverUserInterface; public static BetterChests instance; public override void Load() @@ -23,6 +25,9 @@ public override void Load() ConfirmationUserInterface = new UserInterface(); ConfirmationUserInterface.SetState(new ConfirmationUI()); + + ChestHoverUserInterface = new UserInterface(); + ChestHoverUserInterface.SetState(new ChestHoverUI()); } ILEdits.Load(); @@ -34,6 +39,8 @@ public override void Unload() SortUserInterface = null; ConfirmationUserInterface = null; + ChestHoverUserInterface = null; + ChestHoverUI.chest = null; base.Unload(); } @@ -58,6 +65,11 @@ public override void UpdateUI(GameTime gameTime) { ConfirmationUI.visible = false; } + + if (ChestHoverUI.visible) + { + ChestHoverUserInterface.Update(gameTime); + } } public override void ModifyInterfaceLayers(List layers) @@ -75,11 +87,18 @@ public override void ModifyInterfaceLayers(List layers) { SortUserInterface.Draw(Main.spriteBatch, _lastUpdateUiGameTime); } + if (ConfirmationUI.visible) { ConfirmationUserInterface.Draw(Main.spriteBatch, _lastUpdateUiGameTime); } } + + if (ChestHoverUI.visible) + { + ChestHoverUserInterface.Draw(Main.spriteBatch, _lastUpdateUiGameTime); + } + return true; }, InterfaceScaleType.UI)); } diff --git a/src/ILEdits.cs b/src/ILEdits.cs index 958063a..571157d 100644 --- a/src/ILEdits.cs +++ b/src/ILEdits.cs @@ -1,6 +1,11 @@ using MonoMod.Cil; using System.Reflection; +using Terraria; using Terraria.UI; +using Terraria.ID; +using BetterChests.src.UIStates; +using Microsoft.Xna.Framework; +using System.Linq; namespace BetterChests.src { @@ -9,6 +14,26 @@ public class ILEdits public static void Load() { IL.Terraria.UI.ChestUI.DrawButton += EditButton; + On.Terraria.Player.TileInteractionsMouseOver_Containers += Player_TileInteractionsMouseOver_Containers; + } + + private static void Player_TileInteractionsMouseOver_Containers(On.Terraria.Player.orig_TileInteractionsMouseOver_Containers orig, Player self, int myX, int myY) + { + orig(self, myX, myY); + Tile tile = Main.tile[myX, myY]; + int chestX = myX; + int chestY = myY; + if (tile.frameX % 36 != 0) + { + chestX--; + } + if (tile.frameY % 36 != 0) + { + chestY--; + } + Chest chest = Main.chest[Chest.FindChest(chestX, chestY)]; + ChestHoverUI.chest = chest; + ChestHoverUI.visible = true; } private static void EditButton(ILContext il) diff --git a/src/UIBetterTextBox.cs b/src/UIElements/UIBetterTextBox.cs similarity index 98% rename from src/UIBetterTextBox.cs rename to src/UIElements/UIBetterTextBox.cs index 503c7c0..9cc7ef1 100644 --- a/src/UIBetterTextBox.cs +++ b/src/UIElements/UIBetterTextBox.cs @@ -7,7 +7,7 @@ using Terraria.GameContent.UI.Elements; using Terraria.UI; -namespace BetterChests.src +namespace BetterChests.src.UIElements { //ty jopojelly and darthmorf internal class UIBetterTextBox : UIPanel diff --git a/src/UITextOption.cs b/src/UIElements/UITextOption.cs similarity index 97% rename from src/UITextOption.cs rename to src/UIElements/UITextOption.cs index 089918b..4a3424c 100644 --- a/src/UITextOption.cs +++ b/src/UIElements/UITextOption.cs @@ -5,7 +5,7 @@ using Terraria.ID; using Terraria.UI; -namespace BetterChests.src +namespace BetterChests.src.UIElements { public class UITextOption : UIText { diff --git a/src/UIStates/ChestHoverUI.cs b/src/UIStates/ChestHoverUI.cs new file mode 100644 index 0000000..cb38b5d --- /dev/null +++ b/src/UIStates/ChestHoverUI.cs @@ -0,0 +1,70 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.UI; + +namespace BetterChests.src.UIStates +{ + class ChestHoverUI : UIState + { + public static Chest chest; + public static bool visible; + + public override void Draw(SpriteBatch spriteBatch) + { + base.Draw(spriteBatch); + + if (chest == null) + return; + + Item[] items = chest.item.Where(x => x.type != ItemID.None).ToArray(); + + int collumn = 0; + int row = 20; + int padding = 10; + int maxSize = 20; + for (int i = 0; i < items.Length; i++) + { + if (i % 10 == 0) + { + row += maxSize + padding; + collumn = maxSize; + } + + // draw item + Texture2D itemTexture = Main.itemTexture[items[i].type]; + float drawScale = 1f; + int frameCount = 1; + Rectangle? rect = null; + Vector2 drawPos = new Vector2((int)Main.MouseScreen.X + collumn, (int)Main.MouseScreen.Y + row); + + if (Main.itemAnimations[items[i].type] != null) + { + rect = Main.itemAnimations[items[i].type].GetFrame(itemTexture); + frameCount = Main.itemAnimations[items[i].type].FrameCount; + } + + if (itemTexture.Width > maxSize || itemTexture.Height / frameCount > 18) + drawScale = (float)maxSize / (float)Main.itemTexture[items[i].type].Width; + + spriteBatch.Draw(itemTexture, drawPos, rect, Color.White, 0, Vector2.Zero, drawScale, SpriteEffects.None, 0f); + + // draw stack text + if (items[i].stack != 1) + { + string text = items[i].stack.ToString(); + Vector2 pos = drawPos + new Vector2(0, itemTexture.Height / frameCount / 2); + Utils.DrawBorderString(spriteBatch, text, pos, Color.White, 0.75f); + } + + collumn += maxSize + padding; + } + + visible = false; + } + } +} diff --git a/src/ConfirmationUI.cs b/src/UIStates/ConfirmationUI.cs similarity index 90% rename from src/ConfirmationUI.cs rename to src/UIStates/ConfirmationUI.cs index 64b0c9e..07d408a 100644 --- a/src/ConfirmationUI.cs +++ b/src/UIStates/ConfirmationUI.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using BetterChests.src.UIElements; +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Linq; @@ -8,7 +9,7 @@ using Terraria.GameContent.UI.Elements; using Terraria.UI; -namespace BetterChests.src +namespace BetterChests.src.UIStates { internal class ConfirmationUI : UIState { diff --git a/src/SortOptionsUI.cs b/src/UIStates/SortOptionsUI.cs similarity index 97% rename from src/SortOptionsUI.cs rename to src/UIStates/SortOptionsUI.cs index fca4278..6d5b80b 100644 --- a/src/SortOptionsUI.cs +++ b/src/UIStates/SortOptionsUI.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using BetterChests.src.UIElements; +using Microsoft.Xna.Framework; using System; using System.Linq; using Terraria; @@ -7,7 +8,7 @@ using Terraria.ID; using Terraria.UI; -namespace BetterChests.src +namespace BetterChests.src.UIStates { internal class SortOptionsUI : UIState {