Skip to content

Commit

Permalink
Open zoom map from big map
Browse files Browse the repository at this point in the history
  • Loading branch information
DMagic1 committed Feb 11, 2017
1 parent e57943a commit cfbad3c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
11 changes: 10 additions & 1 deletion SCANsat/SCAN_Unity/SCAN_UI_BigMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,16 @@ public void ClickMap(Vector2 pos)
{
Vector2d mapPos = MousePosition(pos);


if (SCANcontroller.controller.zoomMapVesselLock)
return;

if (SCAN_UI_ZoomMap.Instance == null)
return;

if (SCAN_UI_ZoomMap.Instance.IsVisible)
SCAN_UI_ZoomMap.Instance.Close();

SCAN_UI_ZoomMap.Instance.Open(false, mapPos.y, mapPos.x, bigmap);
}

public void RefreshMap()
Expand Down
36 changes: 15 additions & 21 deletions SCANsat/SCAN_Unity/SCAN_UI_ZoomMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ public SCAN_UI_ZoomMap()
GameEvents.onVesselChange.Add(vesselChange);
GameEvents.onVesselWasModified.Add(vesselChange);
GameEvents.onVesselSOIChanged.Add(soiChange);
GameEvents.onShowUI.Add(showUI);
GameEvents.onHideUI.Add(hideUI);

gen = new System.Random(Environment.TickCount.GetHashCode());

Expand All @@ -102,18 +100,6 @@ private void soiChange(GameEvents.HostedFromToAction<Vessel, CelestialBody> acti
updateMap = true;
}

private void showUI()
{
if (IsVisible && uiElement != null)
uiElement.gameObject.SetActive(true);
}

private void hideUI()
{
if (IsVisible && uiElement != null)
uiElement.gameObject.SetActive(false);
}

private void initializeMap()
{
if (HighLogic.LoadedSceneIsFlight)
Expand Down Expand Up @@ -225,6 +211,9 @@ private void initializeMapCenter(double lat, double lon, CelestialBody body)
t = mapType.Altimetry;
}

spotmap.ResourceActive = SCANcontroller.controller.zoomMapResourceOn;
spotmap.ColorMap = SCANcontroller.controller.zoomMapColor;

spotmap.resetMap(t, false, ResourceToggle, narrowBand);
}

Expand Down Expand Up @@ -436,8 +425,6 @@ public void OnDestroy()
GameEvents.onVesselChange.Remove(vesselChange);
GameEvents.onVesselWasModified.Remove(vesselChange);
GameEvents.onVesselSOIChanged.Remove(soiChange);
GameEvents.onShowUI.Remove(showUI);
GameEvents.onHideUI.Remove(hideUI);

if (uiElement != null)
{
Expand Down Expand Up @@ -879,7 +866,7 @@ private bool mapPosAtT(Orbit o, double dT, double startUT, out Vector2 labelPos)
}
}

public void Open(bool v, double lat = 0, double lon = 0, CelestialBody b = null)
public void Open(bool v, double lat = 0, double lon = 0, SCANmap m = null)
{
uiElement = GameObject.Instantiate(SCAN_UI_Loader.ZoomMapPrefab).GetComponent<SCAN_ZoomMap>();

Expand Down Expand Up @@ -908,7 +895,7 @@ public void Open(bool v, double lat = 0, double lon = 0, CelestialBody b = null)
if (v || VesselLock)
setToVessel();
else
setToPosition(lat, lon, b);
setToPosition(lat, lon, m);

uiElement.setMap(this);

Expand Down Expand Up @@ -939,18 +926,25 @@ public void Close()
}
}

private void setToPosition(double lat, double lon, CelestialBody b)
public void setToPosition(double lat, double lon, SCANmap map)
{
initializeMapCenter(SCANUtil.fixLatShift(lat), SCANUtil.fixLonShift(lon), b);
SCANcontroller.controller.zoomMapType = map.MType.ToString();
SCANcontroller.controller.zoomMapColor = map.ColorMap;
SCANcontroller.controller.zoomMapResource = map.Resource.Name;
SCANcontroller.controller.zoomMapResourceOn = map.ResourceActive;

initializeMapCenter(SCANUtil.fixLatShift(lat), SCANUtil.fixLonShift(lon), map.Body);

initialized = true;
}

public void setToVessel()
{
if (vessel == null)
{
initializeMapCenter(0, 0, FlightGlobals.GetHomeBody());
return;

}
if(initialized && !VesselLock)
return;

Expand Down

0 comments on commit cfbad3c

Please sign in to comment.