Example #1
0
 /// <summary>
 /// Here when a ship loads in the editor or rolling out to the launchpad.
 /// </summary>
 /// <param name="ship"></param>
 internal static void OnShipLoaded(ShipConstruct ship)
 {
     for (int i = 0; i < ship.parts.Count; ++i)
     {
         Part part = ship.parts[i];
         ModuleSimpleFuelSwitch module = TryFind(part);
         if (module != null)
         {
             module.OnShipLoaded();
         }
     }
 }
Example #2
0
 /// <summary>
 /// Here when a vessel is loaded in flight.
 /// </summary>
 /// <param name="vessel"></param>
 internal static void OnVesselLoaded(Vessel vessel)
 {
     for (int i = 0; i < vessel.parts.Count; ++i)
     {
         Part part = vessel.parts[i];
         ModuleSimpleFuelSwitch module = TryFind(part);
         if (module != null)
         {
             module.OnShipLoaded();
         }
     }
 }
Example #3
0
 /// <summary>
 /// Try to find the first ModuleSimpleFuelSwitch on the part, or null if not found.
 /// </summary>
 /// <param name="part"></param>
 /// <returns></returns>
 internal static ModuleSimpleFuelSwitch TryFind(Part part)
 {
     if (part == null)
     {
         return(null);
     }
     for (int i = 0; i < part.Modules.Count; ++i)
     {
         ModuleSimpleFuelSwitch module = part.Modules[i] as ModuleSimpleFuelSwitch;
         if (module != null)
         {
             return(module);
         }
     }
     return(null); // not found
 }
Example #4
0
        /// <summary>
        /// Here when we need to set up the resources on a part (i.e. when first initializing, or
        /// when the player changes it by clicking the button).
        /// </summary>
        /// <param name="affectSymCounterparts"></param>
        private void UpdateSelectedResources(bool affectSymCounterparts)
        {
            InitializeAvailableResources();

            if (currentResourcesId == DEFAULT_FLAG)
            {
                currentResourcesId = availableResources.DefaultResourcesId;
            }
            SwitchableResourceSet.Selection selection = SwitchableResourceSet.UpdatePartResourceList(part, currentResourcesId, true);

            if (selection == null)
            {
                return;
            }

            // Set the name displayed in the PAW.
            SwitchResourcesEvent.guiName = string.Format(
                "{0}: {1}",
                availableResources.selectorFieldName,
                selection.displayName);

            // Also adjust any symmetry counterparts.
            if (affectSymCounterparts)
            {
                for (int i = 0; i < part.symmetryCounterparts.Count; ++i)
                {
                    Part symCounterpart = part.symmetryCounterparts[i];
                    ModuleSimpleFuelSwitch switchModule = TryFind(symCounterpart);
                    if (switchModule != null)
                    {
                        switchModule.currentResourcesId = currentResourcesId;
                        switchModule.UpdateSelectedResources(false);
                    }
                }
            }
        }