Repository navigation
Expand file tree
/
Copy pathCalamityKeybinds.cs
More file actions
231 lines (198 loc) · 9.84 KB
/
Copy pathCalamityKeybinds.cs
File metadata and controls
231 lines (198 loc) · 9.84 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
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
221
222
223
224
225
226
227
228
229
230
231
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using CalamityMod.Systems.Collections;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.GameInput;
using Terraria.ModLoader;
namespace CalamityMod
{
public class CalamityKeybinds : ModSystem
{
public static ModKeybind AdrenalineHotKey { get; private set; }
public static ModKeybind ArmorSetBonusHotKey { get; private set; }
public static ModKeybind DashHotkey { get; private set; }
public static ModKeybind ExoChairSlowdownHotkey { get; private set; }
public static ModKeybind GodSlayerDashHotKey { get; private set; }
public static ModKeybind NormalityRelocatorHotKey { get; private set; }
public static ModKeybind RageHotKey { get; private set; }
public static ModKeybind SwitchGravityHotkey { get; private set; }
public static ModKeybind ExpandDebuffInfo { get; private set; }
public static ModKeybind HeldItem { get; private set; }
public static ModKeybind Accessory1 { get; private set; }
public static ModKeybind Accessory2 { get; private set; }
public static ModKeybind Accessory3 { get; private set; }
public static ModKeybind Accessory4 { get; private set; }
public static ModKeybind Accessory5 { get; private set; }
public static ModKeybind Accessory6 { get; private set; }
public static ModKeybind Accessory7 { get; private set; }
public static ModKeybind[] AccessoryKeybinds = [];
public static List<int> RentedKeybinds = [];
/// <summary>
/// We store the keybind then move it to the main list at the end of the frame
/// This ensures that between frames has keybinds in the values needed for drawing
/// This does means there's a 1 frame delay when switching slots for item tooltips to update, but that's never important
/// </summary>
public static List<int> KeybindRentalQueue = [];
public override void Load()
{
// Register keybinds
AdrenalineHotKey = KeybindLoader.RegisterKeybind(Mod, "AdrenalineMode", "B");
ArmorSetBonusHotKey = KeybindLoader.RegisterKeybind(Mod, "ArmorSetBonus", "Y");
DashHotkey = KeybindLoader.RegisterKeybind(Mod, "DashDoubleTapOverride", "F");
ExoChairSlowdownHotkey = KeybindLoader.RegisterKeybind(Mod, "ExoChairSlowDown", "RightShift");
GodSlayerDashHotKey = KeybindLoader.RegisterKeybind(Mod, "GodSlayerDash", "H");
NormalityRelocatorHotKey = KeybindLoader.RegisterKeybind(Mod, "NormalityRelocator", "Z");
RageHotKey = KeybindLoader.RegisterKeybind(Mod, "RageMode", "V");
SwitchGravityHotkey = KeybindLoader.RegisterKeybind(Mod, "GravitySwapOverride", "T");
ExpandDebuffInfo = KeybindLoader.RegisterKeybind(Mod, "ExpandDebuffInfo", "LeftControl");
HeldItem = KeybindLoader.RegisterKeybind(Mod, "HeldItem", "NumPad0");
Accessory1 = KeybindLoader.RegisterKeybind(Mod, "Accessory1", "NumPad1");
Accessory2 = KeybindLoader.RegisterKeybind(Mod, "Accessory2", "NumPad2");
Accessory3 = KeybindLoader.RegisterKeybind(Mod, "Accessory3", "NumPad3");
Accessory4 = KeybindLoader.RegisterKeybind(Mod, "Accessory4", "NumPad4");
Accessory5 = KeybindLoader.RegisterKeybind(Mod, "Accessory5", "NumPad5");
Accessory6 = KeybindLoader.RegisterKeybind(Mod, "Accessory6", "NumPad6");
Accessory7 = KeybindLoader.RegisterKeybind(Mod, "Accessory7", "NumPad7");
AccessoryKeybinds = [
Accessory1,
Accessory2,
Accessory3,
Accessory4,
Accessory5,
Accessory6,
Accessory7
];
}
public override void Unload()
{
AdrenalineHotKey = null;
ArmorSetBonusHotKey = null;
DashHotkey = null;
ExoChairSlowdownHotkey = null;
GodSlayerDashHotKey = null;
NormalityRelocatorHotKey = null;
RageHotKey = null;
ExpandDebuffInfo = null;
Accessory1 = null;
Accessory2 = null;
Accessory3 = null;
Accessory4 = null;
Accessory5 = null;
Accessory6 = null;
Accessory1 = null;
Accessory7 = null;
AccessoryKeybinds = null;
}
public override void PostUpdateEverything()
{
RentedKeybinds = KeybindRentalQueue.ToList();
KeybindRentalQueue.Clear();
}
}
public class AccessoryKeybindManager : GlobalItem
{
public override bool InstancePerEntity => true;
internal int KeybindId { get; set; }
public override void UpdateEquip(Item item, Player player)
{
if (CalamityItemSets.HasAccessoryKeybind[item.type])
CalamityKeybinds.KeybindRentalQueue.Add(item.type);
}
}
public static class CalamityKeybindsExtensions
{
/// <summary>
/// Gets if the Calamity keybind for the given item was just pressed. <br/>
/// Automatically adjusts between Held Item and Accessory Ability keybinds based on if the item is held and equip order of accessories
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public static bool JustPressedKeybind(this Item item)
{
if (item == Main.LocalPlayer.HeldItem)
return CalamityKeybinds.HeldItem.JustPressed;
if (!CalamityItemSets.HasAccessoryKeybind[item.type])
Debug.Assert(false, "Item is not marked as having a Calamity keybind in the HasAccessoryKeybind item set, but is requesting an accessory keybind");
if (CalamityKeybinds.RentedKeybinds.Contains(item.type))
{
int index = CalamityKeybinds.RentedKeybinds.IndexOf(item.type);
if (CalamityKeybinds.AccessoryKeybinds.IndexInRange(index))
return CalamityKeybinds.AccessoryKeybinds[index].JustPressed;
}
return false;
}
/// <summary>
/// Gets if the Calamity keybind for the given item was just released. <br/>
/// Automatically adjusts between Held Item and Accessory Ability keybinds based on if the item is held and equip order of accessories
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public static bool JustReleasedKeybind(this Item item)
{
if (item == Main.LocalPlayer.HeldItem)
return CalamityKeybinds.HeldItem.JustReleased;
if (!CalamityItemSets.HasAccessoryKeybind[item.type])
Debug.Assert(false, "Item is not marked as having a Calamity keybind in the HasAccessoryKeybind item set, but is requesting an accessory keybind");
if (CalamityKeybinds.RentedKeybinds.Contains(item.type))
{
int index = CalamityKeybinds.RentedKeybinds.IndexOf(item.type);
if (CalamityKeybinds.AccessoryKeybinds.IndexInRange(index))
return CalamityKeybinds.AccessoryKeybinds[index].JustReleased;
}
return false;
}
/// <summary>
/// Gets if the Calamity keybind for the given item is currently held down. <br/>
/// Automatically adjusts between Held Item and Accessory Ability keybinds based on if the item is held and equip order of accessories
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public static bool CurrentlyPressingKeybind(this Item item)
{
if (item == Main.LocalPlayer.HeldItem)
return CalamityKeybinds.HeldItem.Current;
if (!CalamityItemSets.HasAccessoryKeybind[item.type])
Debug.Assert(false, "Item is not marked as having a Calamity keybind in the HasAccessoryKeybind item set, but is requesting an accessory keybind");
if (CalamityKeybinds.RentedKeybinds.Contains(item.type))
{
int index = CalamityKeybinds.RentedKeybinds.IndexOf(item.type);
if (CalamityKeybinds.AccessoryKeybinds.IndexInRange(index))
return CalamityKeybinds.AccessoryKeybinds[index].Current;
}
return false;
}
/// <summary>
/// Gets the Calamity keybind for the given item. <br/>
/// Automatically adjusts between Held Item and Accessory Ability keybinds based on if the item is held and equip order of accessories
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public static ModKeybind? GetDynamicModHotkey(this Item item)
{
if (!CalamityItemSets.HasAccessoryKeybind[item.type])
return CalamityKeybinds.HeldItem;
if (CalamityKeybinds.RentedKeybinds.Contains(item.type))
{
int index = CalamityKeybinds.RentedKeybinds.IndexOf(item.type);
if (CalamityKeybinds.AccessoryKeybinds.IndexInRange(index))
return CalamityKeybinds.AccessoryKeybinds[index];
}
return null;
}
public static bool HasBoundDynamicHotkey(this Item item)
{
var h = item.GetDynamicModHotkey();
if (h == null) return false;
if (h?.GetAssignedKeysOrEmpty(PlayerInput.CurrentInputMode).Count == 0)
return false;
return true;
}
}
}