public override void OnLoad(ConfigNode node) { if (!compatible) { return; } UI_FloatRange f = (UI_FloatRange)(Fields["utilization"].uiControlEditor); f.minValue = minUtilization; f.maxValue = maxUtilization; utilization = Mathf.Clamp(utilization, minUtilization, maxUtilization); if (MFSSettings.tankDefinitions == null) { MFSSettings.Initialize(); } // Load the volume. If totalVolume is specified, use that to calc the volume // otherwise scale up the provided volume. No KSPField support for doubles if (node.HasValue("totalVolume") && double.TryParse(node.GetValue("totalVolume"), out totalVolume)) { ChangeTotalVolume(totalVolume); } else if (node.HasValue("volume") && double.TryParse(node.GetValue("volume"), out volume)) { totalVolume = volume * 100d / utilization; } if (isDatabaseLoad) { MFSSettings.SaveOverrideList(part, node.GetNodes("TANK")); ParseBaseMass(node); ParseBaseCost(node); ParseInsulationFactor(node); typesAvailable = node.GetValues("typeAvailable"); RecordManagedResources(); } else if (isEditorOrFlight) { // The amounts initialized flag is there so that the tank type loading doesn't // try to set up any resources. They'll get loaded directly from the save. UpdateTankType(false); // Destroy any resources still hanging around from the LOADING phase for (int i = part.Resources.Count - 1; i >= 0; --i) { PartResource partResource = part.Resources[i]; if (!tankList.Contains(partResource.resourceName)) { continue; } part.Resources.Remove(partResource.info.id); part.SimulationResources.Remove(partResource.info.id); } RaiseResourceListChanged(); // Setup the mass massDirty = true; CalculateMass(); } OnLoadRF(node); }
public override void OnLoad(ConfigNode node) { if (!compatible) { return; } if (MFSSettings.tankDefinitions == null) { MFSSettings.Initialize(); } // Load the volume. If totalVolume is specified, use that to calc the volume // otherwise scale up the provided volume. No KSPField support for doubles if (node.HasValue("totalVolume") && double.TryParse(node.GetValue("totalVolume"), out totalVolume)) { ChangeTotalVolume(totalVolume); } else if (node.HasValue("volume") && double.TryParse(node.GetValue("volume"), out volume)) { totalVolume = volume * 100 / utilization; } using (PartMessageService.Instance.Ignore(this, null, typeof(PartResourcesChanged))) { if (isDatabaseLoad) { overrideListNodes = node.GetNodes("TANK"); ParseBaseMass(node); ParseBaseCost(node); typesAvailable = node.GetValues("typeAvailable"); RecordManagedResources(); } else if (isEditorOrFlight) { // The amounts initialized flag is there so that the tank type loading doesn't // try to set up any resources. They'll get loaded directly from the save. UpdateTankType(false); // Destroy any resources still hanging around from the LOADING phase for (int i = part.Resources.Count - 1; i >= 0; --i) { PartResource partResource = part.Resources[i]; if (!tankList.Contains(partResource.resourceName)) { continue; } part.Resources.list.RemoveAt(i); DestroyImmediate(partResource); } RaiseResourceListChanged(); // Setup the mass part.mass = mass; MassChanged(mass); } } }
public void GUIWindow(int windowID) { InitializeStyles(); GUILayout.BeginVertical(); GUILayout.Space(20); if (CheckTankList()) { GUILayout.BeginHorizontal(); if (Math.Round(tank_module.AvailableVolume, 4) < 0) { GUILayout.Label("Volume: " + tank_module.volumeDisplay, overfull); } else { GUILayout.Label("Volume: " + tank_module.volumeDisplay); } GUILayout.EndHorizontal(); DisplayMass(); scrollPos = GUILayout.BeginScrollView(scrollPos); GUIEngines(); GUITanks(); GUILayout.EndScrollView(); GUILayout.Label(MFSSettings.GetVersion()); } GUILayout.EndVertical(); if (!(myToolTip.Equals("")) && GUI.tooltip.Equals("")) { if (counterTT > 4) { myToolTip = GUI.tooltip; counterTT = 0; } else { counterTT++; } } else { myToolTip = GUI.tooltip; counterTT = 0; } //print ("GT: " + GUI.tooltip); GUI.DragWindow(); }
private void UpdateTankType(bool initializeAmounts = true) { if (oldType == type || type == null) { return; } // Copy the tank list from the tank definitiion TankDefinition def; if (!MFSSettings.tankDefinitions.Contains(type)) { Debug.LogError("Unable to find tank definition for type \"" + type + "\" reverting."); type = oldType; return; } def = MFSSettings.tankDefinitions[type]; if (!def.canHave) { type = oldType; if (oldType != null && oldType != "") // we have an old type { def = MFSSettings.tankDefinitions[type]; if (def.canHave) { return; // go back to old type } } // else find one that does work foreach (TankDefinition newDef in MFSSettings.tankDefinitions) { if (newDef.canHave) { def = newDef; type = newDef.name; break; } } if (type == oldType) // if we didn't find a new one { Debug.LogError("Unable to find a type that is tech-available for part " + part.name); return; } } oldType = type; // Build the new tank list. tankList = new FuelTankList(); for (int i = 0; i < def.tankList.Count; i++) { FuelTank tank = def.tankList[i]; // Pull the override from the list of overrides ConfigNode overNode = MFSSettings.GetOverrideList(part).FirstOrDefault(n => n.GetValue("name") == tank.name); tankList.Add(tank.CreateCopy(this, overNode, initializeAmounts)); } tankList.TechAmounts(); // update for current techs // Destroy any managed resources that are not in the new type. HashSet <string> managed = MFSSettings.managedResources[part.name]; // if this throws, we have some big fish to fry bool needsMesage = false; for (int i = part.Resources.Count - 1; i >= 0; --i) { PartResource partResource = part.Resources[i]; string resname = partResource.resourceName; if (!managed.Contains(resname) || tankList.Contains(resname)) { continue; } part.Resources.Remove(partResource.info.id); needsMesage = true; } if (needsMesage) { RaiseResourceListChanged(); } if (!basemassOverride) { ParseBaseMass(def.basemass); } if (!baseCostOverride) { ParseBaseCost(def.baseCost); } if (!isDatabaseLoad) { // being called in the SpaceCenter scene is assumed to be a database reload //FIXME is this really needed? massDirty = true; } UpdateTankTypeRF(def); UpdateTestFlight(); }
public override void OnLoad(ConfigNode node) { if (!compatible) { return; } // Make sure this isn't an upgrade node because if we got here during an upgrade application // then RaiseResourceListChanged will throw an error when it hits SendEvent() if (node.name == "CURRENTUPGRADE") { // If there's ever a need for special upgrade handling, put that code here. } else { InitUtilization(); if (MFSSettings.tankDefinitions == null) { MFSSettings.Initialize(); } InitVolume(node); ConfigNode[] unmanagedResourceNodes = node.GetNodes("UNMANAGED_RESOURCE"); //Debug.Log("[ModuleFuelTanks.OnLoad()] " + unmanagedResourceNodes.Count() + " UNMANAGED_RESOURCE nodes found"); for (int i = unmanagedResourceNodes.Count() - 1; i >= 0; --i) { string name = ""; double amount = 0; double maxAmount = 0; // we're going to be strict and demand all of these be present if (!unmanagedResourceNodes[i].HasValue("name") || !unmanagedResourceNodes[i].HasValue("amount") || !unmanagedResourceNodes[i].HasValue("maxAmount")) { Debug.Log("[ModuleFuelTanks.OnLoad()] was missing either name, amount or maxAmount for UNMANAGED_RESOURCE: " + name); continue; } name = unmanagedResourceNodes[i].GetValue("name"); if (PartResourceLibrary.Instance.GetDefinition(name) == null) { Debug.Log("[ModuleFuelTanks.OnLoad()] could not find resource by the name of " + name); continue; } double.TryParse(unmanagedResourceNodes[i].GetValue("amount"), out amount); double.TryParse(unmanagedResourceNodes[i].GetValue("maxAmount"), out maxAmount); amount = Math.Max(amount, 0d); maxAmount = Math.Max(amount, maxAmount); if (!unmanagedResources.ContainsKey(name)) { if (maxAmount > 0) { unmanagedResources.Add(name, new UnmanagedResource(name, amount, maxAmount)); Debug.Log("[ModuleFuelTanks.OnLoad()] added new UnmanagedResource " + name + " with " + amount + "/" + maxAmount); if (!part.Resources.Contains(name)) { ConfigNode resNode = new ConfigNode("RESOURCE"); resNode.AddValue("name", name); resNode.AddValue("amount", amount); resNode.AddValue("maxAmount", maxAmount); part.AddResource(resNode); } } else { Debug.Log("[ModuleFuelTanks.OnLoad()] did not add new UnmanagedResource; maxAmount = 0"); } } else { if (maxAmount > 0) { unmanagedResources[name].amount += amount; unmanagedResources[name].maxAmount += maxAmount; //Debug.Log("[ModuleFuelTanks.OnLoad()] modified UnmanagedResource: " + name + "; amount = " + amount + " / maxAmount = " + maxAmount); // this should be safe; if we're here then we previously would have added this resource if missing. part.Resources[name].amount = Math.Max(part.Resources[name].amount, unmanagedResources[name].amount); part.Resources[name].maxAmount = Math.Max(part.Resources[name].maxAmount, unmanagedResources[name].maxAmount); } else { Debug.Log("[ModuleFuelTanks.OnLoad()] did not add new UnmanagedResource; maxAmount = 0"); } } } if (isDatabaseLoad) { MFSSettings.SaveOverrideList(part, node.GetNodes("TANK")); ParseBaseMass(node); ParseBaseCost(node); ParseInsulationFactor(node); typesAvailable = node.GetValues("typeAvailable"); RecordManagedResources(); } else if (isEditorOrFlight) { // The amounts initialized flag is there so that the tank type loading doesn't // try to set up any resources. They'll get loaded directly from the save. UpdateTankType(false); CleanResources(); // Destroy any resources still hanging around from the LOADING phase for (int i = part.Resources.Count - 1; i >= 0; --i) { PartResource partResource = part.Resources[i]; if (!tankList.Contains(partResource.resourceName) && !unmanagedResources.ContainsKey(partResource.resourceName)) { part.Resources.Remove(partResource.info.id); part.SimulationResources.Remove(partResource.info.id); } } RaiseResourceListChanged(); // Setup the mass massDirty = true; CalculateMass(); } } }
public override void OnLoad(ConfigNode node) { if (!compatible) { return; } UI_FloatRange f = (UI_FloatRange)(Fields["utilization"].uiControlEditor); f.minValue = minUtilization; f.maxValue = maxUtilization; utilization = Mathf.Clamp(utilization, minUtilization, maxUtilization); if (MFSSettings.tankDefinitions == null) { MFSSettings.Initialize(); } // Load the volume. If totalVolume is specified, use that to calc the volume // otherwise scale up the provided volume. No KSPField support for doubles if (node.HasValue("totalVolume") && double.TryParse(node.GetValue("totalVolume"), out totalVolume)) { ChangeTotalVolume(totalVolume); } else if (node.HasValue("volume") && double.TryParse(node.GetValue("volume"), out volume)) { totalVolume = volume * 100d / utilization; } ConfigNode[] unmanagedResourceNodes = node.GetNodes("UNMANAGED_RESOURCE"); Debug.Log("[ModuleFuelTanks.OnLoad()] " + unmanagedResourceNodes.Count() + " UNMANAGED_RESOURCE nodes found"); for (int i = unmanagedResourceNodes.Count() - 1; i >= 0; --i) { string name; double amount = 0; double maxAmount = 0; // we're going to be strict and demand all of these be present if (!unmanagedResourceNodes[i].HasValue("name") || !unmanagedResourceNodes[i].HasValue("amount") || !unmanagedResourceNodes[i].HasValue("maxAmount")) { Debug.Log("[ModuleFuelTanks.OnLoad()] was missing either name, amount or maxAmount"); continue; } name = unmanagedResourceNodes[i].GetValue("name"); if (PartResourceLibrary.Instance.GetDefinition(name) == null) { Debug.Log("[ModuleFuelTanks.OnLoad()] could not find resource by the name of " + name); continue; } double.TryParse(unmanagedResourceNodes[i].GetValue("amount"), out amount); double.TryParse(unmanagedResourceNodes[i].GetValue("maxAmount"), out maxAmount); maxAmount = Math.Max(amount, maxAmount); if (maxAmount > 0 && !unmanagedResources.ContainsKey(name)) { unmanagedResources.Add(name, new UnmanagedResource(name, amount, maxAmount)); Debug.Log("[ModuleFuelTanks.OnLoad()] added new UnmanagedResource " + name + " with " + amount + "/" + maxAmount); } else { Debug.Log("[ModuleFuelTanks.OnLoad()] did not add new UnmanagedResource; maxAmount = 0"); } } if (isDatabaseLoad) { MFSSettings.SaveOverrideList(part, node.GetNodes("TANK")); ParseBaseMass(node); ParseBaseCost(node); ParseInsulationFactor(node); typesAvailable = node.GetValues("typeAvailable"); RecordManagedResources(); } else if (isEditorOrFlight) { // The amounts initialized flag is there so that the tank type loading doesn't // try to set up any resources. They'll get loaded directly from the save. UpdateTankType(false); CleanResources(); // Destroy any resources still hanging around from the LOADING phase for (int i = part.Resources.Count - 1; i >= 0; --i) { PartResource partResource = part.Resources[i]; if (!tankList.Contains(partResource.resourceName) || unmanagedResources.ContainsKey(partResource.resourceName)) { continue; } part.Resources.Remove(partResource.info.id); part.SimulationResources.Remove(partResource.info.id); } RaiseResourceListChanged(); // Setup the mass massDirty = true; CalculateMass(); } OnLoadRF(node); }