From c37fa0a92ea0ae2af965a3fcdc6217765f8a2feb Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 7 May 2015 12:58:50 -0400 Subject: [PATCH 001/117] Update README.md --- README.md | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b6645e2cc..c9f09f2f5 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,9 @@ * [d. BTDT][7d] * [e. MapTraq (deprecated)][7e] * [8. (Career Mode) Research and Development][8] - * [a. Community Tech Tree Support][8a] - * [b. Minimum Scan for Science (30%)][8b] - * [c. Getting Maximum Science][8c] - * [d. Contracts][8d] + * [a. Minimum Scan for Science (30%)][8a] + * [b. Getting Maximum Science][8b] + * [c. Contracts][8c] * [9. Color Management][9] * [a. Terrain Colors and Options][9a] * [b. Biome Colors and Options][9b] @@ -423,29 +422,18 @@ The **Multispectral** sensor can be unlocked in **Advanced Exploration**. The **BTDT** sensor can be unlocked in **Field Science**. -##### [:top:][top] 8a. Community Tech Tree Support -When the [Community Tech Tree][ctt:release] addon is installed SCANsat parts will default to different tech tree nodes. - -The **RADAR Altimetry** sensor can be unlocked in **Orbital Surveys**. - -The **SAR Altimetry** sensor can be unlocked in **Specialized Science Tech**. - -The **Multispectral** sensor can be unlocked in **Advanced Surveys**. - -The **BTDT** sensor can be unlocked in **Field Science**. - -##### [:top:][top] 8b. Minimum Scan for Science +##### [:top:][top] 8a. Minimum Scan for Science Once you scan at least 30% of a particular map, you can use **Analyze Data** to get delicious science: > ![30% is your minimum][science-min] -##### [:top:][top] 8c. Getting Maximum Science +##### [:top:][top] 8b. Getting Maximum Science Between 30% and 100%, you will get a number of science points proportional to the percentage. Really, the upper cutoff is 95% in case you didn't scan the whole map. > ![Scan 95% to get all science][science-max] -##### [:top:][top] 8d. Contract Support +##### [:top:][top] 8c. Contract Support Career mode contracts are supported through third party addons. * [Contract Configurator Forum Thread][cconfig:release] @@ -670,10 +658,9 @@ sneaky then they can of course be sneaky. [7d]: #top-7d-been-there-done-that [7e]: #top-7e-maptraq-deprecated [8]: #top-8-career-mode-research-and-development -[8a]: #top-8a-community-tech-tree-support -[8b]: #top-8b-minimum-scan-for-science -[8c]: #top-8c-getting-maximum-science -[8d]: #top-8d-contract-support +[8a]: #top-8a-minimum-scan-for-science +[8b]: #top-8b-getting-maximum-science +[8c]: #top-8c-contract-support [9]: #top-9-color-management [9a]: #top-9a-terrain-colors-and-options [9b]: #top-9b-biome-colors-and-options From ea9795a5a64a11c4912a7b077a9b9274617dc14b Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 13 May 2015 11:52:58 -0400 Subject: [PATCH 002/117] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c9f09f2f5..34c936cf6 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,9 @@ Anomaly | **Been There, Done That(tm)** | **BTDT** **SCANsat** will scan celestial bodies for resources using the new stock resource system. +With default resource scanning options enabled the SCANsat resource map will automatically update as soon as a **stock resource scan** is completed. +> ![][resource-instant] + Resource scans are initiated in the same way as any other scan. In this case they use the stock **Orbital Survey Scanner**. > ![][resource-scanner] @@ -353,11 +356,14 @@ Different map types, resource overlays and polar projections are all applied to #### [:top:][top] 5a. Target Selection > ![][zoommap-scansat-landing] -The **zoom map** features an option to select and display a target site for each planet. Toggle selection mode by clicking on the target icon in the upper left, then select a sight +The **zoom map** features an option to select and display a target site for each planet. Toggle **Target Selection Mode** by clicking on the target icon in the upper left, then select a sight in the zoom map window. The icon will be displayed, along with standard, FinePrint waypoints, in the zoom window and the big map. While in map view the target site will be overlayed on the planet's surface; shown as a matching, four-arrow green icon. +To clear an existing target, activate **Target Selection Mode** by clicking the target icon, then click somewhere inside of the zoom map window, but outside of the map itself. +> ![][zoommap-clear-target] + #### [:top:][top] 5b. MechJeb Landing Guidance > ![][zoommap-mechjeb-settings] @@ -606,6 +612,7 @@ sneaky then they can of course be sneaky. [zoommap-scansat-landing]: http://i.imgur.com/ILqRfne.gif [zoommap-mechjeb-landing]: http://i.imgur.com/nE0BlA8.gif [zoommap-mechjeb-settings]: http://i.imgur.com/xOQ7ooj.png +[zoommap-clear-target]: http://i.imgur.com/YffxdNs.gif [resource-iva]: http://i.imgur.com/iRo4kSA.png [resource-walkthrough]: http://i.imgur.com/KS4FTh0.gif @@ -614,6 +621,7 @@ sneaky then they can of course be sneaky. [resource-settings]: http://i.imgur.com/sgMklCu.png [resource-zoom-map-covered]: http://i.imgur.com/7YuYMGW.png [resource-zoom-map-uncovered]: http://i.imgur.com/cJ9JtdW.png +[resource-instant]: http://i.imgur.com/mfIMBEP.gif [color-window]: http://i.imgur.com/RQVjq6g.png [color-palette-switch]: http://i.imgur.com/0XdMGSy.gif From 0fca578604f5109de7b65a9489a40a5c94255728 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 13 May 2015 13:29:54 -0400 Subject: [PATCH 003/117] Version --- SCANassets/SCANsat.version | 2 +- SCANmechjeb/Properties/AssemblyInfo.cs | 6 +++--- SCANsat/Properties/AssemblyInfo.cs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SCANassets/SCANsat.version b/SCANassets/SCANsat.version index 792c47756..badedd42a 100644 --- a/SCANassets/SCANsat.version +++ b/SCANassets/SCANsat.version @@ -11,7 +11,7 @@ "MAJOR":1, "MINOR":1, "PATCH":2, - "BUILD":0 + "BUILD":1 }, "KSP_VERSION":{ "MAJOR":1, diff --git a/SCANmechjeb/Properties/AssemblyInfo.cs b/SCANmechjeb/Properties/AssemblyInfo.cs index 38e235b4e..3280692f7 100644 --- a/SCANmechjeb/Properties/AssemblyInfo.cs +++ b/SCANmechjeb/Properties/AssemblyInfo.cs @@ -32,9 +32,9 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] -[assembly: AssemblyInformationalVersion ("v12")] +[assembly: AssemblyVersion("1.2.1.0")] +[assembly: AssemblyFileVersion("1.2.1.0")] +[assembly: AssemblyInformationalVersion ("v12.1")] [assembly: KSPAssembly ("SCANmechjeb", 0, 3)] [assembly: KSPAssemblyDependency ("SCANsat", 1, 2)] diff --git a/SCANsat/Properties/AssemblyInfo.cs b/SCANsat/Properties/AssemblyInfo.cs index cb9ab4faf..7ba7091ef 100644 --- a/SCANsat/Properties/AssemblyInfo.cs +++ b/SCANsat/Properties/AssemblyInfo.cs @@ -14,9 +14,9 @@ // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion ("1.2.0.0")] -[assembly: AssemblyFileVersion ("1.2.0.0")] -[assembly: AssemblyInformationalVersion ("v12")] +[assembly: AssemblyVersion ("1.2.1.0")] +[assembly: AssemblyFileVersion ("1.2.1.0")] +[assembly: AssemblyInformationalVersion ("v12.1")] [assembly: KSPAssembly ("SCANsat", 1, 2)] From 8e15a5862b4de091f3c0efed4ba73521516de7ad Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 13 May 2015 13:30:07 -0400 Subject: [PATCH 004/117] Fix texture file location --- SCANassets/Parts/MapTraq/MapTraq.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SCANassets/Parts/MapTraq/MapTraq.cfg b/SCANassets/Parts/MapTraq/MapTraq.cfg index c326f25eb..866b98825 100644 --- a/SCANassets/Parts/MapTraq/MapTraq.cfg +++ b/SCANassets/Parts/MapTraq/MapTraq.cfg @@ -1,4 +1,4 @@ -PART +PART { name = SCANsat_Tracker module = Part @@ -7,7 +7,7 @@ author = damny MODEL { model = SCANsat/Parts/MapTraq/MapTraq - texture = SCANsat/Parts/BTDT/SCANsat + texture = SCANsat, SCANsat/Parts/BTDT/SCANsat position = 0, 0, 0 rotation = 0, 0, 0 scale = 1, 1, 1 From f925fce3267885513dcc69e3840b7851a0af0968 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 13 May 2015 13:30:17 -0400 Subject: [PATCH 005/117] Remove unused fields --- SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg b/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg index c75cc7f7d..cf837fab6 100644 --- a/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg +++ b/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg @@ -11,7 +11,6 @@ scanName = Ore Scan power = 0.5 activeModule = False - forceActive = False } } @@ -28,7 +27,6 @@ scanName = Resource Scan power = 0.75 activeModule = True - forceActive = False } } @@ -45,7 +43,6 @@ scanName = Resource Scan power = 0.5 activeModule = True - forceActive = False } } @@ -62,6 +59,5 @@ scanName = Karbonite Scan power = 0.5 activeModule = True - forceActive = True } } From e8b7df9a35987e788adf6e0e13db8ac04bbf0148 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 13 May 2015 13:30:25 -0400 Subject: [PATCH 006/117] Make action groups virtual --- SCANsat/SCANsat.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SCANsat/SCANsat.cs b/SCANsat/SCANsat.cs index 6663d5dee..48964db29 100644 --- a/SCANsat/SCANsat.cs +++ b/SCANsat/SCANsat.cs @@ -351,19 +351,19 @@ private void animate(float speed, float time) /* SCAN: actions for ... something ... */ [KSPAction("Start Scan")] - public void startScanAction(KSPActionParam param) + public virtual void startScanAction(KSPActionParam param) { startScan(); } [KSPAction("Stop Scan")] - public void stopScanAction(KSPActionParam param) + public virtual void stopScanAction(KSPActionParam param) { stopScan(); } [KSPAction("Toggle Scan")] - public void toggleScanAction(KSPActionParam param) + public virtual void toggleScanAction(KSPActionParam param) { if (scanning) stopScan(); From 0752a126d63511f55a220a35615dc3e0b55b9a8f Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 13 May 2015 13:30:51 -0400 Subject: [PATCH 007/117] Fix for locating part modules; find animator group; override action groups --- SCANsat/SCANresourceScanner.cs | 68 ++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/SCANsat/SCANresourceScanner.cs b/SCANsat/SCANresourceScanner.cs index 47534042b..a9aa29220 100644 --- a/SCANsat/SCANresourceScanner.cs +++ b/SCANsat/SCANresourceScanner.cs @@ -1,20 +1,30 @@ -using System; +#region license +/* [Scientific Committee on Advanced Navigation] + * S.C.A.N. Satellite + * + * SCANresourceScanner - Resource scanner part module + * + * Copyright (c)2013 damny; + * Copyright (c)2014 technogeeky ; + * Copyright (c)2014 DMagic + * Copyright (c)2014 (Your Name Here) ; see LICENSE.txt for licensing details. + */ +#endregion + using System.Collections.Generic; using System.Linq; using SCANsat.SCAN_Data; - namespace SCANsat { public class ModuleSCANresourceScanner : SCANsat, IAnimatedModule { [KSPField] public bool activeModule = false; - [KSPField] - public bool forceActive = false; - private ModuleOrbitalSurveyor mSurvey; - private ModuleResourceScanner mScanner; + private List mSurvey; + private List mScanner; + private ModuleAnimationGroup animGroup; public override void OnStart(PartModule.StartState state) { @@ -22,10 +32,9 @@ public override void OnStart(PartModule.StartState state) mSurvey = findSurvey(); mScanner = findScanner(); + animGroup = findAnimator(); - if (!forceActive) - this.isEnabled = false; - else + if (animGroup == null) this.isEnabled = true; } @@ -33,21 +42,24 @@ public override string GetInfo() { string info = base.GetInfo(); info += "Resource Scan: " + (SCANtype)sensorType + "\n"; - info += "Active Scanner: " + activeModule + "\n"; + info += "Active Scanner: " + RUIutils.GetYesNoUIString(activeModule) + "\n"; return info; } - private ModuleResourceScanner findScanner() + private List findScanner() { - ModuleResourceScanner r = vessel.FindPartModulesImplementing().FirstOrDefault(); - return r; + return part.Modules.GetModules(); } - private ModuleOrbitalSurveyor findSurvey() + private List findSurvey() { - ModuleOrbitalSurveyor s = vessel.FindPartModulesImplementing().FirstOrDefault(); - return s; + return part.Modules.GetModules(); + } + + private ModuleAnimationGroup findAnimator() + { + return part.Modules.GetModules().FirstOrDefault(); } private void updateEvents() @@ -85,19 +97,29 @@ public override void OnUpdate() } } + public override void startScanAction(KSPActionParam param) + { + if (animGroup != null && !scanning && !animGroup.isDeployed) + animGroup.DeployModule(); + base.startScanAction(param); + } + + public override void toggleScanAction(KSPActionParam param) + { + if (animGroup != null && !scanning && !animGroup.isDeployed) + animGroup.DeployModule(); + base.toggleScanAction(param); + } + public void DisableModule() { - if (!forceActive) - { - this.isEnabled = false; - unregisterScanner(); - } + this.isEnabled = false; + unregisterScanner(); } public void EnableModule() { - if (!forceActive) - this.isEnabled = true; + this.isEnabled = true; } public bool IsSituationValid() From 2ac5701b1a6886366939cec06a276e37c6728bf7 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 16 May 2015 21:26:27 -0400 Subject: [PATCH 008/117] Fix #140 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 34c936cf6..f4f682bdd 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ For licensing information, please see the [included LICENSE.txt][SCANsat:rel-lic * Do I need to attach a part to my vessel to use SCANsat? * **No, but...**. You can view existing maps from any vessel, but you need to attach a scanner to add new data to the maps. * [Career Mode] Does SCANsat give us science points? - * **Yes!** For each type of map, if you scan at least 30% of the surface, you can yse Data for partial science points; up until the maximum value at 95% map coverage. + * **Yes!** For each type of map, if you scan at least 30% of the surface, you can transmit that Data for partial science points; up until the maximum value at 95% map coverage. * [Career Mode] Is it integrated into the tech tree? * **Yes!** **[This link][8]** tells you which nodes unlock which parts in the tech tree. * [Contracts] Does SCANsat offer contracts to complete? From 69e4b5ed47aa7c1f5d70368d4da4349839165a92 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sun, 17 May 2015 16:50:52 -0400 Subject: [PATCH 009/117] fix #141 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f4f682bdd..c068b4098 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,10 @@ For licensing information, please see the [included LICENSE.txt][SCANsat:rel-lic * **No!** This version is completely backwards compatible, and you current scanning state (which is stored in persistent.sfs) will be safe and sound. Nevertheless, you should make a backup copy of your game before upgading any mod. * Do I need to attach a part to my vessel to use SCANsat? * **No, but...**. You can view existing maps from any vessel, but you need to attach a scanner to add new data to the maps. + * What does the "field of view" mean? + * When a sensor is at or above its "best" altitude (but below its maximum altitude) the field of view is half of the width of the swath mapped by the instrument, if it were in orbit around Kerbin. In other words, a field of view of 5° would map swathes which are 1/36th (10°) of the planetary surface wide. The field of view is scaled for smaller bodies so that more of the surface is covered. + * What does the "best" altitude mean? + * At or above the best altitude, the sensor will operate with its listed field of view. Below this altitude the sensor suffers a linear penalty. A 10° FOV instrument with a best altitude of 500km would only have a 5° FOV at 250km. * [Career Mode] Does SCANsat give us science points? * **Yes!** For each type of map, if you scan at least 30% of the surface, you can transmit that Data for partial science points; up until the maximum value at 95% map coverage. * [Career Mode] Is it integrated into the tech tree? From 5a61c71729ace9a434e946326367888a762c9f4c Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:50:26 -0400 Subject: [PATCH 010/117] Version --- SCANmechjeb/Properties/AssemblyInfo.cs | 8 +- SCANsat/Properties/AssemblyInfo.cs | 8 +- SCANsat/SCAN_Map/SCANmap.cs | 310 +++++++++++++------------ 3 files changed, 169 insertions(+), 157 deletions(-) diff --git a/SCANmechjeb/Properties/AssemblyInfo.cs b/SCANmechjeb/Properties/AssemblyInfo.cs index 3280692f7..3ae449b3c 100644 --- a/SCANmechjeb/Properties/AssemblyInfo.cs +++ b/SCANmechjeb/Properties/AssemblyInfo.cs @@ -32,10 +32,10 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.1.0")] -[assembly: AssemblyFileVersion("1.2.1.0")] -[assembly: AssemblyInformationalVersion ("v12.1")] +[assembly: AssemblyVersion("1.3.1.0")] +[assembly: AssemblyFileVersion("1.3.1.0")] +[assembly: AssemblyInformationalVersion ("v13.1")] [assembly: KSPAssembly ("SCANmechjeb", 0, 3)] -[assembly: KSPAssemblyDependency ("SCANsat", 1, 2)] +[assembly: KSPAssemblyDependency ("SCANsat", 1, 3)] [assembly: KSPAssemblyDependency("MechJeb2", 2, 5)] diff --git a/SCANsat/Properties/AssemblyInfo.cs b/SCANsat/Properties/AssemblyInfo.cs index 7ba7091ef..860401d5b 100644 --- a/SCANsat/Properties/AssemblyInfo.cs +++ b/SCANsat/Properties/AssemblyInfo.cs @@ -14,10 +14,10 @@ // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion ("1.2.1.0")] -[assembly: AssemblyFileVersion ("1.2.1.0")] -[assembly: AssemblyInformationalVersion ("v12.1")] +[assembly: AssemblyVersion ("1.3.1.0")] +[assembly: AssemblyFileVersion ("1.3.1.0")] +[assembly: AssemblyInformationalVersion ("v13.1")] -[assembly: KSPAssembly ("SCANsat", 1, 2)] +[assembly: KSPAssembly ("SCANsat", 1, 3)] diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 32a998f9a..569543aaf 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -27,6 +27,14 @@ public class SCANmap internal SCANmap(CelestialBody Body, bool Cache) { body = Body; + pqs = body.pqsController != null; + biomeMap = body.BiomeMap != null; + data = SCANUtil.getData(body); + if (data == null) + { + data = new SCANdata(body); + SCANcontroller.controller.addToBodyData(body, data); + } cache = Cache; } @@ -275,6 +283,7 @@ internal double unprojectLatitude(double lon, double lat) /* MAP: scaling, centering (setting origin), translating, etc */ private double mapscale, lon_offset, lat_offset; private int mapwidth, mapheight; + private Color[] pix; internal void setSize(int w, int h) { @@ -283,6 +292,7 @@ internal void setSize(int w, int h) if (w > 360 * 4) w = 360 * 4; mapwidth = w; + pix = new Color[w]; mapscale = mapwidth / 360f; if (h <= 0) h = (int)(180 * mapscale); @@ -307,6 +317,7 @@ internal void setWidth(int w) if (mapwidth == w) return; mapwidth = w; + pix = new Color[w]; mapscale = mapwidth / 360f; mapheight = (int)(w / 2); /* big map caching */ @@ -378,9 +389,12 @@ private double fixUnscale(double value, int size) private Texture2D map; // refs above: 214,215,216,232, below, and JSISCANsatRPM. private CelestialBody body; // all refs are below private SCANresourceGlobal resource; + private SCANdata data; private SCANmapLegend mapLegend; private int mapstep; // all refs are below private double[] mapline; // all refs are below + private bool pqs; + private bool biomeMap; /* MAP: nearly trivial functions */ public void setBody(CelestialBody b) @@ -388,6 +402,9 @@ public void setBody(CelestialBody b) if (body == b) return; body = b; + pqs = body.pqsController != null; + biomeMap = body.BiomeMap != null; + data = SCANUtil.getData(body); if (SCANconfigLoader.GlobalResource) { resource = SCANcontroller.getResourceNode(SCANcontroller.controller.resourceSelection); @@ -406,7 +423,7 @@ internal bool isMapComplete() public void resetMap(bool setRes = true) { - mapstep = 0; + mapstep = -1; if (SCANconfigLoader.GlobalResource && setRes) { //Make sure that a resource is initialized if necessary if (resource == null && body != null) @@ -460,10 +477,8 @@ internal void exportPNG() /* MAP: build: map to Texture2D */ internal Texture2D getPartialMap() { - SCANdata data = SCANUtil.getData(body); if (data == null) return new Texture2D(1, 1); - Color[] pix; /* init cache if necessary */ if (cache) @@ -499,207 +514,204 @@ internal Texture2D getPartialMap() palette.redline[i] = palette.red; } - if (mapstep < map.height - 1) - { - map.SetPixels(0, mapstep + 1, map.width, 1, palette.redline); - } - - if (mapstep <= 0) + if (mapstep <= -1) { - mapstep = 0; + mapstep = -1; mapline = new double[map.width]; } - pix = map.GetPixels(0, mapstep, map.width, 1); - for (int i = 0; i < map.width; i++) { - Color baseColor = palette.grey; - pix[i] = baseColor; - int scheme = SCANcontroller.controller.colours; - float projVal = 0f; - double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; - double lon = (i * 1.0f / mapscale) - 180f + lon_offset; - double la = lat, lo = lon; - lat = unprojectLatitude(lo, la); - lon = unprojectLongitude(lo, la); - /* Introduce altimetry check here; Use unprojected lat/long coordinates * All cached altimetry data stored in a single 2D array in rectangular format * Pull altimetry data from cache after unprojection */ - if (body.pqsController != null && cache) + if (body.pqsController != null && cache && mapstep + 1 < map.height) { - if (big_heightmap[i, mapstep] == 0f) + double cacheLat = ((mapstep + 1) * 1.0f / mapscale) - 90f + lat_offset; + double cacheLon = (i * 1.0f / mapscale) - 180f + lon_offset; + + if (big_heightmap[i, mapstep + 1] == 0f) { - if (SCANUtil.isCovered(lo, la, data, SCANtype.Altimetry)) - terrainHeightToArray(lo, la, i, mapstep); + if (SCANUtil.isCovered(cacheLon, cacheLat, data, SCANtype.Altimetry)) + terrainHeightToArray(cacheLon, cacheLat, i, mapstep + 1); } } + if (mapstep < 0) + continue; + + Color baseColor = palette.grey; + Color stockBiome = palette.grey; + double resourceAbundance = 0; + bool resources = false; + double bioIndex = 0; + pix[i] = baseColor; + int scheme = SCANcontroller.controller.colours; + float projVal = 0f; + double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; + double lon = (i * 1.0f / mapscale) - 180f + lon_offset; + double la = lat, lo = lon; + lat = unprojectLatitude(lo, la); + lon = unprojectLongitude(lo, la); + if (double.IsNaN(lat) || double.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180) { pix[i] = palette.clear; continue; } - /* Altimetry Map */ - if (mType == mapType.Altimetry) + if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) { - if (body.pqsController == null) - { - baseColor = palette.lerp(palette.black, palette.white, UnityEngine.Random.value); - } - else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Altimetry)) - { - projVal = terrainElevation(lon, lat, data, out scheme); - baseColor = palette.heightToColor(projVal, scheme, data); - } - mapline[i] = projVal; + resourceAbundance = SCANuiUtil.resourceMapValue(lon, lat, data, resource); + if (resourceAbundance >= 0) + resources = true; + } - if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) + if (mType == mapType.Biome && biomeMap) + { + if (SCANcontroller.controller.useStockBiomes && SCANcontroller.controller.colours == 0) { - pix[i] = SCANuiUtil.resourceToColor(lon, lat, data, baseColor, resource); + stockBiome = SCANUtil.getBiome(body, lon, lat).mapColor; + if (SCANcontroller.controller.biomeBorder) + bioIndex = SCANUtil.getBiomeIndexFraction(body, lon, lat); } - else pix[i] = baseColor; - - /* draw height lines - works, but mostly useless... - int step = (int)(val / 1000); - int step_h = step, step_v = step; - if(i > 0) step_h = (int)(bigline[i - 1] / 1000); - if(bigstep > 0) step_v = (int)(bigline[i] / 1000); - if(step != step_h || step != step_v) { - pix[i] = palette.white; - } - */ - //mapline [i] = val; + else + bioIndex = SCANUtil.getBiomeIndexFraction(body, lon, lat); } - /* Slope Map */ - else if (mType == mapType.Slope) + switch (mType) { - if (body.pqsController == null) - { - baseColor = palette.lerp(palette.black, palette.white, UnityEngine.Random.value); - } - else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Altimetry)) - { - projVal = terrainElevation(lon, lat, data, out scheme); - if (mapstep == 0) + case mapType.Altimetry: { - baseColor = palette.grey; - } - else - { - // This doesn't actually calculate the slope per se, but it's faster - // than asking for yet more elevation data. Please don't use this - // code to operate nuclear power plants or rockets. - double v1 = mapline[i]; - if (i > 0) - v1 = Math.Max(v1, mapline[i - 1]); - if (i < mapline.Length - 1) - v1 = Math.Max(v1, mapline[i + 1]); - float v = Mathf.Clamp((float)Math.Abs(projVal - v1) / 1000f, 0, 2f); - if (SCANcontroller.controller.colours == 1) + if (!pqs) { - baseColor = palette.lerp(palette.black, palette.white, v / 2f); + baseColor = palette.lerp(palette.black, palette.white, UnityEngine.Random.value); } - else + else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Altimetry)) { - if (v < 1) - { - baseColor = palette.lerp(SCANcontroller.controller.lowSlopeColorOne, SCANcontroller.controller.highSlopeColorOne, v); - } - else - { - baseColor = palette.lerp(SCANcontroller.controller.lowSlopeColorTwo, SCANcontroller.controller.highSlopeColorTwo, v - 1); - } + projVal = terrainElevation(lon, lat, data, out scheme); + baseColor = palette.heightToColor(projVal, scheme, data); } + break; } - mapline[i] = projVal; - } - if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) - { - pix[i] = SCANuiUtil.resourceToColor(lon, lat, data, baseColor, resource); - } - else pix[i] = baseColor; - } - - /* Biome Map */ - else if (mType == mapType.Biome) - { - if (body.BiomeMap == null) - { - baseColor = palette.lerp(palette.black, palette.white, UnityEngine.Random.value); - } - /* // this just basically stretches the actual biome map to fit... it looks horrible - float u = ((lon + 360 + 180 + 90)) % 360; - float v = ((lat + 180 + 90)) % 180; - if(u < 0 || v < 0 || u >= 360 || v >= 180) continue; - u /= 360f; v /= 180f; - pix[i] = body.BiomeMap.Map.GetPixelBilinear(u, v); - */ - else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Biome)) - { - double bio = SCANUtil.getBiomeIndexFraction(body, lon, lat); - Color biome = palette.grey; - if (SCANcontroller.controller.colours == 1) + case mapType.Slope: { - if ((i > 0 && mapline[i - 1] != bio) || (mapstep > 0 && mapline[i] != bio)) + if (!pqs) { - biome = palette.white; + baseColor = palette.lerp(palette.black, palette.white, UnityEngine.Random.value); } - else + else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Altimetry)) { - biome = palette.lerp(palette.black, palette.white, (float)bio); + projVal = terrainElevation(lon, lat, data, out scheme); + if (mapstep >= 0) + { + // This doesn't actually calculate the slope per se, but it's faster + // than asking for yet more elevation data. Please don't use this + // code to operate nuclear power plants or rockets. + double v1 = mapline[i]; + if (i > 0) + v1 = Math.Max(v1, mapline[i - 1]); + if (i < mapline.Length - 1) + v1 = Math.Max(v1, mapline[i + 1]); + float v = Mathf.Clamp((float)Math.Abs(projVal - v1) / 1000f, 0, 2f); + if (SCANcontroller.controller.colours == 1) + { + baseColor = palette.lerp(palette.black, palette.white, v / 2f); + } + else + { + if (v < 1) + { + baseColor = palette.lerp(SCANcontroller.controller.lowSlopeColorOne, SCANcontroller.controller.highSlopeColorOne, v); + } + else + { + baseColor = palette.lerp(SCANcontroller.controller.lowSlopeColorTwo, SCANcontroller.controller.highSlopeColorTwo, v - 1); + } + } + } + mapline[i] = projVal; } + break; } - else + case mapType.Biome: { - Color elevation = palette.grey; - if (SCANcontroller.controller.biomeTransparency > 0) + if (!biomeMap) + { + baseColor = palette.lerp(palette.black, palette.white, UnityEngine.Random.value); + } + else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Biome)) { - if (body.pqsController == null) + Color biome = palette.grey; + if (SCANcontroller.controller.colours == 1) { - elevation = palette.grey; + if ((i > 0 && mapline[i - 1] != bioIndex) || (mapstep > 0 && mapline[i] != bioIndex)) + { + biome = palette.white; + } + else + { + biome = palette.lerp(palette.black, palette.white, (float)bioIndex); + } } - else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Altimetry)) + else { - projVal = terrainElevation(lon, lat, data, out scheme); - elevation = palette.lerp(palette.black, palette.white, Mathf.Clamp(projVal + 1500f, 0, 9000) / 9000f); + Color elevation = palette.grey; + if (SCANcontroller.controller.biomeTransparency > 0) + { + if (!pqs) + { + elevation = palette.grey; + } + else if (SCANUtil.isCovered(lon, lat, data, SCANtype.Altimetry)) + { + projVal = terrainElevation(lon, lat, data, out scheme); + elevation = palette.lerp(palette.black, palette.white, Mathf.Clamp(projVal + (-1f * data.TerrainConfig.TerrainRange), 0, data.TerrainConfig.TerrainRange) / data.TerrainConfig.TerrainRange); + } + } + + if (SCANcontroller.controller.biomeBorder && ((i > 0 && mapline[i - 1] != bioIndex) || (mapstep > 0 && mapline[i] != bioIndex))) + { + biome = palette.white; + } + else if (SCANcontroller.controller.useStockBiomes) + { + biome = palette.lerp(stockBiome, elevation, SCANcontroller.controller.biomeTransparency / 100f); + } + else + { + biome = palette.lerp(palette.lerp(SCANcontroller.controller.lowBiomeColor, SCANcontroller.controller.highBiomeColor, (float)bioIndex), elevation, SCANcontroller.controller.biomeTransparency / 100f); + } } - } - if ((i > 0 && mapline[i - 1] != bio) || (mapstep > 0 && mapline[i] != bio)) - { - biome = palette.white; - } - else if (SCANcontroller.controller.useStockBiomes) - { - Color c = SCANUtil.getBiome(body, lon, lat).mapColor; - biome = palette.lerp(c, elevation, SCANcontroller.controller.biomeTransparency / 100f); - } - else - { - biome = palette.lerp(palette.lerp(SCANcontroller.controller.lowBiomeColor, SCANcontroller.controller.highBiomeColor, (float)bio), elevation, SCANcontroller.controller.biomeTransparency / 100f); + baseColor = biome; + mapline[i] = bioIndex; } + break; } - - baseColor = biome; - mapline[i] = bio; - } - if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) - { - pix[i] = SCANuiUtil.resourceToColor(lon, lat, data, baseColor, resource); - } - else pix[i] = baseColor; } + + if (resources) + pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, resourceAbundance); + else + pix[i] = baseColor; } - map.SetPixels(0, mapstep, map.width, 1, pix); + + if (mapstep >= 0) + map.SetPixels(0, mapstep, map.width, 1, pix); + mapstep++; + if (mapstep % 10 == 0 || mapstep >= map.height) + { + if (mapstep < map.height - 1) + map.SetPixels(0, mapstep, map.width, 1, palette.redline); + map.Apply(); + } + return map; } From 12ac6aa67c0469baa2bfcfaf7142ff93a179b4c1 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:50:35 -0400 Subject: [PATCH 011/117] new class --- SCANsat/SCANsat.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/SCANsat/SCANsat.csproj b/SCANsat/SCANsat.csproj index e58707acb..add2fcb37 100644 --- a/SCANsat/SCANsat.csproj +++ b/SCANsat/SCANsat.csproj @@ -92,6 +92,7 @@ + From fb31c976871913c43d0f94596c5b85c6acbc850f Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:50:48 -0400 Subject: [PATCH 012/117] disable stock scanner --- SCANsat/SCANresourceScanner.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/SCANsat/SCANresourceScanner.cs b/SCANsat/SCANresourceScanner.cs index a9aa29220..e23d63419 100644 --- a/SCANsat/SCANresourceScanner.cs +++ b/SCANsat/SCANresourceScanner.cs @@ -80,7 +80,7 @@ public override void OnUpdate() if (SCANcontroller.controller == null) return; - if (!SCANcontroller.controller.easyModeScanning) + if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) updateEvents(); else { @@ -115,11 +115,25 @@ public void DisableModule() { this.isEnabled = false; unregisterScanner(); + if (mSurvey != null && SCANcontroller.controller.disableStockResource) + { + foreach (ModuleOrbitalSurveyor m in mSurvey) + { + m.DisableModule(); + } + } } public void EnableModule() { this.isEnabled = true; + if (mSurvey != null && SCANcontroller.controller.disableStockResource) + { + foreach (ModuleOrbitalSurveyor m in mSurvey) + { + m.DisableModule(); + } + } } public bool IsSituationValid() From e2427e2cef503bf2a1164304113c44aae00d2c6e Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:51:08 -0400 Subject: [PATCH 013/117] use cached terrain height range --- SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs b/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs index 32583a5b8..22bf4ec96 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs @@ -116,15 +116,14 @@ public static Color heightToColor(float val, int scheme, SCANdata data) if (data.TerrainConfig.PalRev) c = data.TerrainConfig.ColorPal.colorsReverse; if (scheme == 0) - return heightToColor(val, data.TerrainConfig.MaxTerrain, data.TerrainConfig.MinTerrain, data.TerrainConfig.ClampTerrain, data.TerrainConfig.PalDis, c); + return heightToColor(val, data.TerrainConfig.MaxTerrain, data.TerrainConfig.MinTerrain, data.TerrainConfig.TerrainRange, data.TerrainConfig.ClampTerrain, data.TerrainConfig.PalDis, c); else - return heightToColor(val, data.TerrainConfig.MaxTerrain, data.TerrainConfig.MinTerrain, data.TerrainConfig.PalDis); + return heightToColor(val, data.TerrainConfig.MaxTerrain, data.TerrainConfig.MinTerrain, data.TerrainConfig.TerrainRange, data.TerrainConfig.PalDis); } - private static Color heightToColor(float val, float max, float min, bool discrete) + private static Color heightToColor(float val, float max, float min, float range, bool discrete) { Color c = black; - float range = max - min; val -= min; if (discrete) { @@ -143,7 +142,7 @@ private static Color heightToColor(float val, float max, float min, bool discret return c; } - internal static Color heightToColor(float val, float max, float min, float? clamp, bool discrete, Color32[] p) + internal static Color heightToColor(float val, float max, float min, float range, float? clamp, bool discrete, Color32[] p) { Color c = black; if (clamp != null) @@ -183,7 +182,6 @@ internal static Color heightToColor(float val, float max, float min, float? clam } else { - float range = max - min; val -= min; if (discrete) { From be6ff6f335215784a7aadf3ddde64fa6ea89cd3d Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:51:14 -0400 Subject: [PATCH 014/117] new styles --- SCANsat/SCAN_UI/UI_Framework/SCANskins.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs index b7012d3d7..f819f3e5d 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs @@ -52,6 +52,10 @@ class SCANskins: SCAN_MBE internal static GUIStyle SCAN_insWhiteLabel; internal static GUIStyle SCAN_anomalyOverlay; + //Resource controller styles + internal static GUIStyle SCAN_labelLeft; + internal static GUIStyle SCAN_labelRight; + //Settings menu styles internal static GUIStyle SCAN_headline; internal static GUIStyle SCAN_headlineSmall; @@ -292,6 +296,12 @@ private static void initializeSkins() SCAN_labelSmallRight.name = "SCAN_LabelSmallRight"; SCAN_labelSmallRight.alignment = TextAnchor.MiddleRight; + SCAN_labelLeft = new GUIStyle(SCAN_labelSmallLeft); + SCAN_labelLeft.fontSize = 12; + + SCAN_labelRight = new GUIStyle(SCAN_labelSmallRight); + SCAN_labelRight.fontSize = 12; + SCAN_buttonWarning = new GUIStyle(SCAN_button); SCAN_buttonWarning.name = "SCAN_ButtonWarning"; SCAN_buttonWarning.fontSize = 16; From bea3a63deb5b99e5df694f72a0d6851ea556e985 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:51:45 -0400 Subject: [PATCH 015/117] Biome border option --- SCANsat/SCAN_Color_Config.cs | 9 +++++++++ SCANsat/SCAN_UI/SCANcolorSelection.cs | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/SCANsat/SCAN_Color_Config.cs b/SCANsat/SCAN_Color_Config.cs index 92f2e6ba7..e511d9585 100644 --- a/SCANsat/SCAN_Color_Config.cs +++ b/SCANsat/SCAN_Color_Config.cs @@ -44,6 +44,8 @@ public class SCAN_Color_Config : SCAN_ConfigNodeStorage [Persistent] private bool stockBiomeMap = false; [Persistent] + private bool biomeBorder = true; + [Persistent] private Color bottomLowSlopeColor = palette.xkcd_PukeGreen; [Persistent] private Color bottemHighSlopeColor = palette.xkcd_Lemon; @@ -82,6 +84,8 @@ public override void OnEncodeToConfigNode() lowBiomeColor = SCANcontroller.controller.lowBiomeColor; highBiomeColor = SCANcontroller.controller.highBiomeColor; biomeTransparency = SCANcontroller.controller.biomeTransparency; + stockBiomeMap = SCANcontroller.controller.useStockBiomes; + biomeBorder = SCANcontroller.controller.biomeBorder; bottomLowSlopeColor = SCANcontroller.controller.lowSlopeColorOne; bottemHighSlopeColor = SCANcontroller.controller.highSlopeColorOne; topLowSlopeColor = SCANcontroller.controller.lowSlopeColorTwo; @@ -134,6 +138,11 @@ public bool StockBiomeMap get { return stockBiomeMap; } } + public bool BiomeBorder + { + get { return biomeBorder; } + } + public Color BottomLowSlopeColor { get { return bottomLowSlopeColor; } diff --git a/SCANsat/SCAN_UI/SCANcolorSelection.cs b/SCANsat/SCAN_UI/SCANcolorSelection.cs index 1542fd00c..2c71a5493 100644 --- a/SCANsat/SCAN_UI/SCANcolorSelection.cs +++ b/SCANsat/SCAN_UI/SCANcolorSelection.cs @@ -43,6 +43,7 @@ class SCANcolorSelection: SCAN_MBW private float bTrans, rTrans; private bool stockBiomes = false; + private bool biomeBorders = true; private SCANresourceGlobal currentResource; private float lowRCutoff, highRCutoff; @@ -111,6 +112,7 @@ protected override void Start() currentTerrain = new SCANterrainConfig(data.TerrainConfig); stockBiomes = SCANcontroller.controller.useStockBiomes; + biomeBorders = SCANcontroller.controller.biomeBorder; minTerrainSlider = new SCANuiSlider(data.TerrainConfig.DefaultMinHeight - SCANconfigLoader.SCANNode.RangeBelowMinHeight, data.TerrainConfig.MaxTerrain - 100, data.TerrainConfig.MinTerrain, "Min: ", "m", -2); maxTerrainSlider = new SCANuiSlider(data.TerrainConfig.MinTerrain + 100, data.TerrainConfig.DefaultMaxHeight + SCANconfigLoader.SCANNode.RangeAboveMaxHeight, data.TerrainConfig.MaxTerrain, "Max: ", "m", -2); @@ -750,6 +752,8 @@ private void biomeOptions(int id) fillS(20); stockBiomes = GUILayout.Toggle(stockBiomes, "Use Stock Biome Maps", SCANskins.SCAN_toggle); fillS(8); + biomeBorders = GUILayout.Toggle(biomeBorders, "White Biome Borders", SCANskins.SCAN_toggle); + fillS(8); growE(); fillS(10); biomeTransSlider.drawSlider(false, ref bTrans); @@ -811,6 +815,7 @@ private void biomeConfirm(int id) SCANcontroller.controller.lowBiomeColor = biomeColorPicker.ColorLow; SCANcontroller.controller.highBiomeColor = biomeColorPicker.ColorHigh; SCANcontroller.controller.useStockBiomes = stockBiomes; + SCANcontroller.controller.biomeBorder = biomeBorders; SCANcontroller.controller.biomeTransparency = bTrans; biomeColorPicker.updateOldSwatches(); @@ -829,9 +834,11 @@ private void biomeConfirm(int id) SCANcontroller.controller.lowBiomeColor = SCANconfigLoader.SCANNode.LowBiomeColor; SCANcontroller.controller.highBiomeColor = SCANconfigLoader.SCANNode.HighBiomeColor; SCANcontroller.controller.useStockBiomes = SCANconfigLoader.SCANNode.StockBiomeMap; + SCANcontroller.controller.biomeBorder = SCANconfigLoader.SCANNode.BiomeBorder; SCANcontroller.controller.biomeTransparency = SCANconfigLoader.SCANNode.BiomeTransparency; - stockBiomes = false; + stockBiomes = SCANcontroller.controller.useStockBiomes; + biomeBorders = SCANcontroller.controller.biomeBorder; biomeColorPicker = new SCANuiColorPicker(SCANcontroller.controller.lowBiomeColor, SCANcontroller.controller.highBiomeColor, biomeColorPicker.LowColorChange); @@ -1166,7 +1173,7 @@ private void drawPreviewLegend() if (currentTerrain.PalRev) c = currentTerrain.ColorPal.colorsReverse; previewLegend = new SCANmapLegend(); - previewLegend.Legend = previewLegend.getLegend(maxT, minT, clamp, currentTerrain.PalDis, c); + previewLegend.Legend = previewLegend.getLegend(maxT, minT, maxT - minT, clamp, currentTerrain.PalDis, c); } //Resets the palettes whenever the size slider is adjusted From b56653083bd2ae43d33080a1c80e35d2e6b5cf7c Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:52:11 -0400 Subject: [PATCH 016/117] terrain range --- SCANsat/SCAN_Data/SCANterrainConfig.cs | 28 +++++++++++++++----------- SCANsat/SCAN_Map/SCANmapLegend.cs | 4 ++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/SCANsat/SCAN_Data/SCANterrainConfig.cs b/SCANsat/SCAN_Data/SCANterrainConfig.cs index e4dae6c9c..d7dbbdd81 100644 --- a/SCANsat/SCAN_Data/SCANterrainConfig.cs +++ b/SCANsat/SCAN_Data/SCANterrainConfig.cs @@ -43,6 +43,7 @@ public class SCANterrainConfig : SCAN_ConfigNodeStorage private float? clampTerrain; private float defaultMinHeight, defaultMaxHeight; + private float terrainRange; private Palette defaultPalette; private int defaultPaletteSize; private bool defaultReverse, defaultDiscrete; @@ -52,6 +53,7 @@ internal SCANterrainConfig(float min, float max, float? clamp, Palette color, in { minHeightRange = min; maxHeightRange = max; + terrainRange = max - min; clampTerrain = clamp; if (clampTerrain == null) clampHeight = "Null"; @@ -77,6 +79,7 @@ internal SCANterrainConfig(SCANterrainConfig copy) { minHeightRange = copy.minHeightRange; maxHeightRange = copy.maxHeightRange; + terrainRange = maxHeightRange - minHeightRange; clampTerrain = copy.clampTerrain; clampHeight = copy.clampHeight; colorPal = copy.colorPal; @@ -104,18 +107,9 @@ public override void OnDecodeFromConfigNode() else clampTerrain = null; - setDefaultValues(); + terrainRange = maxHeightRange - minHeightRange; - SCANUtil.SCANdebugLog("SCANsat Terrain Config Decode"); - SCANUtil.SCANdebugLog("-------->Body Name => {0}", name); - SCANUtil.SCANdebugLog("-------->Body Index => {0}", index); - SCANUtil.SCANdebugLog("-------->Min Height Range => {0}", minHeightRange); - SCANUtil.SCANdebugLog("-------->Max Height Range => {0}", maxHeightRange); - SCANUtil.SCANdebugLog("-------->Clamp Height => {0}", clampHeight); - SCANUtil.SCANdebugLog("-------->Palette Name => {0}", paletteName); - SCANUtil.SCANdebugLog("-------->Palette Size => {0}", paletteSize); - SCANUtil.SCANdebugLog("-------->Palette Reverse => {0}", paletteReverse); - SCANUtil.SCANdebugLog("-------->Palette Discrete => {0}", paletteDiscrete); + setDefaultValues(); } private void setDefaultValues() @@ -131,7 +125,6 @@ private void setDefaultValues() public override void OnEncodeToConfigNode() { - SCANUtil.SCANdebugLog("Saving Terrain Node"); if (clampTerrain == null) clampHeight = "Null"; else @@ -146,7 +139,10 @@ public float MinTerrain internal set { if (value < maxHeightRange) + { + terrainRange = maxHeightRange - value; minHeightRange = value; + } } } @@ -156,10 +152,18 @@ public float MaxTerrain internal set { if (value > minHeightRange) + { + terrainRange = value - minHeightRange; maxHeightRange = value; + } } } + public float TerrainRange + { + get { return terrainRange; } + } + public float? ClampTerrain { get { return clampTerrain; } diff --git a/SCANsat/SCAN_Map/SCANmapLegend.cs b/SCANsat/SCAN_Map/SCANmapLegend.cs index d338c5f3c..d20dd2952 100644 --- a/SCANsat/SCAN_Map/SCANmapLegend.cs +++ b/SCANsat/SCAN_Map/SCANmapLegend.cs @@ -66,14 +66,14 @@ internal Texture2D getLegend(int scheme, SCANdata data) return t; } - internal Texture2D getLegend(float max, float min, float? clamp, bool discrete, Color32[] c) + internal Texture2D getLegend(float max, float min, float range, float? clamp, bool discrete, Color32[] c) { Texture2D t = new Texture2D(128, 1, TextureFormat.RGB24, false); Color[] pix = t.GetPixels(); for (int x = 0; x < 128; x++) { float val = (x * (max - min)) / 128f + min; - pix[x] = palette.heightToColor(val, max, min, clamp, discrete, c); + pix[x] = palette.heightToColor(val, max, min, range, clamp, discrete, c); } t.SetPixels(pix); t.Apply(); From 82fe078238bb9d94423c668853ce32c2a7eaef91 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:52:22 -0400 Subject: [PATCH 017/117] New resource types --- SCANsat/SCAN_Data/SCANdata.cs | 4 ++-- SCANsat/SCAN_Data/SCANtype.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SCANsat/SCAN_Data/SCANdata.cs b/SCANsat/SCAN_Data/SCANdata.cs index d0cbfced6..1abefb237 100644 --- a/SCANsat/SCAN_Data/SCANdata.cs +++ b/SCANsat/SCAN_Data/SCANdata.cs @@ -308,7 +308,7 @@ internal int getCoverage(SCANtype type) uncov += coverage_count[7]; if ((type & SCANtype.Ore) != SCANtype.Nothing) uncov += coverage_count[8]; - if ((type & SCANtype.Kethane_4) != SCANtype.Nothing) + if ((type & SCANtype.Helium3) != SCANtype.Nothing) uncov += coverage_count[9]; if ((type & SCANtype.Uraninite) != SCANtype.Nothing) uncov += coverage_count[10]; @@ -328,7 +328,7 @@ internal int getCoverage(SCANtype type) uncov += coverage_count[17]; if ((type & SCANtype.Karbonite) != SCANtype.Nothing) uncov += coverage_count[18]; - if ((type & SCANtype.Regolith_10) != SCANtype.Nothing) + if ((type & SCANtype.FuzzyResources) != SCANtype.Nothing) uncov += coverage_count[19]; if ((type & SCANtype.Regolith_11) != SCANtype.Nothing) uncov += coverage_count[20]; diff --git a/SCANsat/SCAN_Data/SCANtype.cs b/SCANsat/SCAN_Data/SCANtype.cs index 1ac7c2a2d..c4f14df9b 100644 --- a/SCANsat/SCAN_Data/SCANtype.cs +++ b/SCANsat/SCAN_Data/SCANtype.cs @@ -25,10 +25,10 @@ public enum SCANtype : int Biome = 1 << 3, // biome data Anomaly = 1 << 4, // anomalies (position of anomaly) AnomalyDetail = 1 << 5, // anomaly detail (name of anomaly, etc.) - Kethane = 1 << 6, // Kethane - K-type - Kethane + Kethane = 1 << 6, // Kethane MetallicOre = 1 << 7, // CRP Ore - Regolith Ore = 1 << 8, //Stock Ore - Kethane_4 = 1 << 9, // Reserved - K-type + Helium3 = 1 << 9, // Helium 3 Uraninite = 1 << 10, // Uranium - Regolith - KSPI Thorium = 1 << 11, // Thorium - Regolith - KSPI Alumina = 1 << 12, // Alumina - Regolith - KSPI @@ -38,7 +38,7 @@ public enum SCANtype : int Substrate = 1 << 16, // Substrate - Regolith & K-type - MKS KEEZO = 1 << 17, // KEEZO - Regolith - Kass Effect Karbonite = 1 << 18, // Karbonite - Regolith - Regolith_10 = 1 << 19, // Reserved - Regolith + FuzzyResources = 1 << 19, // Low Detail Resource Regolith_11 = 1<< 20, // Reserved - Regolith Everything_SCAN = (1 << 6) - 1, // All default SCANsat scanners From d4a428e5e05dfe39690a9bd56abc920ced6c57cb Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:52:35 -0400 Subject: [PATCH 018/117] check for wrong biomes --- SCANsat/SCANutil.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SCANsat/SCANutil.cs b/SCANsat/SCANutil.cs index ed6ce1b78..638598d11 100644 --- a/SCANsat/SCANutil.cs +++ b/SCANsat/SCANutil.cs @@ -263,7 +263,7 @@ internal static float ResourceOverlay(double lat, double lon, string name, Celes return amount; } - internal static int getBiomeIndex(CelestialBody body, double lon , double lat) + private static int getBiomeIndex(CelestialBody body, double lon , double lat) { if (body.BiomeMap == null) return -1; double u = fixLon(lon); @@ -290,6 +290,8 @@ internal static CBAttributeMapSO.MapAttribute getBiome(CelestialBody body, doubl { if (body.BiomeMap == null) return null; int i = getBiomeIndex(body, lon , lat); + if (i == -1) + return null; return body.BiomeMap.Attributes [i]; } From db8fc4512274efd4a75d59555318f0f78ec30fcc Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:52:48 -0400 Subject: [PATCH 019/117] store planetary resource fraction --- SCANsat/SCAN_Data/SCANresourceBody.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SCANsat/SCAN_Data/SCANresourceBody.cs b/SCANsat/SCAN_Data/SCANresourceBody.cs index 04704bc93..c97280d59 100644 --- a/SCANsat/SCAN_Data/SCANresourceBody.cs +++ b/SCANsat/SCAN_Data/SCANresourceBody.cs @@ -31,6 +31,7 @@ public class SCANresourceBody : SCAN_ConfigNodeStorage private CelestialBody body; private float defaultMinValue, defaultMaxValue; + private float fraction; internal SCANresourceBody(string rName, CelestialBody Body, float min, float max) { @@ -125,5 +126,11 @@ internal set defaultMaxValue = value; } } + + public float Fraction + { + get { return fraction; } + internal set { fraction = value; } + } } } From e43e3943f61028c7bfd6e82ac72fdd0bc42958a7 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:53:01 -0400 Subject: [PATCH 020/117] new resource overlay window --- SCANsat/SCAN_UI/SCANresourceController.cs | 193 ++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 SCANsat/SCAN_UI/SCANresourceController.cs diff --git a/SCANsat/SCAN_UI/SCANresourceController.cs b/SCANsat/SCAN_UI/SCANresourceController.cs new file mode 100644 index 000000000..bbce69589 --- /dev/null +++ b/SCANsat/SCAN_UI/SCANresourceController.cs @@ -0,0 +1,193 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SCANsat.SCAN_Data; +using SCANsat.SCAN_UI.UI_Framework; +using SCANsat.SCAN_Platform; +using UnityEngine; +using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette; + +namespace SCANsat.SCAN_UI +{ + class SCANresourceController : SCAN_MBW + { + internal readonly static Rect defaultRect = new Rect(Screen.width - 200, 200, 250, 300); + private static Rect sessionRect = defaultRect; + private CelestialBody body; + private SCANdata data; + private SCANresourceGlobal currentResource; + private List resources; + private List resourceFractions; + private bool drawResourceOverlay = false; + private bool oldOverlay = false; + + private int step; + + protected override void Awake() + { + WindowCaption = "S.C.A.N. Resources"; + WindowRect = sessionRect; + WindowStyle = SCANskins.SCAN_window; + WindowOptions = new GUILayoutOption[2] { GUILayout.Width(280), GUILayout.Height(300) }; + Visible = false; + DragEnabled = true; + ClampToScreenOffset = new RectOffset(-200, -200, -40, -40); + + SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); + } + + protected override void Start() + { + resources = SCANcontroller.setLoadedResourceList(); + + setBody(FlightGlobals.currentMainBody); + } + + protected override void Update() + { + if (MapView.MapIsEnabled) + { + MapObject target = PlanetariumCamera.fetch.target; + + CelestialBody mapBody = getTargetBody(target); + if (mapBody == null) + return; + + if (mapBody != body) + setBody(mapBody); + } + else + { + if (body != FlightGlobals.currentMainBody) + setBody(FlightGlobals.currentMainBody); + } + } + + protected override void OnDestroy() + { + + } + + private CelestialBody getTargetBody(MapObject target) + { + if (target.type == MapObject.MapObjectType.CELESTIALBODY) + { + return target.celestialBody; + } + else if (target.type == MapObject.MapObjectType.MANEUVERNODE) + { + return target.maneuverNode.patch.referenceBody; + } + else if (target.type == MapObject.MapObjectType.VESSEL) + { + return target.vessel.mainBody; + } + + return null; + } + + protected override void DrawWindowPre(int id) + { + + } + + protected override void DrawWindow(int id) + { + versionLabel(id); /* Standard version label and close button */ + closeBox(id); + + drawResourceList(id); + overlayToggle(id); + drawOverlay(id); + } + + protected override void DrawWindowPost(int id) + { + if (oldOverlay != drawResourceOverlay) + { + oldOverlay = drawResourceOverlay; + if (oldOverlay) + body.SetResourceMap(currentResource.MapOverlay); + else + body.SetResourceMap(null); + } + } + + //Draw the version label in the upper left corner + private void versionLabel(int id) + { + Rect r = new Rect(4, 0, 50, 18); + GUI.Label(r, SCANmainMenuLoader.SCANsatVersion, SCANskins.SCAN_whiteReadoutLabel); + } + + //Draw the close button in the upper right corner + private void closeBox(int id) + { + Rect r = new Rect(WindowRect.width - 20, 1, 18, 18); + if (GUI.Button(r, SCANcontroller.controller.closeBox, SCANskins.SCAN_closeButton)) + { + Visible = false; + } + } + + private void drawResourceList(int id) + { + foreach (SCANresourceGlobal r in resources) + { + growE(); + if (GUILayout.Button(r.Name, SCANskins.SCAN_labelLeft)) + { + currentResource = r; + currentResource.CurrentBodyConfig(body.name); + oldOverlay = drawResourceOverlay = false; + } + + //if (GUILayout.Button(r.CurrentBody.Fraction.ToString("P1"), SCANskins.SCAN_labelRight)) + //{ + // currentResource = r; + // currentResource.CurrentBodyConfig(body.name); + //} + stopE(); + } + } + + private void overlayToggle(int id) + { + drawResourceOverlay = GUILayout.Toggle(drawResourceOverlay, "Draw Overlay", SCANskins.SCAN_settingsToggle); + } + + private void drawOverlay(int id) + { + if (drawResourceOverlay) + SCANuiUtil.drawResourceTexture(512, ref step, data, currentResource); + } + + private void setBody(CelestialBody B) + { + body = B; + data = SCANUtil.getData(body); + if (data == null) + { + data = new SCANdata(body); + SCANcontroller.controller.addToBodyData(body, data); + } + resourceFractions = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, body); + if (resources.Count > 0) + { + currentResource = resources[0]; + currentResource.CurrentBodyConfig(body.name); + + foreach (SCANresourceGlobal r in resources) + { + SCANresourceBody b = r.getBodyConfig(body.name, false); + if (b != null) + { + b.Fraction = resourceFractions.FirstOrDefault(a => a.resourceName == r.Name).fraction; + } + } + } + + oldOverlay = drawResourceOverlay = false; + } + } +} From 9133b55bb1066b2d692cd0aa61228134b0d77e5d Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:53:22 -0400 Subject: [PATCH 021/117] new resource settings and overlay window control --- SCANsat/SCAN_UI/SCANsettingsUI.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/SCANsat/SCAN_UI/SCANsettingsUI.cs b/SCANsat/SCAN_UI/SCANsettingsUI.cs index d08d45044..ac7ce7392 100644 --- a/SCANsat/SCAN_UI/SCANsettingsUI.cs +++ b/SCANsat/SCAN_UI/SCANsettingsUI.cs @@ -39,6 +39,8 @@ class SCANsettingsUI: SCAN_MBW internal readonly static Rect defaultRect = new Rect(Screen.width - (Screen.width / 2) - 180, 100, 360, 300); + private SCANresourceController resourceWindow; + protected override void Awake() { WindowCaption = "S.C.A.N. Settings"; @@ -379,9 +381,15 @@ private void gui_settings_resources(int id) SCANcontroller.controller.needsNarrowBand = GUILayout.Toggle(SCANcontroller.controller.needsNarrowBand, "Zoom Requires Narrow Band Scanner", SCANskins.SCAN_settingsToggle); fillS(); stopE(); + growE(); + fillS(); + SCANcontroller.controller.disableStockResource = GUILayout.Toggle(SCANcontroller.controller.disableStockResource, "Disable Stock Scanning", SCANskins.SCAN_settingsToggle); + fillS(); + stopE(); if (popup) { GUILayout.Label("Reset Resource Coverage", SCANskins.SCAN_button); + GUILayout.Label("Open Resource Overlay Window", SCANskins.SCAN_button); } else { @@ -390,6 +398,15 @@ private void gui_settings_resources(int id) popup = !popup; warningResource = !warningResource; } + + if (GUILayout.Button("Open Resource Overlay Window")) + { + if (resourceWindow == null) + { + resourceWindow = gameObject.AddComponent(); + } + resourceWindow.Visible = !resourceWindow.Visible; + } } } From 6889ef490f2ccc19ffe4acd2c1570acddc84007c Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:53:32 -0400 Subject: [PATCH 022/117] changes to resource overlay --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 70 +++++++++++++--------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 6ffe90b0c..650076560 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.Text.RegularExpressions; +using System.Linq; using FinePrint; using SCANsat.SCAN_Platform; using SCANsat.SCAN_Data; @@ -1350,47 +1351,51 @@ private static void GLVertexMap(Vector3d pos) internal static void drawResourceTexture(int height, ref int step, SCANdata data, SCANresourceGlobal resource) { - Color[] pix; + int stepScale = height / 16; + int width = height * 2; + Color[] pix = new Color[width * stepScale]; float scale = height / 180f; + if (resource.MapOverlay == null) { - resource.MapOverlay = new Texture2D(height * 2, height, TextureFormat.ARGB32, true); - pix = resource.MapOverlay.GetPixels(); + resource.MapOverlay = new Texture2D(width, height, TextureFormat.ARGB32, true); + Color[] c = resource.MapOverlay.GetPixels(); for (int i = 0; i < pix.Length; i++) - pix[i] = palette.clear; - resource.MapOverlay.SetPixels(pix); + c[i] = palette.clear; + resource.MapOverlay.SetPixels(c); } else if (step >= resource.MapOverlay.height) { return; } - pix = resource.MapOverlay.GetPixels(0, step, resource.MapOverlay.width, 1); - - for (int i = 0; i < pix.Length; i++) + for (int j = 0; j < stepScale; j++) { - double lon = (i / scale); - double lat = (step / scale) - 90; + for (int i = 0; i < width; i++) + { + double lon = (i / scale); + double lat = ((step + j) / scale) - 90; - if (lon <= 180) - lon = 180 - lon; - else - lon = (lon - 180) * -1; - lon -= 90; - if (lon < -180) - lon += 360; + if (lon <= 180) + lon = 180 - lon; + else + lon = (lon - 180) * -1; + lon -= 90; + if (lon < -180) + lon += 360; - pix[i] = resourceToColor(lon, lat, data, palette.clear, resource, 0.05f); + pix[j * width + i] = resourceToColor(palette.clear, resource, resourceMapValue(lon, lat, data, resource), 0.05f); + } } - resource.MapOverlay.SetPixels(0, step, resource.MapOverlay.width, 1, pix); - step++; - if (step % 10 == 0 || step >= height) + resource.MapOverlay.SetPixels(0, step, resource.MapOverlay.width, stepScale, pix); + step += stepScale; + if (step % stepScale == 0 || step >= height) resource.MapOverlay.Apply(); } - private static double resourceMapValue(double Lon, double Lat, SCANdata Data, SCANresourceGlobal resource) + internal static double resourceMapValue(double Lon, double Lat, SCANdata Data, SCANresourceGlobal resource) { double amount = 0; if (SCANUtil.isCovered(Lon, Lat, Data, resource.SType)) @@ -1405,21 +1410,32 @@ private static double resourceMapValue(double Lon, double Lat, SCANdata Data, SC else amount = 0; } + else if (SCANUtil.isCovered(Lon, Lat, Data, SCANtype.FuzzyResources)) + { + amount = SCANUtil.ResourceOverlay(((int)(Lat * 5)) / 5, ((int)(Lon * 5)) / 5, resource.Name, Data.Body); + amount *= 100; + if (amount >= resource.CurrentBody.MinValue) + { + if (amount > resource.CurrentBody.MaxValue) + amount = resource.CurrentBody.MaxValue; + } + else + amount = 0; + } else amount = -1; return amount; } /* Converts resource amount to pixel color */ - internal static Color resourceToColor(double Lon, double Lat, SCANdata Data, Color BaseColor, SCANresourceGlobal Resource, float Transparency = 0.4f) + internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resource, double Abundance, float Transparency = 0.4f) { - double amount = resourceMapValue(Lon, Lat, Data, Resource); - if (amount < 0) + if (Abundance < 0) return BaseColor; - else if (amount == 0) + else if (Abundance == 0) return palette.lerp(BaseColor, palette.grey, Transparency); else - return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, (float)amount / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); + return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, (float)Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); } #endregion From 82311d9f7325db4121f9265e6ee9f882c4a401fc Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 01:54:11 -0400 Subject: [PATCH 023/117] disable stock scanning; remove hard-coded kerbin radius --- SCANsat/SCANcontroller.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SCANsat/SCANcontroller.cs b/SCANsat/SCANcontroller.cs index 1fff5ac90..60b50800f 100644 --- a/SCANsat/SCANcontroller.cs +++ b/SCANsat/SCANcontroller.cs @@ -115,6 +115,10 @@ public static SCANcontroller controller public bool easyModeScanning = true; [KSPField(isPersistant = true)] public bool needsNarrowBand = true; + [KSPField(isPersistant = true)] + public bool biomeBorder = true; + [KSPField(isPersistant = true)] + public bool disableStockResource = false; /* Biome and slope colors can't be serialized properly as a KSP Field */ public Color lowBiomeColor = new Color(0, 0.46f, 0.02345098f, 1); @@ -843,7 +847,7 @@ private void Update() if (!HighLogic.LoadedSceneIsFlight && HighLogic.LoadedScene != GameScenes.TRACKSTATION) return; - if (!easyModeScanning) + if (!easyModeScanning || disableStockResource) return; if (body == null) @@ -1394,7 +1398,7 @@ private void doScanPass(SCANvessel vessel, double UT, double startUT, double las if (alt < ba) fov = (alt / ba) * fov; else sensor.bestRange = true; - double surfscale = 600000d / v.mainBody.Radius; + double surfscale = Planetarium.fetch.Home.Radius / v.mainBody.Radius; if (surfscale < 1) surfscale = 1; surfscale = Math.Sqrt(surfscale); fov *= surfscale; From 4cf803cfc83e985a7859cf30ad1aa97e6a353ed3 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 15:52:30 -0400 Subject: [PATCH 024/117] Update MechJeb version number --- SCANmechjeb/SCANmechjebMainMenu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCANmechjeb/SCANmechjebMainMenu.cs b/SCANmechjeb/SCANmechjebMainMenu.cs index 4588c3db8..0773c98dd 100644 --- a/SCANmechjeb/SCANmechjebMainMenu.cs +++ b/SCANmechjeb/SCANmechjebMainMenu.cs @@ -24,7 +24,7 @@ public class SCANmechjebMainMenu : MonoBehaviour { private const string SCANsatName = "SCANsat"; private const string MechJeb = "MechJeb2"; - private readonly Version MechJebVersion = new Version(2, 5, 0, 0); + private readonly Version MechJebVersion = new Version(2, 5, 1, 0); private static bool loaded = false; private void Awake() From e96e4ff0b911003489cda00a7a6be17855324604 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 15:52:38 -0400 Subject: [PATCH 025/117] Color32 options --- SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs b/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs index 22bf4ec96..cdc3924dd 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs @@ -28,7 +28,9 @@ public class SCANpalette public static Color white = Color.white; public static Color red = Color.red; public static Color grey = Color.grey; + public static Color32 Grey = (Color32)grey; public static Color clear = Color.clear; + public static Color32 Clear = new Color32(0, 0, 0, 0); public static Color magenta = Color.magenta; public static Color yellow = Color.yellow; public static Color cyan = Color.cyan; @@ -40,6 +42,11 @@ public static Color lerp (Color a, Color b, float t) { return Color.Lerp (a,b,t); } + public static Color32 lerp(Color32 a, Color32 b, float t) + { + return Color32.Lerp(a, b, t); + } + // XKCD Colors // (these are collected here for the same reason) From 39c6f41c0bb6eea17d64eff1ba37d5bc71ff73cf Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 15:53:01 -0400 Subject: [PATCH 026/117] Add options to resource control window --- SCANsat/SCAN_UI/SCANresourceController.cs | 50 +++++++++++++++-------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANresourceController.cs b/SCANsat/SCAN_UI/SCANresourceController.cs index bbce69589..611ba0c43 100644 --- a/SCANsat/SCAN_UI/SCANresourceController.cs +++ b/SCANsat/SCAN_UI/SCANresourceController.cs @@ -11,7 +11,7 @@ namespace SCANsat.SCAN_UI { class SCANresourceController : SCAN_MBW { - internal readonly static Rect defaultRect = new Rect(Screen.width - 200, 200, 250, 300); + internal readonly static Rect defaultRect = new Rect(Screen.width - 400, 200, 250, 300); private static Rect sessionRect = defaultRect; private CelestialBody body; private SCANdata data; @@ -21,7 +21,9 @@ class SCANresourceController : SCAN_MBW private bool drawResourceOverlay = false; private bool oldOverlay = false; - private int step; + private int mapHeight = 256; + private float transparency = 0f; + private int interpolationScale = 8; protected override void Awake() { @@ -107,9 +109,9 @@ protected override void DrawWindowPost(int id) { oldOverlay = drawResourceOverlay; if (oldOverlay) - body.SetResourceMap(currentResource.MapOverlay); + body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapHeight, data, currentResource, interpolationScale, transparency)); else - body.SetResourceMap(null); + OverlayGenerator.Instance.ClearDisplay(); } } @@ -137,9 +139,20 @@ private void drawResourceList(int id) growE(); if (GUILayout.Button(r.Name, SCANskins.SCAN_labelLeft)) { - currentResource = r; - currentResource.CurrentBodyConfig(body.name); - oldOverlay = drawResourceOverlay = false; + if (currentResource == r) + { + OverlayGenerator.Instance.ClearDisplay(); + oldOverlay = drawResourceOverlay = false; + } + else + { + currentResource = r; + currentResource.CurrentBodyConfig(body.name); + + OverlayGenerator.Instance.ClearDisplay(); + body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapHeight, data, currentResource, interpolationScale, transparency)); + oldOverlay = drawResourceOverlay = true; + } } //if (GUILayout.Button(r.CurrentBody.Fraction.ToString("P1"), SCANskins.SCAN_labelRight)) @@ -159,7 +172,10 @@ private void overlayToggle(int id) private void drawOverlay(int id) { if (drawResourceOverlay) - SCANuiUtil.drawResourceTexture(512, ref step, data, currentResource); + { + if (GUILayout.Button("Refresh")) + body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapHeight, data, currentResource, interpolationScale, transparency)); + } } private void setBody(CelestialBody B) @@ -171,20 +187,20 @@ private void setBody(CelestialBody B) data = new SCANdata(body); SCANcontroller.controller.addToBodyData(body, data); } - resourceFractions = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, body); + //resourceFractions = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, body); if (resources.Count > 0) { currentResource = resources[0]; currentResource.CurrentBodyConfig(body.name); - foreach (SCANresourceGlobal r in resources) - { - SCANresourceBody b = r.getBodyConfig(body.name, false); - if (b != null) - { - b.Fraction = resourceFractions.FirstOrDefault(a => a.resourceName == r.Name).fraction; - } - } + //foreach (SCANresourceGlobal r in resources) + //{ + // SCANresourceBody b = r.getBodyConfig(body.name, false); + // if (b != null) + // { + // b.Fraction = resourceFractions.FirstOrDefault(a => a.resourceName == r.Name).fraction; + // } + //} } oldOverlay = drawResourceOverlay = false; From 2beb21c43750371bb17554c84db31ed5f30b9543 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 15:53:10 -0400 Subject: [PATCH 027/117] Store Color32 values --- SCANsat/SCAN_Data/SCANresourceGlobal.cs | 31 +++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/SCANsat/SCAN_Data/SCANresourceGlobal.cs b/SCANsat/SCAN_Data/SCANresourceGlobal.cs index c24b23fa8..5936372cf 100644 --- a/SCANsat/SCAN_Data/SCANresourceGlobal.cs +++ b/SCANsat/SCAN_Data/SCANresourceGlobal.cs @@ -44,6 +44,8 @@ public class SCANresourceGlobal : SCAN_ConfigNodeStorage private Color defaultLowColor; private Color defaultHighColor; + private Color32 lowColor32; + private Color32 highColor32; private float defaultTrans; private Texture2D mapOverlay; @@ -55,6 +57,8 @@ internal SCANresourceGlobal(string resource, float trans, float defMin, float de resourceTransparency = trans; lowResourceColor = minC; highResourceColor = maxC; + lowColor32 = (Color32)lowResourceColor; + highColor32 = (Color32)highResourceColor; defaultMinValue = defMin; defaultMaxValue = defMax; resourceType = t; @@ -73,6 +77,8 @@ internal SCANresourceGlobal(SCANresourceGlobal copy) resourceTransparency = copy.resourceTransparency; lowResourceColor = copy.lowResourceColor; highResourceColor = copy.highResourceColor; + lowColor32 = copy.lowColor32; + highColor32 = copy.highColor32; sType = copy.sType; resourceType = copy.resourceType; masterBodyConfigs = copyBodyConfigs(copy); @@ -101,6 +107,9 @@ public override void OnDecodeFromConfigNode() resourceType = SCANcontroller.getResourceType(name); sType = resourceType.Type; + lowColor32 = (Color32)lowResourceColor; + highColor32 = (Color32)highResourceColor; + setDefaultValues(); try { @@ -171,13 +180,31 @@ internal set public Color MinColor { get { return lowResourceColor; } - internal set { lowResourceColor = value; } + internal set + { + lowResourceColor = value; + lowColor32 = (Color32)value; + } } public Color MaxColor { get { return highResourceColor; } - internal set { highResourceColor = value; } + internal set + { + highResourceColor = value; + highColor32 = (Color32)value; + } + } + + public Color32 MinColor32 + { + get { return lowColor32; } + } + + public Color32 MaxColor32 + { + get { return highColor32; } } public float DefaultMinValue From b17833b44aa289c62bd6da53c51e85fff5e3c54d Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 15:53:25 -0400 Subject: [PATCH 028/117] interpolation method; improve resource overlay --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 92 ++++++++++++++++------ 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 650076560..57bbb298f 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1349,33 +1349,23 @@ private static void GLVertexMap(Vector3d pos) #region Planet Overlay Textures - internal static void drawResourceTexture(int height, ref int step, SCANdata data, SCANresourceGlobal resource) + internal static Texture2D drawResourceTexture(int height, SCANdata data, SCANresourceGlobal resource, int stepScale = 8, float transparency = 0f) { - int stepScale = height / 16; int width = height * 2; - Color[] pix = new Color[width * stepScale]; + Color32[] pix = new Color32[width * height]; float scale = height / 180f; - if (resource.MapOverlay == null) { resource.MapOverlay = new Texture2D(width, height, TextureFormat.ARGB32, true); - Color[] c = resource.MapOverlay.GetPixels(); - for (int i = 0; i < pix.Length; i++) - c[i] = palette.clear; - resource.MapOverlay.SetPixels(c); - } - else if (step >= resource.MapOverlay.height) - { - return; } - for (int j = 0; j < stepScale; j++) + for (int j = 0; j < height; j += stepScale) { - for (int i = 0; i < width; i++) + for (int i = 0; i < width; i += stepScale) { double lon = (i / scale); - double lat = ((step + j) / scale) - 90; + double lat = (j / scale) - 90; if (lon <= 180) lon = 180 - lon; @@ -1385,14 +1375,62 @@ internal static void drawResourceTexture(int height, ref int step, SCANdata data if (lon < -180) lon += 360; - pix[j * width + i] = resourceToColor(palette.clear, resource, resourceMapValue(lon, lat, data, resource), 0.05f); + pix[j * width + i] = resourceToColor(palette.Clear, resource, resourceMapValue(lon, lat, data, resource), transparency); } } - resource.MapOverlay.SetPixels(0, step, resource.MapOverlay.width, stepScale, pix); - step += stepScale; - if (step % stepScale == 0 || step >= height) - resource.MapOverlay.Apply(); + for (int i = stepScale / 2; i >= 1; i /= 2) + { + interpolate(pix, height, i, i, i); + interpolate(pix, height, 0, i, i); + interpolate(pix, height, i, 0, i); + } + + resource.MapOverlay.SetPixels32(pix); + resource.MapOverlay.Apply(); + + return resource.MapOverlay; + } + + private static void interpolate(Color32[] c, int height, int x, int y, int step) + { + int width = height * 2; + for (int i = y; i < height + y; i += 2 * step) + { + for (int j = x; j < width + x; j += 2 * step) + { + int xpos1 = j - step; + if (xpos1 < 0) + xpos1 += width; + int xpos2 = j + step; + if (xpos2 >= width) + xpos2 -= width; + + int ypos1 = i - step; + if (ypos1 < 0) + ypos1 = 0; + int ypos2 = i + step; + if (ypos2 >= height) + ypos2 = height - 1; + + Color32 xInt; + Color32 yInt; + if (x == y) + { + yInt = palette.lerp(c[(ypos1 * width) + xpos1], c[(ypos2 * width) + xpos2], 0.5f); + xInt = palette.lerp(c[(ypos2 * width) + xpos1], c[(ypos1 * width) + xpos2], 0.5f); + } + else + { + yInt = palette.lerp(c[(i * width) + xpos1], c[(i * width) + xpos2], 0.5f); + xInt = palette.lerp(c[(ypos1 * width) + j], c[(ypos2 * width) + j], 0.5f); + } + + Color32 final = palette.lerp(xInt, yInt, 0.5f); + + c[i * width + j] = final; + } + } } internal static double resourceMapValue(double Lon, double Lat, SCANdata Data, SCANresourceGlobal resource) @@ -1428,16 +1466,26 @@ internal static double resourceMapValue(double Lon, double Lat, SCANdata Data, S } /* Converts resource amount to pixel color */ - internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resource, double Abundance, float Transparency = 0.4f) + internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resource, double Abundance) { if (Abundance < 0) return BaseColor; else if (Abundance == 0) - return palette.lerp(BaseColor, palette.grey, Transparency); + return palette.lerp(BaseColor, palette.grey, 0.3f); else return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, (float)Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); } + private static Color32 resourceToColor(Color32 BaseColor, SCANresourceGlobal Resource, double Abundance, float Transparency = 0.3f) + { + if (Abundance < 0) + return BaseColor; + else if (Abundance == 0) + return palette.lerp(BaseColor, palette.Grey, Transparency); + else + return palette.lerp(palette.lerp(Resource.MinColor32, Resource.MaxColor32, (float)Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); + } + #endregion } From 49d578a0a7c61d1646a04b440782bc6fb67047c1 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 17:17:01 -0400 Subject: [PATCH 029/117] Open resource window from toolbar --- SCANsat/SCAN_Toolbar/SCANtoolbar.cs | 5 +++++ SCANsat/SCAN_UI/SCANsettingsUI.cs | 10 ---------- SCANsat/SCANcontroller.cs | 6 ++++++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/SCANsat/SCAN_Toolbar/SCANtoolbar.cs b/SCANsat/SCAN_Toolbar/SCANtoolbar.cs index 9d1e272b0..af986fa4a 100644 --- a/SCANsat/SCAN_Toolbar/SCANtoolbar.cs +++ b/SCANsat/SCAN_Toolbar/SCANtoolbar.cs @@ -121,6 +121,7 @@ private void createMenu(IButton menu) IButton bigMap = list.AddOption("Big Map"); IButton settings = list.AddOption("Settings"); IButton color = list.AddOption("Color Options"); + IButton resource = list.AddOption("Resource Overlay"); smallMap.OnClick += (e2) => { @@ -144,6 +145,10 @@ private void createMenu(IButton menu) { SCANcontroller.controller.colorManager.Visible = !SCANcontroller.controller.colorManager.Visible; }; + resource.OnClick += (e2) => + { + SCANcontroller.controller.resourceOverlay.Visible = !SCANcontroller.controller.resourceOverlay.Visible; + }; list.OnAnyOptionClicked += () => destroyMenu(menu); menu.Drawable = list; } diff --git a/SCANsat/SCAN_UI/SCANsettingsUI.cs b/SCANsat/SCAN_UI/SCANsettingsUI.cs index ac7ce7392..7f8fb4010 100644 --- a/SCANsat/SCAN_UI/SCANsettingsUI.cs +++ b/SCANsat/SCAN_UI/SCANsettingsUI.cs @@ -389,7 +389,6 @@ private void gui_settings_resources(int id) if (popup) { GUILayout.Label("Reset Resource Coverage", SCANskins.SCAN_button); - GUILayout.Label("Open Resource Overlay Window", SCANskins.SCAN_button); } else { @@ -398,15 +397,6 @@ private void gui_settings_resources(int id) popup = !popup; warningResource = !warningResource; } - - if (GUILayout.Button("Open Resource Overlay Window")) - { - if (resourceWindow == null) - { - resourceWindow = gameObject.AddComponent(); - } - resourceWindow.Visible = !resourceWindow.Visible; - } } } diff --git a/SCANsat/SCANcontroller.cs b/SCANsat/SCANcontroller.cs index 60b50800f..49765743a 100644 --- a/SCANsat/SCANcontroller.cs +++ b/SCANsat/SCANcontroller.cs @@ -159,6 +159,7 @@ public static SCANcontroller controller internal SCANBigMap BigMap; internal SCANkscMap kscMap; internal SCANcolorSelection colorManager; + internal SCANresourceController resourceOverlay; /* App launcher object */ internal SCANappLauncher appLauncher; @@ -766,6 +767,7 @@ private void Start() instrumentsWindow = gameObject.AddComponent(); colorManager = gameObject.AddComponent(); BigMap = gameObject.AddComponent(); + resourceOverlay = gameObject.AddComponent(); } catch (Exception e) { @@ -781,6 +783,8 @@ private void Start() kscMap = gameObject.AddComponent(); settingsWindow = gameObject.AddComponent(); colorManager = gameObject.AddComponent(); + if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) + resourceOverlay = gameObject.AddComponent(); } catch (Exception e) { @@ -916,6 +920,8 @@ private void OnDestroy() Destroy(kscMap); if (BigMap != null) Destroy(BigMap); + if (resourceOverlay != null) + Destroy(resourceOverlay); if (appLauncher != null) Destroy(appLauncher); } From 931ddac6e2ff28491f730eeafc2cde20f32364cd Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 17:17:10 -0400 Subject: [PATCH 030/117] Resource window styles --- SCANsat/SCAN_UI/UI_Framework/SCANskins.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs index f819f3e5d..24a03be9c 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs @@ -55,6 +55,7 @@ class SCANskins: SCAN_MBE //Resource controller styles internal static GUIStyle SCAN_labelLeft; internal static GUIStyle SCAN_labelRight; + internal static GUIStyle SCAN_labelSmall; //Settings menu styles internal static GUIStyle SCAN_headline; @@ -275,6 +276,20 @@ private static void initializeSkins() SCAN_anomalyOverlay.fontStyle = FontStyle.Bold; SCAN_anomalyOverlay.normal.textColor = palette.cb_skyBlue; + //Resource Control settings + SCAN_labelLeft = new GUIStyle(SCAN_SkinsLibrary.DefUnitySkin.label); + SCAN_labelLeft.fontSize = 12; + SCAN_labelLeft.hover.textColor = palette.c_good; + SCAN_labelLeft.alignment = TextAnchor.MiddleLeft; + + SCAN_labelRight = new GUIStyle(SCAN_labelLeft); + SCAN_labelRight.alignment = TextAnchor.MiddleRight; + + SCAN_labelSmall = new GUIStyle(SCAN_whiteReadoutLabel); + SCAN_labelSmall.fontSize = 10; + SCAN_labelSmall.alignment = TextAnchor.MiddleCenter; + SCAN_labelSmall.fontStyle = FontStyle.Bold; + //Initialize settings menu styles SCAN_headline = new GUIStyle(SCAN_SkinsLibrary.DefUnitySkin.label); SCAN_headline.name = "SCAN_Headline"; @@ -296,12 +311,6 @@ private static void initializeSkins() SCAN_labelSmallRight.name = "SCAN_LabelSmallRight"; SCAN_labelSmallRight.alignment = TextAnchor.MiddleRight; - SCAN_labelLeft = new GUIStyle(SCAN_labelSmallLeft); - SCAN_labelLeft.fontSize = 12; - - SCAN_labelRight = new GUIStyle(SCAN_labelSmallRight); - SCAN_labelRight.fontSize = 12; - SCAN_buttonWarning = new GUIStyle(SCAN_button); SCAN_buttonWarning.name = "SCAN_ButtonWarning"; SCAN_buttonWarning.fontSize = 16; From b4bf98395164689d65a756a71850ff184ad801cc Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 17:17:31 -0400 Subject: [PATCH 031/117] Overlay options; tweaks --- SCANsat/SCAN_UI/SCANresourceController.cs | 69 ++++++++++++++++++++--- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANresourceController.cs b/SCANsat/SCAN_UI/SCANresourceController.cs index 611ba0c43..5e0395e66 100644 --- a/SCANsat/SCAN_UI/SCANresourceController.cs +++ b/SCANsat/SCAN_UI/SCANresourceController.cs @@ -11,7 +11,7 @@ namespace SCANsat.SCAN_UI { class SCANresourceController : SCAN_MBW { - internal readonly static Rect defaultRect = new Rect(Screen.width - 400, 200, 250, 300); + internal readonly static Rect defaultRect = new Rect(Screen.width - 280, 200, 200, 300); private static Rect sessionRect = defaultRect; private CelestialBody body; private SCANdata data; @@ -30,7 +30,7 @@ protected override void Awake() WindowCaption = "S.C.A.N. Resources"; WindowRect = sessionRect; WindowStyle = SCANskins.SCAN_window; - WindowOptions = new GUILayoutOption[2] { GUILayout.Width(280), GUILayout.Height(300) }; + WindowOptions = new GUILayoutOption[2] { GUILayout.Width(200), GUILayout.Height(300) }; Visible = false; DragEnabled = true; ClampToScreenOffset = new RectOffset(-200, -200, -40, -40); @@ -100,7 +100,7 @@ protected override void DrawWindow(int id) drawResourceList(id); overlayToggle(id); - drawOverlay(id); + overlayOptions(id); } protected override void DrawWindowPost(int id) @@ -109,10 +109,12 @@ protected override void DrawWindowPost(int id) { oldOverlay = drawResourceOverlay; if (oldOverlay) - body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapHeight, data, currentResource, interpolationScale, transparency)); + refreshMap(); else OverlayGenerator.Instance.ClearDisplay(); } + + sessionRect = WindowRect; } //Draw the version label in the upper left corner @@ -150,7 +152,7 @@ private void drawResourceList(int id) currentResource.CurrentBodyConfig(body.name); OverlayGenerator.Instance.ClearDisplay(); - body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapHeight, data, currentResource, interpolationScale, transparency)); + refreshMap(); oldOverlay = drawResourceOverlay = true; } } @@ -169,15 +171,68 @@ private void overlayToggle(int id) drawResourceOverlay = GUILayout.Toggle(drawResourceOverlay, "Draw Overlay", SCANskins.SCAN_settingsToggle); } - private void drawOverlay(int id) + private void overlayOptions(int id) { if (drawResourceOverlay) { + growE(); + GUILayout.Label("Coverage Transparency:", SCANskins.SCAN_labelSmallLeft); + + if (GUILayout.Button("-", SCANskins.SCAN_labelSmall)) + { + transparency = Mathf.Max(0f, transparency - 0.1f); + refreshMap(); + } + GUILayout.Label(transparency.ToString("P0"), SCANskins.SCAN_labelSmall); + if (GUILayout.Button("+", SCANskins.SCAN_labelSmall)) + { + transparency = Mathf.Min(1f, transparency + 0.1f); + refreshMap(); + } + stopE(); + + growE(); + GUILayout.Label("Interpolation:", SCANskins.SCAN_labelSmallLeft); + + if (GUILayout.Button("-", SCANskins.SCAN_labelSmall)) + { + interpolationScale = Math.Max(2, interpolationScale / 2); + refreshMap(); + } + GUILayout.Label(interpolationScale.ToString(), SCANskins.SCAN_labelSmall); + if (GUILayout.Button("+", SCANskins.SCAN_labelSmall)) + { + interpolationScale = Math.Min(32, interpolationScale * 2); + refreshMap(); + } + stopE(); + + growE(); + GUILayout.Label("Map Height:", SCANskins.SCAN_labelSmallLeft); + + if (GUILayout.Button("-", SCANskins.SCAN_labelSmall)) + { + mapHeight = Math.Max(64, mapHeight / 2); + refreshMap(); + } + GUILayout.Label(mapHeight.ToString(), SCANskins.SCAN_labelSmall); + if (GUILayout.Button("+", SCANskins.SCAN_labelSmall)) + { + mapHeight = Math.Min(1024, mapHeight * 2); + refreshMap(); + } + stopE(); + if (GUILayout.Button("Refresh")) - body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapHeight, data, currentResource, interpolationScale, transparency)); + refreshMap(); } } + private void refreshMap() + { + body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapHeight, data, currentResource, interpolationScale, transparency)); + } + private void setBody(CelestialBody B) { body = B; From b20a30e24531e8960a4cfc362abc39852116fb90 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 18:14:45 -0400 Subject: [PATCH 032/117] Include Helium3 --- SCANsat/SCAN_Data/SCANtype.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCANsat/SCAN_Data/SCANtype.cs b/SCANsat/SCAN_Data/SCANtype.cs index c4f14df9b..2e4f0abd0 100644 --- a/SCANsat/SCAN_Data/SCANtype.cs +++ b/SCANsat/SCAN_Data/SCANtype.cs @@ -43,7 +43,7 @@ public enum SCANtype : int Everything_SCAN = (1 << 6) - 1, // All default SCANsat scanners AllResources = 2147483584, // All resource types - DefinedResources = 392576, // All defined resource types + DefinedResources = 393088, // All defined resource types Everything = Int32.MaxValue // All scanner types } } From acce348eea17d769d029503de2ffc811ee64a524 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 18 May 2015 18:15:13 -0400 Subject: [PATCH 033/117] Separate all Unity API calls; still need to handle polar terrain and uncached terrain --- SCANsat/SCAN_Map/SCANmap.cs | 102 +++++++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 31 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 569543aaf..1ec75c408 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -284,6 +284,9 @@ internal double unprojectLatitude(double lon, double lat) private double mapscale, lon_offset, lat_offset; private int mapwidth, mapheight; private Color[] pix; + private double[] resourceCache; + private double[] biomeIndex; + private Color[] stockBiomeColor; internal void setSize(int w, int h) { @@ -293,6 +296,9 @@ internal void setSize(int w, int h) w = 360 * 4; mapwidth = w; pix = new Color[w]; + biomeIndex = new double[w]; + stockBiomeColor = new Color[w]; + resourceCache = new double[w * 3]; mapscale = mapwidth / 360f; if (h <= 0) h = (int)(180 * mapscale); @@ -318,6 +324,9 @@ internal void setWidth(int w) return; mapwidth = w; pix = new Color[w]; + biomeIndex = new double[w]; + stockBiomeColor = new Color[w]; + resourceCache = new double[w * 3]; mapscale = mapwidth / 360f; mapheight = (int)(w / 2); /* big map caching */ @@ -514,11 +523,6 @@ internal Texture2D getPartialMap() palette.redline[i] = palette.red; } - if (mapstep <= -1) - { - mapstep = -1; - mapline = new double[map.width]; - } for (int i = 0; i < map.width; i++) { @@ -539,17 +543,6 @@ internal Texture2D getPartialMap() } } - if (mapstep < 0) - continue; - - Color baseColor = palette.grey; - Color stockBiome = palette.grey; - double resourceAbundance = 0; - bool resources = false; - double bioIndex = 0; - pix[i] = baseColor; - int scheme = SCANcontroller.controller.colours; - float projVal = 0f; double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; double lon = (i * 1.0f / mapscale) - 180f + lon_offset; double la = lat, lo = lon; @@ -558,28 +551,75 @@ internal Texture2D getPartialMap() if (double.IsNaN(lat) || double.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180) { - pix[i] = palette.clear; continue; } if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) { - resourceAbundance = SCANuiUtil.resourceMapValue(lon, lat, data, resource); - if (resourceAbundance >= 0) - resources = true; + resourceCache[i] = SCANuiUtil.resourceMapValue(lon, lat, data, resource); } if (mType == mapType.Biome && biomeMap) { if (SCANcontroller.controller.useStockBiomes && SCANcontroller.controller.colours == 0) { - stockBiome = SCANUtil.getBiome(body, lon, lat).mapColor; + stockBiomeColor[i] = SCANUtil.getBiome(body, lon, lat).mapColor; if (SCANcontroller.controller.biomeBorder) - bioIndex = SCANUtil.getBiomeIndexFraction(body, lon, lat); + biomeIndex[i] = SCANUtil.getBiomeIndexFraction(body, lon, lat); } else - bioIndex = SCANUtil.getBiomeIndexFraction(body, lon, lat); + biomeIndex[i] = SCANUtil.getBiomeIndexFraction(body, lon, lat); } + } + + if (mapstep <= -1) + { + mapstep = -1; + mapline = new double[map.width]; + mapstep++; + return map; + } + + for (int i = 0; i < map.width; i++) + { + Color baseColor = palette.grey; + //Color stockBiome = palette.grey; + //double resourceAbundance = 0; + //bool resources = false; + //double bioIndex = 0; + pix[i] = baseColor; + int scheme = SCANcontroller.controller.colours; + float projVal = 0f; + double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; + double lon = (i * 1.0f / mapscale) - 180f + lon_offset; + double la = lat, lo = lon; + lat = unprojectLatitude(lo, la); + lon = unprojectLongitude(lo, la); + + if (double.IsNaN(lat) || double.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180) + { + pix[i] = palette.clear; + continue; + } + + //if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) + //{ + // resourceAbundance = SCANuiUtil.resourceMapValue(lon, lat, data, resource); + // if (resourceAbundance >= 0) + // resources = true; + //} + + //if (mType == mapType.Biome && biomeMap) + //{ + // if (SCANcontroller.controller.useStockBiomes && SCANcontroller.controller.colours == 0) + // { + // stockBiome = SCANUtil.getBiome(body, lon, lat).mapColor; + // if (SCANcontroller.controller.biomeBorder) + // bioIndex = SCANUtil.getBiomeIndexFraction(body, lon, lat); + // } + // else + // bioIndex = SCANUtil.getBiomeIndexFraction(body, lon, lat); + //} switch (mType) { @@ -647,13 +687,13 @@ internal Texture2D getPartialMap() Color biome = palette.grey; if (SCANcontroller.controller.colours == 1) { - if ((i > 0 && mapline[i - 1] != bioIndex) || (mapstep > 0 && mapline[i] != bioIndex)) + if ((i > 0 && mapline[i - 1] != biomeIndex[i]) || (mapstep > 0 && mapline[i] != biomeIndex[i])) { biome = palette.white; } else { - biome = palette.lerp(palette.black, palette.white, (float)bioIndex); + biome = palette.lerp(palette.black, palette.white, (float)biomeIndex[i]); } } else @@ -672,29 +712,29 @@ internal Texture2D getPartialMap() } } - if (SCANcontroller.controller.biomeBorder && ((i > 0 && mapline[i - 1] != bioIndex) || (mapstep > 0 && mapline[i] != bioIndex))) + if (SCANcontroller.controller.biomeBorder && ((i > 0 && mapline[i - 1] != biomeIndex[i]) || (mapstep > 0 && mapline[i] != biomeIndex[i]))) { biome = palette.white; } else if (SCANcontroller.controller.useStockBiomes) { - biome = palette.lerp(stockBiome, elevation, SCANcontroller.controller.biomeTransparency / 100f); + biome = palette.lerp(stockBiomeColor[i], elevation, SCANcontroller.controller.biomeTransparency / 100f); } else { - biome = palette.lerp(palette.lerp(SCANcontroller.controller.lowBiomeColor, SCANcontroller.controller.highBiomeColor, (float)bioIndex), elevation, SCANcontroller.controller.biomeTransparency / 100f); + biome = palette.lerp(palette.lerp(SCANcontroller.controller.lowBiomeColor, SCANcontroller.controller.highBiomeColor, (float)biomeIndex[i]), elevation, SCANcontroller.controller.biomeTransparency / 100f); } } baseColor = biome; - mapline[i] = bioIndex; + mapline[i] = biomeIndex[i]; } break; } } - if (resources) - pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, resourceAbundance); + if (resourceCache[i] >= 0) + pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, resourceCache[i]); else pix[i] = baseColor; } From 538fe3dc6a0e5bfa7a81fc25d741dd55c1193597 Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 19 May 2015 17:15:20 -0400 Subject: [PATCH 034/117] Selecting map view target body --- SCANsat/SCAN_UI/SCANresourceController.cs | 72 +++++++-------- SCANsat/SCAN_UI/SCANsettingsUI.cs | 106 +++++++++++++--------- SCANsat/SCANutil.cs | 18 ++++ 3 files changed, 117 insertions(+), 79 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANresourceController.cs b/SCANsat/SCAN_UI/SCANresourceController.cs index 5e0395e66..66a456185 100644 --- a/SCANsat/SCAN_UI/SCANresourceController.cs +++ b/SCANsat/SCAN_UI/SCANresourceController.cs @@ -21,6 +21,7 @@ class SCANresourceController : SCAN_MBW private bool drawResourceOverlay = false; private bool oldOverlay = false; + private Texture2D mapOverlay; private int mapHeight = 256; private float transparency = 0f; private int interpolationScale = 8; @@ -42,23 +43,22 @@ protected override void Start() { resources = SCANcontroller.setLoadedResourceList(); - setBody(FlightGlobals.currentMainBody); + setBody(HighLogic.LoadedSceneIsFlight ? FlightGlobals.currentMainBody : Planetarium.fetch.Home); } protected override void Update() { - if (MapView.MapIsEnabled) + if ((MapView.MapIsEnabled && HighLogic.LoadedSceneIsFlight) || HighLogic.LoadedScene == GameScenes.TRACKSTATION) { - MapObject target = PlanetariumCamera.fetch.target; + CelestialBody mapBody = SCANUtil.getTargetBody(MapView.MapCamera.target); - CelestialBody mapBody = getTargetBody(target); if (mapBody == null) return; if (mapBody != body) setBody(mapBody); } - else + else if (HighLogic.LoadedSceneIsFlight) { if (body != FlightGlobals.currentMainBody) setBody(FlightGlobals.currentMainBody); @@ -70,24 +70,6 @@ protected override void OnDestroy() } - private CelestialBody getTargetBody(MapObject target) - { - if (target.type == MapObject.MapObjectType.CELESTIALBODY) - { - return target.celestialBody; - } - else if (target.type == MapObject.MapObjectType.MANEUVERNODE) - { - return target.maneuverNode.patch.referenceBody; - } - else if (target.type == MapObject.MapObjectType.VESSEL) - { - return target.vessel.mainBody; - } - - return null; - } - protected override void DrawWindowPre(int id) { @@ -230,7 +212,7 @@ private void overlayOptions(int id) private void refreshMap() { - body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapHeight, data, currentResource, interpolationScale, transparency)); + body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapOverlay, mapHeight, data, currentResource, interpolationScale, transparency)); } private void setBody(CelestialBody B) @@ -242,23 +224,39 @@ private void setBody(CelestialBody B) data = new SCANdata(body); SCANcontroller.controller.addToBodyData(body, data); } - //resourceFractions = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, body); - if (resources.Count > 0) + + if (currentResource == null) + { + if (resources.Count > 0) + { + currentResource = resources[0]; + currentResource.CurrentBodyConfig(body.name); + } + } + else { - currentResource = resources[0]; currentResource.CurrentBodyConfig(body.name); - - //foreach (SCANresourceGlobal r in resources) - //{ - // SCANresourceBody b = r.getBodyConfig(body.name, false); - // if (b != null) - // { - // b.Fraction = resourceFractions.FirstOrDefault(a => a.resourceName == r.Name).fraction; - // } - //} } - oldOverlay = drawResourceOverlay = false; + if (drawResourceOverlay) + refreshMap(); + + + //resourceFractions = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, body); + //if (resources.Count > 0) + //{ + // currentResource = resources[0]; + // currentResource.CurrentBodyConfig(body.name); + + // //foreach (SCANresourceGlobal r in resources) + // //{ + // // SCANresourceBody b = r.getBodyConfig(body.name, false); + // // if (b != null) + // // { + // // b.Fraction = resourceFractions.FirstOrDefault(a => a.resourceName == r.Name).fraction; + // // } + // //} + //} } } } diff --git a/SCANsat/SCAN_UI/SCANsettingsUI.cs b/SCANsat/SCAN_UI/SCANsettingsUI.cs index 7f8fb4010..9c36baef0 100644 --- a/SCANsat/SCAN_UI/SCANsettingsUI.cs +++ b/SCANsat/SCAN_UI/SCANsettingsUI.cs @@ -278,12 +278,22 @@ private void gui_settings_numbers(int id) private void gui_settings_data_resets(int id) { CelestialBody thisBody = null; - if (HighLogic.LoadedSceneIsFlight) - thisBody = FlightGlobals.currentMainBody; - else if (HighLogic.LoadedScene == GameScenes.SPACECENTER) - thisBody = Planetarium.fetch.Home; - else if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) - thisBody = getTargetBody(MapView.MapCamera.target); + switch (HighLogic.LoadedScene) + { + case GameScenes.FLIGHT: + thisBody = FlightGlobals.currentMainBody; + break; + case GameScenes.SPACECENTER: + thisBody = Planetarium.fetch.Home; + break; + case GameScenes.TRACKSTATION: + thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); + break; + default: + thisBody = null; + break; + } + if (thisBody == null) return; @@ -311,24 +321,6 @@ private void gui_settings_data_resets(int id) fillS(8); } - private CelestialBody getTargetBody(MapObject target) - { - if (target.type == MapObject.MapObjectType.CELESTIALBODY) - { - return target.celestialBody; - } - else if (target.type == MapObject.MapObjectType.MANEUVERNODE) - { - return target.maneuverNode.patch.referenceBody; - } - else if (target.type == MapObject.MapObjectType.VESSEL) - { - return target.vessel.mainBody; - } - - return null; - } - //Resets all window positions, tooltip toggle private void gui_settings_window_resets_tooltips(int id) { @@ -405,12 +397,22 @@ private void gui_settings_window_mapFill(int id) { growE(); CelestialBody thisBody = null; - if (HighLogic.LoadedSceneIsFlight) - thisBody = FlightGlobals.currentMainBody; - else if (HighLogic.LoadedScene == GameScenes.SPACECENTER) - thisBody = Planetarium.fetch.Home; - else if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) - thisBody = getTargetBody(MapView.MapCamera.target); + switch (HighLogic.LoadedScene) + { + case GameScenes.FLIGHT: + thisBody = FlightGlobals.currentMainBody; + break; + case GameScenes.SPACECENTER: + thisBody = Planetarium.fetch.Home; + break; + case GameScenes.TRACKSTATION: + thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); + break; + default: + thisBody = null; + break; + } + if (thisBody == null) return; if (GUILayout.Button("Fill SCAN map of " + thisBody.theName)) @@ -448,12 +450,22 @@ private void warningBox(int id) if (warningBoxOne) { CelestialBody thisBody = null; - if (HighLogic.LoadedSceneIsFlight) - thisBody = FlightGlobals.currentMainBody; - else if (HighLogic.LoadedScene == GameScenes.SPACECENTER) - thisBody = Planetarium.fetch.Home; - else if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) - thisBody = getTargetBody(MapView.MapCamera.target); + switch (HighLogic.LoadedScene) + { + case GameScenes.FLIGHT: + thisBody = FlightGlobals.currentMainBody; + break; + case GameScenes.SPACECENTER: + thisBody = Planetarium.fetch.Home; + break; + case GameScenes.TRACKSTATION: + thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); + break; + default: + thisBody = null; + break; + } + if (thisBody == null) return; warningRect = new Rect(WindowRect.width - (WindowRect.width / 2) - 150, WindowRect.height - 125, 300, 90); @@ -496,12 +508,22 @@ private void warningBox(int id) else if (warningResource) { CelestialBody thisBody = null; - if (HighLogic.LoadedSceneIsFlight) - thisBody = FlightGlobals.currentMainBody; - else if (HighLogic.LoadedScene == GameScenes.SPACECENTER) - thisBody = Planetarium.fetch.Home; - else if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) - thisBody = getTargetBody(MapView.MapCamera.target); + switch (HighLogic.LoadedScene) + { + case GameScenes.FLIGHT: + thisBody = FlightGlobals.currentMainBody; + break; + case GameScenes.SPACECENTER: + thisBody = Planetarium.fetch.Home; + break; + case GameScenes.TRACKSTATION: + thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); + break; + default: + thisBody = null; + break; + } + if (thisBody == null) return; warningRect = new Rect(WindowRect.width - (WindowRect.width / 2) - 150, WindowRect.height - 125, 300, 90); diff --git a/SCANsat/SCANutil.cs b/SCANsat/SCANutil.cs index 638598d11..bc9cdc654 100644 --- a/SCANsat/SCANutil.cs +++ b/SCANsat/SCANutil.cs @@ -343,6 +343,24 @@ internal static Palette paletteLoader(string name, int size) } } + internal static CelestialBody getTargetBody(MapObject target) + { + if (target.type == MapObject.MapObjectType.CELESTIALBODY) + { + return target.celestialBody; + } + else if (target.type == MapObject.MapObjectType.MANEUVERNODE) + { + return target.maneuverNode.patch.referenceBody; + } + else if (target.type == MapObject.MapObjectType.VESSEL) + { + return target.vessel.mainBody; + } + + return null; + } + internal static void SCANlog(string log, params object[] stringObjects) { log = string.Format(log, stringObjects); From 6e91ad27c21de8b111ff06acb8efdabc2d80d7a9 Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 19 May 2015 17:15:31 -0400 Subject: [PATCH 035/117] fix style --- SCANsat/SCAN_UI/UI_Framework/SCANskins.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs index 24a03be9c..8a910fd8a 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs @@ -279,7 +279,7 @@ private static void initializeSkins() //Resource Control settings SCAN_labelLeft = new GUIStyle(SCAN_SkinsLibrary.DefUnitySkin.label); SCAN_labelLeft.fontSize = 12; - SCAN_labelLeft.hover.textColor = palette.c_good; + SCAN_labelLeft.hover.textColor = palette.cb_bluishGreen; SCAN_labelLeft.alignment = TextAnchor.MiddleLeft; SCAN_labelRight = new GUIStyle(SCAN_labelLeft); From c520f625fe922f496f7ac95b4c0aa20dee2cfc80 Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 19 May 2015 17:16:16 -0400 Subject: [PATCH 036/117] Don't cache map texture --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 57bbb298f..717951a59 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1349,15 +1349,15 @@ private static void GLVertexMap(Vector3d pos) #region Planet Overlay Textures - internal static Texture2D drawResourceTexture(int height, SCANdata data, SCANresourceGlobal resource, int stepScale = 8, float transparency = 0f) + internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdata data, SCANresourceGlobal resource, int stepScale = 8, float transparency = 0f) { int width = height * 2; Color32[] pix = new Color32[width * height]; float scale = height / 180f; - if (resource.MapOverlay == null) + if (map == null || map.height != height) { - resource.MapOverlay = new Texture2D(width, height, TextureFormat.ARGB32, true); + map = new Texture2D(width, height, TextureFormat.ARGB32, true); } for (int j = 0; j < height; j += stepScale) @@ -1386,10 +1386,10 @@ internal static Texture2D drawResourceTexture(int height, SCANdata data, SCANres interpolate(pix, height, i, 0, i); } - resource.MapOverlay.SetPixels32(pix); - resource.MapOverlay.Apply(); + map.SetPixels32(pix); + map.Apply(); - return resource.MapOverlay; + return map; } private static void interpolate(Color32[] c, int height, int x, int y, int step) @@ -1433,6 +1433,12 @@ private static void interpolate(Color32[] c, int height, int x, int y, int step) } } + internal static Color interpolate(Color baseColor, double[] v, int x, int y, int step) + { + + return baseColor; + } + internal static double resourceMapValue(double Lon, double Lat, SCANdata Data, SCANresourceGlobal resource) { double amount = 0; From b3175720e557b8ddd691274588d44e40659c9ec5 Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 19 May 2015 17:16:35 -0400 Subject: [PATCH 037/117] Changes to resource and biome maps --- SCANsat/SCAN_Map/SCANmap.cs | 97 ++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 17 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 1ec75c408..526a1d98f 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -285,6 +285,8 @@ internal double unprojectLatitude(double lon, double lat) private int mapwidth, mapheight; private Color[] pix; private double[] resourceCache; + private int resourceStep; + private int resourceMapSize; private double[] biomeIndex; private Color[] stockBiomeColor; @@ -326,7 +328,12 @@ internal void setWidth(int w) pix = new Color[w]; biomeIndex = new double[w]; stockBiomeColor = new Color[w]; - resourceCache = new double[w * 3]; + if (w < 1024) + resourceMapSize = 64; + else + resourceMapSize = 128; + resourceCache = new double[resourceMapSize * (resourceMapSize / 2)]; + resourceStep = 8; mapscale = mapwidth / 360f; mapheight = (int)(w / 2); /* big map caching */ @@ -489,6 +496,8 @@ internal Texture2D getPartialMap() if (data == null) return new Texture2D(1, 1); + bool resourceOn = false; + /* init cache if necessary */ if (cache) { @@ -543,24 +552,27 @@ internal Texture2D getPartialMap() } } - double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; - double lon = (i * 1.0f / mapscale) - 180f + lon_offset; - double la = lat, lo = lon; - lat = unprojectLatitude(lo, la); - lon = unprojectLongitude(lo, la); - - if (double.IsNaN(lat) || double.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180) + if (mType == mapType.Biome && biomeMap) { - continue; - } - if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) - { - resourceCache[i] = SCANuiUtil.resourceMapValue(lon, lat, data, resource); - } + double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; + double lon = (i * 1.0f / mapscale) - 180f + lon_offset; + double la = lat, lo = lon; + lat = unprojectLatitude(lo, la); + lon = unprojectLongitude(lo, la); - if (mType == mapType.Biome && biomeMap) - { + if (double.IsNaN(lat) || double.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180) + { + continue; + } + + //if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) + //{ + // resourceCache[i] = SCANuiUtil.resourceMapValue(lon, lat, data, resource); + //} + + //if (mType == mapType.Biome && biomeMap) + //{ if (SCANcontroller.controller.useStockBiomes && SCANcontroller.controller.colours == 0) { stockBiomeColor[i] = SCANUtil.getBiome(body, lon, lat).mapColor; @@ -580,6 +592,24 @@ internal Texture2D getPartialMap() return map; } + if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) + { + resourceOn = true; + if (mapstep < resourceMapSize / 8) + { + for (int i = 0; i < resourceMapSize; i++) + { + double resourceLon = ((i * 8) * 1.0f / mapscale) - 180f + lon_offset; + for (int j = 0; j < 4; j++) + { + double resourceLat = ((((mapstep * 4) + j) * 8) * 1.0f / mapscale) - 90f + lat_offset; + + resourceCache[(((mapstep * 4) + j) * resourceMapSize) + i] = SCANuiUtil.resourceMapValue(resourceLon, resourceLat, data, resource); + } + } + } + } + for (int i = 0; i < map.width; i++) { Color baseColor = palette.grey; @@ -733,8 +763,41 @@ internal Texture2D getPartialMap() } } - if (resourceCache[i] >= 0) + if (resourceOn) + { + switch (projection) + { + case MapProjection.Polar: + { + if (lat <= 6 || lat >= -6) + { + + } + //else if (lat >= 87 || lat <= -87) + //{ + + //} + else + { + + } + break; + } + default: + { + if (lat <= -85 || lat >= 85) + { + + } + else + { + + } + break; + } + } pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, resourceCache[i]); + } else pix[i] = baseColor; } From c7273c2cc90ab2d3b9565a915449c218175ea1e4 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 20 May 2015 16:12:06 -0400 Subject: [PATCH 038/117] Texture not needed --- SCANsat/SCAN_Data/SCANresourceGlobal.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/SCANsat/SCAN_Data/SCANresourceGlobal.cs b/SCANsat/SCAN_Data/SCANresourceGlobal.cs index 5936372cf..7675b101c 100644 --- a/SCANsat/SCAN_Data/SCANresourceGlobal.cs +++ b/SCANsat/SCAN_Data/SCANresourceGlobal.cs @@ -47,7 +47,6 @@ public class SCANresourceGlobal : SCAN_ConfigNodeStorage private Color32 lowColor32; private Color32 highColor32; private float defaultTrans; - private Texture2D mapOverlay; private SCANresourceBody currentBody; @@ -289,11 +288,5 @@ public float DefaultTrans { get { return defaultTrans; } } - - public Texture2D MapOverlay - { - get { return mapOverlay; } - set { mapOverlay = value; } - } } } From 72f4ceaad450d3344ef0bc3a1bf05049c237e44e Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 20 May 2015 16:12:23 -0400 Subject: [PATCH 039/117] Add some public API calls for resource settings --- SCANsat/SCANutil.cs | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/SCANsat/SCANutil.cs b/SCANsat/SCANutil.cs index bc9cdc654..32f50aa70 100644 --- a/SCANsat/SCANutil.cs +++ b/SCANsat/SCANutil.cs @@ -142,6 +142,54 @@ public static SCANdata getData(string BodyName) return SCANcontroller.controller.getData(BodyName); } + /// + /// Do SCANsat maps automatically update with the stock, instant-scan orbital surveys? + /// + /// Returns true if instant scan is enabled + public static bool instantResourceScanEnabled() + { + if (SCANcontroller.controller == null) + return true; + + return SCANcontroller.controller.easyModeScanning; + } + + /// + /// Are the stock resource scanner functions disabled; prevents orbital resource surveys? + /// + /// Returns true if stock resource scanning is available + public static bool stockResourceScanEnabled() + { + if (SCANcontroller.controller == null) + return true; + + return !SCANcontroller.controller.disableStockResource; + } + + /// + /// Is the stock resource biome lock enabled; reduced resource abundace accuracy if enabled? + /// + /// Returns true if the biome lock is enabled + public static bool resourceBiomeLockEnabled() + { + if (SCANcontroller.controller == null) + return true; + + return SCANcontroller.controller.resourceBiomeLock; + } + + /// + /// Does the zoom map resource overlay require a narrow-band scanner in orbit? + /// + /// Returns true if a narrow-band scanner is required + public static bool zoomWindowResourceRestrictionEnabled() + { + if (SCANcontroller.controller == null) + return true; + + return SCANcontroller.controller.needsNarrowBand; + } + #endregion #region Internal Utilities From 2f5d9f2104055b6222e6ac033df63722531e0d25 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 20 May 2015 16:12:38 -0400 Subject: [PATCH 040/117] resource interpolation methods --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 68 +++++++++++++++++++--- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 717951a59..54e005c05 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1433,15 +1433,67 @@ private static void interpolate(Color32[] c, int height, int x, int y, int step) } } - internal static Color interpolate(Color baseColor, double[] v, int x, int y, int step) + internal static void interpolate(float[,] V, int Y, int Height, int Width, int XStep, int YStep, int Step) { + for (int i = Y + YStep; i < Height + YStep + Y; i += 2 * Step) + { + for (int j = XStep; j < Width + XStep; j += 2 * Step) + { + int xpos1 = j - Step; + if (xpos1 < 0) + xpos1 = 0; + int xpos2 = j + Step; + if (xpos2 >= Width) + xpos2 = Width - 1; + + int ypos1 = i - Step; + if (ypos1 < 0) + ypos1 = 0; + int ypos2 = i + Step; + if (ypos2 >= Height) + ypos2 = Height - 1; - return baseColor; + float avgX = 0; + float avgY = 0; + + if (XStep == YStep) + { + avgX = Mathf.Lerp(V[xpos1, ypos1], V[xpos2, ypos2], 0.5f); + avgY = Mathf.Lerp(V[xpos1, ypos2], V[xpos2, ypos1], 0.5f); + } + else + { + avgX = Mathf.Lerp(V[xpos1, i], V[xpos2, i], 0.5f); + avgY = Mathf.Lerp(V[j, ypos2], V[j, ypos1], 0.5f); + } + + float avgFinal = Mathf.Lerp(avgX, avgY, 0.5f); + + V[j, i] = avgFinal; + } + } + } + + internal static void interpolate(float[,] V, int Y, int Width, int XStep, int Step) + { + for (int i = XStep; i < Width + XStep; i += 2 * Step) + { + int xpos1 = i - Step; + if (xpos1 < 0) + xpos1 = 0; + int xpos2 = i + Step; + if (xpos2 >= Width) + xpos2 = Width - 1; + + float avgX = Mathf.Lerp(V[xpos1, Y], V[xpos2, Y], 0.5f); + + V[i, Y] = avgX; + } } - internal static double resourceMapValue(double Lon, double Lat, SCANdata Data, SCANresourceGlobal resource) + internal static float resourceMapValue(double Lon, double Lat, SCANdata Data, SCANresourceGlobal resource) { - double amount = 0; + float amount = 0; if (SCANUtil.isCovered(Lon, Lat, Data, resource.SType)) { amount = SCANUtil.ResourceOverlay(Lat, Lon, resource.Name, Data.Body); @@ -1472,24 +1524,24 @@ internal static double resourceMapValue(double Lon, double Lat, SCANdata Data, S } /* Converts resource amount to pixel color */ - internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resource, double Abundance) + internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resource, float Abundance) { if (Abundance < 0) return BaseColor; else if (Abundance == 0) return palette.lerp(BaseColor, palette.grey, 0.3f); else - return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, (float)Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); + return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); } - private static Color32 resourceToColor(Color32 BaseColor, SCANresourceGlobal Resource, double Abundance, float Transparency = 0.3f) + private static Color32 resourceToColor(Color32 BaseColor, SCANresourceGlobal Resource, float Abundance, float Transparency = 0.3f) { if (Abundance < 0) return BaseColor; else if (Abundance == 0) return palette.lerp(BaseColor, palette.Grey, Transparency); else - return palette.lerp(palette.lerp(Resource.MinColor32, Resource.MaxColor32, (float)Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); + return palette.lerp(palette.lerp(Resource.MinColor32, Resource.MaxColor32, Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); } #endregion From 0f691162acc9319c9b132cc0499c309a951ebaf5 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 20 May 2015 16:12:56 -0400 Subject: [PATCH 041/117] More work on big map resource overlays --- SCANsat/SCAN_Map/SCANmap.cs | 81 ++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 526a1d98f..21c31d0c0 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -284,9 +284,11 @@ internal double unprojectLatitude(double lon, double lat) private double mapscale, lon_offset, lat_offset; private int mapwidth, mapheight; private Color[] pix; - private double[] resourceCache; + private float[,] resourceCache; + private int resourceInterpolation; private int resourceStep; private int resourceMapSize; + private double resourceMapScale; private double[] biomeIndex; private Color[] stockBiomeColor; @@ -300,7 +302,7 @@ internal void setSize(int w, int h) pix = new Color[w]; biomeIndex = new double[w]; stockBiomeColor = new Color[w]; - resourceCache = new double[w * 3]; + resourceCache = new float[1,1]; mapscale = mapwidth / 360f; if (h <= 0) h = (int)(180 * mapscale); @@ -329,11 +331,13 @@ internal void setWidth(int w) biomeIndex = new double[w]; stockBiomeColor = new Color[w]; if (w < 1024) - resourceMapSize = 64; + resourceMapSize = 512; else - resourceMapSize = 128; - resourceCache = new double[resourceMapSize * (resourceMapSize / 2)]; - resourceStep = 8; + resourceMapSize = 1024; + resourceCache = new float[resourceMapSize, (resourceMapSize / 2)]; + resourceInterpolation = 8; + resourceMapScale = resourceMapSize / 360f; + resourceStep = 0; mapscale = mapwidth / 360f; mapheight = (int)(w / 2); /* big map caching */ @@ -383,6 +387,14 @@ private double unScaleLatitude(double lat) return lat; } + private double unScaleLatitude(double lat, double scale) + { + lat -= lat_offset; + lat += 90; + lat *= scale; + return lat; + } + private double unScaleLongitude(double lon) { lon -= lon_offset; @@ -391,11 +403,19 @@ private double unScaleLongitude(double lon) return lon; } + private double unScaleLongitude(double lon, double scale) + { + lon -= lon_offset; + lon += 180; + lon *= scale; + return lon; + } + private double fixUnscale(double value, int size) { if (value < 0) value = 0; - else if (value >= size - 0.5) + else if (value >= (size - 0.5f)) value = size - 1; return value; } @@ -595,28 +615,48 @@ internal Texture2D getPartialMap() if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) { resourceOn = true; - if (mapstep < resourceMapSize / 8) + if (mapstep < resourceMapSize / (resourceInterpolation * 8)) { for (int i = 0; i < resourceMapSize; i++) { - double resourceLon = ((i * 8) * 1.0f / mapscale) - 180f + lon_offset; - for (int j = 0; j < 4; j++) + if (i % resourceInterpolation == 0) { - double resourceLat = ((((mapstep * 4) + j) * 8) * 1.0f / mapscale) - 90f + lat_offset; + double resourceLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset; + for (int j = 0; j <= 3 * resourceInterpolation; j++) + { + if (j % resourceInterpolation == 0) + { + double resourceLat = (((mapstep * resourceInterpolation * 4) + j) * 1.0f / resourceMapScale) - 90f + lat_offset; - resourceCache[(((mapstep * 4) + j) * resourceMapSize) + i] = SCANuiUtil.resourceMapValue(resourceLon, resourceLat, data, resource); + resourceCache[i, j] = SCANuiUtil.resourceMapValue(resourceLon, resourceLat, data, resource); + } + } } } } } + if (resourceOn && resourceStep <= (resourceMapSize / 2)) + { + for (int i = resourceInterpolation / 2; i >= 1; i /= 2) + { + if (resourceStep < resourceInterpolation / 2 || resourceStep >= ((resourceMapSize / 2) - (resourceInterpolation / 2))) + { + SCANuiUtil.interpolate(resourceCache, resourceStep, resourceMapSize, i, i); + } + else + { + SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, i, i); + SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, 0, i, i); + SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, 0, i); + } + } + resourceStep++; + } + for (int i = 0; i < map.width; i++) { Color baseColor = palette.grey; - //Color stockBiome = palette.grey; - //double resourceAbundance = 0; - //bool resources = false; - //double bioIndex = 0; pix[i] = baseColor; int scheme = SCANcontroller.controller.colours; float projVal = 0f; @@ -765,6 +805,9 @@ internal Texture2D getPartialMap() if (resourceOn) { + float abundance = 0; + double resourceLat = fixUnscale(unScaleLatitude(lat, resourceMapScale), resourceMapSize / 2); + double resourceLon = fixUnscale(unScaleLongitude(lon, resourceMapScale), resourceMapSize); switch (projection) { case MapProjection.Polar: @@ -779,7 +822,7 @@ internal Texture2D getPartialMap() //} else { - + abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)]; } break; } @@ -791,12 +834,12 @@ internal Texture2D getPartialMap() } else { - + abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)]; } break; } } - pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, resourceCache[i]); + pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, abundance); } else pix[i] = baseColor; From f6633d3873a75d8a5d9b3d7f605242190c43a9be Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 21 May 2015 01:52:03 -0400 Subject: [PATCH 042/117] Fix NRE --- SCANsat/SCAN_UI/SCANresourceController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANresourceController.cs b/SCANsat/SCAN_UI/SCANresourceController.cs index 66a456185..ad42e5751 100644 --- a/SCANsat/SCAN_UI/SCANresourceController.cs +++ b/SCANsat/SCAN_UI/SCANresourceController.cs @@ -48,7 +48,7 @@ protected override void Start() protected override void Update() { - if ((MapView.MapIsEnabled && HighLogic.LoadedSceneIsFlight) || HighLogic.LoadedScene == GameScenes.TRACKSTATION) + if ((MapView.MapIsEnabled && HighLogic.LoadedSceneIsFlight && FlightGlobals.ready) || HighLogic.LoadedScene == GameScenes.TRACKSTATION) { CelestialBody mapBody = SCANUtil.getTargetBody(MapView.MapCamera.target); @@ -58,7 +58,7 @@ protected override void Update() if (mapBody != body) setBody(mapBody); } - else if (HighLogic.LoadedSceneIsFlight) + else if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready) { if (body != FlightGlobals.currentMainBody) setBody(FlightGlobals.currentMainBody); From 59f949539b530e351c84500f6cb4422bf56b967b Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 21 May 2015 01:52:22 -0400 Subject: [PATCH 043/117] Bad fix for array out of range --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 54e005c05..90984c6d8 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1435,6 +1435,9 @@ private static void interpolate(Color32[] c, int height, int x, int y, int step) internal static void interpolate(float[,] V, int Y, int Height, int Width, int XStep, int YStep, int Step) { + if (Y >= Height) + return; + for (int i = Y + YStep; i < Height + YStep + Y; i += 2 * Step) { for (int j = XStep; j < Width + XStep; j += 2 * Step) From a01fbd4a6ed6a05c6c68ac919d3aeb352a084031 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 21 May 2015 01:52:32 -0400 Subject: [PATCH 044/117] interpolation still not working right... --- SCANsat/SCAN_Map/SCANmap.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 21c31d0c0..530f4e841 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -622,11 +622,12 @@ internal Texture2D getPartialMap() if (i % resourceInterpolation == 0) { double resourceLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset; - for (int j = 0; j <= 3 * resourceInterpolation; j++) + int ystep = mapstep * resourceInterpolation * 4; + for (int j = ystep; j <= (3 * resourceInterpolation) + ystep; j++) { if (j % resourceInterpolation == 0) { - double resourceLat = (((mapstep * resourceInterpolation * 4) + j) * 1.0f / resourceMapScale) - 90f + lat_offset; + double resourceLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset; resourceCache[i, j] = SCANuiUtil.resourceMapValue(resourceLon, resourceLat, data, resource); } @@ -636,8 +637,9 @@ internal Texture2D getPartialMap() } } - if (resourceOn && resourceStep <= (resourceMapSize / 2)) + if (resourceOn && resourceStep < (resourceMapSize / 2)) { + bool skip = false; for (int i = resourceInterpolation / 2; i >= 1; i /= 2) { if (resourceStep < resourceInterpolation / 2 || resourceStep >= ((resourceMapSize / 2) - (resourceInterpolation / 2))) @@ -649,9 +651,15 @@ internal Texture2D getPartialMap() SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, i, i); SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, 0, i, i); SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, 0, i); + skip = true; } } - resourceStep++; + if (skip) + resourceStep += 4; + else + resourceStep++; + + SCANUtil.SCANlog("Resource Map Step: {0}", resourceStep); } for (int i = 0; i < map.width; i++) @@ -812,7 +820,7 @@ internal Texture2D getPartialMap() { case MapProjection.Polar: { - if (lat <= 6 || lat >= -6) + if ((lat <= 6 && lat >= 0) || (lat >= -6 && lat <=0)) { } From 0d18099fd6fb71f78c99ae39031dda9ea30a52a5 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 21 May 2015 17:06:06 -0400 Subject: [PATCH 045/117] A few changes to sensorType 0 parts --- SCANsat/SCANsat.cs | 85 ++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/SCANsat/SCANsat.cs b/SCANsat/SCANsat.cs index 48964db29..5111f826a 100644 --- a/SCANsat/SCANsat.cs +++ b/SCANsat/SCANsat.cs @@ -103,58 +103,58 @@ public override void OnStart(StartState state) public override void OnUpdate() { - if (sensorType != 0) + if (sensorType == 0) + return; + + Events["reviewEvent"].active = storedData.Count > 0; + Events["EVACollect"].active = storedData.Count > 0; + Events["startScan"].active = !scanning; + Events["stopScan"].active = scanning; + if (sensorType != 32) + Fields["alt_indicator"].guiActive = scanning; + if (scanning) { - Events["reviewEvent"].active = storedData.Count > 0; - Events["EVACollect"].active = storedData.Count > 0; - Events["startScan"].active = !scanning; - Events["stopScan"].active = scanning; - if (sensorType != 32) - Fields["alt_indicator"].guiActive = scanning; - if (scanning) + if (SCANcontroller.controller == null) { - if (SCANcontroller.controller == null) - { - scanning = false; - Debug.LogError("[SCANsat] Warning: SCANsat scenario module not initialized; Shutting down"); - } - else + scanning = false; + Debug.LogError("[SCANsat] Warning: SCANsat scenario module not initialized; Shutting down"); + } + else + { + if (sensorType != 0 || SCANcontroller.controller.isVesselKnown(vessel.id, (SCANtype)sensorType)) { - if (sensorType != 0 || SCANcontroller.controller.isVesselKnown(vessel.id, (SCANtype)sensorType)) + if (TimeWarp.CurrentRate < 1500) { - if (TimeWarp.CurrentRate < 1500) + float p = power * TimeWarp.deltaTime; + float e = part.RequestResource("ElectricCharge", p); + if (e < p) { - float p = power * TimeWarp.deltaTime; - float e = part.RequestResource("ElectricCharge", p); - if (e < p) - { - unregisterScanner(); - powerIsProblem = true; - } - else - { - registerScanner(); - powerIsProblem = false; - } + unregisterScanner(); + powerIsProblem = true; } - else if (powerIsProblem) + else { registerScanner(); powerIsProblem = false; } } - else - unregisterScanner(); - alt_indicator = scanAlt(); + else if (powerIsProblem) + { + registerScanner(); + powerIsProblem = false; + } } + else + unregisterScanner(); + alt_indicator = scanAlt(); } - if (vessel == FlightGlobals.ActiveVessel) + } + if (vessel == FlightGlobals.ActiveVessel) + { + if (powerIsProblem) { - if (powerIsProblem) - { - addStatic(); - registerScanner(); - } + addStatic(); + registerScanner(); } } } @@ -211,6 +211,9 @@ public override void OnSave(ConfigNode node) public override string GetInfo() { + if (sensorType == 0) + return ""; + string str = base.GetInfo(); if (min_alt != 0) { @@ -351,19 +354,19 @@ private void animate(float speed, float time) /* SCAN: actions for ... something ... */ [KSPAction("Start Scan")] - public virtual void startScanAction(KSPActionParam param) + public void startScanAction(KSPActionParam param) { startScan(); } [KSPAction("Stop Scan")] - public virtual void stopScanAction(KSPActionParam param) + public void stopScanAction(KSPActionParam param) { stopScan(); } [KSPAction("Toggle Scan")] - public virtual void toggleScanAction(KSPActionParam param) + public void toggleScanAction(KSPActionParam param) { if (scanning) stopScan(); From a38cf1ff08d6f6ea3aea65c2bcd9f1db22825a9e Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 21 May 2015 17:06:21 -0400 Subject: [PATCH 046/117] Tweaks to action groups; animator group --- SCANsat/SCANresourceScanner.cs | 71 ++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/SCANsat/SCANresourceScanner.cs b/SCANsat/SCANresourceScanner.cs index e23d63419..8cf2a7b8e 100644 --- a/SCANsat/SCANresourceScanner.cs +++ b/SCANsat/SCANresourceScanner.cs @@ -19,9 +19,6 @@ namespace SCANsat { public class ModuleSCANresourceScanner : SCANsat, IAnimatedModule { - [KSPField] - public bool activeModule = false; - private List mSurvey; private List mScanner; private ModuleAnimationGroup animGroup; @@ -36,30 +33,36 @@ public override void OnStart(PartModule.StartState state) if (animGroup == null) this.isEnabled = true; + + Actions["startScanAction"].active = false; + Actions["stopScanAction"].active = false; + Actions["toggleScanAction"].active = false; + Actions["startResourceScanAction"].guiName = "Start " + scanName; + Actions["stopResourceScanAction"].guiName = "Stop " + scanName; + Actions["toggleResourceScanAction"].guiName = "Toggle " + scanName; } public override string GetInfo() { string info = base.GetInfo(); info += "Resource Scan: " + (SCANtype)sensorType + "\n"; - info += "Active Scanner: " + RUIutils.GetYesNoUIString(activeModule) + "\n"; return info; } private List findScanner() { - return part.Modules.GetModules(); + return part.FindModulesImplementing(); } private List findSurvey() { - return part.Modules.GetModules(); + return part.FindModulesImplementing(); } private ModuleAnimationGroup findAnimator() { - return part.Modules.GetModules().FirstOrDefault(); + return part.FindModulesImplementing().FirstOrDefault(); } private void updateEvents() @@ -70,45 +73,53 @@ private void updateEvents() public override void OnUpdate() { - if (activeModule) - { - base.OnUpdate(); + base.OnUpdate(); - if (!HighLogic.LoadedSceneIsFlight) - return; + if (!HighLogic.LoadedSceneIsFlight) + return; - if (SCANcontroller.controller == null) - return; + if (!FlightGlobals.ready) + return; - if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) - updateEvents(); - else - { - base.Events["startScan"].active = false; - base.Events["stopScan"].active = false; - if (scanning) - unregisterScanner(); - } - } + if (SCANcontroller.controller == null) + return; + + if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) + updateEvents(); else { base.Events["startScan"].active = false; base.Events["stopScan"].active = false; + if (scanning) + unregisterScanner(); } } - public override void startScanAction(KSPActionParam param) + [KSPAction("Start Resource Scan")] + public void startResourceScanAction(KSPActionParam param) { if (animGroup != null && !scanning && !animGroup.isDeployed) animGroup.DeployModule(); - base.startScanAction(param); + startScan(); } - public override void toggleScanAction(KSPActionParam param) + [KSPAction("Stop Resource Scan")] + public void stopResourceScanAction(KSPActionParam param) { - if (animGroup != null && !scanning && !animGroup.isDeployed) - animGroup.DeployModule(); - base.toggleScanAction(param); + stopScan(); + } + + [KSPAction("Toggle Resource Scan")] + public void toggleResourceScanAction(KSPActionParam param) + { + if (scanning) + stopScan(); + else + { + if (animGroup != null && !animGroup.isDeployed) + animGroup.DeployModule(); + startScan(); + } } public void DisableModule() From e573ebda8145e79bbfc7f756ba0844abed3f8daf Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 21 May 2015 17:06:43 -0400 Subject: [PATCH 047/117] New interpolation method; check all resource values, regardless of scanning coverage --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 141 +++++++++++++-------- 1 file changed, 87 insertions(+), 54 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 90984c6d8..a6397b46a 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1352,6 +1352,7 @@ private static void GLVertexMap(Vector3d pos) internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdata data, SCANresourceGlobal resource, int stepScale = 8, float transparency = 0f) { int width = height * 2; + float[,] abundanceValues = new float[width, height]; Color32[] pix = new Color32[width * height]; float scale = height / 180f; @@ -1375,15 +1376,17 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat if (lon < -180) lon += 360; - pix[j * width + i] = resourceToColor(palette.Clear, resource, resourceMapValue(lon, lat, data, resource), transparency); + abundanceValues[i, j] = SCANUtil.ResourceOverlay(lat, lon, resource.Name, data.Body) * 100; + + pix[j * width + i] = resourceToColor(palette.Clear, resource, abundanceValues[i, j], data, lon, lat, transparency); } } for (int i = stepScale / 2; i >= 1; i /= 2) { - interpolate(pix, height, i, i, i); - interpolate(pix, height, 0, i, i); - interpolate(pix, height, i, 0, i); + interpolate(pix, abundanceValues, height, i, i, i, resource, transparency, data); + interpolate(pix, abundanceValues, height, 0, i, i, resource, transparency, data); + interpolate(pix, abundanceValues, height, i, 0, i, resource, transparency, data); } map.SetPixels32(pix); @@ -1392,69 +1395,83 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat return map; } - private static void interpolate(Color32[] c, int height, int x, int y, int step) + private static void interpolate(Color32[] c, float[,] v, int height, int x, int y, int step, SCANresourceGlobal r, float t, SCANdata d) { int width = height * 2; - for (int i = y; i < height + y; i += 2 * step) + float scale = width / 360f; + for (int j = y; j < height + y; j += 2 * step) { - for (int j = x; j < width + x; j += 2 * step) + for (int i = x; i < width + x; i += 2 * step) { - int xpos1 = j - step; + double lon = (i / scale); + double lat = (j / scale) - 90; + + if (lon <= 180) + lon = 180 - lon; + else + lon = (lon - 180) * -1; + lon -= 90; + if (lon < -180) + lon += 360; + + int xpos1 = i - step; if (xpos1 < 0) xpos1 += width; - int xpos2 = j + step; + int xpos2 = i + step; if (xpos2 >= width) xpos2 -= width; - int ypos1 = i - step; + int ypos1 = j - step; if (ypos1 < 0) ypos1 = 0; - int ypos2 = i + step; + int ypos2 = j + step; if (ypos2 >= height) ypos2 = height - 1; - Color32 xInt; - Color32 yInt; + float avgX = 0; + float avgY = 0; + if (x == y) { - yInt = palette.lerp(c[(ypos1 * width) + xpos1], c[(ypos2 * width) + xpos2], 0.5f); - xInt = palette.lerp(c[(ypos2 * width) + xpos1], c[(ypos1 * width) + xpos2], 0.5f); + avgX = Mathf.Lerp(v[xpos1, ypos1], v[xpos2, ypos2], 0.5f); + avgY = Mathf.Lerp(v[xpos1, ypos2], v[xpos2, ypos1], 0.5f); } else { - yInt = palette.lerp(c[(i * width) + xpos1], c[(i * width) + xpos2], 0.5f); - xInt = palette.lerp(c[(ypos1 * width) + j], c[(ypos2 * width) + j], 0.5f); + avgX = Mathf.Lerp(v[xpos1, j], v[xpos2, j], 0.5f); + avgY = Mathf.Lerp(v[i, ypos2], v[i, ypos1], 0.5f); } - Color32 final = palette.lerp(xInt, yInt, 0.5f); + float avgFinal = Mathf.Lerp(avgX, avgY, 0.5f); + + v[i, j] = avgFinal; - c[i * width + j] = final; + c[j * width + i] = resourceToColor(palette.Clear, r, v[i, j], d, lon, lat, t); } } } internal static void interpolate(float[,] V, int Y, int Height, int Width, int XStep, int YStep, int Step) { - if (Y >= Height) - return; + int mapHeight = Width / 2; - for (int i = Y + YStep; i < Height + YStep + Y; i += 2 * Step) + for (int j = Y + YStep; j < Height + YStep + Y; j += 2 * Step) { - for (int j = XStep; j < Width + XStep; j += 2 * Step) + for (int i = XStep; i < Width + XStep; i += 2 * Step) { - int xpos1 = j - Step; + int xpos1 = i - Step; if (xpos1 < 0) xpos1 = 0; - int xpos2 = j + Step; + int xpos2 = i + Step; if (xpos2 >= Width) xpos2 = Width - 1; - int ypos1 = i - Step; + int ypos1 = j - Step; if (ypos1 < 0) ypos1 = 0; - int ypos2 = i + Step; - if (ypos2 >= Height) - ypos2 = Height - 1; + int ypos2 = j + Step; + if (ypos2 >= mapHeight) + ypos2 = mapHeight - 1; float avgX = 0; float avgY = 0; @@ -1466,13 +1483,13 @@ internal static void interpolate(float[,] V, int Y, int Height, int Width, int X } else { - avgX = Mathf.Lerp(V[xpos1, i], V[xpos2, i], 0.5f); - avgY = Mathf.Lerp(V[j, ypos2], V[j, ypos1], 0.5f); + avgX = Mathf.Lerp(V[xpos1, j], V[xpos2, j], 0.5f); + avgY = Mathf.Lerp(V[i, ypos2], V[i, ypos1], 0.5f); } float avgFinal = Mathf.Lerp(avgX, avgY, 0.5f); - V[j, i] = avgFinal; + V[i, j] = avgFinal; } } } @@ -1494,41 +1511,33 @@ internal static void interpolate(float[,] V, int Y, int Width, int XStep, int St } } - internal static float resourceMapValue(double Lon, double Lat, SCANdata Data, SCANresourceGlobal resource) + /* Converts resource amount to pixel color */ + internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resource, float Abundance, SCANdata Data, double Lon, double Lat) { - float amount = 0; - if (SCANUtil.isCovered(Lon, Lat, Data, resource.SType)) + if (SCANUtil.isCovered(Lon, Lat, Data, Resource.SType)) { - amount = SCANUtil.ResourceOverlay(Lat, Lon, resource.Name, Data.Body); - amount *= 100; - if (amount >= resource.CurrentBody.MinValue) + if (Abundance >= Resource.CurrentBody.MinValue) { - if (amount > resource.CurrentBody.MaxValue) - amount = resource.CurrentBody.MaxValue; + if (Abundance > Resource.CurrentBody.MaxValue) + Abundance = Resource.CurrentBody.MaxValue; } else - amount = 0; + Abundance = 0; } else if (SCANUtil.isCovered(Lon, Lat, Data, SCANtype.FuzzyResources)) { - amount = SCANUtil.ResourceOverlay(((int)(Lat * 5)) / 5, ((int)(Lon * 5)) / 5, resource.Name, Data.Body); - amount *= 100; - if (amount >= resource.CurrentBody.MinValue) + Abundance = Mathf.RoundToInt(Abundance); + if (Abundance >= Resource.CurrentBody.MinValue) { - if (amount > resource.CurrentBody.MaxValue) - amount = resource.CurrentBody.MaxValue; + if (Abundance > Resource.CurrentBody.MaxValue) + Abundance = Resource.CurrentBody.MaxValue; } else - amount = 0; + Abundance = 0; } else - amount = -1; - return amount; - } + Abundance = -1; - /* Converts resource amount to pixel color */ - internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resource, float Abundance) - { if (Abundance < 0) return BaseColor; else if (Abundance == 0) @@ -1537,8 +1546,32 @@ internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resour return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); } - private static Color32 resourceToColor(Color32 BaseColor, SCANresourceGlobal Resource, float Abundance, float Transparency = 0.3f) + private static Color32 resourceToColor(Color32 BaseColor, SCANresourceGlobal Resource, float Abundance, SCANdata Data, double Lon, double Lat, float Transparency = 0.3f) { + if (SCANUtil.isCovered(Lon, Lat, Data, Resource.SType)) + { + if (Abundance >= Resource.CurrentBody.MinValue) + { + if (Abundance > Resource.CurrentBody.MaxValue) + Abundance = Resource.CurrentBody.MaxValue; + } + else + Abundance = 0; + } + else if (SCANUtil.isCovered(Lon, Lat, Data, SCANtype.FuzzyResources)) + { + Abundance = Mathf.RoundToInt(Abundance); + if (Abundance >= Resource.CurrentBody.MinValue) + { + if (Abundance > Resource.CurrentBody.MaxValue) + Abundance = Resource.CurrentBody.MaxValue; + } + else + Abundance = 0; + } + else + Abundance = -1; + if (Abundance < 0) return BaseColor; else if (Abundance == 0) From 8407a8edfc3d6d7d49ad7d7f39c1fc7418cc061d Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 21 May 2015 17:07:03 -0400 Subject: [PATCH 048/117] Fix some aspects of big map resource overlay --- SCANsat/SCAN_Map/SCANmap.cs | 71 +++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 530f4e841..59a8fa273 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -572,36 +572,30 @@ internal Texture2D getPartialMap() } } - if (mType == mapType.Biome && biomeMap) - { - - double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; - double lon = (i * 1.0f / mapscale) - 180f + lon_offset; - double la = lat, lo = lon; - lat = unprojectLatitude(lo, la); - lon = unprojectLongitude(lo, la); + if (mType != mapType.Biome && biomeMap) + continue; - if (double.IsNaN(lat) || double.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180) - { - continue; - } + double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; + double lon = (i * 1.0f / mapscale) - 180f + lon_offset; + double la = lat, lo = lon; + lat = unprojectLatitude(lo, la); + lon = unprojectLongitude(lo, la); - //if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) - //{ - // resourceCache[i] = SCANuiUtil.resourceMapValue(lon, lat, data, resource); - //} + if (double.IsNaN(lat) || double.IsNaN(lon) || lat < -90 || lat > 90 || lon < -180 || lon > 180) + { + stockBiomeColor[i] = palette.clear; + biomeIndex[i] = 0; + continue; + } - //if (mType == mapType.Biome && biomeMap) - //{ - if (SCANcontroller.controller.useStockBiomes && SCANcontroller.controller.colours == 0) - { - stockBiomeColor[i] = SCANUtil.getBiome(body, lon, lat).mapColor; - if (SCANcontroller.controller.biomeBorder) - biomeIndex[i] = SCANUtil.getBiomeIndexFraction(body, lon, lat); - } - else + if (SCANcontroller.controller.useStockBiomes && SCANcontroller.controller.colours == 0) + { + stockBiomeColor[i] = SCANUtil.getBiome(body, lon, lat).mapColor; + if (SCANcontroller.controller.biomeBorder) biomeIndex[i] = SCANUtil.getBiomeIndexFraction(body, lon, lat); } + else + biomeIndex[i] = SCANUtil.getBiomeIndexFraction(body, lon, lat); } if (mapstep <= -1) @@ -617,21 +611,22 @@ internal Texture2D getPartialMap() resourceOn = true; if (mapstep < resourceMapSize / (resourceInterpolation * 8)) { - for (int i = 0; i < resourceMapSize; i++) + for (int i = 0; i < resourceMapSize; i++) { - if (i % resourceInterpolation == 0) + if (i % resourceInterpolation != 0) + continue; + + double resourceLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset; + int ystep = mapstep * resourceInterpolation * 4; + + for (int j = ystep; j <= (3 * resourceInterpolation) + ystep; j++) { - double resourceLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset; - int ystep = mapstep * resourceInterpolation * 4; - for (int j = ystep; j <= (3 * resourceInterpolation) + ystep; j++) - { - if (j % resourceInterpolation == 0) - { - double resourceLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset; + if (j % resourceInterpolation != 0) + continue; - resourceCache[i, j] = SCANuiUtil.resourceMapValue(resourceLon, resourceLat, data, resource); - } - } + double resourceLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset; + + resourceCache[i, j] = SCANUtil.ResourceOverlay(resourceLat, resourceLon, resource.Name, body) * 100; } } } @@ -847,7 +842,7 @@ internal Texture2D getPartialMap() break; } } - pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, abundance); + pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, abundance, data, lon, lat); } else pix[i] = baseColor; From 7bfd670c85d3794d9c6030a259619ae13abfb34d Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 25 May 2015 02:57:49 -0400 Subject: [PATCH 049/117] Fix action groups --- SCANsat/SCANresourceScanner.cs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/SCANsat/SCANresourceScanner.cs b/SCANsat/SCANresourceScanner.cs index 8cf2a7b8e..fa97a1b05 100644 --- a/SCANsat/SCANresourceScanner.cs +++ b/SCANsat/SCANresourceScanner.cs @@ -22,6 +22,7 @@ public class ModuleSCANresourceScanner : SCANsat, IAnimatedModule private List mSurvey; private List mScanner; private ModuleAnimationGroup animGroup; + private bool activated = false; public override void OnStart(PartModule.StartState state) { @@ -32,14 +33,19 @@ public override void OnStart(PartModule.StartState state) animGroup = findAnimator(); if (animGroup == null) + { + SCANUtil.SCANlog("No Anim Group Found"); this.isEnabled = true; + } + else + SCANUtil.SCANlog("Anim Group Found"); Actions["startScanAction"].active = false; Actions["stopScanAction"].active = false; Actions["toggleScanAction"].active = false; - Actions["startResourceScanAction"].guiName = "Start " + scanName; - Actions["stopResourceScanAction"].guiName = "Stop " + scanName; - Actions["toggleResourceScanAction"].guiName = "Toggle " + scanName; + Actions["startResourceScanAction"].guiName = "Start Action " + scanName; + Actions["stopResourceScanAction"].guiName = "Stop Action" + scanName; + Actions["toggleResourceScanAction"].guiName = "Toggle Action" + scanName; } public override string GetInfo() @@ -71,8 +77,11 @@ private void updateEvents() base.Events["stopScan"].active = scanning; } - public override void OnUpdate() + public void Update() { + if (!activated) + return; + base.OnUpdate(); if (!HighLogic.LoadedSceneIsFlight) @@ -98,6 +107,7 @@ public override void OnUpdate() [KSPAction("Start Resource Scan")] public void startResourceScanAction(KSPActionParam param) { + SCANUtil.SCANlog("Start Scan"); if (animGroup != null && !scanning && !animGroup.isDeployed) animGroup.DeployModule(); startScan(); @@ -106,12 +116,14 @@ public void startResourceScanAction(KSPActionParam param) [KSPAction("Stop Resource Scan")] public void stopResourceScanAction(KSPActionParam param) { + SCANUtil.SCANlog("Stop Scan"); stopScan(); } [KSPAction("Toggle Resource Scan")] public void toggleResourceScanAction(KSPActionParam param) { + SCANUtil.SCANlog("Toggle Scan"); if (scanning) stopScan(); else @@ -124,7 +136,9 @@ public void toggleResourceScanAction(KSPActionParam param) public void DisableModule() { - this.isEnabled = false; + activated = false; + base.Events["startScan"].active = false; + base.Events["stopScan"].active = false; unregisterScanner(); if (mSurvey != null && SCANcontroller.controller.disableStockResource) { @@ -137,7 +151,7 @@ public void DisableModule() public void EnableModule() { - this.isEnabled = true; + activated = true; if (mSurvey != null && SCANcontroller.controller.disableStockResource) { foreach (ModuleOrbitalSurveyor m in mSurvey) From d5e26e254ececd36f0c8a759f581093bc10ce669 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 25 May 2015 02:58:13 -0400 Subject: [PATCH 050/117] map width divisible by 8 --- SCANsat/SCAN_UI/SCANbigMap.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SCANsat/SCAN_UI/SCANbigMap.cs b/SCANsat/SCAN_UI/SCANbigMap.cs index f8572bb6c..610a0ed6f 100644 --- a/SCANsat/SCAN_UI/SCANbigMap.cs +++ b/SCANsat/SCAN_UI/SCANbigMap.cs @@ -83,6 +83,9 @@ protected override void Start() { bigmap = new SCANmap(b, true); bigmap.setProjection((MapProjection)SCANcontroller.controller.projection); + int i = SCANcontroller.controller.map_width % 8; + if (i != 0) + SCANcontroller.controller.map_width -= i; bigmap.setWidth(SCANcontroller.controller.map_width); } WindowRect.x = SCANcontroller.controller.map_x; @@ -150,6 +153,9 @@ protected override void DrawWindowPre(int id) IsResizing = false; if (resizeW < WindowSize_Min.x) resizeW = WindowSize_Min.x; + int i = (int)resizeW % 8; + if (i != 0) + resizeW -= i; bigmap.setWidth((int)resizeW); drawGrid = true; SCANcontroller.controller.map_width = bigmap.MapWidth; From 7976b884e57ae53c84391d6947b00d3ebeaeebd6 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 25 May 2015 02:58:36 -0400 Subject: [PATCH 051/117] styles for resource window --- SCANsat/SCAN_UI/SCANresourceController.cs | 14 +++++++------- SCANsat/SCAN_UI/UI_Framework/SCANskins.cs | 12 +++++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANresourceController.cs b/SCANsat/SCAN_UI/SCANresourceController.cs index ad42e5751..74b779be6 100644 --- a/SCANsat/SCAN_UI/SCANresourceController.cs +++ b/SCANsat/SCAN_UI/SCANresourceController.cs @@ -121,7 +121,7 @@ private void drawResourceList(int id) foreach (SCANresourceGlobal r in resources) { growE(); - if (GUILayout.Button(r.Name, SCANskins.SCAN_labelLeft)) + if (GUILayout.Button(r.Name, r == currentResource ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) { if (currentResource == r) { @@ -160,13 +160,13 @@ private void overlayOptions(int id) growE(); GUILayout.Label("Coverage Transparency:", SCANskins.SCAN_labelSmallLeft); - if (GUILayout.Button("-", SCANskins.SCAN_labelSmall)) + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { transparency = Mathf.Max(0f, transparency - 0.1f); refreshMap(); } GUILayout.Label(transparency.ToString("P0"), SCANskins.SCAN_labelSmall); - if (GUILayout.Button("+", SCANskins.SCAN_labelSmall)) + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { transparency = Mathf.Min(1f, transparency + 0.1f); refreshMap(); @@ -176,13 +176,13 @@ private void overlayOptions(int id) growE(); GUILayout.Label("Interpolation:", SCANskins.SCAN_labelSmallLeft); - if (GUILayout.Button("-", SCANskins.SCAN_labelSmall)) + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { interpolationScale = Math.Max(2, interpolationScale / 2); refreshMap(); } GUILayout.Label(interpolationScale.ToString(), SCANskins.SCAN_labelSmall); - if (GUILayout.Button("+", SCANskins.SCAN_labelSmall)) + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { interpolationScale = Math.Min(32, interpolationScale * 2); refreshMap(); @@ -192,13 +192,13 @@ private void overlayOptions(int id) growE(); GUILayout.Label("Map Height:", SCANskins.SCAN_labelSmallLeft); - if (GUILayout.Button("-", SCANskins.SCAN_labelSmall)) + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { mapHeight = Math.Max(64, mapHeight / 2); refreshMap(); } GUILayout.Label(mapHeight.ToString(), SCANskins.SCAN_labelSmall); - if (GUILayout.Button("+", SCANskins.SCAN_labelSmall)) + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { mapHeight = Math.Min(1024, mapHeight * 2); refreshMap(); diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs index 8a910fd8a..532f29902 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs @@ -56,6 +56,8 @@ class SCANskins: SCAN_MBE internal static GUIStyle SCAN_labelLeft; internal static GUIStyle SCAN_labelRight; internal static GUIStyle SCAN_labelSmall; + internal static GUIStyle SCAN_labelLeftActive; + internal static GUIStyle SCAN_buttonSmall; //Settings menu styles internal static GUIStyle SCAN_headline; @@ -277,11 +279,14 @@ private static void initializeSkins() SCAN_anomalyOverlay.normal.textColor = palette.cb_skyBlue; //Resource Control settings - SCAN_labelLeft = new GUIStyle(SCAN_SkinsLibrary.DefUnitySkin.label); + SCAN_labelLeft = new GUIStyle(SCAN_texButton); SCAN_labelLeft.fontSize = 12; SCAN_labelLeft.hover.textColor = palette.cb_bluishGreen; SCAN_labelLeft.alignment = TextAnchor.MiddleLeft; + SCAN_labelLeftActive = new GUIStyle(SCAN_labelLeft); + SCAN_labelLeftActive.normal.textColor = palette.cb_bluishGreen; + SCAN_labelRight = new GUIStyle(SCAN_labelLeft); SCAN_labelRight.alignment = TextAnchor.MiddleRight; @@ -290,6 +295,11 @@ private static void initializeSkins() SCAN_labelSmall.alignment = TextAnchor.MiddleCenter; SCAN_labelSmall.fontStyle = FontStyle.Bold; + SCAN_buttonSmall = new GUIStyle(SCAN_SkinsLibrary.DefUnitySkin.button); + SCAN_buttonSmall.fontSize = 10; + SCAN_buttonSmall.alignment = TextAnchor.MiddleCenter; + SCAN_buttonSmall.fontStyle = FontStyle.Bold; + //Initialize settings menu styles SCAN_headline = new GUIStyle(SCAN_SkinsLibrary.DefUnitySkin.label); SCAN_headline.name = "SCAN_Headline"; From 06aa4b2c0b7a557751f205780c4e271aa0d4ea11 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 25 May 2015 02:59:54 -0400 Subject: [PATCH 052/117] Changes to interpolation methods --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 122 ++++++++++++--------- 1 file changed, 68 insertions(+), 54 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index a6397b46a..cdf10f733 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1349,6 +1349,19 @@ private static void GLVertexMap(Vector3d pos) #region Planet Overlay Textures + private static double fixLon(double Lon) + { + if (Lon <= 180) + Lon = 180 - Lon; + else + Lon = (Lon - 180) * -1; + Lon -= 90; + if (Lon < -180) + Lon += 360; + + return Lon; + } + internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdata data, SCANresourceGlobal resource, int stepScale = 8, float transparency = 0f) { int width = height * 2; @@ -1361,21 +1374,15 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat map = new Texture2D(width, height, TextureFormat.ARGB32, true); } + System.Random r = new System.Random(ResourceScenario.Instance.gameSettings.Seed); + for (int j = 0; j < height; j += stepScale) { for (int i = 0; i < width; i += stepScale) { - double lon = (i / scale); + double lon = fixLon(i / scale); double lat = (j / scale) - 90; - if (lon <= 180) - lon = 180 - lon; - else - lon = (lon - 180) * -1; - lon -= 90; - if (lon < -180) - lon += 360; - abundanceValues[i, j] = SCANUtil.ResourceOverlay(lat, lon, resource.Name, data.Body) * 100; pix[j * width + i] = resourceToColor(palette.Clear, resource, abundanceValues[i, j], data, lon, lat, transparency); @@ -1384,9 +1391,9 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat for (int i = stepScale / 2; i >= 1; i /= 2) { - interpolate(pix, abundanceValues, height, i, i, i, resource, transparency, data); - interpolate(pix, abundanceValues, height, 0, i, i, resource, transparency, data); - interpolate(pix, abundanceValues, height, i, 0, i, resource, transparency, data); + interpolate(pix, abundanceValues, height, i, i, i, resource, transparency, data, r); + interpolate(pix, abundanceValues, height, 0, i, i, resource, transparency, data, r); + interpolate(pix, abundanceValues, height, i, 0, i, resource, transparency, data, r); } map.SetPixels32(pix); @@ -1395,7 +1402,15 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat return map; } - private static void interpolate(Color32[] c, float[,] v, int height, int x, int y, int step, SCANresourceGlobal r, float t, SCANdata d) + private static float getLerp(System.Random rand, int l) + { + if (l == 0) + return 0.5f; + + return (float)l / 100f + (float)rand.Next(100 - (l / 2)) / 100f; + } + + private static void interpolate(Color32[] c, float[,] v, int height, int x, int y, int step, SCANresourceGlobal r, float t, SCANdata d, System.Random rand) { int width = height * 2; float scale = width / 360f; @@ -1403,17 +1418,9 @@ private static void interpolate(Color32[] c, float[,] v, int height, int x, int { for (int i = x; i < width + x; i += 2 * step) { - double lon = (i / scale); + double lon = fixLon(i / scale); double lat = (j / scale) - 90; - if (lon <= 180) - lon = 180 - lon; - else - lon = (lon - 180) * -1; - lon -= 90; - if (lon < -180) - lon += 360; - int xpos1 = i - step; if (xpos1 < 0) xpos1 += width; @@ -1431,18 +1438,20 @@ private static void interpolate(Color32[] c, float[,] v, int height, int x, int float avgX = 0; float avgY = 0; + float lerp = getLerp(rand, step * 2); + if (x == y) { - avgX = Mathf.Lerp(v[xpos1, ypos1], v[xpos2, ypos2], 0.5f); - avgY = Mathf.Lerp(v[xpos1, ypos2], v[xpos2, ypos1], 0.5f); + avgX = Mathf.Lerp(v[xpos1, ypos1], v[xpos2, ypos2], lerp); + avgY = Mathf.Lerp(v[xpos1, ypos2], v[xpos2, ypos1], lerp); } else { - avgX = Mathf.Lerp(v[xpos1, j], v[xpos2, j], 0.5f); - avgY = Mathf.Lerp(v[i, ypos2], v[i, ypos1], 0.5f); + avgX = Mathf.Lerp(v[xpos1, j], v[xpos2, j], lerp); + avgY = Mathf.Lerp(v[i, ypos2], v[i, ypos1], lerp); } - float avgFinal = Mathf.Lerp(avgX, avgY, 0.5f); + float avgFinal = Mathf.Lerp(avgX, avgY, lerp); v[i, j] = avgFinal; @@ -1451,63 +1460,68 @@ private static void interpolate(Color32[] c, float[,] v, int height, int x, int } } - internal static void interpolate(float[,] V, int Y, int Height, int Width, int XStep, int YStep, int Step) + internal static void interpolate(float[,] v, int yStart, int height, int width, int x, int y, int step, System.Random r) { - int mapHeight = Width / 2; + int mapHeight = width / 2; - for (int j = Y + YStep; j < Height + YStep + Y; j += 2 * Step) + for (int j = yStart + y; j < height + y + yStart; j += 2 * step) { - for (int i = XStep; i < Width + XStep; i += 2 * Step) + for (int i = x; i < width + x; i += 2 * step) { - int xpos1 = i - Step; + int xpos1 = i - step; if (xpos1 < 0) - xpos1 = 0; - int xpos2 = i + Step; - if (xpos2 >= Width) - xpos2 = Width - 1; + xpos1 += width; + int xpos2 = i + step; + if (xpos2 >= width) + xpos2 -= width; - int ypos1 = j - Step; + int ypos1 = j - step; if (ypos1 < 0) ypos1 = 0; - int ypos2 = j + Step; + int ypos2 = j + step; if (ypos2 >= mapHeight) ypos2 = mapHeight - 1; float avgX = 0; float avgY = 0; - if (XStep == YStep) + float lerp = getLerp(r, step * 2); + + if (x == y) { - avgX = Mathf.Lerp(V[xpos1, ypos1], V[xpos2, ypos2], 0.5f); - avgY = Mathf.Lerp(V[xpos1, ypos2], V[xpos2, ypos1], 0.5f); + avgX = Mathf.Lerp(v[xpos1, ypos1], v[xpos2, ypos2], lerp); + avgY = Mathf.Lerp(v[xpos1, ypos2], v[xpos2, ypos1], lerp); } else { - avgX = Mathf.Lerp(V[xpos1, j], V[xpos2, j], 0.5f); - avgY = Mathf.Lerp(V[i, ypos2], V[i, ypos1], 0.5f); + avgX = Mathf.Lerp(v[xpos1, j], v[xpos2, j], lerp); + avgY = Mathf.Lerp(v[i, ypos2], v[i, ypos1], lerp); } - float avgFinal = Mathf.Lerp(avgX, avgY, 0.5f); + float avgFinal = Mathf.Lerp(avgX, avgY, lerp); - V[i, j] = avgFinal; + v[i, j] = avgFinal; } } } - internal static void interpolate(float[,] V, int Y, int Width, int XStep, int Step) + internal static void interpolate(float[,] v, int yStart, int width, int x, int step, System.Random r) { - for (int i = XStep; i < Width + XStep; i += 2 * Step) + + for (int i = x; i < width + x; i += 2 * step) { - int xpos1 = i - Step; + int xpos1 = i - step; if (xpos1 < 0) - xpos1 = 0; - int xpos2 = i + Step; - if (xpos2 >= Width) - xpos2 = Width - 1; + xpos1 += width; + int xpos2 = i + step; + if (xpos2 >= width) + xpos2 -= width; + + float lerp = getLerp(r, step * 2); - float avgX = Mathf.Lerp(V[xpos1, Y], V[xpos2, Y], 0.5f); + float avgX = Mathf.Lerp(v[xpos1, yStart], v[xpos2, yStart], lerp); - V[i, Y] = avgX; + v[i, yStart] = avgX; } } From 7db4e9503bfc671dfe43f2913be7c2b588fa8429 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 25 May 2015 03:00:06 -0400 Subject: [PATCH 053/117] resource overlay still not working... --- SCANsat/SCAN_Map/SCANmap.cs | 85 ++++++++++++++----------------------- 1 file changed, 33 insertions(+), 52 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 59a8fa273..a2541f35e 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -288,7 +288,6 @@ internal double unprojectLatitude(double lon, double lat) private int resourceInterpolation; private int resourceStep; private int resourceMapSize; - private double resourceMapScale; private double[] biomeIndex; private Color[] stockBiomeColor; @@ -330,14 +329,8 @@ internal void setWidth(int w) pix = new Color[w]; biomeIndex = new double[w]; stockBiomeColor = new Color[w]; - if (w < 1024) - resourceMapSize = 512; - else - resourceMapSize = 1024; - resourceCache = new float[resourceMapSize, (resourceMapSize / 2)]; - resourceInterpolation = 8; - resourceMapScale = resourceMapSize / 360f; - resourceStep = 0; + resourceMapSize = mapwidth; + resourceInterpolation = 4; mapscale = mapwidth / 360f; mapheight = (int)(w / 2); /* big map caching */ @@ -469,6 +462,7 @@ public void resetMap(bool setRes = true) resource = SCANcontroller.GetFirstResource; resource.CurrentBodyConfig(body.name); } + resetResourceMap(); } } @@ -479,6 +473,12 @@ public void resetMap(mapType mode, bool Cache, bool setRes = true) resetMap(setRes); } + public void resetResourceMap() + { + resourceStep = 0; + resourceCache = new float[resourceMapSize, (resourceMapSize / 2)]; + } + /* MAP: export: PNG file */ internal void exportPNG() { @@ -516,6 +516,8 @@ internal Texture2D getPartialMap() if (data == null) return new Texture2D(1, 1); + System.Random r = new System.Random(ResourceScenario.Instance.gameSettings.Seed); + bool resourceOn = false; /* init cache if necessary */ @@ -616,45 +618,43 @@ internal Texture2D getPartialMap() if (i % resourceInterpolation != 0) continue; - double resourceLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset; + double resourceLon = (i * 1.0f / mapscale) - 180f + lon_offset; int ystep = mapstep * resourceInterpolation * 4; - for (int j = ystep; j <= (3 * resourceInterpolation) + ystep; j++) + for (int j = ystep; j < (4 * resourceInterpolation) + ystep; j++) { if (j % resourceInterpolation != 0) continue; - double resourceLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset; + double resourceLat = (j * 1.0f / mapscale) - 90f + lat_offset; resourceCache[i, j] = SCANUtil.ResourceOverlay(resourceLat, resourceLon, resource.Name, body) * 100; } } } - } - if (resourceOn && resourceStep < (resourceMapSize / 2)) - { - bool skip = false; - for (int i = resourceInterpolation / 2; i >= 1; i /= 2) + if (resourceStep < (resourceMapSize / 2)) { - if (resourceStep < resourceInterpolation / 2 || resourceStep >= ((resourceMapSize / 2) - (resourceInterpolation / 2))) + bool skip = false; + for (int i = resourceInterpolation / 2; i >= 1; i /= 2) { - SCANuiUtil.interpolate(resourceCache, resourceStep, resourceMapSize, i, i); + if (resourceStep < resourceInterpolation / 2 || resourceStep >= ((resourceMapSize / 2) - (resourceInterpolation / 2))) + { + SCANuiUtil.interpolate(resourceCache, resourceStep, resourceMapSize, i, i, r); + } + else + { + SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, i, i, r); + SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, 0, i, i, r); + SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, 0, i, r); + skip = true; + } } + if (skip) + resourceStep += 4; else - { - SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, i, i); - SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, 0, i, i); - SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, 0, i); - skip = true; - } + resourceStep++; } - if (skip) - resourceStep += 4; - else - resourceStep++; - - SCANUtil.SCANlog("Resource Map Step: {0}", resourceStep); } for (int i = 0; i < map.width; i++) @@ -675,25 +675,6 @@ internal Texture2D getPartialMap() continue; } - //if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) - //{ - // resourceAbundance = SCANuiUtil.resourceMapValue(lon, lat, data, resource); - // if (resourceAbundance >= 0) - // resources = true; - //} - - //if (mType == mapType.Biome && biomeMap) - //{ - // if (SCANcontroller.controller.useStockBiomes && SCANcontroller.controller.colours == 0) - // { - // stockBiome = SCANUtil.getBiome(body, lon, lat).mapColor; - // if (SCANcontroller.controller.biomeBorder) - // bioIndex = SCANUtil.getBiomeIndexFraction(body, lon, lat); - // } - // else - // bioIndex = SCANUtil.getBiomeIndexFraction(body, lon, lat); - //} - switch (mType) { case mapType.Altimetry: @@ -809,8 +790,8 @@ internal Texture2D getPartialMap() if (resourceOn) { float abundance = 0; - double resourceLat = fixUnscale(unScaleLatitude(lat, resourceMapScale), resourceMapSize / 2); - double resourceLon = fixUnscale(unScaleLongitude(lon, resourceMapScale), resourceMapSize); + double resourceLat = fixUnscale(unScaleLatitude(lat), resourceMapSize / 2); + double resourceLon = fixUnscale(unScaleLongitude(lon), resourceMapSize); switch (projection) { case MapProjection.Polar: From 98ba64cd69775123caf9ae06588b7e15ce72c966 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 27 May 2015 16:23:19 -0400 Subject: [PATCH 054/117] Use new settings window for resource options --- SCANsat/SCAN_UI/SCANresourceSettings.cs | 215 ++++++++++++++++++++++++ SCANsat/SCAN_UI/SCANsettingsUI.cs | 72 +------- SCANsat/SCANcontroller.cs | 13 +- 3 files changed, 231 insertions(+), 69 deletions(-) create mode 100644 SCANsat/SCAN_UI/SCANresourceSettings.cs diff --git a/SCANsat/SCAN_UI/SCANresourceSettings.cs b/SCANsat/SCAN_UI/SCANresourceSettings.cs new file mode 100644 index 000000000..30a7c5b5c --- /dev/null +++ b/SCANsat/SCAN_UI/SCANresourceSettings.cs @@ -0,0 +1,215 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SCANsat.SCAN_Data; +using SCANsat.SCAN_UI.UI_Framework; +using SCANsat.SCAN_Platform; +using UnityEngine; +using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette; + +namespace SCANsat.SCAN_UI +{ + class SCANresourceSettings : SCAN_MBW + { + internal readonly static Rect defaultRect = new Rect(300, 200, 400, 300); + private static Rect sessionRect = defaultRect; + private int mapHeight = 256; + private float transparency = 0f; + private int interpolationScale = 8; + private bool popup, warningResource; + private Rect warningRect; + + protected override void Awake() + { + WindowCaption = "S.C.A.N. Resources Settings"; + WindowRect = sessionRect; + WindowStyle = SCANskins.SCAN_window; + WindowOptions = new GUILayoutOption[2] { GUILayout.Width(400), GUILayout.Height(300) }; + Visible = false; + DragEnabled = true; + ClampToScreenOffset = new RectOffset(-200, -200, -200, -200); + + SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); + } + + protected override void DrawWindow(int id) + { + versionLabel(id); /* Standard version label and close button */ + closeBox(id); + + resourceController(id); + resourceSettings(id); + overlayOptions(id); + + warningBox(id); + } + + protected override void DrawWindowPost(int id) + { + if (popup && Event.current.type == EventType.mouseDown && !warningRect.Contains(Event.current.mousePosition)) + { + popup = false; + } + + sessionRect = WindowRect; + } + + //Draw the version label in the upper left corner + private void versionLabel(int id) + { + Rect r = new Rect(4, 0, 50, 18); + GUI.Label(r, SCANmainMenuLoader.SCANsatVersion, SCANskins.SCAN_whiteReadoutLabel); + } + + //Draw the close button in the upper right corner + private void closeBox(int id) + { + Rect r = new Rect(WindowRect.width - 20, 1, 18, 18); + if (GUI.Button(r, SCANcontroller.controller.closeBox, SCANskins.SCAN_closeButton)) + { + Visible = false; + } + } + + private void resourceController(int id) + { + if (SCANcontroller.controller.resourceOverlay == null) + return; + + if (GUILayout.Button("Planetary Overlay Window")) + { + SCANcontroller.controller.resourceOverlay.Visible = !SCANcontroller.controller.resourceOverlay.Visible; + } + } + + private void resourceSettings(int id) + { + GUILayout.Label("Resource Settings", SCANskins.SCAN_headline); + growE(); + SCANcontroller.controller.resourceBiomeLock = GUILayout.Toggle(SCANcontroller.controller.resourceBiomeLock, "Resource Biome Lock", SCANskins.SCAN_settingsToggle); + SCANcontroller.controller.easyModeScanning = GUILayout.Toggle(SCANcontroller.controller.easyModeScanning, "Instant Resource Scan", SCANskins.SCAN_settingsToggle); + stopE(); + growE(); + fillS(); + SCANcontroller.controller.needsNarrowBand = GUILayout.Toggle(SCANcontroller.controller.needsNarrowBand, "Zoom Requires Narrow Band Scanner", SCANskins.SCAN_settingsToggle); + fillS(); + stopE(); + growE(); + fillS(); + SCANcontroller.controller.disableStockResource = GUILayout.Toggle(SCANcontroller.controller.disableStockResource, "Disable Stock Scanning", SCANskins.SCAN_settingsToggle); + fillS(); + stopE(); + if (popup) + { + GUILayout.Label("Reset Resource Coverage", SCANskins.SCAN_button); + } + else + { + if (GUILayout.Button("Reset Resource Coverage")) + { + popup = !popup; + warningResource = !warningResource; + } + } + } + + private void overlayOptions(int id) + { + growE(); + GUILayout.Label("Interpolation:", SCANskins.SCAN_labelSmallLeft); + + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + { + interpolationScale = Math.Max(2, interpolationScale / 2); + refreshMap(); + } + GUILayout.Label(interpolationScale.ToString(), SCANskins.SCAN_labelSmall); + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + { + interpolationScale = Math.Min(32, interpolationScale * 2); + refreshMap(); + } + stopE(); + + growE(); + GUILayout.Label("Map Height:", SCANskins.SCAN_labelSmallLeft); + + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + { + mapHeight = Math.Max(64, mapHeight / 2); + refreshMap(); + } + GUILayout.Label(mapHeight.ToString(), SCANskins.SCAN_labelSmall); + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + { + mapHeight = Math.Min(1024, mapHeight * 2); + refreshMap(); + } + stopE(); + + if (GUILayout.Button("Refresh")) + refreshMap(); + } + + //Confirmation boxes for map resets + private void warningBox(int id) + { + if (popup) + { + if (warningResource) + { + CelestialBody thisBody = null; + switch (HighLogic.LoadedScene) + { + case GameScenes.FLIGHT: + thisBody = FlightGlobals.currentMainBody; + break; + case GameScenes.SPACECENTER: + thisBody = Planetarium.fetch.Home; + break; + case GameScenes.TRACKSTATION: + thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); + break; + default: + thisBody = null; + break; + } + + if (thisBody == null) + { + popup = false; + return; + } + warningRect = new Rect(WindowRect.width - (WindowRect.width / 2) - 150, WindowRect.height - 125, 300, 90); + GUI.Box(warningRect, ""); + Rect r = new Rect(warningRect.x + 10, warningRect.y + 5, 280, 40); + GUI.Label(r, "Erase resource data for " + thisBody.theName + "?", SCANskins.SCAN_headlineSmall); + r.x += 90; + r.y += 45; + r.width = 80; + r.height = 30; + if (GUI.Button(r, "Confirm", SCANskins.SCAN_buttonWarning)) + { + popup = false; + warningResource = false; + SCANdata data = SCANUtil.getData(thisBody); + if (data != null) + data.resetResources(); + } + } + else + popup = false; + } + } + + private void refreshMap() + { + if (SCANcontroller.controller.resourceOverlay == null) + return; + + SCANcontroller.controller.resourceOverlay.refreshMap(transparency, mapHeight, interpolationScale); + } + + + } +} diff --git a/SCANsat/SCAN_UI/SCANsettingsUI.cs b/SCANsat/SCAN_UI/SCANsettingsUI.cs index 9c36baef0..b352e6809 100644 --- a/SCANsat/SCAN_UI/SCANsettingsUI.cs +++ b/SCANsat/SCAN_UI/SCANsettingsUI.cs @@ -39,8 +39,6 @@ class SCANsettingsUI: SCAN_MBW internal readonly static Rect defaultRect = new Rect(Screen.width - (Screen.width / 2) - 180, 100, 360, 300); - private SCANresourceController resourceWindow; - protected override void Awake() { WindowCaption = "S.C.A.N. Settings"; @@ -123,11 +121,11 @@ protected override void DrawWindow(int id) closeBox(id); growS(); + gui_settings_resources(id); /* resource scanning options */ gui_settings_xmarks(id); /* X marker selection */ gui_settings_toggle_body_scanning(id); /* background and body scanning toggles */ gui_settings_timewarp(id); /* time warp resolution settings */ gui_settings_numbers(id); /* sensor/scanning statistics */ - gui_settings_resources(id); /* resource scanning options */ gui_settings_window_resets_tooltips(id);/* reset windows and positions and toggle tooltips*/ gui_settings_data_resets(id); /* reset data and/or reset resources */ # if DEBUG @@ -363,32 +361,12 @@ private void gui_settings_window_resets_tooltips(int id) private void gui_settings_resources(int id) { - GUILayout.Label("Resource Settings", SCANskins.SCAN_headline); - growE(); - SCANcontroller.controller.resourceBiomeLock = GUILayout.Toggle(SCANcontroller.controller.resourceBiomeLock, "Resource Biome Lock", SCANskins.SCAN_settingsToggle); - SCANcontroller.controller.easyModeScanning = GUILayout.Toggle(SCANcontroller.controller.easyModeScanning, "Instant Resource Scan", SCANskins.SCAN_settingsToggle); - stopE(); - growE(); - fillS(); - SCANcontroller.controller.needsNarrowBand = GUILayout.Toggle(SCANcontroller.controller.needsNarrowBand, "Zoom Requires Narrow Band Scanner", SCANskins.SCAN_settingsToggle); - fillS(); - stopE(); - growE(); - fillS(); - SCANcontroller.controller.disableStockResource = GUILayout.Toggle(SCANcontroller.controller.disableStockResource, "Disable Stock Scanning", SCANskins.SCAN_settingsToggle); - fillS(); - stopE(); - if (popup) - { - GUILayout.Label("Reset Resource Coverage", SCANskins.SCAN_button); - } - else + if (SCANcontroller.controller.resourceSettings == null) + return; + + if (GUILayout.Button("Resource Settings Window")) { - if (GUILayout.Button("Reset Resource Coverage")) - { - popup = !popup; - warningResource = !warningResource; - } + SCANcontroller.controller.resourceSettings.Visible = !SCANcontroller.controller.resourceSettings.Visible; } } @@ -505,44 +483,6 @@ private void warningBox(int id) } } } - else if (warningResource) - { - CelestialBody thisBody = null; - switch (HighLogic.LoadedScene) - { - case GameScenes.FLIGHT: - thisBody = FlightGlobals.currentMainBody; - break; - case GameScenes.SPACECENTER: - thisBody = Planetarium.fetch.Home; - break; - case GameScenes.TRACKSTATION: - thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); - break; - default: - thisBody = null; - break; - } - - if (thisBody == null) - return; - warningRect = new Rect(WindowRect.width - (WindowRect.width / 2) - 150, WindowRect.height - 125, 300, 90); - GUI.Box(warningRect, ""); - Rect r = new Rect(warningRect.x + 10, warningRect.y + 5, 280, 40); - GUI.Label(r, "Erase resource data for " + thisBody.theName + "?", SCANskins.SCAN_headlineSmall); - r.x += 90; - r.y += 45; - r.width = 80; - r.height = 30; - if (GUI.Button(r, "Confirm", SCANskins.SCAN_buttonWarning)) - { - popup = false; - warningResource = false; - SCANdata data = SCANUtil.getData(thisBody); - if (data != null) - data.resetResources(); - } - } else popup = false; } diff --git a/SCANsat/SCANcontroller.cs b/SCANsat/SCANcontroller.cs index 49765743a..18eb7da53 100644 --- a/SCANsat/SCANcontroller.cs +++ b/SCANsat/SCANcontroller.cs @@ -159,7 +159,8 @@ public static SCANcontroller controller internal SCANBigMap BigMap; internal SCANkscMap kscMap; internal SCANcolorSelection colorManager; - internal SCANresourceController resourceOverlay; + internal SCANoverlayController resourceOverlay; + internal SCANresourceSettings resourceSettings; /* App launcher object */ internal SCANappLauncher appLauncher; @@ -767,7 +768,8 @@ private void Start() instrumentsWindow = gameObject.AddComponent(); colorManager = gameObject.AddComponent(); BigMap = gameObject.AddComponent(); - resourceOverlay = gameObject.AddComponent(); + resourceOverlay = gameObject.AddComponent(); + resourceSettings = gameObject.AddComponent(); } catch (Exception e) { @@ -784,7 +786,10 @@ private void Start() settingsWindow = gameObject.AddComponent(); colorManager = gameObject.AddComponent(); if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) - resourceOverlay = gameObject.AddComponent(); + { + resourceOverlay = gameObject.AddComponent(); + resourceSettings = gameObject.AddComponent(); + } } catch (Exception e) { @@ -922,6 +927,8 @@ private void OnDestroy() Destroy(BigMap); if (resourceOverlay != null) Destroy(resourceOverlay); + if (resourceSettings != null) + Destroy(resourceSettings); if (appLauncher != null) Destroy(appLauncher); } From f83a552d124a200e0efae0ad32d54286d2d255f6 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 27 May 2015 16:23:33 -0400 Subject: [PATCH 055/117] Change name of overlay window --- SCANsat/SCAN_Toolbar/SCANtoolbar.cs | 2 +- SCANsat/SCAN_UI/SCANoverlayController.cs | 257 +++++++++++++++++++++++ 2 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 SCANsat/SCAN_UI/SCANoverlayController.cs diff --git a/SCANsat/SCAN_Toolbar/SCANtoolbar.cs b/SCANsat/SCAN_Toolbar/SCANtoolbar.cs index af986fa4a..8c56bb6a8 100644 --- a/SCANsat/SCAN_Toolbar/SCANtoolbar.cs +++ b/SCANsat/SCAN_Toolbar/SCANtoolbar.cs @@ -121,7 +121,7 @@ private void createMenu(IButton menu) IButton bigMap = list.AddOption("Big Map"); IButton settings = list.AddOption("Settings"); IButton color = list.AddOption("Color Options"); - IButton resource = list.AddOption("Resource Overlay"); + IButton resource = list.AddOption("Planetary Overlay"); smallMap.OnClick += (e2) => { diff --git a/SCANsat/SCAN_UI/SCANoverlayController.cs b/SCANsat/SCAN_UI/SCANoverlayController.cs new file mode 100644 index 000000000..5ded39a9c --- /dev/null +++ b/SCANsat/SCAN_UI/SCANoverlayController.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SCANsat.SCAN_Data; +using SCANsat.SCAN_UI.UI_Framework; +using SCANsat.SCAN_Platform; +using UnityEngine; +using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette; + +namespace SCANsat.SCAN_UI +{ + class SCANoverlayController : SCAN_MBW + { + internal readonly static Rect defaultRect = new Rect(Screen.width - 280, 200, 200, 300); + private static Rect sessionRect = defaultRect; + private CelestialBody body; + private SCANdata data; + private SCANresourceGlobal currentResource; + private List resources; + private List resourceFractions; + private bool resourceMode = false; + private bool drawOverlay = false; + private bool oldOverlay = false; + + private Texture2D mapOverlay; + private Texture2D biomeOverlay; + private int mapHeight = 256; + private float transparency = 0f; + private int interpolationScale = 8; + + protected override void Awake() + { + WindowCaption = "S.C.A.N. Planet Overlay"; + WindowRect = sessionRect; + WindowStyle = SCANskins.SCAN_window; + WindowOptions = new GUILayoutOption[2] { GUILayout.Width(200), GUILayout.Height(300) }; + Visible = false; + DragEnabled = true; + ClampToScreenOffset = new RectOffset(-200, -200, -40, -40); + + SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); + } + + protected override void Start() + { + resources = SCANcontroller.setLoadedResourceList(); + + setBody(HighLogic.LoadedSceneIsFlight ? FlightGlobals.currentMainBody : Planetarium.fetch.Home); + } + + protected override void Update() + { + if ((MapView.MapIsEnabled && HighLogic.LoadedSceneIsFlight && FlightGlobals.ready) || HighLogic.LoadedScene == GameScenes.TRACKSTATION) + { + CelestialBody mapBody = SCANUtil.getTargetBody(MapView.MapCamera.target); + + if (mapBody == null) + return; + + if (mapBody != body) + setBody(mapBody); + } + else if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready) + { + if (body != FlightGlobals.currentMainBody) + setBody(FlightGlobals.currentMainBody); + } + } + + protected override void OnDestroy() + { + + } + + public bool DrawOverlay + { + get { return resourceMode; } + } + + protected override void DrawWindowPre(int id) + { + + } + + protected override void DrawWindow(int id) + { + versionLabel(id); /* Standard version label and close button */ + closeBox(id); + + drawResourceList(id); + overlayToggle(id); + overlayOptions(id); + } + + protected override void DrawWindowPost(int id) + { + if (oldOverlay != drawOverlay) + { + oldOverlay = drawOverlay; + if (oldOverlay) + refreshMap(); + else + OverlayGenerator.Instance.ClearDisplay(); + } + + sessionRect = WindowRect; + } + + //Draw the version label in the upper left corner + private void versionLabel(int id) + { + Rect r = new Rect(4, 0, 50, 18); + GUI.Label(r, SCANmainMenuLoader.SCANsatVersion, SCANskins.SCAN_whiteReadoutLabel); + } + + //Draw the close button in the upper right corner + private void closeBox(int id) + { + Rect r = new Rect(WindowRect.width - 20, 1, 18, 18); + if (GUI.Button(r, SCANcontroller.controller.closeBox, SCANskins.SCAN_closeButton)) + { + Visible = false; + } + } + + private void drawResourceList(int id) + { + foreach (SCANresourceGlobal r in resources) + { + growE(); + if (GUILayout.Button(r.Name, (r == currentResource && resourceMode) ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) + { + resourceMode = true; + if (currentResource == r) + { + OverlayGenerator.Instance.ClearDisplay(); + oldOverlay = drawOverlay = false; + } + else + { + currentResource = r; + currentResource.CurrentBodyConfig(body.name); + + OverlayGenerator.Instance.ClearDisplay(); + oldOverlay = drawOverlay = true; + refreshMap(); + } + } + + //if (GUILayout.Button(r.CurrentBody.Fraction.ToString("P1"), SCANskins.SCAN_labelRight)) + //{ + // currentResource = r; + // currentResource.CurrentBodyConfig(body.name); + //} + stopE(); + } + + if (GUILayout.Button("Biome Map", (!resourceMode && drawOverlay) ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) + { + resourceMode = false; + oldOverlay = drawOverlay = true; + refreshMap(); + } + } + + private void overlayToggle(int id) + { + drawOverlay = GUILayout.Toggle(drawOverlay, "Draw Overlay", SCANskins.SCAN_settingsToggle); + } + + private void overlayOptions(int id) + { + if (resourceMode) + { + growE(); + GUILayout.Label("Coverage Transparency:", SCANskins.SCAN_labelSmallLeft); + + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + { + transparency = Mathf.Max(0f, transparency - 0.1f); + refreshMap(); + } + GUILayout.Label(transparency.ToString("P0"), SCANskins.SCAN_labelSmall); + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + { + transparency = Mathf.Min(1f, transparency + 0.1f); + refreshMap(); + } + stopE(); + + if (GUILayout.Button("Refresh")) + refreshMap(); + } + } + + public void refreshMap(float t, int height, int interp) + { + transparency = t; + mapHeight = height; + interpolationScale = interp; + if (drawOverlay) + refreshMap(); + } + + private void refreshMap() + { + if (!resourceMode) + body.SetResourceMap(SCANuiUtil.drawBiomeMap(biomeOverlay, data, transparency)); + else + body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapOverlay, mapHeight, data, currentResource, interpolationScale, transparency)); + } + + private void setBody(CelestialBody B) + { + body = B; + data = SCANUtil.getData(body); + if (data == null) + { + data = new SCANdata(body); + SCANcontroller.controller.addToBodyData(body, data); + } + + if (currentResource == null) + { + if (resources.Count > 0) + { + currentResource = resources[0]; + currentResource.CurrentBodyConfig(body.name); + } + } + else + { + currentResource.CurrentBodyConfig(body.name); + } + + if (drawOverlay) + refreshMap(); + + + //resourceFractions = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, body); + //if (resources.Count > 0) + //{ + // currentResource = resources[0]; + // currentResource.CurrentBodyConfig(body.name); + + // //foreach (SCANresourceGlobal r in resources) + // //{ + // // SCANresourceBody b = r.getBodyConfig(body.name, false); + // // if (b != null) + // // { + // // b.Fraction = resourceFractions.FirstOrDefault(a => a.resourceName == r.Name).fraction; + // // } + // //} + //} + } + } +} From 0d8b0a6fbc2188676b1954ee988bc888b2f84ca2 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 27 May 2015 16:23:41 -0400 Subject: [PATCH 056/117] Color32 values --- SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs b/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs index cdc3924dd..bddea87f1 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANpalette.cs @@ -26,6 +26,7 @@ public class SCANpalette // SCANsat) public static Color black = Color.black; public static Color white = Color.white; + public static Color32 White = (Color32)white; public static Color red = Color.red; public static Color grey = Color.grey; public static Color32 Grey = (Color32)grey; From 5fedab03733869b98d35fdd2386359e61e228a4a Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 27 May 2015 16:23:50 -0400 Subject: [PATCH 057/117] biome overlay methods --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index cdf10f733..e95b0813a 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1402,6 +1402,91 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat return map; } + internal static Texture2D drawBiomeMap(Texture2D map, SCANdata data, float transparency, bool useStock = false, bool whiteBorder = false, int height = 256) + { + if (!useStock && !whiteBorder) + return drawBiomeMap(map, data, transparency); + + int width = height * 2; + float scale = (width * 1f) / 360f; + double[] mapline = new double[width]; + Color32[] pix = new Color32[height * width]; + + if (map == null || map.height != height) + { + map = new Texture2D(width, height, TextureFormat.ARGB32, true); + } + + for (int j = 0; j < height; j++) + { + for (int i = 0; i < width; i++) + { + double lon = fixLon(i / scale); + double lat = (j / scale) - 90; + + if (!SCANUtil.isCovered(lon, lat, data, SCANtype.Biome)) + { + pix[j * width + i] = palette.lerp(palette.Clear, palette.Grey, transparency); + continue; + } + + float biomeIndex = (float)SCANUtil.getBiomeIndexFraction(data.Body, lon, lat); + + if (whiteBorder && ((i > 0 && mapline[i - 1] != biomeIndex) || (j > 0 && mapline[i] != biomeIndex))) + { + pix[j * width + i] = palette.White; + } + else if (useStock) + { + pix[j * width + i] = palette.lerp((Color32)SCANUtil.getBiome(data.Body, lon, lat).mapColor, palette.Clear, SCANcontroller.controller.biomeTransparency / 100f); + } + else + { + pix[j * width + i] = palette.lerp(palette.lerp((Color32)SCANcontroller.controller.lowBiomeColor, (Color32)SCANcontroller.controller.highBiomeColor, biomeIndex), palette.Clear, SCANcontroller.controller.biomeTransparency / 100f); + } + } + } + + map.SetPixels32(pix); + map.Apply(); + + return map; + } + + private static Texture2D drawBiomeMap(Texture2D m, SCANdata d, float t) + { + if (d.Body.BiomeMap == null) + return null; + + if (m == null) + { + m = d.Body.BiomeMap.CompileRGBA(); + } + + Color32[] pix = m.GetPixels32(); + float scale = m.width / 360f; + + for (int j = 0; j < m.height; j++) + { + for (int i = 0; i < m.width; i++) + { + double lon = fixLon(i / scale); + double lat = (j / scale) - 90; + + if (!SCANUtil.isCovered(lon, lat, d, SCANtype.Biome)) + { + pix[j * m.width + i] = palette.lerp(palette.Clear, palette.Grey, t); + continue; + } + } + } + + m.SetPixels32(pix); + m.Apply(); + + return m; + } + private static float getLerp(System.Random rand, int l) { if (l == 0) From 07135d596e27c88b92b4ae43e9f7ffe495223d5b Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 27 May 2015 16:24:03 -0400 Subject: [PATCH 058/117] Revert to old resource overlay for now --- SCANsat/SCAN_Map/SCANmap.cs | 183 ++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 90 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index a2541f35e..a5eddb304 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -301,7 +301,7 @@ internal void setSize(int w, int h) pix = new Color[w]; biomeIndex = new double[w]; stockBiomeColor = new Color[w]; - resourceCache = new float[1,1]; + resourceCache = new float[w, h]; mapscale = mapwidth / 360f; if (h <= 0) h = (int)(180 * mapscale); @@ -476,7 +476,7 @@ public void resetMap(mapType mode, bool Cache, bool setRes = true) public void resetResourceMap() { resourceStep = 0; - resourceCache = new float[resourceMapSize, (resourceMapSize / 2)]; + resourceCache = new float[resourceMapSize, resourceMapSize / 2]; } /* MAP: export: PNG file */ @@ -554,6 +554,7 @@ internal Texture2D getPartialMap() palette.redline[i] = palette.red; } + resourceOn = SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null; for (int i = 0; i < map.width; i++) { @@ -562,23 +563,25 @@ internal Texture2D getPartialMap() * Pull altimetry data from cache after unprojection */ + double cacheLat = ((mapstep + 1) * 1.0f / mapscale) - 90f + lat_offset; + double lon = (i * 1.0f / mapscale) - 180f + lon_offset; + if (body.pqsController != null && cache && mapstep + 1 < map.height) { - double cacheLat = ((mapstep + 1) * 1.0f / mapscale) - 90f + lat_offset; - double cacheLon = (i * 1.0f / mapscale) - 180f + lon_offset; - if (big_heightmap[i, mapstep + 1] == 0f) { - if (SCANUtil.isCovered(cacheLon, cacheLat, data, SCANtype.Altimetry)) - terrainHeightToArray(cacheLon, cacheLat, i, mapstep + 1); + if (SCANUtil.isCovered(lon, cacheLat, data, SCANtype.Altimetry)) + terrainHeightToArray(lon, cacheLat, i, mapstep + 1); } } + if (mapstep < 0) + continue; + if (mType != mapType.Biome && biomeMap) continue; double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; - double lon = (i * 1.0f / mapscale) - 180f + lon_offset; double la = lat, lo = lon; lat = unprojectLatitude(lo, la); lon = unprojectLongitude(lo, la); @@ -608,54 +611,54 @@ internal Texture2D getPartialMap() return map; } - if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) - { - resourceOn = true; - if (mapstep < resourceMapSize / (resourceInterpolation * 8)) - { - for (int i = 0; i < resourceMapSize; i++) - { - if (i % resourceInterpolation != 0) - continue; - - double resourceLon = (i * 1.0f / mapscale) - 180f + lon_offset; - int ystep = mapstep * resourceInterpolation * 4; - - for (int j = ystep; j < (4 * resourceInterpolation) + ystep; j++) - { - if (j % resourceInterpolation != 0) - continue; - - double resourceLat = (j * 1.0f / mapscale) - 90f + lat_offset; - - resourceCache[i, j] = SCANUtil.ResourceOverlay(resourceLat, resourceLon, resource.Name, body) * 100; - } - } - } - - if (resourceStep < (resourceMapSize / 2)) - { - bool skip = false; - for (int i = resourceInterpolation / 2; i >= 1; i /= 2) - { - if (resourceStep < resourceInterpolation / 2 || resourceStep >= ((resourceMapSize / 2) - (resourceInterpolation / 2))) - { - SCANuiUtil.interpolate(resourceCache, resourceStep, resourceMapSize, i, i, r); - } - else - { - SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, i, i, r); - SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, 0, i, i, r); - SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, 0, i, r); - skip = true; - } - } - if (skip) - resourceStep += 4; - else - resourceStep++; - } - } + //if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) + //{ + // resourceOn = true; + // if (mapstep < resourceMapSize / (resourceInterpolation * 8)) + // { + // for (int i = 0; i < resourceMapSize; i++) + // { + // if (i % resourceInterpolation != 0) + // continue; + + // double resourceLon = (i * 1.0f / mapscale) - 180f + lon_offset; + // int ystep = mapstep * resourceInterpolation * 4; + + // for (int j = ystep; j < (4 * resourceInterpolation) + ystep; j++) + // { + // if (j % resourceInterpolation != 0) + // continue; + + // double resourceLat = (j * 1.0f / mapscale) - 90f + lat_offset; + + // resourceCache[i, j] = SCANUtil.ResourceOverlay(resourceLat, resourceLon, resource.Name, body) * 100; + // } + // } + // } + + // if (resourceStep < (resourceMapSize / 2)) + // { + // bool skip = false; + // for (int i = resourceInterpolation / 2; i >= 1; i /= 2) + // { + // if (resourceStep < resourceInterpolation / 2 || resourceStep >= ((resourceMapSize / 2) - (resourceInterpolation / 2))) + // { + // SCANuiUtil.interpolate(resourceCache, resourceStep, resourceMapSize, i, i, r); + // } + // else + // { + // SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, i, i, r); + // SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, 0, i, i, r); + // SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, 0, i, r); + // skip = true; + // } + // } + // if (skip) + // resourceStep += 4; + // else + // resourceStep++; + // } + //} for (int i = 0; i < map.width; i++) { @@ -789,40 +792,40 @@ internal Texture2D getPartialMap() if (resourceOn) { - float abundance = 0; - double resourceLat = fixUnscale(unScaleLatitude(lat), resourceMapSize / 2); - double resourceLon = fixUnscale(unScaleLongitude(lon), resourceMapSize); - switch (projection) - { - case MapProjection.Polar: - { - if ((lat <= 6 && lat >= 0) || (lat >= -6 && lat <=0)) - { - - } - //else if (lat >= 87 || lat <= -87) - //{ - - //} - else - { - abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)]; - } - break; - } - default: - { - if (lat <= -85 || lat >= 85) - { - - } - else - { - abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)]; - } - break; - } - } + float abundance = SCANUtil.ResourceOverlay(lat, lon, resource.Name, body) * 100; + //double resourceLat = fixUnscale(unScaleLatitude(lat), resourceMapSize / 2); + //double resourceLon = fixUnscale(unScaleLongitude(lon), resourceMapSize); + //switch (projection) + //{ + // case MapProjection.Polar: + // { + // if ((lat <= 6 && lat >= 0) || (lat >= -6 && lat <=0)) + // { + + // } + // //else if (lat >= 87 || lat <= -87) + // //{ + + // //} + // else + // { + // abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)]; + // } + // break; + // } + // default: + // { + // if (lat <= -85 || lat >= 85) + // { + + // } + // else + // { + // abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)]; + // } + // break; + // } + //} pix[i] = SCANuiUtil.resourceToColor(baseColor, resource, abundance, data, lon, lat); } else From dd3c5f8d75b19e7fd679f0a828179069f72bf5be Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 27 May 2015 23:53:36 -0400 Subject: [PATCH 059/117] renamed --- SCANsat/SCAN_UI/SCANresourceController.cs | 262 ---------------------- 1 file changed, 262 deletions(-) delete mode 100644 SCANsat/SCAN_UI/SCANresourceController.cs diff --git a/SCANsat/SCAN_UI/SCANresourceController.cs b/SCANsat/SCAN_UI/SCANresourceController.cs deleted file mode 100644 index 74b779be6..000000000 --- a/SCANsat/SCAN_UI/SCANresourceController.cs +++ /dev/null @@ -1,262 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using SCANsat.SCAN_Data; -using SCANsat.SCAN_UI.UI_Framework; -using SCANsat.SCAN_Platform; -using UnityEngine; -using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette; - -namespace SCANsat.SCAN_UI -{ - class SCANresourceController : SCAN_MBW - { - internal readonly static Rect defaultRect = new Rect(Screen.width - 280, 200, 200, 300); - private static Rect sessionRect = defaultRect; - private CelestialBody body; - private SCANdata data; - private SCANresourceGlobal currentResource; - private List resources; - private List resourceFractions; - private bool drawResourceOverlay = false; - private bool oldOverlay = false; - - private Texture2D mapOverlay; - private int mapHeight = 256; - private float transparency = 0f; - private int interpolationScale = 8; - - protected override void Awake() - { - WindowCaption = "S.C.A.N. Resources"; - WindowRect = sessionRect; - WindowStyle = SCANskins.SCAN_window; - WindowOptions = new GUILayoutOption[2] { GUILayout.Width(200), GUILayout.Height(300) }; - Visible = false; - DragEnabled = true; - ClampToScreenOffset = new RectOffset(-200, -200, -40, -40); - - SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); - } - - protected override void Start() - { - resources = SCANcontroller.setLoadedResourceList(); - - setBody(HighLogic.LoadedSceneIsFlight ? FlightGlobals.currentMainBody : Planetarium.fetch.Home); - } - - protected override void Update() - { - if ((MapView.MapIsEnabled && HighLogic.LoadedSceneIsFlight && FlightGlobals.ready) || HighLogic.LoadedScene == GameScenes.TRACKSTATION) - { - CelestialBody mapBody = SCANUtil.getTargetBody(MapView.MapCamera.target); - - if (mapBody == null) - return; - - if (mapBody != body) - setBody(mapBody); - } - else if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready) - { - if (body != FlightGlobals.currentMainBody) - setBody(FlightGlobals.currentMainBody); - } - } - - protected override void OnDestroy() - { - - } - - protected override void DrawWindowPre(int id) - { - - } - - protected override void DrawWindow(int id) - { - versionLabel(id); /* Standard version label and close button */ - closeBox(id); - - drawResourceList(id); - overlayToggle(id); - overlayOptions(id); - } - - protected override void DrawWindowPost(int id) - { - if (oldOverlay != drawResourceOverlay) - { - oldOverlay = drawResourceOverlay; - if (oldOverlay) - refreshMap(); - else - OverlayGenerator.Instance.ClearDisplay(); - } - - sessionRect = WindowRect; - } - - //Draw the version label in the upper left corner - private void versionLabel(int id) - { - Rect r = new Rect(4, 0, 50, 18); - GUI.Label(r, SCANmainMenuLoader.SCANsatVersion, SCANskins.SCAN_whiteReadoutLabel); - } - - //Draw the close button in the upper right corner - private void closeBox(int id) - { - Rect r = new Rect(WindowRect.width - 20, 1, 18, 18); - if (GUI.Button(r, SCANcontroller.controller.closeBox, SCANskins.SCAN_closeButton)) - { - Visible = false; - } - } - - private void drawResourceList(int id) - { - foreach (SCANresourceGlobal r in resources) - { - growE(); - if (GUILayout.Button(r.Name, r == currentResource ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) - { - if (currentResource == r) - { - OverlayGenerator.Instance.ClearDisplay(); - oldOverlay = drawResourceOverlay = false; - } - else - { - currentResource = r; - currentResource.CurrentBodyConfig(body.name); - - OverlayGenerator.Instance.ClearDisplay(); - refreshMap(); - oldOverlay = drawResourceOverlay = true; - } - } - - //if (GUILayout.Button(r.CurrentBody.Fraction.ToString("P1"), SCANskins.SCAN_labelRight)) - //{ - // currentResource = r; - // currentResource.CurrentBodyConfig(body.name); - //} - stopE(); - } - } - - private void overlayToggle(int id) - { - drawResourceOverlay = GUILayout.Toggle(drawResourceOverlay, "Draw Overlay", SCANskins.SCAN_settingsToggle); - } - - private void overlayOptions(int id) - { - if (drawResourceOverlay) - { - growE(); - GUILayout.Label("Coverage Transparency:", SCANskins.SCAN_labelSmallLeft); - - if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) - { - transparency = Mathf.Max(0f, transparency - 0.1f); - refreshMap(); - } - GUILayout.Label(transparency.ToString("P0"), SCANskins.SCAN_labelSmall); - if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) - { - transparency = Mathf.Min(1f, transparency + 0.1f); - refreshMap(); - } - stopE(); - - growE(); - GUILayout.Label("Interpolation:", SCANskins.SCAN_labelSmallLeft); - - if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) - { - interpolationScale = Math.Max(2, interpolationScale / 2); - refreshMap(); - } - GUILayout.Label(interpolationScale.ToString(), SCANskins.SCAN_labelSmall); - if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) - { - interpolationScale = Math.Min(32, interpolationScale * 2); - refreshMap(); - } - stopE(); - - growE(); - GUILayout.Label("Map Height:", SCANskins.SCAN_labelSmallLeft); - - if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) - { - mapHeight = Math.Max(64, mapHeight / 2); - refreshMap(); - } - GUILayout.Label(mapHeight.ToString(), SCANskins.SCAN_labelSmall); - if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) - { - mapHeight = Math.Min(1024, mapHeight * 2); - refreshMap(); - } - stopE(); - - if (GUILayout.Button("Refresh")) - refreshMap(); - } - } - - private void refreshMap() - { - body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapOverlay, mapHeight, data, currentResource, interpolationScale, transparency)); - } - - private void setBody(CelestialBody B) - { - body = B; - data = SCANUtil.getData(body); - if (data == null) - { - data = new SCANdata(body); - SCANcontroller.controller.addToBodyData(body, data); - } - - if (currentResource == null) - { - if (resources.Count > 0) - { - currentResource = resources[0]; - currentResource.CurrentBodyConfig(body.name); - } - } - else - { - currentResource.CurrentBodyConfig(body.name); - } - - if (drawResourceOverlay) - refreshMap(); - - - //resourceFractions = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, body); - //if (resources.Count > 0) - //{ - // currentResource = resources[0]; - // currentResource.CurrentBodyConfig(body.name); - - // //foreach (SCANresourceGlobal r in resources) - // //{ - // // SCANresourceBody b = r.getBodyConfig(body.name, false); - // // if (b != null) - // // { - // // b.Fraction = resourceFractions.FirstOrDefault(a => a.resourceName == r.Name).fraction; - // // } - // //} - //} - } - } -} From c40d10e55da9a425d16b55f9ccba5ae0f0d93ad1 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 27 May 2015 23:53:41 -0400 Subject: [PATCH 060/117] new classes --- SCANsat/SCANsat.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SCANsat/SCANsat.csproj b/SCANsat/SCANsat.csproj index add2fcb37..acd2340e6 100644 --- a/SCANsat/SCANsat.csproj +++ b/SCANsat/SCANsat.csproj @@ -92,7 +92,8 @@ - + + From 12d2ba02c0b064e314925c8d4627a0abcb08ea8f Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 27 May 2015 23:54:32 -0400 Subject: [PATCH 061/117] Fix biome overlays --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index e95b0813a..54a588a9b 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1460,10 +1460,11 @@ private static Texture2D drawBiomeMap(Texture2D m, SCANdata d, float t) if (m == null) { - m = d.Body.BiomeMap.CompileRGBA(); + m = new Texture2D(1024, 512, TextureFormat.RGBA32, true); + SCANUtil.SCANlog("Map Width: {0}; Size: {1}; BPP: {2}; Depth: {3}; Map Name: {4}", d.Body.BiomeMap.Width, d.Body.BiomeMap.SizeString, d.Body.BiomeMap.BitsPerPixel, d.Body.BiomeMap.Depth, d.Body.BiomeMap.MapName); } - Color32[] pix = m.GetPixels32(); + Color32[] pix = new Color32[m.width * m.height]; float scale = m.width / 360f; for (int j = 0; j < m.height; j++) @@ -1473,11 +1474,12 @@ private static Texture2D drawBiomeMap(Texture2D m, SCANdata d, float t) double lon = fixLon(i / scale); double lat = (j / scale) - 90; - if (!SCANUtil.isCovered(lon, lat, d, SCANtype.Biome)) - { - pix[j * m.width + i] = palette.lerp(palette.Clear, palette.Grey, t); - continue; - } + Color32 c = palette.Clear; + + if (SCANUtil.isCovered(lon, lat, d, SCANtype.Biome)) + c = (Color32)SCANUtil.getBiome(d.Body, lon, lat).mapColor;//, palette.clear, SCANcontroller.controller.biomeTransparency / 100); + + pix[j *m.width + i] = c; } } From e112304f79e1ae201af82d2b70070da2e7e863f1 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 28 May 2015 14:08:10 -0400 Subject: [PATCH 062/117] Allow changes to biome map size --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 54a588a9b..70cca7e55 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1385,7 +1385,7 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat abundanceValues[i, j] = SCANUtil.ResourceOverlay(lat, lon, resource.Name, data.Body) * 100; - pix[j * width + i] = resourceToColor(palette.Clear, resource, abundanceValues[i, j], data, lon, lat, transparency); + pix[j * width + i] = resourceToColor32(palette.Clear, resource, abundanceValues[i, j], data, lon, lat, transparency); } } @@ -1402,10 +1402,10 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat return map; } - internal static Texture2D drawBiomeMap(Texture2D map, SCANdata data, float transparency, bool useStock = false, bool whiteBorder = false, int height = 256) + internal static Texture2D drawBiomeMap(Texture2D map, SCANdata data, float transparency, int height = 256, bool useStock = false, bool whiteBorder = false) { if (!useStock && !whiteBorder) - return drawBiomeMap(map, data, transparency); + return drawBiomeMap(map, data, transparency, height); int width = height * 2; float scale = (width * 1f) / 360f; @@ -1453,15 +1453,14 @@ internal static Texture2D drawBiomeMap(Texture2D map, SCANdata data, float trans return map; } - private static Texture2D drawBiomeMap(Texture2D m, SCANdata d, float t) + private static Texture2D drawBiomeMap(Texture2D m, SCANdata d, float t, int h) { if (d.Body.BiomeMap == null) return null; if (m == null) { - m = new Texture2D(1024, 512, TextureFormat.RGBA32, true); - SCANUtil.SCANlog("Map Width: {0}; Size: {1}; BPP: {2}; Depth: {3}; Map Name: {4}", d.Body.BiomeMap.Width, d.Body.BiomeMap.SizeString, d.Body.BiomeMap.BitsPerPixel, d.Body.BiomeMap.Depth, d.Body.BiomeMap.MapName); + m = new Texture2D(h * 2, h, TextureFormat.RGBA32, true); } Color32[] pix = new Color32[m.width * m.height]; @@ -1542,7 +1541,7 @@ private static void interpolate(Color32[] c, float[,] v, int height, int x, int v[i, j] = avgFinal; - c[j * width + i] = resourceToColor(palette.Clear, r, v[i, j], d, lon, lat, t); + c[j * width + i] = resourceToColor32(palette.Clear, r, v[i, j], d, lon, lat, t); } } } @@ -1647,7 +1646,7 @@ internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resour return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); } - private static Color32 resourceToColor(Color32 BaseColor, SCANresourceGlobal Resource, float Abundance, SCANdata Data, double Lon, double Lat, float Transparency = 0.3f) + private static Color32 resourceToColor32(Color32 BaseColor, SCANresourceGlobal Resource, float Abundance, SCANdata Data, double Lon, double Lat, float Transparency = 0.3f) { if (SCANUtil.isCovered(Lon, Lat, Data, Resource.SType)) { From 902ae9d3ba5df3db44043140b6a85f2c9b75c54f Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 28 May 2015 14:08:43 -0400 Subject: [PATCH 063/117] Unused code; consolidate celestial body id --- SCANsat/SCAN_UI/SCANsettingsUI.cs | 73 ++++++++++--------------------- 1 file changed, 23 insertions(+), 50 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANsettingsUI.cs b/SCANsat/SCAN_UI/SCANsettingsUI.cs index b352e6809..d4e87e74c 100644 --- a/SCANsat/SCAN_UI/SCANsettingsUI.cs +++ b/SCANsat/SCAN_UI/SCANsettingsUI.cs @@ -32,7 +32,7 @@ class SCANsettingsUI: SCAN_MBW /* UI: time warp names and settings */ private string[] twnames = { "Off", "Low", "Medium", "High" }; private int[] twvals = { 1, 6, 9, 15 }; - private bool popup, warningResource, warningBoxOne, warningBoxAll, controlLock; + private bool popup, warningBoxOne, warningBoxAll, controlLock; private Rect warningRect; private const string lockID = "settingLockID"; private bool oldTooltips, stockToolbar; @@ -111,7 +111,6 @@ protected override void DrawWindowPre(int id) { warningBoxOne = false; warningBoxAll = false; - warningResource = false; } } @@ -275,22 +274,7 @@ private void gui_settings_numbers(int id) //Reset databases private void gui_settings_data_resets(int id) { - CelestialBody thisBody = null; - switch (HighLogic.LoadedScene) - { - case GameScenes.FLIGHT: - thisBody = FlightGlobals.currentMainBody; - break; - case GameScenes.SPACECENTER: - thisBody = Planetarium.fetch.Home; - break; - case GameScenes.TRACKSTATION: - thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); - break; - default: - thisBody = null; - break; - } + CelestialBody thisBody = getTargetBody(); if (thisBody == null) return; @@ -374,22 +358,7 @@ private void gui_settings_resources(int id) private void gui_settings_window_mapFill(int id) { growE(); - CelestialBody thisBody = null; - switch (HighLogic.LoadedScene) - { - case GameScenes.FLIGHT: - thisBody = FlightGlobals.currentMainBody; - break; - case GameScenes.SPACECENTER: - thisBody = Planetarium.fetch.Home; - break; - case GameScenes.TRACKSTATION: - thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); - break; - default: - thisBody = null; - break; - } + CelestialBody thisBody = getTargetBody(); if (thisBody == null) return; @@ -427,25 +396,14 @@ private void warningBox(int id) { if (warningBoxOne) { - CelestialBody thisBody = null; - switch (HighLogic.LoadedScene) - { - case GameScenes.FLIGHT: - thisBody = FlightGlobals.currentMainBody; - break; - case GameScenes.SPACECENTER: - thisBody = Planetarium.fetch.Home; - break; - case GameScenes.TRACKSTATION: - thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); - break; - default: - thisBody = null; - break; - } + CelestialBody thisBody = getTargetBody(); if (thisBody == null) + { + popup = false; return; + } + warningRect = new Rect(WindowRect.width - (WindowRect.width / 2) - 150, WindowRect.height - 125, 300, 90); GUI.Box(warningRect, ""); Rect r = new Rect(warningRect.x + 10, warningRect.y + 5, 280, 40); @@ -488,5 +446,20 @@ private void warningBox(int id) } } + private CelestialBody getTargetBody() + { + switch (HighLogic.LoadedScene) + { + case GameScenes.FLIGHT: + return FlightGlobals.currentMainBody; + case GameScenes.SPACECENTER: + return Planetarium.fetch.Home; + case GameScenes.TRACKSTATION: + return SCANUtil.getTargetBody(MapView.MapCamera.target); + default: + return null; + } + } + } } From f7d557d25ae11b8d593c799aa1e84841bc226f30 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 28 May 2015 14:09:10 -0400 Subject: [PATCH 064/117] Some tweaks; maybe allow reset of stock resource scanning --- SCANsat/SCAN_UI/SCANresourceSettings.cs | 123 ++++++++++++++++++++---- 1 file changed, 106 insertions(+), 17 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANresourceSettings.cs b/SCANsat/SCAN_UI/SCANresourceSettings.cs index 30a7c5b5c..94bb5fb21 100644 --- a/SCANsat/SCAN_UI/SCANresourceSettings.cs +++ b/SCANsat/SCAN_UI/SCANresourceSettings.cs @@ -16,7 +16,8 @@ class SCANresourceSettings : SCAN_MBW private int mapHeight = 256; private float transparency = 0f; private int interpolationScale = 8; - private bool popup, warningResource; + private bool popup, warningResource, warningStockResource, controlLock; + private const string lockID = "resourceSettingLockID"; private Rect warningRect; protected override void Awake() @@ -32,6 +33,54 @@ protected override void Awake() SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); } + internal void removeControlLocks() + { + InputLockManager.RemoveControlLock(lockID); + controlLock = false; + } + + protected override void DrawWindowPre(int id) + { + //Lock space center click through + if (HighLogic.LoadedScene == GameScenes.SPACECENTER) + { + Vector2 mousePos = Input.mousePosition; + mousePos.y = Screen.height - mousePos.y; + if (WindowRect.Contains(mousePos) && !controlLock) + { + InputLockManager.SetControlLock(ControlTypes.CAMERACONTROLS | ControlTypes.KSC_ALL, lockID); + controlLock = true; + } + else if (!WindowRect.Contains(mousePos) && controlLock) + { + removeControlLocks(); + } + } + + //Lock tracking scene click through + if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) + { + Vector2 mousePos = Input.mousePosition; + mousePos.y = Screen.height - mousePos.y; + if (WindowRect.Contains(mousePos) && !controlLock) + { + InputLockManager.SetControlLock(ControlTypes.TRACKINGSTATION_UI, lockID); + controlLock = true; + } + else if (!WindowRect.Contains(mousePos) && controlLock) + { + InputLockManager.RemoveControlLock(lockID); + controlLock = false; + } + } + + if (!popup) + { + warningResource = false; + warningStockResource = false; + } + } + protected override void DrawWindow(int id) { versionLabel(id); /* Standard version label and close button */ @@ -102,6 +151,11 @@ private void resourceSettings(int id) if (popup) { GUILayout.Label("Reset Resource Coverage", SCANskins.SCAN_button); + if (SCANcontroller.controller.disableStockResource) + { + fillS(8); + GUILayout.Label("Reset Stock Resource Scanning", SCANskins.SCAN_button); + } } else { @@ -110,6 +164,15 @@ private void resourceSettings(int id) popup = !popup; warningResource = !warningResource; } + if (SCANcontroller.controller.disableStockResource) + { + fillS(8); + if (GUILayout.Button("Reset Stock Resource Scanning")) + { + popup = !popup; + warningStockResource = !warningStockResource; + } + } } } @@ -158,22 +221,7 @@ private void warningBox(int id) { if (warningResource) { - CelestialBody thisBody = null; - switch (HighLogic.LoadedScene) - { - case GameScenes.FLIGHT: - thisBody = FlightGlobals.currentMainBody; - break; - case GameScenes.SPACECENTER: - thisBody = Planetarium.fetch.Home; - break; - case GameScenes.TRACKSTATION: - thisBody = SCANUtil.getTargetBody(MapView.MapCamera.target); - break; - default: - thisBody = null; - break; - } + CelestialBody thisBody = getTargetBody(); if (thisBody == null) { @@ -197,6 +245,32 @@ private void warningBox(int id) data.resetResources(); } } + else if (warningStockResource) + { + CelestialBody thisBody = getTargetBody(); + + if (thisBody == null) + { + popup = false; + return; + } + + warningRect = new Rect(WindowRect.width - (WindowRect.width / 2) - 150, WindowRect.height - 125, 300, 90); + GUI.Box(warningRect, ""); + Rect r = new Rect(warningRect.x + 10, warningRect.y + 5, 280, 40); + GUI.Label(r, "Erase stock resource data for " + thisBody.theName + "?", SCANskins.SCAN_headlineSmall); + r.x += 90; + r.y += 45; + r.width = 80; + r.height = 30; + if (GUI.Button(r, "Confirm", SCANskins.SCAN_buttonWarning)) + { + popup = false; + warningStockResource = false; + var resources = ResourceScenario.Instance.gameSettings.GetPlanetScanInfo(); + resources.RemoveAll(a => a.PlanetId == thisBody.flightGlobalsIndex); + } + } else popup = false; } @@ -210,6 +284,21 @@ private void refreshMap() SCANcontroller.controller.resourceOverlay.refreshMap(transparency, mapHeight, interpolationScale); } + private CelestialBody getTargetBody() + { + switch (HighLogic.LoadedScene) + { + case GameScenes.FLIGHT: + return FlightGlobals.currentMainBody; + case GameScenes.SPACECENTER: + return Planetarium.fetch.Home; + case GameScenes.TRACKSTATION: + return SCANUtil.getTargetBody(MapView.MapCamera.target); + default: + return null; + } + } + } } From bf80eeaafed66333bfae078eb1bd33a0aadd0455 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 28 May 2015 14:09:28 -0400 Subject: [PATCH 065/117] Lots of UI tweaks --- SCANsat/SCAN_UI/SCANoverlayController.cs | 71 ++++++++++++------------ 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANoverlayController.cs b/SCANsat/SCAN_UI/SCANoverlayController.cs index 5ded39a9c..7c90e7c8a 100644 --- a/SCANsat/SCAN_UI/SCANoverlayController.cs +++ b/SCANsat/SCAN_UI/SCANoverlayController.cs @@ -11,16 +11,17 @@ namespace SCANsat.SCAN_UI { class SCANoverlayController : SCAN_MBW { - internal readonly static Rect defaultRect = new Rect(Screen.width - 280, 200, 200, 300); + internal readonly static Rect defaultRect = new Rect(Screen.width - 280, 200, 200, 260); private static Rect sessionRect = defaultRect; private CelestialBody body; private SCANdata data; private SCANresourceGlobal currentResource; private List resources; private List resourceFractions; - private bool resourceMode = false; + private bool biomeMode = false; private bool drawOverlay = false; private bool oldOverlay = false; + private int selection; private Texture2D mapOverlay; private Texture2D biomeOverlay; @@ -30,13 +31,13 @@ class SCANoverlayController : SCAN_MBW protected override void Awake() { - WindowCaption = "S.C.A.N. Planet Overlay"; + WindowCaption = "S.C.A.N. Overlay"; WindowRect = sessionRect; WindowStyle = SCANskins.SCAN_window; - WindowOptions = new GUILayoutOption[2] { GUILayout.Width(200), GUILayout.Height(300) }; + WindowOptions = new GUILayoutOption[2] { GUILayout.Width(200), GUILayout.Height(260) }; Visible = false; DragEnabled = true; - ClampToScreenOffset = new RectOffset(-200, -200, -40, -40); + ClampToScreenOffset = new RectOffset(-140, -140, -200, -200); SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); } @@ -74,7 +75,7 @@ protected override void OnDestroy() public bool DrawOverlay { - get { return resourceMode; } + get { return drawOverlay; } } protected override void DrawWindowPre(int id) @@ -125,41 +126,40 @@ private void closeBox(int id) private void drawResourceList(int id) { - foreach (SCANresourceGlobal r in resources) + for (int i = 0; i < resources.Count; i++) { - growE(); - if (GUILayout.Button(r.Name, (r == currentResource && resourceMode) ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) + SCANresourceGlobal r = resources[i]; + + if (r == null) + continue; + + if (GUILayout.Button(r.Name, selection == i ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) { - resourceMode = true; - if (currentResource == r) - { - OverlayGenerator.Instance.ClearDisplay(); - oldOverlay = drawOverlay = false; - } - else + biomeMode = false; + oldOverlay = drawOverlay = !drawOverlay; + OverlayGenerator.Instance.ClearDisplay(); + if (selection != i) { + selection = i; currentResource = r; currentResource.CurrentBodyConfig(body.name); OverlayGenerator.Instance.ClearDisplay(); - oldOverlay = drawOverlay = true; refreshMap(); } } - - //if (GUILayout.Button(r.CurrentBody.Fraction.ToString("P1"), SCANskins.SCAN_labelRight)) - //{ - // currentResource = r; - // currentResource.CurrentBodyConfig(body.name); - //} - stopE(); } - if (GUILayout.Button("Biome Map", (!resourceMode && drawOverlay) ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) + if (GUILayout.Button("Biome Map", selection == (resources.Count) ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) { - resourceMode = false; - oldOverlay = drawOverlay = true; - refreshMap(); + biomeMode = true; + oldOverlay = drawOverlay = !drawOverlay; + OverlayGenerator.Instance.ClearDisplay(); + if (selection != resources.Count) + { + selection = resources.Count; + refreshMap(); + } } } @@ -170,7 +170,13 @@ private void overlayToggle(int id) private void overlayOptions(int id) { - if (resourceMode) + if (!drawOverlay) + return; + + if (GUILayout.Button("Refresh")) + refreshMap(); + + if (!biomeMode) { growE(); GUILayout.Label("Coverage Transparency:", SCANskins.SCAN_labelSmallLeft); @@ -187,9 +193,6 @@ private void overlayOptions(int id) refreshMap(); } stopE(); - - if (GUILayout.Button("Refresh")) - refreshMap(); } } @@ -204,8 +207,8 @@ public void refreshMap(float t, int height, int interp) private void refreshMap() { - if (!resourceMode) - body.SetResourceMap(SCANuiUtil.drawBiomeMap(biomeOverlay, data, transparency)); + if (biomeMode) + body.SetResourceMap(SCANuiUtil.drawBiomeMap(biomeOverlay, data, transparency, mapHeight * 2)); else body.SetResourceMap(SCANuiUtil.drawResourceTexture(mapOverlay, mapHeight, data, currentResource, interpolationScale, transparency)); } From 0991111e30c5ca04f907144a57bece03dfa5978a Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 28 May 2015 22:23:05 -0400 Subject: [PATCH 066/117] Resource and biome buttons respond correctly --- SCANsat/SCAN_UI/SCANoverlayController.cs | 31 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANoverlayController.cs b/SCANsat/SCAN_UI/SCANoverlayController.cs index 7c90e7c8a..df1d6e5e7 100644 --- a/SCANsat/SCAN_UI/SCANoverlayController.cs +++ b/SCANsat/SCAN_UI/SCANoverlayController.cs @@ -136,28 +136,53 @@ private void drawResourceList(int id) if (GUILayout.Button(r.Name, selection == i ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) { biomeMode = false; - oldOverlay = drawOverlay = !drawOverlay; OverlayGenerator.Instance.ClearDisplay(); + if (selection != i) { selection = i; currentResource = r; currentResource.CurrentBodyConfig(body.name); + oldOverlay = drawOverlay = true; + refreshMap(); + return; + } - OverlayGenerator.Instance.ClearDisplay(); + if (drawOverlay) + { + oldOverlay = drawOverlay = false; + } + else + { + oldOverlay = drawOverlay = true; refreshMap(); } + + } } if (GUILayout.Button("Biome Map", selection == (resources.Count) ? SCANskins.SCAN_labelLeftActive : SCANskins.SCAN_labelLeft)) { biomeMode = true; - oldOverlay = drawOverlay = !drawOverlay; + OverlayGenerator.Instance.ClearDisplay(); + if (selection != resources.Count) { selection = resources.Count; + oldOverlay = drawOverlay = true; + refreshMap(); + return; + } + + if (drawOverlay) + { + oldOverlay = drawOverlay = false; + } + else + { + oldOverlay = drawOverlay = true; refreshMap(); } } From beb602801f540073252159a4dc8e7fbf92850645 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 28 May 2015 22:23:12 -0400 Subject: [PATCH 067/117] UI tweaks --- SCANsat/SCAN_UI/SCANresourceSettings.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANresourceSettings.cs b/SCANsat/SCAN_UI/SCANresourceSettings.cs index 94bb5fb21..482179f32 100644 --- a/SCANsat/SCAN_UI/SCANresourceSettings.cs +++ b/SCANsat/SCAN_UI/SCANresourceSettings.cs @@ -209,9 +209,6 @@ private void overlayOptions(int id) refreshMap(); } stopE(); - - if (GUILayout.Button("Refresh")) - refreshMap(); } //Confirmation boxes for map resets @@ -255,12 +252,12 @@ private void warningBox(int id) return; } - warningRect = new Rect(WindowRect.width - (WindowRect.width / 2) - 150, WindowRect.height - 125, 300, 90); + warningRect = new Rect(WindowRect.width - (WindowRect.width / 2) - 150, WindowRect.height - 125, 300, 110); GUI.Box(warningRect, ""); - Rect r = new Rect(warningRect.x + 10, warningRect.y + 5, 280, 40); + Rect r = new Rect(warningRect.x + 10, warningRect.y + 5, 280, 60); GUI.Label(r, "Erase stock resource data for " + thisBody.theName + "?", SCANskins.SCAN_headlineSmall); r.x += 90; - r.y += 45; + r.y += 65; r.width = 80; r.height = 30; if (GUI.Button(r, "Confirm", SCANskins.SCAN_buttonWarning)) @@ -268,7 +265,13 @@ private void warningBox(int id) popup = false; warningStockResource = false; var resources = ResourceScenario.Instance.gameSettings.GetPlanetScanInfo(); + for (int i = 0; i < resources.Count; i++) + { + if (resources[i].PlanetId == thisBody.flightGlobalsIndex) + SCANUtil.SCANlog("Removing Stock Resource Value"); + } resources.RemoveAll(a => a.PlanetId == thisBody.flightGlobalsIndex); + } } else From 8c8ac7d122f7ba5617dc44ed1091e4f5ec213d61 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 28 May 2015 22:23:25 -0400 Subject: [PATCH 068/117] Try to fix resource scanners --- SCANsat/SCANresourceScanner.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SCANsat/SCANresourceScanner.cs b/SCANsat/SCANresourceScanner.cs index fa97a1b05..4e514eafc 100644 --- a/SCANsat/SCANresourceScanner.cs +++ b/SCANsat/SCANresourceScanner.cs @@ -73,16 +73,14 @@ private ModuleAnimationGroup findAnimator() private void updateEvents() { - base.Events["startScan"].active = !scanning; - base.Events["stopScan"].active = scanning; + base.Events["startScan"].active = !scanning && activated; + base.Events["stopScan"].active = scanning && activated; } public void Update() { - if (!activated) - return; - - base.OnUpdate(); + if (activated) + base.OnUpdate(); if (!HighLogic.LoadedSceneIsFlight) return; From 562360e77e1862eed1289cdddc1837f551524916 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 30 May 2015 15:08:27 -0400 Subject: [PATCH 069/117] Fix map SCANdata object not getting updated --- SCANsat/SCAN_Map/SCANmap.cs | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index a5eddb304..08b524c2e 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -118,7 +118,6 @@ public MapProjection Projection /* MAP: Big Map height map caching */ private float[,] big_heightmap; - private CelestialBody big_heightmap_body; private bool cache; private double centeredLong, centeredLat; @@ -335,7 +334,6 @@ internal void setWidth(int w) mapheight = (int)(w / 2); /* big map caching */ big_heightmap = new float[mapwidth, mapheight]; - big_heightmap_body = body; map = null; resetMap(); } @@ -428,12 +426,21 @@ private double fixUnscale(double value, int size) /* MAP: nearly trivial functions */ public void setBody(CelestialBody b) { - if (body == b) - return; body = b; pqs = body.pqsController != null; biomeMap = body.BiomeMap != null; data = SCANUtil.getData(body); + + /* init cache if necessary */ + if (cache) + { + for (int x = 0; x < mapwidth; x++) + { + for (int y = 0; y < mapwidth / 2; y++) + big_heightmap[x, y] = 0f; + } + } + if (SCANconfigLoader.GlobalResource) { resource = SCANcontroller.getResourceNode(SCANcontroller.controller.resourceSelection); @@ -520,20 +527,6 @@ internal Texture2D getPartialMap() bool resourceOn = false; - /* init cache if necessary */ - if (cache) - { - if (body != big_heightmap_body) - { - for (int x = 0; x < mapwidth; x++) - { - for (int y = 0; y < mapwidth / 2; y++) - big_heightmap[x, y] = 0f; - } - big_heightmap_body = body; - } - } - if (map == null) { map = new Texture2D(mapwidth, mapheight, TextureFormat.ARGB32, false); From 0c7e7aae91c363f2d2297e9f3a914894493fa03d Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 1 Jun 2015 20:54:32 -0400 Subject: [PATCH 070/117] New icon for overlay control --- SCANassets/Icons/SCAN_Overlay_Icon.dds | Bin 0 -> 1152 bytes SCANsat/SCAN_UI/UI_Framework/SCANskins.cs | 2 ++ 2 files changed, 2 insertions(+) create mode 100644 SCANassets/Icons/SCAN_Overlay_Icon.dds diff --git a/SCANassets/Icons/SCAN_Overlay_Icon.dds b/SCANassets/Icons/SCAN_Overlay_Icon.dds new file mode 100644 index 0000000000000000000000000000000000000000..78ab017f071b0f52b968a3bc544ea9d1a38bab4a GIT binary patch literal 1152 zcmb7@O=uHQ5XWC)*IGj`ny$Sl&7tuYXqD81NER&8DwII?wSj~Z+*_-ppaBDgZbb?a z3MP=2g3?qFR%IaSKzzJ9HoMW{(a35KwTkZV1`)d52x@vYIAozSsVS<{Ar#a z7Aa+U0o?FB#KkzN#-oJDg3ZekA?_UGoO<+uD8^#mFOOTLrIw~E!zob^oVGsZ!*SfW zTugk@6HTKYAsiN2d{Ujei5Z??+(lm!N-|;gxFknA^XuPwan0>=xtLv7yc@3I!1~#0 z;dphk^%h_^kMf)h=eLI@x3Q%w^Uda>r7x;+$?p$Z^<%wQAMvyE+WdLOvj44L&&!g- zvCql;ck?GRYin!kaY)}SrSH5l?uX;?{$wHGmDb z8SS&BgN*e;+dpWrawOAeTwh?!Z;hlwrvm}9vQ+C`s(JOoa7wr^H|NvdBw#dg1|Tkp z;jnd|SbsF=_jlGCjYRTRzm59q^p=&6uAH0qyB(HYNBu}_8VAXoGhG=;2V5>Ec^axY z2R-Q5zdm3oE0}O_aRg8X9%JcU8nR)$-L+=|qAMlsj`%zbBMM4&^Vi>(4 eN+u2NyZncFB5QECg8pqi9yL1tKLc$x^?w68KaOw! literal 0 HcmV?d00001 diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs index 532f29902..c332dc0b9 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs @@ -107,6 +107,7 @@ class SCANskins: SCAN_MBE internal static Texture2D SCAN_InstrumentIcon; internal static Texture2D SCAN_SmallMapIcon; internal static Texture2D SCAN_BigMapIcon; + internal static Texture2D SCAN_OverlayIcon; //Zoom Window Textures internal static Texture2D SCAN_ZoomOutIcon; @@ -156,6 +157,7 @@ private static void initializeTextures() SCAN_WaypointIcon = GameDatabase.Instance.GetTexture("SCANsat/Icons/SCAN_WayPointIcon", false); SCAN_MechJebIcon = GameDatabase.Instance.GetTexture("SCANsat/Icons/SCAN_MechJebIcon", false); SCAN_TargetIcon = GameDatabase.Instance.GetTexture("SCANsat/Icons/SCAN_TargetIcon", false); + SCAN_OverlayIcon = GameDatabase.Instance.GetTexture("SCANsat/Icons/SCAN_Overlay_Icon", false); } private static void initializeColors() From eaefab684ce9de8485890126fa5346bc8351ecb6 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 1 Jun 2015 20:54:41 -0400 Subject: [PATCH 071/117] Add button for overlay window --- SCANsat/SCAN_UI/SCANbigMap.cs | 15 +++++++++++---- SCANsat/SCAN_UI/SCANkscMap.cs | 12 +++++++++++- SCANsat/SCAN_UI/SCANmainMap.cs | 4 ++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANbigMap.cs b/SCANsat/SCAN_UI/SCANbigMap.cs index 610a0ed6f..93ac46bb2 100644 --- a/SCANsat/SCAN_UI/SCANbigMap.cs +++ b/SCANsat/SCAN_UI/SCANbigMap.cs @@ -194,7 +194,7 @@ protected override void DrawWindow(int id) mapDraw(id); /* Draw the main map texture */ stopE(); growE(); - fillS(160); + fillS(180); growS(); mouseOver(id); /* Handle all mouse-over info and zoom-map code */ legendBar(id); /* Draw the mouseover info and legend bar along the bottom */ @@ -471,27 +471,34 @@ private void toggleBar(int id) SCANcontroller.controller.mainMap.Visible = !SCANcontroller.controller.mainMap.Visible; } - s.x += 40; + s.x += 36; if (GUI.Button(s, iconWithTT(SCANskins.SCAN_InstrumentIcon, "Instrument Window"), SCANskins.SCAN_windowButton)) { SCANcontroller.controller.instrumentsWindow.Visible = !SCANcontroller.controller.instrumentsWindow.Visible; } - s.x += 40; + s.x += 36; if (GUI.Button(s, iconWithTT(SCANskins.SCAN_SettingsIcon, "Settings Menu"), SCANskins.SCAN_windowButton)) { SCANcontroller.controller.settingsWindow.Visible = !SCANcontroller.controller.settingsWindow.Visible; } - s.x += 40; + s.x += 36; if (GUI.Button(s, iconWithTT(SCANskins.SCAN_ColorIcon, "Color Control"), SCANskins.SCAN_windowButton)) { SCANcontroller.controller.colorManager.Visible = !SCANcontroller.controller.colorManager.Visible; } + s.x += 36; + + if (GUI.Button(s, iconWithTT(SCANskins.SCAN_OverlayIcon, "Overlay Control"), SCANskins.SCAN_windowButton)) + { + SCANcontroller.controller.resourceOverlay.Visible = !SCANcontroller.controller.resourceOverlay.Visible; + } + s.x = WindowRect.width - 66; if (GUI.Button(s, iconWithTT(SCANskins.SCAN_ScreenshotIcon, "Export Map"), SCANskins.SCAN_windowButton)) diff --git a/SCANsat/SCAN_UI/SCANkscMap.cs b/SCANsat/SCAN_UI/SCANkscMap.cs index e99aa3b4b..21fff1ce3 100644 --- a/SCANsat/SCAN_UI/SCANkscMap.cs +++ b/SCANsat/SCAN_UI/SCANkscMap.cs @@ -482,7 +482,7 @@ private void toggleBar(int id) SCANcontroller.controller.settingsWindow.removeControlLocks(); } - s.x += 40; + s.x += 36; if (GUI.Button(s, iconWithTT(SCANskins.SCAN_ColorIcon, "Color Control"), SCANskins.SCAN_windowButton)) { @@ -490,6 +490,16 @@ private void toggleBar(int id) SCANcontroller.controller.colorManager.removeControlLocks(); } + if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) + { + s.x += 36; + + if (GUI.Button(s, iconWithTT(SCANskins.SCAN_OverlayIcon, "Overlay Control"), SCANskins.SCAN_windowButton)) + { + SCANcontroller.controller.resourceOverlay.Visible = !SCANcontroller.controller.resourceOverlay.Visible; + } + } + s.x = WindowRect.width - 66; if (GUI.Button(s, iconWithTT(SCANskins.SCAN_ScreenshotIcon, "Export Map"), SCANskins.SCAN_windowButton)) diff --git a/SCANsat/SCAN_UI/SCANmainMap.cs b/SCANsat/SCAN_UI/SCANmainMap.cs index d3dee6239..ba80d93c7 100644 --- a/SCANsat/SCAN_UI/SCANmainMap.cs +++ b/SCANsat/SCAN_UI/SCANmainMap.cs @@ -165,6 +165,10 @@ private void windowButtons(int id) { SCANcontroller.controller.colorManager.Visible = !SCANcontroller.controller.colorManager.Visible; } + if (GUILayout.Button(iconWithTT(SCANskins.SCAN_OverlayIcon, "Overlay Contral"), SCANskins.SCAN_windowButton, GUILayout.Height(32), GUILayout.Width(32))) + { + SCANcontroller.controller.resourceOverlay.Visible = !SCANcontroller.controller.resourceOverlay.Visible; + } } //Draw the vessel location and alt info From 70b22d75f78242db565b2400ae36606641602f18 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 1 Jun 2015 20:54:54 -0400 Subject: [PATCH 072/117] Check assembly version for MechJeb loading --- SCANmechjeb/SCANmechjebMainMenu.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/SCANmechjeb/SCANmechjebMainMenu.cs b/SCANmechjeb/SCANmechjebMainMenu.cs index 0773c98dd..e21b190b8 100644 --- a/SCANmechjeb/SCANmechjebMainMenu.cs +++ b/SCANmechjeb/SCANmechjebMainMenu.cs @@ -69,12 +69,7 @@ private bool checkLoaded() if (MechJebAssembly == null) return false; - var fileV = Attribute.GetCustomAttribute(MechJebAssembly.assembly, typeof(AssemblyFileVersionAttribute)) as AssemblyFileVersionAttribute; - - if (fileV == null) - return false; - - if (fileV.Version == MechJebVersion.ToString()) + if (MechJebAssembly.assembly.GetName().Version == MechJebVersion) { SCANsat.SCANmainMenuLoader.MechJebLoaded = true; return true; From 737bf3a464c6c468c3cefb7f3ad0224405a001f4 Mon Sep 17 00:00:00 2001 From: DMagic Date: Mon, 1 Jun 2015 20:55:03 -0400 Subject: [PATCH 073/117] Fix MM configs --- SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg b/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg index cf837fab6..39ac29e7e 100644 --- a/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg +++ b/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg @@ -10,7 +10,6 @@ best_alt = 100000 scanName = Ore Scan power = 0.5 - activeModule = False } } @@ -19,14 +18,13 @@ MODULE { name = ModuleSCANresourceScanner - sensorType = 392576 //Use 256 for Ore only + sensorType = 524288 fov = 4 min_alt = 20000 max_alt = 750000 best_alt = 100000 scanName = Resource Scan power = 0.75 - activeModule = True } } @@ -42,7 +40,6 @@ best_alt = 100000 scanName = Resource Scan power = 0.5 - activeModule = True } } @@ -58,6 +55,5 @@ best_alt = 100000 scanName = Karbonite Scan power = 0.5 - activeModule = True } } From c736a31b4aab037e73b372705902b43baabc16e8 Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 2 Jun 2015 15:33:10 -0400 Subject: [PATCH 074/117] Retard coordinates still need fixing --- SCANsat/SCAN_Data/SCANwaypoint.cs | 6 +++--- SCANsat/SCANutil.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/SCANsat/SCAN_Data/SCANwaypoint.cs b/SCANsat/SCAN_Data/SCANwaypoint.cs index cc83a31f0..b211b2c6f 100644 --- a/SCANsat/SCAN_Data/SCANwaypoint.cs +++ b/SCANsat/SCAN_Data/SCANwaypoint.cs @@ -30,7 +30,7 @@ internal SCANwaypoint(SurveyWaypointParameter p) param = p; name = way.name; longitude = SCANUtil.fixLonShift(way.longitude); - latitude = SCANUtil.fixLatShift(way.latitude); + latitude = SCANUtil.fixWaypointLatShift(way.latitude); landingTarget = false; } } @@ -45,7 +45,7 @@ internal SCANwaypoint(StationaryPointParameter p) param = p; name = way.name; longitude = SCANUtil.fixLonShift(way.longitude); - latitude = SCANUtil.fixLatShift(way.latitude); + latitude = SCANUtil.fixWaypointLatShift(way.latitude); landingTarget = false; } } @@ -58,7 +58,7 @@ internal SCANwaypoint(Waypoint p) param = null; name = way.name; longitude = SCANUtil.fixLonShift(way.longitude); - latitude = SCANUtil.fixLatShift(way.latitude); + latitude = SCANUtil.fixWaypointLatShift(way.latitude); landingTarget = false; } diff --git a/SCANsat/SCANutil.cs b/SCANsat/SCANutil.cs index 32f50aa70..8ad9d881b 100644 --- a/SCANsat/SCANutil.cs +++ b/SCANsat/SCANutil.cs @@ -262,6 +262,25 @@ internal static double fixLon(double lon) return (lon + 360 + 180) % 360; } + internal static double fixWaypointLatShift(double lat) + { + if (lat < -90) + { + while (lat < -90) + lat += 90; + return -90 + Math.Abs(lat); + } + + if (lat > 90) + { + while (lat > 90) + lat -= 90; + return 90 - Math.Abs(lat); + } + + return lat; + } + internal static double getElevation(CelestialBody body, double lon, double lat) { if (body.pqsController == null) return 0; From 5e7957908928e808836bc4ce21c1109f718c7c61 Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 2 Jun 2015 15:33:21 -0400 Subject: [PATCH 075/117] Show the landing target on any focused planet --- SCANsat/SCANcontroller.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SCANsat/SCANcontroller.cs b/SCANsat/SCANcontroller.cs index 18eb7da53..6c05b7c7b 100644 --- a/SCANsat/SCANcontroller.cs +++ b/SCANsat/SCANcontroller.cs @@ -941,12 +941,12 @@ private void drawTarget() if (!MapView.MapIsEnabled) return; - Vessel v = FlightGlobals.ActiveVessel; + CelestialBody b = SCANUtil.getTargetBody(MapView.MapCamera.target); - if (v == null) + if (b == null) return; - SCANdata d = getData(v.mainBody.name); + SCANdata d = getData(b.name); if (d == null) return; @@ -956,7 +956,7 @@ private void drawTarget() if (target == null) return; - SCANuiUtil.drawTargetOverlay(v.mainBody, target.Latitude, target.Longitude, XKCDColors.DarkGreen); + SCANuiUtil.drawTargetOverlay(b, target.Latitude, target.Longitude, XKCDColors.DarkGreen); } private void removeVessel(Vessel v) From ba44842200952c90381f7f8e15a2d3c9a2ed6c2a Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 2 Jun 2015 15:33:38 -0400 Subject: [PATCH 076/117] Resource map overlays working --- SCANsat/SCAN_Map/SCANmap.cs | 51 ++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 08b524c2e..575eb9729 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -287,6 +287,7 @@ internal double unprojectLatitude(double lon, double lat) private int resourceInterpolation; private int resourceStep; private int resourceMapSize; + private float resourceMapScale; private double[] biomeIndex; private Color[] stockBiomeColor; @@ -328,8 +329,9 @@ internal void setWidth(int w) pix = new Color[w]; biomeIndex = new double[w]; stockBiomeColor = new Color[w]; - resourceMapSize = mapwidth; - resourceInterpolation = 4; + resourceMapSize = 512; + resourceInterpolation = 8; + resourceMapScale = resourceMapSize / 360f; mapscale = mapwidth / 360f; mapheight = (int)(w / 2); /* big map caching */ @@ -459,7 +461,7 @@ internal bool isMapComplete() public void resetMap(bool setRes = true) { - mapstep = -1; + mapstep = -2; if (SCANconfigLoader.GlobalResource && setRes) { //Make sure that a resource is initialized if necessary if (resource == null && body != null) @@ -549,6 +551,30 @@ internal Texture2D getPartialMap() resourceOn = SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null; + if (mapstep <= -2) + { + if (!resourceOn) + { + mapstep++; + return map; + } + else + { + for (int j = 0; j < resourceMapSize / 2; j += resourceInterpolation) + { + for (int i = 0; i < resourceMapSize; i += resourceInterpolation) + { + double rLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset; + double rLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset; + + resourceCache[i, j] = SCANUtil.ResourceOverlay(rLat, rLon, resource.Name, body) * 100f; + } + } + mapstep++; + return map; + } + } + for (int i = 0; i < map.width; i++) { /* Introduce altimetry check here; Use unprojected lat/long coordinates @@ -598,6 +624,16 @@ internal Texture2D getPartialMap() if (mapstep <= -1) { + if (resourceOn) + { + for (int i = resourceInterpolation / 2; i >= 1; i /= 2) + { + SCANuiUtil.interpolate(resourceCache, 0, resourceMapSize / 2, resourceMapSize, i, i, i, r); + SCANuiUtil.interpolate(resourceCache, 0, resourceMapSize / 2, resourceMapSize, 0, i, i, r); + SCANuiUtil.interpolate(resourceCache, 0, resourceMapSize / 2, resourceMapSize, i, 0, i, r); + } + } + mapstep = -1; mapline = new double[map.width]; mapstep++; @@ -785,9 +821,10 @@ internal Texture2D getPartialMap() if (resourceOn) { - float abundance = SCANUtil.ResourceOverlay(lat, lon, resource.Name, body) * 100; - //double resourceLat = fixUnscale(unScaleLatitude(lat), resourceMapSize / 2); - //double resourceLon = fixUnscale(unScaleLongitude(lon), resourceMapSize); + float abundance = 0;// SCANUtil.ResourceOverlay(lat, lon, resource.Name, body) * 100; + double resourceLat = fixUnscale(unScaleLatitude(lat, resourceMapScale), resourceMapSize / 2); + double resourceLon = fixUnscale(unScaleLongitude(lon, resourceMapScale), resourceMapSize); + //switch (projection) //{ // case MapProjection.Polar: @@ -802,7 +839,7 @@ internal Texture2D getPartialMap() // //} // else // { - // abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)]; + abundance = resourceCache[Mathf.RoundToInt((float)resourceLon), Mathf.RoundToInt((float)resourceLat)]; // } // break; // } From 453c07727f8b8e575ad378b19c4b308f6bc0b97d Mon Sep 17 00:00:00 2001 From: DMagic Date: Tue, 2 Jun 2015 15:52:07 -0400 Subject: [PATCH 077/117] For real fix retard coordinates --- SCANsat/SCAN_Data/SCANwaypoint.cs | 16 ++++++++++------ SCANsat/SCANutil.cs | 28 ++++++++++++++++++---------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/SCANsat/SCAN_Data/SCANwaypoint.cs b/SCANsat/SCAN_Data/SCANwaypoint.cs index b211b2c6f..dec8b376b 100644 --- a/SCANsat/SCAN_Data/SCANwaypoint.cs +++ b/SCANsat/SCAN_Data/SCANwaypoint.cs @@ -15,6 +15,7 @@ using FinePrint.Contracts.Parameters; using FinePrint; using FinePrint.Utilities; +using UnityEngine; namespace SCANsat.SCAN_Data { @@ -29,8 +30,9 @@ internal SCANwaypoint(SurveyWaypointParameter p) root = p.Root; param = p; name = way.name; - longitude = SCANUtil.fixLonShift(way.longitude); - latitude = SCANUtil.fixWaypointLatShift(way.latitude); + Vector2d coords = SCANUtil.fixRetardCoordinates(new Vector2d(way.longitude, way.latitude)); + longitude = coords.x; + latitude = coords.y; landingTarget = false; } } @@ -44,8 +46,9 @@ internal SCANwaypoint(StationaryPointParameter p) root = p.Root; param = p; name = way.name; - longitude = SCANUtil.fixLonShift(way.longitude); - latitude = SCANUtil.fixWaypointLatShift(way.latitude); + Vector2d coords = SCANUtil.fixRetardCoordinates(new Vector2d(way.longitude, way.latitude)); + longitude = coords.x; + latitude = coords.y; landingTarget = false; } } @@ -57,8 +60,9 @@ internal SCANwaypoint(Waypoint p) root = p.contractReference; param = null; name = way.name; - longitude = SCANUtil.fixLonShift(way.longitude); - latitude = SCANUtil.fixWaypointLatShift(way.latitude); + Vector2d coords = SCANUtil.fixRetardCoordinates(new Vector2d(way.longitude, way.latitude)); + longitude = coords.x; + latitude = coords.y; landingTarget = false; } diff --git a/SCANsat/SCANutil.cs b/SCANsat/SCANutil.cs index 8ad9d881b..15ee2799d 100644 --- a/SCANsat/SCANutil.cs +++ b/SCANsat/SCANutil.cs @@ -262,23 +262,31 @@ internal static double fixLon(double lon) return (lon + 360 + 180) % 360; } - internal static double fixWaypointLatShift(double lat) + internal static Vector2d fixRetardCoordinates(Vector2d coords) { - if (lat < -90) + if (coords.y < -90) { - while (lat < -90) - lat += 90; - return -90 + Math.Abs(lat); + while (coords.y < -90) + coords.y += 90; + coords.y = -90 + Math.Abs(coords.y); + coords.x = fixLonShift(coords.x + 180); + + return coords; } - if (lat > 90) + if (coords.y > 90) { - while (lat > 90) - lat -= 90; - return 90 - Math.Abs(lat); + while (coords.y > 90) + coords.y -= 90; + coords.y = 90 - Math.Abs(coords.y); + coords.x = fixLonShift(coords.x - 180); + + return coords; } - return lat; + coords.x = fixLonShift(coords.x); + + return coords; } internal static double getElevation(CelestialBody body, double lon, double lat) From 2085da396830acd77ecbf4110a2ac6bd56868022 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 00:58:39 -0400 Subject: [PATCH 078/117] Low accuracy resource abundance --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 70cca7e55..f6387a15f 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -158,10 +158,16 @@ internal static void mouseOverInfo(double lon, double lat, SCANmap mapObj, SCANd if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && mapObj.Resource != null) //Adds selected resource amount to big map legend { - if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) + string label = ""; + if (SCANUtil.isCovered(lon, lat, data, SCANtype.FuzzyResources)) + { + int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body)) * 100f); + label = amount.ToString() + "%"; + info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); + } + else if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) { double amount = SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body); - string label; if (amount < 0) label = "Unknown"; else @@ -236,10 +242,16 @@ internal static void mouseOverInfoSimple(double lon, double lat, SCANmap mapObj, if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && mapObj.Resource != null) //Adds selected resource amount to big map legend { - if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) + string label = ""; + if (SCANUtil.isCovered(lon, lat, data, SCANtype.FuzzyResources)) + { + int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body)) * 100f); + label = amount.ToString() + "%"; + info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); + } + else if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) { double amount = SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body); - string label; if (amount < 0) label = "Unknown"; else @@ -1548,8 +1560,6 @@ private static void interpolate(Color32[] c, float[,] v, int height, int x, int internal static void interpolate(float[,] v, int yStart, int height, int width, int x, int y, int step, System.Random r) { - int mapHeight = width / 2; - for (int j = yStart + y; j < height + y + yStart; j += 2 * step) { for (int i = x; i < width + x; i += 2 * step) @@ -1565,8 +1575,8 @@ internal static void interpolate(float[,] v, int yStart, int height, int width, if (ypos1 < 0) ypos1 = 0; int ypos2 = j + step; - if (ypos2 >= mapHeight) - ypos2 = mapHeight - 1; + if (ypos2 >= height) + ypos2 = height - 1; float avgX = 0; float avgY = 0; From 57ab916ff5f873ab741de7eeec85952acf580f49 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 00:59:09 -0400 Subject: [PATCH 079/117] Map dimensions must be even numbers --- SCANsat/SCAN_UI/SCANzoomWindow.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SCANsat/SCAN_UI/SCANzoomWindow.cs b/SCANsat/SCAN_UI/SCANzoomWindow.cs index f93d488e9..4a1e0f68d 100644 --- a/SCANsat/SCAN_UI/SCANzoomWindow.cs +++ b/SCANsat/SCAN_UI/SCANzoomWindow.cs @@ -316,6 +316,11 @@ protected override void DrawWindowPre(int id) else if (resizeH > WindowSize_Max.y) resizeH = WindowSize_Max.y; + if ((int)resizeW % 2 != 0) + resizeW += 1; + if ((int)resizeH % 2 != 0) + resizeH += 1; + spotmap.setSize((int)resizeW, (int)resizeH); spotmap.MapScale = scale; spotmap.centerAround(spotmap.CenteredLong, spotmap.CenteredLat); From 81975590594a1ae96adb389eda5c76ae39b48c0f Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 00:59:25 -0400 Subject: [PATCH 080/117] Map resizing must be even numbers --- SCANsat/SCAN_UI/SCANbigMap.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANbigMap.cs b/SCANsat/SCAN_UI/SCANbigMap.cs index 93ac46bb2..6f645b01d 100644 --- a/SCANsat/SCAN_UI/SCANbigMap.cs +++ b/SCANsat/SCAN_UI/SCANbigMap.cs @@ -83,9 +83,8 @@ protected override void Start() { bigmap = new SCANmap(b, true); bigmap.setProjection((MapProjection)SCANcontroller.controller.projection); - int i = SCANcontroller.controller.map_width % 8; - if (i != 0) - SCANcontroller.controller.map_width -= i; + if (SCANcontroller.controller.map_width % 2 != 0) + SCANcontroller.controller.map_width += 1; bigmap.setWidth(SCANcontroller.controller.map_width); } WindowRect.x = SCANcontroller.controller.map_x; @@ -153,9 +152,8 @@ protected override void DrawWindowPre(int id) IsResizing = false; if (resizeW < WindowSize_Min.x) resizeW = WindowSize_Min.x; - int i = (int)resizeW % 8; - if (i != 0) - resizeW -= i; + if ((int)resizeW % 2 != 0) + resizeW += 1; bigmap.setWidth((int)resizeW); drawGrid = true; SCANcontroller.controller.map_width = bigmap.MapWidth; From 4d044907e8101e763cdee3df792ee3abcb6bd739 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 00:59:39 -0400 Subject: [PATCH 081/117] Fix zoom map resource overlay... --- SCANsat/SCAN_Map/SCANmap.cs | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 575eb9729..e58f3123d 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -47,7 +47,11 @@ internal SCANmap() public double MapScale { get { return mapscale; } - internal set { mapscale = value; } + internal set + { + mapscale = value; + resourceMapScale = (resourceMapWidth / 360f) * mapscale; + } } public double Lon_Offset @@ -285,9 +289,9 @@ internal double unprojectLatitude(double lon, double lat) private Color[] pix; private float[,] resourceCache; private int resourceInterpolation; - private int resourceStep; - private int resourceMapSize; - private float resourceMapScale; + private int resourceMapWidth; + private int resourceMapHeight; + private double resourceMapScale; private double[] biomeIndex; private Color[] stockBiomeColor; @@ -301,7 +305,11 @@ internal void setSize(int w, int h) pix = new Color[w]; biomeIndex = new double[w]; stockBiomeColor = new Color[w]; + resourceMapWidth = w; + resourceMapHeight = h; resourceCache = new float[w, h]; + resourceInterpolation = 2; + resourceMapScale = resourceMapWidth / 360; mapscale = mapwidth / 360f; if (h <= 0) h = (int)(180 * mapscale); @@ -329,9 +337,10 @@ internal void setWidth(int w) pix = new Color[w]; biomeIndex = new double[w]; stockBiomeColor = new Color[w]; - resourceMapSize = 512; + resourceMapWidth = 512; + resourceMapHeight = resourceMapWidth / 2; resourceInterpolation = 8; - resourceMapScale = resourceMapSize / 360f; + resourceMapScale = resourceMapWidth / 360f; mapscale = mapwidth / 360f; mapheight = (int)(w / 2); /* big map caching */ @@ -484,8 +493,7 @@ public void resetMap(mapType mode, bool Cache, bool setRes = true) public void resetResourceMap() { - resourceStep = 0; - resourceCache = new float[resourceMapSize, resourceMapSize / 2]; + resourceCache = new float[resourceMapWidth, resourceMapHeight]; } /* MAP: export: PNG file */ @@ -560,9 +568,9 @@ internal Texture2D getPartialMap() } else { - for (int j = 0; j < resourceMapSize / 2; j += resourceInterpolation) + for (int j = 0; j < resourceMapHeight; j += resourceInterpolation) { - for (int i = 0; i < resourceMapSize; i += resourceInterpolation) + for (int i = 0; i < resourceMapWidth; i += resourceInterpolation) { double rLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset; double rLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset; @@ -628,9 +636,9 @@ internal Texture2D getPartialMap() { for (int i = resourceInterpolation / 2; i >= 1; i /= 2) { - SCANuiUtil.interpolate(resourceCache, 0, resourceMapSize / 2, resourceMapSize, i, i, i, r); - SCANuiUtil.interpolate(resourceCache, 0, resourceMapSize / 2, resourceMapSize, 0, i, i, r); - SCANuiUtil.interpolate(resourceCache, 0, resourceMapSize / 2, resourceMapSize, i, 0, i, r); + SCANuiUtil.interpolate(resourceCache, 0, resourceMapHeight, resourceMapWidth, i, i, i, r); + SCANuiUtil.interpolate(resourceCache, 0, resourceMapHeight, resourceMapWidth, 0, i, i, r); + SCANuiUtil.interpolate(resourceCache, 0, resourceMapHeight, resourceMapWidth, i, 0, i, r); } } @@ -821,9 +829,9 @@ internal Texture2D getPartialMap() if (resourceOn) { - float abundance = 0;// SCANUtil.ResourceOverlay(lat, lon, resource.Name, body) * 100; - double resourceLat = fixUnscale(unScaleLatitude(lat, resourceMapScale), resourceMapSize / 2); - double resourceLon = fixUnscale(unScaleLongitude(lon, resourceMapScale), resourceMapSize); + float abundance = 0; + double resourceLat = fixUnscale(unScaleLatitude(lat, resourceMapScale), resourceMapHeight); + double resourceLon = fixUnscale(unScaleLongitude(lon, resourceMapScale), resourceMapWidth); //switch (projection) //{ From ea7a38b57c20db6b9704dda7fe3515ea974d28af Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 12:55:51 -0400 Subject: [PATCH 082/117] Maybe fixes for resource scanner action groups --- SCANsat/SCANresourceScanner.cs | 58 +++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/SCANsat/SCANresourceScanner.cs b/SCANsat/SCANresourceScanner.cs index 4e514eafc..1396b3470 100644 --- a/SCANsat/SCANresourceScanner.cs +++ b/SCANsat/SCANresourceScanner.cs @@ -22,7 +22,7 @@ public class ModuleSCANresourceScanner : SCANsat, IAnimatedModule private List mSurvey; private List mScanner; private ModuleAnimationGroup animGroup; - private bool activated = false; + private bool activated; public override void OnStart(PartModule.StartState state) { @@ -33,19 +33,14 @@ public override void OnStart(PartModule.StartState state) animGroup = findAnimator(); if (animGroup == null) - { - SCANUtil.SCANlog("No Anim Group Found"); - this.isEnabled = true; - } - else - SCANUtil.SCANlog("Anim Group Found"); + activated = true; Actions["startScanAction"].active = false; Actions["stopScanAction"].active = false; Actions["toggleScanAction"].active = false; - Actions["startResourceScanAction"].guiName = "Start Action " + scanName; - Actions["stopResourceScanAction"].guiName = "Stop Action" + scanName; - Actions["toggleResourceScanAction"].guiName = "Toggle Action" + scanName; + Actions["startResourceScanAction"].guiName = "Start " + scanName; + Actions["stopResourceScanAction"].guiName = "Stop " + scanName; + Actions["toggleResourceScanAction"].guiName = "Toggle " + scanName; } public override string GetInfo() @@ -73,14 +68,22 @@ private ModuleAnimationGroup findAnimator() private void updateEvents() { - base.Events["startScan"].active = !scanning && activated; - base.Events["stopScan"].active = scanning && activated; + base.Events["startScan"].active = !scanning; + base.Events["stopScan"].active = scanning; } public void Update() { - if (activated) - base.OnUpdate(); + base.OnUpdate(); + + if (!activated) + { + base.Events["startScan"].active = false; + base.Events["stopScan"].active = false; + if (scanning) + unregisterScanner(); + return; + } if (!HighLogic.LoadedSceneIsFlight) return; @@ -105,30 +108,33 @@ public void Update() [KSPAction("Start Resource Scan")] public void startResourceScanAction(KSPActionParam param) { - SCANUtil.SCANlog("Start Scan"); - if (animGroup != null && !scanning && !animGroup.isDeployed) - animGroup.DeployModule(); - startScan(); + if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) + { + if (animGroup != null && !scanning && !animGroup.isDeployed) + animGroup.DeployModule(); + startScan(); + } } [KSPAction("Stop Resource Scan")] public void stopResourceScanAction(KSPActionParam param) { - SCANUtil.SCANlog("Stop Scan"); stopScan(); } [KSPAction("Toggle Resource Scan")] public void toggleResourceScanAction(KSPActionParam param) { - SCANUtil.SCANlog("Toggle Scan"); if (scanning) stopScan(); else { - if (animGroup != null && !animGroup.isDeployed) - animGroup.DeployModule(); - startScan(); + if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) + { + if (animGroup != null && !animGroup.isDeployed) + animGroup.DeployModule(); + startScan(); + } } } @@ -137,7 +143,9 @@ public void DisableModule() activated = false; base.Events["startScan"].active = false; base.Events["stopScan"].active = false; - unregisterScanner(); + if (scanning) + unregisterScanner(); + if (mSurvey != null && SCANcontroller.controller.disableStockResource) { foreach (ModuleOrbitalSurveyor m in mSurvey) @@ -166,7 +174,7 @@ public bool IsSituationValid() public bool ModuleIsActive() { - return isEnabled; + return activated; } } } From 30625d7f13ea9c5ba2fcbb717a33fa12bd6ec411 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 12:56:04 -0400 Subject: [PATCH 083/117] New scanner types --- SCANsat/SCAN_Data/SCANtype.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SCANsat/SCAN_Data/SCANtype.cs b/SCANsat/SCAN_Data/SCANtype.cs index 2e4f0abd0..715a40e9c 100644 --- a/SCANsat/SCAN_Data/SCANtype.cs +++ b/SCANsat/SCAN_Data/SCANtype.cs @@ -44,6 +44,7 @@ public enum SCANtype : int Everything_SCAN = (1 << 6) - 1, // All default SCANsat scanners AllResources = 2147483584, // All resource types DefinedResources = 393088, // All defined resource types + MKSResources = 107648, // All standard MKS/USI resources Everything = Int32.MaxValue // All scanner types } } From 2da005941340efa62cb9bfaf99994f33cba3c2f9 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 12:56:25 -0400 Subject: [PATCH 084/117] Update active vessel; changes to map initialization --- SCANsat/SCAN_UI/SCANbigMap.cs | 44 ++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANbigMap.cs b/SCANsat/SCAN_UI/SCANbigMap.cs index 6f645b01d..ccc8d660f 100644 --- a/SCANsat/SCAN_UI/SCANbigMap.cs +++ b/SCANsat/SCAN_UI/SCANbigMap.cs @@ -75,10 +75,28 @@ protected override void Start() { //Initialize the map object Visible = SCANcontroller.controller.bigMapVisible; - if (v == null) - v = FlightGlobals.ActiveVessel; + WindowRect.x = SCANcontroller.controller.map_x; + WindowRect.y = SCANcontroller.controller.map_y; + lastColor = currentColor = SCANcontroller.controller.colours == 0; + lastResource = SCANcontroller.controller.map_ResourceOverlay; + if (SCANconfigLoader.GlobalResource) + loadedResources = SCANcontroller.setLoadedResourceList(); + TooltipsEnabled = SCANcontroller.controller.toolTips; + + initializeMap(); + } + + private void initializeMap() + { + v = FlightGlobals.ActiveVessel; if (b == null) - b = v.mainBody; + { + if (v == null) + b = FlightGlobals.Bodies[1]; + else + b = v.mainBody; + } + if (bigmap == null) { bigmap = new SCANmap(b, true); @@ -87,12 +105,7 @@ protected override void Start() SCANcontroller.controller.map_width += 1; bigmap.setWidth(SCANcontroller.controller.map_width); } - WindowRect.x = SCANcontroller.controller.map_x; - WindowRect.y = SCANcontroller.controller.map_y; - currentColor = SCANcontroller.controller.colours == 0; - lastColor = currentColor; - lastResource = SCANcontroller.controller.map_ResourceOverlay; - WindowCaption = string.Format("Map of {0}", b.theName); + data = SCANUtil.getData(b); if (data == null) { @@ -100,11 +113,8 @@ protected override void Start() SCANcontroller.controller.addToBodyData(b, data); } bigmap.setBody(b); - if (SCANconfigLoader.GlobalResource) - { - loadedResources = SCANcontroller.setLoadedResourceList(); - } - TooltipsEnabled = SCANcontroller.controller.toolTips; + + WindowCaption = string.Format("Map of {0}", b.theName); } protected override void OnDestroy() @@ -113,6 +123,12 @@ protected override void OnDestroy() Destroy(spotMap); } + protected override void Update() + { + if (FlightGlobals.ready) + v = FlightGlobals.ActiveVessel; + } + //Properties used to sync with color selection window public static SCANmap BigMap { From 7d8bdc98588b83f9b7685d5bdebdbb0d2f60a2d0 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 12:56:46 -0400 Subject: [PATCH 085/117] Clarify SCANsat resource reset --- SCANsat/SCAN_UI/SCANresourceSettings.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANresourceSettings.cs b/SCANsat/SCAN_UI/SCANresourceSettings.cs index 482179f32..ad519a611 100644 --- a/SCANsat/SCAN_UI/SCANresourceSettings.cs +++ b/SCANsat/SCAN_UI/SCANresourceSettings.cs @@ -150,7 +150,7 @@ private void resourceSettings(int id) stopE(); if (popup) { - GUILayout.Label("Reset Resource Coverage", SCANskins.SCAN_button); + GUILayout.Label("Reset SCANsat Resource Coverage", SCANskins.SCAN_button); if (SCANcontroller.controller.disableStockResource) { fillS(8); @@ -159,7 +159,7 @@ private void resourceSettings(int id) } else { - if (GUILayout.Button("Reset Resource Coverage")) + if (GUILayout.Button("Reset SCANsat Resource Coverage")) { popup = !popup; warningResource = !warningResource; @@ -228,7 +228,7 @@ private void warningBox(int id) warningRect = new Rect(WindowRect.width - (WindowRect.width / 2) - 150, WindowRect.height - 125, 300, 90); GUI.Box(warningRect, ""); Rect r = new Rect(warningRect.x + 10, warningRect.y + 5, 280, 40); - GUI.Label(r, "Erase resource data for " + thisBody.theName + "?", SCANskins.SCAN_headlineSmall); + GUI.Label(r, "Erase SCANsat resource data for " + thisBody.theName + "?", SCANskins.SCAN_headlineSmall); r.x += 90; r.y += 45; r.width = 80; @@ -265,13 +265,7 @@ private void warningBox(int id) popup = false; warningStockResource = false; var resources = ResourceScenario.Instance.gameSettings.GetPlanetScanInfo(); - for (int i = 0; i < resources.Count; i++) - { - if (resources[i].PlanetId == thisBody.flightGlobalsIndex) - SCANUtil.SCANlog("Removing Stock Resource Value"); - } resources.RemoveAll(a => a.PlanetId == thisBody.flightGlobalsIndex); - } } else From 589f4e326ebd6c788b6d133623d97ba3de6eb36f Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 12:57:31 -0400 Subject: [PATCH 086/117] Remove periodic narrow band check --- SCANsat/SCAN_UI/SCANzoomWindow.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANzoomWindow.cs b/SCANsat/SCAN_UI/SCANzoomWindow.cs index 4a1e0f68d..9e8a21f26 100644 --- a/SCANsat/SCAN_UI/SCANzoomWindow.cs +++ b/SCANsat/SCAN_UI/SCANzoomWindow.cs @@ -173,8 +173,6 @@ private double inc(double d) private void checkForScanners() { - //DateTime duration = DateTime.Now; - narrowBand = false; foreach (Vessel vessel in FlightGlobals.Vessels) { @@ -261,29 +259,16 @@ where nodes.GetValue("name") == "ModuleResourceScanner" if (!narrowBand) spotmap.Resource = null; - - //SCANUtil.SCANdebugLog("Loop Time: {0}", duration - DateTime.Now); } - private int timer; - protected override void Update() { if (Visible) { - if (SCANcontroller.controller.needsNarrowBand && SCANconfigLoader.GlobalResource) - { - if (SCANcontroller.controller.map_ResourceOverlay && timer >= 60) - checkForScanners(); - } - else + if (!SCANcontroller.controller.needsNarrowBand && SCANconfigLoader.GlobalResource) narrowBand = true; - timer++; - if (timer > 60) - timer = 0; - - if (HighLogic.LoadedSceneIsFlight) + if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready) v = FlightGlobals.ActiveVessel; else if (HighLogic.LoadedScene == GameScenes.TRACKSTATION) { From 97fb3bb6f8327a3d2617880090378d71d1760de1 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 12:57:51 -0400 Subject: [PATCH 087/117] A few tweaks to interpolation --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index f6387a15f..41ffca86d 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -1558,7 +1558,7 @@ private static void interpolate(Color32[] c, float[,] v, int height, int x, int } } - internal static void interpolate(float[,] v, int yStart, int height, int width, int x, int y, int step, System.Random r) + internal static void interpolate(float[,] v, int yStart, int height, int width, int x, int y, int step, System.Random r, bool edges) { for (int j = yStart + y; j < height + y + yStart; j += 2 * step) { @@ -1581,7 +1581,9 @@ internal static void interpolate(float[,] v, int yStart, int height, int width, float avgX = 0; float avgY = 0; - float lerp = getLerp(r, step * 2); + float lerp = 0.5f; + if (!edges) + lerp = getLerp(r, step * 2); if (x == y) { @@ -1646,11 +1648,9 @@ internal static Color resourceToColor(Color BaseColor, SCANresourceGlobal Resour Abundance = 0; } else - Abundance = -1; - - if (Abundance < 0) return BaseColor; - else if (Abundance == 0) + + if (Abundance == 0) return palette.lerp(BaseColor, palette.grey, 0.3f); else return palette.lerp(palette.lerp(Resource.MinColor, Resource.MaxColor, Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); @@ -1680,11 +1680,9 @@ private static Color32 resourceToColor32(Color32 BaseColor, SCANresourceGlobal R Abundance = 0; } else - Abundance = -1; - - if (Abundance < 0) return BaseColor; - else if (Abundance == 0) + + if (Abundance == 0) return palette.lerp(BaseColor, palette.Grey, Transparency); else return palette.lerp(palette.lerp(Resource.MinColor32, Resource.MaxColor32, Abundance / (Resource.CurrentBody.MaxValue - Resource.CurrentBody.MinValue)), BaseColor, Resource.Transparency / 100f); From ffd242e390837b8b7075edb24692f01df931b44c Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 12:58:15 -0400 Subject: [PATCH 088/117] Changes to SetSize resource maps --- SCANsat/SCAN_Map/SCANmap.cs | 85 ++++++++++--------------------------- 1 file changed, 23 insertions(+), 62 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index e58f3123d..18878d9b3 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -292,6 +292,7 @@ internal double unprojectLatitude(double lon, double lat) private int resourceMapWidth; private int resourceMapHeight; private double resourceMapScale; + private bool randomEdges = true; private double[] biomeIndex; private Color[] stockBiomeColor; @@ -302,18 +303,19 @@ internal void setSize(int w, int h) if (w > 360 * 4) w = 360 * 4; mapwidth = w; - pix = new Color[w]; - biomeIndex = new double[w]; - stockBiomeColor = new Color[w]; - resourceMapWidth = w; - resourceMapHeight = h; - resourceCache = new float[w, h]; - resourceInterpolation = 2; - resourceMapScale = resourceMapWidth / 360; + pix = new Color[mapwidth]; + biomeIndex = new double[mapwidth]; + stockBiomeColor = new Color[mapwidth]; mapscale = mapwidth / 360f; if (h <= 0) h = (int)(180 * mapscale); mapheight = h; + resourceMapWidth = mapwidth; + resourceMapHeight = mapheight; + resourceCache = new float[resourceMapWidth, resourceMapHeight]; + resourceInterpolation = 2; + resourceMapScale = resourceMapWidth / 360; + randomEdges = false; if (map != null) { if (mapwidth != map.width || mapheight != map.height) @@ -341,6 +343,8 @@ internal void setWidth(int w) resourceMapHeight = resourceMapWidth / 2; resourceInterpolation = 8; resourceMapScale = resourceMapWidth / 360f; + resourceCache = new float[resourceMapWidth, resourceMapHeight]; + randomEdges = true; mapscale = mapwidth / 360f; mapheight = (int)(w / 2); /* big map caching */ @@ -493,7 +497,13 @@ public void resetMap(mapType mode, bool Cache, bool setRes = true) public void resetResourceMap() { - resourceCache = new float[resourceMapWidth, resourceMapHeight]; + for (int i = 0; i < resourceMapWidth; i++ ) + { + for (int j = 0; j < resourceMapHeight; j++) + { + resourceCache[i, j] = 0; + } + } } /* MAP: export: PNG file */ @@ -605,7 +615,7 @@ internal Texture2D getPartialMap() if (mapstep < 0) continue; - if (mType != mapType.Biome && biomeMap) + if (mType != mapType.Biome || !biomeMap) continue; double lat = (mapstep * 1.0f / mapscale) - 90f + lat_offset; @@ -636,9 +646,9 @@ internal Texture2D getPartialMap() { for (int i = resourceInterpolation / 2; i >= 1; i /= 2) { - SCANuiUtil.interpolate(resourceCache, 0, resourceMapHeight, resourceMapWidth, i, i, i, r); - SCANuiUtil.interpolate(resourceCache, 0, resourceMapHeight, resourceMapWidth, 0, i, i, r); - SCANuiUtil.interpolate(resourceCache, 0, resourceMapHeight, resourceMapWidth, i, 0, i, r); + SCANuiUtil.interpolate(resourceCache, 0, resourceMapHeight, resourceMapWidth, i, i, i, r, randomEdges); + SCANuiUtil.interpolate(resourceCache, 0, resourceMapHeight, resourceMapWidth, 0, i, i, r, randomEdges); + SCANuiUtil.interpolate(resourceCache, 0, resourceMapHeight, resourceMapWidth, i, 0, i, r, randomEdges); } } @@ -648,55 +658,6 @@ internal Texture2D getPartialMap() return map; } - //if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && resource != null) - //{ - // resourceOn = true; - // if (mapstep < resourceMapSize / (resourceInterpolation * 8)) - // { - // for (int i = 0; i < resourceMapSize; i++) - // { - // if (i % resourceInterpolation != 0) - // continue; - - // double resourceLon = (i * 1.0f / mapscale) - 180f + lon_offset; - // int ystep = mapstep * resourceInterpolation * 4; - - // for (int j = ystep; j < (4 * resourceInterpolation) + ystep; j++) - // { - // if (j % resourceInterpolation != 0) - // continue; - - // double resourceLat = (j * 1.0f / mapscale) - 90f + lat_offset; - - // resourceCache[i, j] = SCANUtil.ResourceOverlay(resourceLat, resourceLon, resource.Name, body) * 100; - // } - // } - // } - - // if (resourceStep < (resourceMapSize / 2)) - // { - // bool skip = false; - // for (int i = resourceInterpolation / 2; i >= 1; i /= 2) - // { - // if (resourceStep < resourceInterpolation / 2 || resourceStep >= ((resourceMapSize / 2) - (resourceInterpolation / 2))) - // { - // SCANuiUtil.interpolate(resourceCache, resourceStep, resourceMapSize, i, i, r); - // } - // else - // { - // SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, i, i, r); - // SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, 0, i, i, r); - // SCANuiUtil.interpolate(resourceCache, resourceStep, 4, resourceMapSize, i, 0, i, r); - // skip = true; - // } - // } - // if (skip) - // resourceStep += 4; - // else - // resourceStep++; - // } - //} - for (int i = 0; i < map.width; i++) { Color baseColor = palette.grey; From dd66f01ae6610d24371972cd7daa88284c4bdbf6 Mon Sep 17 00:00:00 2001 From: DMagic Date: Wed, 3 Jun 2015 13:49:51 -0400 Subject: [PATCH 089/117] Add resource settings button to overlay window --- SCANsat/SCAN_UI/SCANoverlayController.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANoverlayController.cs b/SCANsat/SCAN_UI/SCANoverlayController.cs index df1d6e5e7..c100e7524 100644 --- a/SCANsat/SCAN_UI/SCANoverlayController.cs +++ b/SCANsat/SCAN_UI/SCANoverlayController.cs @@ -91,6 +91,7 @@ protected override void DrawWindow(int id) drawResourceList(id); overlayToggle(id); overlayOptions(id); + resourceSettings(id); } protected override void DrawWindowPost(int id) @@ -157,8 +158,6 @@ private void drawResourceList(int id) oldOverlay = drawOverlay = true; refreshMap(); } - - } } @@ -221,6 +220,15 @@ private void overlayOptions(int id) } } + private void resourceSettings(int id) + { + fillS(); + if (GUILayout.Button("Resource Settings")) + { + SCANcontroller.controller.resourceSettings.Visible = !SCANcontroller.controller.resourceSettings.Visible; + } + } + public void refreshMap(float t, int height, int interp) { transparency = t; From 4770a4e527e268f9a2f05d7f9a81bf0a9499eb29 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 4 Jun 2015 15:20:55 -0400 Subject: [PATCH 090/117] Move these --- SCANsat/SCANresourceScanner.cs | 180 ----------- SCANsat/SCANsat.cs | 570 --------------------------------- 2 files changed, 750 deletions(-) delete mode 100644 SCANsat/SCANresourceScanner.cs delete mode 100644 SCANsat/SCANsat.cs diff --git a/SCANsat/SCANresourceScanner.cs b/SCANsat/SCANresourceScanner.cs deleted file mode 100644 index 1396b3470..000000000 --- a/SCANsat/SCANresourceScanner.cs +++ /dev/null @@ -1,180 +0,0 @@ -#region license -/* [Scientific Committee on Advanced Navigation] - * S.C.A.N. Satellite - * - * SCANresourceScanner - Resource scanner part module - * - * Copyright (c)2013 damny; - * Copyright (c)2014 technogeeky ; - * Copyright (c)2014 DMagic - * Copyright (c)2014 (Your Name Here) ; see LICENSE.txt for licensing details. - */ -#endregion - -using System.Collections.Generic; -using System.Linq; -using SCANsat.SCAN_Data; - -namespace SCANsat -{ - public class ModuleSCANresourceScanner : SCANsat, IAnimatedModule - { - private List mSurvey; - private List mScanner; - private ModuleAnimationGroup animGroup; - private bool activated; - - public override void OnStart(PartModule.StartState state) - { - base.OnStart(state); - - mSurvey = findSurvey(); - mScanner = findScanner(); - animGroup = findAnimator(); - - if (animGroup == null) - activated = true; - - Actions["startScanAction"].active = false; - Actions["stopScanAction"].active = false; - Actions["toggleScanAction"].active = false; - Actions["startResourceScanAction"].guiName = "Start " + scanName; - Actions["stopResourceScanAction"].guiName = "Stop " + scanName; - Actions["toggleResourceScanAction"].guiName = "Toggle " + scanName; - } - - public override string GetInfo() - { - string info = base.GetInfo(); - info += "Resource Scan: " + (SCANtype)sensorType + "\n"; - - return info; - } - - private List findScanner() - { - return part.FindModulesImplementing(); - } - - private List findSurvey() - { - return part.FindModulesImplementing(); - } - - private ModuleAnimationGroup findAnimator() - { - return part.FindModulesImplementing().FirstOrDefault(); - } - - private void updateEvents() - { - base.Events["startScan"].active = !scanning; - base.Events["stopScan"].active = scanning; - } - - public void Update() - { - base.OnUpdate(); - - if (!activated) - { - base.Events["startScan"].active = false; - base.Events["stopScan"].active = false; - if (scanning) - unregisterScanner(); - return; - } - - if (!HighLogic.LoadedSceneIsFlight) - return; - - if (!FlightGlobals.ready) - return; - - if (SCANcontroller.controller == null) - return; - - if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) - updateEvents(); - else - { - base.Events["startScan"].active = false; - base.Events["stopScan"].active = false; - if (scanning) - unregisterScanner(); - } - } - - [KSPAction("Start Resource Scan")] - public void startResourceScanAction(KSPActionParam param) - { - if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) - { - if (animGroup != null && !scanning && !animGroup.isDeployed) - animGroup.DeployModule(); - startScan(); - } - } - - [KSPAction("Stop Resource Scan")] - public void stopResourceScanAction(KSPActionParam param) - { - stopScan(); - } - - [KSPAction("Toggle Resource Scan")] - public void toggleResourceScanAction(KSPActionParam param) - { - if (scanning) - stopScan(); - else - { - if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) - { - if (animGroup != null && !animGroup.isDeployed) - animGroup.DeployModule(); - startScan(); - } - } - } - - public void DisableModule() - { - activated = false; - base.Events["startScan"].active = false; - base.Events["stopScan"].active = false; - if (scanning) - unregisterScanner(); - - if (mSurvey != null && SCANcontroller.controller.disableStockResource) - { - foreach (ModuleOrbitalSurveyor m in mSurvey) - { - m.DisableModule(); - } - } - } - - public void EnableModule() - { - activated = true; - if (mSurvey != null && SCANcontroller.controller.disableStockResource) - { - foreach (ModuleOrbitalSurveyor m in mSurvey) - { - m.DisableModule(); - } - } - } - - public bool IsSituationValid() - { - return true; - } - - public bool ModuleIsActive() - { - return activated; - } - } -} diff --git a/SCANsat/SCANsat.cs b/SCANsat/SCANsat.cs deleted file mode 100644 index 5111f826a..000000000 --- a/SCANsat/SCANsat.cs +++ /dev/null @@ -1,570 +0,0 @@ -#region license -/* [Scientific Committee on Advanced Navigation] - * S.C.A.N. Satellite - * - * SCANsat - SCAN RADAR Altimetry Sensor part (& More) - * - * Copyright (c)2013 damny; - * Copyright (c)2014 technogeeky ; - * Copyright (c)2014 (Your Name Here) ; see LICENSE.txt for licensing details. - */ -#endregion - -using System; -using System.Collections.Generic; -using System.Linq; -using SCANsat.SCAN_Data; -using SCANsat.SCAN_Toolbar; -using SCANsat.SCAN_UI; - -using UnityEngine; -using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette; - -namespace SCANsat -{ - public class SCANsat : PartModule, IScienceDataContainer - { - private bool powerIsProblem; - private Animation anim = null; - private List storedData = new List(); - private ExperimentsResultDialog expDialog = null; - - /* SAT: KSP entry points */ - public override void OnStart(StartState state) - { - if (state == StartState.Editor) - { - print("[SCANsat] start: in editor"); - Events["editorExtend"].active = !string.IsNullOrEmpty(animationName); - } - else - { - print("[SCANsat] start: live"); - } - if (!string.IsNullOrEmpty(animationName)) - { - Animation[] a = part.FindModelAnimators(animationName); - if (a.Length == 0) - { - print("[SCANsat] animation '" + animationName + "' not found"); - } - else - { - print("[SCANsat] using animation #1 out of " + a.Length.ToString() + " animations named '" + animationName + "'"); - anim = a[0]; - } - } - if (scanName != null) - { // Use bitwise operators to check if the part has valid science collection scanners - if ((sensorType & (Int32)SCANtype.AltimetryLoRes) == 0 && (sensorType & (Int32)SCANtype.AltimetryHiRes) == 0 && (sensorType & (Int32)SCANtype.Biome) == 0) - { - Events["startScan"].guiName = "Start " + scanName; - Events["stopScan"].guiName = "Stop " + scanName; - Events["analyze"].active = false; - Actions["startScanAction"].guiName = "Start " + scanName; - Actions["stopScanAction"].guiName = "Stop " + scanName; - Actions["toggleScanAction"].guiName = "Toggle " + scanName; - Actions["analyzeData"].active = false; - } - else - { - Events["startScan"].guiName = "Start " + scanName; - Events["stopScan"].guiName = "Stop " + scanName; - Events["analyze"].active = true; - Actions["startScanAction"].guiName = "Start " + scanName; - Actions["stopScanAction"].guiName = "Stop " + scanName; - Actions["toggleScanAction"].guiName = "Toggle " + scanName; - } - } - - if (sensorType == 0) - { - // here, we override all event and action labels - // and we also disable the analyze button (it does nothing) - Events["startScan"].active = false; - Events["stopScan"].active = false; - Events["analyze"].active = false; - Events["editorExtend"].active = false; - Actions["startScanAction"].active = false; - Actions["stopScanAction"].active = false; - Actions["toggleScanAction"].active = false; - Actions["analyzeData"].active = false; - } - else if (sensorType == 32) - { - // here, we only disable analyze; BTDT has good labels - Events["analyze"].active = false; - Actions["analyzeData"].active = false; - } - if (scanning) animate(1, 1); - powerIsProblem = false; - print("[SCANsat] sensorType: " + sensorType.ToString() + " fov: " + fov.ToString() + " min_alt: " + min_alt.ToString() + " max_alt: " + max_alt.ToString() + " best_alt: " + best_alt.ToString() + " power: " + power.ToString()); - } - - public override void OnUpdate() - { - if (sensorType == 0) - return; - - Events["reviewEvent"].active = storedData.Count > 0; - Events["EVACollect"].active = storedData.Count > 0; - Events["startScan"].active = !scanning; - Events["stopScan"].active = scanning; - if (sensorType != 32) - Fields["alt_indicator"].guiActive = scanning; - if (scanning) - { - if (SCANcontroller.controller == null) - { - scanning = false; - Debug.LogError("[SCANsat] Warning: SCANsat scenario module not initialized; Shutting down"); - } - else - { - if (sensorType != 0 || SCANcontroller.controller.isVesselKnown(vessel.id, (SCANtype)sensorType)) - { - if (TimeWarp.CurrentRate < 1500) - { - float p = power * TimeWarp.deltaTime; - float e = part.RequestResource("ElectricCharge", p); - if (e < p) - { - unregisterScanner(); - powerIsProblem = true; - } - else - { - registerScanner(); - powerIsProblem = false; - } - } - else if (powerIsProblem) - { - registerScanner(); - powerIsProblem = false; - } - } - else - unregisterScanner(); - alt_indicator = scanAlt(); - } - } - if (vessel == FlightGlobals.ActiveVessel) - { - if (powerIsProblem) - { - addStatic(); - registerScanner(); - } - } - } - - public override void OnLoad(ConfigNode node) - { - if (node.HasNode("ScienceData")) - { - foreach (ConfigNode storedDataNode in node.GetNodes("ScienceData")) - { - ScienceData data = new ScienceData(storedDataNode); - storedData.Add(data); - } - } - if (node.HasNode("SCANsatRPM")) - { - ConfigNode RPMPersistence = node.GetNode("SCANsatRPM"); - foreach (ConfigNode RPMNode in RPMPersistence.GetNodes("Prop")) - { - string id = RPMNode.GetValue("Prop ID"); - int Mode = Convert.ToInt32(RPMNode.GetValue("Mode")); - int Color = Convert.ToInt32(RPMNode.GetValue("Color")); - int Zoom = Convert.ToInt32(RPMNode.GetValue("Zoom")); - bool Lines = Convert.ToBoolean(RPMNode.GetValue("Lines")); - RPMList.Add(new RPMPersistence(id, Mode, Color, Zoom, Lines)); - } - } - } - - public override void OnSave(ConfigNode node) - { - node.RemoveNodes("ScienceData"); //** Prevent duplicates - foreach (ScienceData SCANData in storedData) - { - ConfigNode storedDataNode = node.AddNode("ScienceData"); - SCANData.Save(storedDataNode); - } - if (RPMList.Count > 0) - { - ConfigNode RPMPersistence = new ConfigNode("SCANsatRPM"); - foreach (RPMPersistence RPMMFD in RPMList) - { - ConfigNode RPMProp = new ConfigNode("Prop"); - RPMProp.AddValue("Prop ID", RPMMFD.RPMID); - RPMProp.AddValue("Mode", RPMMFD.RPMMode); - RPMProp.AddValue("Color", RPMMFD.RPMColor); - RPMProp.AddValue("Zoom", RPMMFD.RPMZoom); - RPMProp.AddValue("Lines", RPMMFD.RPMLines); - RPMPersistence.AddNode(RPMProp); - } - node.AddNode(RPMPersistence); - } - } - - public override string GetInfo() - { - if (sensorType == 0) - return ""; - - string str = base.GetInfo(); - if (min_alt != 0) - { - str += "Altitude ( min): " + (min_alt / 1000).ToString("F0") + " km\n"; - } - if (best_alt != min_alt) - { - str += "Altitude (best): " + (best_alt / 1000).ToString("F0") + " km\n"; - } - if (max_alt != 0) - { - str += "Altitude ( max): " + (max_alt / 1000).ToString("F0") + " km\n"; - } - if (fov != 0) - { - str += "FOV: " + fov.ToString("F0") + " °\n"; - } - str += "Power usage: " + power.ToString("F1") + " charge/s\n"; - return str; - } - - /* SAT: KSP fields */ - [KSPField] - public int sensorType; - [KSPField] - public float fov; - [KSPField] - public float min_alt; - [KSPField] - public float max_alt; - [KSPField] - public float best_alt; - [KSPField] - public float power; - [KSPField] - public string scanName; - [KSPField] - public string animationName; - [KSPField(guiName = "SCANsat Altitude", guiActive = false)] - public string alt_indicator; - internal List RPMList = new List(); - - /* SCAN: all of these fields and only scanning is persistant */ - [KSPField(isPersistant = true)] - protected bool scanning = false; - public bool scanningNow() { return scanning; } - - /* SCAN: context (right click) buttons in FLIGHT */ - [KSPEvent(guiActive = true, guiName = "Start RADAR Scan", active = true)] - public void startScan() - { - if (!ToolbarManager.ToolbarAvailable && SCANcontroller.controller != null) - { - if (!SCANcontroller.controller.useStockAppLauncher) - SCANcontroller.controller.mainMap.Visible = true; - } - registerScanner(); - animate(1, 0); - } - - [KSPEvent(guiActive = true, guiName = "Stop RADAR Scan", active = true)] - public void stopScan() - { - unregisterScanner(); - powerIsProblem = false; - animate(-1, 1); - } - - [KSPEvent(guiActive = true, guiName = "Analyze Data", active = true)] - public void analyze() - { - makeScienceData(true); - ReviewData(); - } - - [KSPEvent(guiActive = true, guiName = "Review Data", active = false)] - public void reviewEvent() - { - ReviewData(); - } - - [KSPEvent(guiActiveUnfocused = true, guiName = "Collect Stored Data", externalToEVAOnly = true, unfocusedRange = 1.5f, active = false)] - public void EVACollect() - { - List EVACont = FlightGlobals.ActiveVessel.FindPartModulesImplementing(); - if (storedData.Count > 0) - { - if (EVACont.First().StoreData(new List() { this }, false)) - { - foreach (ScienceData data in storedData) - DumpData(data); - } - } - } - - /* SCAN: context (right click) buttons in EDTIOR */ - [KSPEvent(guiActiveEditor = true, guiName = "Extend", active = true)] - public void editorExtend() - { - Events["editorExtend"].active = false; - Events["editorRetract"].active = true; - animate(1, 0); - } - - [KSPEvent(guiActiveEditor = true, guiName = "Retract", active = false)] - public void editorRetract() - { - Events["editorExtend"].active = true; - Events["editorRetract"].active = false; - animate(-1, 1); - } - - /* SCAN: trivial function to do animation */ - private void animate(float speed, float time) - { - if (anim != null && anim[animationName] != null) - { - anim[animationName].speed = speed; - if (anim.IsPlaying(animationName)) - { - if (anim[animationName].normalizedTime <= 0) - { - anim[animationName].normalizedTime = time; - } - else if (anim[animationName].normalizedTime >= 1 - float.Epsilon) - { - anim[animationName].normalizedTime = time; - } - } - else - { - anim[animationName].wrapMode = WrapMode.ClampForever; - anim[animationName].normalizedTime = time; - anim.Play(animationName); - } - } - } - - /* SCAN: actions for ... something ... */ - [KSPAction("Start Scan")] - public void startScanAction(KSPActionParam param) - { - startScan(); - } - - [KSPAction("Stop Scan")] - public void stopScanAction(KSPActionParam param) - { - stopScan(); - } - - [KSPAction("Toggle Scan")] - public void toggleScanAction(KSPActionParam param) - { - if (scanning) - stopScan(); - else - startScan(); - } - - [KSPAction("Analyze Data")] - public void analyzeData(KSPActionParam param) - { - //if (scanning) ** Always available - analyze(); - } - - /* SCAN: add static (a warning that we're low on electric charge) */ - private void addStatic() - { - SCANdata data = SCANUtil.getData(vessel.mainBody); - if (data == null) - return; - Texture2D map = data.Map; - if (map != null) - { - for (int i = 0; i < 1000; ++i) - { - map.SetPixel(UnityEngine.Random.Range(0, 360), UnityEngine.Random.Range(0, 180), palette.lerp(palette.black, palette.white, UnityEngine.Random.value)); - } - } - } - - /* SCAN: register scanners without going through animation */ - private void registerScanner() - { - scanning = true; - if (sensorType > 0 && SCANcontroller.controller != null) - SCANcontroller.controller.registerSensor(vessel, (SCANtype)sensorType, fov, min_alt, max_alt, best_alt); - } - - protected void unregisterScanner() - { - scanning = false; - if (sensorType > 0 && SCANcontroller.controller != null) - SCANcontroller.controller.unregisterSensor(vessel, (SCANtype)sensorType); - } - - private string scanAlt() - { - string altitude = "Unknown"; - if (vessel.altitude < min_alt) - altitude = "Too low"; - else if (vessel.altitude < best_alt) - altitude = "Sub-optimal"; - else if (vessel.altitude >= best_alt && vessel.altitude <= max_alt) - altitude = "Ideal"; - else if (vessel.altitude > max_alt) - altitude = "Too high"; - return altitude; - } - - /* SCAN: SCIENCE! make, store, transmit, keep - * discard, review, count DATA */ - private void makeScienceData(bool notZero) - { - if (expDialog != null) - DestroyImmediate(expDialog); - storedData.Clear(); - ScienceData sd = getAvailableScience((SCANtype)sensorType, notZero); - if (sd == null) - return; - storedData.Add(sd); - } - - private ScienceData getAvailableScience(SCANtype sensor, bool notZero) - { - SCANdata data = SCANUtil.getData(vessel.mainBody); - if (data == null) - return null; - ScienceData sd = null; - ScienceExperiment se = null; - ScienceSubject su = null; - bool found = false; - string id = null; - double coverage = 0f; - float multiplier = 1f; - - if (!found && (sensor & SCANtype.AltimetryLoRes) != SCANtype.Nothing) - { - found = true; - if (vessel.mainBody.pqsController == null) - multiplier = 0.5f; - id = "SCANsatAltimetryLoRes"; - coverage = SCANUtil.getCoveragePercentage(data, SCANtype.AltimetryLoRes); - } - else if (!found && (sensor & SCANtype.AltimetryHiRes) != SCANtype.Nothing) - { - found = true; - if (vessel.mainBody.pqsController == null) - multiplier = 0.5f; - id = "SCANsatAltimetryHiRes"; - coverage = SCANUtil.getCoveragePercentage(data, SCANtype.AltimetryHiRes); - } - else if (!found && (sensor & SCANtype.Biome) != SCANtype.Nothing) - { - found = true; - if (vessel.mainBody.BiomeMap == null) - multiplier = 0.5f; - id = "SCANsatBiomeAnomaly"; - coverage = SCANUtil.getCoveragePercentage(data, SCANtype.Biome); - } - if (!found) return null; - se = ResearchAndDevelopment.GetExperiment(id); - if (se == null) return null; - - su = ResearchAndDevelopment.GetExperimentSubject(se, ExperimentSituations.InSpaceHigh, vessel.mainBody, "surface"); - if (su == null) return null; - - su.scienceCap *= multiplier; - - SCANUtil.SCANlog("Coverage: {0}, Science cap: {1}, Subject value: {2}, Scientific value: {3}, Science: {4}", new object[5] { coverage.ToString("F1"), su.scienceCap.ToString("F1"), su.subjectValue.ToString("F2"), su.scientificValue.ToString("F2"), su.science.ToString("F2") }); - - su.scientificValue = 1; - - float science = (float)coverage; - if (science > 95) science = 100; - if (science < 30) science = 0; - science = science / 100f; - science = Mathf.Max(0, (science * su.scienceCap) - su.science); - - SCANUtil.SCANlog("Remaining science: {0}, Base value: {1}", new object[2] { science.ToString("F1"), se.baseValue.ToString("F1") }); - - science /= Mathf.Max(0.1f, su.scientificValue); //look 10 lines up; this is always 1... - science /= su.subjectValue; - - SCANUtil.SCANlog("Resulting science value: {0}", new object[1] { science.ToString("F2") }); - - if (notZero && science <= 0) science = 0.00001f; - - sd = new ScienceData(science * su.dataScale, 1f, 0f, su.id, se.experimentTitle + " of " + vessel.mainBody.theName); - su.title = sd.title; - return sd; - } - - public ScienceData[] GetData() - { - return storedData.ToArray(); - } - - private void KeepData(ScienceData data) - { - expDialog = null; - } - - private void TransmitData(ScienceData data) - { - expDialog = null; - List tranList = vessel.FindPartModulesImplementing(); - if (tranList.Count > 0 && storedData.Count > 0) - { - makeScienceData(false); - tranList.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(storedData); - DumpData(storedData[0]); - } - else ScreenMessages.PostScreenMessage("No transmitters available on this vessel.", 4f, ScreenMessageStyle.UPPER_LEFT); - } - - public void DumpData(ScienceData data) - { - expDialog = null; - while (storedData.Contains(data)) - { - storedData.Remove(data); - } - } - - public void ReviewDataItem(ScienceData sd) - { - ReviewData(); - } - - public void ReviewData() - { - if (storedData.Count < 1) - return; - if (expDialog != null) - DestroyImmediate(expDialog); - ScienceData sd = storedData[0]; - expDialog = ExperimentsResultDialog.DisplayResult(new ExperimentResultDialogPage(part, sd, 1f, 0f, false, "", true, false, DumpData, KeepData, TransmitData, null)); - } - - public bool IsRerunnable() - { - return true; - } - - public int GetScienceCount() - { - return storedData.Count; - } - } -} - From 33d3708ba23d64c11bd0932dd08372d039c66263 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 4 Jun 2015 15:21:24 -0400 Subject: [PATCH 091/117] Part Modules moved to new namespace --- SCANsat/SCAN_PartModules/SCANsat.cs | 570 ++++++++++++++++++++++++++++ SCANsat/SCAN_UI/SCANsatRPM.cs | 5 +- SCANsat/SCANcontroller.cs | 2 +- 3 files changed, 574 insertions(+), 3 deletions(-) create mode 100644 SCANsat/SCAN_PartModules/SCANsat.cs diff --git a/SCANsat/SCAN_PartModules/SCANsat.cs b/SCANsat/SCAN_PartModules/SCANsat.cs new file mode 100644 index 000000000..760a4dcca --- /dev/null +++ b/SCANsat/SCAN_PartModules/SCANsat.cs @@ -0,0 +1,570 @@ +#region license +/* [Scientific Committee on Advanced Navigation] + * S.C.A.N. Satellite + * + * SCANsat - SCAN RADAR Altimetry Sensor part (& More) + * + * Copyright (c)2013 damny; + * Copyright (c)2014 technogeeky ; + * Copyright (c)2014 (Your Name Here) ; see LICENSE.txt for licensing details. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using SCANsat.SCAN_Data; +using SCANsat.SCAN_Toolbar; +using SCANsat.SCAN_UI; + +using UnityEngine; +using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette; + +namespace SCANsat.SCAN_PartModules +{ + public class SCANsat : PartModule, IScienceDataContainer + { + private bool powerIsProblem; + private Animation anim = null; + private List storedData = new List(); + private ExperimentsResultDialog expDialog = null; + + /* SAT: KSP entry points */ + public override void OnStart(StartState state) + { + if (state == StartState.Editor) + { + print("[SCANsat] start: in editor"); + Events["editorExtend"].active = !string.IsNullOrEmpty(animationName); + } + else + { + print("[SCANsat] start: live"); + } + if (!string.IsNullOrEmpty(animationName)) + { + Animation[] a = part.FindModelAnimators(animationName); + if (a.Length == 0) + { + print("[SCANsat] animation '" + animationName + "' not found"); + } + else + { + print("[SCANsat] using animation #1 out of " + a.Length.ToString() + " animations named '" + animationName + "'"); + anim = a[0]; + } + } + if (scanName != null) + { // Use bitwise operators to check if the part has valid science collection scanners + if ((sensorType & (Int32)SCANtype.AltimetryLoRes) == 0 && (sensorType & (Int32)SCANtype.AltimetryHiRes) == 0 && (sensorType & (Int32)SCANtype.Biome) == 0) + { + Events["startScan"].guiName = "Start " + scanName; + Events["stopScan"].guiName = "Stop " + scanName; + Events["analyze"].active = false; + Actions["startScanAction"].guiName = "Start " + scanName; + Actions["stopScanAction"].guiName = "Stop " + scanName; + Actions["toggleScanAction"].guiName = "Toggle " + scanName; + Actions["analyzeData"].active = false; + } + else + { + Events["startScan"].guiName = "Start " + scanName; + Events["stopScan"].guiName = "Stop " + scanName; + Events["analyze"].active = true; + Actions["startScanAction"].guiName = "Start " + scanName; + Actions["stopScanAction"].guiName = "Stop " + scanName; + Actions["toggleScanAction"].guiName = "Toggle " + scanName; + } + } + + if (sensorType == 0) + { + // here, we override all event and action labels + // and we also disable the analyze button (it does nothing) + Events["startScan"].active = false; + Events["stopScan"].active = false; + Events["analyze"].active = false; + Events["editorExtend"].active = false; + Actions["startScanAction"].active = false; + Actions["stopScanAction"].active = false; + Actions["toggleScanAction"].active = false; + Actions["analyzeData"].active = false; + } + else if (sensorType == 32) + { + // here, we only disable analyze; BTDT has good labels + Events["analyze"].active = false; + Actions["analyzeData"].active = false; + } + if (scanning) animate(1, 1); + powerIsProblem = false; + print("[SCANsat] sensorType: " + sensorType.ToString() + " fov: " + fov.ToString() + " min_alt: " + min_alt.ToString() + " max_alt: " + max_alt.ToString() + " best_alt: " + best_alt.ToString() + " power: " + power.ToString()); + } + + public override void OnUpdate() + { + if (sensorType == 0) + return; + + Events["reviewEvent"].active = storedData.Count > 0; + Events["EVACollect"].active = storedData.Count > 0; + Events["startScan"].active = !scanning; + Events["stopScan"].active = scanning; + if (sensorType != 32) + Fields["alt_indicator"].guiActive = scanning; + if (scanning) + { + if (SCANcontroller.controller == null) + { + scanning = false; + Debug.LogError("[SCANsat] Warning: SCANsat scenario module not initialized; Shutting down"); + } + else + { + if (sensorType != 0 || SCANcontroller.controller.isVesselKnown(vessel.id, (SCANtype)sensorType)) + { + if (TimeWarp.CurrentRate < 1500) + { + float p = power * TimeWarp.deltaTime; + float e = part.RequestResource("ElectricCharge", p); + if (e < p) + { + unregisterScanner(); + powerIsProblem = true; + } + else + { + registerScanner(); + powerIsProblem = false; + } + } + else if (powerIsProblem) + { + registerScanner(); + powerIsProblem = false; + } + } + else + unregisterScanner(); + alt_indicator = scanAlt(); + } + } + if (vessel == FlightGlobals.ActiveVessel) + { + if (powerIsProblem) + { + addStatic(); + registerScanner(); + } + } + } + + public override void OnLoad(ConfigNode node) + { + if (node.HasNode("ScienceData")) + { + foreach (ConfigNode storedDataNode in node.GetNodes("ScienceData")) + { + ScienceData data = new ScienceData(storedDataNode); + storedData.Add(data); + } + } + if (node.HasNode("SCANsatRPM")) + { + ConfigNode RPMPersistence = node.GetNode("SCANsatRPM"); + foreach (ConfigNode RPMNode in RPMPersistence.GetNodes("Prop")) + { + string id = RPMNode.GetValue("Prop ID"); + int Mode = Convert.ToInt32(RPMNode.GetValue("Mode")); + int Color = Convert.ToInt32(RPMNode.GetValue("Color")); + int Zoom = Convert.ToInt32(RPMNode.GetValue("Zoom")); + bool Lines = Convert.ToBoolean(RPMNode.GetValue("Lines")); + RPMList.Add(new RPMPersistence(id, Mode, Color, Zoom, Lines)); + } + } + } + + public override void OnSave(ConfigNode node) + { + node.RemoveNodes("ScienceData"); //** Prevent duplicates + foreach (ScienceData SCANData in storedData) + { + ConfigNode storedDataNode = node.AddNode("ScienceData"); + SCANData.Save(storedDataNode); + } + if (RPMList.Count > 0) + { + ConfigNode RPMPersistence = new ConfigNode("SCANsatRPM"); + foreach (RPMPersistence RPMMFD in RPMList) + { + ConfigNode RPMProp = new ConfigNode("Prop"); + RPMProp.AddValue("Prop ID", RPMMFD.RPMID); + RPMProp.AddValue("Mode", RPMMFD.RPMMode); + RPMProp.AddValue("Color", RPMMFD.RPMColor); + RPMProp.AddValue("Zoom", RPMMFD.RPMZoom); + RPMProp.AddValue("Lines", RPMMFD.RPMLines); + RPMPersistence.AddNode(RPMProp); + } + node.AddNode(RPMPersistence); + } + } + + public override string GetInfo() + { + if (sensorType == 0) + return ""; + + string str = base.GetInfo(); + if (min_alt != 0) + { + str += "Altitude ( min): " + (min_alt / 1000).ToString("F0") + " km\n"; + } + if (best_alt != min_alt) + { + str += "Altitude (best): " + (best_alt / 1000).ToString("F0") + " km\n"; + } + if (max_alt != 0) + { + str += "Altitude ( max): " + (max_alt / 1000).ToString("F0") + " km\n"; + } + if (fov != 0) + { + str += "FOV: " + fov.ToString("F0") + " °\n"; + } + str += "Power usage: " + power.ToString("F1") + " charge/s\n"; + return str; + } + + /* SAT: KSP fields */ + [KSPField] + public int sensorType; + [KSPField] + public float fov; + [KSPField] + public float min_alt; + [KSPField] + public float max_alt; + [KSPField] + public float best_alt; + [KSPField] + public float power; + [KSPField] + public string scanName; + [KSPField] + public string animationName; + [KSPField(guiName = "SCANsat Altitude", guiActive = false)] + public string alt_indicator; + internal List RPMList = new List(); + + /* SCAN: all of these fields and only scanning is persistant */ + [KSPField(isPersistant = true)] + protected bool scanning = false; + public bool scanningNow() { return scanning; } + + /* SCAN: context (right click) buttons in FLIGHT */ + [KSPEvent(guiActive = true, guiName = "Start RADAR Scan", active = true)] + public void startScan() + { + if (!ToolbarManager.ToolbarAvailable && SCANcontroller.controller != null) + { + if (!SCANcontroller.controller.useStockAppLauncher) + SCANcontroller.controller.mainMap.Visible = true; + } + registerScanner(); + animate(1, 0); + } + + [KSPEvent(guiActive = true, guiName = "Stop RADAR Scan", active = true)] + public void stopScan() + { + unregisterScanner(); + powerIsProblem = false; + animate(-1, 1); + } + + [KSPEvent(guiActive = true, guiName = "Analyze Data", active = true)] + public void analyze() + { + makeScienceData(true); + ReviewData(); + } + + [KSPEvent(guiActive = true, guiName = "Review Data", active = false)] + public void reviewEvent() + { + ReviewData(); + } + + [KSPEvent(guiActiveUnfocused = true, guiName = "Collect Stored Data", externalToEVAOnly = true, unfocusedRange = 1.5f, active = false)] + public void EVACollect() + { + List EVACont = FlightGlobals.ActiveVessel.FindPartModulesImplementing(); + if (storedData.Count > 0) + { + if (EVACont.First().StoreData(new List() { this }, false)) + { + foreach (ScienceData data in storedData) + DumpData(data); + } + } + } + + /* SCAN: context (right click) buttons in EDTIOR */ + [KSPEvent(guiActiveEditor = true, guiName = "Extend", active = true)] + public void editorExtend() + { + Events["editorExtend"].active = false; + Events["editorRetract"].active = true; + animate(1, 0); + } + + [KSPEvent(guiActiveEditor = true, guiName = "Retract", active = false)] + public void editorRetract() + { + Events["editorExtend"].active = true; + Events["editorRetract"].active = false; + animate(-1, 1); + } + + /* SCAN: trivial function to do animation */ + private void animate(float speed, float time) + { + if (anim != null && anim[animationName] != null) + { + anim[animationName].speed = speed; + if (anim.IsPlaying(animationName)) + { + if (anim[animationName].normalizedTime <= 0) + { + anim[animationName].normalizedTime = time; + } + else if (anim[animationName].normalizedTime >= 1 - float.Epsilon) + { + anim[animationName].normalizedTime = time; + } + } + else + { + anim[animationName].wrapMode = WrapMode.ClampForever; + anim[animationName].normalizedTime = time; + anim.Play(animationName); + } + } + } + + /* SCAN: actions for ... something ... */ + [KSPAction("Start Scan")] + public void startScanAction(KSPActionParam param) + { + startScan(); + } + + [KSPAction("Stop Scan")] + public void stopScanAction(KSPActionParam param) + { + stopScan(); + } + + [KSPAction("Toggle Scan")] + public void toggleScanAction(KSPActionParam param) + { + if (scanning) + stopScan(); + else + startScan(); + } + + [KSPAction("Analyze Data")] + public void analyzeData(KSPActionParam param) + { + //if (scanning) ** Always available + analyze(); + } + + /* SCAN: add static (a warning that we're low on electric charge) */ + private void addStatic() + { + SCANdata data = SCANUtil.getData(vessel.mainBody); + if (data == null) + return; + Texture2D map = data.Map; + if (map != null) + { + for (int i = 0; i < 1000; ++i) + { + map.SetPixel(UnityEngine.Random.Range(0, 360), UnityEngine.Random.Range(0, 180), palette.lerp(palette.black, palette.white, UnityEngine.Random.value)); + } + } + } + + /* SCAN: register scanners without going through animation */ + private void registerScanner() + { + scanning = true; + if (sensorType > 0 && SCANcontroller.controller != null) + SCANcontroller.controller.registerSensor(vessel, (SCANtype)sensorType, fov, min_alt, max_alt, best_alt); + } + + protected void unregisterScanner() + { + scanning = false; + if (sensorType > 0 && SCANcontroller.controller != null) + SCANcontroller.controller.unregisterSensor(vessel, (SCANtype)sensorType); + } + + private string scanAlt() + { + string altitude = "Unknown"; + if (vessel.altitude < min_alt) + altitude = "Too low"; + else if (vessel.altitude < best_alt) + altitude = "Sub-optimal"; + else if (vessel.altitude >= best_alt && vessel.altitude <= max_alt) + altitude = "Ideal"; + else if (vessel.altitude > max_alt) + altitude = "Too high"; + return altitude; + } + + /* SCAN: SCIENCE! make, store, transmit, keep + * discard, review, count DATA */ + private void makeScienceData(bool notZero) + { + if (expDialog != null) + DestroyImmediate(expDialog); + storedData.Clear(); + ScienceData sd = getAvailableScience((SCANtype)sensorType, notZero); + if (sd == null) + return; + storedData.Add(sd); + } + + private ScienceData getAvailableScience(SCANtype sensor, bool notZero) + { + SCANdata data = SCANUtil.getData(vessel.mainBody); + if (data == null) + return null; + ScienceData sd = null; + ScienceExperiment se = null; + ScienceSubject su = null; + bool found = false; + string id = null; + double coverage = 0f; + float multiplier = 1f; + + if (!found && (sensor & SCANtype.AltimetryLoRes) != SCANtype.Nothing) + { + found = true; + if (vessel.mainBody.pqsController == null) + multiplier = 0.5f; + id = "SCANsatAltimetryLoRes"; + coverage = SCANUtil.getCoveragePercentage(data, SCANtype.AltimetryLoRes); + } + else if (!found && (sensor & SCANtype.AltimetryHiRes) != SCANtype.Nothing) + { + found = true; + if (vessel.mainBody.pqsController == null) + multiplier = 0.5f; + id = "SCANsatAltimetryHiRes"; + coverage = SCANUtil.getCoveragePercentage(data, SCANtype.AltimetryHiRes); + } + else if (!found && (sensor & SCANtype.Biome) != SCANtype.Nothing) + { + found = true; + if (vessel.mainBody.BiomeMap == null) + multiplier = 0.5f; + id = "SCANsatBiomeAnomaly"; + coverage = SCANUtil.getCoveragePercentage(data, SCANtype.Biome); + } + if (!found) return null; + se = ResearchAndDevelopment.GetExperiment(id); + if (se == null) return null; + + su = ResearchAndDevelopment.GetExperimentSubject(se, ExperimentSituations.InSpaceHigh, vessel.mainBody, "surface"); + if (su == null) return null; + + su.scienceCap *= multiplier; + + SCANUtil.SCANlog("Coverage: {0}, Science cap: {1}, Subject value: {2}, Scientific value: {3}, Science: {4}", new object[5] { coverage.ToString("F1"), su.scienceCap.ToString("F1"), su.subjectValue.ToString("F2"), su.scientificValue.ToString("F2"), su.science.ToString("F2") }); + + su.scientificValue = 1; + + float science = (float)coverage; + if (science > 95) science = 100; + if (science < 30) science = 0; + science = science / 100f; + science = Mathf.Max(0, (science * su.scienceCap) - su.science); + + SCANUtil.SCANlog("Remaining science: {0}, Base value: {1}", new object[2] { science.ToString("F1"), se.baseValue.ToString("F1") }); + + science /= Mathf.Max(0.1f, su.scientificValue); //look 10 lines up; this is always 1... + science /= su.subjectValue; + + SCANUtil.SCANlog("Resulting science value: {0}", new object[1] { science.ToString("F2") }); + + if (notZero && science <= 0) science = 0.00001f; + + sd = new ScienceData(science * su.dataScale, 1f, 0f, su.id, se.experimentTitle + " of " + vessel.mainBody.theName); + su.title = sd.title; + return sd; + } + + public ScienceData[] GetData() + { + return storedData.ToArray(); + } + + private void KeepData(ScienceData data) + { + expDialog = null; + } + + private void TransmitData(ScienceData data) + { + expDialog = null; + List tranList = vessel.FindPartModulesImplementing(); + if (tranList.Count > 0 && storedData.Count > 0) + { + makeScienceData(false); + tranList.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(storedData); + DumpData(storedData[0]); + } + else ScreenMessages.PostScreenMessage("No transmitters available on this vessel.", 4f, ScreenMessageStyle.UPPER_LEFT); + } + + public void DumpData(ScienceData data) + { + expDialog = null; + while (storedData.Contains(data)) + { + storedData.Remove(data); + } + } + + public void ReviewDataItem(ScienceData sd) + { + ReviewData(); + } + + public void ReviewData() + { + if (storedData.Count < 1) + return; + if (expDialog != null) + DestroyImmediate(expDialog); + ScienceData sd = storedData[0]; + expDialog = ExperimentsResultDialog.DisplayResult(new ExperimentResultDialogPage(part, sd, 1f, 0f, false, "", true, false, DumpData, KeepData, TransmitData, null)); + } + + public bool IsRerunnable() + { + return true; + } + + public int GetScienceCount() + { + return storedData.Count; + } + } +} + diff --git a/SCANsat/SCAN_UI/SCANsatRPM.cs b/SCANsat/SCAN_UI/SCANsatRPM.cs index b5e8714d2..865853d77 100644 --- a/SCANsat/SCAN_UI/SCANsatRPM.cs +++ b/SCANsat/SCAN_UI/SCANsatRPM.cs @@ -22,6 +22,7 @@ using System.Globalization; using SCANsat.SCAN_Map; using SCANsat.SCAN_Data; +using SCANsat.SCAN_PartModules; using SCANsat.SCAN_UI.UI_Framework; namespace SCANsat.SCAN_UI @@ -109,7 +110,7 @@ public class JSISCANsatRPM: InternalModule private SCANanomaly[] localAnomalies; private List localWaypoints; private Material iconMaterial; - private SCANsat sat; + private SCANsat.SCAN_PartModules.SCANsat sat; internal RPMPersistence persist; private string persistentVarName; private double pixelsPerKm; @@ -667,7 +668,7 @@ private void Start() persistentVarName = "scansat" + internalProp.propID; try { - sat = part.FindModulesImplementing().First(); + sat = part.FindModulesImplementing().First(); } catch { Debug.LogWarning("[SCANsatRPM] SCANsat module not attached to this IVA, check for Module Manager problems and make sure the RPMMapTraq.cfg file is in the SCANsat/MMconfigs folder"); diff --git a/SCANsat/SCANcontroller.cs b/SCANsat/SCANcontroller.cs index 6c05b7c7b..47c37bb0f 100644 --- a/SCANsat/SCANcontroller.cs +++ b/SCANsat/SCANcontroller.cs @@ -970,7 +970,7 @@ private void removeVessel(Vessel v) private void addVessel(Vessel v) { - foreach (SCANsat s in v.FindPartModulesImplementing()) + foreach (SCANsat.SCAN_PartModules.SCANsat s in v.FindPartModulesImplementing()) { if (s.scanningNow()) registerSensor(v.id, (SCANtype)s.sensorType, s.fov, s.min_alt, s.max_alt, s.best_alt); From 5ebd673e0ec988514a99674e3d68deb48d0b8b0b Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 4 Jun 2015 15:21:46 -0400 Subject: [PATCH 092/117] Explicit biome unlock check --- SCANsat/SCAN_Map/SCANmap.cs | 2 +- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 10 +++++----- SCANsat/SCANutil.cs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index 18878d9b3..a5ce2a54a 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -585,7 +585,7 @@ internal Texture2D getPartialMap() double rLon = (i * 1.0f / resourceMapScale) - 180f + lon_offset; double rLat = (j * 1.0f / resourceMapScale) - 90f + lat_offset; - resourceCache[i, j] = SCANUtil.ResourceOverlay(rLat, rLon, resource.Name, body) * 100f; + resourceCache[i, j] = SCANUtil.ResourceOverlay(rLat, rLon, resource.Name, body, SCANcontroller.controller.resourceBiomeLock) * 100f; } } mapstep++; diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 41ffca86d..3296d725e 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -161,13 +161,13 @@ internal static void mouseOverInfo(double lon, double lat, SCANmap mapObj, SCANd string label = ""; if (SCANUtil.isCovered(lon, lat, data, SCANtype.FuzzyResources)) { - int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body)) * 100f); + int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock)) * 100f); label = amount.ToString() + "%"; info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); } else if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) { - double amount = SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body); + double amount = SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock); if (amount < 0) label = "Unknown"; else @@ -245,13 +245,13 @@ internal static void mouseOverInfoSimple(double lon, double lat, SCANmap mapObj, string label = ""; if (SCANUtil.isCovered(lon, lat, data, SCANtype.FuzzyResources)) { - int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body)) * 100f); + int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock)) * 100f); label = amount.ToString() + "%"; info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); } else if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) { - double amount = SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body); + double amount = SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock); if (amount < 0) label = "Unknown"; else @@ -1395,7 +1395,7 @@ internal static Texture2D drawResourceTexture(Texture2D map, int height, SCANdat double lon = fixLon(i / scale); double lat = (j / scale) - 90; - abundanceValues[i, j] = SCANUtil.ResourceOverlay(lat, lon, resource.Name, data.Body) * 100; + abundanceValues[i, j] = SCANUtil.ResourceOverlay(lat, lon, resource.Name, data.Body, SCANcontroller.controller.resourceBiomeLock) * 100; pix[j * width + i] = resourceToColor32(palette.Clear, resource, abundanceValues[i, j], data, lon, lat, transparency); } diff --git a/SCANsat/SCANutil.cs b/SCANsat/SCANutil.cs index 15ee2799d..48e74adf1 100644 --- a/SCANsat/SCANutil.cs +++ b/SCANsat/SCANutil.cs @@ -318,7 +318,7 @@ internal static double getElevation(this CelestialBody body, Vector3d worldPosit return ret; } - internal static float ResourceOverlay(double lat, double lon, string name, CelestialBody body) + internal static float ResourceOverlay(double lat, double lon, string name, CelestialBody body, bool biomeLock) { float amount = 0f; var aRequest = new AbundanceRequest @@ -329,7 +329,7 @@ internal static float ResourceOverlay(double lat, double lon, string name, Celes ResourceName = name, ResourceType = HarvestTypes.Planetary, Altitude = 0, - CheckForLock = SCANcontroller.controller.resourceBiomeLock, + CheckForLock = biomeLock, BiomeName = getBiomeName(body, lon, lat), ExcludeVariance = false, }; From ff73e3d3d744901901fa9e8570bd1d61b797c9c2 Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 4 Jun 2015 15:22:10 -0400 Subject: [PATCH 093/117] New namespace; a few changes to disabling stock modules --- .../SCAN_PartModules/SCANresourceScanner.cs | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 SCANsat/SCAN_PartModules/SCANresourceScanner.cs diff --git a/SCANsat/SCAN_PartModules/SCANresourceScanner.cs b/SCANsat/SCAN_PartModules/SCANresourceScanner.cs new file mode 100644 index 000000000..92d415391 --- /dev/null +++ b/SCANsat/SCAN_PartModules/SCANresourceScanner.cs @@ -0,0 +1,212 @@ +#region license +/* [Scientific Committee on Advanced Navigation] + * S.C.A.N. Satellite + * + * SCANresourceScanner - Resource scanner part module + * + * Copyright (c)2013 damny; + * Copyright (c)2014 technogeeky ; + * Copyright (c)2014 DMagic + * Copyright (c)2014 (Your Name Here) ; see LICENSE.txt for licensing details. + */ +#endregion + +using System.Collections.Generic; +using System.Linq; +using SCANsat.SCAN_Data; + +namespace SCANsat.SCAN_PartModules +{ + public class ModuleSCANresourceScanner : SCANsat, IAnimatedModule + { + private List mSurvey; + private List mScanner; + private ModuleAnimationGroup animGroup; + private bool activated; + + public override void OnStart(PartModule.StartState state) + { + base.OnStart(state); + + Actions["startScanAction"].active = false; + Actions["stopScanAction"].active = false; + Actions["toggleScanAction"].active = false; + Actions["startResourceScanAction"].guiName = "Start " + scanName; + Actions["stopResourceScanAction"].guiName = "Stop " + scanName; + Actions["toggleResourceScanAction"].guiName = "Toggle " + scanName; + + if (state == StartState.Editor) + return; + + mSurvey = findSurvey(); + mScanner = findScanner(); + animGroup = findAnimator(); + + if (animGroup == null) + activated = true; + + if (SCANcontroller.controller.disableStockResource) + { + if (mSurvey != null) + { + foreach (ModuleOrbitalSurveyor m in mSurvey) + m.DisableModule(); + } + + if (mScanner != null) + { + foreach (ModuleOrbitalScanner m in mScanner) + m.DisableModule(); + } + } + } + + public override string GetInfo() + { + string info = base.GetInfo(); + info += "Resource Scan: " + (SCANtype)sensorType + "\n"; + + return info; + } + + private List findScanner() + { + return part.FindModulesImplementing(); + } + + private List findSurvey() + { + return part.FindModulesImplementing(); + } + + private ModuleAnimationGroup findAnimator() + { + return part.FindModulesImplementing().FirstOrDefault(); + } + + private void updateEvents() + { + base.Events["startScan"].active = !scanning; + base.Events["stopScan"].active = scanning; + } + + public void Update() + { + base.OnUpdate(); + + if (!activated) + { + base.Events["startScan"].active = false; + base.Events["stopScan"].active = false; + if (scanning) + unregisterScanner(); + return; + } + + if (!HighLogic.LoadedSceneIsFlight) + return; + + if (!FlightGlobals.ready) + return; + + if (SCANcontroller.controller == null) + return; + + if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) + updateEvents(); + else + { + base.Events["startScan"].active = false; + base.Events["stopScan"].active = false; + if (scanning) + unregisterScanner(); + } + } + + [KSPAction("Start Resource Scan")] + public void startResourceScanAction(KSPActionParam param) + { + if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) + { + if (animGroup != null && !scanning && !animGroup.isDeployed) + animGroup.DeployModule(); + startScan(); + } + } + + [KSPAction("Stop Resource Scan")] + public void stopResourceScanAction(KSPActionParam param) + { + stopScan(); + } + + [KSPAction("Toggle Resource Scan")] + public void toggleResourceScanAction(KSPActionParam param) + { + if (scanning) + stopScan(); + else + { + if (!SCANcontroller.controller.easyModeScanning || SCANcontroller.controller.disableStockResource) + { + if (animGroup != null && !animGroup.isDeployed) + animGroup.DeployModule(); + startScan(); + } + } + } + + public void DisableModule() + { + activated = false; + base.Events["startScan"].active = false; + base.Events["stopScan"].active = false; + if (scanning) + unregisterScanner(); + + if (SCANcontroller.controller.disableStockResource) + { + if (mSurvey != null) + { + foreach (ModuleOrbitalSurveyor m in mSurvey) + m.DisableModule(); + } + + if (mScanner != null) + { + foreach (ModuleOrbitalScanner m in mScanner) + m.DisableModule(); + } + } + } + + public void EnableModule() + { + activated = true; + if (SCANcontroller.controller.disableStockResource) + { + if (mSurvey != null) + { + foreach (ModuleOrbitalSurveyor m in mSurvey) + m.DisableModule(); + } + + if (mScanner != null) + { + foreach (ModuleOrbitalScanner m in mScanner) + m.DisableModule(); + } + } + } + + public bool IsSituationValid() + { + return true; + } + + public bool ModuleIsActive() + { + return activated; + } + } +} From b86509fd2f8745ab0efeb47c41b3b59b32a1cd1e Mon Sep 17 00:00:00 2001 From: DMagic Date: Thu, 4 Jun 2015 15:22:29 -0400 Subject: [PATCH 094/117] New module for narrow-band scanner resource displays --- .../SCAN_PartModules/SCANresourceDisplay.cs | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 SCANsat/SCAN_PartModules/SCANresourceDisplay.cs diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs new file mode 100644 index 000000000..7818c7e8d --- /dev/null +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SCANsat.SCAN_Data; + + +namespace SCANsat.SCAN_PartModules +{ + class SCANresourceDisplay : ModuleResourceScanner, IAnimatedModule + { + [KSPField] + public int sensorType; + + private List stockScanners; + private bool tooHigh; + private bool fuzzy; + + public override void OnStart(PartModule.StartState state) + { + if (state == StartState.Editor) + return; + + this.enabled = true; + + stockScanners = findScanners(); + + setupFields(stockScanners.FirstOrDefault()); + + if (stockScanners != null && SCANcontroller.controller.disableStockResource) + { + foreach (ModuleResourceScanner m in stockScanners) + { + m.DisableModule(); + } + } + } + + private List findScanners() + { + return part.FindModulesImplementing().Where(r => r.ScannerType == 0 && r.ResourceName == ResourceName).ToList(); + } + + private void setupFields(ModuleResourceScanner m) + { + if (m != null) + { + MaxAbundanceAltitude = m.MaxAbundanceAltitude; + RequiresUnlock = m.RequiresUnlock; + } + else + { + MaxAbundanceAltitude = 250000; + RequiresUnlock = true; + } + } + + public override void OnUpdate() + { + if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready) + return; + + if (!SCANcontroller.controller.disableStockResource) + { + Fields["abundanceDisplay"].guiActive = false; + return; + } + + Fields["abundanceDisplay"].guiActive = true; + + if (tooHigh) + abundanceDisplay = string.Format("{0}: Too High", ResourceName); + else if (abundanceValue < 0) + abundanceDisplay = string.Format("{0}: No Data", ResourceName); + else if (fuzzy) + abundanceDisplay = string.Format("{0}: {1:P0}", ResourceName, abundanceValue); + else + abundanceDisplay = string.Format("{0}: {1:P2}", ResourceName, abundanceValue); + } + + public override void OnFixedUpdate() + { + if (vessel.altitude > MaxAbundanceAltitude) + { + tooHigh = true; + return; + } + + tooHigh = false; + double lat = SCANUtil.fixLatShift(vessel.latitude); + double lon = SCANUtil.fixLonShift(vessel.longitude); + if (SCANUtil.isCovered(lon, lat, vessel.mainBody, sensorType)) + { + abundanceValue = SCANUtil.ResourceOverlay(lat, lon, ResourceName, vessel.mainBody, RequiresUnlock && SCANcontroller.controller.resourceBiomeLock); + fuzzy = false; + } + else if (SCANUtil.isCovered(lon, lat, vessel.mainBody, 524288)) + { + abundanceValue = SCANUtil.ResourceOverlay(lat, lon, ResourceName, vessel.mainBody, RequiresUnlock && SCANcontroller.controller.resourceBiomeLock); + fuzzy = true; + } + else + { + abundanceValue = -1; + } + } + + void IAnimatedModule.EnableModule() + { + this.enabled = true; + if (stockScanners != null && SCANcontroller.controller.disableStockResource) + { + foreach (ModuleResourceScanner m in stockScanners) + { + m.DisableModule(); + } + } + } + + void IAnimatedModule.DisableModule() + { + this.enabled = false; + if (stockScanners != null && SCANcontroller.controller.disableStockResource) + { + foreach (ModuleResourceScanner m in stockScanners) + { + m.DisableModule(); + } + } + } + + bool IAnimatedModule.ModuleIsActive() + { + return isEnabled; + } + + bool IAnimatedModule.IsSituationValid() + { + return true; + } + } +} From 9bccaffd986f9a78c16c3c075afbd932986c8358 Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 00:26:39 -0400 Subject: [PATCH 095/117] New class; change namespace --- SCANsat/SCANsat.csproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SCANsat/SCANsat.csproj b/SCANsat/SCANsat.csproj index acd2340e6..63d716afa 100644 --- a/SCANsat/SCANsat.csproj +++ b/SCANsat/SCANsat.csproj @@ -47,7 +47,6 @@ - @@ -61,6 +60,9 @@ + + + Code @@ -104,7 +106,6 @@ - From 4ac2fb2f87eb289830095539971cbc45324c5de6 Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 00:26:49 -0400 Subject: [PATCH 096/117] Fix scaling with resource map --- SCANsat/SCAN_Map/SCANmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCANsat/SCAN_Map/SCANmap.cs b/SCANsat/SCAN_Map/SCANmap.cs index a5ce2a54a..1d52c0bb5 100644 --- a/SCANsat/SCAN_Map/SCANmap.cs +++ b/SCANsat/SCAN_Map/SCANmap.cs @@ -50,7 +50,7 @@ public double MapScale internal set { mapscale = value; - resourceMapScale = (resourceMapWidth / 360f) * mapscale; + resourceMapScale = (mapwidth / resourceMapWidth) * mapscale; } } From c38d83a26418be824f7db1dfd976dc3c109de0f9 Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 00:27:02 -0400 Subject: [PATCH 097/117] Fix low-res resource readout --- SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs index 3296d725e..baa146f24 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANuiUtil.cs @@ -159,13 +159,8 @@ internal static void mouseOverInfo(double lon, double lat, SCANmap mapObj, SCANd if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && mapObj.Resource != null) //Adds selected resource amount to big map legend { string label = ""; - if (SCANUtil.isCovered(lon, lat, data, SCANtype.FuzzyResources)) - { - int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock)) * 100f); - label = amount.ToString() + "%"; - info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); - } - else if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) + + if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) { double amount = SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock); if (amount < 0) @@ -178,6 +173,12 @@ internal static void mouseOverInfo(double lon, double lat, SCANmap mapObj, SCANd } info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); } + else if (SCANUtil.isCovered(lon, lat, data, SCANtype.FuzzyResources)) + { + int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock)) * 100f); + label = amount.ToString() + "%"; + info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); + } } if (SCANcontroller.controller.map_waypoints && WaypointManager.Instance() != null) @@ -243,13 +244,7 @@ internal static void mouseOverInfoSimple(double lon, double lat, SCANmap mapObj, if (SCANcontroller.controller.map_ResourceOverlay && SCANconfigLoader.GlobalResource && mapObj.Resource != null) //Adds selected resource amount to big map legend { string label = ""; - if (SCANUtil.isCovered(lon, lat, data, SCANtype.FuzzyResources)) - { - int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock)) * 100f); - label = amount.ToString() + "%"; - info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); - } - else if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) + if (SCANUtil.isCovered(lon, lat, data, mapObj.Resource.SType)) { double amount = SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock); if (amount < 0) @@ -262,6 +257,12 @@ internal static void mouseOverInfoSimple(double lon, double lat, SCANmap mapObj, } info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); } + else if (SCANUtil.isCovered(lon, lat, data, SCANtype.FuzzyResources)) + { + int amount = Mathf.RoundToInt(((float)SCANUtil.ResourceOverlay(lat, lon, mapObj.Resource.Name, mapObj.Body, SCANcontroller.controller.resourceBiomeLock)) * 100f); + label = amount.ToString() + "%"; + info += palette.colored(mapObj.Resource.MaxColor, mapObj.Resource.Name + ": " + label + " "); + } } if (SCANcontroller.controller.map_waypoints && WaypointManager.Instance() != null) From 9497fb3736e0e002aef2fd038e5ea58279249552 Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 00:27:19 -0400 Subject: [PATCH 098/117] Still working on resource display readout --- SCANsat/SCAN_PartModules/SCANresourceDisplay.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs index 7818c7e8d..1a5cb9111 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -68,13 +68,13 @@ public override void OnUpdate() Fields["abundanceDisplay"].guiActive = true; if (tooHigh) - abundanceDisplay = string.Format("{0}: Too High", ResourceName); + abundanceDisplay = string.Format("{0}[Surf]: Too High", ResourceName); else if (abundanceValue < 0) - abundanceDisplay = string.Format("{0}: No Data", ResourceName); + abundanceDisplay = string.Format("{0}[Surf]: No Data", ResourceName); else if (fuzzy) - abundanceDisplay = string.Format("{0}: {1:P0}", ResourceName, abundanceValue); + abundanceDisplay = string.Format("{0}[Surf]: {1:P0}", ResourceName, abundanceValue); else - abundanceDisplay = string.Format("{0}: {1:P2}", ResourceName, abundanceValue); + abundanceDisplay = string.Format("{0}[Surf]: {1:P2}", ResourceName, abundanceValue); } public override void OnFixedUpdate() From b71c01aa5bbd8d0f96911f13a7ba0b15871db131 Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 12:15:10 -0400 Subject: [PATCH 099/117] Helium 3 configs --- SCANassets/Resources/SCANcolors.cfg | 164 ++++++++++++++++++++++++-- SCANassets/Resources/SCANresource.cfg | 5 + 2 files changed, 161 insertions(+), 8 deletions(-) diff --git a/SCANassets/Resources/SCANcolors.cfg b/SCANassets/Resources/SCANcolors.cfg index f107c2f19..63a4a2ce3 100644 --- a/SCANassets/Resources/SCANcolors.cfg +++ b/SCANassets/Resources/SCANcolors.cfg @@ -7,7 +7,7 @@ SCAN_Color_Config defaultPalette = Default lowBiomeColor = 0,0.46,0.02345098,1 highBiomeColor = 0.7,0.2388235,0,1 - biomeTransparency = 30 + biomeTransparency = 25 stockBiomeMap = False bottomLowSlopeColor = 0.004705883,0.6,0.3788235,1 bottemHighSlopeColor = 0.9764706,1,0.4627451,1 @@ -229,7 +229,7 @@ SCAN_Color_Config highResourceColor = 0.7888628,0,0.94,1 resourceTransparency = 20 defaultMinValue = 1 - defaultMaxValue = 7.5 + defaultMaxValue = 15 Resource_Planetary_Config { Item @@ -377,7 +377,7 @@ SCAN_Color_Config highResourceColor = 0.75,0.3823529,0,1 resourceTransparency = 20 defaultMinValue = 1 - defaultMaxValue = 7.5 + defaultMaxValue = 10 Resource_Planetary_Config { Item @@ -525,7 +525,7 @@ SCAN_Color_Config highResourceColor = 0,0.576471,0.07451,1 resourceTransparency = 20 defaultMinValue = 1 - defaultMaxValue = 7.5 + defaultMaxValue = 10 Resource_Planetary_Config { Item @@ -673,7 +673,7 @@ SCAN_Color_Config highResourceColor = 0.7428235,0.82,0,1 resourceTransparency = 20 defaultMinValue = 1 - defaultMaxValue = 7.5 + defaultMaxValue = 10 Resource_Planetary_Config { Item @@ -821,7 +821,7 @@ SCAN_Color_Config highResourceColor = 1,0.2352941,0.03137255,1 resourceTransparency = 20 defaultMinValue = 1 - defaultMaxValue = 7.5 + defaultMaxValue = 10 Resource_Planetary_Config { Item @@ -969,7 +969,7 @@ SCAN_Color_Config highResourceColor = 0,0.5687844,0.98,1 resourceTransparency = 20 defaultMinValue = 1 - defaultMaxValue = 7.5 + defaultMaxValue = 10 Resource_Planetary_Config { Item @@ -1117,7 +1117,7 @@ SCAN_Color_Config highResourceColor = 0.9,0.6,0,1 resourceTransparency = 20 defaultMinValue = 1 - defaultMaxValue = 7.5 + defaultMaxValue = 10 Resource_Planetary_Config { Item @@ -1258,5 +1258,153 @@ SCAN_Color_Config } } } + Item + { + name = He-3 + lowResourceColor = 0,0.5490196,1,1 + highResourceColor = 0.3670588,0.9,0,1 + resourceTransparency = 20 + defaultMinValue = 0 + defaultMaxValue = 5 + Resource_Planetary_Config + { + Item + { + resourceName = He-3 + bodyName = Sun + index = 0 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Kerbin + index = 1 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Mun + index = 2 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Minmus + index = 3 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Moho + index = 4 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Eve + index = 5 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Duna + index = 6 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Ike + index = 7 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Jool + index = 8 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Laythe + index = 9 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Vall + index = 10 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Bop + index = 11 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Tylo + index = 12 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Gilly + index = 13 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Pol + index = 14 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Dres + index = 15 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + Item + { + resourceName = He-3 + bodyName = Eeloo + index = 16 + lowResourceCutoff = 0 + highResourceCutoff = 5 + } + } + } } } diff --git a/SCANassets/Resources/SCANresource.cfg b/SCANassets/Resources/SCANresource.cfg index 96877a26c..bd968211b 100644 --- a/SCANassets/Resources/SCANresource.cfg +++ b/SCANassets/Resources/SCANresource.cfg @@ -23,6 +23,11 @@ SCANSAT_SENSOR SCANtype = 256 //2^8 } SCANSAT_SENSOR +{ + name = He-3 + SCANtype = 512 //2^9 +} +SCANSAT_SENSOR { name = Uraninite SCANtype = 1024 //2^10 From 31f2f605bdcdc701501011b5883e6f83784e684e Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 13:36:23 -0400 Subject: [PATCH 100/117] Add resource display modules where needed --- .../MM_Parts/SCANsat_Resource_Scanner.cfg | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg b/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg index 39ac29e7e..984c54645 100644 --- a/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg +++ b/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg @@ -1,3 +1,91 @@ +@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Ore],@ScannerType[0]]] +{ + MODULE + { + name = SCANresourceDisplay + sensorType = 256 + ScannerType = 0 + ResourceName = Ore + } +} + +@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Karbonite],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +{ + MODULE + { + name = SCANresourceDisplay + sensorType = 262144 + ScannerType = 0 + ResourceName = Karbonite + } +} + +@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[MetallicOre],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +{ + MODULE + { + name = SCANresourceDisplay + sensorType = 128 + ScannerType = 0 + ResourceName = MetallicOre + } +} + +@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Minerals],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +{ + MODULE + { + name = SCANresourceDisplay + sensorType = 32768 + ScannerType = 0 + ResourceName = Minerals + } +} + +@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Substrate],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +{ + MODULE + { + name = SCANresourceDisplay + sensorType = 65536 + ScannerType = 0 + ResourceName = Substrate + } +} + +@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Uraninite],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +{ + MODULE + { + name = SCANresourceDisplay + sensorType = 1024 + ScannerType = 0 + ResourceName = Uraninite + } +} + +@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Water],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +{ + MODULE + { + name = SCANresourceDisplay + sensorType = 8192 + ScannerType = 0 + ResourceName = Water + } +} + +@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[He-3],@ScannerType[0]]]:NEEDS[] +{ + MODULE + { + name = SCANresourceDisplay + sensorType = 512 + ScannerType = 0 + ResourceName = He-3 + } +} + @PART[OrbitalScanner]:FOR[SCANsat] { MODULE From 54d912fb73682c77471d94f28b4ed17e6f5ca14b Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 13:36:33 -0400 Subject: [PATCH 101/117] UI tweaks --- SCANsat/SCAN_UI/SCANoverlayController.cs | 6 +++--- SCANsat/SCAN_UI/SCANresourceSettings.cs | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANoverlayController.cs b/SCANsat/SCAN_UI/SCANoverlayController.cs index c100e7524..7ab308946 100644 --- a/SCANsat/SCAN_UI/SCANoverlayController.cs +++ b/SCANsat/SCAN_UI/SCANoverlayController.cs @@ -205,13 +205,13 @@ private void overlayOptions(int id) growE(); GUILayout.Label("Coverage Transparency:", SCANskins.SCAN_labelSmallLeft); - if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(10))) { transparency = Mathf.Max(0f, transparency - 0.1f); refreshMap(); } - GUILayout.Label(transparency.ToString("P0"), SCANskins.SCAN_labelSmall); - if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + GUILayout.Label(transparency.ToString("P0"), SCANskins.SCAN_labelSmall, GUILayout.Width(30)); + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(10))) { transparency = Mathf.Min(1f, transparency + 0.1f); refreshMap(); diff --git a/SCANsat/SCAN_UI/SCANresourceSettings.cs b/SCANsat/SCAN_UI/SCANresourceSettings.cs index ad519a611..4eda40b42 100644 --- a/SCANsat/SCAN_UI/SCANresourceSettings.cs +++ b/SCANsat/SCAN_UI/SCANresourceSettings.cs @@ -181,12 +181,14 @@ private void overlayOptions(int id) growE(); GUILayout.Label("Interpolation:", SCANskins.SCAN_labelSmallLeft); + fillS(); + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { interpolationScale = Math.Max(2, interpolationScale / 2); refreshMap(); } - GUILayout.Label(interpolationScale.ToString(), SCANskins.SCAN_labelSmall); + GUILayout.Label(interpolationScale.ToString(), SCANskins.SCAN_labelSmall, GUILayout.Width(20)); if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { interpolationScale = Math.Min(32, interpolationScale * 2); @@ -197,12 +199,14 @@ private void overlayOptions(int id) growE(); GUILayout.Label("Map Height:", SCANskins.SCAN_labelSmallLeft); + fillS(); + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { mapHeight = Math.Max(64, mapHeight / 2); refreshMap(); } - GUILayout.Label(mapHeight.ToString(), SCANskins.SCAN_labelSmall); + GUILayout.Label(mapHeight.ToString(), SCANskins.SCAN_labelSmall, GUILayout.Width(40)); if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) { mapHeight = Math.Min(1024, mapHeight * 2); From d5eafe0fb0e1ff876f4dcb793be94628d62dd054 Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 13:36:51 -0400 Subject: [PATCH 102/117] Handle biomes that haven't been scanned --- .../SCAN_PartModules/SCANresourceDisplay.cs | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs index 1a5cb9111..4304019f4 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -12,6 +12,8 @@ class SCANresourceDisplay : ModuleResourceScanner, IAnimatedModule public int sensorType; private List stockScanners; + private Dictionary abundanceSummary; + private CelestialBody body; private bool tooHigh; private bool fuzzy; @@ -20,6 +22,8 @@ public override void OnStart(PartModule.StartState state) if (state == StartState.Editor) return; + GameEvents.onVesselSOIChanged.Add(onSOIChange); + this.enabled = true; stockScanners = findScanners(); @@ -33,6 +37,9 @@ public override void OnStart(PartModule.StartState state) m.DisableModule(); } } + + body = FlightGlobals.currentMainBody; + refreshAbundance(body.flightGlobalsIndex); } private List findScanners() @@ -54,6 +61,11 @@ private void setupFields(ModuleResourceScanner m) } } + private void OnDestroy() + { + GameEvents.onVesselSOIChanged.Remove(onSOIChange); + } + public override void OnUpdate() { if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready) @@ -68,13 +80,41 @@ public override void OnUpdate() Fields["abundanceDisplay"].guiActive = true; if (tooHigh) + { abundanceDisplay = string.Format("{0}[Surf]: Too High", ResourceName); + return; + } else if (abundanceValue < 0) + { abundanceDisplay = string.Format("{0}[Surf]: No Data", ResourceName); - else if (fuzzy) - abundanceDisplay = string.Format("{0}[Surf]: {1:P0}", ResourceName, abundanceValue); + return; + } + + string biome = "Landed"; + + if (body.BiomeMap != null) + biome = SCANUtil.getBiomeName(body, SCANUtil.fixLonShift(vessel.longitude), SCANUtil.fixLatShift(vessel.latitude)); + + if (checkBiome(biome)) + { + if (fuzzy) + abundanceDisplay = string.Format("{0}[Surf]: {1:P0}", ResourceName, abundanceValue); + else + abundanceDisplay = string.Format("{0}[Surf]: {1:P2}", ResourceName, abundanceValue); + } else - abundanceDisplay = string.Format("{0}[Surf]: {1:P2}", ResourceName, abundanceValue); + { + float biomeAbundance = abundanceSummary.ContainsKey(biome) ? abundanceSummary[biome].Abundance : 0f; + if (fuzzy) + abundanceDisplay = string.Format("{0}[Surf]: {1:P0}", ResourceName, biomeAbundance); + else + abundanceDisplay = string.Format("{0}[Surf]: {1:P2}", ResourceName, biomeAbundance); + } + } + + private bool checkBiome (string b) + { + return ResourceMap.Instance.IsBiomeUnlocked(body.flightGlobalsIndex, b); } public override void OnFixedUpdate() @@ -104,6 +144,21 @@ public override void OnFixedUpdate() } } + private void onSOIChange(GameEvents.HostedFromToAction VB) + { + body = VB.to; + refreshAbundance(body.flightGlobalsIndex); + } + + private void refreshAbundance(int bodyID) + { + abundanceSummary = new Dictionary(); + + abundanceSummary = ResourceCache.Instance.AbundanceCache. + Where(a => a.ResourceName == ResourceName && a.HarvestType == HarvestTypes.Planetary && a.BodyId == bodyID). + ToDictionary(a => a.BiomeName, a => a); + } + void IAnimatedModule.EnableModule() { this.enabled = true; From a903a74417b0b859e67cae11b150c86aa541121d Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 13:37:51 -0400 Subject: [PATCH 103/117] Override biome lock --- SCANsat/SCAN_PartModules/SCANresourceDisplay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs index 4304019f4..beaf39917 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -95,7 +95,7 @@ public override void OnUpdate() if (body.BiomeMap != null) biome = SCANUtil.getBiomeName(body, SCANUtil.fixLonShift(vessel.longitude), SCANUtil.fixLatShift(vessel.latitude)); - if (checkBiome(biome)) + if (checkBiome(biome) || !SCANcontroller.controller.resourceBiomeLock) { if (fuzzy) abundanceDisplay = string.Format("{0}[Surf]: {1:P0}", ResourceName, abundanceValue); From c52c207ff20198aed4ca276fca2894c67d166aec Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 16:37:37 -0400 Subject: [PATCH 104/117] Fix mm configs --- SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg b/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg index 984c54645..a9e8d4ed7 100644 --- a/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg +++ b/SCANassets/MM_Parts/SCANsat_Resource_Scanner.cfg @@ -1,4 +1,4 @@ -@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Ore],@ScannerType[0]]] +@PART[*]:HAS[@MODULE[ModuleResourceScanner]:HAS[#ResourceName[Ore],#ScannerType[0]]]:FOR[SCANsat] { MODULE { @@ -9,7 +9,7 @@ } } -@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Karbonite],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +@PART[*]:HAS[@MODULE[ModuleResourceScanner]:HAS[#ResourceName[Karbonite],#ScannerType[0]]]:NEEDS[CommunityResourcePack]:FOR[SCANsat] { MODULE { @@ -20,7 +20,7 @@ } } -@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[MetallicOre],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +@PART[*]:HAS[@MODULE[ModuleResourceScanner]:HAS[#ResourceName[MetallicOre],#ScannerType[0]]]:NEEDS[CommunityResourcePack]:FOR[SCANsat] { MODULE { @@ -31,7 +31,7 @@ } } -@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Minerals],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +@PART[*]:HAS[@MODULE[ModuleResourceScanner]:HAS[#ResourceName[Minerals],#ScannerType[0]]]:NEEDS[CommunityResourcePack]:FOR[SCANsat] { MODULE { @@ -42,7 +42,7 @@ } } -@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Substrate],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +@PART[*]:HAS[@MODULE[ModuleResourceScanner]:HAS[#ResourceName[Substrate],#ScannerType[0]]]:NEEDS[CommunityResourcePack]:FOR[SCANsat] { MODULE { @@ -53,7 +53,7 @@ } } -@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Uraninite],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +@PART[*]:HAS[@MODULE[ModuleResourceScanner]:HAS[#ResourceName[Uraninite],#ScannerType[0]]]:NEEDS[CommunityResourcePack]:FOR[SCANsat] { MODULE { @@ -64,7 +64,7 @@ } } -@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[Water],@ScannerType[0]]]:NEEDS[CommunityResourcePack] +@PART[*]:HAS[@MODULE[ModuleResourceScanner]:HAS[#ResourceName[Water],#ScannerType[0]]]:NEEDS[CommunityResourcePack]:FOR[SCANsat] { MODULE { @@ -75,7 +75,7 @@ } } -@PART[*]:FOR[SCANsat]:HAS[@MODULE[ModuleResourceScanner]:HAS[@ResourceName[He-3],@ScannerType[0]]]:NEEDS[] +@PART[*]:HAS[@MODULE[ModuleResourceScanner]:HAS[#ResourceName[He-3],#ScannerType[0]]]:FOR[SCANsat]:NEEDS[] { MODULE { From 40bd426376e77cafaf8302209730955ed52e3c50 Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 16:37:51 -0400 Subject: [PATCH 105/117] UI tweak --- SCANsat/SCAN_UI/SCANoverlayController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANoverlayController.cs b/SCANsat/SCAN_UI/SCANoverlayController.cs index 7ab308946..fe1e0ba3b 100644 --- a/SCANsat/SCAN_UI/SCANoverlayController.cs +++ b/SCANsat/SCAN_UI/SCANoverlayController.cs @@ -205,13 +205,13 @@ private void overlayOptions(int id) growE(); GUILayout.Label("Coverage Transparency:", SCANskins.SCAN_labelSmallLeft); - if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(10))) + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(18))) { transparency = Mathf.Max(0f, transparency - 0.1f); refreshMap(); } GUILayout.Label(transparency.ToString("P0"), SCANskins.SCAN_labelSmall, GUILayout.Width(30)); - if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(10))) + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(18))) { transparency = Mathf.Min(1f, transparency + 0.1f); refreshMap(); From 42a83cabd98fe486e21cbf3a7cc6792efb460ed3 Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 16:38:16 -0400 Subject: [PATCH 106/117] Null check --- .../SCAN_PartModules/SCANresourceScanner.cs | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceScanner.cs b/SCANsat/SCAN_PartModules/SCANresourceScanner.cs index 92d415391..662224232 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceScanner.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceScanner.cs @@ -23,6 +23,7 @@ public class ModuleSCANresourceScanner : SCANsat, IAnimatedModule private List mScanner; private ModuleAnimationGroup animGroup; private bool activated; + private bool forceStart; public override void OnStart(PartModule.StartState state) { @@ -45,20 +46,9 @@ public override void OnStart(PartModule.StartState state) if (animGroup == null) activated = true; - if (SCANcontroller.controller.disableStockResource) - { - if (mSurvey != null) - { - foreach (ModuleOrbitalSurveyor m in mSurvey) - m.DisableModule(); - } + forceStart = true; - if (mScanner != null) - { - foreach (ModuleOrbitalScanner m in mScanner) - m.DisableModule(); - } - } + SCANUtil.SCANlog("Starting resource scanner"); } public override string GetInfo() @@ -109,6 +99,25 @@ public void Update() if (!FlightGlobals.ready) return; + if (forceStart && SCANcontroller.controller != null) + { + if (SCANcontroller.controller.disableStockResource) + { + if (mSurvey != null) + { + foreach (ModuleOrbitalSurveyor m in mSurvey) + m.DisableModule(); + } + + if (mScanner != null) + { + foreach (ModuleOrbitalScanner m in mScanner) + m.DisableModule(); + } + } + forceStart = false; + } + if (SCANcontroller.controller == null) return; @@ -164,7 +173,7 @@ public void DisableModule() if (scanning) unregisterScanner(); - if (SCANcontroller.controller.disableStockResource) + if (SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource) { if (mSurvey != null) { @@ -183,7 +192,7 @@ public void DisableModule() public void EnableModule() { activated = true; - if (SCANcontroller.controller.disableStockResource) + if (SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource) { if (mSurvey != null) { From acde58c19da6af287548423c4d19bc9e78338fdd Mon Sep 17 00:00:00 2001 From: DMagic Date: Fri, 5 Jun 2015 16:38:31 -0400 Subject: [PATCH 107/117] Still needs work... --- .../SCAN_PartModules/SCANresourceDisplay.cs | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs index beaf39917..844036135 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -16,6 +16,7 @@ class SCANresourceDisplay : ModuleResourceScanner, IAnimatedModule private CelestialBody body; private bool tooHigh; private bool fuzzy; + private bool forceStart; public override void OnStart(PartModule.StartState state) { @@ -25,19 +26,14 @@ public override void OnStart(PartModule.StartState state) GameEvents.onVesselSOIChanged.Add(onSOIChange); this.enabled = true; + forceStart = true; + + SCANUtil.SCANlog("Resource Display Module [{0}] Starting...", ResourceName); stockScanners = findScanners(); setupFields(stockScanners.FirstOrDefault()); - if (stockScanners != null && SCANcontroller.controller.disableStockResource) - { - foreach (ModuleResourceScanner m in stockScanners) - { - m.DisableModule(); - } - } - body = FlightGlobals.currentMainBody; refreshAbundance(body.flightGlobalsIndex); } @@ -51,6 +47,7 @@ private void setupFields(ModuleResourceScanner m) { if (m != null) { + SCANUtil.SCANlog("Resource Display Module set to Max Alt: {0} ; Unlock: {1}", m.MaxAbundanceAltitude, m.RequiresUnlock); MaxAbundanceAltitude = m.MaxAbundanceAltitude; RequiresUnlock = m.RequiresUnlock; } @@ -59,6 +56,8 @@ private void setupFields(ModuleResourceScanner m) MaxAbundanceAltitude = 250000; RequiresUnlock = true; } + + Fields["abundanceDisplay"].guiName = string.Format("{0}[Surf]: ", ResourceName); } private void OnDestroy() @@ -68,25 +67,37 @@ private void OnDestroy() public override void OnUpdate() { + SCANUtil.SCANlog("Updating Resource Module..."); if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready) return; - + SCANUtil.SCANlog("Scene Ready..."); + if (forceStart && SCANcontroller.controller != null) + { + if (stockScanners != null && SCANcontroller.controller.disableStockResource) + { + foreach (ModuleResourceScanner m in stockScanners) + { + m.DisableModule(); + } + } + } + SCANUtil.SCANlog("Checking for stock resource options..."); if (!SCANcontroller.controller.disableStockResource) { Fields["abundanceDisplay"].guiActive = false; return; } - + SCANUtil.SCANlog("Setting SCAN Resource Display Active"); Fields["abundanceDisplay"].guiActive = true; if (tooHigh) { - abundanceDisplay = string.Format("{0}[Surf]: Too High", ResourceName); + abundanceDisplay = "Too High"; return; } else if (abundanceValue < 0) { - abundanceDisplay = string.Format("{0}[Surf]: No Data", ResourceName); + abundanceDisplay = "No Data"; return; } @@ -98,17 +109,17 @@ public override void OnUpdate() if (checkBiome(biome) || !SCANcontroller.controller.resourceBiomeLock) { if (fuzzy) - abundanceDisplay = string.Format("{0}[Surf]: {1:P0}", ResourceName, abundanceValue); + abundanceDisplay = abundanceValue.ToString("P0"); else - abundanceDisplay = string.Format("{0}[Surf]: {1:P2}", ResourceName, abundanceValue); + abundanceDisplay = abundanceValue.ToString("P2"); } else { float biomeAbundance = abundanceSummary.ContainsKey(biome) ? abundanceSummary[biome].Abundance : 0f; if (fuzzy) - abundanceDisplay = string.Format("{0}[Surf]: {1:P0}", ResourceName, biomeAbundance); + abundanceDisplay = biomeAbundance.ToString("P0"); else - abundanceDisplay = string.Format("{0}[Surf]: {1:P2}", ResourceName, biomeAbundance); + abundanceDisplay = biomeAbundance.ToString("P2"); } } @@ -162,7 +173,8 @@ private void refreshAbundance(int bodyID) void IAnimatedModule.EnableModule() { this.enabled = true; - if (stockScanners != null && SCANcontroller.controller.disableStockResource) + SCANUtil.SCANlog("Enabling Resource Module"); + if (stockScanners != null && SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource) { foreach (ModuleResourceScanner m in stockScanners) { @@ -174,7 +186,8 @@ void IAnimatedModule.EnableModule() void IAnimatedModule.DisableModule() { this.enabled = false; - if (stockScanners != null && SCANcontroller.controller.disableStockResource) + SCANUtil.SCANlog("Disabling Resource Module"); + if (stockScanners != null && SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource) { foreach (ModuleResourceScanner m in stockScanners) { From 5ddd29628c5249c7b7a7239c166304d07777ff02 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 18:26:03 -0400 Subject: [PATCH 108/117] update .version --- SCANassets/SCANsat.version | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SCANassets/SCANsat.version b/SCANassets/SCANsat.version index badedd42a..b350f5838 100644 --- a/SCANassets/SCANsat.version +++ b/SCANassets/SCANsat.version @@ -5,12 +5,12 @@ "GITHUB":{ "USERNAME":"S-C-A-N", "REPOSITORY":"SCANsat", - "ALLOW_PRE_RELEASE":false + "ALLOW_PRE_RELEASE":true }, "VERSION":{ "MAJOR":1, "MINOR":1, - "PATCH":2, + "PATCH":3, "BUILD":1 }, "KSP_VERSION":{ From 4bae105437aeea8000a5259d959074622ff974aa Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 18:26:11 -0400 Subject: [PATCH 109/117] change log --- SCANsat/CHANGELOG.txt | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/SCANsat/CHANGELOG.txt b/SCANsat/CHANGELOG.txt index 54289f033..510511872 100644 --- a/SCANsat/CHANGELOG.txt +++ b/SCANsat/CHANGELOG.txt @@ -1,3 +1,59 @@ +Version 13.1 - 2015-6-6 +------------------------ + +- Resource Scanning Overhaul + +- New option available to disable stock scanning + - Disables the orbital survey + - Replaces the resource concentration readout from scanners with SCANsat modules + - Right-click menu resource concentration readout dependent on SCANsat scanning coverage + - Stock resource scanning data can be erased for each planet (does not affect resource biome scanning data) + +- Stock resource parts adapted for SCANsat resource scanning + - Module Manager required for SCANsat resource scanning + - M700 (clamshell) scanner used for low-resolution resource scanning; covers all resources + - Narrow-band scanners used for high-resolution, individual resource scanning + +- Planetary map overlay + - New window to control resource and biome map overlays + - Biome overlays limited to stock color scheme for now + - Overlay window buttons added to the big map and small map windows; also added to the Toolbar menu + - Select between all available resources and biome maps + - Coverage Transparency option shows scanned areas in grey if there are no resources present + +- Resource settings window + - New window to control resource options and planetary overlay quality + - Biome lock, instant scan, and zoom window options are the same as in previous versions + - The instant scan option is automatically disabled when Disable Stock Resources is activated + - Both SCANsat and stock resource scanning data for the current planet can be reset + - Interpolation and map overlay size can be configured + - Biome maps use twice the map height as resource maps (512*256 for resources; 1024*512 for biomes by default) + +- SCANsat big map + - Resource overlay now matches the planetary overlay more closely + - Interpolation is used to generate the map overlay; this greatly speeds up big map rendering speed + - Zoom map uses more accurate interpolation method + - Biome maps can be generated without the white border + +- Bug Fixes + - Waypoint location correct when waypoint coordinates are stored with nonsense values (ie. -120 S...) + - Active vessel properly updates for the big map orbit display + +Version 12.1 - 2015-5-30 +------------------------ + +- Updated for MechJeb 2.5.1 + +- Added SCANsat sensor type and color configs for He-3 + - SCANsat sensortype = 512 + +- Fix a bug while adding resource scanners in the editor +- Add resource scanner action groups + - Only work when the scanner is deployed + +- Fix MapTraq texture location + + Version 12 - 2015-5-3 ------------------------ From 0d31561532e661bb96007c398f72f8c9517ddf02 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 18:26:20 -0400 Subject: [PATCH 110/117] small button style --- SCANsat/SCAN_UI/UI_Framework/SCANskins.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs index c332dc0b9..8afb49c1b 100644 --- a/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs +++ b/SCANsat/SCAN_UI/UI_Framework/SCANskins.cs @@ -299,7 +299,7 @@ private static void initializeSkins() SCAN_buttonSmall = new GUIStyle(SCAN_SkinsLibrary.DefUnitySkin.button); SCAN_buttonSmall.fontSize = 10; - SCAN_buttonSmall.alignment = TextAnchor.MiddleCenter; + SCAN_buttonSmall.alignment = TextAnchor.MiddleLeft; SCAN_buttonSmall.fontStyle = FontStyle.Bold; //Initialize settings menu styles From 0cd42b040949cc68c4252349a9acbf0b4f367edd Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 18:26:46 -0400 Subject: [PATCH 111/117] UI tweak; disable biome data debug --- SCANsat/SCAN_UI/SCANoverlayController.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SCANsat/SCAN_UI/SCANoverlayController.cs b/SCANsat/SCAN_UI/SCANoverlayController.cs index fe1e0ba3b..70b941616 100644 --- a/SCANsat/SCAN_UI/SCANoverlayController.cs +++ b/SCANsat/SCAN_UI/SCANoverlayController.cs @@ -210,7 +210,7 @@ private void overlayOptions(int id) transparency = Mathf.Max(0f, transparency - 0.1f); refreshMap(); } - GUILayout.Label(transparency.ToString("P0"), SCANskins.SCAN_labelSmall, GUILayout.Width(30)); + GUILayout.Label(transparency.ToString("P0"), SCANskins.SCAN_labelSmall); if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(18))) { transparency = Mathf.Min(1f, transparency + 0.1f); @@ -227,6 +227,17 @@ private void resourceSettings(int id) { SCANcontroller.controller.resourceSettings.Visible = !SCANcontroller.controller.resourceSettings.Visible; } + + //if (GUILayout.Button("Biome Summary")) + //{ + // foreach (ResourceCache.AbundanceSummary a in ResourceCache.Instance.AbundanceCache) + // { + // if (a.ResourceName == "Ore" && a.HarvestType == HarvestTypes.Planetary) + // SCANUtil.SCANlog("{0}: For {1} on Body {2} of scanner type {3}: Abundance = {4:P3}", a.ResourceName, a.BiomeName, a.BodyId, a.HarvestType, a.Abundance); + // } + + + //} } public void refreshMap(float t, int height, int interp) From 054254fc38d7e982958d368a5ca80619c5c9f3b9 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 18:26:56 -0400 Subject: [PATCH 112/117] Remove debug spam --- SCANsat/SCAN_PartModules/SCANresourceScanner.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceScanner.cs b/SCANsat/SCAN_PartModules/SCANresourceScanner.cs index 662224232..5010b4540 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceScanner.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceScanner.cs @@ -47,8 +47,6 @@ public override void OnStart(PartModule.StartState state) activated = true; forceStart = true; - - SCANUtil.SCANlog("Starting resource scanner"); } public override string GetInfo() From 363bb6121b6bf4960a59a1f5504e903eb8ef1f8e Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 18:27:04 -0400 Subject: [PATCH 113/117] UI tweaks --- SCANsat/SCAN_UI/SCANresourceSettings.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/SCANsat/SCAN_UI/SCANresourceSettings.cs b/SCANsat/SCAN_UI/SCANresourceSettings.cs index 4eda40b42..f6ac97e70 100644 --- a/SCANsat/SCAN_UI/SCANresourceSettings.cs +++ b/SCANsat/SCAN_UI/SCANresourceSettings.cs @@ -11,7 +11,7 @@ namespace SCANsat.SCAN_UI { class SCANresourceSettings : SCAN_MBW { - internal readonly static Rect defaultRect = new Rect(300, 200, 400, 300); + internal readonly static Rect defaultRect = new Rect(300, 200, 300, 300); private static Rect sessionRect = defaultRect; private int mapHeight = 256; private float transparency = 0f; @@ -25,7 +25,7 @@ protected override void Awake() WindowCaption = "S.C.A.N. Resources Settings"; WindowRect = sessionRect; WindowStyle = SCANskins.SCAN_window; - WindowOptions = new GUILayoutOption[2] { GUILayout.Width(400), GUILayout.Height(300) }; + WindowOptions = new GUILayoutOption[2] { GUILayout.Width(350), GUILayout.Height(300) }; Visible = false; DragEnabled = true; ClampToScreenOffset = new RectOffset(-200, -200, -200, -200); @@ -136,7 +136,10 @@ private void resourceSettings(int id) GUILayout.Label("Resource Settings", SCANskins.SCAN_headline); growE(); SCANcontroller.controller.resourceBiomeLock = GUILayout.Toggle(SCANcontroller.controller.resourceBiomeLock, "Resource Biome Lock", SCANskins.SCAN_settingsToggle); - SCANcontroller.controller.easyModeScanning = GUILayout.Toggle(SCANcontroller.controller.easyModeScanning, "Instant Resource Scan", SCANskins.SCAN_settingsToggle); + if (SCANcontroller.controller.disableStockResource) + GUILayout.Toggle(false, "Instant Resource Scan", SCANskins.SCAN_settingsToggle); + else + SCANcontroller.controller.easyModeScanning = GUILayout.Toggle(SCANcontroller.controller.easyModeScanning, "Instant Resource Scan", SCANskins.SCAN_settingsToggle); stopE(); growE(); fillS(); @@ -183,13 +186,13 @@ private void overlayOptions(int id) fillS(); - if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(18))) { interpolationScale = Math.Max(2, interpolationScale / 2); refreshMap(); } - GUILayout.Label(interpolationScale.ToString(), SCANskins.SCAN_labelSmall, GUILayout.Width(20)); - if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + GUILayout.Label(interpolationScale.ToString(), SCANskins.SCAN_labelSmall, GUILayout.Width(36)); + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(18))) { interpolationScale = Math.Min(32, interpolationScale * 2); refreshMap(); @@ -201,13 +204,13 @@ private void overlayOptions(int id) fillS(); - if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + if (GUILayout.Button("-", SCANskins.SCAN_buttonSmall, GUILayout.Width(18))) { mapHeight = Math.Max(64, mapHeight / 2); refreshMap(); } - GUILayout.Label(mapHeight.ToString(), SCANskins.SCAN_labelSmall, GUILayout.Width(40)); - if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(15))) + GUILayout.Label(mapHeight.ToString(), SCANskins.SCAN_labelSmall, GUILayout.Width(36)); + if (GUILayout.Button("+", SCANskins.SCAN_buttonSmall, GUILayout.Width(18))) { mapHeight = Math.Min(1024, mapHeight * 2); refreshMap(); From 2379c06aa9790026112afa80e5ccd5e4c176bdd9 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 18:27:25 -0400 Subject: [PATCH 114/117] Resource readouts working a little better... --- .../SCAN_PartModules/SCANresourceDisplay.cs | 77 ++++++++++++------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs index 844036135..7f5d5d721 100644 --- a/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs +++ b/SCANsat/SCAN_PartModules/SCANresourceDisplay.cs @@ -6,10 +6,20 @@ namespace SCANsat.SCAN_PartModules { - class SCANresourceDisplay : ModuleResourceScanner, IAnimatedModule + class SCANresourceDisplay : PartModule, IAnimatedModule { [KSPField] public int sensorType; + [KSPField(guiActive = true, guiName = "Abundance")] + public string abundanceField; + [KSPField] + public string ResourceName; + [KSPField] + public float MaxAbundanceAltitude; + [KSPField] + public bool RequiresUnlock; + + private float abundanceValue; private List stockScanners; private Dictionary abundanceSummary; @@ -17,6 +27,7 @@ class SCANresourceDisplay : ModuleResourceScanner, IAnimatedModule private bool tooHigh; private bool fuzzy; private bool forceStart; + private bool activated; public override void OnStart(PartModule.StartState state) { @@ -25,11 +36,11 @@ public override void OnStart(PartModule.StartState state) GameEvents.onVesselSOIChanged.Add(onSOIChange); + part.force_activate(); this.enabled = true; + activated = true; forceStart = true; - SCANUtil.SCANlog("Resource Display Module [{0}] Starting...", ResourceName); - stockScanners = findScanners(); setupFields(stockScanners.FirstOrDefault()); @@ -57,7 +68,7 @@ private void setupFields(ModuleResourceScanner m) RequiresUnlock = true; } - Fields["abundanceDisplay"].guiName = string.Format("{0}[Surf]: ", ResourceName); + Fields["abundanceField"].guiName = string.Format("{0}[Surf]", ResourceName); } private void OnDestroy() @@ -65,12 +76,20 @@ private void OnDestroy() GameEvents.onVesselSOIChanged.Remove(onSOIChange); } - public override void OnUpdate() + private void Update() { - SCANUtil.SCANlog("Updating Resource Module..."); + if (!activated) + { + Fields["abundanceField"].guiActive = false; + return; + } + if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready) return; - SCANUtil.SCANlog("Scene Ready..."); + + if (SCANcontroller.controller == null) + return; + if (forceStart && SCANcontroller.controller != null) { if (stockScanners != null && SCANcontroller.controller.disableStockResource) @@ -81,23 +100,23 @@ public override void OnUpdate() } } } - SCANUtil.SCANlog("Checking for stock resource options..."); + if (!SCANcontroller.controller.disableStockResource) { - Fields["abundanceDisplay"].guiActive = false; + Fields["abundanceField"].guiActive = false; return; } - SCANUtil.SCANlog("Setting SCAN Resource Display Active"); - Fields["abundanceDisplay"].guiActive = true; + + Fields["abundanceField"].guiActive = true; if (tooHigh) { - abundanceDisplay = "Too High"; + abundanceField = "Too High"; return; } else if (abundanceValue < 0) { - abundanceDisplay = "No Data"; + abundanceField = "No Data"; return; } @@ -109,17 +128,17 @@ public override void OnUpdate() if (checkBiome(biome) || !SCANcontroller.controller.resourceBiomeLock) { if (fuzzy) - abundanceDisplay = abundanceValue.ToString("P0"); + abundanceField = abundanceValue.ToString("P0"); else - abundanceDisplay = abundanceValue.ToString("P2"); + abundanceField = abundanceValue.ToString("P2"); } else { float biomeAbundance = abundanceSummary.ContainsKey(biome) ? abundanceSummary[biome].Abundance : 0f; if (fuzzy) - abundanceDisplay = biomeAbundance.ToString("P0"); + abundanceField = biomeAbundance.ToString("P0"); else - abundanceDisplay = biomeAbundance.ToString("P2"); + abundanceField = biomeAbundance.ToString("P2"); } } @@ -128,8 +147,14 @@ private bool checkBiome (string b) return ResourceMap.Instance.IsBiomeUnlocked(body.flightGlobalsIndex, b); } - public override void OnFixedUpdate() + private void FixedUpdate() { + if (!activated) + { + abundanceValue = -1f; + return; + } + if (vessel.altitude > MaxAbundanceAltitude) { tooHigh = true; @@ -170,10 +195,9 @@ private void refreshAbundance(int bodyID) ToDictionary(a => a.BiomeName, a => a); } - void IAnimatedModule.EnableModule() + public void EnableModule() { - this.enabled = true; - SCANUtil.SCANlog("Enabling Resource Module"); + activated = true; if (stockScanners != null && SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource) { foreach (ModuleResourceScanner m in stockScanners) @@ -183,10 +207,9 @@ void IAnimatedModule.EnableModule() } } - void IAnimatedModule.DisableModule() + public void DisableModule() { - this.enabled = false; - SCANUtil.SCANlog("Disabling Resource Module"); + activated = false; if (stockScanners != null && SCANcontroller.controller != null && SCANcontroller.controller.disableStockResource) { foreach (ModuleResourceScanner m in stockScanners) @@ -196,12 +219,12 @@ void IAnimatedModule.DisableModule() } } - bool IAnimatedModule.ModuleIsActive() + public bool ModuleIsActive() { - return isEnabled; + return activated; } - bool IAnimatedModule.IsSituationValid() + public bool IsSituationValid() { return true; } From c2af0e5753f4c2c39dc48f8eb5d0d1e4724ecfc5 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 19:05:25 -0400 Subject: [PATCH 115/117] readme updates --- README.md | 191 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 121 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index c068b4098..3f87a5cba 100644 --- a/README.md +++ b/README.md @@ -36,28 +36,30 @@ * [b. Mismatched Scanners][3b] * [4. Big Map][4] * [a. Big Map Options][4a] -* [5. Zoom Map][5] - * [a. Target Selection][5a] - * [b. MechJeb Landing Guidance][5b] -* [6. Instrument Window][6] -* [7. Parts and Sensors Types][7] - * [a. RADAR][7a] - * [b. SAR][7b] - * [c. Multi][7c] - * [d. BTDT][7d] - * [e. MapTraq (deprecated)][7e] -* [8. (Career Mode) Research and Development][8] - * [a. Minimum Scan for Science (30%)][8a] - * [b. Getting Maximum Science][8b] - * [c. Contracts][8c] -* [9. Color Management][9] - * [a. Terrain Colors and Options][9a] - * [b. Biome Colors and Options][9b] - * [c. Resource Colors and Options][9c] -* [10 Background Scanning][10] -* [11. Time Warp][11] -* [12. Settings Menu][12] -* [13. Note: Data Sources][13] +* [5. Planetary Overlay][5] + * [a. Overlay Control Window][5a] +* [6. Zoom Map][6] + * [a. Target Selection][6a] + * [b. MechJeb Landing Guidance][6b] +* [7. Instrument Window][7] +* [8. Parts and Sensors Types][8] + * [a. RADAR][8a] + * [b. SAR][8b] + * [c. Multi][8c] + * [d. BTDT][8d] + * [e. MapTraq (deprecated)][8e] +* [9. (Career Mode) Research and Development][9] + * [a. Minimum Scan for Science (30%)][9a] + * [b. Getting Maximum Science][9b] + * [c. Contracts][9c] +* [10. Color Management][10] + * [a. Terrain Colors and Options][10a] + * [b. Biome Colors and Options][10b] + * [c. Resource Colors and Options][10c] +* [11 Background Scanning][11] +* [12. Time Warp][12] +* [13. Settings Menu][13] +* [14. Note: Data Sources][14] **WARNING**: @@ -232,6 +234,11 @@ Resource scanning proceeds the same way as standard SCANsat scanning instruments The resource system can be enabled through the **SCANsat** Big Map: > ![][resource-walkthrough] +The examples below show the difference between high (top) and low (bottom) resolution resource scans +> ![][resource-bigmap-hires-full-biome] + +> ![][resource-bigmap-lores-full-biome] + Zoom map resource overlays require that a vessel with a narrow-band scanner be present in orbit and at an inclination high enough to cover the area in the zoom map. > ![][resource-zoom-map-covered] @@ -243,7 +250,7 @@ Resource overlays will work in IVA, too: #### [:top:][top] 2c. Resource Setting -A number of options are available in the **Settings Menu** for SCANsat resource scanning. +A number of options are available in the **Resource Settings Menu** for SCANsat resource scanning. > ![][resource-settings] @@ -256,10 +263,20 @@ A number of options are available in the **Settings Menu** for SCANsat resource * **Zoom Requires Narrow Band Scanner** * With this active the zoom map will only display resource overlays when a suitable **Narrow-Band Scanner** is in orbit around the planet, and its orbit covers the region showed in the zoom map. * When disabled the zoom map will display resource overlays regardless of **Narrow-Band Scanner** coverage. -* **Reset Resource Coverage** +* **Disable Stock Scanning** + * Disables the stock orbital survey + * Replaces the resource concentration readout from scanners with SCANsat modules + * Right-click menu resource concentration readout dependent on SCANsat scanning coverage +* **Reset SCANsat Resource Coverage** * This button will erase all resource scanning data for the current planet. * Regular SCANsat data will not be affected. * A confirmation window will appear upon clicking the button. +* **Reset Stock Resource Scanning** + * Stock resource scanning data can be erased for each planet (does not affect resource biome scanning data) + +* **SCAN Planet Overlay** Quality Settings + * Interpolation settings can be increased or decreased to increase the accuracy of overlays + * Overlay map size can be adjusted for higher quality, but slower maps ### [:top:][top] 3. Basic Usage ------------------------------------------ @@ -338,7 +355,25 @@ The camera icon in the lower-right exports a copy of the map. The re-size icon in the lower-right corner can be dragged to re-size the map. -### [:top:][top] 5. Zoom Map +### [:top:][top] 5. Planetary Overlay +------------------------------------------ + +> ![][resource-planet-hires-full-biome] + +A separate window is used to control resource and biome planetary overlay maps. These maps are drawn directly over the surface of the current planet; they use the same system as the stock resource overlays and will replace those maps if both are opened at the same time. Map coverage is dependent upon SCANsat data; only scanned areas will be displayed on the map. +> ![][biome-planet-in-progress] + +SCANsat biome coverage can also be displayed using the overlay window. +> ![][resource-planet-in-progress] + +#### [:top:][top] 5a. Overlay Control Window +> ![][resource-overlay-window] + +Each available resource can be selected for the planetary overlay maps, along with biome maps. Biome maps are currently limited to the stock color scheme without borders. + +The **Coverage Transparency** Options adds a grey background to areas that have been scanned but do not have any resources; this helps to visualize scanning progress. + +### [:top:][top] 6. Zoom Map ------------------------------------------ > ![][bigmap-zoom-open] @@ -357,7 +392,7 @@ The **zoom map** also features mouse-over information for the cursor location si Different map types, resource overlays and polar projections are all applied to the **zoom map** as well. > ![][zoommap-in] -#### [:top:][top] 5a. Target Selection +#### [:top:][top] 6a. Target Selection > ![][zoommap-scansat-landing] The **zoom map** features an option to select and display a target site for each planet. Toggle **Target Selection Mode** by clicking on the target icon in the upper left, then select a sight @@ -368,7 +403,7 @@ While in map view the target site will be overlayed on the planet's surface; sho To clear an existing target, activate **Target Selection Mode** by clicking the target icon, then click somewhere inside of the zoom map window, but outside of the map itself. > ![][zoommap-clear-target] -#### [:top:][top] 5b. MechJeb Landing Guidance +#### [:top:][top] 6b. MechJeb Landing Guidance > ![][zoommap-mechjeb-settings] If MechJeb is installed and an additional option is available in the settings menu to activate **MechJeb Landing Guidance Mode** @@ -381,7 +416,7 @@ and the MechJeb Landing Guidance module must be unlocked in the R&D Center. Landing sites selected through MechJeb will automatically show up as a waypoint on SCANsat maps. -### [:top:][top] 6. Instrument Window +### [:top:][top] 7. Instrument Window ------------------------------------------ > ![][instruments-small] @@ -398,7 +433,7 @@ The instruments window provides a readout of several types of data based on curr > ![][instruments-btdt] -### [:top:][top] 7. Parts and Sensor Types +### [:top:][top] 8. Parts and Sensor Types ------------------------------------------ | **Part** | **Scan Type** | **FOV** | Altitude (**Min**) | (**Ideal**) | (**Max**) @@ -409,19 +444,19 @@ The instruments window provides a readout of several types of data based on curr | [Been There Done That®][5d] | **Anomaly** | 1 | 0 m | 0 m | 2 km | [MapTraq® (deprecated)][5e] | **None** | N/A | N/A | N/A | N/A -#### [:top:][top] 7a. The RADAR Altimetry Sensor +#### [:top:][top] 8a. The RADAR Altimetry Sensor > ![RADAR][vab-radar] -#### [:top:][top] 7b. The SAR Altimetry Sensor +#### [:top:][top] 8b. The SAR Altimetry Sensor > ![SAR][vab-sar] -#### [:top:][top] 7c. The Multispectral Sensor +#### [:top:][top] 8c. The Multispectral Sensor > ![Multi][vab-multi] -#### [:top:][top] 7d. Been There Done That +#### [:top:][top] 8d. Been There Done That > ![BTDT][vab-btdt] -#### [:top:][top] 7e. MapTraq (deprecated) +#### [:top:][top] 8e. MapTraq (deprecated) > ![MapTraq][vab-maptraq] -### [:top:][top] 8. (Career Mode) Research and Development +### [:top:][top] 9. (Career Mode) Research and Development ------------------------------------------ The **RADAR Altimetry** sensor can be unlocked in **Basic Science**. @@ -432,24 +467,24 @@ The **Multispectral** sensor can be unlocked in **Advanced Exploration**. The **BTDT** sensor can be unlocked in **Field Science**. -##### [:top:][top] 8a. Minimum Scan for Science +##### [:top:][top] 9a. Minimum Scan for Science Once you scan at least 30% of a particular map, you can use **Analyze Data** to get delicious science: > ![30% is your minimum][science-min] -##### [:top:][top] 8b. Getting Maximum Science +##### [:top:][top] 9b. Getting Maximum Science Between 30% and 100%, you will get a number of science points proportional to the percentage. Really, the upper cutoff is 95% in case you didn't scan the whole map. > ![Scan 95% to get all science][science-max] -##### [:top:][top] 8c. Contract Support +##### [:top:][top] 9c. Contract Support Career mode contracts are supported through third party addons. * [Contract Configurator Forum Thread][cconfig:release] * [SCANsat Contract Pack][ccfgSCANsat:release] -### [:top:][top] 9. Color Management +### [:top:][top] 10. Color Management ------------------------------------------ > ![][color-window] @@ -458,7 +493,7 @@ SCANsat provides multiple options for map color configurations and terrain level The color management window can be accessed from the big or small map with the color palette icon, or from the toolbar menu. -##### [:top:][top] 9a. Terrain Colors and Options +##### [:top:][top] 10a. Terrain Colors and Options On the left are the various color palettes available; there are four different styles that can be selected from the drop down menu. Palettes can be customized by changing the number of colors in the palette, reversing the order, or making the palette use discrete color transitions, rather than the smooth gradient used by default. @@ -478,7 +513,7 @@ from ocean to solid terrain more pronounced. All stock KSP planets have default color palette and terrain height values appropriate for the planet's terrain. Standard default values are used for any addon planets. -##### [:top:][top] 9b. Biome Colors and Options +##### [:top:][top] 10b. Biome Colors and Options Biome map colors and options can be controlled in the **Biome** tab of the window. * The end-point colors can be selected using the HSV color-picker; the value slider controls the brightness of the color. * Terrain transparency is controlled with a slider. @@ -490,7 +525,7 @@ Biomes can also be displayed using the stock color maps. > ![][color-biome-stock] -##### [:top:][top] 9c. Resource Colors and Options +##### [:top:][top] 10c. Resource Colors and Options Resource overlays can also be adjusted, using the **Resource** tab. * Resource colors are selected in the same manner as biome colors. * Upper and lower resource cutoff values can be adjusted with the sliders; use fine control mode for small adjustments. @@ -499,7 +534,7 @@ Resource overlays can also be adjusted, using the **Resource** tab. > ![][color-resource] -### [:top:][top] 10. Background Scanning +### [:top:][top] 12. Background Scanning ------------------------------------------ ![Note the background scanning (non-active vessels are scanning)][small-scan] @@ -508,7 +543,7 @@ Unlike some other KSP scanning systems, SCANsat allows scanning with multiple vessels. All online scanners scan at the same time during any scene where time progresses; no active SCANsat parts are necessary. -### [:top:][top] 11. Time Warp +### [:top:][top] 12. Time Warp ------------------------------------------ SCANsat does not interpolate satellite paths during time warp; nevertheless, due to the relatively large field of view @@ -525,7 +560,7 @@ It starts at **1000x** and then speeds up to **10,000x**: Notice that the only gaps in coverage are those at the poles (ie, the selected inclination was not high enough to capture the poles). -### [:top:][top] 12. Settings Menu +### [:top:][top] 13. Settings Menu ------------------------------------------ > ![][settings-window] @@ -534,7 +569,6 @@ The settings menu has a various general options * The marker used for **Anomalies** can be specified * **Background scanning** can be controlled for each planet * **Background scanning** resolution can be lowered for better performance (watch for short pauses when several scanners are active at very high timewarp; reducing the scanning resolution can help with this) -* See the **[Resource Settings][2c]** section for information about resource options * Toggles control the availability of the **Stock App Launcher** button, and the **Tooltips** for various icons on other windows * If MechJeb is installed an additional option is available to toggle the MechJeb Landing Guidance interface * If the windows are ever dragged off screen there is an option to **Reset All Windows** to their default positions @@ -544,7 +578,7 @@ The settings menu has a various general options * **Sensors:** The total number of SCANsat sensors on all vessels; note that all combination sensors are separated into their invidual components, i.e. the Multi-Spectral scanner consists of two sensors, Biomes and Anomalies. * **Passes:** The number of scanning passes recorded per second, this number can easily be in the tens of thousands at high time warp with multiple vessels and sensors active. -### [:top:][top] 13. Note Concerning Data Sources +### [:top:][top] 14. Note Concerning Data Sources ------------------------------------------ All data this mod shows you is pulled from your game as you play. This @@ -622,11 +656,26 @@ sneaky then they can of course be sneaky. [resource-walkthrough]: http://i.imgur.com/KS4FTh0.gif [resource-scanner]: http://i.imgur.com/mY0fFjr.gif [resource-bigmap]: http://i.imgur.com/JYKG6f5.gif -[resource-settings]: http://i.imgur.com/sgMklCu.png +[resource-settings]: http://i.imgur.com/TTKttD2.png [resource-zoom-map-covered]: http://i.imgur.com/7YuYMGW.png [resource-zoom-map-uncovered]: http://i.imgur.com/cJ9JtdW.png [resource-instant]: http://i.imgur.com/mfIMBEP.gif +[resource-planet-hires-limited-biome]: http://i.imgur.com/yhv2bsq.png +[resource-planet-hires-full-biome]: http://i.imgur.com/rwy77M3.png +[resource-planet-lores-limited-biome]: http://i.imgur.com/tR3eTzL.png +[resource-planet-lores-full-biome]: http://i.imgur.com/kPcO2H7.png +[resource-planet-in-progress]: http://i.imgur.com/0JBSFbB.png +[biome-planet-overlay]: http://i.imgur.com/YofnSEI.png +[biome-planet-in-progress]: http://i.imgur.com/AwQfBgq.png + +[resource-bigmap-hires-limited-biome]: http://i.imgur.com/y0jitxK.png +[resource-bigmap-hires-full-biome]: http://i.imgur.com/fCdXTIq.png +[resource-bigmap-lores-limited-biome]: http://i.imgur.com/iHCBfes.png +[resource-bigmap-lores-full-biome]: http://i.imgur.com/TIR1xv5.png + +[resource-overlay-window]: http://i.imgur.com/9PcxEqN.png + [color-window]: http://i.imgur.com/RQVjq6g.png [color-palette-switch]: http://i.imgur.com/0XdMGSy.gif [color-clamp-terrain]: http://i.imgur.com/8dgFLGj.gif @@ -659,28 +708,30 @@ sneaky then they can of course be sneaky. [3b]: #top-3b-mismatched-scanners [4]: #top-4-big-map [4a]: #top-4a-big-map-options -[5]: #top-5-zoom-map -[5a]: #top-5a-target-selection -[5b]: #top-5b-mechJeb-landing-guidance -[6]: #top-6-instrument-window -[7]: #top-7-parts-and-sensor-types -[7a]: #top-7a-the-radar-altimetry-sensor -[7b]: #top-7b-the-sar-altimetry-sensor -[7c]: #top-7c-the-multispectral-sensor -[7d]: #top-7d-been-there-done-that -[7e]: #top-7e-maptraq-deprecated -[8]: #top-8-career-mode-research-and-development -[8a]: #top-8a-minimum-scan-for-science -[8b]: #top-8b-getting-maximum-science -[8c]: #top-8c-contract-support -[9]: #top-9-color-management -[9a]: #top-9a-terrain-colors-and-options -[9b]: #top-9b-biome-colors-and-options -[9c]: #top-9c-resource-colors-and-options -[10]: #top-10-background-scanning -[11]: #top-11-time-warp -[12]: #top-12-settings-menu -[13]: #top-13-note-concerning-data-sources +[5]: #top-planetary-overlay +[5a]: #top-overlay-control-window +[6]: #top-6-zoom-map +[6a]: #top-6a-target-selection +[6b]: #top-6b-mechJeb-landing-guidance +[7]: #top-7-instrument-window +[8]: #top-8-parts-and-sensor-types +[8a]: #top-8a-the-radar-altimetry-sensor +[8b]: #top-8b-the-sar-altimetry-sensor +[8c]: #top-8c-the-multispectral-sensor +[8d]: #top-8d-been-there-done-that +[8e]: #top-8e-maptraq-deprecated +[9]: #top-9-career-mode-research-and-development +[9a]: #top-9a-minimum-scan-for-science +[9b]: #top-9b-getting-maximum-science +[9c]: #top-9c-contract-support +[10]: #top-10-color-management +[10a]: #top-10a-terrain-colors-and-options +[10b]: #top-10b-biome-colors-and-options +[10c]: #top-10c-resource-colors-and-options +[11]: #top-11-background-scanning +[12]: #top-12-time-warp +[13]: #top-13-settings-menu +[14]: #top-14-note-concerning-data-sources [shield:license-bsd]: http://img.shields.io/:license-bsd-blue.svg [shield:license-mit]: http://img.shields.io/:license-mit-a31f34.svg From 2f1db6a85e15611f0e75eebb2737096d6502cae1 Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 19:08:35 -0400 Subject: [PATCH 116/117] readme updates --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3f87a5cba..ae3e31feb 100644 --- a/README.md +++ b/README.md @@ -361,10 +361,10 @@ The re-size icon in the lower-right corner can be dragged to re-size the map. > ![][resource-planet-hires-full-biome] A separate window is used to control resource and biome planetary overlay maps. These maps are drawn directly over the surface of the current planet; they use the same system as the stock resource overlays and will replace those maps if both are opened at the same time. Map coverage is dependent upon SCANsat data; only scanned areas will be displayed on the map. -> ![][biome-planet-in-progress] +> ![][resource-planet-in-progress] SCANsat biome coverage can also be displayed using the overlay window. -> ![][resource-planet-in-progress] +> ![][biome-planet-overlay] #### [:top:][top] 5a. Overlay Control Window > ![][resource-overlay-window] @@ -708,8 +708,8 @@ sneaky then they can of course be sneaky. [3b]: #top-3b-mismatched-scanners [4]: #top-4-big-map [4a]: #top-4a-big-map-options -[5]: #top-planetary-overlay -[5a]: #top-overlay-control-window +[5]: #top-5-planetary-overlay +[5a]: #top-5a-overlay-control-window [6]: #top-6-zoom-map [6a]: #top-6a-target-selection [6b]: #top-6b-mechJeb-landing-guidance From 1de1807eb185f6fccd56fae2e0a5a7f34ffc28dc Mon Sep 17 00:00:00 2001 From: DMagic Date: Sat, 6 Jun 2015 19:09:35 -0400 Subject: [PATCH 117/117] A few more --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ae3e31feb..2859e0509 100644 --- a/README.md +++ b/README.md @@ -272,9 +272,8 @@ A number of options are available in the **Resource Settings Menu** for SCANsat * Regular SCANsat data will not be affected. * A confirmation window will appear upon clicking the button. * **Reset Stock Resource Scanning** - * Stock resource scanning data can be erased for each planet (does not affect resource biome scanning data) - -* **SCAN Planet Overlay** Quality Settings + * Stock resource scanning data can be erased for each planet (does not affect resource biome scanning data) +* **SCAN Planet Overlay Quality Settings** * Interpolation settings can be increased or decreased to increase the accuracy of overlays * Overlay map size can be adjusted for higher quality, but slower maps