Skip to content

Commit

Permalink
Fix auto refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
DMagic1 committed Aug 20, 2019
1 parent 5d2315f commit c920b89
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 85 deletions.
165 changes: 80 additions & 85 deletions SCANsat.Unity/Unity/SCAN_ZoomMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,99 +155,89 @@ protected override void Awake()
Alpha(0);
}

private void Update()
{
if (zoomInterface == null || !zoomInterface.IsVisible)
return;
private void Update()
{
if (zoomInterface == null || !zoomInterface.IsVisible)
return;

if (zoomInterface.LockInput)
{
if (m_WaypointInput != null && !m_WaypointInput.IsFocused)
zoomInterface.LockInput = false;
}
if (zoomInterface.LockInput)
{
if (m_WaypointInput != null && !m_WaypointInput.IsFocused)
zoomInterface.LockInput = false;
}

zoomInterface.Update();
zoomInterface.Update();

if (vesselLabel != null)
{
Vector2 pos = zoomInterface.VesselPosition();
if (vesselLabel != null)
{
Vector2 pos = zoomInterface.VesselPosition();

if (pos.x < 0 || pos.y < 0)
vesselLabel.UpdateActive(false);
else
{
vesselLabel.UpdateActive(true);
vesselLabel.UpdatePosition(pos);
}
}
if (pos.x < 0 || pos.y < 0)
vesselLabel.UpdateActive(false);
else
{
vesselLabel.UpdateActive(true);
vesselLabel.UpdatePosition(pos);
}
}

if (inMap && m_ZoomImage != null && m_ReadoutText != null)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_ZoomImage.rectTransform, Input.mousePosition, zoomInterface.MainCanvas.worldCamera, out rectPos);
if (inMap && m_ZoomImage != null && m_ReadoutText != null)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_ZoomImage.rectTransform, Input.mousePosition, zoomInterface.MainCanvas.worldCamera, out rectPos);

m_ReadoutText.OnTextUpdate.Invoke(zoomInterface.MapInfo(rectPos));
m_ReadoutText.OnTextUpdate.Invoke(zoomInterface.MapInfo(rectPos));

if (waypointSelecting)
{
if (hoverWaypointLabel != null)
{
Vector2 mapPos = new Vector2(rectPos.x, rectPos.y + zoomInterface.Size.y);
if (waypointSelecting)
{
if (hoverWaypointLabel != null)
{
Vector2 mapPos = new Vector2(rectPos.x, rectPos.y + zoomInterface.Size.y);

hoverWaypointLabel.UpdateActive(true);
hoverWaypointLabel.UpdateActive(true);

hoverWaypointLabel.UpdatePosition(mapPos);
}
}
}
else if (waypointSelecting)
{
if (hoverWaypointLabel != null)
hoverWaypointLabel.UpdateActive(false);
}
hoverWaypointLabel.UpdatePosition(mapPos);
}
}
}
else if (waypointSelecting)
{
if (hoverWaypointLabel != null)
hoverWaypointLabel.UpdateActive(false);
}

if (tooltipOn)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_LegendImage.rectTransform, Input.mousePosition, zoomInterface.MainCanvas.worldCamera, out rectPos);
if (tooltipOn)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_LegendImage.rectTransform, Input.mousePosition, zoomInterface.MainCanvas.worldCamera, out rectPos);

float halfWidth = m_LegendImage.rectTransform.rect.width / 2;
float halfWidth = m_LegendImage.rectTransform.rect.width / 2;

float legendXPos = (rectPos.x + halfWidth) / m_LegendImage.rectTransform.rect.width;
float legendXPos = (rectPos.x + halfWidth) / m_LegendImage.rectTransform.rect.width;

if (_tooltip != null)
_tooltip.UpdateText(zoomInterface.TooltipText(legendXPos));
}
if (_tooltip != null)
_tooltip.UpdateText(zoomInterface.TooltipText(legendXPos));
}

if (zoomInterface.OrbitToggle && zoomInterface.ShowOrbit)
{
for (int i = orbitLabels.Count - 1; i >= 0; i--)
{
SCAN_SimpleLabel label = orbitLabels[i];
if (zoomInterface.OrbitToggle && zoomInterface.ShowOrbit)
{
for (int i = orbitLabels.Count - 1; i >= 0; i--)
{
SCAN_SimpleLabel label = orbitLabels[i];

label.UpdateIcon(zoomInterface.OrbitInfo(i));
}
label.UpdateIcon(zoomInterface.OrbitInfo(i));
}

for (int i = orbitIconLabels.Count - 1; i >= 0; i--)
{
SCAN_MapLabel label = orbitIconLabels[i];
for (int i = orbitIconLabels.Count - 1; i >= 0; i--)
{
SCAN_MapLabel label = orbitIconLabels[i];

label.UpdatePositionActivation(zoomInterface.OrbitIconInfo(label.StringID));
}
}
label.UpdatePositionActivation(zoomInterface.OrbitIconInfo(label.StringID));
}
}

if (zoomInterface.MapRefresh > 0 && !resizing && !zoomInterface.Rebuilding)
{
float time = Time.realtimeSinceStartup;

if (zoomInterface.MapRefresh == 1)
{
if (time > nextRefresh)
RefreshMap();
}
else
{
if (time > nextRefresh)
RefreshMap();
}
if (Time.realtimeSinceStartup > nextRefresh)
RefreshMap();
}
}

Expand Down Expand Up @@ -521,23 +511,28 @@ private void SetRefreshState(int i)
m_AutoRefresh.color = Color.green;
break;
}

ResetRefreshState(i);
}

private void ResetRefreshState(int i)
{
switch (i)
if (zoomInterface.Rebuilding)
nextRefresh = float.MaxValue;
else
{
case 0:
nextRefresh = float.MaxValue;
break;
case 1:
nextRefresh = Time.realtimeSinceStartup + refreshTimeOne;
break;
case 2:
nextRefresh = Time.realtimeSinceStartup + refreshTimeTwo;
break;
switch (i)
{
case 0:
nextRefresh = float.MaxValue;
break;
case 1:
nextRefresh = Time.realtimeSinceStartup + refreshTimeOne;
break;
case 2:
nextRefresh = Time.realtimeSinceStartup + refreshTimeTwo;
break;
}
}
}

Expand Down Expand Up @@ -1170,7 +1165,7 @@ public void UpdateMapTexture(Texture2D map)

public void UpdateMapData(bool text)
{
if (text)
if (text || zoomInterface.VesselLock)
ResetText();

ResetRefreshState(zoomInterface.MapRefresh);
Expand Down
2 changes: 2 additions & 0 deletions SCANsat/SCAN_Unity/SCAN_UI_ZoomMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ private void initializeMapCenter(double lat, double lon, CelestialBody b)
spotmap.ColorMap = SCANcontroller.controller.zoomMapColor;
spotmap.Terminator = SCANcontroller.controller.zoomMapTerminator;

rebuilding = true;

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

Expand Down

0 comments on commit c920b89

Please sign in to comment.