-
Notifications
You must be signed in to change notification settings - Fork 1
/
OffHandidiotmod.cs
220 lines (191 loc) · 6.39 KB
/
OffHandidiotmod.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
218
219
220
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using Microsoft.Xna.Framework;
using Newtonsoft.Json;
using Terraria;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
using Terraria.UI;
namespace OffHandidiotmod
{
public class OffHandidiotmod : Mod
{
public static UserInterface _myUserInterface;
public static MySlotUI SlotUI;
public override void Load()
{
// You can only display the UI to the local player -- prevent an error message!
if (!Main.dedServ)
{
_myUserInterface = new UserInterface();
SlotUI = new MySlotUI();
SlotUI.Activate();
_myUserInterface.SetState(SlotUI);
}
}
public override void Unload()
{
// Ensure that you unload the UI's event handlers here
SlotUI.Unload();
}
internal static void SaveConfig(OffHandConfig configInstance) // yoinked from calamitymod
{
// There is no current way to manually save a mod configuration file in tModLoader.
// The method which saves mod config files is private in ConfigManager, so reflection is used to invoke it.
try
{
MethodInfo saveMethodInfo = typeof(ConfigManager).GetMethod("Save", BindingFlags.Static | BindingFlags.NonPublic);
if (saveMethodInfo is not null)
{
saveMethodInfo.Invoke(null, [configInstance]);
}
else
{
string ContactDev = Language.GetTextValue("Mods.OffHandidiotmod.TextMessages.ContactDev");
Main.NewText($"Modconfig save reflection failed. {ContactDev}");
}
}
catch
{
}
}
}
public class Activation : ModSystem
{
public static MethodInfo getCooldownsMethod;
public static object calamityConfigInstance;
public static PropertyInfo cooldownDisplayProperty;
public override void PostSetupContent()
{
if (ModLoader.TryGetMod("CalamityMod", out Mod Calamity)) // Calamity mod
{
try
{
MySlotUI.Calamity = Calamity;
//calamity cooldown method
Type calamityUtilsType = Calamity.Code.GetType("CalamityMod.CalamityUtils");
getCooldownsMethod = calamityUtilsType.GetMethod("GetDisplayedCooldowns", BindingFlags.Public | BindingFlags.Static);
//calamity config's cooldownrack setting
calamityConfigInstance = Calamity.GetConfig("CalamityConfig");
cooldownDisplayProperty = calamityConfigInstance.GetType().GetProperty("CooldownDisplay");
}
catch (Exception exception)
{
MySlotUI.Calamity = null;
Mod.Logger.Warn($"Error setting up calamity compatibility with offhand mod. {exception}");
}
}
else
{
MySlotUI.Calamity = null;
}
if (ModLoader.TryGetMod("ImproveGame", out _)) // Quality of terraria mod that adds stupid ass 20 trash slots
{
MySlotUI.QoTEnabled = true;
}
else
{
MySlotUI.QoTEnabled = false;
}
}
public override void UpdateUI(GameTime gameTime)
{
OffHandidiotmod._myUserInterface?.Update(gameTime);
}
// Make sure the UI can draw
public override void ModifyInterfaceLayers(List<GameInterfaceLayer> layers)
{
// This will draw on the same layer as the inventory
int inventoryLayer = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Inventory"));
if (inventoryLayer != -1)
{
layers.Insert(
inventoryLayer,
new LegacyGameInterfaceLayer("My Mod: My Slot UI", () =>
{
if (OffHandidiotmod.SlotUI.Visible)
{
OffHandidiotmod._myUserInterface.Draw(Main.spriteBatch, new GameTime());
}
return true;
},
InterfaceScaleType.UI));
}
}
public static ModKeybind SwapKeybind { get; private set; }
public static ModKeybind UseOffhandKeybind { get; private set; }
public override void Load()
{
// Register new keybind
SwapKeybind = KeybindLoader.RegisterKeybind(Mod, "Swap Offhand", "Q");
UseOffhandKeybind = KeybindLoader.RegisterKeybind(Mod, "Use Offhand Item", "Mouse2");
}
public override void Unload()
{
SwapKeybind = null;
UseOffhandKeybind = null;
}
}
public class OffHandConfig : ModConfig
{
public static OffHandConfig Instance => ModContent.GetInstance<OffHandConfig>();
public override ConfigScope Mode => ConfigScope.ClientSide;
[JsonProperty("PosYInventory")]
[DefaultValue(260f)]
private float _PosYInventory; // 260
[JsonIgnore]
public float PosYInventory { get => _PosYInventory; set => _PosYInventory = value; }
[JsonProperty("PosYHUD")]
[DefaultValue(79f)]
private float _PosYHUD;// 79
[JsonIgnore]
public float PosYHUD { get => _PosYHUD; set => _PosYHUD = value; }
[JsonProperty("PosXInventory")]
[DefaultValue(20f)]
private float _PosXInventory;// 20
[JsonIgnore]
public float PosXInventory { get => _PosXInventory; set => _PosXInventory = value; }
[JsonProperty("PosXHUD")]
[DefaultValue(25f)]
private float _PosXHUD; // 25
[JsonIgnore]
public float PosXHUD { get => _PosXHUD; set => _PosXHUD = value; }
[LabelKey("$Mods.OffHandidiotmod.Configs.OffHandConfig.Label")]
[DefaultValue(true)]
public bool ChatMessageToggle;
[Header("$Mods.OffHandidiotmod.Configs.OffHandConfig.HUDHeader")]
[TooltipKey("$Mods.OffHandidiotmod.Configs.OffHandConfig.SlotOffsetXHUD.Tooltip")]
[DefaultValue(0)]
[Range(-100, 100)]
public int SlotOffsetXHUD;
[TooltipKey("$Mods.OffHandidiotmod.Configs.OffHandConfig.SlotOffsetYHUD.Tooltip")]
[DefaultValue(0)]
[Range(-100, 100)]
public int SlotOffsetYHUD;
[Header("$Mods.OffHandidiotmod.Configs.OffHandConfig.InventoryHeader")]
[TooltipKey("$Mods.OffHandidiotmod.Configs.OffHandConfig.SlotOffsetXInventory.Tooltip")]
[DefaultValue(0)]
[Range(-100, 100)]
public int SlotOffsetXInventory;
[TooltipKey("$Mods.OffHandidiotmod.Configs.OffHandConfig.SlotOffsetYInventory.Tooltip")]
[DefaultValue(0)]
[Range(-100, 100)]
public int SlotOffsetYInventory;
[Header("$Mods.OffHandidiotmod.Configs.OffHandConfig.DraggingHeader")]
[LabelKey("$Mods.OffHandidiotmod.Configs.OffHandConfig.DraggingEnabled.Label")]
[TooltipKey("$Mods.OffHandidiotmod.Configs.OffHandConfig.DraggingEnabled.Tooltip")]
[DefaultValue(false)]
public bool DraggingEnabled;
[Header("$Mods.OffHandidiotmod.Configs.OffHandConfig.PriorityListHeader")]
[LabelKey("$Mods.OffHandidiotmod.Configs.OffHandConfig.PriorityList.Label")]
[TooltipKey("$Mods.OffHandidiotmod.Configs.OffHandConfig.PriorityList.Tooltip")]
public List<ItemDefinition> ItemPriorityList { get; set; } = [];
public override void OnChanged()
{
MyPlayer.priorityListChanged = true;
}
}
}