Пример #1
0
        // Shows a list of all available ship-payloads and returns true, if the player has selected one:
        public bool DisplayList()
        {
            CheckInternals();
            GUILayout.Label("<size=14><b>Payload:</b></size>");
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUI.scrollStyle);

            // Show list with all possible payloads:
            List <GUIContent> contents = new List <GUIContent>();

            foreach (CachedShipTemplate ship in GUI.shipTemplates)
            {
                contents.Add(new GUIContent(
                                 "<color=#F9FA86><b>" + ship.template.shipName + "</b></color>\n" +
                                 "<color=#FFFFFF><b>Size:</b> " + ship.template.shipSize.x.ToString("0.0m") + ", " + ship.template.shipSize.y.ToString("0.0m") + ", " + ship.template.shipSize.z.ToString("0.0m") + "</color>\n" +
                                 "<color=#FFFFFF><b>Mass:</b> " + ship.template.totalMass.ToString("0.0t") + "</color>\n" +
                                 "<color=#B3D355><b>Cost:</b> " + ship.template.totalCost.ToString("#,##0√") + "</color>"
                                 , ship.thumbnail
                                 ));
            }
            if ((selectedIndex = GUILayout.SelectionGrid(selectedIndex, contents.ToArray(), 1, GUI.selectionGridStyle)) >= 0)
            {
                // The player has selected a payload:
                payload = GUI.shipTemplates[selectedIndex];
            }
            GUILayout.EndScrollView();
            return(payload != null);
        }
Пример #2
0
 public GUICrewTransferSelector(CachedShipTemplate targetTemplate, MissionProfile missionProfile)
 {
     this.targetTemplate = targetTemplate;
     this.missionProfile = missionProfile;
     crewToDeliver       = new List <string>();
     crewToCollect       = new List <string>();
 }
Пример #3
0
 // Makes sure that the cached settings are still valid (eg if the player has deleted the selected payload):
 private void CheckInternals()
 {
     if (!GUI.shipTemplates.Contains(payload) || selectedIndex < 0 || selectedIndex >= GUI.shipTemplates.Count)
     {
         selectedIndex = -1;
         payload       = null;
     }
 }
Пример #4
0
 // Displays the currently selected ship-payload and returns true, if the player has deselected it:
 public bool DisplaySelected()
 {
     CheckInternals();
     if (payload == null)
     {
         return(true);
     }
     GUILayout.BeginHorizontal();
     GUILayout.Label("<size=14><b>Payload:</b></size>", new GUIStyle(GUI.labelStyle)
     {
         stretchWidth = true
     });
     if (GUILayout.Button("<size=14><color=#F9FA86><b>" + payload.template.shipName + "</b></color> (Mass: " + payload.template.totalMass.ToString("0.0t") + ")</size>", new GUIStyle(GUI.buttonStyle)
     {
         alignment = TextAnchor.MiddleRight, stretchWidth = false, fixedWidth = 320
     }))
     {
         selectedIndex = -1;
         payload       = null;
     }
     GUILayout.EndHorizontal();
     return(payload == null);
 }
Пример #5
0
        static void ReadAllCraftFiles(string editorFacility, string shipDirectory)
        {
            foreach (var craftFile in Directory.GetFiles(shipDirectory, "*.craft"))
            {
                try
                {
                    string validFileName = Path.GetFileNameWithoutExtension(craftFile);
                    if (validFileName == "Auto-Saved Ship")
                    {
                        continue;                                     // Skip these, they would lead to duplicates, we only use finished crafts.
                    }
                    var cachedTemplate = new CachedShipTemplate();
                    switch (editorFacility)
                    {
                    case "VAB": cachedTemplate.templateOrigin = TemplateOrigin.VAB; break;

                    case "SPH": cachedTemplate.templateOrigin = TemplateOrigin.SPH; break;

                    case "Subassemblies": cachedTemplate.templateOrigin = TemplateOrigin.SubAssembly; break;
                    }

                    cachedTemplate.template = ShipConstruction.LoadTemplate(craftFile);

                    if (cachedTemplate.template == null)
                    {
                        continue;
                    }
                    if (cachedTemplate.template.shipPartsExperimental || !cachedTemplate.template.shipPartsUnlocked)
                    {
                        continue;                                                                                              // We won't bother with ships we can't use anyways.
                    }
                    // Try to load the thumbnail for this craft:
                    var thumbFile = KSPUtil.ApplicationRootPath + "thumbs/" + HighLogic.SaveFolder + "_" + editorFacility + "_" + validFileName + ".png";

                    Texture2D thumbnail;

                    //
                    // Make the thumbnail file if it doesn't exist.
                    // Needed for the subassemblies, will also replace any missing thumbnail files for regular craft
                    //
                    if (!HighLogic.LoadedSceneIsFlight)
                    {
                        if (!File.Exists(thumbFile))
                        {
                            Log.Info("Missing Thumbfile: " + thumbFile);
                            ShipConstruct ship = ShipConstruction.LoadShip(craftFile);
                            ThumbnailHelper.CaptureThumbnail(ship, 256, "thumbs/", HighLogic.SaveFolder + "_" + editorFacility + "_" + validFileName);
                        }
                    }

                    bool placeholder = false;
                    if (File.Exists(thumbFile))
                    {
                        thumbnail = new Texture2D(256, 256, TextureFormat.RGBA32, false);
                        thumbnail.LoadImage(File.ReadAllBytes(thumbFile));
                    }
                    else
                    {
                        thumbnail   = placeholderImage;
                        placeholder = true;
                    }

                    // The thumbnails are rather large, so we have to resize them first:
                    cachedTemplate.thumbnail = GUI.ResizeTexture(thumbnail, 64, 64);
                    if (!placeholder)
                    {
                        Destroy(thumbnail);
                    }
                    GUI.shipTemplates.Add(cachedTemplate);
                }
                catch (Exception e)
                {
                    Debug.LogError("UpdateShipTemplateCache() processing '" + craftFile + "': " + e.ToString());
                }
            }
        }
