Skip to content

Commit 297cf42

Browse files
committed
lots of small stuff
-exponential resource scale -fixed log(0) -active button marked -anomaly overlay
1 parent 74a99b4 commit 297cf42

File tree

6 files changed

+143
-10
lines changed

6 files changed

+143
-10
lines changed
2.5 KB
Binary file not shown.

Source/MapResourceOverlay/Coordinates.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace MapResourceOverlay
1+
using System;
2+
3+
namespace MapResourceOverlay
24
{
35
public class Coordinates
46
{
@@ -20,5 +22,17 @@ public double Longitude
2022
{
2123
get { return _longitude; }
2224
}
25+
26+
public double Distance(Coordinates other)
27+
{
28+
var distLong = Longitude - other.Longitude;
29+
var distLat = Latitude - other.Latitude;
30+
return Math.Sqrt(Math.Pow(distLong, 2) + Math.Pow(distLat, 2));
31+
}
32+
33+
public override string ToString()
34+
{
35+
return "Latitude " + Latitude + ", Longitude" + Longitude;
36+
}
2337
}
2438
}

Source/MapResourceOverlay/IOverlayProvider.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,65 @@ public virtual void BodyChanged(CelestialBody body)
8787
}
8888
}
8989

90+
public class AnomalyMapProvider : OverlayProviderBase
91+
{
92+
private Dictionary<Coordinates, PQSCity> _pqsCities;
93+
94+
public override void Activate(CelestialBody body)
95+
{
96+
base.Activate(body);
97+
CalculateAnomalies();
98+
}
99+
100+
public override void BodyChanged(CelestialBody body)
101+
{
102+
base.BodyChanged(body);
103+
CalculateAnomalies();
104+
}
105+
106+
private void CalculateAnomalies()
107+
{
108+
_pqsCities = new Dictionary<Coordinates,PQSCity>();
109+
PQSCity[] sites = _body.GetComponentsInChildren<PQSCity>(true);
110+
foreach (var pqsCity in sites)
111+
{
112+
_pqsCities[new Coordinates(_body.GetLatitude(pqsCity.transform.position),
113+
_body.GetLongitude(pqsCity.transform.position))] = pqsCity;
114+
115+
}
116+
this.Log(_pqsCities.Aggregate("",(x,y) => x +" "+ y.Value.name +" lat: "+y.Key.Latitude+" long: "+y.Key.Longitude));
117+
}
118+
119+
public override Color32 CalculateColor32(double latitude, double longitude, CelestialBody body, bool useScansat, bool bright,
120+
double cutoff)
121+
{
122+
var anoms = _pqsCities.Keys.Where(x => x.Distance(new Coordinates(latitude, Utilities.ClampDegrees(longitude))) < 2).ToList();
123+
if (anoms.Count > 0)
124+
{
125+
return new Color32(0,255,255,255);
126+
}
127+
return new Color32(0,0,0,0);
128+
}
129+
130+
public override OverlayTooltip TooltipContent(double latitude, double longitude, CelestialBody body)
131+
{
132+
var anoms = _pqsCities.Keys.Where(x => x.Distance(new Coordinates(latitude, Utilities.ClampDegrees(longitude))) < 2).ToList();
133+
if (anoms.Count > 0)
134+
{
135+
var anom = _pqsCities[anoms.First()];
136+
return new OverlayTooltip(anom.name,new GUIContent(""));
137+
}
138+
return base.TooltipContent(latitude, longitude, body);
139+
}
140+
141+
142+
public override string GuiName
143+
{
144+
get { return "Anomaly Map"; }
145+
}
146+
}
147+
148+
90149
public class OverlayTooltip
91150
{
92151
public OverlayTooltip(string title, GUIContent content, Vector2 size = new Vector2())

Source/MapResourceOverlay/MapOverlayGui.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ protected override void DrawWindowContents(int windowId)
8484
GUILayout.Box("Overlay types:");
8585
foreach (var overlayProvider in Model.OverlayProviders)
8686
{
87-
if (GUILayout.Button(overlayProvider.GuiName))
87+
var style = new GUIStyle(GUI.skin.button);
88+
if (overlayProvider == Model.OverlayProvider)
89+
{
90+
style.normal.textColor = Color.yellow;
91+
}
92+
if (GUILayout.Button(overlayProvider.GuiName,style))
8893
{
8994
Model.SetOverlayProvider(overlayProvider);
9095
}

Source/MapResourceOverlay/ResourceOverlayProvider.cs

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ private delegate Object GetResourceAvailabilityByRealResourceNameDelegate(
2323
private GetResourceAvailabilityByRealResourceNameDelegate _getResourceAvailabilityByRealResourceName;
2424
private bool _logaritmic;
2525
private bool _coloredScale;
26+
private bool _exponential;
2627

2728
public ResourceConfig ActiveResource
2829
{
@@ -76,18 +77,38 @@ public override Color32 CalculateColor32(double latitude, double longitude, Cele
7677
var amount = (double)_getAmount(avail) * 1000000;
7778
if (amount > cutoff)
7879
{
79-
if (Logaritmic)
80+
if (Exponential)
8081
{
81-
amount = ((Math.Log(amount, 2) - (Math.Log(cutoff, 2))) * 255) / ((Math.Log(_displayMax, 2) - (Math.Log(cutoff, 2))));
82+
amount = ((Math.Pow(amount, 2) - (Math.Pow(cutoff, 2))) *255) / ((Math.Pow(_displayMax, 2) - (Math.Pow(cutoff, 2))));
83+
if (ColoredScale)
84+
{
85+
var color = ScanSatWrapper.heightToColor((float)amount, 0, 255);
86+
color.a = ActiveResource.HighColor.a;
87+
return color;
88+
}
8289
}
83-
else if (_coloredScale)
90+
else if (Logaritmic)
8491
{
85-
var color = ScanSatWrapper.heightToColor((float) amount, cutoff, (float) _displayMax);
86-
color.a = ActiveResource.HighColor.a;
87-
return color;
92+
if (cutoff < 1)
93+
{
94+
cutoff = 1;
95+
}
96+
amount = ((Math.Log(amount, 2) - (Math.Log(cutoff, 2)))*255) / ((Math.Log(_displayMax, 2) - (Math.Log(cutoff, 2))));
97+
if (ColoredScale)
98+
{
99+
var color = ScanSatWrapper.heightToColor((float)amount*255, 0, 255f);
100+
color.a = ActiveResource.HighColor.a;
101+
return color;
102+
}
88103
}
89104
else
90105
{
106+
if (ColoredScale)
107+
{
108+
var color = ScanSatWrapper.heightToColor((float)amount, cutoff, (float)_displayMax);
109+
color.a = ActiveResource.HighColor.a;
110+
return color;
111+
}
91112
amount =((amount - cutoff) * 255) / (_displayMax - cutoff);
92113
}
93114
amount = Mathf.Clamp((float) amount, 0f, 255f);
@@ -116,6 +137,10 @@ public bool Logaritmic
116137
{
117138
_logaritmic = value;
118139
RequiresRedraw();
140+
if (_logaritmic)
141+
{
142+
_exponential = false;
143+
}
119144
}
120145
}
121146
}
@@ -266,18 +291,43 @@ public override void DrawGui(MapOverlayGui gui)
266291
base.DrawGui(gui);
267292
GUILayout.BeginVertical();
268293
Logaritmic = GUILayout.Toggle(Logaritmic, "Logarithmic Scale");
294+
Exponential = GUILayout.Toggle(Exponential, "Exponential Scale");
269295
ColoredScale = GUILayout.Toggle(ColoredScale, "Colored Scale");
270296
GUILayout.Space(15);
271297
foreach (var res in ColorConfigs)
272298
{
273-
if (GUILayout.Button(res.Resource.ResourceName))
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))
274305
{
275306
ActiveResource = res;
276307
}
277308
}
278309
GUILayout.EndVertical();
279310
}
280311

312+
public bool Exponential
313+
{
314+
get { return _exponential; }
315+
set
316+
{
317+
if (_exponential != value)
318+
{
319+
_exponential = value;
320+
RequiresRedraw();
321+
if (_exponential)
322+
{
323+
_logaritmic = false;
324+
}
325+
}
326+
327+
328+
}
329+
}
330+
281331
public bool ColoredScale
282332
{
283333
get { return _coloredScale; }

Source/MapResourceOverlay/ScienceOverlayProvider.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ protected override void DrawWindowContents(int windowId)
156156
GUILayout.BeginVertical();
157157
foreach (var situation in Enum.GetValues(typeof(ExperimentSituations)).Cast<ExperimentSituations>())
158158
{
159-
if (GUILayout.Button(Enum.GetName(typeof(ExperimentSituations),situation)))
159+
var style = new GUIStyle(GUI.skin.button);
160+
if (situation == _model.Situation)
161+
{
162+
style.normal.textColor = Color.yellow;
163+
}
164+
if (GUILayout.Button(Enum.GetName(typeof(ExperimentSituations),situation), style))
160165
{
161166
_model.Situation = situation;
162167
}

0 commit comments

Comments
 (0)