private void UpdateFuelInfo(FuelInfo f, string title) { FuelInfo found; if (!usedBy.TryGetValue(f.Label, out found)) { usedBy.Add(f.Label, f); } else if (!found.names.Contains(title)) { found.names += ", " + title; } }
internal void ConfigureFor(FuelInfo fi) { if (fi.ratioFactor == 0.0 || fi.efficiency == 0) // can't configure for this engine { return; } double availableVolume = AvailableVolume; foreach (Propellant tfuel in fi.propellants) { if (PartResourceLibrary.Instance.GetDefinition(tfuel.name).resourceTransferMode != ResourceTransferMode.NONE) { FuelTank tank; if (tankList.TryGet(tfuel.name, out tank)) { double amt = availableVolume * tfuel.ratio / fi.efficiency; tank.maxAmount += amt; tank.amount += amt; } } } GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); }
public void UpdateUsedBy() { log.dbg("Updating UsedBy"); usedBy.Clear(); // Get part list List <Part> parts; if (HighLogic.LoadedSceneIsEditor && EditorLogic.fetch.ship != null) { parts = EditorLogic.fetch.ship.parts; } else if (HighLogic.LoadedSceneIsFlight && vessel != null) { parts = vessel.parts; } else { parts = new List <Part>(); } FuelInfo f; string title; PartModule m; for (int i = 0; i < parts.Count; ++i) { title = parts[i].partInfo.title; for (int j = 0; j < parts[i].Modules.Count; ++j) { m = parts[i].Modules[j]; if (m is ModuleEngines) { f = new FuelInfo((m as ModuleEngines).propellants, this, title); if (f.ratioFactor > 0d) { UpdateFuelInfo(f, title); } } else if (m is ModuleRCS) { f = new FuelInfo((m as ModuleRCS).propellants, this, title); if (f.ratioFactor > 0d) { UpdateFuelInfo(f, title); } } } } // Need to update the tweakable menu too if (HighLogic.LoadedSceneIsEditor) { Events.RemoveAll(button => button.name.StartsWith("MFT")); bool activeEditor = (AvailableVolume >= 0.001); int idx = 0; foreach (FuelInfo info in usedBy.Values) { KSPEvent kspEvent = new KSPEvent { name = "MFT" + idx++, guiActive = false, guiActiveEditor = activeEditor, guiName = info.Label }; FuelInfo info1 = info; BaseEvent button = new BaseEvent(Events, kspEvent.name, () => ConfigureFor(info1), kspEvent) { guiActiveEditor = activeEditor }; Events.Add(button); } MarkWindowDirty(); } }