Пример #6
0
        // Shows a list of all available ship-payloads and returns true, if the player has selected one:
        // need to add filter
        public bool DisplayList()
        {
            indexReference = new int[GUI.shipTemplates.Count];
            int indexCnt = 0;

            CheckInternals();
            GUILayout.BeginHorizontal();
            GUILayout.Label("<size=14><b>Payload:</b></size>");
            GUILayout.FlexibleSpace();
            GUILayout.Label("Filter:");
            filter = GUILayout.TextField(filter, GUILayout.Width(200));
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            selVAB = GUILayout.Toggle(selVAB, "VAB");
            GUILayout.Space(30);
            selSPH = GUILayout.Toggle(selSPH, "SPH");
            GUILayout.Space(30);
            selSubassembly = GUILayout.Toggle(selSubassembly, "Subassemblies");
            GUILayout.EndHorizontal();
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUI.scrollStyle);

            // Show list with all possible payloads:
            var contents = new List <GUIContent>();

            for (int i = 0; i < GUI.shipTemplates.Count; i++)
            {
                var ship = GUI.shipTemplates[i];

                if (filter == "" || ship.template.shipName.Contains(filter))
                {
                    bool b = false;
                    switch (ship.templateOrigin)
                    {
                    case TemplateOrigin.SPH: b = selSPH; break;

                    case TemplateOrigin.VAB: b = selVAB; break;

                    case TemplateOrigin.SubAssembly: b = selSubassembly; break;
                    }
                    if (b)
                    {
                        indexReference[indexCnt++] = i;
                        contents.Add(new GUIContent(
                                         "<color=#F9FA86><b>" + ship.template.shipName + "</b></color>\n" +
                                         "<color=#FFFFFF><b>Size:</b> " + ship.template.shipSize.x.ToString("0.0m") + ", " + ship.template.shipSize.y.ToString("0.0m") + ", " + ship.template.shipSize.z.ToString("0.0m") + "</color>\n" +
                                         "<color=#FFFFFF><b>Mass:</b> " + ship.template.totalMass.ToString("0.0t") + "</color>\n" +
                                         "<color=#B3D355><b>Cost:</b> " + ship.template.totalCost.ToString("#,##0√") + "</color>"
                                         , ship.thumbnail
                                         ));
                    }
                }
            }
            if ((selectedIndex = GUILayout.SelectionGrid(selectedIndex, contents.ToArray(), 1, GUI.selectionGridStyle)) >= 0)
            {
                // The player has selected a payload:
                payload = GUI.shipTemplates[indexReference[selectedIndex]];
            }
            GUILayout.EndScrollView();
            return(payload != null);
        }
Пример #7
0
Файл: GUI.cs Проект: MrKiel/KSTS
        // Updates the cache we use to store the meta-data of the various ships the player has designed:
        public static void UpdateShipTemplateCache()
        {
            if (GUI.shipTemplates == null)
            {
                GUI.shipTemplates = new List <CachedShipTemplate>();
            }
            string[] editorFacilities = { "VAB", "SPH" }; // This is usually an enum, but we need the string later.
            GUI.shipTemplates.Clear();

            foreach (string editorFacility in editorFacilities)
            {
                string shipDirectory = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/Ships/" + editorFacility; // Directory where the crafts are stored for the current game.
                if (!Directory.Exists(shipDirectory))
                {
                    continue;
                }

                // Get all crafts the player has designed in this savegame:
                foreach (string craftFile in Directory.GetFiles(shipDirectory, "*.craft"))
                {
                    try
                    {
                        if (Path.GetFileNameWithoutExtension(craftFile) == "Auto-Saved Ship")
                        {
                            continue;                                                                   // Skip these, they would lead to duplicates, we only use finished crafts.
                        }
                        CachedShipTemplate cachedTemplate = new CachedShipTemplate();

                        cachedTemplate.template = ShipConstruction.LoadTemplate(craftFile);
                        if (cachedTemplate.template == null)
                        {
                            continue;
                        }
                        if (cachedTemplate.template.shipPartsExperimental || !cachedTemplate.template.shipPartsUnlocked)
                        {
                            continue;                                                                                              // We won't bother with ships we can't use anyways.
                        }
                        // Try to load the thumbnail for this craft:
                        string    thumbFile = KSPUtil.ApplicationRootPath + "/thumbs/" + HighLogic.SaveFolder + "_" + editorFacility + "_" + cachedTemplate.template.shipName + ".png";
                        Texture2D thumbnail;
                        if (File.Exists(thumbFile))
                        {
                            thumbnail = new Texture2D(256, 256, TextureFormat.RGBA32, false);
                            thumbnail.LoadImage(File.ReadAllBytes(thumbFile));
                        }
                        else
                        {
                            thumbnail = placeholderImage;
                        }

                        // The thumbnails are rather large, so we have to resize them first:
                        cachedTemplate.thumbnail = GUI.ResizeTexture(thumbnail, 64, 64);

                        GUI.shipTemplates.Add(cachedTemplate);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("[KSTS] UpdateShipTemplateCache() processing '" + craftFile + "': " + e.ToString());
                    }
                }
            }

            GUI.shipTemplates.Sort((x, y) => x.template.shipName.CompareTo(y.template.shipName));
        }