Skip to content

Commit

Permalink
Support localized resource conc limits; show true 0% resource conc in…
Browse files Browse the repository at this point in the history
… map mouse over info
  • Loading branch information
DMagic1 committed Aug 15, 2020
1 parent eef5673 commit d4be860
Showing 1 changed file with 66 additions and 20 deletions.
86 changes: 66 additions & 20 deletions SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs
Expand Up @@ -272,12 +272,17 @@ internal static string resourceLabel(bool fuzz, double lat, double lon, SCANreso
return string.Format("{0}: {1}", resource.DisplayName, SCANUtil.ResourceOverlay(lat, lon, resource.Name, b, SCAN_Settings_Config.Instance.BiomeLock).ToString("P2"));
}

internal static string LoResourceGroup(float abundance)
{
abundance = Mathf.Floor(abundance * 100 / 5) * 5;
internal static string LoResourceGroup(float abundance)
{
if (abundance > 0)
{
abundance = Mathf.Floor(abundance * 100 / 5) * 5;

return string.Format("{0}-{1}%", abundance.ToString("F0"), (abundance + 5).ToString("F0"));
}
return string.Format("{0}-{1}%", abundance.ToString("F0"), (abundance + 5).ToString("F0"));
}
else
return "0%";
}

private static double inc(double d)
{
Expand Down Expand Up @@ -667,7 +672,7 @@ internal static void generateOverlayResourcePixels(ref Color32[] pix, ref float[
{
double lat = (j / scale) - 90;

pix[j * width + i] = resourceToColor32(palette.Clear, resource, values[i, j], data, lon, lat, transparency);
pix[j * width + i] = resourceToColor32(palette.Clear, resource, resource.CurrentBody.MinValue, resource.CurrentBody.MaxValue, values[i, j], data, lon, lat, transparency);
}
}
}
Expand Down Expand Up @@ -711,7 +716,7 @@ internal static Texture2D drawResourceTexture(ref Texture2D map, ref Color32[] p
{
double lat = (j / scale) - 90;

pix[j * width + i] = resourceToColor32(palette.Clear, resource, values[i, j], data, lon, lat, transparency);
pix[j * width + i] = resourceToColor32(palette.Clear, resource, resource.CurrentBody.MinValue, resource.CurrentBody.MaxValue, values[i, j], data, lon, lat, transparency);
}
}

Expand Down Expand Up @@ -1083,7 +1088,7 @@ internal static Texture2D drawLoDetailMap(ref Color32[] pix, ref float[,] values

Color32 c = pix[j * width + i];

pix[j * width + i] = resourceToColor32(c, map.Resource, values[i, j], data, lon, lat);
pix[j * width + i] = resourceToColor32(c, map.Resource, map.Resource.CurrentBody.MinValue, map.Resource.CurrentBody.MaxValue, values[i, j], data, lon, lat);
}
}
}
Expand Down Expand Up @@ -1130,6 +1135,44 @@ internal static void generateResourceCache(ref float[,] values, int height, int
}
}

//internal static void generateResourceCache(Texture2D tex, int height, int width, int stepScale, double scale, SCANmap map)
//{
// for (int j = 0; j < height; j += stepScale)
// {
// for (int i = 0; i < width; i += stepScale)
// {
// Vector2d coords;
// if (map.Projection == MapProjection.Orthographic)
// {
// double rLon = (i * 1.0f / scale) - 180f + map.Lon_Offset;
// double rLat = (j * 1.0f / scale) - 90f + map.Lat_Offset;

// double la = rLat, lo = rLon;
// rLat = map.unprojectLatitude(lo, la);
// rLon = map.unprojectLongitude(lo, la);

// if (double.IsNaN(rLat) || double.IsNaN(rLon) || rLat < -90 || rLat > 90 || rLon < -180 || rLon > 180)
// {
// tex.SetPixel(i, j, palette.clear);
// continue;
// }

// coords = new Vector2d(rLon, rLat);
// }
// else
// {
// double rLon = SCANUtil.fixLonShift((i * 1.0f / scale) - 180f + map.Lon_Offset);
// double rLat = (j * 1.0f / scale) - 90f + map.Lat_Offset;
// coords = SCANUtil.fixRetardCoordinates(new Vector2d(rLon, rLat));
// }

// float abundance = SCANUtil.ResourceOverlay(coords.y, coords.x, map.Resource.Name, map.Body, SCAN_Settings_Config.Instance.BiomeLock) * 100f;

// tex.SetPixel(i, j, resourceToColor(palette.clear, map.Resource, abundance, );
// }
// }
//}

private static float getLerp(System.Random rand, int l)
{
if (l == 0)
Expand Down Expand Up @@ -1270,37 +1313,40 @@ internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resour
return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, (Abundance - Resource.CurrentBody.MinValue) / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f);
}

internal static Color32 resourceToColor32(Color32 BaseColor, SCANresourceGlobal Resource, float Abundance, SCANdata Data, double Lon, double Lat, float Transparency = 0.3f)
internal static Color32 resourceToColor32(Color32 BaseColor, SCANresourceGlobal Resource, float MinRange, float MaxRange, float Abundance, SCANdata Data, double Lon, double Lat, float Transparency = 0.3f)
{
if (SCANUtil.isCovered(Lon, Lat, Data, SCANtype.ResourceHiRes))
{
if (Abundance >= Resource.CurrentBody.MinValue)
if (Abundance >= MinRange)
{
if (Abundance > Resource.CurrentBody.MaxValue)
Abundance = Resource.CurrentBody.MaxValue;
if (Abundance > MaxRange)
Abundance = MaxRange;
}
else
Abundance = 0;
}
else if (SCANUtil.isCovered(Lon, Lat, Data, SCANtype.ResourceLoRes))
{
Abundance = Mathf.Floor(Abundance / 5) * 5 + 2.5f;

if (Abundance >= Resource.CurrentBody.MinValue)
if (Abundance > 0)
{
if (Abundance > Resource.CurrentBody.MaxValue)
Abundance = Resource.CurrentBody.MaxValue;
Abundance = Mathf.Floor(Abundance / 5) * 5 + 2.5f;

if (Abundance >= MinRange)
{
if (Abundance > MaxRange)
Abundance = MaxRange;
}
else
Abundance = 0;
}
else
Abundance = 0;
}
else
return BaseColor;

if (Abundance == 0)
return palette.lerp(BaseColor, palette.Grey, Transparency);
else
return palette.lerp(palette.lerp(Resource.MinColor32, Resource.MaxColor32, (Abundance - Resource.CurrentBody.MinValue) / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f);
return palette.lerp(palette.lerp(Resource.MinColor32, Resource.MaxColor32, (Abundance - MinRange) / (MaxRange - MinRange)), BaseColor, Resource.Transparency / 100f);
}

#endregion
Expand Down

0 comments on commit d4be860

Please sign in to comment.