public override void OnStart(StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            // load stored overflow setting
            _overflowAllowed = lastOverflowSettings;

            _windowId = new System.Random(part.GetInstanceID()).Next(int.MinValue, int.MaxValue);

            var refineriesList = part.FindModulesImplementing <IRefineryActivity>().ToList();

            if (RefineryType > 0)
            {
                AddIfMissing(refineriesList, new AluminiumElectrolyzer());
                AddIfMissing(refineriesList, new AmmoniaElectrolyzer());
                AddIfMissing(refineriesList, new AnthraquinoneProcessor());
                AddIfMissing(refineriesList, new AtmosphereProcessor());
                AddIfMissing(refineriesList, new CarbonDioxideElectrolyzer());
                AddIfMissing(refineriesList, new HaberProcess());
                AddIfMissing(refineriesList, new HeavyWaterElectrolyzer());
                AddIfMissing(refineriesList, new PartialMethaneOxidation());
                AddIfMissing(refineriesList, new PeroxideProcess());
                AddIfMissing(refineriesList, new UF4Ammonolysiser());
                AddIfMissing(refineriesList, new RegolithProcessor());
                AddIfMissing(refineriesList, new ReverseWaterGasShift());
                AddIfMissing(refineriesList, new NuclearFuelReprocessor());
                AddIfMissing(refineriesList, new SabatierReactor());
                AddIfMissing(refineriesList, new OceanProcessor());
                AddIfMissing(refineriesList, new SolarWindProcessor());
                AddIfMissing(refineriesList, new WaterElectrolyzer());
                AddIfMissing(refineriesList, new WaterGasShift());

                _availableRefineries = refineriesList
                                       .Where(m => ((int)m.RefineryType & RefineryType) == (int)m.RefineryType)
                                       .OrderBy(a => a.ActivityName).ToList();
            }
            else
            {
                _availableRefineries = refineriesList.OrderBy(a => a.ActivityName).ToList();
            }

            // initialize refineries
            _availableRefineries.ForEach(m => m.Initialize(part));

            // load same
            if (refinery_is_enabled && !string.IsNullOrEmpty(lastActivityName))
            {
                Debug.Log("[KSPI]: ISRU Refinery looking to restart " + lastActivityName);
                CurrentActivity = _availableRefineries.FirstOrDefault(a => a.ActivityName == lastActivityName);

                if (CurrentActivity == null)
                {
                    Debug.Log("[KSPI]: ISRU Refinery looking to restart " + lastClassName);
                    CurrentActivity = _availableRefineries.FirstOrDefault(a => a.GetType().Name == lastClassName);
                }
            }
        }
 private void AddIfMissing(List <IRefineryActivity> list, IRefineryActivity refinery)
 {
     if (list.All(m => m.ActivityName != refinery.ActivityName))
     {
         list.Add(refinery);
     }
 }
        [KSPEvent(guiActive = true, guiName = "#LOC_KSPIE_Refinery_ToggleRefineryWindow", active = true)]//Toggle Refinery Window
        public void ToggleWindow()
        {
            _render_window = !_render_window;

            if (_render_window && _refinery_activities.Count == 1)
            {
                _current_activity = _refinery_activities.First();
            }
        }
Пример #4
0
        [KSPEvent(guiActive = true, guiName = "#LOC_KSPIE_Refinery_ToggleRefineryWindow", active = true)]//Toggle Refinery Window
        public void ToggleWindow()
        {
            _render_window = !_render_window;

            if (_render_window && availableRefineries.Count == 1)
            {
                _current_activity = availableRefineries.First();
            }
        }
        [KSPEvent(guiActive = true, guiName = "#LOC_KSPIE_Refinery_ToggleRefineryWindow", active = true)]//Toggle Refinery Window
        public void ToggleWindow()
        {
            _renderWindow = !_renderWindow;

            if (_renderWindow && _availableRefineries.Count == 1)
            {
                CurrentActivity = _availableRefineries.First();
            }
        }
        public void ToggleRefinery(IRefineryActivity activity)
        {
            if (refinery_is_enabled)
            {
                DeactivateRefinery();
                return;
            }

            ActivateRefinery(activity);
        }
        private void ActivateRefinery(IRefineryActivity activity)
        {
            bool hasRequirement = activity.HasActivityRequirements(); // if the requirements for the activity are fulfilled

            if (hasRequirement)
            {
                currentActivity     = activity; // the activity will be treated as the current activity
                refinery_is_enabled = true;     // refinery is now on
            }
            else
            {
                activity.PrintMissingResources();
            }
        }
