Skip to content

Commit

Permalink
Tooltip implementation and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DMagic1 committed Feb 1, 2017
1 parent b552c85 commit 289adab
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 16 deletions.
32 changes: 30 additions & 2 deletions SCANsat/SCAN_Unity/SCAN_UI_Instruments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using SCANsat.SCAN_Toolbar;
using SCANsat.Unity.Interfaces;
using SCANsat.Unity.Unity;
using SCANsat.SCAN_Data;
Expand Down Expand Up @@ -71,6 +72,12 @@ public void SetScale(float scale)
uiElement.SetScale(scale);
}

public void ProcessTooltips()
{
if (uiElement != null)
uiElement.ProcessTooltips();
}

public void Update()
{
if (!_isVisible || uiElement == null)
Expand Down Expand Up @@ -144,6 +151,12 @@ public void Open()
uiElement.SetInstruments(this);

_isVisible = true;

if (HighLogic.LoadedSceneIsFlight && SCAN_Settings_Config.Instance.StockToolbar && SCAN_Settings_Config.Instance.ToolbarMenu)
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.UIElement != null)
SCANappLauncher.Instance.UIElement.SetInstrumentToggle(true);
}
}

public void Close()
Expand All @@ -153,8 +166,13 @@ public void Close()
if (uiElement == null)
return;

uiElement.gameObject.SetActive(false);
MonoBehaviour.Destroy(uiElement.gameObject);
uiElement.FadeOut();

if (HighLogic.LoadedSceneIsFlight && SCAN_Settings_Config.Instance.StockToolbar && SCAN_Settings_Config.Instance.ToolbarMenu)
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.UIElement != null)
SCANappLauncher.Instance.UIElement.SetInstrumentToggle(false);
}
}

public string Version
Expand Down Expand Up @@ -207,6 +225,11 @@ public bool Anomaly
get { return false; }
}

public bool TooltipsOn
{
get { return SCAN_Settings_Config.Instance.WindowTooltips; }
}

public float Scale
{
get { return SCAN_Settings_Config.Instance.UIScale; }
Expand All @@ -217,6 +240,11 @@ public Texture AnomalyCamera
get { return null; }
}

public Canvas TooltipCanvas
{
get { return UIMasterController.Instance.tooltipCanvas; }
}

public Vector2 Position
{
get { return SCAN_Settings_Config.Instance.InstrumentsPosition; }
Expand Down
61 changes: 56 additions & 5 deletions SCANsat/SCAN_Unity/SCAN_UI_MainMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using SCANsat.SCAN_Toolbar;
using SCANsat.Unity.Interfaces;
using SCANsat.Unity;
using SCANsat.Unity.Unity;
Expand Down Expand Up @@ -57,6 +58,9 @@ public SCAN_UI_MainMap()
GameEvents.onVesselSOIChanged.Add(soiChange);
GameEvents.onVesselChange.Add(vesselChange);
GameEvents.onVesselWasModified.Add(vesselChange);

if (SCANcontroller.controller.mainMapVisible)
Open();
}

public void OnDestroy()
Expand Down Expand Up @@ -114,6 +118,12 @@ public void SetScale(float scale)
uiElement.SetScale(scale);
}

public void ProcessTooltips()
{
if (uiElement != null)
uiElement.ProcessTooltips();
}

public void Update()
{
if (!_isVisible || data == null)
Expand Down Expand Up @@ -215,7 +225,7 @@ public void Open()
{
data = new SCANdata(v.mainBody);
SCANcontroller.controller.addToBodyData(v.mainBody, data);
}
}

uiElement = GameObject.Instantiate(SCAN_UI_Loader.MainMapPrefab).GetComponent<SCAN_MainMap>();

Expand All @@ -229,17 +239,46 @@ public void Open()
uiElement.UpdateMapTexture(map_small);

_isVisible = true;
SCANcontroller.controller.mainMapVisible = true;

