Skip to content

Commit b30b73f

Browse files
committed
indvidual cutoffs for resources and new icons
1 parent 297cf42 commit b30b73f

File tree

9 files changed

+76
-26
lines changed

9 files changed

+76
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,4 @@ UpgradeLog*.htm
173173
# Microsoft Fakes
174174
FakesAssemblies/
175175
*.db
176+
GameData/MapResourceOverlay/MapResourceOverlay.dll
4 Bytes
Loading
240 Bytes
Loading
-207 Bytes
Loading

GameData/MapResourceOverlay/Base.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ globalNode
1414
{
1515
Karbonite
1616
{
17+
Cutoff = 0
1718
Resource = ResourceName=Karbonite,ScansatName=Karbonite
1819
LowColor = (0,0,0,0)
1920
HighColor = (255,0,0,200)
@@ -23,30 +24,35 @@ globalNode
2324
{
2425
Karbonite
2526
{
27+
Cutoff = 100
2628
Resource = ResourceName=Karbonite,ScansatName=Karbonite
2729
LowColor = (0,0,0,0)
2830
HighColor = (255,0,0,200)
2931
}
3032
Ore
3133
{
34+
Cutoff = 50
3235
Resource = ResourceName=Ore,ScansatName=Ore
3336
LowColor = (0,0,0,0)
3437
HighColor = (0,255,0,200)
3538
}
3639
Water
3740
{
41+
Cutoff = 100
3842
Resource = ResourceName=Water,ScansatName=Aquifer
3943
LowColor = (0,0,0,0)
4044
HighColor = (0,0,255,200)
4145
}
4246
Minerals
4347
{
48+
Cutoff = 25
4449
Resource = ResourceName=Minerals,ScansatName=Minerals
4550
LowColor = (0,0,0,0)
4651
HighColor = (0,255,255,200)
4752
}
4853
Substrate
4954
{
55+
Cutoff = 0
5056
Resource = ResourceName=Substrate,ScansatName=Substrate
5157
LowColor = (0,0,0,0)
5258
HighColor = (255,0,255,200)

GameData/MapResourceOverlay/MapResourceOverlay.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"URL":"https://raw.githubusercontent.com/Cyrik/MapResourceOverlay/master/GameData/MapResourceOverlay/MapResourceOverlay.version",
44
"DOWNLOAD":"https://github.com/Cyrik/MapResourceOverlay/releases",
55
"CHANGE_LOG_URL":"",
6-
"VERSION":{"MAJOR":0,"MINOR":2,"PATCH":4,"BUILD":0},
6+
"VERSION":{"MAJOR":0,"MINOR":2,"PATCH":5,"BUILD":0},
77
"KSP_VERSION":{"MAJOR":0,"MINOR":24,"PATCH":2}
88
}

Source/MapResourceOverlay/IOverlayProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ _pqsCities[new Coordinates(_body.GetLatitude(pqsCity.transform.position),
113113
_body.GetLongitude(pqsCity.transform.position))] = pqsCity;
114114

115115
}
116-
this.Log(_pqsCities.Aggregate("",(x,y) => x +" "+ y.Value.name +" lat: "+y.Key.Latitude+" long: "+y.Key.Longitude));
116+
//this.Log(_pqsCities.Aggregate("",(x,y) => x +" "+ y.Value.name +" lat: "+y.Key.Latitude+" long: "+y.Key.Longitude));
117117
}
118118

119119
public override Color32 CalculateColor32(double latitude, double longitude, CelestialBody body, bool useScansat, bool bright,

Source/MapResourceOverlay/ResourceConfig.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ public class ResourceConfig
99
public Resource Resource { get; set; }
1010
public Color32 LowColor { get; set; }
1111
public Color32 HighColor { get; set; }
12+
public double Cutoff { get; set; }
13+
1214
public static ResourceConfig Load(ConfigNode configNode)
1315
{
1416
var res = new ResourceConfig
1517
{
1618
Resource = Resource.DeserializeResource(configNode.GetValue("Resource")),
1719
LowColor = StringToColor(configNode.GetValue("LowColor")),
18-
HighColor = StringToColor(configNode.GetValue("HighColor"))
20+
HighColor = StringToColor(configNode.GetValue("HighColor")),
21+
Cutoff = Double.Parse(configNode.GetValue("Cutoff"))
1922
};
2023
return res;
2124
}
@@ -34,6 +37,7 @@ private static Color StringToColor(string str)
3437
public void Save(ConfigNode node)
3538
{
3639
var colorConfigNode = node.AddNode(Resource.ResourceName);
40+
colorConfigNode.AddValue("Cutoff", Cutoff);
3741
colorConfigNode.AddValue("Resource", Resource.Serialize());
3842
colorConfigNode.AddValue("LowColor", ColorToString(LowColor));
3943
colorConfigNode.AddValue("HighColor", ColorToString(HighColor));

Source/MapResourceOverlay/ResourceOverlayProvider.cs

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ public override Color32 CalculateColor32(double latitude, double longitude, Cele
7575
var avail = _getResourceAvailabilityByRealResourceName(body.flightGlobalsIndex,
7676
ActiveResource.Resource.ResourceName, latitude, longitude);
7777
var amount = (double)_getAmount(avail) * 1000000;
78-
if (amount > cutoff)
78+
if (amount > ActiveResource.Cutoff)
7979
{
8080
if (Exponential)
8181
{
82-
amount = ((Math.Pow(amount, 2) - (Math.Pow(cutoff, 2))) *255) / ((Math.Pow(_displayMax, 2) - (Math.Pow(cutoff, 2))));
82+
amount = ((Math.Pow(amount, 2) - (Math.Pow(ActiveResource.Cutoff, 2))) * 255) / ((Math.Pow(_displayMax, 2) - (Math.Pow(ActiveResource.Cutoff, 2))));
8383
if (ColoredScale)
8484
{
8585
var color = ScanSatWrapper.heightToColor((float)amount, 0, 255);
@@ -89,11 +89,11 @@ public override Color32 CalculateColor32(double latitude, double longitude, Cele
8989
}
9090
else if (Logaritmic)
9191
{
92-
if (cutoff < 1)
92+
if (ActiveResource.Cutoff < 1)
9393
{
94-
cutoff = 1;
94+
ActiveResource.Cutoff = 1;
9595
}
96-
amount = ((Math.Log(amount, 2) - (Math.Log(cutoff, 2)))*255) / ((Math.Log(_displayMax, 2) - (Math.Log(cutoff, 2))));
96+
amount = ((Math.Log(amount, 2) - (Math.Log(ActiveResource.Cutoff, 2))) * 255) / ((Math.Log(_displayMax, 2) - (Math.Log(ActiveResource.Cutoff, 2))));
9797
if (ColoredScale)
9898
{
9999
var color = ScanSatWrapper.heightToColor((float)amount*255, 0, 255f);
@@ -105,11 +105,11 @@ public override Color32 CalculateColor32(double latitude, double longitude, Cele
105105
{
106106
if (ColoredScale)
107107
{
108-
var color = ScanSatWrapper.heightToColor((float)amount, cutoff, (float)_displayMax);
108+
var color = ScanSatWrapper.heightToColor((float)amount, ActiveResource.Cutoff, (float)_displayMax);
109109
color.a = ActiveResource.HighColor.a;
110110
return color;
111111
}
112-
amount =((amount - cutoff) * 255) / (_displayMax - cutoff);
112+
amount = ((amount - ActiveResource.Cutoff) * 255) / (_displayMax - ActiveResource.Cutoff);
113113
}
114114
amount = Mathf.Clamp((float) amount, 0f, 255f);
115115
if (!bright)
@@ -289,24 +289,11 @@ static Func<object, object> GenerateFunc(MethodInfo method)
289289
public override void DrawGui(MapOverlayGui gui)
290290
{
291291
base.DrawGui(gui);
292-
GUILayout.BeginVertical();
293-
Logaritmic = GUILayout.Toggle(Logaritmic, "Logarithmic Scale");
294-
Exponential = GUILayout.Toggle(Exponential, "Exponential Scale");
295-
ColoredScale = GUILayout.Toggle(ColoredScale, "Colored Scale");
296-
GUILayout.Space(15);
297-
foreach (var res in ColorConfigs)
292+
if (GUILayout.Button("Resource Options"))
298293
{
299-
var style = new GUIStyle(GUI.skin.button);
300-
if (res == ActiveResource)
301-
{
302-
style.normal.textColor = Color.yellow;
303-
}
304-
if (GUILayout.Button(res.Resource.ResourceName,style))
305-
{
306-
ActiveResource = res;
307-
}
294+
new ResourceOverlayView(this);
308295
}
309-
GUILayout.EndVertical();
296+
310297
}
311298

312299
public bool Exponential
@@ -343,4 +330,56 @@ public bool ColoredScale
343330
}
344331
}
345332
}
333+
334+
public class ResourceOverlayView : Window<ResourceOverlay>
335+
{
336+
private readonly ResourceOverlayProvider _model;
337+
338+
public ResourceOverlayView(ResourceOverlayProvider model) : base("Resource Overlay Options", 300, 400)
339+
{
340+
_model = model;
341+
SetVisible(true);
342+
}
343+
344+
protected override void DrawWindowContents(int windowId)
345+
{
346+
GUILayout.BeginVertical();
347+
_model.Logaritmic = GUILayout.Toggle(_model.Logaritmic, "Logarithmic Scale");
348+
_model.Exponential = GUILayout.Toggle(_model.Exponential, "Exponential Scale");
349+
_model.ColoredScale = GUILayout.Toggle(_model.ColoredScale, "Colored Scale");
350+
351+
GUILayout.Space(15);
352+
foreach (var res in _model.ColorConfigs)
353+
{
354+
var style = new GUIStyle(GUI.skin.button);
355+
if (res == _model.ActiveResource)
356+
{
357+
style.normal.textColor = Color.yellow;
358+
}
359+
if (GUILayout.Button(res.Resource.ResourceName, style))
360+
{
361+
_model.ActiveResource = res;
362+
}
363+
GUILayout.BeginHorizontal();
364+
GUILayout.Label("low Cuttoff ppm: ");
365+
int temp;
366+
var cutoff = GUILayout.TextField(res.Cutoff.ToString());
367+
GUILayout.EndHorizontal();
368+
bool changed = cutoff != res.Cutoff.ToString() && res == _model.ActiveResource;
369+
if (Int32.TryParse(cutoff, out temp))
370+
{
371+
res.Cutoff = temp;
372+
}
373+
else if (cutoff == "")
374+
{
375+
res.Cutoff = 0;
376+
}
377+
if (changed)
378+
{
379+
_model.ActiveResource = res;
380+
}
381+
}
382+
GUILayout.EndVertical();
383+
}
384+
}
346385
}

0 commit comments

Comments
 (0)