ExLP.ExLaunchPad.WindowGUI C# (CSharp) Method

WindowGUI() private method

private WindowGUI ( int windowID ) : void
windowID int
return void
        private void WindowGUI(int windowID)
        {
            Styles.Init();
            /*
             * ToDo:
             * can extend FileBrowser class to see currently highlighted file?
             * rslashphish says: public myclass(arg1, arg2) : base(arg1, arg2);
             * KSPUtil.ApplicationRootPath - gets KSPO root
             * expose m_files and m_selectedFile?
             * fileBrowser = new FileBrowser(new Rect(Screen.width / 2, 100, 350, 500), title, callback, true);
             */

            EditorLogic editor = EditorLogic.fetch;
            if (editor) return;

            if (!uis.builduiactive) return;

            if (padResources != null && padPartsCount != vessel.Parts.Count) {
            // something docked or undocked, so rebuild the pad's resouces info
            padResources = null;
            }
            if (padResources == null) {
            padPartsCount = vessel.Parts.Count;
            padResources = new VesselResources(vessel);
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal("box");
            GUILayout.FlexibleSpace();
            // VAB / SPH selection
            if (GUILayout.Toggle(uis.ct == crafttype.VAB, "VAB", GUILayout.Width(80))) {
            uis.ct = crafttype.VAB;
            }
            if (GUILayout.Toggle(uis.ct == crafttype.SPH, "SPH", GUILayout.Width(80))) {
            uis.ct = crafttype.SPH;
            }
            if (GUILayout.Toggle(uis.ct == crafttype.SUB, "SubAss", GUILayout.Width(160))) {
            uis.ct = crafttype.SUB;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            string strpath = HighLogic.SaveFolder;

            if (GUILayout.Button("Select Craft", Styles.normal, GUILayout.ExpandWidth(true))) {
            string [] dir = new string[] {"SPH", "VAB", "../Subassemblies"};
            bool stock = HighLogic.CurrentGame.Parameters.Difficulty.AllowStockVessels;
            if (uis.ct == crafttype.SUB)
                HighLogic.CurrentGame.Parameters.Difficulty.AllowStockVessels = false;
            //GUILayout.Button is "true" when clicked
            uis.craftlist = new CraftBrowser(new Rect(Screen.width / 2, 100, 350, 500), dir[(int)uis.ct], strpath, "Select a ship to load", craftSelectComplete, craftSelectCancel, HighLogic.Skin, EditorLogic.ShipFileImage, true);
            uis.showcraftbrowser = true;
            HighLogic.CurrentGame.Parameters.Difficulty.AllowStockVessels = stock;
            }

            if (uis.craftselected) {
            GUILayout.Box("Selected Craft:	" + uis.craftnode.GetValue("ship"), Styles.white);

            // Resource requirements
            GUILayout.Label("Resources required to build:", Styles.label, GUILayout.Width(600));

            // Link LFO toggle

            uis.linklfosliders = GUILayout.Toggle(uis.linklfosliders, "Link RocketFuel sliders for LiquidFuel and Oxidizer");

            uis.resscroll = GUILayout.BeginScrollView(uis.resscroll, GUILayout.Width(600), GUILayout.Height(300));

            GUILayout.BeginHorizontal();

            // Headings
            GUILayout.Label("Resource", Styles.label, GUILayout.Width(120));
            GUILayout.Label("Fill Percentage", Styles.label, GUILayout.Width(300));
            GUILayout.Label("Required", Styles.label, GUILayout.Width(75));
            GUILayout.Label("Available", Styles.label, GUILayout.Width(75));
            GUILayout.EndHorizontal();

            uis.canbuildcraft = true;	   // default to can build - if something is stopping us from building, we will set to false later

            if (!uis.requiredresources.ContainsKey("RocketParts")) {
                // if the craft to be built has no rocket parts storage, then the amount to use is not adjustable
                string resname = "RocketParts";
                double available = padResources.ResourceAmount(resname);
                ResourceLine(resname, resname, 1.0F, uis.hullRocketParts, uis.hullRocketParts, available);
            }

            // Cycle through required resources
            foreach (KeyValuePair<string, double> pair in uis.requiredresources) {
                string resname = pair.Key;	// Holds REAL resource name. May need to translate from "JetFuel" back to "LiquidFuel"
                string reslabel = resname;	 // Resource name for DISPLAY purposes only. Internally the app uses pair.Key
                if (reslabel == "JetFuel") {
                    if (pair.Value == 0f) {
                        // Do not show JetFuel line if not being used
                        continue;
                    }
                    //resname = "JetFuel";
                    resname = "LiquidFuel";
                }
                if (!uis.resourcesliders.ContainsKey(pair.Key)) {
                    uis.resourcesliders.Add(pair.Key, 1);
                }

                // If in link LFO sliders mode, rename Oxidizer to LFO (Oxidizer) and LiquidFuel to LFO (LiquidFuel)
                if (reslabel == "Oxidizer") {
                    reslabel = "RocketFuel (Ox)";
                }
                if (reslabel == "LiquidFuel") {
                    reslabel = "RocketFuel (LF)";
                }

                double minAmount = 0.0;
                double maxAmount = uis.requiredresources[resname];
                if (resname == "RocketParts") {
                    minAmount += uis.hullRocketParts;
                    maxAmount += uis.hullRocketParts;
                }

                double available = padResources.ResourceAmount(resname);
                // If LFO LiquidFuel exists and we are on LiquidFuel (Non-LFO), then subtract the amount used by LFO(LiquidFuel) from the available amount
                if (pair.Key == "JetFuel") {
                    available -= uis.requiredresources["LiquidFuel"] * uis.resourcesliders["LiquidFuel"];
                    if (available < 0.0)
                        available = 0.0;
                }

                uis.resourcesliders[pair.Key] = ResourceLine(reslabel, pair.Key, uis.resourcesliders[pair.Key], minAmount, maxAmount, available);
                if (uis.linklfosliders) {
                    float tmp = uis.resourcesliders[pair.Key];
                    if (pair.Key == "Oxidizer") {
                        uis.resourcesliders["LiquidFuel"] = tmp;
                    } else if (pair.Key == "LiquidFuel") {
                        uis.resourcesliders["Oxidizer"] = tmp;
                    }
                }
            }

            GUILayout.EndScrollView();

            // Build button
            if (uis.canbuildcraft) {
                if (GUILayout.Button("Build", Styles.normal, GUILayout.ExpandWidth(true))) {
                    BuildAndLaunchCraft();
                    // Reset the UI
                    uis.craftselected = false;
                    uis.requiredresources = null;
                    uis.resourcesliders = new Dictionary<string, float>();;
                    uis.builduiactive = false;
                    UpdateGUIState();
                }
            } else {
                GUILayout.Box("You do not have the resources to build this craft", Styles.red);
            }
            } else {
            GUILayout.Box("You must select a craft before you can build", Styles.red);
            }
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close")) {
            HideBuildMenu();
            }

            uis.showbuilduionload = GUILayout.Toggle(uis.showbuilduionload, "Show on StartUp");

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            //DragWindow makes the window draggable. The Rect specifies which part of the window it can by dragged by, and is
            //clipped to the actual boundary of the window. You can also pass no argument at all and then the window can by
            //dragged by any part of it. Make sure the DragWindow command is AFTER all your other GUI input stuff, or else
            //it may "cover up" your controls and make them stop responding to the mouse.
            GUI.DragWindow(new Rect(0, 0, 10000, 20));
        }