Skip to content

Commit

Permalink
Merge pull request #260 from DMagic1/dev
Browse files Browse the repository at this point in the history
Version 17.4
  • Loading branch information
DMagic1 authored Mar 7, 2017
2 parents 24559e0 + 4682149 commit a701529
Show file tree
Hide file tree
Showing 159 changed files with 2,032 additions and 827 deletions.
6 changes: 4 additions & 2 deletions SCANassets/Resources/SCANlocalization.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ SCAN_Localization
settingsHelpStockUIStyle = Switch between stock KSP-style UI elements and Unity-style elements.
settingsHelpOverlayTooltips = Displays tooltips for the current mouse position when a planetary overlay map is activated.\nThese tooltips include The cursor coordinates, terrain height, slope, biome name,\nand resource abundance, depending on scanning coverage.
settingsHelpWindowTooltips = Display tooltips on some map window buttons.\nThese are primarily used to identify icon buttons.
settingsHelpLegendTooltips = Display tooltips on the map legend.\nDisabling will also disable biome map legends.
settingsHelpStockToolbar = Use the stock toolbar.\nCan be used concurrently with the Blizzy78 Toolbar.
settingsHelpToolbarMenu = Use a pop-out menu for the stock toolbar to show all available windows.
settingsHelpMechJeb = The SCANsat zoom map target selection mode can be used to select a MechJeb landing site.
settingsHelpSlowMap = Enable this to reduce map generation speed.\nThis will save CPU resources and may reduce the performance impact\nof generating the small and/or big map.
settingsHelpMechJeb = The SCANsat zoom map and big map waypoint selection modes\ncan be used to select a MechJeb landing site.
settingsHelpMechJebLoad = Load a saved MechJeb landing target.\nThis only works while in the flight scene with a valid MechJeb vessel.
settingsHelpMapGenSpeed = Adjust all SCANsat map generation speeds.\nLower values will save CPU resources and may reduce the\nperformance impact of generating maps.
settingsHelpResetWindows = Reset all window positions and scale.\nUse this in case a window has been dragged completely\noff screen or if any windows are not visible.
settingsHelpResetPlanetData = Resets all SCANsat data for the current celestial body.\nA confirmation window will open before activating.\nCannot be reversed.
settingsHelpResetAllData = Resets all SCANsat data for all celestial bodies.\nA confirmation window will open before activating.\nCannot be reversed.
Expand Down
Binary file added SCANassets/Resources/scan_icons.scan
Binary file not shown.
Binary file removed SCANassets/Resources/scan_images
Binary file not shown.
Binary file added SCANassets/Resources/scan_prefabs.scan
Binary file not shown.
Binary file added SCANassets/Resources/scan_shaders-linux.scan
Binary file not shown.
Binary file added SCANassets/Resources/scan_shaders-macosx.scan
Binary file not shown.
Binary file added SCANassets/Resources/scan_shaders-windows.scan
Binary file not shown.
Binary file added SCANassets/Resources/scan_unity_skin.scan
Binary file not shown.
Binary file removed SCANassets/Resources/scansat_prefabs
Binary file not shown.
2 changes: 1 addition & 1 deletion SCANassets/SCANsat.version
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"MAJOR":1,
"MINOR":1,
"PATCH":7,
"BUILD":3
"BUILD":4
},
"KSP_VERSION":{
"MAJOR":1,
Expand Down
10 changes: 5 additions & 5 deletions SCANmechjeb/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.11")]
[assembly: AssemblyFileVersion("1.6.0.11")]
[assembly: AssemblyInformationalVersion ("v16.11")]
[assembly: AssemblyVersion("1.7.4.0")]
[assembly: AssemblyFileVersion("1.7.4.0")]
[assembly: AssemblyInformationalVersion ("v17.4")]

[assembly: KSPAssembly ("SCANmechjeb", 0, 4)]
[assembly: KSPAssemblyDependency ("SCANsat", 1, 6)]
[assembly: KSPAssembly ("SCANmechjeb", 0, 5)]
[assembly: KSPAssemblyDependency ("SCANsat", 1, 7)]
[assembly: KSPAssemblyDependency("MechJeb2", 2, 5)]
2 changes: 2 additions & 0 deletions SCANmechjeb/SCANmechStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ private void Start()
print("[SCANsatMechJeb] Starting SCANsat - MechJeb Interface...");
SCANmechjebInt = gameObject.AddComponent<SCANmechjeb>();
}
else
Destroy(gameObject);
}
}
}
251 changes: 121 additions & 130 deletions SCANmechjeb/SCANmechjeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,176 +11,107 @@
*/
#endregion

