public void Start() { Log.Info("Start"); if (!HighLogic.LoadedSceneIsFlight) { return; } Instance = this; clsGPSMath.Reset(); Events["DeactivateReceiver"].active = true; Events["ActivateReceiver"].active = false; gyReceiverOn = true; gyKerbalGPSInitialised = false; giLastVesselCount = 0; gbDisplayMode = MODE_GPS_POSITION; gLastSVCheckTime = DateTime.Now; FileIO.LoadData(this); // GPSToolbar.AppLauncherKerbalGPS.localStart(this.gameObject); GameEvents.onHideUI.Add(this.HideUI); GameEvents.onShowUI.Add(this.ShowUI); GameEvents.onGamePause.Add(this.HideUIWhenPaused); GameEvents.onGameUnpause.Add(this.ShowUIwhenPaused); }
static void SaveWindowPositions(KerbalGPS Instance, ConfigNode settings) { ConfigNode winPos = new ConfigNode(); SaveWinPos(winPos, "varWindowPos", Instance.varWindowPos); SaveWinPos(winPos, "varDestWindowPos", Instance.varDestWindowPos); settings.AddNode(WINDOWPOSNODE, winPos); }
static void LoadWindowPositions(KerbalGPS Instance, ConfigNode settings) { ConfigNode winPos = settings.GetNode(WINDOWPOSNODE); if (winPos == null) { Log.Info("Unable to load window positions"); return; } Instance.varWindowPos = GetWinPos(winPos, "varWindowPos", KerbalGPS.GPS_GUI_WIDTH, KerbalGPS.GPS_GUI_HEIGHT); Instance.varDestWindowPos = GetWinPos(winPos, "varDestWindowPos", KerbalGPS.GPS_GUI_WIDTH, Instance.GPS_DEST_GUI_HEIGHT); }
static public void LoadData(KerbalGPS Instance) { gdDestinations.Clear(); if (File.Exists(PLUGINDATA)) { ConfigNode dataFile = ConfigNode.Load(PLUGINDATA); if (dataFile != null) { Log.Info("Datafile opened and loaded"); ConfigNode dataNode = dataFile.GetNode(DATANODE); if (dataNode != null) { Log.Info("Nodes loaded"); // load screen coordinates here LoadWindowPositions(Instance, dataNode); ConfigNode[] entries = dataNode.GetNodes(DESTNODE); Log.Info("Entries loaded: " + entries.Length); foreach (var entry in entries) { GPS_Coordinates coordinates = new GPS_Coordinates(); coordinates.sDestName = entry.GetValue("sDestName"); coordinates.sCelestialBodyName = entry.GetValue("sCelestialBodyName"); if (coordinates.sCelestialBodyName == null) { coordinates.sCelestialBodyName = FlightGlobals.GetHomeBody().name; } coordinates.fDestLat = (float)Double.Parse(SafeLoad(entry.GetValue("fDestLat"), KerbalGPS.DEF_DESTLAT)); coordinates.fDestLon = (float)Double.Parse(SafeLoad(entry.GetValue("fDestLon"), KerbalGPS.DEF_DESTLON)); gdDestinations.Add(coordinates.sDestName, coordinates); Log.Info("sDestName: " + coordinates.sDestName + ", fDestLat: " + coordinates.fDestLat + ", fDestLon: " + coordinates.fDestLon); } } } } }
static public void SaveData(KerbalGPS Instance) { ConfigNode dataFile = new ConfigNode(DATANODE); ConfigNode dataNode = new ConfigNode(DATANODE); dataFile.AddNode(dataNode); // Save screen coordinates here SaveWindowPositions(Instance, dataNode); foreach (var entry in gdDestinations) { ConfigNode n = new ConfigNode(); n.AddValue("sDestName", entry.Key); n.AddValue("sCelestialBodyName", entry.Value.sCelestialBodyName); n.AddValue("fDestLat", entry.Value.fDestLat); n.AddValue("fDestLon", entry.Value.fDestLon); dataNode.AddNode(DESTNODE, n); } dataFile.Save(PLUGINDATA); }