protected void getEditorBayItem() { editorBayItem = BARISScenario.Instance.GetEditorBay(isVAB, bayID); if (editorBayItem != null) { debugLog("Bay " + bayID + " exists."); debugLog(editorBayItem.ToString()); } else { debugLog("Bay " + bayID + " does not exist, creating."); editorBayItem = new EditorBayItem(); editorBayItem = BARISScenario.Instance.AddEditorBay(isVAB, bayID); } }
public EditorBayView(int editorBayID, bool isVABBay) { bayID = editorBayID; isVAB = isVABBay; editorBayItem = BARISScenario.Instance.GetEditorBay(isVAB, bayID); if (editorBayItem != null) { debugLog("Bay " + bayID + " exists."); debugLog(editorBayItem.ToString()); } else { debugLog("Bay " + bayID + " does not exist, creating."); editorBayItem = new EditorBayItem(); editorBayItem = BARISScenario.Instance.AddEditorBay(isVAB, bayID); } //Get the thumbnails folder. // See: http://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in/283917#283917 DirectoryInfo directoryInfo = Directory.GetParent(Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Path))).Parent.Parent; string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); thumbnailFullPath = Path.GetDirectoryName(path); //Setup the root folder and thumbs folder. if (thumbnailFullPath.Contains("GameData")) { thumbnailBaseFileName = HighLogic.SaveFolder; if (isVAB) { thumbnailBaseFileName = thumbnailBaseFileName + "_VAB_"; } else { thumbnailBaseFileName = thumbnailBaseFileName + "_SPH_"; } int index = thumbnailFullPath.IndexOf("GameData"); thumbnailFullPath = thumbnailFullPath.Substring(0, index); savesFolder = thumbnailFullPath + "saves/" + HighLogic.SaveFolder + "/"; thumbnailFullPath += "thumbs/" + thumbnailBaseFileName; } //Icons if (exitIconBlack == null) { exitIconBlack = GameDatabase.Instance.GetTexture("WildBlueIndustries/000BARIS/Icons/Exit", false); } if (exitIconWhite == null) { exitIconWhite = GameDatabase.Instance.GetTexture("WildBlueIndustries/000BARIS/Icons/ExitWhite", false); } exitIcon = exitIconBlack; if (newIconBlack == null) { newIconBlack = GameDatabase.Instance.GetTexture("WildBlueIndustries/000BARIS/Icons/NewIconBlack", false); } if (newIconWhite == null) { newIconWhite = GameDatabase.Instance.GetTexture("WildBlueIndustries/000BARIS/Icons/NewIconWhite", false); } newIcon = newIconBlack; if (loadIconBlack == null) { loadIconBlack = GameDatabase.Instance.GetTexture("WildBlueIndustries/000BARIS/Icons/loadIconBlack", false); } if (loadIconWhite == null) { loadIconWhite = GameDatabase.Instance.GetTexture("WildBlueIndustries/000BARIS/Icons/loadIconWhite", false); } launchIcon = loadIconBlack; if (fundsIconBlack == null) { fundsIconBlack = GameDatabase.Instance.GetTexture("WildBlueIndustries/000BARIS/Icons/FundsIconBlack", false); } if (fundsIconWhite == null) { fundsIconWhite = GameDatabase.Instance.GetTexture("WildBlueIndustries/000BARIS/Icons/FundsIconWhite", false); } fundsIcon = fundsIconBlack; }
protected void drawEmptyBay() { ShipConstruct ship = EditorLogic.fetch.ship; Color oldColor = GUI.backgroundColor; if (ship.parts.Count > 0) { GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); //If the new integration button is pressed then record the info we need //to add editor bay data to the database. GUI.backgroundColor = XKCDColors.ColorTranslator.FromHtml("#97f5ff"); if (GUILayout.Button(newIcon, buttonOptions)) { //Set up a new vehicle integration editorBayItem.Clear(); editorBayItem.vesselName = ship.shipName; //Generate snapshot of the vessel ConfigNode shipNode = ship.SaveShip(); editorBayItem.vesselFilePath = savesFolder + ship.shipName + isVAB + editorBayItem.editorBayID + ".cfg"; debugLog("Vessel file: " + editorBayItem.vesselFilePath); if (File.Exists(editorBayItem.vesselFilePath)) { File.Delete(editorBayItem.vesselFilePath); } shipNode.Save(editorBayItem.vesselFilePath); editorBayItem.vesselThumbnail = null; float dryCost, fuelCost; ship.GetShipCosts(out dryCost, out fuelCost); editorBayItem.rushJobCost = dryCost; calculateReliability(editorBayItem, ship); editorBayItem.totalVesselParts = ship.parts.Count; //Generate thumbnail ShipConstruction.CaptureThumbnail(ship, "thumbs", thumbnailBaseFileName + ship.shipName); //Generate the full path to the thumbnail and add it to the editorBayItem editorBayItem.thumbnailPath = thumbnailFullPath + ship.shipName + ".png"; //Add workers int availableWorkers = BARISScenario.Instance.GetAvailableWorkers(isVAB); if (availableWorkers >= BARISScenario.MaxWorkersPerBay) { editorBayItem.workerCount = BARISScenario.MaxWorkersPerBay; availableWorkers -= editorBayItem.workerCount; BARISScenario.Instance.SetAvailableWorkers(availableWorkers, isVAB); } else { editorBayItem.workerCount = availableWorkers; BARISScenario.Instance.SetAvailableWorkers(0, isVAB); } //Generate a KAC alarm (if KAC is installed) setKACAlarm(editorBayItem); //Save the new item BARISScenario.Instance.SetEditorBay(editorBayItem); GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.BACKUP); //Cleanup debugLog(editorBayItem.ToString()); } newIcon = selectNewIcon(); GUI.backgroundColor = oldColor; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); //Tooltip if (string.IsNullOrEmpty(newToolTip) == false) { GUILayout.Label(newToolTip); } else { GUILayout.Label(" "); } } }