public void CreatePreviewInstance(StaticModel model)
        {
            StaticObject obj = new StaticObject();
            obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));
            obj.setSetting("RadiusOffset", (float)FlightGlobals.ActiveVessel.altitude);
            obj.setSetting("CelestialBody", KerbalKonstructs.instance.getCurrentBody());
            obj.setSetting("Group", "Ungrouped");
            obj.setSetting("RadialPosition", KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position));
            obj.setSetting("RotationAngle", 0f);
            obj.setSetting("Orientation", Vector3.up);
            obj.setSetting("VisibilityRange", 25000f);

            obj.model = model;

            KerbalKonstructs.instance.getStaticDB().addStatic(obj);
            obj.spawnObject(true, true);
            // KerbalKonstructs.instance.selectObject(obj, false);
            currPreview = obj;
        }
 public List<StaticObject> getObjectsFromModel(StaticModel model)
 {
     return (from obj in getAllStatics() where obj.model == model select obj).ToList();
 }
 public List <StaticObject> getObjectsFromModel(StaticModel model)
 {
     return((from obj in getAllStatics() where obj.model == model select obj).ToList());
 }
 public void registerModel(StaticModel model)
 {
     modelList.Add(model);
 }
        public StaticObject spawnInstance(StaticModel model)
        {
            StaticObject obj = new StaticObject();
            obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));
            obj.setSetting("RadiusOffset", (float)FlightGlobals.ActiveVessel.altitude);
            obj.setSetting("CelestialBody", KerbalKonstructs.instance.getCurrentBody());
            obj.setSetting("Group", "Ungrouped");
            obj.setSetting("RadialPosition", KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(FlightGlobals.ActiveVessel.transform.position));
            obj.setSetting("RotationAngle", 0f);
            obj.setSetting("Orientation", Vector3.up);
            obj.setSetting("VisibilityRange", 25000f);

            string sPad = ((string)model.getSetting("DefaultLaunchPadTransform"));
            if (sPad != null) obj.setSetting("LaunchPadTransform", sPad);

            if (!KerbalKonstructs.instance.DevMode)
            {
                obj.setSetting("CustomInstance", "True");
            }

            obj.model = model;

            KerbalKonstructs.instance.getStaticDB().addStatic(obj);
            enableColliders = false;
            obj.spawnObject(true, false);
            return obj;
        }
 public void updateSelection(StaticModel obj)
 {
     infAuthor = (string)obj.getSetting("author");
     infMesh = "" + obj.getSetting("mesh");
     infManufacturer = (string)obj.getSetting("manufacturer");
     infCost = obj.getSetting("cost").ToString();
     infDescription = (string)obj.getSetting("description");
     infTitle = (string)obj.getSetting("title");
     infCategory = (string)obj.getSetting("category");
 }
        public void loadObjects()
        {
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("STATIC");

            foreach(UrlDir.UrlConfig conf in configs)
            {
                StaticModel model = new StaticModel();
                model.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
                model.config = conf.url;
                model.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
                model.settings = KKAPI.loadConfig(conf.config, KKAPI.getModelSettings());

                if (model.settings.ContainsKey("LocalToSave"))
                {
                    if ((string)model.getSetting("LocalToSave") == "True")
                        continue;
                    // Ignore it for second pass
                }

                /* if (model.settings.ContainsKey("mesh"))
                {
                    string sMesh = (string)model.getSetting("mesh");
                    if (sMesh.Contains(".mu"))
                    {}
                    else
                    {
                        Debug.Log("KK: mesh name missing suffix. Adding it.");
                        sMesh = sMesh + ".mu";
                        model.setSetting("mesh", sMesh);
                    }
                } */

                if (model.settings.ContainsKey("pointername"))
                {
                    if ((string)model.getSetting("pointername") != "None")
                        continue;
                    // Ignore it for second pass
                }

                foreach (ConfigNode ins in conf.config.GetNodes("MODULE"))
                {
                    StaticModule module = new StaticModule();
                    foreach (ConfigNode.Value value in ins.values)
                    {
                        switch (value.name)
                        {
                            case "namespace":
                                module.moduleNamespace = value.value;
                                break;
                            case "name":
                                module.moduleClassname = value.value;
                                break;
                            default:
                                module.moduleFields.Add(value.name, value.value);
                                break;
                        }
                    }
                    model.modules.Add(module);
                }

                loadInstances(conf.config, model);

                staticDB.registerModel(model);
            }
        }
        public void loadCareerObjects()
        {
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("STATIC");

            foreach (UrlDir.UrlConfig conf in configs)
            {
                StaticModel model = new StaticModel();
                model.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
                model.config = conf.url;
                model.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
                model.settings = KKAPI.loadConfig(conf.config, KKAPI.getModelSettings());

                string sConfigName = (Path.GetFileName(conf.url)) + ".cfg";

                savedObjectPath = string.Format("{0}saves/{1}/{2}", KSPUtil.ApplicationRootPath, HighLogic.SaveFolder, sConfigName);

                if (!File.Exists(savedObjectPath))
                    continue;

                ConfigNode CareerConfig = ConfigNode.Load(savedObjectPath);
                ConfigNode CareerConfigRoot = CareerConfig.GetNode("STATIC");

                loadInstances(CareerConfigRoot, model, true);
            }
        }
        public void drawModelInfoGUI(StaticModel mSelectedModel)
        {
            if (mSelectedModel != null)
            {
                if (mModel != mSelectedModel)
                {
                    if (currPreview != null)
                        DestroyPreviewInstance(currPreview);

                    updateSelection(mSelectedModel);

                    if (KerbalKonstructs.instance.spawnPreviewModels)
                        CreatePreviewInstance(mSelectedModel);
                }

                mModel = mSelectedModel;

                KKWindow = new GUIStyle(GUI.skin.window);
                KKWindow.padding = new RectOffset(8, 8, 3, 3);

                StaticInfoRect = GUI.Window(0xD00B1E2, StaticInfoRect, drawStaticInfoWindow, "", KKWindow);
            }
        }
		public void loadObjects()
		{
			UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("STATIC");
			
			foreach(UrlDir.UrlConfig conf in configs)
			{
				StaticModel model = new StaticModel();
				model.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
				model.config = conf.url;
				model.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
				model.settings = KKAPI.loadConfig(conf.config, KKAPI.getModelSettings());

				if (model.settings.ContainsKey("LocalToSave"))
				{
					if ((string)model.getSetting("LocalToSave") == "True")
					{
						// Debug.Log("KK: Static Config is local to save. Skipping model and its instances.");
						continue;
					}
				}

				foreach (ConfigNode ins in conf.config.GetNodes("MODULE"))
				{
					// Debug.Log("KK: Found module: "+ins.name+" in "+conf.name);
					StaticModule module = new StaticModule();
					foreach (ConfigNode.Value value in ins.values)
					{
						switch (value.name)
						{
							case "namespace":
								module.moduleNamespace = value.value;
								break;
							case "name":
								module.moduleClassname = value.value;
								break;
							default:
								module.moduleFields.Add(value.name, value.value);
								break;
						}
					}
					model.modules.Add(module);
					// Debug.Log("KK: Adding module");
				}

				loadInstances(conf.config, model);
				
				staticDB.registerModel(model);
			}
		}
		public void loadInstances(ConfigNode confconfig, StaticModel model)
		{
			foreach (ConfigNode ins in confconfig.GetNodes("Instances"))
			{
				// Debug.Log("KK: Loading models");
				StaticObject obj = new StaticObject();
				obj.model = model;
				obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));

				if (obj.gameObject == null)
				{
					Debug.Log("KK: Could not find " + model.getSetting("mesh") + ".mu! Did the mod forget to include it or did you actually install it?");
					continue;
				}
				// Debug.Log("KK: mesh is " + (string)model.getSetting("mesh"));

				obj.settings = KKAPI.loadConfig(ins, KKAPI.getInstanceSettings());

				if (!obj.settings.ContainsKey("LaunchPadTransform") && obj.settings.ContainsKey("LaunchSiteName"))
				{

					if (model.settings.Keys.Contains("DefaultLaunchPadTransform"))
					{
						obj.settings.Add("LaunchPadTransform", model.getSetting("DefaultLaunchPadTransform"));
					}
					else
					{
						Debug.Log("KK: Launch site is missing a transform. Defaulting to " + obj.getSetting("LaunchSiteName") + "_spawn...");

						if (obj.gameObject.transform.Find(obj.getSetting("LaunchSiteName") + "_spawn") != null)
						{
							obj.settings.Add("LaunchPadTransform", obj.getSetting("LaunchSiteName") + "_spawn");
						}
						else
						{
							Debug.Log("KK: FAILED: " + obj.getSetting("LaunchSiteName") + "_spawn does not exist! Attempting to use any transform with _spawn in the name.");
							Transform lastResort = obj.gameObject.transform.Cast<Transform>().FirstOrDefault(trans => trans.name.EndsWith("_spawn"));

							if (lastResort != null)
							{
								Debug.Log("KK: Using " + lastResort.name + " as launchpad transform");
								obj.settings.Add("LaunchPadTransform", lastResort.name);
							}
							else
							{
								Debug.Log("KK: All attempts at finding a launchpad transform have failed (╯°□°)╯︵ ┻━┻ This static isn't configured for KK properly. Tell the modder.");
							}
						}
					}
				}

				staticDB.addStatic(obj);
				spawnObject(obj, false);
				if (obj.settings.ContainsKey("LaunchSiteName"))
				{
					LaunchSiteManager.createLaunchSite(obj);
				}
			}
		}
        public void loadObjects()
        {
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("STATIC");

            foreach(UrlDir.UrlConfig conf in configs)
            {
                StaticModel model = new StaticModel();
                model.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
                model.config = conf.url;
                model.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
                model.settings = KKAPI.loadConfig(conf.config, KKAPI.getModelSettings());

                foreach (ConfigNode ins in conf.config.GetNodes("MODULE"))
                {
                    Debug.Log("KK: Found module: "+ins.name+" in "+conf.name);
                    StaticModule module = new StaticModule();
                    foreach (ConfigNode.Value value in ins.values)
                    {
                        switch (value.name)
                        {
                            case "namespace":
                                module.moduleNamespace = value.value;
                                break;
                            case "name":
                                module.moduleClassname = value.value;
                                break;
                            default:
                                module.moduleFields.Add(value.name, value.value);
                                break;
                        }
                    }
                    model.modules.Add(module);
                    Debug.Log("KK: Adding module");
                }

                foreach (ConfigNode ins in conf.config.GetNodes("Instances"))
                {
                    // Debug.Log("KK: Loading models");
                    StaticObject obj = new StaticObject();
                    obj.model = model;
                    obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));

                    if (obj.gameObject == null)
                    {
                        Debug.Log("KK: Could not find " + model.getSetting("mesh") + ".mu! Did the mod forget to include it or did you actually install it?");
                        continue;
                    }
                    // Debug.Log("KK: mesh is " + (string)model.getSetting("mesh"));

                    obj.settings = KKAPI.loadConfig(ins, KKAPI.getInstanceSettings());

                    if (!obj.settings.ContainsKey("LaunchPadTransform") && obj.settings.ContainsKey("LaunchSiteName"))
                    {

                        if (model.settings.Keys.Contains("DefaultLaunchPadTransform"))
                        {
                            obj.settings.Add("LaunchPadTransform", model.getSetting("DefaultLaunchPadTransform"));
                        }
                        else
                        {
                            Debug.Log("KK: Launch site is missing a transform. Defaulting to " + obj.getSetting("LaunchSiteName") + "_spawn...");

                            if (obj.gameObject.transform.Find(obj.getSetting("LaunchSiteName") + "_spawn") != null)
                            {
                                obj.settings.Add("LaunchPadTransform", obj.getSetting("LaunchSiteName") + "_spawn");
                            }
                            else
                            {
                                Debug.Log("KK: FAILED: " + obj.getSetting("LaunchSiteName") + "_spawn does not exist! Attempting to use any transform with _spawn in the name.");
                                Transform lastResort = obj.gameObject.transform.Cast<Transform>().FirstOrDefault(trans => trans.name.EndsWith("_spawn"));

                                if (lastResort != null)
                                {
                                    Debug.Log("KK: Using " + lastResort.name + " as launchpad transform");
                                    obj.settings.Add("LaunchPadTransform", lastResort.name);
                                }
                                else
                                {
                                    Debug.Log("KK: All attempts at finding a launchpad transform have failed (╯°□°)╯︵ ┻━┻ This static isn't configured for KK properly. Tell the modder.");
                                }
                            }
                        }
                    }

                    staticDB.addStatic(obj);
                    spawnObject(obj, false);
                    if (obj.settings.ContainsKey("LaunchSiteName"))
                    {
                        LaunchSiteManager.createLaunchSite(obj);
                    }
                }

                staticDB.registerModel(model);
            }
        }
