-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathDecraftingGUI.cs
More file actions
156 lines (131 loc) · 5.81 KB
/
DecraftingGUI.cs
File metadata and controls
156 lines (131 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using MagicStorage.Common.Systems;
using MagicStorage.Common.Systems.Shimmering;
using MagicStorage.Common.Threading;
using MagicStorage.Common.Threading.Refreshing;
using MagicStorage.Components;
using MagicStorage.UI.States;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace MagicStorage {
public static partial class DecraftingGUI {
internal static readonly ShimmeringRefreshThread NullThread = null;
internal static readonly List<int> viewingItems = new();
internal static readonly List<bool> itemAvailable = new();
internal static int selectedItem = -1;
// Used to cache the reports for use by StoredIngredientsRefreshThread
internal static readonly List<ItemReport> cachedShimmerReports = [];
internal static void Unload() => ClearAllCollections(callCraftingClear: true);
internal static void ClearAllCollections(bool callCraftingClear) {
if (callCraftingClear)
CraftingGUI.ClearAllCollections();
ResetRefreshCache();
viewingItems.Clear();
itemAvailable.Clear();
resultItems.Clear();
resultItemsInfo.Clear();
selectedItem = -1;
StorageGUI.hasAnyErrorItems = false;
}
internal static TEStorageHeart GetHeart() => StoragePlayer.LocalPlayer.GetStorageHeart();
internal static TEDecraftingAccess GetDecraftingEntity() => StoragePlayer.LocalPlayer.GetDecraftingAccess();
internal static Item DoWithdraw(Item toWithdraw, bool toInventory = false) {
TEStorageHeart heart = GetHeart();
if (heart is null)
return new Item();
using var _ = SecuritySystem.CreateAccessContext();
if (Main.netMode == NetmodeID.MultiplayerClient) {
ModPacket packet = heart.PrepareClientRequest(toInventory ? TEStorageHeart.Operation.WithdrawToInventoryThenTryModuleInventory : TEStorageHeart.Operation.WithdrawThenTryModuleInventory);
ItemIO.Send(toWithdraw, packet, true, true);
packet.Send();
return new Item();
}
Item withdrawn = heart.Withdraw(toWithdraw, false);
if (withdrawn.IsAir)
withdrawn = CraftingGUI.TryToWithdrawFromModuleItems(heart, toWithdraw, false);
return withdrawn;
}
internal static void SetSelectedItem(int item) {
NetHelper.Report(true, "Reassigning current item and refreshing recipe panel...");
CraftingGUI.craftAmountTarget = 1;
CraftingGUI.blockStorageItems.Clear();
CreateSelectedItemRefreshThread(item, 1, caller: "DecraftingGUI.SetSelectedItem()").Start();
}
public static RefreshThread CreateFullRefreshThread(string caller) {
var thread = FullRefreshBuilder.Instance.CreateThread();
thread.SetDebugName($"{caller} thread");
return thread;
}
public static RefreshThread CreateItemListRefreshThread(string caller) {
// Force all items to be recalculated
if (MagicUI.IgnoreSpecificZoneRefreshing)
itemsToRefresh = null;
var thread = new ItemListRefreshThread(
controls: CraftingGUI.CreateRefreshThreadControls(MagicUI.decraftingUI),
processedStorage: new(
staticWasModuleItemTable: CraftingGUI.wasModuleItem,
staticModuleItemWasFromInventoryTable: CraftingGUI.moduleItemWasFromInventory,
staticResultItemsList: CraftingGUI.items,
staticResultItemGroupsList: CraftingGUI.itemGroups,
staticResultItemsFromModulesList: CraftingGUI.sourceItemsFromModules,
staticCountsDictionary: CraftingGUI.itemCounts,
staticCountsByPrefixDictionary: CraftingGUI.itemCountsByPrefix
),
mainZoneControls: new(
zoneObjectFilterChoice: MagicUI.decraftingUI.GetDefaultPage<DecraftingUIState.ShimmeringPage>().recipeButtons.Choice,
favorited: StoragePlayer.LocalPlayer.FavoritedShimmerItems,
hidden: StoragePlayer.LocalPlayer.HiddenShimmerItems,
configBlacklist: MagicStorageConfig.GlobalShimmerItemBlacklist
),
mainZoneResults: new(
objectsToRefresh: itemsToRefresh,
staticObjectList: viewingItems,
staticAvailableList: itemAvailable
),
ingredientControls: new(
staticShowAllIngredientsField: new ConstantValueProvider<bool>(false),
staticInfiniteItemsSet: CraftingGUI.isItemInfinite,
staticBlockedList: CraftingGUI.blockStorageItems,
staticCreativeUnitField: new CraftingGUI.CreativeUnitPresentProvider()
)
);
thread.SetDebugName($"{caller} thread");
return thread;
}
public static RefreshThread CreateSelectedItemRefreshThread(int selectedItem, int craftAmountTarget, string caller) {
var thread = new ShimmerInfoPanelRefreshThread(
controls: CraftingGUI.CreateRefreshThreadControls(MagicUI.decraftingUI),
processedStorage: new(
staticWasModuleItemTable: CraftingGUI.wasModuleItem,
staticModuleItemWasFromInventoryTable: CraftingGUI.moduleItemWasFromInventory,
staticResultItemsList: CraftingGUI.items,
staticResultItemGroupsList: CraftingGUI.itemGroups,
staticResultItemsFromModulesList: CraftingGUI.sourceItemsFromModules,
staticCountsDictionary: CraftingGUI.itemCounts,
staticCountsByPrefixDictionary: CraftingGUI.itemCountsByPrefix
),
ingredientControls: new(
staticShowAllIngredientsField: new ConstantValueProvider<bool>(false),
staticInfiniteItemsSet: CraftingGUI.isItemInfinite,
staticBlockedList: CraftingGUI.blockStorageItems,
staticCreativeUnitField: new CraftingGUI.CreativeUnitPresentProvider()
),
craftingObject: new(
selection: new SelectionProvider(selectedItem),
craftAmountTarget: new CraftingGUI.CraftAmountTargetProvider(craftAmountTarget)
),
recipeItems: new ZoneResultsRecipeItemsProvider(
staticStoredIngredientsList: CraftingGUI.storageItems,
staticStoredIngredientsInfoList: CraftingGUI.storageItemInfo,
staticResultItemsList: resultItems,
staticResultItemsInfoList: resultItemsInfo
),
staticReportCacheList: cachedShimmerReports
);
thread.SetDebugName($"{caller} thread");
return thread;
}
}
}