Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PlayerInputProfile.cs
Go to the documentation of this file.
1using System;
3using Microsoft.Xna.Framework.Input;
4using Newtonsoft.Json;
5using Newtonsoft.Json.Linq;
6
7namespace Terraria.GameInput;
8
10{
12 {
13 {
14 InputMode.Keyboard,
16 },
17 {
18 InputMode.KeyboardUI,
20 },
21 {
22 InputMode.XBoxGamepad,
24 },
25 {
26 InputMode.XBoxGamepadUI,
28 }
29 };
30
31 public string Name = "";
32
33 public bool AllowEditting = true;
34
36
37 public float TriggersDeadzone = 0.3f;
38
39 public float InterfaceDeadzoneX = 0.2f;
40
41 public float LeftThumbstickDeadzoneX = 0.25f;
42
43 public float LeftThumbstickDeadzoneY = 0.4f;
44
46
48
50
52
54
56
57 public int InventoryMoveCD = 6;
58
59 public string ShowName => Name;
60
62
63 public PlayerInputProfile(string name)
64 {
65 Name = name;
66 }
67
68 public void Initialize(PresetProfiles style)
69 {
71 {
72 inputMode.Value.SetupKeys();
73 PlayerInput.Reset(inputMode.Value, style, inputMode.Key);
74 }
75 }
76
78 {
79 //IL_0035: Unknown result type (might be due to invalid IL or missing references)
80 //IL_003f: Expected O, but got Unknown
81 //IL_0065: Unknown result type (might be due to invalid IL or missing references)
82 //IL_006f: Expected O, but got Unknown
83 //IL_0095: Unknown result type (might be due to invalid IL or missing references)
84 //IL_009f: Expected O, but got Unknown
85 //IL_00c5: Unknown result type (might be due to invalid IL or missing references)
86 //IL_00cf: Expected O, but got Unknown
87 //IL_0304: Unknown result type (might be due to invalid IL or missing references)
88 //IL_030e: Expected O, but got Unknown
89 int num = 0;
90 if (dict.TryGetValue("Last Launched Version", out var value))
91 {
92 num = (int)(long)value;
93 }
94 if (dict.TryGetValue("Mouse And Keyboard", out value))
95 {
96 InputModes[InputMode.Keyboard].ReadPreferences(JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(((object)(JObject)value).ToString()));
97 }
98 if (dict.TryGetValue("Gamepad", out value))
99 {
100 InputModes[InputMode.XBoxGamepad].ReadPreferences(JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(((object)(JObject)value).ToString()));
101 }
102 if (dict.TryGetValue("Mouse And Keyboard UI", out value))
103 {
104 InputModes[InputMode.KeyboardUI].ReadPreferences(JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(((object)(JObject)value).ToString()));
105 }
106 if (dict.TryGetValue("Gamepad UI", out value))
107 {
108 InputModes[InputMode.XBoxGamepadUI].ReadPreferences(JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(((object)(JObject)value).ToString()));
109 }
110 if (num < 190)
111 {
112 InputModes[InputMode.Keyboard].KeyStatus["ViewZoomIn"] = new List<string>();
113 InputModes[InputMode.Keyboard].KeyStatus["ViewZoomIn"].AddRange(PlayerInput.OriginalProfiles["Redigit's Pick"].InputModes[InputMode.Keyboard].KeyStatus["ViewZoomIn"]);
114 InputModes[InputMode.Keyboard].KeyStatus["ViewZoomOut"] = new List<string>();
115 InputModes[InputMode.Keyboard].KeyStatus["ViewZoomOut"].AddRange(PlayerInput.OriginalProfiles["Redigit's Pick"].InputModes[InputMode.Keyboard].KeyStatus["ViewZoomOut"]);
116 }
117 if (num < 218)
118 {
119 InputModes[InputMode.Keyboard].KeyStatus["ToggleCreativeMenu"] = new List<string>();
120 InputModes[InputMode.Keyboard].KeyStatus["ToggleCreativeMenu"].AddRange(PlayerInput.OriginalProfiles["Redigit's Pick"].InputModes[InputMode.Keyboard].KeyStatus["ToggleCreativeMenu"]);
121 }
122 if (num < 227)
123 {
124 List<string> list = InputModes[InputMode.KeyboardUI].KeyStatus["MouseLeft"];
125 string item = "Mouse1";
126 if (!list.Contains(item))
127 {
128 list.Add(item);
129 }
130 }
131 if (num < 265)
132 {
133 string[] array = new string[4] { "Loadout1", "Loadout2", "Loadout3", "ToggleCameraMode" };
134 foreach (string key in array)
135 {
136 InputModes[InputMode.Keyboard].KeyStatus[key] = new List<string>(PlayerInput.OriginalProfiles["Redigit's Pick"].InputModes[InputMode.Keyboard].KeyStatus[key]);
137 }
138 }
139 if (dict.TryGetValue("Settings", out value))
140 {
142 if (dictionary.TryGetValue("Edittable", out value))
143 {
145 }
146 if (dictionary.TryGetValue("Gamepad - HotbarRadialHoldTime", out value))
147 {
149 }
150 if (dictionary.TryGetValue("Gamepad - LeftThumbstickDeadzoneX", out value))
151 {
152 LeftThumbstickDeadzoneX = (float)(double)value;
153 }
154 if (dictionary.TryGetValue("Gamepad - LeftThumbstickDeadzoneY", out value))
155 {
156 LeftThumbstickDeadzoneY = (float)(double)value;
157 }
158 if (dictionary.TryGetValue("Gamepad - RightThumbstickDeadzoneX", out value))
159 {
160 RightThumbstickDeadzoneX = (float)(double)value;
161 }
162 if (dictionary.TryGetValue("Gamepad - RightThumbstickDeadzoneY", out value))
163 {
164 RightThumbstickDeadzoneY = (float)(double)value;
165 }
166 if (dictionary.TryGetValue("Gamepad - LeftThumbstickInvertX", out value))
167 {
169 }
170 if (dictionary.TryGetValue("Gamepad - LeftThumbstickInvertY", out value))
171 {
173 }
174 if (dictionary.TryGetValue("Gamepad - RightThumbstickInvertX", out value))
175 {
177 }
178 if (dictionary.TryGetValue("Gamepad - RightThumbstickInvertY", out value))
179 {
181 }
182 if (dictionary.TryGetValue("Gamepad - TriggersDeadzone", out value))
183 {
184 TriggersDeadzone = (float)(double)value;
185 }
186 if (dictionary.TryGetValue("Gamepad - InterfaceDeadzoneX", out value))
187 {
188 InterfaceDeadzoneX = (float)(double)value;
189 }
190 if (dictionary.TryGetValue("Gamepad - InventoryMoveCD", out value))
191 {
192 InventoryMoveCD = (int)(long)value;
193 }
194 }
195 return true;
196 }
197
199 {
202 dictionary.Add("Last Launched Version", 279);
203 dictionary2.Add("Edittable", AllowEditting);
204 dictionary2.Add("Gamepad - HotbarRadialHoldTime", HotbarRadialHoldTimeRequired);
205 dictionary2.Add("Gamepad - LeftThumbstickDeadzoneX", LeftThumbstickDeadzoneX);
206 dictionary2.Add("Gamepad - LeftThumbstickDeadzoneY", LeftThumbstickDeadzoneY);
207 dictionary2.Add("Gamepad - RightThumbstickDeadzoneX", RightThumbstickDeadzoneX);
208 dictionary2.Add("Gamepad - RightThumbstickDeadzoneY", RightThumbstickDeadzoneY);
209 dictionary2.Add("Gamepad - LeftThumbstickInvertX", LeftThumbstickInvertX);
210 dictionary2.Add("Gamepad - LeftThumbstickInvertY", LeftThumbstickInvertY);
211 dictionary2.Add("Gamepad - RightThumbstickInvertX", RightThumbstickInvertX);
212 dictionary2.Add("Gamepad - RightThumbstickInvertY", RightThumbstickInvertY);
213 dictionary2.Add("Gamepad - TriggersDeadzone", TriggersDeadzone);
214 dictionary2.Add("Gamepad - InterfaceDeadzoneX", InterfaceDeadzoneX);
215 dictionary2.Add("Gamepad - InventoryMoveCD", InventoryMoveCD);
216 dictionary.Add("Settings", dictionary2);
217 dictionary.Add("Mouse And Keyboard", InputModes[InputMode.Keyboard].WritePreferences());
218 dictionary.Add("Gamepad", InputModes[InputMode.XBoxGamepad].WritePreferences());
219 dictionary.Add("Mouse And Keyboard UI", InputModes[InputMode.KeyboardUI].WritePreferences());
220 dictionary.Add("Gamepad UI", InputModes[InputMode.XBoxGamepadUI].WritePreferences());
221 return dictionary;
222 }
223
225 {
226 if (PlayerInput.OriginalProfiles.ContainsKey(Name))
227 {
228 foreach (KeyValuePair<string, List<string>> item in PlayerInput.OriginalProfiles[Name].InputModes[nm].WritePreferences())
229 {
230 bool flag = true;
231 if (dict.TryGetValue(item.Key, out var value))
232 {
233 if (value.Count != item.Value.Count)
234 {
235 flag = false;
236 }
237 if (!flag)
238 {
239 for (int i = 0; i < value.Count; i++)
240 {
241 if (value[i] != item.Value[i])
242 {
243 flag = false;
244 break;
245 }
246 }
247 }
248 }
249 else
250 {
251 flag = false;
252 }
253 if (flag)
254 {
255 dict.Remove(item.Key);
256 }
257 }
258 }
259 if (dict.Count > 0)
260 {
261 dicttouse.Add(k, dict);
262 }
263 }
264
266 {
268 {
269 dicttouse.Add(a, b);
270 }
271 }
272
274 {
275 string[] keysToCopy = new string[23]
276 {
277 "MouseLeft", "MouseRight", "Up", "Down", "Left", "Right", "Jump", "Grapple", "SmartSelect", "SmartCursor",
278 "QuickMount", "QuickHeal", "QuickMana", "QuickBuff", "Throw", "Inventory", "ViewZoomIn", "ViewZoomOut", "Loadout1", "Loadout2",
279 "Loadout3", "ToggleCreativeMenu", "ToggleCameraMode"
280 };
282 }
283
285 {
286 string[] keysToCopy = new string[12]
287 {
288 "HotbarMinus", "HotbarPlus", "Hotbar1", "Hotbar2", "Hotbar3", "Hotbar4", "Hotbar5", "Hotbar6", "Hotbar7", "Hotbar8",
289 "Hotbar9", "Hotbar10"
290 };
292 }
293
295 {
296 string[] keysToCopy = new string[6] { "MapZoomIn", "MapZoomOut", "MapAlphaUp", "MapAlphaDown", "MapFull", "MapStyle" };
298 }
299
301 {
302 string[] keysToCopy = new string[10] { "RadialHotbar", "RadialQuickbar", "DpadSnap1", "DpadSnap2", "DpadSnap3", "DpadSnap4", "DpadRadial1", "DpadRadial2", "DpadRadial3", "DpadRadial4" };
304 CopyKeysFrom(profile, InputMode.XBoxGamepadUI, keysToCopy);
305 }
306
308 {
309 TriggersDeadzone = profile.TriggersDeadzone;
310 InterfaceDeadzoneX = profile.InterfaceDeadzoneX;
311 LeftThumbstickDeadzoneX = profile.LeftThumbstickDeadzoneX;
312 LeftThumbstickDeadzoneY = profile.LeftThumbstickDeadzoneY;
313 RightThumbstickDeadzoneX = profile.RightThumbstickDeadzoneX;
314 RightThumbstickDeadzoneY = profile.RightThumbstickDeadzoneY;
315 LeftThumbstickInvertX = profile.LeftThumbstickInvertX;
316 LeftThumbstickInvertY = profile.LeftThumbstickInvertY;
317 RightThumbstickInvertX = profile.RightThumbstickInvertX;
318 RightThumbstickInvertY = profile.RightThumbstickInvertY;
319 InventoryMoveCD = profile.InventoryMoveCD;
320 }
321
323 {
324 for (int i = 0; i < keysToCopy.Length; i++)
325 {
326 if (profile.InputModes[mode].KeyStatus.TryGetValue(keysToCopy[i], out var value))
327 {
328 InputModes[mode].KeyStatus[keysToCopy[i]].Clear();
329 InputModes[mode].KeyStatus[keysToCopy[i]].AddRange(value);
330 }
331 }
332 }
333
334 public bool UsingDpadHotbar()
335 {
336 if (InputModes[InputMode.XBoxGamepad].KeyStatus["DpadRadial1"].Contains(Buttons.DPadUp.ToString()) && InputModes[InputMode.XBoxGamepad].KeyStatus["DpadRadial2"].Contains(Buttons.DPadRight.ToString()) && InputModes[InputMode.XBoxGamepad].KeyStatus["DpadRadial3"].Contains(Buttons.DPadDown.ToString()) && InputModes[InputMode.XBoxGamepad].KeyStatus["DpadRadial4"].Contains(Buttons.DPadLeft.ToString()) && InputModes[InputMode.XBoxGamepadUI].KeyStatus["DpadRadial1"].Contains(Buttons.DPadUp.ToString()) && InputModes[InputMode.XBoxGamepadUI].KeyStatus["DpadRadial2"].Contains(Buttons.DPadRight.ToString()) && InputModes[InputMode.XBoxGamepadUI].KeyStatus["DpadRadial3"].Contains(Buttons.DPadDown.ToString()))
337 {
338 return InputModes[InputMode.XBoxGamepadUI].KeyStatus["DpadRadial4"].Contains(Buttons.DPadLeft.ToString());
339 }
340 return false;
341 }
342
343 public bool UsingDpadMovekeys()
344 {
345 if (InputModes[InputMode.XBoxGamepad].KeyStatus["DpadSnap1"].Contains(Buttons.DPadUp.ToString()) && InputModes[InputMode.XBoxGamepad].KeyStatus["DpadSnap2"].Contains(Buttons.DPadRight.ToString()) && InputModes[InputMode.XBoxGamepad].KeyStatus["DpadSnap3"].Contains(Buttons.DPadDown.ToString()) && InputModes[InputMode.XBoxGamepad].KeyStatus["DpadSnap4"].Contains(Buttons.DPadLeft.ToString()) && InputModes[InputMode.XBoxGamepadUI].KeyStatus["DpadSnap1"].Contains(Buttons.DPadUp.ToString()) && InputModes[InputMode.XBoxGamepadUI].KeyStatus["DpadSnap2"].Contains(Buttons.DPadRight.ToString()) && InputModes[InputMode.XBoxGamepadUI].KeyStatus["DpadSnap3"].Contains(Buttons.DPadDown.ToString()))
346 {
347 return InputModes[InputMode.XBoxGamepadUI].KeyStatus["DpadSnap4"].Contains(Buttons.DPadLeft.ToString());
348 }
349 return false;
350 }
351}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void AddRange(IEnumerable< KeyValuePair< TKey, TValue > > collection)
void Add(TKey key, TValue value)
void CopyKeysFrom(PlayerInputProfile profile, InputMode mode, string[] keysToCopy)
void ConditionalAdd(Dictionary< string, object > dicttouse, string a, object b, Func< PlayerInputProfile, bool > check)
void CopyMapSettingsFrom(PlayerInputProfile profile, InputMode mode)
void CopyHotbarSettingsFrom(PlayerInputProfile profile, InputMode mode)
void ConditionalAddProfile(Dictionary< string, object > dicttouse, string k, InputMode nm, Dictionary< string, List< string > > dict)
Dictionary< string, object > Save()
bool Load(Dictionary< string, object > dict)
Dictionary< InputMode, KeyConfiguration > InputModes
void Initialize(PresetProfiles style)
void CopyGamepadAdvancedSettingsFrom(PlayerInputProfile profile, InputMode mode)
void CopyGamepadSettingsFrom(PlayerInputProfile profile, InputMode mode)
void CopyGameplaySettingsFrom(PlayerInputProfile profile, InputMode mode)
static void Reset(KeyConfiguration c, PresetProfiles style, InputMode mode)
static Dictionary< string, PlayerInputProfile > OriginalProfiles