Пример #8
0
 private void Window(int window)
 {
     if (_bold_label == null)
     {
         _bold_label           = new GUIStyle(GUI.skin.label);
         _bold_label.fontStyle = FontStyle.Bold;
     }
     if (GUI.Button(new Rect(_window_position.width - 20, 2, 18, 18), "x"))
     {
         _render_window = false;
     }
     GUILayout.BeginVertical();
     if (_current_activity == null || !refinery_is_enabled)
     {
         _refinery_activities.ForEach(act =>
         {
             GUILayout.BeginHorizontal();
             if (GUILayout.Button(act.ActivityName, GUILayout.ExpandWidth(true)) && act.HasActivityRequirements)
             {
                 _current_activity   = act;
                 refinery_is_enabled = true;
             }
             GUILayout.EndHorizontal();
         });
     }
     else
     {
         GUILayout.BeginHorizontal();
         GUILayout.Label("Current Activity", _bold_label, GUILayout.Width(150));
         GUILayout.Label(_current_activity.ActivityName, GUILayout.Width(150));
         GUILayout.EndHorizontal();
         GUILayout.BeginHorizontal();
         GUILayout.Label("Status", _bold_label, GUILayout.Width(150));
         GUILayout.Label(_current_activity.Status, GUILayout.Width(150));
         GUILayout.EndHorizontal();
         _current_activity.UpdateGUI();
         GUILayout.BeginHorizontal();
         if (GUILayout.Button("Deactivate", GUILayout.ExpandWidth(true)))
         {
             refinery_is_enabled = false;
             _current_activity   = null;
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndVertical();
     GUI.DragWindow();
 }
 private void Window(int window)
 {
     if (_bold_label == null)
     {
         _bold_label = new GUIStyle(GUI.skin.label);
         _bold_label.fontStyle = FontStyle.Bold;
     }
     if (GUI.Button(new Rect(_window_position.width - 20, 2, 18, 18), "x"))
     {
         _render_window = false;
     }
     GUILayout.BeginVertical();
     if (_current_activity == null || !refinery_is_enabled)
     {
         _refinery_activities.ForEach(act =>
         {
             GUILayout.BeginHorizontal();
             if (GUILayout.Button(act.ActivityName, GUILayout.ExpandWidth(true)) && act.HasActivityRequirements)
             {
                 _current_activity = act;
                 refinery_is_enabled = true;
             }
             GUILayout.EndHorizontal();
         });
     } else
     {
         GUILayout.BeginHorizontal();
         GUILayout.Label("Current Activity", _bold_label, GUILayout.Width(150));
         GUILayout.Label(_current_activity.ActivityName, GUILayout.Width(150));
         GUILayout.EndHorizontal();
         GUILayout.BeginHorizontal();
         GUILayout.Label("Status", _bold_label, GUILayout.Width(150));
         GUILayout.Label(_current_activity.Status, GUILayout.Width(150));
         GUILayout.EndHorizontal();
         _current_activity.UpdateGUI();
         GUILayout.BeginHorizontal();
         if (GUILayout.Button("Deactivate", GUILayout.ExpandWidth(true)))
         {
             refinery_is_enabled = false;
             _current_activity = null;
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndVertical();
     GUI.DragWindow();
 }
        private void Window(int window)
        {
            if (_bold_label == null)
            {
                _bold_label           = new GUIStyle(GUI.skin.label);
                _bold_label.fontStyle = FontStyle.Bold;
                _bold_label.font      = PluginHelper.MainFont;
            }

            if (_value_label == null)
            {
                _value_label = new GUIStyle(GUI.skin.label)
                {
                    font = PluginHelper.MainFont
                }
            }
            ;

            if (_enabled_button == null)
            {
                _enabled_button           = new GUIStyle(GUI.skin.button);
                _enabled_button.fontStyle = FontStyle.Bold;
                _enabled_button.font      = PluginHelper.MainFont;
            }

            if (_disabled_button == null)
            {
                _disabled_button           = new GUIStyle(GUI.skin.button);
                _disabled_button.fontStyle = FontStyle.Normal;
                _disabled_button.font      = PluginHelper.MainFont;
            }

            if (GUI.Button(new Rect(_window_position.width - 20, 2, 18, 18), "x"))
            {
                _render_window = false;
            }

            GUILayout.BeginVertical();

            if (_current_activity == null || !refinery_is_enabled) // if there is no processing going on or the refinery is not enabled
            {
                _refinery_activities.ForEach(act =>                // per each activity (notice the end brackets are there, 13 lines below)
                {
                    GUILayout.BeginHorizontal();
                    bool hasRequirement = act.HasActivityRequirements();                           // if the requirements for the activity are fulfilled
                    GUIStyle guistyle   = hasRequirement ? _enabled_button : _disabled_button;     // either draw the enabled, bold button, or the disabled one

                    if (GUILayout.Button(act.ActivityName, guistyle, GUILayout.ExpandWidth(true))) // if user clicks the button and has requirements for the activity
                    {
                        if (hasRequirement)
                        {
                            _current_activity   = act;  // the activity will be treated as the current activity
                            refinery_is_enabled = true; // refinery is now on
                        }
                        else
                        {
                            act.PrintMissingResources();
                        }
                    }
                    GUILayout.EndHorizontal();
                });
            }
            else
            {
                bool hasRequirement = _current_activity.HasActivityRequirements();

                // show button to enable/disable resource overflow
                GUILayout.BeginHorizontal();
                if (overflowAllowed)
                {
                    if (GUILayout.Button(Localizer.Format("#LOC_KSPIE_Refinery_DisableOverflow"), GUILayout.ExpandWidth(true)))//"Disable Overflow"
                    {
                        overflowAllowed = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(Localizer.Format("#LOC_KSPIE_Refinery_EnableOverflow"), GUILayout.ExpandWidth(true)))//"Enable Overflow"
                    {
                        overflowAllowed = true;
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label(Localizer.Format("#LOC_KSPIE_Refinery_CurrentActivity"), _bold_label, GUILayout.Width(RefineryActivityBase.labelWidth));//"Current Activity"
                GUILayout.Label(_current_activity.ActivityName, _value_label, GUILayout.Width(RefineryActivityBase.valueWidth * 2));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label(Localizer.Format("#LOC_KSPIE_Refinery_Status"), _bold_label, GUILayout.Width(RefineryActivityBase.labelWidth));//"Status"
                GUILayout.Label(_current_activity.Status, _value_label, GUILayout.Width(RefineryActivityBase.valueWidth * 2));
                GUILayout.EndHorizontal();

                // allow current activity to show feedback
                _current_activity.UpdateGUI();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button(Localizer.Format("#LOC_KSPIE_Refinery_DeactivateProcess"), GUILayout.ExpandWidth(true)))//"Deactivate Process"
                {
                    refinery_is_enabled = false;
                    _current_activity   = null;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
            GUI.DragWindow();
        }
    }
        public override void OnStart(PartModule.StartState state)
        {
            powerSupply = part.FindModuleImplementing <IPowerSupply>();

            if (powerSupply != null)
            {
                powerSupply.DisplayName = Localizer.Format("#LOC_KSPIE_Refinery_started");//"started"
            }
            if (state == StartState.Editor)
            {
                return;
            }

            // load stored overflow setting
            overflowAllowed = lastOverflowSettings;

            _window_ID = new System.Random(part.GetInstanceID()).Next(int.MinValue, int.MaxValue);

            _refinery_activities = part.FindModulesImplementing <IRefineryActivity>();
            if (_refinery_activities == null || _refinery_activities.Count == 0)
            {
                var unsortedList = new List <IRefineryActivity>();

                unsortedList.Add(new AnthraquinoneProcessor());
                unsortedList.Add(new NuclearFuelReprocessor());
                unsortedList.Add(new AluminiumElectrolyser());
                unsortedList.Add(new SabatierReactor());
                unsortedList.Add(new WaterElectroliser());
                unsortedList.Add(new HeavyWaterElectroliser());
                unsortedList.Add(new PeroxideProcess());
                unsortedList.Add(new UF4Ammonolysiser());
                unsortedList.Add(new HaberProcess());
                unsortedList.Add(new AmmoniaElectrolyzer());
                unsortedList.Add(new CarbonDioxideElectroliser());
                unsortedList.Add(new WaterGasShift());
                unsortedList.Add(new ReverseWaterGasShift());
                unsortedList.Add(new PartialOxidationMethane());
                unsortedList.Add(new SolarWindProcessor());
                unsortedList.Add(new RegolithProcessor());
                unsortedList.Add(new AtmosphericExtractor());
                unsortedList.Add(new SeawaterExtractor());

                _refinery_activities = unsortedList.Where(m => ((int)m.RefineryType & this.refineryType) == (int)m.RefineryType).OrderBy(a => a.ActivityName).ToList();
            }

            _refinery_activities.ForEach(m => m.Initialize(this.part));

            // load same
            if (refinery_is_enabled && !string.IsNullOrEmpty(lastActivityName))
            {
                Debug.Log("[KSPI]: ISRU Refinery looking to restart " + lastActivityName);
                _current_activity = _refinery_activities.FirstOrDefault(a => a.ActivityName == lastActivityName);

                if (_current_activity == null)
                {
                    Debug.Log("[KSPI]: ISRU Refinery looking to restart " + lastClassName);
                    _current_activity = _refinery_activities.FirstOrDefault(a => a.GetType().Name == lastClassName);
                }
            }

            if (_current_activity != null)
            {
                bool hasRequirement = _current_activity.HasActivityRequirements();
                lastActivityName = _current_activity.ActivityName;

                Debug.Log("[KSPI]: ISRU Refinery initializing " + lastActivityName + " for which hasRequirement: " + hasRequirement);

                var productionModifier = productionMult * baseProduction;

                var timeDifference = (Planetarium.GetUniversalTime() - lastActiveTime);

                if (timeDifference > 0.01)
                {
                    string message = Localizer.Format("#LOC_KSPIE_Refinery_Postmsg1", lastActivityName, timeDifference.ToString("0"));//"IRSU performed " +  + " for " +  + " seconds"
                    Debug.Log("[KSPI]: " + message);
                    ScreenMessages.PostScreenMessage(message, 20, ScreenMessageStyle.LOWER_CENTER);
                }

                if (lastActivityName == "Atmospheric Extraction")
                {
                    ((AtmosphericExtractor)_current_activity).ExtractAir(lastPowerRatio * productionModifier, lastPowerRatio, productionModifier, lastOverflowSettings, timeDifference, true);
                }
                else if (lastActivityName == "Seawater Extraction")
                {
                    ((SeawaterExtractor)_current_activity).ExtractSeawater(lastPowerRatio * productionModifier, lastPowerRatio, productionModifier, lastOverflowSettings, timeDifference, true);
                }
                else
                {
                    _current_activity.UpdateFrame(lastPowerRatio * productionModifier, lastPowerRatio, productionModifier, lastOverflowSettings, timeDifference, true);
                }
            }
        }
        public override void OnStart(StartState state)
        {
            powerSupply = part.FindModuleImplementing <IPowerSupply>();

            if (powerSupply != null)
            {
                powerSupply.DisplayName = Localizer.Format("#LOC_KSPIE_Refinery_started"); //"started"
            }
            if (state == StartState.Editor)
            {
                return;
            }

            // load stored overflow setting
            _overflowAllowed = lastOverflowSettings;

            _windowId = new System.Random(part.GetInstanceID()).Next(int.MinValue, int.MaxValue);

            var refineriesList = part.FindModulesImplementing <IRefineryActivity>().ToList();

            if (refineryType > 0)
            {
                AddIfMissing(refineriesList, new AluminiumElectrolyzer());
                AddIfMissing(refineriesList, new AmmoniaElectrolyzer());
                AddIfMissing(refineriesList, new AnthraquinoneProcessor());
                AddIfMissing(refineriesList, new AtmosphereProcessor());
                AddIfMissing(refineriesList, new CarbonDioxideElectrolyzer());
                AddIfMissing(refineriesList, new HaberProcess());
                AddIfMissing(refineriesList, new HeavyWaterElectrolyzer());
                AddIfMissing(refineriesList, new PartialMethaneOxidation());
                AddIfMissing(refineriesList, new PeroxideProcess());
                AddIfMissing(refineriesList, new UF4Ammonolysiser());
                AddIfMissing(refineriesList, new RegolithProcessor());
                AddIfMissing(refineriesList, new ReverseWaterGasShift());
                AddIfMissing(refineriesList, new NuclearFuelReprocessor());
                AddIfMissing(refineriesList, new SabatierReactor());
                AddIfMissing(refineriesList, new OceanProcessor());
                AddIfMissing(refineriesList, new SolarWindProcessor());
                AddIfMissing(refineriesList, new WaterElectrolyzer());
                AddIfMissing(refineriesList, new WaterGasShift());

                availableRefineries = refineriesList
                                      .Where(m => ((int)m.RefineryType & refineryType) == (int)m.RefineryType)
                                      .OrderBy(a => a.ActivityName).ToList();
            }
            else
            {
                availableRefineries = refineriesList.OrderBy(a => a.ActivityName).ToList();
            }

            // initialize refineries
            foreach (var availableRefinery in availableRefineries)
            {
                try
                {
                    availableRefinery.Initialize(part, this);
                }
                catch (Exception e)
                {
                    Debug.LogError("[KSPI]: Failed to initialize " + availableRefinery.ActivityName + " with exception: " + e.Message);
                }
            }

            // load same
            if (refinery_is_enabled && !string.IsNullOrEmpty(lastActivityName))
            {
                Debug.Log("[KSPI]: ISRU Refinery looking to restart " + lastActivityName);
                currentActivity = availableRefineries.FirstOrDefault(a => a.ActivityName == lastActivityName);

                if (currentActivity == null)
                {
                    Debug.Log("[KSPI]: ISRU Refinery looking to restart " + lastClassName);
                    currentActivity = availableRefineries.FirstOrDefault(a => a.GetType().Name == lastClassName);
                }
            }

            if (currentActivity != null)
            {
                bool hasRequirement = currentActivity.HasActivityRequirements();
                lastActivityName = currentActivity.ActivityName;

                Debug.Log("[KSPI]: ISRU Refinery initializing " + lastActivityName + " for which hasRequirement: " + hasRequirement);

                var timeDifference = (Planetarium.GetUniversalTime() - lastActiveTime);

                if (timeDifference > 0.01)
                {
                    string message = Localizer.Format("#LOC_KSPIE_Refinery_Postmsg1", lastActivityName, timeDifference.ToString("0")); //"IRSU performed " +  + " for " +  + " seconds"
                    Debug.Log("[KSPI]: " + message);
                    ScreenMessages.PostScreenMessage(message, 20, ScreenMessageStyle.LOWER_CENTER);
                }

                var productionModifier = productionMult * baseProduction;
                if (lastActivityName == "Atmospheric Extraction")
                {
                    ((AtmosphereProcessor)currentActivity).ExtractAir(lastPowerRatio * productionModifier,
                                                                      lastPowerRatio, productionModifier, lastOverflowSettings, timeDifference, true);
                }
                else if (lastActivityName == "Seawater Extraction")
                {
                    ((OceanProcessor)currentActivity).ExtractSeawater(lastPowerRatio * productionModifier,
                                                                      lastPowerRatio, productionModifier, lastOverflowSettings, timeDifference, true);
                }
                else
                {
                    currentActivity.UpdateFrame(lastPowerRatio * productionModifier, lastPowerRatio,
                                                productionModifier, lastOverflowSettings, timeDifference, true);
                }
            }
        }
Пример #13
0
        private void Window(int window)
        {
            if (_bold_label == null)
            {
                _bold_label           = new GUIStyle(GUI.skin.label);
                _bold_label.fontStyle = FontStyle.Bold;
            }

            if (_enabled_button == null)
            {
                _enabled_button           = new GUIStyle(GUI.skin.button);
                _enabled_button.fontStyle = FontStyle.Bold;
            }

            if (_disabled_button == null)
            {
                _disabled_button           = new GUIStyle(GUI.skin.button);
                _disabled_button.fontStyle = FontStyle.Normal;
            }



            if (GUI.Button(new Rect(_window_position.width - 20, 2, 18, 18), "x"))
            {
                _render_window = false;
            }

            GUILayout.BeginVertical();

            if (_current_activity == null || !refinery_is_enabled)
            {
                _refinery_activities.ForEach(act =>
                {
                    GUILayout.BeginHorizontal();
                    bool hasRequirement = act.HasActivityRequirements;
                    GUIStyle guistyle   = hasRequirement ? _enabled_button : _disabled_button;

                    if (GUILayout.Button(act.ActivityName, guistyle, GUILayout.ExpandWidth(true)) && hasRequirement)
                    {
                        _current_activity   = act;
                        refinery_is_enabled = true;
                    }
                    GUILayout.EndHorizontal();
                });
            }
            else
            {
                // show button to enable/disable resource overflow
                GUILayout.BeginHorizontal();
                if (overflowAllowed)
                {
                    if (GUILayout.Button("Disable Overflow", GUILayout.ExpandWidth(true)))
                    {
                        overflowAllowed = false;
                    }
                }
                else
                {
                    if (GUILayout.Button("Enable Overflow", GUILayout.ExpandWidth(true)))
                    {
                        overflowAllowed = true;
                    }
                }
                GUILayout.EndHorizontal();


                GUILayout.BeginHorizontal();
                GUILayout.Label("Current Activity", _bold_label, GUILayout.Width(labelWidth));
                GUILayout.Label(_current_activity.ActivityName, GUILayout.Width(valueWidth));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Status", _bold_label, GUILayout.Width(labelWidth));
                GUILayout.Label(_current_activity.Status, GUILayout.Width(valueWidth));
                GUILayout.EndHorizontal();

                // allow current activity to show feedback
                _current_activity.UpdateGUI();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Deactivate Proces", GUILayout.ExpandWidth(true)))
                {
                    refinery_is_enabled = false;
                    _current_activity   = null;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
            GUI.DragWindow();
        }
        private void Window(int window)
        {
            if (_boldLabel == null)
            {
                _boldLabel = new GUIStyle(GUI.skin.label)
                {
                    fontStyle = FontStyle.Bold, font = PluginHelper.MainFont
                }
            }
            ;

            if (_valueLabel == null)
            {
                _valueLabel = new GUIStyle(GUI.skin.label)
                {
                    font = PluginHelper.MainFont
                }
            }
            ;

            if (_enabledButton == null)
            {
                _enabledButton = new GUIStyle(GUI.skin.button)
                {
                    fontStyle = FontStyle.Bold, font = PluginHelper.MainFont
                }
            }
            ;

            if (_disabledButton == null)
            {
                _disabledButton = new GUIStyle(GUI.skin.button)
                {
                    fontStyle = FontStyle.Normal, font = PluginHelper.MainFont
                }
            }
            ;

            if (GUI.Button(new Rect(_windowPosition.width - 20, 2, 18, 18), "x"))
            {
                showWindow = false;
            }

            GUILayout.BeginVertical();

            if (currentActivity == null || !refinery_is_enabled) // if there is no processing going on or the refinery is not enabled
            {
                availableRefineries.ForEach(activity =>          // per each activity (notice the end brackets are there, 13 lines below)
                {
                    GUILayout.BeginHorizontal();
                    bool hasRequirement = activity.HasActivityRequirements();                // if the requirements for the activity are fulfilled
                    GUIStyle guiStyle   = hasRequirement ? _enabledButton : _disabledButton; // either draw the enabled, bold button, or the disabled one

                    var buttonText = string.IsNullOrEmpty(activity.Formula) ? activity.ActivityName : activity.ActivityName + " : " + activity.Formula;

                    if (GUILayout.Button(buttonText, guiStyle, GUILayout.ExpandWidth(true))) // if user clicks the button and has requirements for the activity
                    {
                        ToggleRefinery(activity);
                    }
                    GUILayout.EndHorizontal();
                });
            }
            else
            {
                bool hasRequirement = currentActivity.HasActivityRequirements();

                // show button to enable/disable resource overflow
                GUILayout.BeginHorizontal();
                if (_overflowAllowed)
                {
                    if (GUILayout.Button(Localizer.Format("#LOC_KSPIE_Refinery_DisableOverflow"), GUILayout.ExpandWidth(true)))//"Disable Overflow"
                    {
                        _overflowAllowed = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(Localizer.Format("#LOC_KSPIE_Refinery_EnableOverflow"), GUILayout.ExpandWidth(true)))//"Enable Overflow"
                    {
                        _overflowAllowed = true;
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label(Localizer.Format("#LOC_KSPIE_Refinery_CurrentActivity"), _boldLabel, GUILayout.Width(RefineryActivity.labelWidth));//"Current Activity"
                GUILayout.Label(currentActivity.ActivityName, _valueLabel, GUILayout.Width(RefineryActivity.valueWidth * 2));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label(Localizer.Format("#LOC_KSPIE_Refinery_Status"), _boldLabel, GUILayout.Width(RefineryActivity.labelWidth));//"Status"
                GUILayout.Label(currentActivity.Status, _valueLabel, GUILayout.Width(RefineryActivity.valueWidth * 2));
                GUILayout.EndHorizontal();

                // allow current activity to show feedback
                currentActivity.UpdateGUI();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button(Localizer.Format("#LOC_KSPIE_Refinery_DeactivateProcess"), GUILayout.ExpandWidth(true)))//"Deactivate Process"
                {
                    refinery_is_enabled = false;
                    currentActivity     = null;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
            GUI.DragWindow();
        }
    }
}
 public void DeactivateRefinery()
 {
     refinery_is_enabled = false;
     currentActivity     = null;
 }
Пример #16
0
        public override void OnStart(PartModule.StartState state)
        {
            powerSupply = part.FindModuleImplementing <IPowerSupply>();

            if (powerSupply != null)
            {
                powerSupply.DisplayName = "started";
            }

            if (state == StartState.Editor)
            {
                return;
            }

            // load stored overflow setting
            overflowAllowed = lastOverflowSettings;

            _window_ID = new System.Random(part.GetInstanceID()).Next(int.MinValue, int.MaxValue);

            var unsortedList = new List <IRefineryActivity>();

            try
            {
                unsortedList.Add(new AnthraquinoneProcessor(this.part));
                unsortedList.Add(new NuclearFuelReprocessor(this.part));
                unsortedList.Add(new AluminiumElectrolyser(this.part));
                unsortedList.Add(new SabatierReactor(this.part));
                unsortedList.Add(new WaterElectroliser(this.part));
                unsortedList.Add(new HeavyWaterElectroliser(this.part));
                unsortedList.Add(new PeroxideProcess(this.part));
                unsortedList.Add(new UF4Ammonolysiser(this.part));
                unsortedList.Add(new HaberProcess(this.part));
                unsortedList.Add(new AmmoniaElectrolyzer(this.part));
                unsortedList.Add(new CarbonDioxideElectroliser(this.part));
                unsortedList.Add(new WaterGasShift(this.part));
                unsortedList.Add(new ReverseWaterGasShift(this.part));
                unsortedList.Add(new PartialOxidationMethane(this.part));
                unsortedList.Add(new SolarWindProcessor(this.part));
                unsortedList.Add(new RegolithProcessor(this.part));
                unsortedList.Add(new AtmosphericExtractor(this.part));
                unsortedList.Add(new SeawaterExtractor(this.part));
            }
            catch (Exception e)
            {
                Debug.LogException(e, new UnityEngine.Object()
                {
                    name = "ISRU Refinery"
                });
                Debug.LogWarning("[KSPI] - ISRU Refinery Exception " + e.Message);
            }

            _refinery_activities = unsortedList.Where(m => ((int)m.RefineryType & this.refineryType) == (int)m.RefineryType).OrderBy(a => a.ActivityName).ToList();

            // load same
            if (refinery_is_enabled && !string.IsNullOrEmpty(lastActivityName))
            {
                _current_activity = _refinery_activities.FirstOrDefault(a => a.ActivityName == lastActivityName);
            }

            if (_current_activity != null)
            {
                var productionRate = lastPowerRatio * productionMult * baseProduction;

                var timeDifference = (Planetarium.GetUniversalTime() - lastActiveTime);
                //string message = "[KSPI] - IRSU performed " + lastActivityName + " for " + timeDifference.ToString("0.0") + " seconds with production rate " + productionRate.ToString("0.0");
                //Debug.Log(message);
                //ScreenMessages.PostScreenMessage(message, 60.0f, ScreenMessageStyle.LOWER_CENTER);

                if (lastActivityName == "Atmospheric Extraction")
                {
                    ((AtmosphericExtractor)_current_activity).ExtractAir(productionRate, lastPowerRatio, productionMult * baseProduction, lastOverflowSettings, timeDifference, true);
                }
                else if (lastActivityName == "Seawater Extraction")
                {
                    ((SeawaterExtractor)_current_activity).ExtractSeawater(productionRate, lastPowerRatio, productionMult * baseProduction, lastOverflowSettings, timeDifference, true);
                }
                else
                {
                    _current_activity.UpdateFrame(productionRate, lastPowerRatio, productionMult * baseProduction, lastOverflowSettings, timeDifference);
                }
            }
        }
        private void Window(int window)
        {
            if (_bold_label == null)
            {
                _bold_label = new GUIStyle(GUI.skin.label);
                _bold_label.fontStyle = FontStyle.Bold;
            }

            if (_enabled_button == null)
            {
                _enabled_button = new GUIStyle(GUI.skin.button);
                _enabled_button.fontStyle = FontStyle.Bold;
            }

            if (_disabled_button == null)
            {
                _disabled_button = new GUIStyle(GUI.skin.button);
                _disabled_button.fontStyle = FontStyle.Normal;
            }

            

            if (GUI.Button(new Rect(_window_position.width - 20, 2, 18, 18), "x"))
                _render_window = false;

            GUILayout.BeginVertical();

            if (_current_activity == null || !refinery_is_enabled)
            {
                _refinery_activities.ForEach(act =>
                {

                    GUILayout.BeginHorizontal();
                    bool hasRequirement = act.HasActivityRequirements;
                    GUIStyle guistyle = hasRequirement ? _enabled_button : _disabled_button;

                    if (GUILayout.Button(act.ActivityName, guistyle, GUILayout.ExpandWidth(true)) && hasRequirement)
                    {
                        _current_activity = act;
                        refinery_is_enabled = true;
                    }
                    GUILayout.EndHorizontal();
                });
            }
            else
            {
                // show button to enable/disable resource overflow
                GUILayout.BeginHorizontal();
                if (overflowAllowed)
                {
                    if (GUILayout.Button("Disable Overflow", GUILayout.ExpandWidth(true)))
                        overflowAllowed = false;
                }
                else
                {
                    if (GUILayout.Button("Enable Overflow", GUILayout.ExpandWidth(true)))
                        overflowAllowed = true;
                }
                GUILayout.EndHorizontal();


                GUILayout.BeginHorizontal();
                GUILayout.Label("Current Activity", _bold_label, GUILayout.Width(labelWidth));
                GUILayout.Label(_current_activity.ActivityName, GUILayout.Width(valueWidth));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Status", _bold_label, GUILayout.Width(labelWidth));
                GUILayout.Label(_current_activity.Status, GUILayout.Width(valueWidth));
                GUILayout.EndHorizontal();

                // allow current activity to show feedback
                _current_activity.UpdateGUI();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Deactivate Proces", GUILayout.ExpandWidth(true)))
                {
                    refinery_is_enabled = false;
                    _current_activity = null;
                }
                GUILayout.EndHorizontal();


            }
            GUILayout.EndVertical();
            GUI.DragWindow();

        }
 public bool IsActive(IRefineryActivity activity)
 {
     return(refinery_is_enabled && currentActivity == activity);
 }