Skip to content

Commit

Permalink
indvidual cutoffs for resources and new icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrik committed Sep 2, 2014
1 parent 297cf42 commit b30b73f
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,4 @@ UpgradeLog*.htm
# Microsoft Fakes
FakesAssemblies/
*.db
GameData/MapResourceOverlay/MapResourceOverlay.dll
Binary file modified GameData/MapResourceOverlay/Assets/MapOverlayIcon.disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GameData/MapResourceOverlay/Assets/MapOverlayIcon.enabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GameData/MapResourceOverlay/Assets/MapOverlayIcon.hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions GameData/MapResourceOverlay/Base.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ globalNode
{
Karbonite
{
Cutoff = 0
Resource = ResourceName=Karbonite,ScansatName=Karbonite
LowColor = (0,0,0,0)
HighColor = (255,0,0,200)
Expand All @@ -23,30 +24,35 @@ globalNode
{
Karbonite
{
Cutoff = 100
Resource = ResourceName=Karbonite,ScansatName=Karbonite
LowColor = (0,0,0,0)
HighColor = (255,0,0,200)
}
Ore
{
Cutoff = 50
Resource = ResourceName=Ore,ScansatName=Ore
LowColor = (0,0,0,0)
HighColor = (0,255,0,200)
}
Water
{
Cutoff = 100
Resource = ResourceName=Water,ScansatName=Aquifer
LowColor = (0,0,0,0)
HighColor = (0,0,255,200)
}
Minerals
{
Cutoff = 25
Resource = ResourceName=Minerals,ScansatName=Minerals
LowColor = (0,0,0,0)
HighColor = (0,255,255,200)
}
Substrate
{
Cutoff = 0
Resource = ResourceName=Substrate,ScansatName=Substrate
LowColor = (0,0,0,0)
HighColor = (255,0,255,200)
Expand Down
2 changes: 1 addition & 1 deletion GameData/MapResourceOverlay/MapResourceOverlay.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"URL":"https://raw.githubusercontent.com/Cyrik/MapResourceOverlay/master/GameData/MapResourceOverlay/MapResourceOverlay.version",
"DOWNLOAD":"https://github.com/Cyrik/MapResourceOverlay/releases",
"CHANGE_LOG_URL":"",
"VERSION":{"MAJOR":0,"MINOR":2,"PATCH":4,"BUILD":0},
"VERSION":{"MAJOR":0,"MINOR":2,"PATCH":5,"BUILD":0},
"KSP_VERSION":{"MAJOR":0,"MINOR":24,"PATCH":2}
}
2 changes: 1 addition & 1 deletion Source/MapResourceOverlay/IOverlayProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ _pqsCities[new Coordinates(_body.GetLatitude(pqsCity.transform.position),
_body.GetLongitude(pqsCity.transform.position))] = pqsCity;

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

public override Color32 CalculateColor32(double latitude, double longitude, CelestialBody body, bool useScansat, bool bright,
Expand Down
6 changes: 5 additions & 1 deletion Source/MapResourceOverlay/ResourceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ public class ResourceConfig
public Resource Resource { get; set; }
public Color32 LowColor { get; set; }
public Color32 HighColor { get; set; }
public double Cutoff { get; set; }

public static ResourceConfig Load(ConfigNode configNode)
{
var res = new ResourceConfig
{
Resource = Resource.DeserializeResource(configNode.GetValue("Resource")),
LowColor = StringToColor(configNode.GetValue("LowColor")),
HighColor = StringToColor(configNode.GetValue("HighColor"))
HighColor = StringToColor(configNode.GetValue("HighColor")),
Cutoff = Double.Parse(configNode.GetValue("Cutoff"))
};
return res;
}
Expand All @@ -34,6 +37,7 @@ private static Color StringToColor(string str)
public void Save(ConfigNode node)
{
var colorConfigNode = node.AddNode(Resource.ResourceName);
colorConfigNode.AddValue("Cutoff", Cutoff);
colorConfigNode.AddValue("Resource", Resource.Serialize());
colorConfigNode.AddValue("LowColor", ColorToString(LowColor));
colorConfigNode.AddValue("HighColor", ColorToString(HighColor));
Expand Down
85 changes: 62 additions & 23 deletions Source/MapResourceOverlay/ResourceOverlayProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public override Color32 CalculateColor32(double latitude, double longitude, Cele
var avail = _getResourceAvailabilityByRealResourceName(body.flightGlobalsIndex,
ActiveResource.Resource.ResourceName, latitude, longitude);
var amount = (double)_getAmount(avail) * 1000000;
if (amount > cutoff)
if (amount > ActiveResource.Cutoff)
{
if (Exponential)
{
amount = ((Math.Pow(amount, 2) - (Math.Pow(cutoff, 2))) *255) / ((Math.Pow(_displayMax, 2) - (Math.Pow(cutoff, 2))));
amount = ((Math.Pow(amount, 2) - (Math.Pow(ActiveResource.Cutoff, 2))) * 255) / ((Math.Pow(_displayMax, 2) - (Math.Pow(ActiveResource.Cutoff, 2))));
if (ColoredScale)
{
var color = ScanSatWrapper.heightToColor((float)amount, 0, 255);
Expand All @@ -89,11 +89,11 @@ public override Color32 CalculateColor32(double latitude, double longitude, Cele
}
else if (Logaritmic)
{
if (cutoff < 1)
if (ActiveResource.Cutoff < 1)
{
cutoff = 1;
ActiveResource.Cutoff = 1;
}
amount = ((Math.Log(amount, 2) - (Math.Log(cutoff, 2)))*255) / ((Math.Log(_displayMax, 2) - (Math.Log(cutoff, 2))));
amount = ((Math.Log(amount, 2) - (Math.Log(ActiveResource.Cutoff, 2))) * 255) / ((Math.Log(_displayMax, 2) - (Math.Log(ActiveResource.Cutoff, 2))));
if (ColoredScale)
{
var color = ScanSatWrapper.heightToColor((float)amount*255, 0, 255f);
Expand All @@ -105,11 +105,11 @@ public override Color32 CalculateColor32(double latitude, double longitude, Cele
{
if (ColoredScale)
{
var color = ScanSatWrapper.heightToColor((float)amount, cutoff, (float)_displayMax);
var color = ScanSatWrapper.heightToColor((float)amount, ActiveResource.Cutoff, (float)_displayMax);
color.a = ActiveResource.HighColor.a;
return color;
}
amount =((amount - cutoff) * 255) / (_displayMax - cutoff);
amount = ((amount - ActiveResource.Cutoff) * 255) / (_displayMax - ActiveResource.Cutoff);
}
amount = Mathf.Clamp((float) amount, 0f, 255f);
if (!bright)
Expand Down Expand Up @@ -289,24 +289,11 @@ static Func<object, object> GenerateFunc(MethodInfo method)
public override void DrawGui(MapOverlayGui gui)
{
base.DrawGui(gui);
GUILayout.BeginVertical();
Logaritmic = GUILayout.Toggle(Logaritmic, "Logarithmic Scale");
Exponential = GUILayout.Toggle(Exponential, "Exponential Scale");
ColoredScale = GUILayout.Toggle(ColoredScale, "Colored Scale");
GUILayout.Space(15);
foreach (var res in ColorConfigs)
if (GUILayout.Button("Resource Options"))
{
var style = new GUIStyle(GUI.skin.button);
if (res == ActiveResource)
{
style.normal.textColor = Color.yellow;
}
if (GUILayout.Button(res.Resource.ResourceName,style))
{
ActiveResource = res;
}
new ResourceOverlayView(this);
}
GUILayout.EndVertical();

}

public bool Exponential
Expand Down Expand Up @@ -343,4 +330,56 @@ public bool ColoredScale
}
}
}

public class ResourceOverlayView : Window<ResourceOverlay>
{
private readonly ResourceOverlayProvider _model;

public ResourceOverlayView(ResourceOverlayProvider model) : base("Resource Overlay Options", 300, 400)
{
_model = model;
SetVisible(true);
}

protected override void DrawWindowContents(int windowId)
{
GUILayout.BeginVertical();
_model.Logaritmic = GUILayout.Toggle(_model.Logaritmic, "Logarithmic Scale");
_model.Exponential = GUILayout.Toggle(_model.Exponential, "Exponential Scale");
_model.ColoredScale = GUILayout.Toggle(_model.ColoredScale, "Colored Scale");

GUILayout.Space(15);
foreach (var res in _model.ColorConfigs)
{
var style = new GUIStyle(GUI.skin.button);
if (res == _model.ActiveResource)
{
style.normal.textColor = Color.yellow;
}
if (GUILayout.Button(res.Resource.ResourceName, style))
{
_model.ActiveResource = res;
}
GUILayout.BeginHorizontal();
GUILayout.Label("low Cuttoff ppm: ");
int temp;
var cutoff = GUILayout.TextField(res.Cutoff.ToString());
GUILayout.EndHorizontal();
bool changed = cutoff != res.Cutoff.ToString() && res == _model.ActiveResource;
if (Int32.TryParse(cutoff, out temp))
{
res.Cutoff = temp;
}
else if (cutoff == "")
{
res.Cutoff = 0;
}
if (changed)
{
_model.ActiveResource = res;
}
}
GUILayout.EndVertical();
}
}
}

0 comments on commit b30b73f

Please sign in to comment.