Skip to content

Commit

Permalink
Use events for stock resource scan; fix hiding UI
Browse files Browse the repository at this point in the history
  • Loading branch information
DMagic1 committed Nov 4, 2016
1 parent ab564f2 commit 2b93490
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 56 deletions.
18 changes: 17 additions & 1 deletion SCANsat/SCAN_UI/SCANresourceSettings.cs
Expand Up @@ -187,6 +187,22 @@ protected override void DrawWindowPost(int id)
warningMMLoaded = !warningMMLoaded;
}
}
else
{
if (oldInstantScan != SCANcontroller.controller.easyModeScanning)
{
oldInstantScan = SCANcontroller.controller.easyModeScanning;
if (oldInstantScan)
{
for (int i = FlightGlobals.Bodies.Count - 1; i >= 0; i--)
{
CelestialBody b = FlightGlobals.Bodies[i];

SCANcontroller.controller.checkStockResourceScanStatus(b);
}
}
}
}

if (oldNarrowBand != SCANcontroller.controller.needsNarrowBand)
{
Expand All @@ -200,7 +216,7 @@ protected override void DrawWindowPost(int id)
oldStockScanThreshold = SCANcontroller.controller.useScanThreshold;
if (oldStockScanThreshold)
{
for (int i = 0; i < FlightGlobals.Bodies.Count; i++)
for (int i = FlightGlobals.Bodies.Count - 1; i >= 0; i--)
{
CelestialBody b = FlightGlobals.Bodies[i];

Expand Down
104 changes: 49 additions & 55 deletions SCANsat/SCANcontroller.cs
Expand Up @@ -211,9 +211,6 @@ public static SCANcontroller controller
/* Used as holder for vessel id's while loading */
private List<Guid> tempIDs = new List<Guid>();

private CelestialBody body = null;
private bool bodyScanned = false;
private bool bodyCoverage = false;
private bool heightMapsBuilt = false;

private static SCANcontroller instance;
Expand Down Expand Up @@ -923,6 +920,7 @@ private void Start()
GameEvents.onGUIAstronautComplexSpawn.Add(UIOff);
GameEvents.onGUIAstronautComplexDespawn.Add(UIOn);

GameEvents.OnOrbitalSurveyCompleted.Add(onSurvey);
GameEvents.onVesselSOIChanged.Add(SOIChange);
GameEvents.onVesselCreate.Add(newVesselCheck);
GameEvents.onPartCouple.Add(dockingEventCheck);
Expand Down Expand Up @@ -973,13 +971,22 @@ private void Start()

if (disableStockResource && useScanThreshold)
{
for (int i = 0; i < FlightGlobals.Bodies.Count; i++)
{
for (int i = FlightGlobals.Bodies.Count - 1; i >= 0; i--)
{
CelestialBody b = FlightGlobals.Bodies[i];

checkResourceScanStatus(b);
}
}
else if (!disableStockResource && easyModeScanning)
{
for (int i = FlightGlobals.Bodies.Count - 1; i >= 0; i--)
{
CelestialBody b = FlightGlobals.Bodies[i];

checkStockResourceScanStatus(b);
}
}
}

private void Update()
Expand All @@ -989,61 +996,28 @@ private void Update()

if (!heightMapsBuilt)
checkHeightMapStatus();
}

if (!HighLogic.LoadedSceneIsFlight && HighLogic.LoadedScene != GameScenes.TRACKSTATION)
public void checkStockResourceScanStatus(CelestialBody body)
{
if (disableStockResource || !easyModeScanning)
return;

if (!easyModeScanning || disableStockResource)
if (body == null)
return;

if (body == null)
{
if (HighLogic.LoadedSceneIsFlight)
{
body = FlightGlobals.ActiveVessel.mainBody;
bodyScanned = false;
bodyCoverage = false;
}
else if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
{
MapObject target = PlanetariumCamera.fetch.target;
if (!ResourceMap.Instance.IsPlanetScanned(body.flightGlobalsIndex))
return;

if (target.type != MapObject.ObjectType.CelestialBody)
{
body = null;
return;
}
if (SCANUtil.GetCoverage((int)SCANtype.AllResources, body) >= 100)
return;

body = target.celestialBody;
bodyScanned = false;
bodyCoverage = false;
}
}
SCANdata data = getData(body.name);

if (bodyScanned)
if (data == null)
return;

if (!bodyCoverage)
{
if (SCANUtil.GetCoverage((int)SCANtype.AllResources, body) >= 100)
{
bodyScanned = true;
return;
}
bodyCoverage = true;
}

if (ResourceMap.Instance.IsPlanetScanned(body.flightGlobalsIndex))
{
SCANdata data = SCANUtil.getData(body);
if (data == null)
{
data = new SCANdata(body);
addToBodyData(body, data);
}
data.fillResourceMap();
bodyScanned = true;
}
data.fillResourceMap();
}

public void checkResourceScanStatus(CelestialBody body)
Expand Down Expand Up @@ -1126,8 +1100,8 @@ private void checkHeightMapStatus()

private void OnDestroy()
{
GameEvents.onShowUI.Remove(UIOn);
GameEvents.onHideUI.Remove(UIOff);
GameEvents.onShowUI.Remove(UIShow);
GameEvents.onHideUI.Remove(UIHide);
GameEvents.onGUIMissionControlSpawn.Remove(UIOff);
GameEvents.onGUIMissionControlDespawn.Remove(UIOn);
GameEvents.onGUIRnDComplexSpawn.Remove(UIOff);
Expand All @@ -1137,6 +1111,7 @@ private void OnDestroy()
GameEvents.onGUIAstronautComplexSpawn.Remove(UIOff);
GameEvents.onGUIAstronautComplexDespawn.Remove(UIOn);

GameEvents.OnOrbitalSurveyCompleted.Remove(onSurvey);
GameEvents.onVesselSOIChanged.Remove(SOIChange);
GameEvents.onVesselCreate.Remove(newVesselCheck);
GameEvents.onPartCouple.Remove(dockingEventCheck);
Expand Down Expand Up @@ -1194,6 +1169,28 @@ private void UIHide()
showUI = false;
}

private void onSurvey(Vessel v, CelestialBody b)
{
if (!easyModeScanning || disableStockResource)
return;

if (b == null)
return;

if (SCANUtil.GetCoverage((int)SCANtype.AllResources, b) >= 100)
return;

SCANdata data = SCANUtil.getData(b);

if (data == null)
{
data = new SCANdata(b);
addToBodyData(b, data);
}

data.fillResourceMap();
}

internal void loadPQS(CelestialBody b, mapSource s = mapSource.Data)
{
if (!SCANmainMenuLoader.KopernicusLoaded)
Expand Down Expand Up @@ -1595,9 +1592,6 @@ private void SOIChange(GameEvents.HostedFromToAction<Vessel, CelestialBody> VC)
{
if (!body_data.Contains(VC.to.name))
body_data.Add(VC.to.name, new SCANdata(VC.to));
body = VC.to;
bodyScanned = false;
bodyCoverage = false;
}

private void setNewTerrainConfigValues(SCANterrainConfig terrain, float min, float max, float? clamp, Palette c, int size, bool reverse, bool discrete)
Expand Down

0 comments on commit 2b93490

Please sign in to comment.