Skip to content

Commit

Permalink
2.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RealAgrair committed Jun 15, 2019
1 parent 4a14fdf commit f714ee8
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 45 deletions.
50 changes: 50 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.IO;
using System.Linq;
using System.Reflection;
using Terraria;

namespace InvTweaks
{
public static class Config
{
private static readonly FieldInfo[] fields = typeof(Config).GetFields(BindingFlags.Static | BindingFlags.Public);
private static readonly string path = Path.Combine(Main.SavePath, "InvTweaksConf.json");

public static bool cursorFill = true;
public static bool helmetSlot = true;
// public static bool shopClick
public static bool lifeCrystalDevour = true;
// public static bool saplingPlacer;

public static void Load()
{
if (File.Exists(path))
{
string[] array = File.ReadAllLines(path);
for (int i = 0; i < array.Length; i++)
{
string item = array[i];
var split = item.Split(':');
var key = split[0].Trim();
var value = split.Last().Trim();
if (fields.Any(x => x.Name == key) && bool.TryParse(value, out bool result))
{
fields.FirstOrDefault(x => x.Name == key).SetValue(null, result);
}
}
}
Write();
}

public static void Write()
{
var writer = new StreamWriter(File.Create(path));
for (int i = 0; i < fields.Length; i++)
{
FieldInfo fld = fields[i];
writer.WriteLine(fld.Name + " : " + ((bool)fld.GetValue(null) ? bool.TrueString : bool.FalseString));
}
writer.Close();
}
}
}
11 changes: 8 additions & 3 deletions InvTweaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
namespace InvTweaks
{
public class InvTweaks : Mod
{
{
public override void Load()
{
Config.Load();
}

public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
int index = layers.FindIndex(x => x.Name == "Vanilla: Hotbar");
if (index != -1)
{
layers.Insert(index + 1,
new LegacyGameInterfaceLayer("Inventory Tweaks : Hotbar", DrawExtraHotbarSlot,
new LegacyGameInterfaceLayer("InvTweaks: Hotbar", DrawExtraHotbarSlot,
InterfaceScaleType.UI));
}
}

private bool DrawExtraHotbarSlot()
{
if (!Main.gameMenu)
if (!Main.gameMenu && Config.helmetSlot)
{
float oldScale = Main.inventoryScale;
Main.inventoryScale = .75f;
Expand Down
5 changes: 3 additions & 2 deletions InvTweaks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="InvTweaks.cs" />
<Compile Include="InvTweaksItem.cs" />
<Compile Include="InvTweaksPlayer.cs" />
Expand All @@ -56,8 +57,8 @@
<HintPath>C:\Windows\Microsoft.NET\assembly\GAC_32\Microsoft.Xna.Framework.Xact\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Xact.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="Terraria">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\terraria\Terraria.exe</HintPath>
<Reference Include="tML v0.10.1.5">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Terraria\tML v0.10.1.5.exe</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
17 changes: 16 additions & 1 deletion InvTweaksItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace InvTweaks
Expand All @@ -7,7 +8,7 @@ public class InvTweaksItem : GlobalItem
{
public override bool ConsumeItem(Item item, Player player)
{
if (item.stack == 1)
if (item.stack == 1 && Config.cursorFill)
{
for (int i = 0; i < player.inventory.Length; i++)
{
Expand All @@ -22,5 +23,19 @@ public override bool ConsumeItem(Item item, Player player)
}
return true;
}

public override void SetDefaults(Item item)
{
if ((item.type == ItemID.ManaCrystal ||
item.type == ItemID.LifeCrystal ||
item.type == ItemID.LifeFruit) && Config.lifeCrystalDevour)
{
item.useTime = 3;
item.useAnimation = 9;
item.autoReuse = true;
item.reuseDelay = 2;
item.useTurn = true;
}
}
}
}
145 changes: 111 additions & 34 deletions InvTweaksPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Terraria;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using Terraria.UI;
Expand All @@ -18,64 +20,139 @@ public override void Initialize()

public override void Load(TagCompound tag)
{
extraSlotItem.SetDefaults(tag.GetInt("extraSlotItem_Type"));
// legacy load
int type = tag.GetInt("extraSlotItem_Type");
if (type != 0) extraSlotItem.SetDefaults(type);
if (tag.GetCompound("extraSlotItem") is TagCompound item
&& item != new TagCompound())
{
extraSlotItem = ItemIO.Load(item);
}
}

public override TagCompound Save()
{
return new TagCompound
{
["extraSlotItem_Type"] = extraSlotItem.type
["extraSlotItem"] = ItemIO.Save(extraSlotItem)
};
}

#region TODO: MAKE THIS SHIT WORK

/*
public override bool ShiftClickSlot(Item[] inventory, int context, int slot)
{
if (!inventory[slot].IsAir)
{
if (context == ItemSlot.Context.ShopItem)
{
var num = Utils.CoinsCount(out bool flag, player.bank.item);
var num2 = Utils.CoinsCount(out flag, player.bank2.item);
var num3 = Utils.CoinsCount(out flag, player.bank3.item);
var num4 = Utils.CoinsCount(out flag, player.inventory);
var totalSavings = Utils.CoinsCombineStacks(out flag, num, num2, num3, num4);
if (totalSavings >= inventory[slot].GetStoreValue()
&& Main.mouseItem.stack <= Main.mouseItem.maxStack)
var num = Utils.CoinsCount(out _, player.bank.item);
var num2 = Utils.CoinsCount(out _, player.bank2.item);
var num3 = Utils.CoinsCount(out _, player.bank3.item);
var num4 = Utils.CoinsCount(out _, player.inventory, new int[]
{
Main.PlaySound(18);
flag = true;
}
while (totalSavings >= inventory[slot].GetStoreValue()
&& Main.mouseItem.stack <= Main.mouseItem.maxStack)
58,
57,
56,
55,
54
});
var change = Utils.CoinsCombineStacks(out _, num, num2, num3, num4);
if (change < inventory[slot].GetStoreValue()) return false;
if ((Main.mouseItem.type == inventory[slot].type || Main.mouseItem.type == 0)
&& Main.mouseItem.stack < Main.mouseItem.maxStack)
{
Chest chest = Main.instance.shop[Main.npcShop];
if (Main.stackSplit <= 1 && inventory[slot].type > 0
&& (Main.mouseItem.IsTheSameAs(inventory[slot]) || Main.mouseItem.type == 0))
do
{
if ((Main.mouseItem.stack < Main.mouseItem.maxStack || Main.mouseItem.type == 0)
&& player.BuyItem(inventory[slot].GetStoreValue(),
inventory[slot].shopSpecialCurrency)
&& inventory[slot].stack > 0)
// , PlayerHooks.CanBuyItem())
if (Main.mouseItem.type == 0)
{
Main.mouseItem.stack++;
Main.mouseItem.SetDefaults(inventory[slot].type);
Main.mouseItem.stack = 0;
}
Main.mouseItem.stack++;
purchase();
change -= inventory[slot].GetStoreValue();
}
num = Utils.CoinsCount(out flag, player.bank.item);
num2 = Utils.CoinsCount(out flag, player.bank2.item);
num3 = Utils.CoinsCount(out flag, player.bank3.item);
num4 = Utils.CoinsCount(out flag, player.inventory);
totalSavings = Utils.CoinsCombineStacks(out flag, num, num2, num3, num4);
while (Main.mouseItem.stack < Main.mouseItem.maxStack
&& change >= inventory[slot].GetStoreValue());
return true;
}
return flag;
}
}
return false;
void purchase()
{
int remainingCost = inventory[slot].GetStoreValue();
for (int i = 0; i < player.bank.item.Length; i++)
{
if (consumeCoin(player.bank.item[i])) return;
}
for (int i = 0; i < player.bank2.item.Length; i++)
{
if (consumeCoin(player.bank2.item[i])) return;
}
for (int i = 0; i < player.bank3.item.Length; i++)
{
if (consumeCoin(player.bank3.item[i])) return;
}
for (int i = 0; i < player.inventory.Length; i++)
{
if (consumeCoin(player.inventory[i])) return;
}
bool consumeCoin(Item item)
{
if (item.type == ItemID.PlatinumCoin)
{
var consumeCount = Utils.Clamp((int)Math.Floor(remainingCost / 100000000.0), 0, item.stack);
remainingCost -= 100000000 * consumeCount;
if ((item.stack -= consumeCount) == 0) item.TurnToAir();
if (remainingCost == 0) return true;
if (remainingCost < 0)
{
remainingCost = Math.Abs(remainingCost);
// if `remainingCost` was negative, that means it was
// less than one platinum
player.QuickSpawnItem(ItemID.GoldCoin, remainingCost);
}
}
else if (item.type == ItemID.GoldCoin)
{
var consumeCount = Utils.Clamp((int)Math.Floor(remainingCost / 100000000.0), 0, item.stack);
remainingCost -= 100000000 * consumeCount;
if ((item.stack -= consumeCount) == 0) item.TurnToAir();
if (remainingCost == 0) return true;
if (remainingCost < 0)
{
remainingCost = Math.Abs(remainingCost);
player.QuickSpawnItem(ItemID.GoldCoin, remainingCost);
}
}
else if (item.type == ItemID.SilverCoin)
{
var consumeCount = Utils.Clamp((int)Math.Floor(remainingCost / 100000000.0), 0, item.stack);
remainingCost -= 100000000 * consumeCount;
if ((item.stack -= consumeCount) == 0) item.TurnToAir();
if (remainingCost == 0) return true;
if (remainingCost < 0)
{
remainingCost = Math.Abs(remainingCost);
player.QuickSpawnItem(ItemID.CopperCoin, remainingCost);
}
}
else if (item.type == ItemID.CopperCoin)
{
var consumeCount = Utils.Clamp(remainingCost, 0, item.stack);
remainingCost -= consumeCount;
if ((item.stack -= consumeCount) == 0) item.TurnToAir();
if (remainingCost == 0) return true;
}
return false;
}
}
}
*/
#endregion
*/
}
}
4 changes: 2 additions & 2 deletions build.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
author = Agrair
version = 2.2.0.6
version = 2.2.3
displayName = Inventory Tweaks
buildIgnore = .vs/, .csproj, bin/, obj/, LICENSE, .gitignore, .git, .sln, .user
includePDB = true
includePDB = false
hideCode = false
hideResources = false
includeSource = true
Expand Down
9 changes: 6 additions & 3 deletions description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

[i:109] Features:
[i:97] When you consume an item, and the same kind of item is in your inventory, it'll automatically go into your hand after use.
[i:97] A new hotbar slot for your Spectre Hood/Helment, right click it to swap them out.
[i:97] A new hotbar slot for your Spectre Hood/Helmet, right click it to swap them out.
[i:97] Shift clicking shop slots will automatically buy as much of that item as you can. (Unimplemented)
[i:97] Using Life Fruits, Life Crystals, and Mana Crystals is super fast.
[i:97] Cut down a tree and if you have a sapling in your inventory it'll be placed. (Unimplemented)
[i:97] All features are configurable, find the config in your saves folder and open it like a text.

[i:75] Changelog for 2.2.0.1
[i:97] Extra hotbar slot is faster by a couple milliseconds, cleaned up the code.
[i:109] Changelog:
[i:97] Config!

Report any issues through GitHub (homepage) or on Discord (Agrair#7746)

0 comments on commit f714ee8

Please sign in to comment.