-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheSettingsGUI.cs
More file actions
91 lines (74 loc) · 3.21 KB
/
CacheSettingsGUI.cs
File metadata and controls
91 lines (74 loc) · 3.21 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
using System;
using System.Reflection;
using ModSettings;
namespace CacheControl {
internal class CacheSettingsGUI : ModSettingsBase {
private const int CACHES_IN_ML = 9;
private const int CACHES_IN_PV = 9;
private const int CACHES_IN_BR = 9;
internal enum SpawnAlgorithm {
FixedNumber, SpawnChance
}
internal readonly CacheSettings confirmedSettings = new CacheSettings();
[Name("Override number of Prepper Caches")]
[Description("Determines whether CacheControl is enabled in this save file.")]
public bool enabled = false;
[Name("Cache spawning algorithm")]
[Description("- Fixed number of caches:\n Spawns exactly the number of caches\n you specified.\n"
+ "- Cache spawn chance:\n Each cache has a set chance of spawning,\n leading to a randomized amount of caches.")]
[Choice("Fixed number of caches", "Cache spawn chance")]
public SpawnAlgorithm algorithm = SpawnAlgorithm.FixedNumber;
[Name("Number of caches in Mystery Lake")]
[Slider(0, CACHES_IN_ML)]
public int numCachesML = 0;
[Name("Number of caches in Pleasant Valley")]
[Slider(0, CACHES_IN_PV)]
public int numCachesPV = 0;
[Name("Number of caches in Blackrock")]
[Slider(0, CACHES_IN_BR)]
public int numCachesBR = 0;
[Name("Cache spawn chance in Mystery Lake")]
[Slider(0, 100, NumberFormat = "{0:F0}%")]
public float spawnChanceML = 0;
[Name("Cache spawn chance in Pleasant Valley")]
[Slider(0, 100, NumberFormat = "{0:F0}%")]
public float spawnChancePV = 0;
[Name("Cache spawn chance in Blackrock")]
[Slider(0, 100, NumberFormat = "{0:F0}%")]
public float spawnChanceBR = 0;
internal CacheSettingsGUI() {
RefreshFieldsVisible();
}
protected override void OnChange(FieldInfo field, object oldValue, object newValue) {
if (field.Name == nameof(enabled) || field.Name == nameof(algorithm)) {
RefreshFieldsVisible();
}
}
internal void RefreshFieldsVisible() {
SetFieldVisible(nameof(algorithm), enabled);
SetFieldVisible(nameof(numCachesML), enabled && algorithm == SpawnAlgorithm.FixedNumber);
SetFieldVisible(nameof(numCachesPV), enabled && algorithm == SpawnAlgorithm.FixedNumber);
SetFieldVisible(nameof(numCachesBR), enabled && algorithm == SpawnAlgorithm.FixedNumber);
SetFieldVisible(nameof(spawnChanceML), enabled && algorithm == SpawnAlgorithm.SpawnChance);
SetFieldVisible(nameof(spawnChancePV), enabled && algorithm == SpawnAlgorithm.SpawnChance);
SetFieldVisible(nameof(spawnChanceBR), enabled && algorithm == SpawnAlgorithm.SpawnChance);
}
protected override void OnConfirm() {
confirmedSettings.enabled = enabled;
switch (algorithm) {
case SpawnAlgorithm.FixedNumber:
confirmedSettings.numCachesML = numCachesML;
confirmedSettings.numCachesPV = numCachesPV;
confirmedSettings.numCachesBR = numCachesBR;
break;
case SpawnAlgorithm.SpawnChance:
confirmedSettings.numCachesML = CacheControl.RandomBinomial(CACHES_IN_ML, spawnChanceML);
confirmedSettings.numCachesPV = CacheControl.RandomBinomial(CACHES_IN_PV, spawnChancePV);
confirmedSettings.numCachesBR = CacheControl.RandomBinomial(CACHES_IN_BR, spawnChanceBR);
break;
default:
throw new NotImplementedException();
}
}
}
}