Пример #13
0
        public StaticObject spawnInstance(StaticModel model, float fOffset, Vector3 vPosition, float fAngle)
        {
            StaticObject obj = new StaticObject();
            obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));
            obj.setSetting("RadiusOffset", fOffset);
            obj.setSetting("CelestialBody", KerbalKonstructs.instance.getCurrentBody());
            obj.setSetting("Group", "Ungrouped");
            obj.setSetting("RadialPosition", vPosition);
            obj.setSetting("RotationAngle", fAngle);
            obj.setSetting("Orientation", Vector3.up);
            obj.setSetting("VisibilityRange", 25000f);
            obj.model = model;

            KerbalKonstructs.instance.getStaticDB().addStatic(obj);
            enableColliders = false;
            KerbalKonstructs.instance.spawnObject(obj, true);
            return obj;
        }
 public void updateSettings(StaticModel mModel)
 {
     mModel.setSetting("author", infAuthor);
     mModel.setSetting("mesh", infMesh);
     mModel.setSetting("manufacturer", infManufacturer);
     mModel.setSetting("cost", infCost);
     mModel.setSetting("description", infDescription);
     mModel.setSetting("title", infTitle);
     mModel.setSetting("category", infCategory);
 }
 public void registerModel(StaticModel model)
 {
     modelList.Add(model);
 }
        public void drawStaticInfoWindow(int WindowID)
        {
            if (mModel == null) return;

            BoxNoBorder = new GUIStyle(GUI.skin.box);
            BoxNoBorder.normal.background = null;
            BoxNoBorder.normal.textColor = Color.green;
            BoxNoBorder.fontSize = 13;
            BoxNoBorder.fontStyle = FontStyle.Bold;

            BoxNoBorder2 = new GUIStyle(GUI.skin.box);
            BoxNoBorder2.normal.background = null;
            BoxNoBorder2.normal.textColor = Color.white;
            BoxNoBorder2.fontSize = 13;
            BoxNoBorder2.fontStyle = FontStyle.Normal;

            LabelGreen = new GUIStyle(GUI.skin.label);
            LabelGreen.normal.textColor = Color.green;
            LabelGreen.fontSize = 13;
            LabelGreen.fontStyle = FontStyle.Bold;
            LabelGreen.padding.bottom = 1;
            LabelGreen.padding.top = 1;

            LabelWhite = new GUIStyle(GUI.skin.label);
            LabelWhite.normal.textColor = Color.white;
            LabelWhite.fontSize = 13;
            LabelWhite.fontStyle = FontStyle.Normal;
            LabelWhite.padding.bottom = 1;
            LabelWhite.padding.top = 1;

            DeadButton = new GUIStyle(GUI.skin.button);
            DeadButton.normal.background = null;
            DeadButton.hover.background = null;
            DeadButton.active.background = null;
            DeadButton.focused.background = null;
            DeadButton.normal.textColor = Color.yellow;
            DeadButton.hover.textColor = Color.white;
            DeadButton.active.textColor = Color.yellow;
            DeadButton.focused.textColor = Color.yellow;
            DeadButton.fontSize = 14;
            DeadButton.fontStyle = FontStyle.Normal;

            DeadButtonRed = new GUIStyle(GUI.skin.button);
            DeadButtonRed.normal.background = null;
            DeadButtonRed.hover.background = null;
            DeadButtonRed.active.background = null;
            DeadButtonRed.focused.background = null;
            DeadButtonRed.normal.textColor = Color.red;
            DeadButtonRed.hover.textColor = Color.yellow;
            DeadButtonRed.active.textColor = Color.red;
            DeadButtonRed.focused.textColor = Color.red;
            DeadButtonRed.fontSize = 12;
            DeadButtonRed.fontStyle = FontStyle.Bold;

            if (currPreview != null)
            {
                double dTicker = Planetarium.GetUniversalTime();
                if ((dTicker - dUpdater) > 0.01)
                {
                    dUpdater = Planetarium.GetUniversalTime();

                    if (bSpinning)
                        SpinPreview(currPreview);
                }
            }

            bool shouldUpdateSelection = false;
            string smessage = "";

            GUILayout.BeginHorizontal();
            {
                GUI.enabled = false;
                GUILayout.Button("-KK-", DeadButton, GUILayout.Height(21));

                GUILayout.FlexibleSpace();

                GUILayout.Button("Static Model Config Editor", DeadButton, GUILayout.Height(21));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(21)))
                {
                    if (currPreview != null)
                        DestroyPreviewInstance(currPreview);

                    KerbalKonstructs.instance.showModelInfo = false;
                    mModel = null;
                    KerbalKonstructs.instance.selectedModel = null;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            GUILayout.Box(" " + infTitle + " ", GUILayout.Height(20));
            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(1);

            if (infLaunchTransform != "")
            {
                GUILayout.Box("DefaultLaunchPadTransform", BoxNoBorder, GUILayout.Height(19));
                GUILayout.Box("" + infLaunchTransform, BoxNoBorder2);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Length: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infLaunchLength = GUILayout.TextField(infLaunchLength, 5, GUILayout.Width(130), GUILayout.Height(18));
                GUILayout.Label("m", LabelWhite, GUILayout.Width(20));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Width: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infLaunchWidth = GUILayout.TextField(infLaunchWidth, 5, GUILayout.Width(130), GUILayout.Height(18));
                GUILayout.Label("m", LabelWhite, GUILayout.Width(20));
                GUILayout.EndHorizontal();

                GUILayout.Space(1);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(1);
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Mesh: ", LabelGreen);
            GUILayout.FlexibleSpace();
            GUILayout.Label("" + infMesh + ".mu", LabelWhite);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Manufacturer: ", LabelGreen);
            GUILayout.FlexibleSpace();
            GUILayout.Label("" + infManufacturer, LabelWhite);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Author: ", LabelGreen);
            GUILayout.FlexibleSpace();
            GUILayout.Label("" + infAuthor, LabelWhite);
            GUILayout.EndHorizontal();

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(1);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Category: ", LabelGreen);
            GUILayout.FlexibleSpace();
            infCategory = GUILayout.TextField(infCategory, GUILayout.Width(150), GUILayout.Height(18));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Cost: ", LabelGreen);
            GUILayout.FlexibleSpace();
            infCost = GUILayout.TextField(infCost, GUILayout.Width(150), GUILayout.Height(18));
            GUILayout.EndHorizontal();

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(1);

            if (GUILayout.Button("Facility Type: " + infFacType, GUILayout.Height(23)))
                bChangeFacilityType = true;

            if (bChangeFacilityType)
            {
                facilityscroll = GUILayout.BeginScrollView(facilityscroll);
                if (GUILayout.Button("Cancel - No change", GUILayout.Height(23)))
                    bChangeFacilityType = false;

                if (GUILayout.Button("Barracks", GUILayout.Height(23)))
                {
                    infFacType = "Barracks";
                    shouldUpdateSelection = true;
                    bChangeFacilityType = false;
                }

                if (GUILayout.Button("Business", GUILayout.Height(23)))
                {
                    infFacType = "Business";
                    shouldUpdateSelection = true;
                    bChangeFacilityType = false;
                }

                if (GUILayout.Button("Fuel Tanks", GUILayout.Height(23)))
                {
                    infFacType = "FuelTanks";
                    shouldUpdateSelection = true;
                    bChangeFacilityType = false;
                }

                if (GUILayout.Button("Hangar", GUILayout.Height(23)))
                {
                    infFacType = "Hangar";
                    shouldUpdateSelection = true;
                    bChangeFacilityType = false;
                }

                if (GUILayout.Button("Research", GUILayout.Height(23)))
                {
                    infFacType = "Research";
                    shouldUpdateSelection = true;
                    bChangeFacilityType = false;
                }

                if (GUILayout.Button("Tracking Station", GUILayout.Height(23)))
                {
                    infFacType = "TrackingStation";
                    shouldUpdateSelection = true;
                    bChangeFacilityType = false;
                }

                GUILayout.EndScrollView();
            }

            if (infFacType == "Barracks" || infFacType == "Research" || infFacType == "Business")
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Max Staff: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infStaffMax = GUILayout.TextField(infStaffMax, 2, GUILayout.Width(150), GUILayout.Height(18));
                GUILayout.EndHorizontal();
            }

            if (infFacType == "Research" || infFacType == "Business")
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Production Rate: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infProdRateMax = GUILayout.TextField(infProdRateMax, 5, GUILayout.Width(150), GUILayout.Height(18));
                GUILayout.EndHorizontal();

                GUILayout.Label("Amount produced every 12 hours is production rate multiplied by current number of staff.", LabelWhite);
            }

            if (infFacType == "Research")
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Max Science: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infScienceMax = GUILayout.TextField(infScienceMax, 3, GUILayout.Width(150), GUILayout.Height(18));
                GUILayout.EndHorizontal();
            }

            if (infFacType == "Business")
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Max Funds: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infFundsMax = GUILayout.TextField(infFundsMax, 6, GUILayout.Width(150), GUILayout.Height(18));
                GUILayout.EndHorizontal();
            }

            if (infFacType == "FuelTanks")
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Max LiquidFuel: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infLqFMax = GUILayout.TextField(infLqFMax, 6, GUILayout.Width(150), GUILayout.Height(18));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max Oxidizer: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infOxFMax = GUILayout.TextField(infOxFMax, 6, GUILayout.Width(150), GUILayout.Height(18));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max Monoprop: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infMoFMax = GUILayout.TextField(infMoFMax, 6, GUILayout.Width(150), GUILayout.Height(18));
                GUILayout.EndHorizontal();
            }

            if (infFacType == "Hangar")
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Max Craft Mass: ", LabelGreen);
                GUILayout.FlexibleSpace();
                infFacMassCap = GUILayout.TextField(infFacMassCap, 4, GUILayout.Width(130), GUILayout.Height(18));
                GUILayout.Label("T", LabelWhite, GUILayout.Width(20));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max Craft: ", LabelGreen);
                GUILayout.FlexibleSpace();
                GUILayout.Label("" + infFacCraftCap, LabelWhite, GUILayout.Width(30));

                if (GUILayout.Button("1", GUILayout.Width(23), GUILayout.Height(23)))
                {
                    infFacCraftCap = "1";
                    shouldUpdateSelection = true;
                }
                if (GUILayout.Button("2", GUILayout.Width(23), GUILayout.Height(23)))
                {
                    infFacCraftCap = "2";
                    shouldUpdateSelection = true;
                }

                if (GUILayout.Button("3", GUILayout.Width(23), GUILayout.Height(23)))
                {
                    infFacCraftCap = "3";
                    shouldUpdateSelection = true;
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(1);
            GUILayout.Box("Description", BoxNoBorder, GUILayout.Height(19));
            infDescription = GUILayout.TextArea(infDescription, GUILayout.Height(50));

            GUILayout.FlexibleSpace();
            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(1);

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Save", GUILayout.Height(23), GUILayout.Width(120)))
            {
                updateSettings(mModel);
                KerbalKonstructs.instance.saveModelConfig(mModel);
                smessage = "Saved changes to static models config.";
                MiscUtils.HUDMessage(smessage, 10, 2);
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close", GUILayout.Height(23), GUILayout.Width(120)))
            {
                if (currPreview != null)
                    DestroyPreviewInstance(currPreview);

                KerbalKonstructs.instance.showModelInfo = false;
                mModel = null;
                KerbalKonstructs.instance.selectedModel = null;
            }
            GUILayout.EndHorizontal();

            if (currPreview != null)
            {
                GUILayout.Space(1);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(1);

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Delete Preview", GUILayout.Height(23), GUILayout.Width(120)))
                    DestroyPreviewInstance(currPreview);

                GUILayout.FlexibleSpace();

                if (bSpinning)
                {
                    if (GUILayout.Button("Stop Spin", GUILayout.Height(23), GUILayout.Width(120)))
                        bSpinning = false;
                }
                else
                {
                    if (GUILayout.Button("Resume Spin", GUILayout.Height(23), GUILayout.Width(120)))
                        bSpinning = true;
                }

                GUILayout.EndHorizontal();
            }

            if (Event.current.keyCode == KeyCode.Return)
            {
                MiscUtils.HUDMessage("Applied changes to object.", 10, 2);
                shouldUpdateSelection = true;
            }

            if (shouldUpdateSelection)
            {
                updateSettings(mModel);
                updateSelection(mModel);
            }

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(1);

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
        public void importCustomInstances()
        {
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("STATIC");

            foreach (UrlDir.UrlConfig conf in configs)
            {
                StaticModel model = new StaticModel();
                model.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
                model.config = conf.url;
                model.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg";
                model.settings = KKAPI.loadConfig(conf.config, KKAPI.getModelSettings());

                if (!model.settings.ContainsKey("pointername"))
                    continue;

                string sPointerName = (string)model.getSetting("pointername");

                foreach (StaticModel model2 in staticDB.getModels())
                {
                    ConfigNode modelConfig = GameDatabase.Instance.GetConfigNode(model2.config);

                    if ((string)modelConfig.GetValue("name") == sPointerName)
                    {
                        loadInstances(conf.config, model2, true);
                        break;
                    }
                }
            }
        }
        public void updateSelection(StaticModel obj)
        {
            infAuthor = (string)obj.getSetting("author");
            infMesh = "" + obj.getSetting("mesh");
            infManufacturer = (string)obj.getSetting("manufacturer");
            infCost = obj.getSetting("cost").ToString();
            infDescription = (string)obj.getSetting("description");
            infTitle = (string)obj.getSetting("title");
            infCategory = (string)obj.getSetting("category");
            infLaunchTransform = (string)obj.getSetting("DefaultLaunchPadTransform");

            infLaunchLength = obj.getSetting("DefaultLaunchSiteLength").ToString();
            infLaunchWidth = obj.getSetting("DefaultLaunchSiteWidth").ToString();
            infFacType = (string)obj.getSetting("DefaultFacilityType");
            infFacLength = obj.getSetting("DefaultFacilityLength").ToString();
            infFacWidth = obj.getSetting("DefaultFacilityWidth").ToString();
            infFacHeight = obj.getSetting("DefaultFacilityHeight").ToString();
            infFacMassCap = obj.getSetting("DefaultFacilityMassCapacity").ToString();
            infFacCraftCap = obj.getSetting("DefaultFacilityCraftCapacity").ToString();
            infStaffMax = obj.getSetting("DefaultStaffMax").ToString();
            infLqFMax = obj.getSetting("LqFMax").ToString();
            infOxFMax = obj.getSetting("OxFMax").ToString();
            infMoFMax = obj.getSetting("MoFMax").ToString();
            infECMax = obj.getSetting("ECMax").ToString();
            infOreMax = obj.getSetting("OreMax").ToString();
            infPrOreMax = obj.getSetting("PrOreMax").ToString();
            infProdRateMax = obj.getSetting("DefaultProductionRateMax").ToString();
            infScienceMax = obj.getSetting("DefaultScienceOMax").ToString();
            infRepMax = obj.getSetting("DefaultRepOMax").ToString();
            infFundsMax = obj.getSetting("DefaultFundsOMax").ToString();
        }
        public void loadInstances(ConfigNode confconfig, StaticModel model, bool bSecondPass = false)
        {
            if (model == null)
            {
                Debug.Log("KK: Attempting to loadInstances for a null model. Check your model and config.");
                return;
            }

            if (confconfig == null)
            {
                Debug.Log("KK: Attempting to loadInstances for a null ConfigNode. Check your model and config.");
                return;
            }

            foreach (ConfigNode ins in confconfig.GetNodes("Instances"))
            {
                StaticObject obj = new StaticObject();
                obj.model = model;

                obj.gameObject = GameDatabase.Instance.GetModel(model.path + "/" + model.getSetting("mesh"));

                if (obj.gameObject == null)
                {
                    Debug.Log("KK: Could not find " + model.getSetting("mesh") + ".mu! Did the modder forget to include it or did you actually install it?");
                    continue;
                }

                // Fix colliders
                if (!String.IsNullOrEmpty(model.getSetting("concaveColliders").ToString().Trim()))
                {
                    string value = model.getSetting("concaveColliders").ToString();
                    string[] names = value.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    MeshCollider[] colliders = obj.gameObject.GetComponentsInChildren<MeshCollider>(true);
                    MeshCollider[] concave = value.ToLower() == "all" ? colliders : colliders.Where(c => names.Contains(c.name)).ToArray();
                    foreach (MeshCollider collider in concave)
                    {
                        if (DebugMode) Debug.Log("KK: Making collider " + collider.name + " concave.");
                        collider.convex = false;
                    }
                }

                obj.settings = KKAPI.loadConfig(ins, KKAPI.getInstanceSettings());

                if (obj.settings == null)
                {
                    Debug.Log("KK: Error loading instances for " + model.getSetting("mesh") + ".mu! Check your model and config.");
                    continue;
                }

                if (bSecondPass)
                {
                    Vector3 secondInstanceKey = (Vector3)obj.getSetting("RadialPosition");
                    bool bSpaceOccupied = false;

                    foreach (StaticObject soThis in KerbalKonstructs.instance.getStaticDB().getAllStatics())
                    {
                        Vector3 firstInstanceKey = (Vector3)soThis.getSetting("RadialPosition");

                        if (firstInstanceKey == secondInstanceKey)
                        {
                            string sThisMesh = (string)soThis.model.getSetting("mesh");
                            string sThatMesh = (string)obj.model.getSetting("mesh");

                            if (DebugMode)
                                Debug.Log("KK: Custom instance has a RadialPosition that already has an instance."
                                + sThisMesh + ":"
                                + (string)soThis.getSetting("Group") + ":" + firstInstanceKey.ToString() + "|"
                                + sThatMesh + ":"
                                + (string)obj.getSetting("Group") + ":" + secondInstanceKey.ToString());

                            if (sThisMesh == sThatMesh)
                            {
                                float fThisOffset = (float)soThis.getSetting("RadiusOffset");
                                float fThatOffset = (float)obj.getSetting("RadiusOffset");
                                float fThisRotation = (float)soThis.getSetting("RotationAngle");
                                float fThatRotation = (float)obj.getSetting("RotationAngle");

                                if ((fThisOffset == fThatOffset) && (fThisRotation == fThatRotation))
                                {
                                    bSpaceOccupied = true;
                                    break;
                                }
                                else
                                {
                                    if (DebugMode) Debug.Log("KK: Different rotation or offset. Allowing. Could be a feature of the same model such as a doorway being used. Will cause z tearing probably.");
                                }
                            }
                            else
                            {
                                if (DebugMode) Debug.Log("KK: Different models. Allowing. Could be a terrain foundation or integrator.");
                            }
                        }
                    }

                    if (bSpaceOccupied)
                    {
                        Debug.Log("KK: Attempted to import identical custom instance to same RadialPosition as existing instance. Skipped. Check for duplicate custom statics you have installed. Did you export the custom instances to make a pack? If not, ask the mod-makers if they are duplicating the same stuff as each other.");
                        continue;
                    }
                }

                if (!obj.settings.ContainsKey("LaunchPadTransform") && obj.settings.ContainsKey("LaunchSiteName"))
                {
                    if (model.settings.Keys.Contains("DefaultLaunchPadTransform"))
                    {
                        obj.settings.Add("LaunchPadTransform", model.getSetting("DefaultLaunchPadTransform"));
                    }
                    else
                    {
                        Debug.Log("KK: Launch site is missing a transform. Defaulting to " + obj.getSetting("LaunchSiteName") + "_spawn...");

                        if (obj.gameObject.transform.Find(obj.getSetting("LaunchSiteName") + "_spawn") != null)
                        {
                            obj.settings.Add("LaunchPadTransform", obj.getSetting("LaunchSiteName") + "_spawn");
                        }
                        else
                        {
                            Debug.Log("KK: FAILED: " + obj.getSetting("LaunchSiteName") + "_spawn does not exist! Attempting to use any transform with _spawn in the name.");
                            Transform lastResort = obj.gameObject.transform.Cast<Transform>().FirstOrDefault(trans => trans.name.EndsWith("_spawn"));

                            if (lastResort != null)
                            {
                                Debug.Log("KK: Using " + lastResort.name + " as launchpad transform");
                                obj.settings.Add("LaunchPadTransform", lastResort.name);
                            }
                            else
                            {
                                Debug.Log("KK: All attempts at finding a launchpad transform have failed (╯°□°)╯︵ ┻━┻ This static isn't configured for KK properly. Tell the modder.");
                            }
                        }
                    }
                }

                staticDB.addStatic(obj);
                obj.spawnObject(false, false);

                if (obj.settings.ContainsKey("LaunchPadTransform") && obj.settings.ContainsKey("LaunchSiteName"))
                    LaunchSiteManager.createLaunchSite(obj);
            }
        }
        public void updateSettings(StaticModel mModel)
        {
            mModel.setSetting("author", infAuthor);
            mModel.setSetting("manufacturer", infManufacturer);
            mModel.setSetting("cost", float.Parse(infCost));
            mModel.setSetting("description", infDescription);
            mModel.setSetting("title", infTitle);
            mModel.setSetting("category", infCategory);

            if (infFacType != "") mModel.setSetting("DefaultFacilityType", infFacType);

            if (infLaunchLength != "") mModel.setSetting("DefaultLaunchSiteLength", float.Parse(infLaunchLength));
            if (infLaunchWidth != "") mModel.setSetting("DefaultLaunchSiteWidth", float.Parse(infLaunchWidth));
            if (infFacLength != "") mModel.setSetting("DefaultFacilityLength", float.Parse(infFacLength));
            if (infFacWidth != "") mModel.setSetting("DefaultFacilityWidth", float.Parse(infFacWidth));
            if (infFacHeight != "") mModel.setSetting("DefaultFacilityHeight", float.Parse(infFacHeight));
            if (infFacMassCap != "") mModel.setSetting("DefaultFacilityMassCapacity", float.Parse(infFacMassCap));
            if (infFacCraftCap != "") mModel.setSetting("DefaultFacilityCraftCapacity", float.Parse(infFacCraftCap));
            if (infStaffMax != "") mModel.setSetting("DefaultStaffMax", float.Parse(infStaffMax));
            if (infLqFMax != "") mModel.setSetting("LqFMax", float.Parse(infLqFMax));
            if (infOxFMax != "") mModel.setSetting("OxFMax", float.Parse(infOxFMax));
            if (infMoFMax != "") mModel.setSetting("MoFMax", float.Parse(infMoFMax));
            if (infECMax != "") mModel.setSetting("ECMax", float.Parse(infECMax));
            if (infOreMax != "") mModel.setSetting("OreMax", float.Parse(infOreMax));
            if (infPrOreMax != "") mModel.setSetting("PrOreMax", float.Parse(infPrOreMax));
            if (infProdRateMax != "") mModel.setSetting("DefaultProductionRateMax", float.Parse(infProdRateMax));
            if (infScienceMax != "") mModel.setSetting("DefaultScienceOMax", float.Parse(infScienceMax));
            if (infRepMax != "") mModel.setSetting("DefaultRepOMax", float.Parse(infRepMax));
            if (infFundsMax != "") mModel.setSetting("DefaultFundsOMax", float.Parse(infFundsMax));
        }
        public void saveModelConfig(StaticModel mModelToSave)
        {
            foreach (StaticModel model in staticDB.getModels())
            {
                if (model == mModelToSave)
                {
                    ConfigNode staticNode = new ConfigNode("STATIC");
                    ConfigNode modelConfig = GameDatabase.Instance.GetConfigNode(model.config);

                    foreach (KeyValuePair<string, object> modelsetting in model.settings)
                    {
                        if (modelsetting.Key == "mesh") continue;

                        if (modelConfig.HasValue(modelsetting.Key))
                        {
                            modelConfig.RemoveValue(modelsetting.Key);
                            modelConfig.AddValue(modelsetting.Key, KKAPI.getModelSettings()[modelsetting.Key].convertValueToConfig(modelsetting.Value));
                        }
                        else
                        {
                            modelConfig.AddValue(modelsetting.Key, KKAPI.getModelSettings()[modelsetting.Key].convertValueToConfig(modelsetting.Value));
                        }
                    }

                    modelConfig.RemoveNodes("Instances");

                    foreach (StaticObject obj in staticDB.getObjectsFromModel(model))
                    {
                        ConfigNode inst = new ConfigNode("Instances");
                        foreach (KeyValuePair<string, object> setting in obj.settings)
                        {
                            inst.AddValue(setting.Key, KKAPI.getInstanceSettings()[setting.Key].convertValueToConfig(setting.Value));
                        }
                        modelConfig.nodes.Add(inst);
                    }

                    staticNode.AddNode(modelConfig);
                    staticNode.Save(KSPUtil.ApplicationRootPath + "GameData/" + model.configPath, "Generated by Kerbal Konstructs");

                    break;
                }
                else
                    continue;
            }
        }
        public void drawStaticInfoWindow(int WindowID)
        {
            if (mModel == null) return;

            BoxNoBorder = new GUIStyle(GUI.skin.box);
            BoxNoBorder.normal.background = null;
            BoxNoBorder.normal.textColor = Color.white;

            DeadButton = new GUIStyle(GUI.skin.button);
            DeadButton.normal.background = null;
            DeadButton.hover.background = null;
            DeadButton.active.background = null;
            DeadButton.focused.background = null;
            DeadButton.normal.textColor = Color.yellow;
            DeadButton.hover.textColor = Color.white;
            DeadButton.active.textColor = Color.yellow;
            DeadButton.focused.textColor = Color.yellow;
            DeadButton.fontSize = 14;
            DeadButton.fontStyle = FontStyle.Normal;

            DeadButtonRed = new GUIStyle(GUI.skin.button);
            DeadButtonRed.normal.background = null;
            DeadButtonRed.hover.background = null;
            DeadButtonRed.active.background = null;
            DeadButtonRed.focused.background = null;
            DeadButtonRed.normal.textColor = Color.red;
            DeadButtonRed.hover.textColor = Color.yellow;
            DeadButtonRed.active.textColor = Color.red;
            DeadButtonRed.focused.textColor = Color.red;
            DeadButtonRed.fontSize = 12;
            DeadButtonRed.fontStyle = FontStyle.Bold;

            if (currPreview != null)
            {
                double dTicker = Planetarium.GetUniversalTime();
                if ((dTicker - dUpdater) > 0.01)
                {
                    dUpdater = Planetarium.GetUniversalTime();

                    if (bSpinning)
                        SpinPreview(currPreview);
                }
            }

            bool shouldUpdateSelection = false;
            string smessage = "";
            ScreenMessageStyle smsStyle = (ScreenMessageStyle)2;

            GUILayout.BeginHorizontal();
            {
                GUI.enabled = false;
                GUILayout.Button("-KK-", DeadButton, GUILayout.Height(21));

                GUILayout.FlexibleSpace();

                GUILayout.Button("Static Model Config Editor", DeadButton, GUILayout.Height(21));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(21)))
                {
                    if (currPreview != null)
                        DestroyPreviewInstance(currPreview);

                    KerbalKonstructs.instance.showModelInfo = false;
                    mModel = null;
                    KerbalKonstructs.instance.selectedModel = null;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            GUILayout.Box(" " + infTitle + " ");
            GUILayout.Space(3);
            GUILayout.Box("Mesh: " + infMesh + ".mu");

            GUILayout.Box("Manufacturer: " + infManufacturer);
            GUILayout.Box("Author: " + infAuthor);
            GUILayout.Space(3);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Category: ");
            GUILayout.FlexibleSpace();
            infCategory = GUILayout.TextField(infCategory, GUILayout.Width(150));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Cost: ");
            GUILayout.FlexibleSpace();
            infCost = GUILayout.TextField(infCost, GUILayout.Width(150));
            GUILayout.EndHorizontal();

            GUILayout.Label("Description");
            infDescription = GUILayout.TextArea(infDescription, GUILayout.Height(100));

            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Save", GUILayout.Height(23)))
            {
                updateSettings(mModel);
                KerbalKonstructs.instance.saveObjects();
                smessage = "Saved all changes to all static models and instances.";
                ScreenMessages.PostScreenMessage(smessage, 10, smsStyle);
            }
            if (GUILayout.Button("Close", GUILayout.Height(23)))
            {
                if (currPreview != null)
                    DestroyPreviewInstance(currPreview);

                KerbalKonstructs.instance.showModelInfo = false;
                mModel = null;
                KerbalKonstructs.instance.selectedModel = null;
            }
            GUILayout.EndHorizontal();

            if (currPreview != null)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Delete Preview", GUILayout.Height(23)))
                    DestroyPreviewInstance(currPreview);

                if (bSpinning)
                {
                    if (GUILayout.Button("Stop Spin", GUILayout.Height(23)))
                        bSpinning = false;

                }
                else
                {
                    if (GUILayout.Button("Resume Spin", GUILayout.Height(23)))
                        bSpinning = true;
                }

                GUILayout.EndHorizontal();
            }

            if (Event.current.keyCode == KeyCode.Return)
            {
                ScreenMessages.PostScreenMessage("Applied changes to object.", 10, smsStyle);
                shouldUpdateSelection = true;
            }

            if (shouldUpdateSelection)
            {
                updateSettings(mModel);
                updateSelection(mModel);
            }

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }