-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCAN_Settings_Config.cs
219 lines (199 loc) · 5.11 KB
/
SCAN_Settings_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
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
using System;
using System.IO;
using System.Reflection;
using UnityEngine;
using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette;
namespace SCANsat
{
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class SCAN_Settings_Config : MonoBehaviour
{
[Persistent]
public bool BackgroundScanning = true;
[Persistent]
public int TimeWarpResolution = 15;
[Persistent]
public bool ShowGroundTracks = true;
[Persistent]
public bool GroundTracksActiveOnly = true;
[Persistent]
public bool MechJebTarget = false;
[Persistent]
public bool OverlayTooltips = true;
[Persistent]
public bool WindowTooltips = true;
[Persistent]
public bool StockToolbar = true;
[Persistent]
public bool ToolbarMenu = true;
[Persistent]
public bool StockUIStyle = false;
[Persistent]
public bool SlowMapGeneration = false;
[Persistent]
public float UIScale = 1;
[Persistent]
public bool BiomeLock = true;
[Persistent]
public bool RequireNarrowBand = true;
[Persistent]
public bool DisableStockResource = false;
[Persistent]
public bool InstantScan = true;
[Persistent]
public bool UseStockTreshold = true;
[Persistent]
public float StockTreshold = 0.9f;
[Persistent]
public int Interpolation = 8;
[Persistent]
public int ResourceMapHeight = 256;
[Persistent]
public int BiomeMapHeight = 512;
[Persistent]
public float CoverageTransparency = 0.2f;
[Persistent]
public bool TrueGreyScale = false;
[Persistent]
public bool ExportCSV = false;
[Persistent]
public float BiomeTransparency = 0.4f;
[Persistent]
public bool BigMapBiomeBorder = true;
[Persistent]
public bool BigMapStockBiomes = true;
[Persistent]
public bool SmallMapBiomeBorder = false;
[Persistent]
public bool SmallMapStockBiomes = true;
[Persistent]
public Color LowBiomeColor = palette.xkcd_CamoGreen;
[Persistent]
public Color HighBiomeColor = palette.xkcd_Marigold;
[Persistent]
public float SlopeCutoff = 1;
[Persistent]
public Color BottomLowSlopeColor = palette.xkcd_PukeGreen;
[Persistent]
public Color BottomHighSlopeColor = palette.xkcd_Lemon;
[Persistent]
public Color TopLowSlopeColor = palette.xkcd_Lemon;
[Persistent]
public Color TopHighSlopeColor = palette.xkcd_OrangeRed;
[Persistent]
public bool CheatMapFill = false;
[Persistent]
public bool CheatStartLoTerrain = false;
[Persistent]
public bool CheatStartHiTerrain = false;
[Persistent]
public bool CheatStartBiome = false;
[Persistent]
public bool CheatStartFuzzyResources = false;
[Persistent]
public bool CheatStartOre = false;
[Persistent]
public bool CheatStartAllResources = false;
[Persistent]
public int BigMapWidth = 720;
[Persistent]
public Vector2 ZoomMapSize = new Vector2(360, 240);
[Persistent]
public Vector2 BigMapPosition = new Vector2(400, -400);
[Persistent]
public Vector2 MainMapPosition = new Vector2(100, -200);
[Persistent]
public Vector2 ZoomMapPosition = new Vector2(400, -400);
[Persistent]
public Vector2 InstrumentsPosition = new Vector2(100, -500);
[Persistent]
public Vector2 OverlayPosition = new Vector2(600, -200);
private const string filePath = "GameData/SCANsat/PluginData/Settings.cfg";
private string fullPath;
private static bool loaded;
private static SCAN_Settings_Config instance;
public static SCAN_Settings_Config Instance
{
get { return instance; }
}
private void Awake()
{
if (loaded)
Destroy(gameObject);
DontDestroyOnLoad(gameObject);
loaded = true;
instance = this;
fullPath = Path.Combine(KSPUtil.ApplicationRootPath, filePath).Replace("\\", "/");
if (Load())
SCANUtil.SCANlog("Settings file loaded");
else
{
if (Save())
SCANUtil.SCANlog("Settings file generated at:\n{0}", filePath);
}
GameEvents.onGameStateSaved.Add(GameSaved);
}
private void GameSaved(Game g)
{
if (HighLogic.CurrentGame == g)
Save();
}
public bool Load()
{
bool b = false;
try
{
if (File.Exists(fullPath))
{
ConfigNode node = ConfigNode.Load(fullPath);
ConfigNode unwrapped = node.GetNode(GetType().Name);
ConfigNode.LoadObjectFromConfig(this, unwrapped);
b = true;
}
else
{
SCANUtil.SCANlog("Settings file could not be found [{0}]", fullPath);
b = false;
}
}
catch (Exception e)
{
SCANUtil.SCANlog("Error while loading settings file from [{0}]\n{1}", fullPath, e);
b = false;
}
return b;
}
public bool Save()
{
bool b = false;
try
{
ConfigNode node = AsConfigNode();
ConfigNode wrapper = new ConfigNode(GetType().Name);
wrapper.AddNode(node);
wrapper.Save(fullPath);
b = true;
}
catch (Exception e)
{
SCANUtil.SCANlog("Error while saving settings file from [{0}]\n{1}", fullPath, e);
b = false;
}
return b;
}
private ConfigNode AsConfigNode()
{
try
{
ConfigNode node = new ConfigNode(GetType().Name);
node = ConfigNode.CreateConfigFromObject(this, node);
return node;
}
catch (Exception e)
{
SCANUtil.SCANlog("Failed to generate settings file node...\n{0}", e);
return new ConfigNode(GetType().Name);
}
}
}
}