using System.Collections;
using SCANsat;
using SCANsat.SCAN_Data;
using SCANsat.SCAN_Platform;
using log = SCANsat.SCAN_Platform.Logging.ConsoleLogger;
using palette = SCANsat.SCAN_UI.UI_Framework.SCANpalette;
using MuMech;

using UnityEngine;
using UnityEngine.Events;

namespace SCANmechjeb
{
class SCANmechjeb : SCAN_MBE
class SCANmechjeb : MonoBehaviour
{
private const string siteName = "MechJeb Landing Target";
private Vessel v;
private Vessel vessel;
private CelestialBody body;
private MechJebCore mjCore;
private MechJebModuleTargetController target;
private DisplayModule guidanceModule;
private SCANwaypoint way;
private SCANdata data;
private Vector2d coords = new Vector2d();
private bool selectingTarget, selectingInMap, shutdown;
private bool shutdown, mjOnboard, mjTechTreeLocked;

protected override void LateUpdate()
private void Start()
{
if (shutdown)
return;
GameEvents.onVesselWasModified.Add(VesselChange);
GameEvents.onVesselChange.Add(VesselChange);
GameEvents.onVesselSOIChanged.Add(SOIChange);
SCANcontroller.controller.MJTargetSet.AddListener(new UnityAction<Vector2d, CelestialBody>(OnTargetSet));

if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready)
return;
StartCoroutine(WaitForReady());
}

if (SCANcontroller.controller == null)
{
way = null;
return;
}
private IEnumerator WaitForReady()
{
shutdown = true;

if (!SCANcontroller.controller.mechJebTargetSelection)
{
way = null;
return;
}
while (!FlightGlobals.ready || FlightGlobals.ActiveVessel == null)
yield return null;

v = FlightGlobals.ActiveVessel;
vessel = FlightGlobals.ActiveVessel;

if (v == null)
{
SCANcontroller.controller.MechJebLoaded = false;
way = null;
return;
}
if (vessel == null)
yield break;

if (v.mainBody != SCANcontroller.controller.LandingTargetBody)
SCANcontroller.controller.LandingTargetBody = v.mainBody;
VesselChange(vessel);

data = SCANUtil.getData(v.mainBody);
body = vessel.mainBody;

if (data == null)
{
SCANcontroller.controller.MechJebLoaded = false;
way = null;
return;
}
data = SCANUtil.getData(body);

if (v.FindPartModulesImplementing<MechJebCore>().Count <= 0)
{
SCANcontroller.controller.MechJebLoaded = false;
way = null;
return;
}
if (data == null)
shutdown = true;
else
shutdown = false;
}

mjCore = v.GetMasterMechJeb();
private void OnDestroy()
{
GameEvents.onVesselChange.Remove(VesselChange);
GameEvents.onVesselWasModified.Remove(VesselChange);
GameEvents.onVesselSOIChanged.Remove(SOIChange);
SCANcontroller.controller.MJTargetSet.RemoveListener(OnTargetSet);
}

if (mjCore == null)
{
SCANcontroller.controller.MechJebLoaded = false;
way = null;
private void LateUpdate()
{
if (shutdown || !mjOnboard || mjTechTreeLocked || body == null || vessel == null || data == null)
return;
}

if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
{
if (guidanceModule == null)
guidanceModule = (DisplayModule)mjCore.GetComputerModule("MechJebModuleLandingGuidance");

if (guidanceModule == null)
{
SCANcontroller.controller.MechJebLoaded = false;
way = null;
return;
}

if (!guidanceModule.unlockChecked)
return;
if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready)
return;

if (guidanceModule.hidden)
{
SCANcontroller.controller.MechJebLoaded = false;
shutdown = true;
way = null;
return;
}
}
way = null;

target = mjCore.target;
if (!SCAN_Settings_Config.Instance.MechJebTarget)
return;

if (target == null)
{
SCANcontroller.controller.MechJebLoaded = false;
way = null;
if (SCANcontroller.controller == null)
return;
}

if (!SCANcontroller.controller.MechJebLoaded)
{
SCANcontroller.controller.MechJebLoaded = true;
}

if (SCANcontroller.controller.LandingTarget != null)
{
way = SCANcontroller.controller.LandingTarget;
}

if (SCANcontroller.controller.TargetSelecting)
{
way = null;
selectingTarget = true;
if (SCANcontroller.controller.TargetSelectingActive)
selectingInMap = true;
else
selectingInMap = false;
coords = SCANcontroller.controller.LandingTargetCoords;
return;
}
else if (selectingTarget)
{
selectingTarget = false;
if (selectingInMap)
{
selectingInMap = false;
coords = SCANcontroller.controller.LandingTargetCoords;
way = new SCANwaypoint(coords.y, coords.x, siteName);
target.SetPositionTarget(SCANcontroller.controller.LandingTargetBody, way.Latitude, way.Longitude);
}
}

selectingInMap = false;
selectingTarget = false;

if (target.Target == null)
{
way = null;
return;
}

if (target.targetBody != v.mainBody)
{
way = null;
if (target.targetBody != body)
return;
}

if ((target.Target is DirectionTarget))
{
way = null;
return;
}

coords.x = target.targetLongitude;
coords.y = target.targetLatitude;

if (SCANcontroller.controller.LandingTarget != null)
way = SCANcontroller.controller.LandingTarget;

if (way != null)
{
if (!SCANUtil.ApproxEq(coords.x, way.Longitude) || !SCANUtil.ApproxEq(coords.y, way.Latitude))
Expand All @@ -198,34 +129,94 @@ protected override void LateUpdate()
}
}

