-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathMagicStorageConfig.cs
217 lines (158 loc) · 6.55 KB
/
MagicStorageConfig.cs
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using MagicStorage.Common.Players;
using MagicStorage.Common.Systems.RecurrentRecipes;
using MagicStorage.UI.States;
using Newtonsoft.Json;
using Terraria;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnassignedField.Global
namespace MagicStorage {
public class MagicStorageConfig : ModConfig
{
[Header($"$Mods.MagicStorage.Config.Headers.Storage")]
[DefaultValue(true)]
public bool quickStackDepositMode;
[Header($"$Mods.MagicStorage.Config.Headers.Crafting")]
[DefaultValue(true)]
public bool useConfigFilter;
[DefaultValue(false)]
public bool showAllRecipes;
[DefaultValue(false)]
public bool useOldCraftMenu;
[DefaultValue(false)]
public bool recipeBlacklist;
// TODO: remove custom json converter when tml fix ItemDefinition format error
[JsonProperty(ItemConverterType = typeof(ItemDefinitionToFromStringJsonConverter))]
[Expand(false)]
public HashSet<ItemDefinition> globalRecipeBlacklist = new();
[JsonProperty(ItemConverterType = typeof(ItemDefinitionToFromStringJsonConverter))]
[Expand(false)]
public HashSet<ItemDefinition> globalShimmerItemBlacklist = new();
[DefaultValue(false)]
public bool clearHistory;
[DefaultValue(0)]
[DrawTicks]
[Range(-1, 10)]
public int recursionCraftingDepth; // Renamed in v0.6.0.2 to force a value reset
[Header($"$Mods.MagicStorage.Config.Headers.StorageAndCrafting")]
[DefaultValue(false)]
public bool glowNewItems;
[DefaultValue(true)]
public bool clearSearchText;
[DefaultValue(true)]
public bool searchBarRefreshOnKey;
[DefaultValue(false)]
public bool uiFavorites;
[DefaultValue(true)]
[ReloadRequired]
public bool extraFilterIcons;
[DefaultValue(ButtonConfigurationMode.Legacy)]
[DrawTicks]
public ButtonConfigurationMode buttonLayout;
[Header($"$Mods.MagicStorage.Config.Headers.General")]
[DefaultValue(false)]
public bool itemDataDebug; //Previously "allowItemDataDebug"
[DefaultValue(true)]
public bool canMovePanels;
[DefaultValue(true)]
public bool automatonRemembers;
public static MagicStorageConfig Instance => ModContent.GetInstance<MagicStorageConfig>();
[JsonIgnore]
public static bool GlowNewItems => Instance.glowNewItems;
[JsonIgnore]
public static bool UseConfigFilter => Instance.useConfigFilter;
[JsonIgnore]
public static bool ShowAllRecipes => Instance.showAllRecipes;
[JsonIgnore]
public static bool QuickStackDepositMode => Instance.quickStackDepositMode;
[JsonIgnore]
public static bool ClearSearchText => Instance.clearSearchText;
[JsonIgnore]
public static bool ExtraFilterIcons => Instance.extraFilterIcons;
[JsonIgnore]
public static bool UseOldCraftMenu => Instance.useOldCraftMenu;
[JsonIgnore]
public static bool ItemDataDebug => Instance.itemDataDebug;
[JsonIgnore]
public static bool SearchBarRefreshOnKey => Instance.searchBarRefreshOnKey;
[JsonIgnore]
public static bool CraftingFavoritingEnabled => Instance.uiFavorites;
[JsonIgnore]
public static bool RecipeBlacklistEnabled => Instance.recipeBlacklist;
[JsonIgnore]
public static HashSet<ItemDefinition> GlobalRecipeBlacklist => Instance.globalRecipeBlacklist;
[JsonIgnore]
public static HashSet<ItemDefinition> GlobalShimmerItemBlacklist => Instance.globalShimmerItemBlacklist;
[JsonIgnore]
public static ButtonConfigurationMode ButtonUIMode => Instance.buttonLayout;
[JsonIgnore]
public static bool ClearRecipeHistory => Instance.clearHistory;
[JsonIgnore]
public static bool CanMoveUIPanels => Instance.canMovePanels;
[JsonIgnore]
public static int RecipeRecursionDepth => Instance.recursionCraftingDepth;
[JsonIgnore]
public static bool IsRecursionEnabled => RecipeRecursionDepth != 0;
[JsonIgnore]
public static bool IsRecursionInfinite => RecipeRecursionDepth == -1;
[JsonIgnore]
public static bool DisplayLastSeenAutomatonTip => Instance.automatonRemembers;
public override ConfigScope Mode => ConfigScope.ClientSide;
// TODO: remove custom json converter when tml fix ItemDefinition format error
private sealed class ItemDefinitionToFromStringJsonConverter : JsonConverter<ItemDefinition> {
public override ItemDefinition ReadJson(JsonReader reader, Type objectType, ItemDefinition existingValue, bool hasExistingValue, JsonSerializer serializer) {
return ItemDefinition.FromString((string)reader.Value);
}
public override void WriteJson(JsonWriter writer, ItemDefinition value, JsonSerializer serializer) {
writer.WriteValue(value.ToString());
}
}
}
public class MagicStorageServerConfig : ModConfig {
public override ConfigScope Mode => ConfigScope.ServerSide;
public static MagicStorageServerConfig Instance => ModContent.GetInstance<MagicStorageServerConfig>();
[DefaultValue(true)]
public bool allowAutomatonToMoveIn;
[DefaultValue(false)]
public bool auditLog;
[JsonIgnore]
public static bool AllowAutomatonToMoveIn => Instance.allowAutomatonToMoveIn;
[JsonIgnore]
public static bool ReportClientStorageUsage => Instance.auditLog;
public override bool AcceptClientChanges(ModConfig pendingConfig, int whoAmI, ref NetworkText message) {
if (Main.player[whoAmI].GetModPlayer<OperatorPlayer>().hasOp)
return true;
message = Mod.GetLocalization("ServerOperator.ConfigChangeDenied").ToNetworkText();
return false;
}
}
#if NETPLAY
/// <summary>
/// The config for beta builds. Make sure to wrap uses of this class with <c>#if NETPLAY</c>
/// </summary>
public class MagicStorageBetaConfig : ModConfig {
// Old path required since autogenerated localization may not exist when NETPLAY isn't defined
public override LocalizedText DisplayName => Language.GetText("Mods.MagicStorage.Config.BetaLabel");
public override ConfigScope Mode => ConfigScope.ClientSide;
public static MagicStorageBetaConfig Instance => ModContent.GetInstance<MagicStorageBetaConfig>();
[LabelKey("$Mods.MagicStorage.Config.PrintTextToChat.Label")]
[TooltipKey("$Mods.MagicStorage.Config.PrintTextToChat.Tooltip")]
[DefaultValue(false)]
public bool printTextToChat;
[LabelKey("$Mods.MagicStorage.Config.ShowDebugPylonRangeAreas.Label")]
[TooltipKey("$Mods.MagicStorage.Config.ShowDebugPylonRangeAreas.Tooltip")]
[DefaultValue(false)]
public bool showPylonAreas;
[JsonIgnore]
public static bool PrintTextToChat => Instance.printTextToChat;
[JsonIgnore]
public static bool ShowDebugPylonRangeAreas => Instance.showPylonAreas;
}
#endif
}