예제 #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary> Updates the given part with all upgrades provided in "upgradesToApply".</summary>
        ///
        /// <exception cref="Exception"> Thrown when an exception error condition occurs.</exception>
        ///
        /// <param name="part">				 The part.</param>
        /// <param name="upgrades_to_apply"> The upgrades to apply.</param>
        public static void UpdatePart(Part part, PartUpgrades upgrades_to_apply)
        {
            try {
                // Find all relevant modules of this part:
                var rnd_module = PartStats.GetKRnDModule(part);
                if (rnd_module == null)
                {
                    return;
                }
                if (upgrades == null)
                {
                    throw new Exception("upgrades-dictionary missing");
                }
                if (originalStats == null)
                {
                    throw new Exception("original-stats-dictionary missing");
                }

                // Get the part-name ("):
                var part_name = SanitizePartName(part.name);

                // Get the original part-stats:
                if (!originalStats.TryGetValue(part_name, out var original_stats))
                {
                    throw new Exception("no original-stats for part '" + part_name + "'");
                }

                /*
                 * Updates the part to match the upgrade levels specified in the upgrades_to_apply parameter. This provides the hard
                 * link between the ValueConstants class, the upgrade level field in PartUpgrades class, and the algorithm to actually
                 * update the part -- sometimes the algorithm is simple, but could be more complex such as with ISP efficiency
                 * curves.
                 */
                foreach (var u in ValueConstants.upgradeDatabase)
                {
                    if (u.Value.applyUpgradeFunction != null)
                    {
                        u.Value.applyUpgradeFunction(u.Value, part, original_stats, upgrades_to_apply);
                    }
                    else
                    {
                        if (u.Key == StringConstants.ISP_VAC)
                        {
                            UpdateISPVacAtm(ValueConstants.GetData(StringConstants.ISP_VAC), ValueConstants.GetData(StringConstants.ISP_ATM), part, original_stats, upgrades_to_apply);
                        }
                    }
                }

#if false
                UpdateDryMass(ValueConstants.GetData(StringConstants.DRY_MASS), part, original_stats, upgrades_to_apply);
                UpdateMaxTemperature(ValueConstants.GetData(StringConstants.MAX_TEMPERATURE), part, original_stats, upgrades_to_apply);
                UpdateFuelFlow(ValueConstants.GetData(StringConstants.FUEL_FLOW), part, original_stats, upgrades_to_apply);
                UpdateISPVacAtm(ValueConstants.GetData(StringConstants.ISP_VAC), ValueConstants.GetData(StringConstants.ISP_ATM), part, original_stats, upgrades_to_apply);
                UpdateTorque(ValueConstants.GetData(StringConstants.TORQUE), part, original_stats, upgrades_to_apply);
                UpdateChargeRate(ValueConstants.GetData(StringConstants.CHARGE_RATE), part, original_stats, upgrades_to_apply);
                UpdateCrashTolerance(ValueConstants.GetData(StringConstants.CRASH_TOLERANCE), part, original_stats, upgrades_to_apply);
                UpdateBatteryCharge(ValueConstants.GetData(StringConstants.BATTERY_CHARGE), part, original_stats, upgrades_to_apply);
                UpdateGeneratorEfficiency(ValueConstants.GetData(StringConstants.GENERATOR_EFFICIENCY), part, original_stats, upgrades_to_apply);
                UpdateConverterEfficiency(ValueConstants.GetData(StringConstants.CONVERTER_EFFICIENCY), part, original_stats, upgrades_to_apply);
                UpdateAntennaPower(ValueConstants.GetData(StringConstants.ANTENNA_POWER), part, original_stats, upgrades_to_apply);
                UpdatePacketSize(ValueConstants.GetData(StringConstants.PACKET_SIZE), part, original_stats, upgrades_to_apply);
                UpdateDataStorage(ValueConstants.GetData(StringConstants.DATA_STORAGE), part, original_stats, upgrades_to_apply);
                UpdateParachuteStrength(ValueConstants.GetData(StringConstants.PARACHUTE_STRENGTH), part, original_stats, upgrades_to_apply);
                UpdateResourceHarvester(ValueConstants.GetData(StringConstants.RESOURCE_HARVESTER), part, original_stats, upgrades_to_apply);
                UpdateFuelCapacity(ValueConstants.GetData(StringConstants.FUEL_CAPACITY), part, original_stats, upgrades_to_apply);
                UpdateActiveRadiator(ValueConstants.GetData(StringConstants.ENERGY_TRANSFER), part, original_stats, upgrades_to_apply);
                UpdateElConverter(ValueConstants.GetData(StringConstants.EL_CONVERTER), part, original_stats, upgrades_to_apply);
#endif


                /*
                 * Update the RnD module to reflect the upgrades specified.
                 */
                rnd_module.ApplyUpgrades(upgrades_to_apply);
            } catch (Exception e) {
                Debug.LogError("[KRnD] updatePart(" + part.name + "): " + e);
            }
        }