protected override void OnGUIEvery()
private void OnTargetSet(Vector2d pos, CelestialBody b)
{
if (SCANcontroller.controller == null)
if (!mjOnboard || target == null)
return;

if (!SCANcontroller.controller.MechJebLoaded)
target.SetPositionTarget(b, pos.y, pos.x);
}

private void SOIChange(GameEvents.HostedFromToAction<Vessel, CelestialBody> action)
{
if (vessel == null)
return;

if (!selectingInMap)
if (vessel != action.host)
return;

drawTarget();
body = action.to;

data = SCANUtil.getData(body);

if (data == null)
shutdown = true;
}

//Draw the mapview MechJeb target arrows
private void drawTarget()
private void VesselChange(Vessel v)
{
if (!selectingInMap)
if (vessel != v)
return;

body = v.mainBody;

if (vessel.FindPartModulesImplementing<MechJebCore>().Count <= 0)
{
SCANcontroller.controller.MechJebLoaded = false;
mjOnboard = false;
mjCore = null;
return;
}

target.pickingPositionTarget = false;
mjCore = vessel.GetMasterMechJeb();

if (!MapView.MapIsEnabled)
if (mjCore == null)
{
SCANcontroller.controller.MechJebLoaded = false;
mjOnboard = false;
target = null;
return;
if (!v.isActiveVessel || v.GetMasterMechJeb() != mjCore)
}

target = mjCore.target;

if (target == null)
{
SCANcontroller.controller.MechJebLoaded = false;
mjOnboard = false;
return;
}

mjOnboard = true;

if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
{
if (guidanceModule == null)
guidanceModule = (DisplayModule)mjCore.GetComputerModule("MechJebModuleLandingGuidance");

if (guidanceModule == null)
{
SCANcontroller.controller.MechJebLoaded = false;
way = null;
mjOnboard = false;
mjTechTreeLocked = true;
return;
}

guidanceModule.UnlockCheck();

if (guidanceModule.hidden)
{
SCANcontroller.controller.MechJebLoaded = false;
way = null;
mjOnboard = false;
mjTechTreeLocked = true;
return;
}
}

GLUtils.DrawGroundMarker(SCANcontroller.controller.LandingTargetBody, coords.y, coords.x, palette.mechjebYellow, true);
SCANcontroller.controller.MechJebLoaded = true;
mjTechTreeLocked = false;
}
}
}
2 changes: 2 additions & 0 deletions SCANmechjeb/SCANmechjebMainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ private void Awake()
loaded = checkLoaded();

print(loaded ? "[SCANsatMechJeb] SCANsat and MechJeb Assemblies Detected" : "[SCANsatMechJeb] SCANsat or MechJeb Assembly Not Detected; Shutting Down...");

Destroy(gameObject);
}

public static bool Loaded
Expand Down
Loading

0 comments on commit a701529

Please sign in to comment.