diff --git a/src/Core/Config/ConfigParser.cs b/src/Core/Config/ConfigParser.cs
index c6406bff..2f9c1894 100644
--- a/src/Core/Config/ConfigParser.cs
+++ b/src/Core/Config/ConfigParser.cs
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.IO.Compression;
using System.Linq;
using UnityEngine;
-using System.IO.Compression;
namespace KerbalKonstructs.Core
@@ -328,7 +328,6 @@ internal static void LoadAllMapDecals()
Log.Normal("Rebuilding PQS sphere on: " + body.name);
body.pqsController.RebuildSphere();
}
-
}
///
@@ -337,6 +336,7 @@ internal static void LoadAllMapDecals()
///
internal static void SaveMapDecalInstance(MapDecalInstance instance)
{
+ if (instance.isInSavegame) return;
if (!Directory.Exists(KSPUtil.ApplicationRootPath + "GameData/" + KerbalKonstructs.newInstancePath))
{
@@ -346,7 +346,7 @@ internal static void SaveMapDecalInstance(MapDecalInstance instance)
if (instance.configPath == null)
{
instance.configPath = KerbalKonstructs.newInstancePath + "/KK_MapDecal_" + instance.Name + ".cfg";
- if (System.IO.File.Exists(instance.configPath))
+ if (System.IO.File.Exists(KSPUtil.ApplicationRootPath + "GameData/" + instance.configPath))
{
instance.configPath = KerbalKonstructs.newInstancePath + "/KK_MapDecal_" + instance.Name + "_" + Guid.NewGuid() + ".cfg";
}
@@ -416,34 +416,40 @@ internal static void SaveInstanceByCfg(string pathname)
}
Log.Debug("Saving File: " + pathname);
- StaticInstance[] allInstances = StaticDatabase.allStaticInstances.Where(instance => instance.configPath == pathname).ToArray();
- StaticInstance firstInstance = allInstances.First();
- ConfigNode instanceConfig = null;
+ StaticInstance[] allInstances = StaticDatabase.allStaticInstances.Where(instance => instance.configPath == pathname && !instance.isInSavegame).ToArray();
ConfigNode staticNode = new ConfigNode("STATIC");
- if (firstInstance.configUrl == null) //this are newly spawned instances
+ if (allInstances.Length > 0)
{
- instanceConfig = new ConfigNode("STATIC");
- instanceConfig.AddValue("pointername", firstInstance.model.name);
- }
- else
- {
- //instanceConfig = GameDatabase.Instance.GetConfigNode(firstInstance.configUrl.url);
- //instanceConfig.RemoveNodes("Instances");
- //instanceConfig.RemoveValues();
- instanceConfig = new ConfigNode("STATIC");
- instanceConfig.AddValue("pointername", firstInstance.model.name);
+ StaticInstance firstInstance = allInstances.First();
+ ConfigNode instanceConfig = null;
- }
- staticNode.AddNode(instanceConfig);
- foreach (StaticInstance instance in allInstances)
- {
- ConfigNode inst = new ConfigNode("Instances");
- ConfigParser.WriteInstanceConfig(instance, inst);
- instanceConfig.nodes.Add(inst);
+ if (firstInstance.configUrl == null) //this are newly spawned instances
+ {
+ instanceConfig = new ConfigNode("STATIC");
+ instanceConfig.AddValue("pointername", firstInstance.model.name);
+ }
+ else
+ {
+ //instanceConfig = GameDatabase.Instance.GetConfigNode(firstInstance.configUrl.url);
+ //instanceConfig.RemoveNodes("Instances");
+ //instanceConfig.RemoveValues();
+ instanceConfig = new ConfigNode("STATIC");
+ instanceConfig.AddValue("pointername", firstInstance.model.name);
+
+ }
+
+ staticNode.AddNode(instanceConfig);
+ foreach (StaticInstance instance in allInstances)
+ {
+ ConfigNode inst = new ConfigNode("Instances");
+ ConfigParser.WriteInstanceConfig(instance, inst);
+ instanceConfig.nodes.Add(inst);
+ }
}
+
staticNode.Save(KSPUtil.ApplicationRootPath + "GameData/" + pathname, "Generated by Kerbal Konstructs");
}
@@ -483,6 +489,8 @@ internal static void ExportAllGroups()
foreach (GroupCenter group in StaticDatabase.allGroupCenters)
{
+ if (group.isInSavegame) continue;
+
parsedModels.Clear();
if (!System.IO.Directory.Exists(basePath))
@@ -505,6 +513,8 @@ internal static void ExportAllGroups()
}
foreach (StaticInstance instance in group.childInstances)
{
+ if (instance.isInSavegame) continue;
+
if (parsedModels.Contains(instance.model.name))
{
continue;
@@ -562,9 +572,9 @@ internal static void CreateZips()
string basePath = KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/ExportedInstances/" + exportTime;
string allFileName = "AllExports" + DateTime.Now.ToString("_yyyy-MMdd-HHmm-ss") + ".zip";
-
-
- ZipFile.CreateFromDirectory(basePath, KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/ExportedInstances/"+ allFileName, System.IO.Compression.CompressionLevel.Fastest, false);
+
+
+ ZipFile.CreateFromDirectory(basePath, KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/ExportedInstances/" + allFileName, System.IO.Compression.CompressionLevel.Fastest, false);
foreach (string dirname in Directory.GetDirectories(basePath))
{
@@ -579,7 +589,7 @@ internal static void CreateZips()
ZipFile.CreateFromDirectory(dirname, groupFilename, System.IO.Compression.CompressionLevel.Fastest, true);
Directory.Delete(dirname, true);
}
- }
+ }
}
}
diff --git a/src/Core/LaunchSites/LaunchSiteManager.cs b/src/Core/LaunchSites/LaunchSiteManager.cs
index 1f34e782..526e96bb 100644
--- a/src/Core/LaunchSites/LaunchSiteManager.cs
+++ b/src/Core/LaunchSites/LaunchSiteManager.cs
@@ -479,7 +479,7 @@ internal static void RegisterMHLaunchSites(EditorFacility facility)
/// Removes the launchSite from the facilities
///
///
- internal static void UnregisterLaunchSite(KKLaunchSite site)
+ public static void UnregisterLaunchSite(KKLaunchSite site)
{
if (site.isOpen)
{
@@ -510,7 +510,7 @@ internal static void UnregisterLaunchSite(KKLaunchSite site)
/// Deletes a LaunchSite from the internal Database
///
///
- internal static void DeleteLaunchSite(KKLaunchSite site2delete)
+ public static void DeleteLaunchSite(KKLaunchSite site2delete)
{
if (launchSites.Contains(site2delete))
{
diff --git a/src/Core/MapDecals/DecalsDatabase.cs b/src/Core/MapDecals/DecalsDatabase.cs
index 327909e1..1be4d159 100644
--- a/src/Core/MapDecals/DecalsDatabase.cs
+++ b/src/Core/MapDecals/DecalsDatabase.cs
@@ -41,6 +41,11 @@ internal static void DeleteMapDecalInstance(MapDecalInstance instance)
_allMapDecalInstances.Remove(instance);
allMapDecalInstances = _allMapDecalInstances.ToArray();
Log.Debug("MapDecal instace " + instance.Name + " removed from Database");
+
+ if (instance.configPath != null && System.IO.File.Exists(KSPUtil.ApplicationRootPath + "GameData/" + instance.configPath))
+ {
+ System.IO.File.Delete(KSPUtil.ApplicationRootPath + "GameData/" + instance.configPath);
+ }
}
}
diff --git a/src/Core/MapDecals/MapDecalInstance.cs b/src/Core/MapDecals/MapDecalInstance.cs
index 91f78c85..aa582110 100644
--- a/src/Core/MapDecals/MapDecalInstance.cs
+++ b/src/Core/MapDecals/MapDecalInstance.cs
@@ -56,6 +56,8 @@ public class MapDecalInstance
[CFGSetting]
public string Group = "Ungrouped";
+ public bool isInSavegame = false;
+
internal MapDecalsMap heighMap = null;
internal MapDecalsMap colormapMap = null;
diff --git a/src/Core/StaticGroup/GroupCenter.cs b/src/Core/StaticGroup/GroupCenter.cs
index 4c0dab91..36805a59 100644
--- a/src/Core/StaticGroup/GroupCenter.cs
+++ b/src/Core/StaticGroup/GroupCenter.cs
@@ -34,32 +34,32 @@ public class GroupCenter
[CFGSetting]
public bool SeaLevelAsReference = false;
[CFGSetting]
- internal double RefLatitude = 361d;
+ public double RefLatitude = 361d;
[CFGSetting]
- internal double RefLongitude = 361d;
+ public double RefLongitude = 361d;
public UrlDir.UrlConfig configUrl;
public String configPath = null;
- internal GameObject gameObject;
+ public GameObject gameObject;
internal PQSCity pqsCity;
private Vector3 origScale = new Vector3(1, 1, 1);
- internal List childInstances = new List();
- internal bool isActive = true;
+ public List childInstances = new List();
+ public bool isActive = true;
- internal List launchsites = new List();
+ public List launchsites = new List();
- internal bool hidden = false;
- internal bool isBuiltIn = false;
- internal bool isInSavegame = false;
+ public bool hidden = false;
+ public bool isBuiltIn = false;
+ public bool isInSavegame = false;
- internal bool isHidden
+ public bool isHidden
{
get
{
@@ -197,7 +197,7 @@ internal void UpdateRotation2Heading()
}
- internal void RenameGroup(string newName)
+ public void RenameGroup(string newName)
{
StaticDatabase.RemoveGroupCenter(this);
Group = newName;
@@ -212,7 +212,7 @@ internal void RenameGroup(string newName)
}
- internal void AddInstance(StaticInstance instance)
+ public void AddInstance(StaticInstance instance)
{
if (!childInstances.Contains(instance))
{
@@ -222,7 +222,7 @@ internal void AddInstance(StaticInstance instance)
}
- internal void RemoveInstance(StaticInstance instance)
+ public void RemoveInstance(StaticInstance instance)
{
if (childInstances.Contains(instance))
{
@@ -232,7 +232,7 @@ internal void RemoveInstance(StaticInstance instance)
- internal void SetInstancesEnabled(bool isInRange)
+ public void SetInstancesEnabled(bool isInRange)
{
if (isInRange == isActive)
{
@@ -262,7 +262,7 @@ internal void SetInstancesEnabled(bool isInRange)
///
///
///
- internal void CheckIfInRange(float distance, float maxDistance)
+ public void CheckIfInRange(float distance, float maxDistance)
{
if (distance < 5000 && isHidden)
@@ -277,7 +277,7 @@ internal void CheckIfInRange(float distance, float maxDistance)
SetInstancesEnabled(isInRange);
}
- internal static void ActivateInstance(StaticInstance instance)
+ public static void ActivateInstance(StaticInstance instance)
{
switch (instance.FacilityType)
{
@@ -296,7 +296,7 @@ internal static void ActivateInstance(StaticInstance instance)
}
}
- internal static void DeActivateInstance(StaticInstance instance)
+ public static void DeActivateInstance(StaticInstance instance)
{
switch (instance.FacilityType)
{
@@ -316,7 +316,7 @@ internal static void DeActivateInstance(StaticInstance instance)
}
- internal void Update()
+ public void Update()
{
if (pqsCity != null)
{
@@ -444,13 +444,15 @@ internal void CopyGroup(GroupCenter sourceGroup)
}
- internal void DeleteGroupCenter()
+ public void DeleteGroupCenter()
{
foreach (StaticInstance child in childInstances.ToArray())
{
KerbalKonstructs.instance.DeleteInstance(child);
}
+ if (StaticsEditorGUI.GetActiveGroup() == this) StaticsEditorGUI.SetActiveGroup(null);
+
StaticDatabase.RemoveGroupCenter(this);
// check later when saving if this file is empty
@@ -469,7 +471,7 @@ internal void SetReference()
pqsCity.repositionToSphereSurfaceAddHeight = !SeaLevelAsReference;
}
- internal double surfaceHeight
+ public double surfaceHeight
{
get
{
@@ -477,7 +479,7 @@ internal double surfaceHeight
}
}
- internal string dbKey
+ public string dbKey
{
get
{
@@ -488,7 +490,7 @@ internal string dbKey
}
}
- internal float heading
+ public float heading
{
get
{
diff --git a/src/Core/StaticObjects/StaticInstance.cs b/src/Core/StaticObjects/StaticInstance.cs
index 677660b3..0d11b503 100644
--- a/src/Core/StaticObjects/StaticInstance.cs
+++ b/src/Core/StaticObjects/StaticInstance.cs
@@ -1,4 +1,5 @@
using KerbalKonstructs.Modules;
+using KerbalKonstructs.UI;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -121,7 +122,7 @@ internal GameObject mesh
internal GroupCenter groupCenter = null;
- internal bool isInSavegame = false;
+ public bool isInSavegame = false;
internal bool isDestroyed = false;
@@ -634,6 +635,8 @@ internal void Deactivate()
internal void Destroy()
{
+ if (StaticsEditorGUI.selectedObject == this) StaticsEditorGUI.selectedObject = null;
+
if (groupCenter != null)
{
groupCenter.RemoveInstance(this);
diff --git a/src/Editor/GroupEditor/GroupEditor.cs b/src/Editor/GroupEditor/GroupEditor.cs
index 483f9285..31786ea7 100644
--- a/src/Editor/GroupEditor/GroupEditor.cs
+++ b/src/Editor/GroupEditor/GroupEditor.cs
@@ -7,6 +7,11 @@ namespace KerbalKonstructs.UI
{
public class GroupEditor : KKWindow
{
+ public enum GroupEditorMode
+ {
+ Group,
+ StaticOffset
+ }
protected static GroupEditor _instance = null;
public static GroupEditor instance
@@ -54,8 +59,10 @@ public static GroupEditor instance
#region GUI Windows
// GUI Windows
- public Rect toolRect = new Rect(300, 35, 330, 350);
-
+ public Rect toolRect = new Rect(300, 35, 330, 380);
+ public static Vector2 groupEditorSize = new Vector2(330, 380);
+ public static Vector2 staticOffsetEditorSize = new Vector2(330, 445);
+ public static int NamechangeSize = 80;
#endregion
@@ -64,6 +71,7 @@ public static GroupEditor instance
public static GroupCenter selectedGroup = null;
public GroupCenter selectedObjectPrevious = null;
+ public static GroupEditorMode editorMode = GroupEditorMode.Group;
public string refLat, refLng, headingStr;
@@ -88,7 +96,7 @@ public static GroupEditor instance
protected static Vector3 startPosition = Vector3.zero;
- public static float maxEditorRange = 250;
+ public static float maxEditorRange = 0;
#endregion
@@ -120,6 +128,8 @@ public override void Close()
EditorGizmo.CloseGizmo();
CloseEditors();
selectedObjectPrevious = null;
+ editorMode = GroupEditorMode.Group;
+ toolRect.size = groupEditorSize;
base.Close();
}
@@ -201,15 +211,17 @@ protected virtual void GroupEditorWindow(int windowID)
{
showNameField = true;
newGroupName = selectedGroup.Group;
+ if (editorMode == GroupEditorMode.Group) toolRect.size = groupEditorSize;
+ else if (editorMode == GroupEditorMode.StaticOffset) toolRect.size = staticOffsetEditorSize;
+ toolRect.height += NamechangeSize;
}
GUILayout.EndHorizontal();
if (showNameField)
{
-
GUILayout.Label("Enter new Name: ");
- newGroupName = GUILayout.TextField(newGroupName, 15, GUILayout.Width(150));
+ newGroupName = GUILayout.TextField(newGroupName, GUILayout.Width(150));
GUILayout.BeginHorizontal();
{
@@ -217,10 +229,14 @@ protected virtual void GroupEditorWindow(int windowID)
{
selectedGroup.RenameGroup(newGroupName);
showNameField = false;
+ if (editorMode == GroupEditorMode.Group) toolRect.size = groupEditorSize;
+ else if (editorMode == GroupEditorMode.StaticOffset) toolRect.size = staticOffsetEditorSize;
}
if (GUILayout.Button("Cancel", GUILayout.Height(23)))
{
showNameField = false;
+ if (editorMode == GroupEditorMode.Group) toolRect.size = groupEditorSize;
+ else if (editorMode == GroupEditorMode.StaticOffset) toolRect.size = staticOffsetEditorSize;
}
}
GUILayout.EndHorizontal();
@@ -285,6 +301,32 @@ protected virtual void GroupEditorWindow(int windowID)
}
GUILayout.EndHorizontal();
+ GUILayout.BeginHorizontal();
+ {
+ GUILayout.Label("Editor Mode: ");
+ GUILayout.FlexibleSpace();
+
+ GUI.enabled = editorMode != GroupEditorMode.Group;
+ if (GUILayout.Button("Group", GUILayout.Height(23)))
+ {
+ editorMode = GroupEditorMode.Group;
+
+ toolRect.size = groupEditorSize;
+ if (showNameField) toolRect.height += NamechangeSize;
+ }
+ GUI.enabled = editorMode != GroupEditorMode.StaticOffset;
+ if (GUILayout.Button("Static offset", GUILayout.Height(23)))
+ {
+ editorMode = GroupEditorMode.StaticOffset;
+
+ toolRect.size = staticOffsetEditorSize;
+ if (showNameField) toolRect.height += NamechangeSize;
+ }
+ GUI.enabled = true;
+ }
+ GUILayout.EndHorizontal();
+ if (editorMode == GroupEditorMode.StaticOffset) GUILayout.Label("Static offset mode: changes the offset of the group statics but does NOT change the group position.");
+
//
// Set reference butons
//
@@ -324,27 +366,22 @@ protected virtual void GroupEditorWindow(int windowID)
if (foldedIn)
fTempWidth = 40f;
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.back * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.forward * increment);
- }
+
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Left / Right:");
GUILayout.FlexibleSpace();
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.left * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.right * increment);
- }
+
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
@@ -358,27 +395,22 @@ protected virtual void GroupEditorWindow(int windowID)
if (foldedIn)
fTempWidth = 40f;
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
Setlatlng(0d, -increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
Setlatlng(0d, increment);
- }
+
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("South / North:");
GUILayout.FlexibleSpace();
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
Setlatlng(-increment, 0d);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
Setlatlng(increment, 0d);
- }
+
}
GUILayout.EndHorizontal();
@@ -405,15 +437,60 @@ protected virtual void GroupEditorWindow(int windowID)
GUILayout.Label("Alt.");
GUILayout.FlexibleSpace();
selectedGroup.RadiusOffset = float.Parse(GUILayout.TextField(selectedGroup.RadiusOffset.ToString(), 25, GUILayout.Width(fTempWidth)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
{
- selectedGroup.RadiusOffset -= increment;
+ if (editorMode == GroupEditorMode.Group)
+ {
+ selectedGroup.RadiusOffset -= increment;
+ ApplySettings();
+ if (!CheckRange(selectedGroup.gameObject.transform.position))
+ {
+ Log.Debug("Position out of range, reverting changes.");
+ selectedGroup.RadiusOffset += increment;
+ ApplySettings();
+ }
+ }
+ else if (editorMode == GroupEditorMode.StaticOffset)
+ {
+ selectedGroup.childInstances.ForEach(instance =>
+ {
+ instance.RelativePosition.y -= increment;
+
+ instance.RadiusOffset -= increment;
+
+ instance.gameObject.transform.localPosition -= Vector3.up * increment;
+ });
+ }
+
ApplySettings();
+
}
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
{
- selectedGroup.RadiusOffset += increment;
- ApplySettings();
+ if (editorMode == GroupEditorMode.Group)
+ {
+ selectedGroup.RadiusOffset += increment;
+ ApplySettings();
+ if (!CheckRange(selectedGroup.gameObject.transform.position))
+ {
+ Log.Debug("Position out of range, reverting changes.");
+ selectedGroup.RadiusOffset -= increment;
+ ApplySettings();
+ }
+ }
+ else if (editorMode == GroupEditorMode.StaticOffset)
+ {
+ selectedGroup.childInstances.ForEach(instance =>
+ {
+ instance.RelativePosition.y += increment;
+
+ instance.RadiusOffset += increment;
+
+ instance.gameObject.transform.localPosition += Vector3.up * increment;
+ });
+ ApplySettings();
+ }
+
}
}
GUILayout.EndHorizontal();
@@ -434,22 +511,11 @@ protected virtual void GroupEditorWindow(int windowID)
GUILayout.FlexibleSpace();
headingStr = GUILayout.TextField(headingStr, 9, GUILayout.Width(fTempWidth));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
SetRotation(-increment);
- }
- if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
- {
- SetRotation(-increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)))
- {
- SetRotation(increment);
- }
- if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
SetRotation(increment);
- }
+
}
GUILayout.EndHorizontal();
@@ -532,6 +598,7 @@ public static void CloseEditors()
#region Utility Functions
+ public bool CheckRange(Vector3 targetPos) => maxEditorRange == 0 || FlightGlobals.ActiveVessel == null || Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, targetPos) <= maxEditorRange;
public void DeleteGroupCenter()
{
@@ -748,12 +815,47 @@ public void Setlatlng(double north, double east)
{
body = Planetarium.fetch.CurrentMainBody;
double latOffset = north / (body.Radius * KKMath.deg2rad);
- selectedGroup.RefLatitude += latOffset;
double lonOffset = east / (body.Radius * KKMath.deg2rad);
- selectedGroup.RefLongitude += lonOffset * Math.Cos(Mathf.Deg2Rad * selectedGroup.RefLatitude);
- selectedGroup.RadialPosition = body.GetRelSurfaceNVector(selectedGroup.RefLatitude, selectedGroup.RefLongitude).normalized * body.Radius;
- ApplySettings();
+ if (editorMode == GroupEditorMode.Group)
+ {
+ double oldLat = selectedGroup.RefLatitude;
+ double oldLon = selectedGroup.RefLongitude;
+ Vector3 oldRad = selectedGroup.RadialPosition;
+
+ selectedGroup.RefLatitude += latOffset;
+
+ selectedGroup.RefLongitude += lonOffset * Math.Cos(Mathf.Deg2Rad * selectedGroup.RefLatitude);
+
+ selectedGroup.RadialPosition = body.GetRelSurfaceNVector(selectedGroup.RefLatitude, selectedGroup.RefLongitude).normalized * body.Radius;
+
+ ApplySettings();
+
+ if (!CheckRange(selectedGroup.gameObject.transform.position))
+ {
+ Log.Debug("Position out of range, reverting changes.");
+ selectedGroup.RefLatitude = oldLat;
+ selectedGroup.RefLongitude = oldLon;
+ selectedGroup.RadialPosition = oldRad;
+ ApplySettings();
+ }
+ }
+ else if (editorMode == GroupEditorMode.StaticOffset)
+ {
+ selectedGroup.childInstances.ForEach(instance =>
+ {
+ instance.RefLatitude += latOffset;
+ instance.RefLongitude += lonOffset * Math.Cos(Mathf.Deg2Rad * instance.RefLatitude);
+
+ instance.gameObject.transform.position = instance.CelestialBody.GetWorldSurfacePosition(instance.RefLatitude, instance.RefLongitude, instance.RadiusOffset);
+
+ instance.RelativePosition = instance.gameObject.transform.localPosition;
+ instance.RadiusOffset = (float)((instance.surfaceHeight - instance.groupCenter.surfaceHeight) + instance.RelativePosition.y);
+
+ ApplySettings();
+ });
+ }
+
}
@@ -766,7 +868,7 @@ public void Setlatlng(double north, double east)
///
public void SetRotation(float increment)
{
- selectedGroup.RotationAngle += (float)increment;
+ selectedGroup.RotationAngle += increment;
selectedGroup.RotationAngle = (360f + selectedGroup.RotationAngle) % 360f;
ApplySettings();
}
@@ -778,31 +880,61 @@ public void SetRotation(float increment)
///
public void SetTransform(Vector3 direction)
{
- // adjust transform for scaled models
- direction = direction / selectedGroup.ModelScale;
- direction = selectedGroup.gameObject.transform.TransformVector(direction);
- double northInc = Vector3d.Dot(northVector, direction);
- double eastInc = Vector3d.Dot(eastVector, direction);
-
- Setlatlng(northInc, eastInc);
+ if (editorMode == GroupEditorMode.Group)
+ {
+ direction = selectedGroup.gameObject.transform.TransformVector(direction);
+ double northInc = Vector3d.Dot(northVector, direction);
+ double eastInc = Vector3d.Dot(eastVector, direction);
+ Setlatlng(northInc, eastInc);
+ }
+ else if (editorMode == GroupEditorMode.StaticOffset)
+ {
+ selectedGroup.childInstances.ForEach(instance =>
+ {
+ instance.transform.localPosition += direction;
+ instance.Update();
+ });
+ }
}
-
public void OnMoveCallBack(Vector3 vector)
{
// Log.Normal("OnMove: " + vector.ToString());
//moveGizmo.transform.position += 3* vector;
- selectedGroup.gameObject.transform.position = EditorGizmo.moveGizmo.transform.position;
- selectedGroup.RadialPosition = selectedGroup.gameObject.transform.localPosition;
+ if (editorMode == GroupEditorMode.Group)
+ {
+ if (!CheckRange(EditorGizmo.moveGizmo.transform.position))
+ {
+ Log.Debug("Position out of range, reverting changes.");
+ return;
+ }
+
+ selectedGroup.gameObject.transform.position = EditorGizmo.moveGizmo.transform.position;
+ selectedGroup.RadialPosition = selectedGroup.gameObject.transform.localPosition;
- double alt;
- selectedGroup.CelestialBody.GetLatLonAlt(EditorGizmo.moveGizmo.transform.position, out selectedGroup.RefLatitude, out selectedGroup.RefLongitude, out alt);
+ double alt;
+ selectedGroup.CelestialBody.GetLatLonAlt(EditorGizmo.moveGizmo.transform.position, out selectedGroup.RefLatitude, out selectedGroup.RefLongitude, out alt);
- selectedGroup.RadiusOffset = (float)(alt - selectedGroup.surfaceHeight);
- //float oldY = selectedInstance.gameObject.transform.localPosition.y;
+ selectedGroup.RadiusOffset = (float)(alt - selectedGroup.surfaceHeight);
+ }
+ else if (editorMode == GroupEditorMode.StaticOffset)
+ {
+ // continues movement, longitude and height are swapped
+
+ vector /= 8;
+ selectedGroup.childInstances.ForEach(instance =>
+ {
+ instance.gameObject.transform.position += vector;
+
+ instance.RelativePosition = instance.gameObject.transform.localPosition;
+ instance.RadiusOffset = -(float)((instance.surfaceHeight - instance.groupCenter.surfaceHeight) + instance.RelativePosition.y);
+ });
+
+ EditorGizmo.moveGizmo.transform.position += vector;
+ }
}
public void WhenMovedCallBack(Vector3 vector)
diff --git a/src/Editor/InstanceEditor/EditorGUI.cs b/src/Editor/InstanceEditor/EditorGUI.cs
index 0e231f5d..aad0acae 100644
--- a/src/Editor/InstanceEditor/EditorGUI.cs
+++ b/src/Editor/InstanceEditor/EditorGUI.cs
@@ -373,42 +373,33 @@ public virtual void InstanceEditorWindow(int windowID)
GUILayout.FlexibleSpace();
posZStr = (GUILayout.TextField(posZStr, 11, GUILayout.Width(fTempWidth)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.back * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.forward * increment);
- }
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Left / Right:");
GUILayout.FlexibleSpace();
posXStr = (GUILayout.TextField(posXStr, 11, GUILayout.Width(fTempWidth)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.left * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.right * increment);
- }
+
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Down / Up:");
GUILayout.FlexibleSpace();
posYStr = (GUILayout.TextField(posYStr, 11, GUILayout.Width(fTempWidth)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.down * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.up * increment);
- }
@@ -502,14 +493,12 @@ public virtual void InstanceEditorWindow(int windowID)
fTempWidth = 80f;
oriXStr = (GUILayout.TextField(oriXStr, 8, GUILayout.Width(fTempWidth)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetRotation(Vector3.right, increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetRotation(Vector3.left, increment);
- }
+
}
GUILayout.EndHorizontal();
@@ -519,14 +508,11 @@ public virtual void InstanceEditorWindow(int windowID)
GUILayout.Label("Roll:");
GUILayout.FlexibleSpace();
oriZStr = (GUILayout.TextField(oriZStr, 8, GUILayout.Width(fTempWidth)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetRotation(Vector3.forward, increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetRotation(Vector3.back, increment);
- }
}
GUILayout.EndHorizontal();
@@ -544,22 +530,10 @@ public virtual void InstanceEditorWindow(int windowID)
//GUILayout.Box(GetHeading(), GUILayout.Width(fTempWidth));
oriYStr = (GUILayout.TextField(oriYStr, 8, GUILayout.Width(fTempWidth)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
SetRotation(Vector3.up, -increment);
- }
- if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
- {
- SetRotation(Vector3.up, -increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)))
- {
- SetRotation(Vector3.up, increment);
- }
- if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
SetRotation(Vector3.up, increment);
- }
}
GUILayout.EndHorizontal();
@@ -585,22 +559,12 @@ public virtual void InstanceEditorWindow(int windowID)
GUILayout.FlexibleSpace();
selectedInstance.ModelScale = Math.Max(0.01f, float.Parse(GUILayout.TextField(selectedInstance.ModelScale.ToString(), 4, GUILayout.Width(fTempWidth))));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)))
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
{
selectedInstance.ModelScale = Math.Max(0.01f, selectedInstance.ModelScale - increment);
ApplySettings();
}
- if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
- {
- selectedInstance.ModelScale = Math.Max(0.01f, selectedInstance.ModelScale - increment);
- ApplySettings();
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)))
- {
- selectedInstance.ModelScale += increment;
- ApplySettings();
- }
- if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
{
selectedInstance.ModelScale += increment;
ApplySettings();
diff --git a/src/Editor/MapDecalEditor.cs b/src/Editor/MapDecalEditor.cs
index 1560e809..dd656f49 100644
--- a/src/Editor/MapDecalEditor.cs
+++ b/src/Editor/MapDecalEditor.cs
@@ -1,5 +1,4 @@
using KerbalKonstructs.Core;
-using KerbalKonstructs.Utilities;
using System;
using System.Collections.Generic;
using UnityEngine;
@@ -286,7 +285,7 @@ void MapDecalEditorWindow(int windowID)
{
//GUILayout.FlexibleSpace();
GUILayout.Label("Increment: ");
- GUILayout.TextField(increment.ToString(), GUILayout.Width(48));
+ if (float.TryParse(GUILayout.TextField(increment.ToString(), GUILayout.Width(48)), out float inc)) increment = inc;
GUILayout.FlexibleSpace();
}
GUILayout.EndHorizontal();
@@ -358,40 +357,32 @@ void MapDecalEditorWindow(int windowID)
GUILayout.FlexibleSpace();
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.back * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.forward * increment);
- }
+
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Left / Right:");
GUILayout.FlexibleSpace();
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.left * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.right * increment);
- }
+
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Down / Up:");
GUILayout.FlexibleSpace();
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.down * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.up * increment);
- }
}
else
@@ -400,27 +391,21 @@ void MapDecalEditorWindow(int windowID)
GUILayout.FlexibleSpace();
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
Setlatlng(0d, -increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
Setlatlng(0d, increment);
- }
+
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("South / North:");
GUILayout.FlexibleSpace();
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
Setlatlng(-increment, 0d);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
Setlatlng(increment, 0d);
- }
}
}
@@ -431,9 +416,34 @@ void MapDecalEditorWindow(int windowID)
GUILayout.BeginHorizontal();
{
GUILayout.Label("Latitude");
- GUILayout.TextField(latitude.ToString("#0.0000000"));
+ if (double.TryParse(GUILayout.TextField(latitude.ToString("#0.0000000"), 12, GUILayout.Width(100)), out double lat) && lat != Math.Round(latitude, 7))
+ {
+ Debug.Log($"KK Mapdecal editor latitude: {latitude.ToString("#0.0000000")}, lat: {lat}, rounded: {Math.Round(latitude, 7)}, floor: {Math.Floor(latitude * 10000000) / 10000000}");
+
+ latitude = Math.Round(lat, 7);
+
+ Vector3d newpos = body.GetWorldSurfacePosition(latitude, longitude, altitude);
+ selectedDecal.mapDecal.transform.position = newpos;
+
+ referenceVector = body.GetRelSurfaceNVector(latitude, longitude).normalized * body.Radius;
+
+ UpdateMoveGizmo();
+ }
+
GUILayout.Label("Longitude");
- GUILayout.TextField(longitude.ToString("#0.0000000"));
+ if (double.TryParse(GUILayout.TextField(longitude.ToString("#0.0000000"), 12, GUILayout.Width(100)), out double lon) && lon != Math.Round(longitude, 7))
+ {
+ Debug.Log($"KK Mapdecal editor longitude: {longitude.ToString("#0.0000000")}, lon: {lon}, rounded: {Math.Round(longitude, 7)}, floor: {Math.Floor(longitude * 10000000) / 10000000}");
+
+ longitude = Math.Round(lon, 7);
+
+ Vector3d newpos = body.GetWorldSurfacePosition(latitude, longitude, altitude);
+ selectedDecal.mapDecal.transform.position = newpos;
+
+ referenceVector = body.GetRelSurfaceNVector(latitude, longitude).normalized * body.Radius;
+
+ UpdateMoveGizmo();
+ }
}
GUILayout.EndHorizontal();
GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
@@ -445,24 +455,13 @@ void MapDecalEditorWindow(int windowID)
{
GUILayout.Label("Heading:");
GUILayout.FlexibleSpace();
- GUILayout.TextField(selectedDecal.Angle.ToString(), 9, GUILayout.Width(80));
+ if (float.TryParse(GUILayout.TextField(selectedDecal.Angle.ToString(), 9, GUILayout.Width(80)), out float angle) && angle != selectedDecal.Angle) SetRotation(angle);
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
SetRotation(-increment);
- }
- if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
- {
- SetRotation(-increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)))
- {
- SetRotation(increment);
- }
- if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
SetRotation(increment);
- }
+
}
GUILayout.EndHorizontal();
GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
@@ -474,24 +473,13 @@ void MapDecalEditorWindow(int windowID)
{
GUILayout.Label("Placement order:");
GUILayout.FlexibleSpace();
- GUILayout.TextField(selectedDecal.Order.ToString(), 9, GUILayout.Width(80));
+ if (int.TryParse(GUILayout.TextField(selectedDecal.Order.ToString(), 9, GUILayout.Width(80)), out int order)) selectedDecal.Order = Math.Max(100000, order);
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)))
- {
- selectedDecal.Order = Math.Max(100000, selectedDecal.Order - 1);
- }
- if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
selectedDecal.Order = Math.Max(100000, selectedDecal.Order - 1);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
selectedDecal.Order += 1;
- }
- if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
- {
- selectedDecal.Order += 1;
- }
+
}
GUILayout.EndHorizontal();
GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
@@ -503,26 +491,17 @@ void MapDecalEditorWindow(int windowID)
{
GUILayout.Label("Radius:");
GUILayout.FlexibleSpace();
- GUILayout.TextField(selectedDecal.Radius.ToString(), 9, GUILayout.Width(80));
+ //selectedDecal.Radius = double.Parse(GUILayout.TextField(selectedDecal.Radius.ToString(), 9, GUILayout.Width(80)));
+ if (double.TryParse(GUILayout.TextField(selectedDecal.Radius.ToString(), 9, GUILayout.Width(80)), out double radius)) selectedDecal.Radius = radius;
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)))
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
{
selectedDecal.Radius -= increment;
selectedDecal.Radius = Math.Max(1, selectedDecal.Radius);
}
- if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
- {
- selectedDecal.Radius -= increment;
- selectedDecal.Radius = Math.Max(1, selectedDecal.Radius);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)))
- {
- selectedDecal.Radius += increment;
- }
- if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
selectedDecal.Radius += increment;
- }
+
}
GUILayout.EndHorizontal();
@@ -549,15 +528,14 @@ void MapDecalEditorWindow(int windowID)
{
GUILayout.Label("Absolut offset:");
GUILayout.FlexibleSpace();
- selectedDecal.AbsolutOffset = float.Parse(GUILayout.TextField(selectedDecal.AbsolutOffset.ToString(), 25, GUILayout.Width(75)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+
+ if (float.TryParse(GUILayout.TextField(selectedDecal.AbsolutOffset.ToString(), 25, GUILayout.Width(75)), out float absOffset)) selectedDecal.AbsolutOffset = absOffset;
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.down * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.up * increment);
- }
+
}
GUILayout.EndHorizontal();
GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
@@ -567,7 +545,7 @@ void MapDecalEditorWindow(int windowID)
{
selectHeightMap = true;
}
- GUILayout.TextField(selectedDecal.HeightMapName, GUILayout.Width(200));
+ GUILayout.Label(selectedDecal.HeightMapName, GUILayout.Width(200));
GUILayout.EndHorizontal();
@@ -591,16 +569,13 @@ void MapDecalEditorWindow(int windowID)
{
GUILayout.Label("HeightMapDeformity:");
GUILayout.FlexibleSpace();
- selectedDecal.HeightMapDeformity = double.Parse(GUILayout.TextField(selectedDecal.HeightMapDeformity.ToString(), 25, GUILayout.Width(75)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (double.TryParse(GUILayout.TextField(selectedDecal.HeightMapDeformity.ToString(), 25, GUILayout.Width(75)), out double deform)) selectedDecal.HeightMapDeformity = deform;
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
selectedDecal.HeightMapDeformity -= increment;
- //selectedDecal.HeightMapDeformity = Math.Max(0, selectedDecal.HeightMapDeformity);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
selectedDecal.HeightMapDeformity += increment;
- }
+
}
GUILayout.EndHorizontal();
@@ -609,16 +584,16 @@ void MapDecalEditorWindow(int windowID)
{
GUILayout.Label("SmoothHeight:");
GUILayout.FlexibleSpace();
- selectedDecal.SmoothHeight = float.Parse(GUILayout.TextField(selectedDecal.SmoothHeight.ToString(), 25, GUILayout.Width(75)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
+ if (float.TryParse(GUILayout.TextField(selectedDecal.SmoothHeight.ToString(), 25, GUILayout.Width(75)), out float height)) selectedDecal.SmoothHeight = height;
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
{
selectedDecal.SmoothHeight -= increment;
selectedDecal.SmoothHeight = Math.Max(0, selectedDecal.SmoothHeight);
}
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
selectedDecal.SmoothHeight += increment;
- }
+
}
GUILayout.EndHorizontal();
GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
@@ -628,7 +603,7 @@ void MapDecalEditorWindow(int windowID)
{
selectColorMap = true;
}
- GUILayout.TextField(selectedDecal.ColorMapName, GUILayout.Width(200));
+ GUILayout.Label(selectedDecal.ColorMapName, GUILayout.Width(200));
GUILayout.EndHorizontal();
@@ -652,16 +627,16 @@ void MapDecalEditorWindow(int windowID)
{
GUILayout.Label("SmoothColor:");
GUILayout.FlexibleSpace();
- selectedDecal.SmoothColor = float.Parse(GUILayout.TextField(selectedDecal.SmoothColor.ToString(), 25, GUILayout.Width(75)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
+ if (float.TryParse(GUILayout.TextField(selectedDecal.SmoothColor.ToString(), 25, GUILayout.Width(75)), out float color)) selectedDecal.SmoothColor = color;
+
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
{
selectedDecal.SmoothColor -= increment;
selectedDecal.SmoothColor = Math.Max(0, selectedDecal.SmoothColor);
}
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
selectedDecal.SmoothColor += increment;
- }
+
}
GUILayout.EndHorizontal();
diff --git a/src/Editor/StaticsEditorGUI.cs b/src/Editor/StaticsEditorGUI.cs
index 0f10af8f..d851b826 100644
--- a/src/Editor/StaticsEditorGUI.cs
+++ b/src/Editor/StaticsEditorGUI.cs
@@ -1,5 +1,4 @@
using KerbalKonstructs.Core;
-using KerbalKonstructs.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -780,6 +779,7 @@ internal void ShowGroupScroll()
GroupEditor.instance.Close();
GroupEditor.selectedGroup = groupCenter;
// MapDecalEditor.selectedDecal = mapDecalInstance;
+ GroupEditor.maxEditorRange = 0;
GroupEditor.instance.Open();
}
@@ -820,6 +820,7 @@ internal void ShowGroupFooter()
}
else
{
+ GroupEditor.maxEditorRange = 0;
GroupEditor.instance.Open();
Log.Normal("Group Editor spawned");
}
@@ -864,24 +865,21 @@ internal void ShowGroupFooter()
internal static void ResetLocalGroupList()
{
List foundList = new List();
- foreach (var groupCenter in StaticDatabase.allGroupCenters)
- {
-
- if (groupCenter.CelestialBody != FlightGlobals.currentMainBody)
- {
- continue;
- }
- if (groupCenter.isInSavegame)
+ if (FlightGlobals.ActiveVessel != null)
+ foreach (var groupCenter in StaticDatabase.allGroupCenters)
{
- continue;
- }
- if (Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, groupCenter.gameObject.transform.position) > KerbalKonstructs.localGroupRange)
- {
- continue;
- }
- foundList.Add(groupCenter);
- }
+ if (groupCenter.CelestialBody != FlightGlobals.currentMainBody)
+ {
+ continue;
+ }
+ if (Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, groupCenter.gameObject.transform.position) > KerbalKonstructs.localGroupRange)
+ {
+ continue;
+ }
+
+ foundList.Add(groupCenter);
+ }
localGroups = foundList.ToArray();
}
diff --git a/src/ExternalAPI/API.cs b/src/ExternalAPI/API.cs
index 2a710f4e..bb2d625b 100644
--- a/src/ExternalAPI/API.cs
+++ b/src/ExternalAPI/API.cs
@@ -10,11 +10,11 @@ namespace KerbalKonstructs
public static class API
{
- internal static Action OnBuildingSpawned = delegate { };
- internal static Action OnStaticClicked = delegate { };
- internal static Action OnStaticMouseEnter = delegate { };
- internal static Action OnStaticMouseExit = delegate { };
- internal static Action OnGroupSaved = delegate { };
+ public static Action OnBuildingSpawned = delegate { };
+ public static Action OnStaticClicked = delegate { };
+ public static Action OnStaticMouseEnter = delegate { };
+ public static Action OnStaticMouseExit = delegate { };
+ public static Action OnGroupSaved = delegate { };
public static string SpawnObject(string modelName)
{
@@ -139,7 +139,6 @@ public static string PlaceStatic(string modelName, string bodyName, double lat,
if (model != null)
{
StaticInstance instance = new StaticInstance();
- instance.isInSavegame = true;
instance.heighReference = HeightReference.Terrain;
diff --git a/src/KerbalKonstructs.cs b/src/KerbalKonstructs.cs
index 28322307..98982b69 100644
--- a/src/KerbalKonstructs.cs
+++ b/src/KerbalKonstructs.cs
@@ -1270,6 +1270,8 @@ internal void SaveModelConfig(StaticModel mModelToSave)
foreach (StaticInstance instance in StaticDatabase.GetInstancesFromModel(model))
{
+ if (instance.isInSavegame) continue;
+
ConfigNode inst = new ConfigNode("Instances");
ConfigParser.WriteInstanceConfig(instance, inst);
modelConfig.nodes.Add(inst);
@@ -1343,6 +1345,8 @@ public void SaveObjects()
internal void SaveGroupCenters()
{
+ StaticDatabase.allGroupCenters.Where(g => g.isInSavegame && !string.IsNullOrEmpty(g.configPath)).ToList().ForEach(g => deletedGroups.Add(g));
+
foreach (GroupCenter center in deletedGroups)
{
if (File.Exists(KSPUtil.ApplicationRootPath + "GameData/" + center.configPath))
diff --git a/src/KerbalKonstructs.csproj b/src/KerbalKonstructs.csproj
index e79de0ba..6d8ea83b 100644
--- a/src/KerbalKonstructs.csproj
+++ b/src/KerbalKonstructs.csproj
@@ -208,6 +208,8 @@
+
+
diff --git a/src/Modules/Career/CareerEditor.cs b/src/Modules/Career/CareerEditor.cs
index befa62c2..bdae320f 100644
--- a/src/Modules/Career/CareerEditor.cs
+++ b/src/Modules/Career/CareerEditor.cs
@@ -318,27 +318,19 @@ void InstanceEditorWindow(int windowID)
GUILayout.FlexibleSpace();
;
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.back * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.forward * increment);
- }
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Left / Right:");
GUILayout.FlexibleSpace();
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.left * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.right * increment);
- }
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
@@ -360,14 +352,10 @@ void InstanceEditorWindow(int windowID)
GUILayout.Label("Alt.");
GUILayout.FlexibleSpace();
selectedInstance.RadiusOffset = float.Parse(GUILayout.TextField(selectedInstance.RadiusOffset.ToString(), 25, GUILayout.Width(fTempWidth)));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.down * increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) || GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(21)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(21)))
SetTransform(Vector3.up * increment);
- }
}
GUILayout.EndHorizontal();
@@ -392,22 +380,10 @@ void InstanceEditorWindow(int windowID)
GUILayout.FlexibleSpace();
GUILayout.TextField(heading.ToString(), 9, GUILayout.Width(fTempWidth));
- if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)))
- {
- SetRotation(-increment);
- }
- if (GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.RepeatButton("<<", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.Button("<", GUILayout.Width(30), GUILayout.Height(23)))
SetRotation(-increment);
- }
- if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)))
- {
+ if (GUILayout.Button(">", GUILayout.Width(30), GUILayout.Height(23)) | GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
SetRotation(increment);
- }
- if (GUILayout.RepeatButton(">>", GUILayout.Width(30), GUILayout.Height(23)))
- {
- SetRotation(increment);
- }
}
GUILayout.EndHorizontal();
diff --git a/src/Modules/Career/CareerGroups.cs b/src/Modules/Career/CareerGroups.cs
new file mode 100644
index 00000000..031276c6
--- /dev/null
+++ b/src/Modules/Career/CareerGroups.cs
@@ -0,0 +1,54 @@
+using KerbalKonstructs.Core;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using UnityEngine;
+
+namespace KerbalKonstructs.Modules.Career
+{
+ public class CareerGroups
+ {
+ private static string groupCFGNodeName = "KKGroups";
+
+ public static void SaveGroups(ConfigNode cfgNode)
+ {
+ if (cfgNode.HasNode(groupCFGNodeName)) cfgNode.RemoveNode(groupCFGNodeName);
+
+ ConfigNode buildingNode = cfgNode.AddNode(groupCFGNodeName);
+
+ StaticDatabase.allGroupCenters.Where(g => g.isInSavegame).ToList().ForEach(center =>
+ {
+ Debug.Log($"Saving group {center.Group} in savegame");
+ ConfigNode instanceNode = buildingNode.AddNode("Group");
+
+ center.WriteConfig(instanceNode);
+ });
+ }
+
+ public static void LoadGroups(ConfigNode cfgNode)
+ {
+ RemoveAllGroups();
+
+ if (!cfgNode.HasNode(groupCFGNodeName)) return;
+
+ ConfigNode groupNode = cfgNode.GetNode(groupCFGNodeName);
+
+ foreach (ConfigNode instanceNode in groupNode.GetNodes()) LoadGroup(instanceNode);
+ }
+
+ public static void RemoveAllGroups() => StaticDatabase.allGroupCenters.Where(g => g.isInSavegame).ToList().ForEach(g => g.DeleteGroupCenter());
+
+ public static void LoadGroup(ConfigNode cfgNode)
+ {
+ GroupCenter center = new GroupCenter();
+
+ center.isInSavegame = true;
+
+ center.ParseCFGNode(cfgNode);
+
+ center.Spawn();
+ }
+ }
+}
diff --git a/src/Modules/Career/CareerMapDecals.cs b/src/Modules/Career/CareerMapDecals.cs
new file mode 100644
index 00000000..79b6a363
--- /dev/null
+++ b/src/Modules/Career/CareerMapDecals.cs
@@ -0,0 +1,106 @@
+using KerbalKonstructs.Core;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine;
+
+namespace KerbalKonstructs.Modules.Career
+{
+ public class CareerMapDecals
+ {
+ private static string decalCFGNodeName = "KKMapDecals";
+
+ public static void SaveDecals(ConfigNode cfgNode)
+ {
+ // See ConfigParser.SaveMapDecalInstance
+
+ if (cfgNode.HasNode(decalCFGNodeName)) cfgNode.RemoveNode(decalCFGNodeName);
+
+ ConfigNode decalNode = cfgNode.AddNode(decalCFGNodeName);
+
+ DecalsDatabase.allMapDecalInstances.Where(d => d.isInSavegame).ToList().ForEach(decal =>
+ {
+ Debug.Log($"Saving decal {decal.Name} in savegame");
+
+ ConfigNode instanceNode = decalNode.AddNode("MapDecalInstance");
+ ConfigParser.WriteMapDecalConfig(decal, instanceNode);
+ });
+ }
+
+ public static void LoadDecals(ConfigNode cfgNode)
+ {
+ RemoveAllDecals();
+
+ if (!cfgNode.HasNode(decalCFGNodeName)) return;
+
+ ConfigNode decalNode = cfgNode.GetNode(decalCFGNodeName);
+
+ foreach (ConfigNode instanceNode in decalNode.GetNodes())
+ {
+ LoadDecal(instanceNode);
+ }
+ }
+
+ public static void RemoveAllDecals()
+ {
+ List decals = DecalsDatabase.allMapDecalInstances.Where(d => d.isInSavegame).ToList();
+
+ List changedBodies = new List();
+
+ decals.ForEach(d =>
+ {
+ d.gameObject.transform.parent = null;
+ d.mapDecal.transform.parent = null;
+ d.gameObject.DestroyGameObject();
+ DecalsDatabase.DeleteMapDecalInstance(d);
+
+ if (!changedBodies.Contains(d.CelestialBody)) changedBodies.Add(d.CelestialBody);
+ });
+
+ changedBodies.ForEach(b => b.pqsController.RebuildSphere());
+ }
+
+ public static void LoadDecal(ConfigNode cfgNode)
+ {
+ MapDecalInstance newMapDecalInstance = new MapDecalInstance();
+ newMapDecalInstance.isInSavegame = true;
+
+ ConfigParser.ParseMapDecalConfig(newMapDecalInstance, cfgNode);
+
+ HashSet bodies2Update = new HashSet();
+
+ // remove all instances where no planet was assigned
+ foreach (MapDecalInstance instance in DecalsDatabase.allMapDecalInstances)
+ {
+ if (instance.CelestialBody == null)
+ {
+ Log.Normal("No valid CelestialBody found: removing MapDecal instance " + instance.configPath);
+ DecalsDatabase.DeleteMapDecalInstance(instance);
+ continue;
+ }
+ else
+ {
+ //Log.Normal("Loaded MapDecal instance " + instance.Name);
+ if (!bodies2Update.Contains(instance.CelestialBody))
+ {
+ bodies2Update.Add(instance.CelestialBody);
+ }
+
+
+ instance.mapDecal.transform.position = instance.CelestialBody.GetWorldSurfacePosition(instance.Latitude, instance.Longitude, instance.AbsolutOffset);
+ instance.mapDecal.transform.up = instance.CelestialBody.GetSurfaceNVector(instance.Latitude, instance.Longitude);
+
+ instance.Update(false);
+
+ instance.Group = DecalsDatabase.GetCloesedCenter(instance.mapDecal.transform.position).Group;
+ }
+
+ }
+ // Rebuild spheres on all plants with new MapDecals
+ foreach (CelestialBody body in bodies2Update)
+ {
+ Log.Normal("Rebuilding PQS sphere on: " + body.name);
+ body.pqsController.RebuildSphere();
+ }
+ }
+ }
+}
diff --git a/src/Modules/Career/CareerObjects.cs b/src/Modules/Career/CareerObjects.cs
index 668a9ba9..13bdc1a5 100644
--- a/src/Modules/Career/CareerObjects.cs
+++ b/src/Modules/Career/CareerObjects.cs
@@ -1,9 +1,10 @@
using KerbalKonstructs.Core;
+using System.Linq;
using UnityEngine;
namespace KerbalKonstructs.Modules
{
- class CareerObjects
+ public class CareerObjects
{
private static string buildingCFGNodeName = "KKBuildings";
@@ -21,15 +22,11 @@ public static void SaveBuildings(ConfigNode cfgNode)
{
if (instance.isInSavegame)
{
+ Debug.Log($"Saving instance {instance.UUID} ({instance.groupCenterName}) in savegame");
ConfigNode instanceNode = buildingNode.AddNode("Instance");
-
- instanceNode.AddValue("UUID", instance.UUID);
instanceNode.AddValue("ModelName", instance.model.name);
- instanceNode.AddValue("Body", instance.CelestialBody.name);
- instanceNode.AddValue("Position", instance.RadialPosition);
- instanceNode.AddValue("Altitude", instance.RadiusOffset);
- instanceNode.AddValue("Rotation", instance.RotationAngle);
- instanceNode.AddValue("IsScanable", instance.isScanable);
+
+ ConfigParser.WriteInstanceConfig(instance, instanceNode);
}
}
}
@@ -80,46 +77,49 @@ public static void LoadBuilding(ConfigNode cfgNode)
instance.isInSavegame = true;
- instance.Orientation = Vector3.up;
- instance.heighReference = HeightReference.Terrain;
- instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000);
-
- instance.Group = "SaveGame";
-
- instance.RadialPosition = ConfigNode.ParseVector3(cfgNode.GetValue("Position"));
-
+ Debug.Log($"ModelName: {cfgNode.GetValue("ModelName")}");
instance.model = StaticDatabase.GetModelByName(cfgNode.GetValue("ModelName"));
-
if (instance.model == null)
{
Log.UserError("LoadFromSave: Canot find model named: " + cfgNode.GetValue("ModelName"));
instance = null;
return;
}
- //instance.mesh = UnityEngine.Object.Instantiate(instance.model.prefab);
+ ConfigParser.ParseInstanceConfig(instance, cfgNode);
+ if (instance.CelestialBody == null)
+ {
+ instance = null;
+ return;
+ }
+
+ if (instance.Group == null)
+ {
+ instance = null;
+ return;
+ }
- instance.UUID = cfgNode.GetValue("UUID");
+ instance.Orientate();
+
+ if (!StaticDatabase.HasInstance(instance))
+ {
+ instance.Destroy();
+ return;
+ }
- instance.CelestialBody = ConfigUtil.GetCelestialBody(cfgNode.GetValue("Body"));
+ LaunchSiteManager.AttachLaunchSite(instance, cfgNode);
+ KerbalKonstructs.AttachFacilities(instance, cfgNode);
- instance.RadiusOffset = float.Parse(cfgNode.GetValue("Altitude"));
- instance.RotationAngle = float.Parse(cfgNode.GetValue("Rotation"));
- instance.RefLatitude = KKMath.GetLatitudeInDeg(instance.RadialPosition);
- instance.RefLongitude = KKMath.GetLongitudeInDeg(instance.RadialPosition);
- InstanceUtil.CreateGroupCenterIfMissing(instance);
+ instance.grassColor2Configs = cfgNode.GetNodes("GrassColor2").ToList();
- if (cfgNode.HasValue("IsScanable"))
+ // update the references
+ foreach (var facility in instance.myFacilities)
{
- bool.TryParse(cfgNode.GetValue("IsScanable"), out instance.isScanable);
+ facility.staticInstance = instance;
}
- bool oldLegacySpawn = KerbalKonstructs.convertLegacyConfigs;
-
- instance.Orientate();
-
- KerbalKonstructs.convertLegacyConfigs = oldLegacySpawn;
+ instance.Deactivate();
}
}
diff --git a/src/Modules/Career/CareerScenario.cs b/src/Modules/Career/CareerScenario.cs
index 12f430ae..7f701f74 100644
--- a/src/Modules/Career/CareerScenario.cs
+++ b/src/Modules/Career/CareerScenario.cs
@@ -1,5 +1,6 @@
using KerbalKonstructs.Core;
using KerbalKonstructs.Modules;
+using KerbalKonstructs.Modules.Career;
namespace KerbalKonstructs.Career
@@ -28,6 +29,10 @@ public override void OnLoad(ConfigNode node)
return;
}
+ CareerMapDecals.LoadDecals(node);
+
+ CareerGroups.LoadGroups(node);
+
CareerObjects.LoadBuildings(node);
// resetting old state in caase it is needed
@@ -93,6 +98,10 @@ public override void OnSave(ConfigNode node)
CareerState.Save(node);
//}
+ CareerMapDecals.SaveDecals(node);
+
+ CareerGroups.SaveGroups(node);
+
CareerObjects.SaveBuildings(node);
}
diff --git a/src/Modules/MapIcons/MapIconDraw.cs b/src/Modules/MapIcons/MapIconDraw.cs
index 8c754e53..c80f9375 100644
--- a/src/Modules/MapIcons/MapIconDraw.cs
+++ b/src/Modules/MapIcons/MapIconDraw.cs
@@ -132,6 +132,8 @@ public void drawTrackingStations()
continue;
}
+ if (groundStation.CelestialBody != body) continue;
+
isOpen = ((GroundStation)groundStation.myFacilities[0]).isOpen;
@@ -231,6 +233,8 @@ public void DrawLaunchsites()
continue;
}
+ if (launchSite.body != body) continue;
+
Vector3 lsPosition = MapView.MapCamera.GetComponent().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(launchSitePosition));
screenRect = new Rect((lsPosition.x - 8), (Screen.height - lsPosition.y) - 8, 16, 16);
@@ -311,6 +315,8 @@ private void DrawSpaceCenters()
continue;
}
+ if (customSpaceCenter.staticInstance.CelestialBody != body) continue;
+
cscIsOpen = customSpaceCenter.isOpen;
diff --git a/src/Modules/RemoteNet/ConnectionManager.cs b/src/Modules/RemoteNet/ConnectionManager.cs
index 504c7a04..217f6329 100644
--- a/src/Modules/RemoteNet/ConnectionManager.cs
+++ b/src/Modules/RemoteNet/ConnectionManager.cs
@@ -221,7 +221,7 @@ private static void AddCommNetStation(GroundStation facility)
StaticInstance instance = facility.staticInstance;
float antennaPower = facility.TrackingShort * 1000000;
Log.Normal("Adding Groundstation: " + instance.Group);
- if (openCNStations.Contains(instance) == false)
+ if (!openCNStations.Contains(instance))
{
KKCommNetHome commNetGroudStation = instance.gameObject.AddComponent();
commNetGroudStation.nodeName = instance.CelestialBody.name + ": " + instance.Group;
diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs
index bb732533..b959206a 100644
--- a/src/Properties/AssemblyInfo.cs
+++ b/src/Properties/AssemblyInfo.cs
@@ -41,9 +41,9 @@
[assembly: AssemblyFileVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")]
[assembly: AssemblyInformationalVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")]
#else
-[assembly: AssemblyFileVersion("1.9.1.0")]
-[assembly: AssemblyInformationalVersion("1.9.1.0")]
+[assembly: AssemblyFileVersion("1.11.0.0")]
+[assembly: AssemblyInformationalVersion("1.11.0.0")]
#endif
-[assembly: KSPAssembly("KerbalKonstructs", 1, 9, 1)]
+[assembly: KSPAssembly("KerbalKonstructs", 1, 11, 0)]