예제 #2
0
파일: KRnDUI.cs 프로젝트: JoeBostic/KRnD
        private void OnWindow(int window_id)
        {
            try {
                GUILayout.BeginVertical();

                // Get all modules of the selected part:
                var                            part_title               = "";
                Part                           part                     = null;
                KRnDModule                     rnd_module               = null;
                List <ModuleEngines>           engine_modules           = null;
                ModuleRCS                      rcs_module               = null;
                ModuleReactionWheel            reaction_wheel_module    = null;
                ModuleDeployableSolarPanel     solar_panel_module       = null;
                ModuleWheelBase                landing_leg_module       = null;
                PartResource                   electric_charge_resource = null;
                ModuleGenerator                generator_module         = null;
                PartModule                     fission_generator        = null;
                List <ModuleResourceConverter> converter_modules        = null;
                ModuleParachute                parachute_module         = null;
                ModuleDataTransmitter          antenna_module           = null;
                ModuleScienceLab               science_lab              = null;
                List <PartResource>            fuel_resources           = null;
                ModuleResourceHarvester        harvester_module         = null;
                ModuleActiveRadiator           radiator_module          = null;
                ELConverter                    el_converter             = null;


                if (selectedPart != null)
                {
                    foreach (var a_part in PartLoader.LoadedPartsList)
                    {
                        if (a_part.partPrefab.name == selectedPart.name)
                        {
                            part       = a_part.partPrefab;
                            part_title = a_part.title;
                            break;
                        }
                    }

                    if (part)
                    {
                        antenna_module           = PartStats.GetModuleDataTransmitter(part);
                        science_lab              = PartStats.GetModuleScienceLab(part);
                        rnd_module               = PartStats.GetKRnDModule(part);
                        engine_modules           = PartStats.GetModuleEnginesList(part);
                        rcs_module               = PartStats.GetModuleRCS(part);
                        reaction_wheel_module    = PartStats.GetModuleReactionWheel(part);
                        solar_panel_module       = PartStats.GetModuleDeployableSolarPanel(part);
                        landing_leg_module       = PartStats.GetModuleWheelBase(part);
                        electric_charge_resource = PartStats.GetElectricCharge(part);
                        generator_module         = PartStats.GetModuleGenerator(part);
                        fission_generator        = PartStats.GetFissionGenerator(part);
                        converter_modules        = PartStats.GetModuleResourceConverterList(part);
                        parachute_module         = PartStats.GetModuleParachute(part);
                        fuel_resources           = PartStats.GetFuelResources(part);
                        harvester_module         = PartStats.GetModuleResourceHarvester(part);
                        radiator_module          = PartStats.GetModuleActiveRadiator(part);
                        el_converter             = PartStats.GetModuleElConverter(part);
                    }
                }

                if (!part)
                {
                    // No part selected:
                    GUILayout.BeginArea(new Rect(10, 5, _windowStyle.fixedWidth, 20));
                    GUILayout.Label("<b>Kerbal R&D: Select a part to improve</b>", _labelStyle);
                    GUILayout.EndArea();
                    GUILayout.EndVertical();
                    GUI.DragWindow();
                    return;
                }

                if (!rnd_module)
                {
                    // Invalid part selected:
                    GUILayout.BeginArea(new Rect(10, 5, _windowStyle.fixedWidth, 20));
                    GUILayout.Label("<b>Kerbal R&D: Select a different part to improve</b>", _labelStyle);
                    GUILayout.EndArea();
                    GUILayout.EndVertical();
                    GUI.DragWindow();
                    return;
                }

                // Get stats of the current version of the selected part:
                if (!KRnD.upgrades.TryGetValue(part.name, out var current_upgrade))
                {
                    current_upgrade = new PartUpgrades();
                }
                var current_info = BuildPartInfoString(part, current_upgrade);

                // Create a copy of the part-stats which we can use to mock an upgrade further below:
                var next_upgrade = current_upgrade.Clone();

                // Title:
                GUILayout.BeginArea(new Rect(10, 5, _windowStyle.fixedWidth, 20));
                var version = rnd_module.GetVersion();
                if (version != "")
                {
                    version = " - " + version;
                }
                GUILayout.Label("<b>" + part_title + version + "</b>", _labelStyle);
                GUILayout.EndArea();

                // List with upgrade-options:
                float options_width  = 100;
                var   options_height = _windowStyle.fixedHeight - 30 - 30 - 20;
                GUILayout.BeginArea(new Rect(10, 30 + 20, options_width, options_height));


                GUILayout.BeginVertical();

                var options = new List <string> {
                    "Dry Mass", "Max Temp"
                };
                if (engine_modules != null || rcs_module)
                {
                    options.Add("ISP Vac");
                    options.Add("ISP Atm");
                    options.Add("Fuel Flow");
                }

                if (antenna_module != null)
                {
                    options.Add("Antenna Power");
                }
                if (antenna_module != null && antenna_module.antennaType != AntennaType.INTERNAL)
                {
                    options.Add("Packet Size");
                }
                if (science_lab != null)
                {
                    options.Add("Data Storage");
                }

                if (reaction_wheel_module != null)
                {
                    options.Add("Torque");
                }
                if (solar_panel_module != null)
                {
                    options.Add("Charge Rate");
                }
                if (landing_leg_module != null)
                {
                    options.Add("Crash Tolerance");
                }
                if (electric_charge_resource != null)
                {
                    options.Add("Battery");
                }
                //if (fuel_resources != null) options.Add("Fuel Pressure");
                if (generator_module || fission_generator)
                {
                    options.Add("Generator");
                }
                if (converter_modules != null)
                {
                    options.Add("Converter");
                }
                if (parachute_module)
                {
                    options.Add("Parachute");
                }
                if (harvester_module)
                {
                    options.Add("Harvester");
                }
                if (radiator_module)
                {
                    options.Add("Radiator");
                }
                if (el_converter)
                {
                    options.Add("EL Converter");
                }

                if (_selectedUpgradeOption >= options.Count)
                {
                    _selectedUpgradeOption = 0;
                }
                _selectedUpgradeOption = GUILayout.SelectionGrid(_selectedUpgradeOption, options.ToArray(), 1, _buttonStyle);

                GUILayout.EndVertical();

                GUILayout.EndArea();

                var              selected_upgrade_option = options.ToArray()[_selectedUpgradeOption];
                int              current_upgrade_level;
                int              next_upgrade_level;
                int              science_cost;
                float            current_improvement_factor;
                float            next_improvement_factor;
                UpgradeConstants u_constants;

                if (!KRnD.originalStats.TryGetValue(part.name, out var original_stats))
                {
                    throw new Exception("no original-stats for part '" + part.name + "'");
                }

                //Func<PartUpgrades, int> improve_function;
                if (selected_upgrade_option == "ISP Vac")
                {
                    //improve_function = KRnD.ImproveIspVac;
                    current_upgrade_level      = current_upgrade.ispVac;
                    next_upgrade_level         = ++next_upgrade.ispVac;
                    u_constants                = ValueConstants.GetData(StringConstants.ISP_VAC);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.ispVac);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.ispVac);
                    science_cost               = u_constants.CalculateScienceCost(0, next_upgrade.ispVac);
                }
                else if (selected_upgrade_option == "ISP Atm")
                {
                    //improve_function = KRnD.ImproveIspAtm;
                    current_upgrade_level      = current_upgrade.ispAtm;
                    next_upgrade_level         = ++next_upgrade.ispAtm;
                    u_constants                = ValueConstants.GetData(StringConstants.ISP_ATM);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.ispAtm);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.ispAtm);
                    science_cost               = u_constants.CalculateScienceCost(0, next_upgrade.ispAtm);
                }
                else if (selected_upgrade_option == "Fuel Flow")
                {
                    //improve_function = KRnD.ImproveFuelFlow;
                    current_upgrade_level      = current_upgrade.fuelFlow;
                    next_upgrade_level         = ++next_upgrade.fuelFlow;
                    u_constants                = ValueConstants.GetData(StringConstants.FUEL_FLOW);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.fuelFlow);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.fuelFlow);
                    science_cost               = u_constants.CalculateScienceCost(0, next_upgrade.fuelFlow);
                }
                else if (selected_upgrade_option == "Dry Mass")
                {
                    //improve_function = KRnD.ImproveDryMass;
                    current_upgrade_level      = current_upgrade.dryMass;
                    next_upgrade_level         = ++next_upgrade.dryMass;
                    u_constants                = ValueConstants.GetData(StringConstants.DRY_MASS);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.dryMass);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.dryMass);
                    science_cost               = u_constants.CalculateScienceCost(original_stats.dryMass, next_upgrade.dryMass);
                }
                else if (selected_upgrade_option == "Torque")
                {
                    //improve_function = KRnD.ImproveTorque;
                    current_upgrade_level      = current_upgrade.torqueStrength;
                    next_upgrade_level         = ++next_upgrade.torqueStrength;
                    u_constants                = ValueConstants.GetData(StringConstants.TORQUE);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.torqueStrength);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.torqueStrength);
                    science_cost               = u_constants.CalculateScienceCost(original_stats.torqueStrength, next_upgrade.torqueStrength);
                }
                else if (selected_upgrade_option == "Antenna Power")
                {
                    //improve_function = KRnD.ImproveAntennaPower;
                    current_upgrade_level      = current_upgrade.antennaPower;
                    next_upgrade_level         = ++next_upgrade.antennaPower;
                    u_constants                = ValueConstants.GetData(StringConstants.ANTENNA_POWER);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.antennaPower);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.antennaPower);
                    science_cost               = u_constants.CalculateScienceCost((float)original_stats.antennaPower, next_upgrade.antennaPower);
                }
                else if (selected_upgrade_option == "Packet Size")
                {
                    //improve_function = KRnD.ImprovePacketSize;
                    current_upgrade_level      = current_upgrade.packetSize;
                    next_upgrade_level         = ++next_upgrade.packetSize;
                    u_constants                = ValueConstants.GetData(StringConstants.PACKET_SIZE);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.packetSize);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.packetSize);
                    science_cost               = u_constants.CalculateScienceCost(original_stats.packetSize, next_upgrade.packetSize);
                }
                else if (selected_upgrade_option == "Data Storage")
                {
                    //improve_function = KRnD.ImproveDataStorage;
                    current_upgrade_level      = current_upgrade.dataStorage;
                    next_upgrade_level         = ++next_upgrade.dataStorage;
                    u_constants                = ValueConstants.GetData(StringConstants.DATA_STORAGE);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.dataStorage);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.dataStorage);
                    science_cost               = u_constants.CalculateScienceCost(original_stats.dataStorage, next_upgrade.dataStorage);
                }
                else if (selected_upgrade_option == "Harvester")
                {
                    //improve_function = KRnD.ImproveResourceHarvester;
                    current_upgrade_level      = current_upgrade.resourceHarvester;
                    next_upgrade_level         = ++next_upgrade.resourceHarvester;
                    u_constants                = ValueConstants.GetData(StringConstants.RESOURCE_HARVESTER);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.resourceHarvester);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.resourceHarvester);
                    science_cost               = u_constants.CalculateScienceCost(original_stats.resourceHarvester, next_upgrade.resourceHarvester);
                }
                else if (selected_upgrade_option == "Radiator")
                {
                    //improve_function = KRnD.ImproveActiveRadiator;
                    current_upgrade_level      = current_upgrade.maxEnergyTransfer;
                    next_upgrade_level         = ++next_upgrade.maxEnergyTransfer;
                    u_constants                = ValueConstants.GetData(StringConstants.ENERGY_TRANSFER);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.maxEnergyTransfer);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.maxEnergyTransfer);
                    science_cost               = u_constants.CalculateScienceCost((float)original_stats.maxEnergyTransfer, next_upgrade.maxEnergyTransfer);
                }
                else if (selected_upgrade_option == "Charge Rate")
                {
                    //improve_function = KRnD.ImproveChargeRate;
                    current_upgrade_level      = current_upgrade.efficiencyMult;
                    next_upgrade_level         = ++next_upgrade.efficiencyMult;
                    u_constants                = ValueConstants.GetData(StringConstants.CHARGE_RATE);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.efficiencyMult);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.efficiencyMult);
                    science_cost               = u_constants.CalculateScienceCost(original_stats.efficiencyMult, next_upgrade.efficiencyMult);
                }
                else if (selected_upgrade_option == "Crash Tolerance")
                {
                    //improve_function = KRnD.ImproveCrashTolerance;
                    current_upgrade_level      = current_upgrade.crashTolerance;
                    next_upgrade_level         = ++next_upgrade.crashTolerance;
                    u_constants                = ValueConstants.GetData(StringConstants.CRASH_TOLERANCE);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.crashTolerance);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.crashTolerance);
                    science_cost               = u_constants.CalculateScienceCost(original_stats.crashTolerance, next_upgrade.crashTolerance);
                }
                else if (selected_upgrade_option == "Battery")
                {
                    //improve_function = KRnD.ImproveBatteryCharge;
                    current_upgrade_level      = current_upgrade.batteryCharge;
                    next_upgrade_level         = ++next_upgrade.batteryCharge;
                    u_constants                = ValueConstants.GetData(StringConstants.BATTERY_CHARGE);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.batteryCharge);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.batteryCharge);
                    science_cost               = u_constants.CalculateScienceCost((float)original_stats.batteryCharge, next_upgrade.batteryCharge);
                }
                else if (selected_upgrade_option == "Fuel Pressure")
                {
                    //improve_function = KRnD.ImproveFuelCapacity;
                    current_upgrade_level      = current_upgrade.fuelCapacity;
                    next_upgrade_level         = ++next_upgrade.fuelCapacity;
                    u_constants                = ValueConstants.GetData(StringConstants.FUEL_CAPACITY);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.fuelCapacity);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.fuelCapacity);
                    science_cost               = u_constants.CalculateScienceCost((float)original_stats.fuelCapacitiesSum, next_upgrade.fuelCapacity);
                }
                else if (selected_upgrade_option == "Generator")
                {
                    //improve_function = KRnD.ImproveGeneratorEfficiency;
                    current_upgrade_level      = current_upgrade.generatorEfficiency;
                    next_upgrade_level         = ++next_upgrade.generatorEfficiency;
                    u_constants                = ValueConstants.GetData(StringConstants.GENERATOR_EFFICIENCY);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.generatorEfficiency);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.generatorEfficiency);
                    science_cost               = u_constants.CalculateScienceCost(0, next_upgrade.generatorEfficiency);
                }
                else if (selected_upgrade_option == "Converter")
                {
                    //improve_function = KRnD.ImproveConverterEfficiency;
                    current_upgrade_level      = current_upgrade.converterEfficiency;
                    next_upgrade_level         = ++next_upgrade.converterEfficiency;
                    u_constants                = ValueConstants.GetData(StringConstants.CONVERTER_EFFICIENCY);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.converterEfficiency);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.converterEfficiency);
                    science_cost               = u_constants.CalculateScienceCost(0, next_upgrade.converterEfficiency);
                }
                else if (selected_upgrade_option == "Parachute")
                {
                    //improve_function = KRnD.ImproveParachuteStrength;
                    current_upgrade_level      = current_upgrade.parachuteStrength;
                    next_upgrade_level         = ++next_upgrade.parachuteStrength;
                    u_constants                = ValueConstants.GetData(StringConstants.PARACHUTE_STRENGTH);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.parachuteStrength);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.parachuteStrength);
                    science_cost               = u_constants.CalculateScienceCost((float)original_stats.chuteMaxTemp, next_upgrade.parachuteStrength);
                }
                else if (selected_upgrade_option == "Max Temp")
                {
                    //improve_function = KRnD.ImproveMaxTemperature;
                    current_upgrade_level      = current_upgrade.maxTemperature;
                    next_upgrade_level         = ++next_upgrade.maxTemperature;
                    u_constants                = ValueConstants.GetData(StringConstants.MAX_TEMPERATURE);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.maxTemperature);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.maxTemperature);
                    science_cost               = u_constants.CalculateScienceCost((float)original_stats.intMaxTemp, next_upgrade.maxTemperature);
                }
                else if (selected_upgrade_option == "EL Converter")
                {
                    //improve_function = KRnD.ImproveMaxTemperature;
                    current_upgrade_level      = current_upgrade.elConverter;
                    next_upgrade_level         = ++next_upgrade.elConverter;
                    u_constants                = ValueConstants.GetData(StringConstants.EL_CONVERTER);
                    current_improvement_factor = u_constants.CalculateImprovementFactor(current_upgrade.elConverter);
                    next_improvement_factor    = u_constants.CalculateImprovementFactor(next_upgrade.elConverter);
                    science_cost               = u_constants.CalculateScienceCost((float)original_stats.ELConverter, next_upgrade.elConverter);
                }
                else
                {
                    throw new Exception("unexpected option '" + selected_upgrade_option + "'");
                }

                var new_info = BuildPartInfoString(part, next_upgrade);                 // Calculate part-info if the selected stat was upgraded.
                new_info = HighlightChanges(current_info, new_info);

                // Current stats:
                GUILayout.BeginArea(new Rect(10 + options_width + 10, 30, _windowStyle.fixedWidth, 20));
                GUILayout.Label("<color=#FFFFFF><b>Current:</b> " + current_upgrade_level + " (" + current_improvement_factor.ToString("+0.##%;-0.##%;-") + ")</color>", _labelStyle);
                GUILayout.EndArea();

                var area_width  = (_windowStyle.fixedWidth - 20 - options_width) / 2;
                var area_height = options_height;
                GUILayout.BeginArea(new Rect(10 + options_width, 30 + 20, area_width, area_height));
                _scrollPos = GUILayout.BeginScrollView(_scrollPos, _scrollStyle, GUILayout.Width(area_width), GUILayout.Height(area_height));

                GUILayout.Label(current_info, _labelStyleSmall);
                GUILayout.EndScrollView();
                GUILayout.EndArea();

                // Next stats:
                GUILayout.BeginArea(new Rect(10 + options_width + area_width + 10, 30, _windowStyle.fixedWidth, 20));
                GUILayout.Label("<color=#FFFFFF><b>Next upgrade:</b> " + next_upgrade_level + " (" + next_improvement_factor.ToString("+0.##%;-0.##%;-") + ")</color>", _labelStyle);
                GUILayout.EndArea();

                GUILayout.BeginArea(new Rect(10 + options_width + area_width, 30 + 20, area_width, area_height));
                _scrollPos = GUILayout.BeginScrollView(_scrollPos, _scrollStyle, GUILayout.Width(area_width), GUILayout.Height(area_height));
                GUILayout.Label(new_info, _labelStyleSmall);
                GUILayout.EndScrollView();
                GUILayout.EndArea();

                // Bottom-line (display only if the upgrade would have an effect):
                if (Math.Abs(current_improvement_factor - next_improvement_factor) > float.Epsilon)
                {
                    GUILayout.BeginArea(new Rect(10, _windowStyle.fixedHeight - 25, _windowStyle.fixedWidth, 30));
                    float current_science = 0;
                    if (ResearchAndDevelopment.Instance != null)
                    {
                        current_science = ResearchAndDevelopment.Instance.Science;
                    }
                    var color = "FF0000";
                    if (current_science >= science_cost)
                    {
                        color = "00FF00";
                    }
                    GUILayout.Label("<b>Science: <color=#" + color + ">" + science_cost + " / " + Math.Floor(current_science) + "</color></b>", _labelStyle);
                    GUILayout.EndArea();
                    if (current_science >= science_cost && ResearchAndDevelopment.Instance != null && u_constants != null /*&& improve_function != null*/)
                    {
                        GUILayout.BeginArea(new Rect(_windowStyle.fixedWidth - 110, _windowStyle.fixedHeight - 30, 100, 30));
                        if (GUILayout.Button("Research", _buttonStyle))
                        {
                            //upgrade_function(part);
                            try {
                                if (!KRnD.upgrades.TryGetValue(part.name, out var store))
                                {
                                    store = new PartUpgrades();
                                    KRnD.upgrades.Add(part.name, store);
                                }

                                u_constants.upgradeFunction(store);
                                //improve_function(store);
                                KRnD.UpdateGlobalParts();
                                KRnD.UpdateEditorVessel();
                            } catch (Exception e) {
                                Debug.LogError("[KRnD] UpgradeIspVac(): " + e);
                            }



                            ResearchAndDevelopment.Instance.AddScience(-science_cost, TransactionReasons.RnDTechResearch);
                        }

                        GUILayout.EndArea();
                    }
                }

                GUILayout.EndVertical();
                GUI.DragWindow();
            } catch (Exception e) {
                Debug.LogError("[KRnD] GenerateWindow(): " + e);
            }
        }