Skip to content

Commit

Permalink
UI scale
Browse files Browse the repository at this point in the history
  • Loading branch information
DMagic1 committed Dec 30, 2016
1 parent 862500c commit 9b3fc7d
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 4 deletions.
2 changes: 2 additions & 0 deletions SCANsat.Unity/Interfaces/ISCAN_Instruments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface ISCAN_Instruments

bool Anomaly { get; }

float Scale { get; }

Texture AnomalyCamera { get; }

Vector2 Position { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions SCANsat.Unity/Interfaces/ISCAN_Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public interface ISCAN_Overlay

bool DrawTerrain { get; set; }

float Scale { get; }

IList<string> Resources { get; }

Vector2 Position { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions SCANsat.Unity/Unity/SCAN_BigMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,18 @@ public void setMap(ISCAN_BigMap map)
if (!map.ShowWaypoint && m_WaypointObject != null)
m_WaypointObject.SetActive(false);

SetScale(map.Scale);

SetPosition(map.Position);

loaded = true;
}

public void SetScale(float scale)
{
rect.localScale = Vector3.one * scale;
}

public void SetPosition(Vector2 pos)
{
if (rect == null)
Expand Down
7 changes: 7 additions & 0 deletions SCANsat.Unity/Unity/SCAN_Instruments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ public void SetInstruments(ISCAN_Instruments ins)
if (!ins.ResourceButtons && m_ResourceButtons != null)
m_ResourceButtons.gameObject.SetActive(false);

SetScale(ins.Scale);

SetPosition(ins.Position);
}

public void SetScale(float scale)
{
rect.localScale = Vector3.one * scale;
}

public void SetPosition(Vector2 pos)
{
if (rect == null)
Expand Down
7 changes: 7 additions & 0 deletions SCANsat.Unity/Unity/SCAN_Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ public void SetOverlay(ISCAN_Overlay over)

CreateResources(over.Resources);

SetScale(over.Scale);

SetPosition(over.Position);

loaded = true;
}

public void SetScale(float scale)
{
rect.localScale = Vector3.one * scale;
}

public void SetPosition(Vector2 pos)
{
if (rect == null)
Expand Down
7 changes: 7 additions & 0 deletions SCANsat.Unity/Unity/SCAN_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public void setSettings(ISCAN_Settings settings, int page)
m_GeneralToggle.isOn = true;
break;
}

SetScale(settings.UIScale);
}

public void SetScale(float scale)
{
rect.localScale = Vector3.one * scale;
}

public void OnBeginDrag(PointerEventData eventData)
Expand Down
19 changes: 16 additions & 3 deletions SCANsat/SCAN_Unity/SCAN_UI_BigMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private void initializeMap()
data = new SCANdata(b);
SCANcontroller.controller.addToBodyData(b, data);
}

bigmap.setBody(b);
}

Expand All @@ -82,6 +83,12 @@ public void OnDestroy()
SCANcontroller.controller.unloadPQS(bigmap.Body, mapSource.BigMap);
}

public void SetScale(float scale)
{
if (uiElement != null)
uiElement.SetScale(scale);
}

public void Update()
{
if (!_isVisible || data == null || bigmap == null)
Expand Down Expand Up @@ -357,7 +364,7 @@ public bool ShowWaypoint

public float Scale
{
get { return 1; }
get { return SCAN_Settings_Config.Instance.UIScale; }
}

public Vector2 Position
Expand All @@ -368,8 +375,14 @@ public Vector2 Position

public Vector2 Size
{
get { return new Vector2(1024, 512); }//return SCAN_Settings_Config.Instance.BigMapWidth; }
set { }
get
{
float width = SCAN_Settings_Config.Instance.BigMapWidth;
float height = width / 2;

return new Vector2(width, height);
}
set { SCAN_Settings_Config.Instance.BigMapWidth = (int)value.x; }
}

public IList<string> Projections
Expand Down
11 changes: 11 additions & 0 deletions SCANsat/SCAN_Unity/SCAN_UI_Instruments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public SCAN_UI_Instruments()
GameEvents.onVesselWasModified.Add(vesselChange);
}

public void SetScale(float scale)
{
if (uiElement != null)
uiElement.SetScale(scale);
}

public void Update()
{
if (!_isVisible || uiElement == null)
Expand Down Expand Up @@ -192,6 +198,11 @@ public bool Anomaly
get { return false; }
}

public float Scale
{
get { return SCAN_Settings_Config.Instance.UIScale; }
}

public Texture AnomalyCamera
{
get { return null; }
Expand Down
11 changes: 11 additions & 0 deletions SCANsat/SCAN_Unity/SCAN_UI_Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ private void switchScene(GameEvents.FromToAction<GameScenes, GameScenes> FT)
removeOverlay();
}

public void SetScale(float scale)
{
if (uiElement != null)
uiElement.SetScale(scale);
}

public void Update()
{

Expand Down Expand Up @@ -190,6 +196,11 @@ public bool DrawTerrain
}
}

public float Scale
{
get { return SCAN_Settings_Config.Instance.UIScale; }
}

public IList<string> Resources
{
get { return new List<string>(resources.Select(r => r.Name)); }
Expand Down
19 changes: 18 additions & 1 deletion SCANsat/SCAN_Unity/SCAN_UI_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,24 @@ public float StockThresholdValue
public float UIScale
{
get { return SCAN_Settings_Config.Instance.UIScale; }
set { SCAN_Settings_Config.Instance.UIScale = value; }
set
{
SCAN_Settings_Config.Instance.UIScale = value;

uiElement.SetScale(value);

if (SCAN_UI_BigMap.Instance != null && SCAN_UI_BigMap.Instance.IsVisible)
SCAN_UI_BigMap.Instance.SetScale(value);

if (SCAN_UI_MainMap.Instance != null && SCAN_UI_MainMap.Instance.IsVisible)
SCAN_UI_MainMap.Instance.SetScale(value);

if (SCAN_UI_Instruments.Instance != null && SCAN_UI_Instruments.Instance.IsVisible)
SCAN_UI_Instruments.Instance.SetScale(value);

if (SCAN_UI_Overlay.Instance != null && SCAN_UI_Overlay.Instance.IsVisible)
SCAN_UI_Overlay.Instance.SetScale(value);
}
}

public bool IsVisible
Expand Down

0 comments on commit 9b3fc7d

Please sign in to comment.