コード例 #1
0
        public override void OnLoad(ConfigNode node)
        // public new void Load(ConfigNode node)
        {
            Debug.Log($"[KSPI Beam Generator] Load()ing");

            _beamConfigurationNodes = node.GetNodes("BeamConfiguration");

            if (!_beamConfigurationNodes.Any())
            {
                Debug.Log("[KSPI]: OnLoad Found no BeamConfigurations - something is broken.");
                return;
            }

            var inlineConfigurations = new List <BeamConfiguration>();

            foreach (var beamConfigurationNode in _beamConfigurationNodes)
            {
                var beamConfiguration = new BeamConfiguration(beamConfigurationNode, part.partInfo.title);
                if (beamConfiguration.IsValid)
                {
                    inlineConfigurations.Add(beamConfiguration);
                }
                else
                {
                    Debug.Log($"[KSPI]: OnLoad discarding BeamConfiguration of {beamConfiguration.beamWaveName} / {beamConfiguration.TechLevel}, it is not valid.");
                }
            }

            _inlineConfigurations = inlineConfigurations.OrderByDescending(m => m.wavelength).ToList();
        }
コード例 #2
0
        /// <summary>
        /// Called whenever chooseOption is changed by user
        /// </summary>
        /// <param name="field"></param>
        /// <param name="oldFieldValueObj"></param>
        private void UpdateFromGUI(BaseField field, object oldFieldValueObj)
        {
            Debug.Log("[KSPI]: BeamGenerator UpdateFromGUI called");

            if (!BeamConfigurations.Any())
            {
                Debug.LogWarning("[KSPI]: BeamGenerator UpdateFromGUI no BeamConfigurations found");
                return;
            }

            if (isLoaded == false)
            {
                LoadInitialConfiguration();
            }
            else
            {
                if (selectedBeamConfiguration < BeamConfigurations.Count)
                {
                    _activeConfiguration = BeamConfigurations[selectedBeamConfiguration];
                }
                else
                {
                    Debug.LogWarning("[KSPI]: selectedBeamConfiguration < " + BeamConfigurations.Count + ", selecting last");
                    selectedBeamConfiguration = BeamConfigurations.Count - 1;
                    _activeConfiguration      = BeamConfigurations.Last();
                }
            }

            if (_activeConfiguration == null)
            {
                Debug.Log("[KSPI]: UpdateFromGUI no activeConfiguration found");
                return;
            }

            beamWaveName   = _activeConfiguration.beamWaveName;
            wavelength     = _activeConfiguration.wavelength;
            wavelengthText = WavelengthToText(wavelength);
            atmosphericAbsorptionPercentage = _activeConfiguration.atmosphericAbsorptionPercentage;
            waterAbsorptionPercentage       = _activeConfiguration.waterAbsorptionPercentage;

            UpdateEfficiencyPercentage();

            // synchronize with receiver;
            if (_transmitter != null && _transmitter.PartReceiver != null)
            {
                Debug.Log("[KSPI]: Called SetActiveBandwidthConfigurationByWaveLength with wavelength " + wavelength);
                _transmitter.PartReceiver.SetActiveBandwidthConfigurationByWaveLength(wavelength);
            }
            //else
            //{
            //    Debug.Log("[KSPI]: No transmitter found ");
            //}
        }
コード例 #3
0
        private void LoadInitialConfiguration()
        {
            isLoaded = true;

            if (!string.IsNullOrEmpty(beamWaveName))
            {
                _activeConfiguration = BeamConfigurations.FirstOrDefault(m => String.Equals(m.beamWaveName, beamWaveName, StringComparison.CurrentCultureIgnoreCase));
                if (_activeConfiguration != null)
                {
                    selectedBeamConfiguration = BeamConfigurations.IndexOf(_activeConfiguration);
                    wavelength = _activeConfiguration.wavelength;
                    return;
                }
            }

            var currentWavelength = wavelength != 0 ? wavelength : 1;

            _activeConfiguration = BeamConfigurations.FirstOrDefault();

            selectedBeamConfiguration = 0;

            if (BeamConfigurations.Count <= 1 || _activeConfiguration == null)
            {
                return;
            }

            var lowestWavelengthDifference = Math.Abs(currentWavelength - _activeConfiguration.wavelength);

            foreach (var currentConfig in BeamConfigurations)
            {
                var configWaveLengthDifference = Math.Abs(currentWavelength - currentConfig.wavelength);

                if (!(configWaveLengthDifference < lowestWavelengthDifference))
                {
                    continue;
                }

                _activeConfiguration       = currentConfig;
                lowestWavelengthDifference = configWaveLengthDifference;
                selectedBeamConfiguration  = BeamConfigurations.IndexOf(currentConfig);
            }
        }
コード例 #4
0
        private void InitializeWavelengthSelector()
        {
            Debug.Log("[KSPI]: Setup Transmit Beams Configurations for " + part.partInfo.title);

            _chooseField           = Fields[nameof(selectedBeamConfiguration)];
            _chooseField.guiActive = BeamConfigurations.Count > 1 && (HighLogic.CurrentGame.Parameters.CustomParams <KITGamePlayParams>().ReconfigureAntennas || canSwitchWavelengthInFlight);

            var chooseOptionEditor = _chooseField.uiControlEditor as UI_ChooseOption;
            var chooseOptionFlight = _chooseField.uiControlFlight as UI_ChooseOption;

            var names = BeamConfigurations.Select(m => m.beamWaveName).ToArray();

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

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

            if (!string.IsNullOrEmpty(beamWaveName))
            {
                _activeConfiguration = BeamConfigurations.FirstOrDefault(m => String.Equals(m.beamWaveName, beamWaveName, StringComparison.CurrentCultureIgnoreCase));
                if (_activeConfiguration != null)
                {
                    selectedBeamConfiguration = BeamConfigurations.IndexOf(_activeConfiguration);
                    wavelength = _activeConfiguration.wavelength;
                    return;
                }
            }

            if (wavelength != 0)
            {
                // find first wavelength with equal or shorter wavelength
                _activeConfiguration = BeamConfigurations.FirstOrDefault(m => m.wavelength <= wavelength);

                if (_activeConfiguration == null)
                {
                    _activeConfiguration = selectedBeamConfiguration < BeamConfigurations.Count ? BeamConfigurations[selectedBeamConfiguration] : BeamConfigurations.FirstOrDefault();
                }

                if (_activeConfiguration != null)
                {
                    selectedBeamConfiguration = BeamConfigurations.IndexOf(_activeConfiguration);
                }
            }

            UpdateFromGUI(_chooseField, selectedBeamConfiguration);

            // connect on change event
            if (chooseOptionEditor != null)
            {
                chooseOptionEditor.onFieldChanged = UpdateFromGUI;
            }
            if (chooseOptionFlight != null)
            {
                chooseOptionFlight.onFieldChanged = UpdateFromGUI;
            }
        }