mirror of
https://github.com/OMGeeky/ItemChecklist.git
synced 2026-02-23 15:38:25 +01:00
0.4, collect chest items, magic storage integration
This commit is contained in:
@@ -9,6 +9,12 @@ using System;
|
||||
|
||||
namespace ItemChecklist
|
||||
{
|
||||
// TODO: is ItemChecklistPlayer.foundItems a waste of memory? investigate and trim it down if needed.
|
||||
// TODO: World Checklist? MP shared checklist?
|
||||
// Has this item ever been seen on this world? - easy. Maintain separate bool array, on change, notify server, relay to clients.
|
||||
// send bool array as byte array?
|
||||
// query magic storage?
|
||||
// WHY? I want to know everything we can craft yet
|
||||
public class ItemChecklist : Mod
|
||||
{
|
||||
static internal ItemChecklist instance;
|
||||
@@ -29,6 +35,7 @@ namespace ItemChecklist
|
||||
{
|
||||
instance = this;
|
||||
ToggleChecklistHotKey = RegisterHotKey("Toggle Item Checklist", "I");
|
||||
MagicStorageIntegration.Load();
|
||||
}
|
||||
|
||||
public override void Unload()
|
||||
@@ -37,6 +44,7 @@ namespace ItemChecklist
|
||||
instance = null;
|
||||
ToggleChecklistHotKey = null;
|
||||
ItemChecklistInterface = null;
|
||||
MagicStorageIntegration.Unload();
|
||||
}
|
||||
|
||||
public override void AddRecipes()
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MagicStorage_v0.4.3.1">
|
||||
<HintPath>lib\MagicStorage_v0.4.3.1.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Xna.Framework">
|
||||
<HintPath>..\..\solutiondlls\Microsoft.Xna.Framework.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -69,6 +72,7 @@
|
||||
<Compile Include="ItemChecklistPlayer.cs" />
|
||||
<Compile Include="ItemChecklistUI.cs" />
|
||||
<Compile Include="ItemSlot.cs" />
|
||||
<Compile Include="MagicStorageIntegration.cs" />
|
||||
<Compile Include="UICheckbox.cs" />
|
||||
<Compile Include="UIGrid.cs" />
|
||||
<Compile Include="UIHoverImageButton.cs" />
|
||||
@@ -89,7 +93,7 @@
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>"C:\Program Files (x86)\Steam\steamapps\common\Terraria\Terraria.exe" -build "$(ProjectDir)\" -eac "$(TargetPath)"</PostBuildEvent>
|
||||
<PostBuildEvent>"C:\Program Files (x86)\Steam\steamapps\common\Terraria\tModLoaderServer.exe" -build "$(ProjectDir)\" -eac "$(TargetPath)"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using ItemChecklist.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.GameInput;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
@@ -29,6 +32,7 @@ namespace ItemChecklist
|
||||
// Because of save, these values inherit the last used setting while loading
|
||||
internal SortModes sortModePreference = SortModes.TerrariaSort;
|
||||
internal bool announcePreference;
|
||||
internal bool findChestItemsPreference = true;
|
||||
internal int showCompletedPreference;
|
||||
|
||||
public override void ProcessTriggers(TriggersSet triggersSet)
|
||||
@@ -48,6 +52,7 @@ namespace ItemChecklist
|
||||
var itemChecklistPlayer = Main.LocalPlayer.GetModPlayer<ItemChecklistPlayer>(mod);
|
||||
ItemChecklistUI.visible = false;
|
||||
ItemChecklistUI.announce = announcePreference;
|
||||
ItemChecklistUI.collectChestItems = findChestItemsPreference;
|
||||
ItemChecklistUI.sortMode = sortModePreference;
|
||||
ItemChecklistUI.showCompleted = showCompletedPreference;
|
||||
ItemChecklist.instance.ItemChecklistUI.RefreshPreferences();
|
||||
@@ -72,23 +77,55 @@ namespace ItemChecklist
|
||||
}
|
||||
|
||||
announcePreference = false;
|
||||
findChestItemsPreference = true;
|
||||
sortModePreference = SortModes.TerrariaSort;
|
||||
showCompletedPreference = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateAutopause()
|
||||
{
|
||||
ChestCheck();
|
||||
}
|
||||
|
||||
public override void PreUpdate()
|
||||
{
|
||||
if (!Main.dedServ)
|
||||
ChestCheck();
|
||||
}
|
||||
|
||||
private void ChestCheck()
|
||||
{
|
||||
if (!Main.dedServ && player.whoAmI == Main.myPlayer)
|
||||
{
|
||||
var itemChecklistPlayer = Main.LocalPlayer.GetModPlayer<ItemChecklistPlayer>(mod);
|
||||
for (int i = 0; i < 59; i++)
|
||||
{
|
||||
if (!player.inventory[i].IsAir && !itemChecklistPlayer.foundItem[player.inventory[i].type] && itemChecklistPlayer.findableItems[player.inventory[i].type])
|
||||
if (!player.inventory[i].IsAir && !foundItem[player.inventory[i].type] && findableItems[player.inventory[i].type])
|
||||
{
|
||||
((ItemChecklistGlobalItem)mod.GetGlobalItem("ItemChecklistGlobalItem")).ItemReceived(player.inventory[i]);
|
||||
mod.GetGlobalItem<ItemChecklistGlobalItem>().ItemReceived(player.inventory[i]); // TODO: Analyze performance impact? do every 60 frames only?
|
||||
}
|
||||
}
|
||||
if (player.chest != -1 && (player.chest != player.lastChest || Main.autoPause && Main.gamePaused) && ItemChecklistUI.collectChestItems)
|
||||
{
|
||||
//Main.NewText(player.chest + " " + player.lastChest);
|
||||
Item[] items;
|
||||
if (player.chest == -2)
|
||||
items = player.bank.item;
|
||||
else if (player.chest == -3)
|
||||
items = player.bank2.item;
|
||||
else if (player.chest == -4)
|
||||
items = player.bank3.item;
|
||||
else
|
||||
items = Main.chest[player.chest].item;
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
if (!items[i].IsAir && !foundItem[items[i].type] && findableItems[items[i].type])
|
||||
{
|
||||
mod.GetGlobalItem<ItemChecklistGlobalItem>().ItemReceived(items[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ItemChecklistUI.collectChestItems && MagicStorageIntegration.Enabled)
|
||||
MagicStorageIntegration.FindItemsInStorage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +136,8 @@ namespace ItemChecklist
|
||||
{
|
||||
["FoundItems"] = foundItems.Select(ItemIO.Save).ToList(),
|
||||
["SortMode"] = (int)ItemChecklistUI.sortMode,
|
||||
["Announce"] = ItemChecklistUI.announce,
|
||||
["Announce"] = ItemChecklistUI.announce, // Not saving default, saving last used....good thing?
|
||||
["CollectChestItems"] = ItemChecklistUI.collectChestItems,
|
||||
["ShowCompleted"] = ItemChecklistUI.showCompleted,
|
||||
};
|
||||
}
|
||||
@@ -109,6 +147,8 @@ namespace ItemChecklist
|
||||
foundItems = tag.GetList<TagCompound>("FoundItems").Select(ItemIO.Load).ToList();
|
||||
sortModePreference = (SortModes)tag.GetInt("SortMode");
|
||||
announcePreference = tag.GetBool("Announce");
|
||||
if (tag.ContainsKey("CollectChestItems")) // Missing tags get defaultvalue, which would be false, which isn't what we want.
|
||||
findChestItemsPreference = tag.GetBool("CollectChestItems");
|
||||
showCompletedPreference = tag.GetInt("ShowCompleted");
|
||||
|
||||
foreach (var item in foundItems)
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace ItemChecklist.UI
|
||||
public UIToggleHoverImageButton muteButton;
|
||||
public UIHoverImageButton sortButton;
|
||||
public UIHoverImageButton modFilterButton;
|
||||
public UIToggleHoverImageButton collectChestItemsButton;
|
||||
public UIPanel checklistPanel;
|
||||
public UIGrid checklistGrid;
|
||||
public static SortModes sortMode = SortModes.TerrariaSort;
|
||||
@@ -26,6 +27,7 @@ namespace ItemChecklist.UI
|
||||
public static bool visible = false;
|
||||
public static int showCompleted = 0; // 0: both, 1: unfound, 2: found
|
||||
public static bool announce = true;
|
||||
public static bool collectChestItems = true;
|
||||
public static string hoverText = "";
|
||||
|
||||
ItemSlot[] itemSlots;
|
||||
@@ -41,6 +43,7 @@ namespace ItemChecklist.UI
|
||||
// Is initialize called? (Yes it is called on reload) I want to reset nicely with new character or new loaded mods: visible = false;
|
||||
|
||||
announce = false; // overwritten by modplayer
|
||||
collectChestItems = false;
|
||||
|
||||
checklistPanel = new UIPanel();
|
||||
checklistPanel.SetPadding(10);
|
||||
@@ -76,6 +79,12 @@ namespace ItemChecklist.UI
|
||||
modFilterButton.Top.Pixels = 4;
|
||||
checklistPanel.Append(modFilterButton);
|
||||
|
||||
collectChestItemsButton = new UIToggleHoverImageButton(Main.cursorTextures[8], ItemChecklist.instance.GetTexture("closeButton"), "Toggle Collect Chest Items", collectChestItems);
|
||||
collectChestItemsButton.OnClick += ToggleFindChestItemsButtonClicked;
|
||||
collectChestItemsButton.Left.Pixels = spacing * 8 + 28 * 4;
|
||||
collectChestItemsButton.Top.Pixels = 4;
|
||||
checklistPanel.Append(collectChestItemsButton);
|
||||
|
||||
checklistGrid = new UIGrid(5);
|
||||
checklistGrid.Top.Pixels = 32f + spacing;
|
||||
checklistGrid.Width.Set(-25f, 1f);
|
||||
@@ -160,12 +169,20 @@ namespace ItemChecklist.UI
|
||||
UpdateNeeded();
|
||||
}
|
||||
|
||||
private void ToggleFindChestItemsButtonClicked(UIMouseEvent evt, UIElement listeningElement)
|
||||
{
|
||||
collectChestItems = !collectChestItems;
|
||||
Main.PlaySound(collectChestItems ? SoundID.MenuOpen : SoundID.MenuClose);
|
||||
collectChestItemsButton.SetEnabled(collectChestItems);
|
||||
}
|
||||
|
||||
internal void RefreshPreferences()
|
||||
{
|
||||
foundFilterButton.hoverText = "Cycle Found Filter: " + foundFilterStrings[showCompleted];
|
||||
sortButton.hoverText = "Cycle Sort Method: " + sortMode.ToFriendlyString();
|
||||
modFilterButton.hoverText = "Cycle Mod Filter: " + modnames[currentMod];
|
||||
muteButton.SetEnabled(announce);
|
||||
collectChestItemsButton.SetEnabled(collectChestItems);
|
||||
UpdateNeeded();
|
||||
}
|
||||
|
||||
|
||||
56
MagicStorageIntegration.cs
Normal file
56
MagicStorageIntegration.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using MagicStorage;
|
||||
using MagicStorage.Components;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace ItemChecklist
|
||||
{
|
||||
// autopause?
|
||||
static class MagicStorageIntegration
|
||||
{
|
||||
static Mod MagicStorage;
|
||||
public static bool Enabled => MagicStorage != null;
|
||||
static Point16 previousStorageAccess = new Point16(-1, -1);
|
||||
static StorageAccess tile;
|
||||
//static StorageAccess tile = null; //throws TypeInitializationException
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
MagicStorage = ModLoader.GetMod("MagicStorage");
|
||||
}
|
||||
|
||||
public static void Unload()
|
||||
{
|
||||
MagicStorage = null;
|
||||
}
|
||||
|
||||
internal static void FindItemsInStorage()
|
||||
{
|
||||
var storagePlayer = Main.LocalPlayer.GetModPlayer<StoragePlayer>();
|
||||
Point16 storageAccess = storagePlayer.ViewingStorage();
|
||||
if (storageAccess == previousStorageAccess)
|
||||
return;
|
||||
previousStorageAccess = storageAccess;
|
||||
if (!Main.playerInventory || storageAccess.X < 0 || storageAccess.Y < 0)
|
||||
return;
|
||||
ModTile modTile = TileLoader.GetTile(Main.tile[storageAccess.X, storageAccess.Y].type);
|
||||
if (modTile == null || !(modTile is StorageAccess))
|
||||
{
|
||||
return;
|
||||
}
|
||||
TEStorageHeart heart = ((StorageAccess)modTile).GetHeart(storageAccess.X, storageAccess.Y);
|
||||
if (heart == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var items = heart.GetStoredItems();
|
||||
// Will 1000 items crash the chat?
|
||||
foreach (var item in items)
|
||||
{
|
||||
ItemChecklist.instance.GetGlobalItem<ItemChecklistGlobalItem>().ItemReceived(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
author = jopojelly
|
||||
version = 0.2.2.4
|
||||
version = 0.4
|
||||
displayName = Item Checklist
|
||||
homepage = https://forums.terraria.org/index.php?threads/item-checklist-in-game-100-item-collection-checklist.52786/
|
||||
hideCode = false
|
||||
@@ -9,3 +9,4 @@ languageVersion = 6
|
||||
includePDB = true
|
||||
notworkingside = Client
|
||||
buildIgnore = .vs\*, Properties\*, *.csproj, *.user, obj\*, bin\*, *.config, lib\*, .gitignore, .git\*
|
||||
weakReferences = MagicStorage@0.4.3.1
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
Item Checklist lets you view a checklist for picking up or crafting 100% of the items in the game
|
||||
|
||||
Toggle the checklist with the hotkey assigned to it in the settings.
|
||||
|
||||
The checklist has several buttons at the top.
|
||||
|
||||
Cycle Found Filter: Filters the list to show All, only Found, or only missing items.
|
||||
Cycle Sort Method: Sorts the list by ID, Value, Alphabetical, Rarity, or the chest auto-sorting algorithm.
|
||||
Cycle Mod Filter: Lets you filter by all items, only vanilla items, or individual mods.
|
||||
Toggle Messages: Toggles the announcement chat text that happens when you pick up a new item.
|
||||
Toggle Collect Chest Items: You can toggle the behavior of counting items seen in chests as "collected".
|
||||
|
||||
If you use Magic Storage and have the Toggle Collect Chest Items enabled, you will also collect all items in storage if you access it.
|
||||
|
||||
BIN
lib/MagicStorage_v0.4.3.1.dll
Normal file
BIN
lib/MagicStorage_v0.4.3.1.dll
Normal file
Binary file not shown.
Reference in New Issue
Block a user