if (HighLogic.LoadedSceneIsFlight && SCAN_Settings_Config.Instance.StockToolbar)
{
if (SCAN_Settings_Config.Instance.ToolbarMenu)
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.UIElement != null)
SCANappLauncher.Instance.UIElement.SetMainMapToggle(true);
}
else
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.SCANAppButton != null)
SCANappLauncher.Instance.SCANAppButton.SetTrue(false);
}
}
}

public void Close()
{
_isVisible = false;
SCANcontroller.controller.mainMapVisible = false;

if (uiElement == null)
return;

uiElement.gameObject.SetActive(false);
MonoBehaviour.Destroy(uiElement.gameObject);
uiElement.FadeOut();

if (HighLogic.LoadedSceneIsFlight && SCAN_Settings_Config.Instance.StockToolbar)
{
if (SCAN_Settings_Config.Instance.ToolbarMenu)
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.UIElement != null)
SCANappLauncher.Instance.UIElement.SetMainMapToggle(false);
}
else
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.SCANAppButton != null)
SCANappLauncher.Instance.SCANAppButton.SetFalse(false);
}
}
}

public bool IsVisible
Expand Down Expand Up @@ -282,11 +321,21 @@ public bool Minimized
set { SCANcontroller.controller.mainMapMinimized = value; }
}

public bool TooltipsOn
{
get { return SCAN_Settings_Config.Instance.WindowTooltips; }
}

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

public Canvas TooltipCanvas
{
get { return UIMasterController.Instance.tooltipCanvas; }
}

public Vector2 Position
{
get { return SCAN_Settings_Config.Instance.MainMapPosition; }
Expand Down Expand Up @@ -355,7 +404,8 @@ public Dictionary<Guid, MapLabelInfo> VesselInfoList
baseColor = Color ? palette.white : palette.cb_skyBlue,
flashColor = palette.cb_yellow,
flash = true,
width = 18
width = 18,
show = true
});

int count = 2;
Expand All @@ -378,7 +428,8 @@ public Dictionary<Guid, MapLabelInfo> VesselInfoList
pos = VesselPosition(sv.vessel.id),
baseColor = Color ? palette.white : palette.cb_skyBlue,
flash = false,
width = 18
width = 18,
show = true
});

count++;
Expand Down
32 changes: 30 additions & 2 deletions SCANsat/SCAN_Unity/SCAN_UI_Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Text;
using UnityEngine;
using SCANsat.SCAN_Toolbar;
using SCANsat.Unity.Interfaces;
using SCANsat.Unity.Unity;
using SCANsat.SCAN_Data;
Expand Down Expand Up @@ -86,6 +87,12 @@ public void SetScale(float scale)
uiElement.SetScale(scale);
}

public void ProcessTooltips()
{
if (uiElement != null)
uiElement.ProcessTooltips();
}

public void Update()
{
if ((MapView.MapIsEnabled && HighLogic.LoadedSceneIsFlight && FlightGlobals.ready) || HighLogic.LoadedScene == GameScenes.TRACKSTATION)
Expand Down Expand Up @@ -117,6 +124,12 @@ public void Open()
uiElement.SetOverlay(this);

_isVisible = true;

if (HighLogic.LoadedSceneIsFlight && SCAN_Settings_Config.Instance.StockToolbar && SCAN_Settings_Config.Instance.ToolbarMenu)
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.UIElement != null)
SCANappLauncher.Instance.UIElement.SetOverlayToggle(true);
}
}

public void Close()
Expand All @@ -126,8 +139,13 @@ public void Close()
if (uiElement == null)
return;

uiElement.gameObject.SetActive(false);
MonoBehaviour.Destroy(uiElement.gameObject);
uiElement.FadeOut();

if (HighLogic.LoadedSceneIsFlight && SCAN_Settings_Config.Instance.StockToolbar && SCAN_Settings_Config.Instance.ToolbarMenu)
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.UIElement != null)
SCANappLauncher.Instance.UIElement.SetOverlayToggle(false);
}
}

