Skip to content

Commit

Permalink
Merge pull request #2 from ColinZeidler/1-hide-orbits-of-vessels-that…
Browse files Browse the repository at this point in the history
…-arent-the-active

1 hide orbits of vessels that arent the active
  • Loading branch information
ColinZeidler authored Mar 24, 2023
2 parents ca8b2f1 + ebc1bdb commit 33e268c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
8 changes: 6 additions & 2 deletions HideOrbitsProject/HideOrbits.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AssemblyName>com.github.colinzeidler.hide_distant_orbits</AssemblyName>
<Product>Hide Orbits</Product>
<Description>Automatically hide distant orbits while zoomed in</Description>
<Version>0.3.1</Version>
<Version>0.4.0</Version>
<RestoreAdditionalProjectSources>
https://api.nuget.org/v3/index.json;
https://nuget.bepinex.dev/v3/index.json
Expand All @@ -22,14 +22,18 @@
<Publicize>true</Publicize>
<Private>false</Private>
</Reference>
<Reference Include="SpaceWarp">
<HintPath>..\external_dlls\SpaceWarp.dll</HintPath>
<Publicize>true</Publicize>
<Private>false</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all"/>
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.0" PrivateAssets="all"/>
<PackageReference Include="BepInEx.Core" Version="5.*"/>
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.*"/>
<PackageReference Include="HarmonyX" Version="2.10.1"/>
<PackageReference Include="SpaceWarp" Version="0.4.0"/>
<PackageReference Include="UnityEngine.Modules" Version="2020.3.33" IncludeAssets="compile"/>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
Expand Down
49 changes: 42 additions & 7 deletions HideOrbitsProject/HideOrbitsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class HideOrbitsPlugin : BaseSpaceWarpPlugin
private Rect _windowRect;

public bool AutoHideOrbits { get; private set; }
public bool HideVesselOrbits { get; private set; }
public ManualLogSource logger { get; private set; }

private const string ToolbarFlightButtonID = "BTN-HideOrbitsFlight";
Expand All @@ -44,11 +45,7 @@ public override void OnInitialized()
"Hide Orbits",
ToolbarFlightButtonID,
AssetManager.GetAsset<Texture2D>($"{SpaceWarpMetadata.ModID}/images/icon.png"),
isOpen =>
{
_isWindowOpen = isOpen;
GameObject.Find(ToolbarFlightButtonID)?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(isOpen);
}
ToggleGuiButton
);

// Register all Harmony patches in the project
Expand All @@ -61,12 +58,21 @@ public override void OnInitialized()
var configValue = Config.Bind<bool>("Orbits", "Enable Orbit Hiding", defaultValue, "Enables automatic hiding of distant orbits");
AutoHideOrbits = configValue.Value;

var hideVessels = Config.Bind<bool>("Orbits", "Enable Vessel Orbit Hiding", defaultValue, "Hides non active or target vessel orbits by default");
HideVesselOrbits = hideVessels.Value;


// Log the config value into <KSP2 Root>/BepInEx/LogOutput.log
Logger.LogInfo($"OrbitHiding: {configValue.Value}");
logger = Logger;
}

void ToggleGuiButton(bool toggle)
{
_isWindowOpen = toggle;
GameObject.Find(ToolbarFlightButtonID)?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(toggle);
}

/// <summary>
/// Draws a simple UI window when <code>this._isWindowOpen</code> is set to <code>true</code>.
/// </summary>
Expand Down Expand Up @@ -94,18 +100,47 @@ private void OnGUI()
/// <param name="windowID"></param>
private void FillWindow(int windowID)
{
GUILayout.BeginVertical();
var exitRect = new Rect(_windowRect.width - 18, 2, 16, 16);
string exitFont = "<size=8>x</size>";
if (exitRect.Contains(Event.current.mousePosition))
{
exitFont = "<color=red><size=8>x</size></color>";
}

if (GUI.Button(exitRect, exitFont))
{
if (_isWindowOpen)
{
ToggleGuiButton(false);
}
}
GUILayout.EndVertical();


GUILayout.BeginHorizontal();
GUILayout.Label("Hide Orbits - Automatically hide distant orbits while zoomed in");
GUILayout.Label("Hide Orbits - Automatically hide distant planet orbits while zoomed in");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label($"Auto hiding orbits: {AutoHideOrbits}");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Toggle Orbits"))
if (GUILayout.Button("Toggle Planet Orbits"))
{
AutoHideOrbits = !AutoHideOrbits;
}
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label($"Hiding vessel orbits: {HideVesselOrbits}");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Toggle Vessel Orbits"))
{
HideVesselOrbits = !HideVesselOrbits;
}
GUILayout.EndHorizontal();

GUI.DragWindow(new Rect(0, 0, 10000, 500));
}
}
17 changes: 16 additions & 1 deletion HideOrbitsProject/OrbitHiderPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,23 @@ public static void OrbitRenderer_UpdateOrbitStyling(Dictionary<IGGuid, OrbitRend
segment.SetColors(hiddenOrbit, hiddenOrbit);
}
}
else
{
if (!HideOrbitsPlugin.Instance.HideVesselOrbits)
{
continue;
}
if (orbitRenderData.Vessel.GlobalId != activeVessel.GlobalId && orbitRenderData.Vessel.GlobalId != activeVessel.TargetObjectId)
{
foreach (OrbitRenderSegment segment in orbitRenderData.Segments)
{
segment.SetColors(hiddenOrbit, hiddenOrbit);
}
}
}
}
}
} // end Hide orbits

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions hide_orbits/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Hide Orbits",
"description": "Automatically hide distant orbits while zoomed in",
"source": "https://github.com/ColinZeidler/KSP2-HideDistantOrbits",
"version": "0.3.1",
"version": "0.4.0",
"dependencies": [
{
"id": "SpaceWarp",
Expand All @@ -15,7 +15,7 @@
}
],
"ksp2_version": {
"min": "0.1.0",
"min": "0.1.1.0",
"max": "*"
}
}

0 comments on commit 33e268c

Please sign in to comment.