//Convert all of our saved strings into the appropriate arrays for each game scene public override void OnLoad(ConfigNode node) { instance = this; try { //The first step is manually checking for active contracts from the Game ConfigNode (ie persistent.sfs file); the count of active contracts will be used later when the window is loading ConfigNode gameNode = HighLogic.CurrentGame.config; if (gameNode != null) { ConfigNode contractSystemNode = gameNode.GetNodes("SCENARIO").FirstOrDefault(c => c.GetValue("name") == "ContractSystem"); if (contractSystemNode != null) { ConfigNode cNode = contractSystemNode.GetNode("CONTRACTS"); if (cNode != null) { foreach (ConfigNode C in cNode.GetNodes("CONTRACT")) { if (C == null) { continue; } if (C.HasValue("autoAccept")) { if (C.GetValue("autoAccept") == "True") { continue; } } if (C.HasValue("state")) { if (C.GetValue("state") == "Active") { contractCount++; } } } } else { DMC_MBE.LogFormatted("Contract System Can't Be Checked... Node Invalid"); } } } ConfigNode scenes = node.GetNode("Contracts_Window_Parameters"); if (scenes != null) { windowPos = stringSplit(scenes.GetValue("WindowPosition")); windowVisible = stringSplitBool(scenes.GetValue("WindowVisible")); int[] winPos = new int[4] { windowPos[4 * currentScene(HighLogic.LoadedScene)], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 1], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 2], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 3] }; //All saved contract missions are loaded here //Each mission has a separate contract list foreach (ConfigNode m in scenes.GetNodes("Contracts_Window_Mission")) { if (m == null) { continue; } string name; string activeString = ""; string hiddenString = ""; string vesselString = ""; bool ascending, showActive; int sortMode; bool master = false; if (m.HasValue("MissionName")) { name = m.GetValue("MissionName"); } else { continue; } if (name == "MasterMission") { master = true; } if (m.HasValue("ActiveListID")) { activeString = m.GetValue("ActiveListID"); } if (m.HasValue("HiddenListID")) { hiddenString = m.GetValue("HiddenListID"); } if (m.HasValue("VesselIDs")) { vesselString = m.GetValue("VesselIDs"); } if (!bool.TryParse(m.GetValue("AscendingSort"), out ascending)) { ascending = true; } if (!bool.TryParse(m.GetValue("ShowActiveList"), out showActive)) { showActive = true; } if (!int.TryParse(m.GetValue("SortMode"), out sortMode)) { sortMode = 0; } contractMission mission = new contractMission(name, activeString, hiddenString, vesselString, ascending, showActive, sortMode, master); if (master) { masterMission = mission; DMC_MBE.LogFormatted_DebugOnly("Setting Master Mission During Load"); } if (!missionList.Contains(name)) { missionList.Add(name, mission); } } loadWindow(winPos); } } catch (Exception e) { DMC_MBE.LogFormatted("Contracts Window Settings Cannot Be Loaded: {0}", e); } }
//Convert all of our saved strings into the appropriate arrays for each game scene public override void OnLoad(ConfigNode node) { instance = this; try { //The first step is manually checking for active contracts from the Game ConfigNode (ie persistent.sfs file); the count of active contracts will be used later when the window is loading ConfigNode gameNode = HighLogic.CurrentGame.config; if (gameNode != null) { ConfigNode contractSystemNode = gameNode.GetNodes("SCENARIO").FirstOrDefault(c => c.GetValue("name") == "ContractSystem"); if (contractSystemNode != null) { ConfigNode cNode = contractSystemNode.GetNode("CONTRACTS"); if (cNode != null) { foreach (ConfigNode C in cNode.GetNodes("CONTRACT")) { if (C == null) continue; if (C.HasValue("autoAccept")) { if (C.GetValue("autoAccept") == "True") continue; } if (C.HasValue("state")) { if (C.GetValue("state") == "Active") contractCount++; } } } else DMC_MBE.LogFormatted("Contract System Can't Be Checked... Node Invalid"); } } //The next step is checking the current version number and comparing it to the saved value; //if a newer version number is detected the rest of the load process is skipped; //this resets all values for version updates //if (version == contractAssembly.Version) //{ ConfigNode scenes = node.GetNode("Contracts_Window_Parameters"); if (scenes != null) { windowPos = stringSplit(scenes.GetValue("WindowPosition")); windowVisible = stringSplitBool(scenes.GetValue("WindowVisible")); int[] winPos = new int[4] { windowPos[4 * currentScene(HighLogic.LoadedScene)], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 1], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 2], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 3] }; //All saved contract missions are loaded here //Each mission has a separate contract list foreach (ConfigNode m in scenes.GetNodes("Contracts_Window_Mission")) { if (m == null) continue; string name; string activeString = ""; string hiddenString = ""; string vesselString = ""; bool ascending, showActive; int sortMode; bool master = false; if (m.HasValue("MissionName")) name = m.GetValue("MissionName"); else continue; if (name == "MasterMission") master = true; if (m.HasValue("ActiveListID")) activeString = m.GetValue("ActiveListID"); if (m.HasValue("HiddenListID")) hiddenString = m.GetValue("HiddenListID"); if (m.HasValue("VesselIDs")) vesselString = m.GetValue("VesselIDs"); if (!bool.TryParse(m.GetValue("AscendingSort"), out ascending)) ascending = true; if (!bool.TryParse(m.GetValue("ShowActiveList"), out showActive)) showActive = true; if (!int.TryParse(m.GetValue("SortMode"), out sortMode)) sortMode = 0; contractMission mission = new contractMission(name, activeString, hiddenString, vesselString, ascending, showActive, sortMode, master); if (master) { masterMission = mission; DMC_MBE.LogFormatted_DebugOnly("Setting Master Mission During Load"); } if (!missionList.ContainsKey(name)) missionList.Add(name, mission); } loadWindow(winPos); } //} version = contractAssembly.Version; } catch (Exception e) { DMC_MBE.LogFormatted("Contracts Window Settings Cannot Be Loaded: {0}", e); } }