Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NotLe0n committed Apr 21, 2021
1 parent bb26880 commit 9aa114e
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
displayName = Better Chests
author = NotLe0n
version = 1.0
version = 1.1
hideCode = false
hideResources = false
includeSource = false
Expand Down
2 changes: 2 additions & 0 deletions description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

_________________________

Expand All @@ -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

_________________________

Expand Down
19 changes: 19 additions & 0 deletions src/BetterChests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BetterChests.src.UIStates;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
Expand All @@ -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()
Expand All @@ -23,6 +25,9 @@ public override void Load()

ConfirmationUserInterface = new UserInterface();
ConfirmationUserInterface.SetState(new ConfirmationUI());

ChestHoverUserInterface = new UserInterface();
ChestHoverUserInterface.SetState(new ChestHoverUI());
}

ILEdits.Load();
Expand All @@ -34,6 +39,8 @@ public override void Unload()

SortUserInterface = null;
ConfirmationUserInterface = null;
ChestHoverUserInterface = null;
ChestHoverUI.chest = null;

base.Unload();
}
Expand All @@ -58,6 +65,11 @@ public override void UpdateUI(GameTime gameTime)
{
ConfirmationUI.visible = false;
}

if (ChestHoverUI.visible)
{
ChestHoverUserInterface.Update(gameTime);
}
}

public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
Expand All @@ -75,11 +87,18 @@ public override void ModifyInterfaceLayers(List<GameInterfaceLayer> 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));
}
Expand Down
25 changes: 25 additions & 0 deletions src/ILEdits.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/UITextOption.cs → src/UIElements/UITextOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Terraria.ID;
using Terraria.UI;

namespace BetterChests.src
namespace BetterChests.src.UIElements
{
public class UITextOption : UIText
{
Expand Down
70 changes: 70 additions & 0 deletions src/UIStates/ChestHoverUI.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
5 changes: 3 additions & 2 deletions src/ConfirmationUI.cs → src/UIStates/ConfirmationUI.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,7 +9,7 @@
using Terraria.GameContent.UI.Elements;
using Terraria.UI;

namespace BetterChests.src
namespace BetterChests.src.UIStates
{
internal class ConfirmationUI : UIState
{
Expand Down
5 changes: 3 additions & 2 deletions src/SortOptionsUI.cs → src/UIStates/SortOptionsUI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using BetterChests.src.UIElements;
using Microsoft.Xna.Framework;
using System;
using System.Linq;
using Terraria;
Expand All @@ -7,7 +8,7 @@
using Terraria.ID;
using Terraria.UI;

namespace BetterChests.src
namespace BetterChests.src.UIStates
{
internal class SortOptionsUI : UIState
{
Expand Down

0 comments on commit 9aa114e

Please sign in to comment.