-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
444 additions
and
136 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
[c/FFE900:This mod adds more options to sort your chests] | ||
[c/FFE900:This mod improves some aspects of vanilla chests] | ||
|
||
For a Changlog and more information visit my homepage! | ||
|
||
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/FFE900: Changes] | ||
_________________________ | ||
|
||
- "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. | ||
|
||
_________________________ | ||
|
||
[c/FFE900: How to use] | ||
_________________________ | ||
|
||
[c/C4C4C4: Simply open a chest and click on "Sort Items".] | ||
[c/C4C4C4: This will open another menu to the right.] | ||
[c/C4C4C4: This will open another menu to the right.] | ||
|
||
[c/C4C4C4: Use the search bar to search for items] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using Microsoft.Xna.Framework; | ||
using System.Collections.Generic; | ||
using Terraria; | ||
using Terraria.ModLoader; | ||
using Terraria.UI; | ||
|
||
namespace BetterChests.src | ||
{ | ||
public class BetterChests : Mod | ||
{ | ||
internal UserInterface SortUserInterface; | ||
internal UserInterface ConfirmationUserInterface; | ||
public static BetterChests instance; | ||
|
||
public override void Load() | ||
{ | ||
instance = this; | ||
|
||
if (!Main.dedServ) | ||
{ | ||
SortUserInterface = new UserInterface(); | ||
SortUserInterface.SetState(new SortOptionsUI()); | ||
|
||
ConfirmationUserInterface = new UserInterface(); | ||
ConfirmationUserInterface.SetState(new ConfirmationUI()); | ||
} | ||
|
||
ILEdits.Load(); | ||
} | ||
|
||
public override void Unload() | ||
{ | ||
instance = null; | ||
|
||
SortUserInterface = null; | ||
ConfirmationUserInterface = null; | ||
|
||
base.Unload(); | ||
} | ||
|
||
private GameTime _lastUpdateUiGameTime; | ||
public override void UpdateUI(GameTime gameTime) | ||
{ | ||
_lastUpdateUiGameTime = gameTime; | ||
if (Main.LocalPlayer.chest != -1) | ||
{ | ||
if (SortOptionsUI.visible) | ||
{ | ||
SortUserInterface.Update(gameTime); | ||
} | ||
|
||
if (ConfirmationUI.visible) | ||
{ | ||
ConfirmationUserInterface.Update(gameTime); | ||
} | ||
} | ||
else | ||
{ | ||
ConfirmationUI.visible = false; | ||
} | ||
} | ||
|
||
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers) | ||
{ | ||
int mouseTextIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text")); | ||
if (mouseTextIndex != -1) | ||
{ | ||
layers.Insert(mouseTextIndex, new LegacyGameInterfaceLayer( | ||
"BetterChests: UI", | ||
delegate | ||
{ | ||
if (Main.LocalPlayer.chest != -1) | ||
{ | ||
if (SortOptionsUI.visible) | ||
{ | ||
SortUserInterface.Draw(Main.spriteBatch, _lastUpdateUiGameTime); | ||
} | ||
if (ConfirmationUI.visible) | ||
{ | ||
ConfirmationUserInterface.Draw(Main.spriteBatch, _lastUpdateUiGameTime); | ||
} | ||
} | ||
return true; | ||
}, InterfaceScaleType.UI)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.Xna.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Terraria; | ||
using Terraria.GameContent.UI.Elements; | ||
using Terraria.UI; | ||
|
||
namespace BetterChests.src | ||
{ | ||
internal class ConfirmationUI : UIState | ||
{ | ||
public static bool visible = false; | ||
public int buttonID; | ||
public float topOffset; | ||
public MouseEvent onclick; | ||
|
||
public override void OnInitialize() | ||
{ | ||
var confirmation = new UITextOption("Are you sure?"); | ||
confirmation.TextColor = Color.Red; | ||
confirmation.Top.Set(Main.instance.invBottom + topOffset, 0); | ||
confirmation.Left.Set(506, 0); // magic number because vanilla does it the same way lmao | ||
confirmation.OnMouseDown += onclick; | ||
Append(confirmation); | ||
} | ||
|
||
public override void Update(GameTime gameTime) | ||
{ | ||
base.Update(gameTime); | ||
|
||
ChestUI.ButtonScale[buttonID] = 0f; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using MonoMod.Cil; | ||
using System.Reflection; | ||
using Terraria.UI; | ||
|
||
namespace BetterChests.src | ||
{ | ||
public class ILEdits | ||
{ | ||
public static void Load() | ||
{ | ||
IL.Terraria.UI.ChestUI.DrawButton += EditButton; | ||
} | ||
|
||
private static void EditButton(ILContext il) | ||
{ | ||
var c = new ILCursor(il); | ||
|
||
if (!c.TryGotoNext(MoveType.After, i => i.MatchCall<ChestUI>("LootAll"))) | ||
return; | ||
|
||
c.Prev.Operand = typeof(ILEdits).GetMethod("OpenLootConfirmation", BindingFlags.NonPublic | BindingFlags.Static); | ||
|
||
// IL_0362: br.s IL_038C | ||
// IL_0364: call void Terraria.UI.ChestUI::DepositAll() | ||
// <=== here | ||
|
||
if (!c.TryGotoNext(MoveType.After, i => i.MatchCall<ChestUI>("DepositAll"))) | ||
return; | ||
|
||
c.Prev.Operand = typeof(ILEdits).GetMethod("OpenDepositConfirmation", BindingFlags.NonPublic | BindingFlags.Static); | ||
|
||
// The goal of this IL edit is to replace SortChest() with code to open my UI | ||
// IL_0385: br.s IL_038C | ||
// IL_0387: call void Terraria.UI.ItemSorting::SortChest() | ||
// <=== here | ||
|
||
if (!c.TryGotoNext(MoveType.After, i => i.MatchCall<ItemSorting>("SortChest"))) | ||
return; | ||
|
||
c.Prev.Operand = typeof(ILEdits).GetMethod("ToggleSortUI", BindingFlags.NonPublic | BindingFlags.Static); | ||
} | ||
|
||
private static void ToggleSortUI() | ||
{ | ||
SortOptionsUI.visible = !SortOptionsUI.visible; | ||
} | ||
|
||
private static void OpenDepositConfirmation() | ||
{ | ||
var ui = new ConfirmationUI | ||
{ | ||
buttonID = ChestUI.ButtonID.DepositAll, | ||
topOffset = 55, | ||
onclick = (evt, elm) => | ||
{ | ||
ChestUI.DepositAll(); | ||
ConfirmationUI.visible = false; | ||
} | ||
}; | ||
|
||
BetterChests.instance.ConfirmationUserInterface.SetState(ui); | ||
ConfirmationUI.visible = true; | ||
} | ||
|
||
private static void OpenLootConfirmation() | ||
{ | ||
var ui = new ConfirmationUI | ||
{ | ||
buttonID = ChestUI.ButtonID.LootAll, | ||
topOffset = 30, | ||
onclick = (evt, elm) => | ||
{ | ||
ChestUI.LootAll(); | ||
ConfirmationUI.visible = false; | ||
} | ||
}; | ||
|
||
BetterChests.instance.ConfirmationUserInterface.SetState(ui); | ||
ConfirmationUI.visible = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.