public string Version
Expand Down Expand Up @@ -216,11 +234,21 @@ public bool DrawResource
get { return SCANcontroller.controller.overlaySelection == 2; }
}

public bool TooltipsOn
{
get { return SCAN_Settings_Config.Instance.WindowTooltips; }
}

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

public Canvas TooltipCanvas
{
get { return UIMasterController.Instance.tooltipCanvas; }
}

public IList<string> Resources
{
get { return new List<string>(resources.Select(r => r.Name)); }
Expand Down
59 changes: 52 additions & 7 deletions SCANsat/SCAN_Unity/SCAN_UI_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ public void Open(int page = 0, bool savePosition = false)
uiElement.setSettings(this, page);

if (!savePosition)
_position = new Vector2();
_position = new Vector2(0, 100);

uiElement.SetPosition(_position);

_isVisible = true;

if (HighLogic.LoadedSceneIsFlight && SCAN_Settings_Config.Instance.StockToolbar && SCAN_Settings_Config.Instance.ToolbarMenu)
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.UIElement != null)
SCANappLauncher.Instance.UIElement.SetSettingsToggle(true);
}
}

public void Close()
Expand All @@ -88,8 +94,15 @@ public void Close()
if (uiElement == null)
return;

uiElement.gameObject.SetActive(false);
MonoBehaviour.Destroy(uiElement.gameObject);
uiElement.FadeOut();

uiElement.FadeOut();

if (HighLogic.LoadedSceneIsFlight && SCAN_Settings_Config.Instance.StockToolbar && SCAN_Settings_Config.Instance.ToolbarMenu)
{
if (SCANappLauncher.Instance != null && SCANappLauncher.Instance.UIElement != null)
SCANappLauncher.Instance.UIElement.SetSettingsToggle(false);
}
}

public string Version
Expand Down Expand Up @@ -206,7 +219,28 @@ public bool OverlayTooltips
public bool WindowTooltips
{
get { return SCAN_Settings_Config.Instance.WindowTooltips; }
set { SCAN_Settings_Config.Instance.WindowTooltips = value; }
set
{
SCAN_Settings_Config.Instance.WindowTooltips = value;

SCAN_UI_Loader.ToggleTooltips(value);

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

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

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

if (SCAN_UI_Overlay.Instance != null && SCAN_UI_Overlay.Instance.IsVisible)
SCAN_UI_Overlay.Instance.ProcessTooltips();

if (SCAN_Settings_Config.Instance.StockToolbar && SCAN_Settings_Config.Instance.ToolbarMenu
&& SCANappLauncher.Instance != null && SCANappLauncher.Instance.IsVisible)
SCANappLauncher.Instance.ProcessTooltips();
}
}

public bool StockToolbar
Expand All @@ -229,7 +263,13 @@ public bool StockToolbar
public bool ToolbarMenu
{
get { return SCAN_Settings_Config.Instance.ToolbarMenu; }
set { SCAN_Settings_Config.Instance.ToolbarMenu = value; }
set
{
SCAN_Settings_Config.Instance.ToolbarMenu = value;

if (SCANappLauncher.Instance != null)
SCANappLauncher.Instance.ToggleToolbarType();
}
}

public bool StockUIStyle
Expand Down Expand Up @@ -326,7 +366,12 @@ public bool ShowMapFill
{
get { return SCAN_Settings_Config.Instance.CheatMapFill; }
}


public Canvas TooltipCanvas
{
get { return UIMasterController.Instance.tooltipCanvas; }
}

public Vector2 Position
{
set { _position = value; }
Expand Down Expand Up @@ -445,7 +490,7 @@ public double BodyPercentage(string bodyName)
if (data == null)
return 0;

return SCANUtil.getCoveragePercentage(data, SCANtype.Nothing);
return SCANUtil.getCoveragePercentage(data, SCANtype.Nothing) / 100;
}

private CelestialBody getTargetBody()
Expand Down

0 comments on commit 289adab

Please sign in to comment.