Example #1
0
        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(" ");
                }
            }
        }