forked from direwolf420/ConsistentReforging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cs
93 lines (77 loc) · 2.35 KB
/
Config.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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using Terraria;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;
namespace ConsistentReforging
{
public class Config : ModConfig
{
public override ConfigScope Mode => ConfigScope.ClientSide;
public static Config Instance => ModContent.GetInstance<Config>();
public const int RangeMin = 2;
public const int RangeMax = 90 / 2; //90 is the amount of prefixes in vanilla
[DefaultValue(8)]
[Range(RangeMin, RangeMax)]
[Slider]
public int ReforgeHistoryLength;
[DefaultValue(false)]
public bool ShowReforgeHistoryTooltip;
[DefaultValue(false)]
public bool ShowOrphanedReforgeHistoryTooltip;
[DefaultValue(false)]
public bool SaveReforges;
[DefaultValue(true)]
public bool PreventDuplicatesFromHistory;
//Old data and names for reference
[JsonExtensionData]
private IDictionary<string, JToken> _additionalData = new Dictionary<string, JToken>();
public const string AnchorBottom = "Bottom";
public const string AnchorRight = "Right";
public enum UndoButtonAnchorPosType : byte
{
Bottom = 0,
Right = 1
}
[DrawTicks]
[DefaultValue(UndoButtonAnchorPosType.Right)]
public UndoButtonAnchorPosType UndoButtonAnchor;
[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context)
{
ReforgeHistoryLength = Utils.Clamp(ReforgeHistoryLength, RangeMin, RangeMax);
//port "UndoButtonAnchorPos": "Bottom" from string to enum, which requires (!) a member rename aswell
JToken token;
if (_additionalData.TryGetValue("UndoButtonAnchorPos", out token))
{
var undoButtonAnchorPos = token.ToObject<string>();
if (undoButtonAnchorPos == AnchorBottom)
{
UndoButtonAnchor = UndoButtonAnchorPosType.Bottom;
}
else
{
UndoButtonAnchor = UndoButtonAnchorPosType.Right;
}
}
_additionalData.Clear(); //Clear this or it'll crash.
//Correct invalid values to default fallback
EnumFallback(ref UndoButtonAnchor, UndoButtonAnchorPosType.Right);
}
private static void EnumFallback<T>(ref T value, T defaultValue) where T : Enum
{
if (!Enum.IsDefined(typeof(T), value))
{
value = defaultValue;
}
}
public override void OnChanged()
{
CRUISystem.uiState?.Recalculate();
}
}
}