private void UpdateUsedBy()
        {
            //print ("*RK* Updating UsedBy");

            usedBy.Clear();

            List <Part> enginesList = GetEnginesFedBy(part);

            engineCount = enginesList.Count;

            foreach (Part engine in enginesList)
            {
                foreach (PartModule engine_module in engine.Modules)
                {
                    List <Propellant> propellants = GetEnginePropellants(engine_module);
                    if ((object)propellants != null)
                    {
                        FuelInfo f = new FuelInfo(propellants, this, engine.partInfo.title);
                        if (f.ratioFactor > 0.0)
                        {
                            FuelInfo found;
                            if (!usedBy.TryGetValue(f.Label, out found))
                            {
                                usedBy.Add(f.Label, f);
                            }
                            else if (!found.names.Contains(engine.partInfo.title))
                            {
                                found.names += ", " + engine.partInfo.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();
            }
        }
        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;
                    }
                }
            }
        }
        public void UpdateUsedBy()
        {
            //print ("*RK* 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 ();
            }
        }
 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;
                    }
                }
            }
        }
        public void UpdateUsedBy()
        {
            //print ("*RK* 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 ();
            }
        }