Beispiel #1
0
        private void InitializeFuelSelector()
        {
            Debug.Log("[KSPI]: InitializeFuelSelector Setup Fuels Configurations for " + part.partInfo.title);

            var chooseField = Fields["selectedFuel"];

            chooseOptionEditor = chooseField.uiControlEditor as UI_ChooseOption;
            chooseOptionFlight = chooseField.uiControlFlight as UI_ChooseOption;

            Debug.Log("[KSPI]: InitializeFuelSelector call ActiveConfigurations hideEmpty = " + hideEmpty);
            _activeConfigurations = ActiveConfigurations;

            if (_activeConfigurations.Count <= 1)
            {
                chooseField.guiActive       = false;
                chooseField.guiActiveEditor = false;
                selectedFuel     = 0;
                selectedTankName = "";
            }
            else
            {
                chooseField.guiActive       = true;
                chooseField.guiActiveEditor = true;

                Debug.Log("[KSPI]: InitializeFuelSelector Looking for config # " + selectedTankName);
                _currentActiveConfiguration = _activeConfigurations.FirstOrDefault(m => m.ConfigName == selectedTankName);

                if (_currentActiveConfiguration != null)
                {
                    selectedFuel = _activeConfigurations.IndexOf(_currentActiveConfiguration);
                    Debug.Log("[KSPI]: InitializeFuelSelector Found config # " + selectedTankName + " with index " + selectedFuel);
                }
                else if (_activeConfigurations.Count > 0)
                {
                    selectedFuel = 0;
                    Debug.Log("[KSPI]: InitializeFuelSelector Selecting fuel index # " + selectedFuel);
                    _currentActiveConfiguration = _activeConfigurations[selectedFuel];
                    selectedTankName            = _currentActiveConfiguration.fuelConfigurationName;
                }
            }

            var names = _activeConfigurations.Select(m => m.fuelConfigurationName).ToArray();

            if (chooseOptionEditor != null)
            {
                chooseOptionEditor.options = names;
            }

            if (chooseOptionFlight != null)
            {
                chooseOptionFlight.options = names;
            }

            // connect on change event
            if (chooseField.guiActive && chooseOptionFlight != null)
            {
                chooseOptionFlight.onFieldChanged = UpdateFlightGUI;
            }
            if (chooseField.guiActiveEditor && chooseOptionEditor != null)
            {
                chooseOptionEditor.onFieldChanged = UpdateEditorGUI;
            }
            _currentActiveConfiguration = _activeConfigurations[selectedFuel];
        }