示例#1
0
 internal void InitializeAvailableResources()
 {
     if (availableResources == null)
     {
         availableResources = SwitchableResourceSet.ForPart(part.name);
     }
 }
示例#2
0
        /// <summary>
        /// Here when the part we're on was loaded on a ship in the editor, on initial vessel
        /// rollout, or when switching to a vessel.
        /// </summary>
        private void OnShipLoaded()
        {
            // This is needed because in certain circumstances (it's complicated, depends on the
            // precise sequence of building, saving, loading, launching, etc.), then when the ship
            // is loaded, it adds all the "missing" default resources even though the saved ship
            // doesn't actually contain them. So we need to do a scan through all the parts on the
            // ship, and for any that have ModuleSimpleFuelSwitch on them, check the resources
            // and remove any that don't belong based on the currently selected resource option.

            // To reproduce the case that needs this:
            // 1. create a ship in the editor
            // 2. switch some part so that some of the default resources aren't there anymore
            //    (e.g. a normally LFO part switches to have, say, LF-only)
            // 3. save the ship
            // 4. new
            // 5. load the ship.  Bingo, it has the extra resources in it.
            // 6. launch the ship. Bingo, it has the extra resources in it.

            // This function finds and strips out those unwanted "extra" resources.
            InitializeAvailableResources();
            if (currentResourcesId == DEFAULT_FLAG)
            {
                currentResourcesId = availableResources.DefaultResourcesId;
            }

            SwitchableResourceSet.UpdatePartResourceList(part, currentResourcesId, false);
        }
示例#3
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);
                    }
                }
            }
        }