protected virtual void OnDestroy()
        {
            try
            {
                if (this.vessel.vesselName != null)
                {
                    GTIDebug.Log(this.vessel.vesselName + " --> " + this.GetType().Name + " --> OnDestroy()");
                }
            }
            catch { /* DO NOTHING */ }


            if (GameEvents.OnAnimationGroupStateChanged != null)
            {
                GameEvents.OnAnimationGroupStateChanged.Remove(OnModuleAnimationGroupStateChanged);
            }
            if (GameEvents.onCrewOnEva != null)
            {
                GameEvents.onCrewOnEva.Remove(onEVA);
            }
            if (GameEvents.onCrewBoardVessel != null)
            {
                GameEvents.onCrewBoardVessel.Remove(onEVABoard);
            }
            if (GameEvents.onVesselSwitching != null)
            {
                GameEvents.onVesselSwitching.Remove(onVesselSwitching);
            }
        }
 public static void LogEvents(PartModule module, object message = null)
 {
     GTIDebug.Log("--- PartModule Events --- " + module.moduleName, iDebugLevel.None);
     if (message != null)
     {
         Debug.Log("[GTI] " + message);
     }
     for (int i = 0; i < module.Events.Count; i++)
     {
         Debug.Log("[GTI]" +
                   "\ni: [" + i + "]" +
                   "\nGUIName: " + module.Events[i].GUIName +
                   "\nid: " + module.Events[i].id +
                   "\nname: " + module.Events[i].name +
                   "\nactive: " + module.Events[i].active +
                   "\nassigned: " + module.Events[i].assigned +
                   "\ncategory: " + module.Events[i].category +
                   "\nexternalToEVAOnly: " + module.Events[i].externalToEVAOnly +
                   "\nguiActive: " + module.Events[i].guiActive +
                   "\nguiActiveEditor: " + module.Events[i].guiActiveEditor +
                   "\nguiActiveUncommand: " + module.Events[i].guiActiveUncommand +
                   "\nguiActiveUnfocused: " + module.Events[i].guiActiveUnfocused +
                   "\nguiIcon: " + module.Events[i].guiIcon +
                   "\nunfocusedRange: " + module.Events[i].unfocusedRange +
                   "\n");
     }
 }
Exemple #3
0
        public void OnEnable()
        {
            // Create singleton accessor.
            Instance = this;

            //Check if original mod is present. If so, then disable this.
            GTIDebug.Log("GTI_ProjectManagerScenario Starting", "GTI - PM", GTIConfig.iDebugLevel.DebugInfo);
            if (!GTIConfig.ProjectManager_v2.Activate || PluginExists("ProjectManager") || 1 == 1)     //##################################################Force disable
            {
                if (PluginExists("ProjectManager") && GTIConfig.ProjectManager_v2.Activate)
                {
                    GTIDebug.Log("ProjectManager Detected -- Disabling GTI Project Manager", "GTI - PM", GTIConfig.iDebugLevel.DebugInfo);
                }
                Destroy(this.gameObject);
            }

            // Subscribe to launch event.
            if (!Instance.subscribed)
            {
                GameEvents.OnVesselRollout.Add(ApplyLaunchNumber);
                Debug.LogFormat("{0} Subscribed to rollout event.", LOG_PREFIX);
                Instance.subscribed = true;
            }

            this.enabled = false;           //###################### Disable module
        }
        /*[KSPEvent(active = false, guiActive = false, guiActiveEditor = false, guiName = "Deploy")]
         * public void ModuleAnimationGroupEvent()
         * {
         *  float AnimLength;
         *
         #region tests
         *  //Debug.Log("ModuleAnimationGroupEvent fired");
         *
         *  //Debug.Log("Anim.isPlaying " + Anim.isPlaying.ToString());
         #endregion
         *
         *  try { AnimLength = Anim.clip.length; } catch { AnimLength = 1f; }
         *
         *  BaseField chooseField = Fields[nameof(ChooseOption)];
         *  try  //We only handle the  first module
         *  {
         *      if (MAG.isDeployed)
         *      {
         *          MAG.RetractModule();
         *          chooseField.guiActive = false;
         *          chooseField.guiActiveEditor = false;
         *
         *          this.Events["ModuleAnimationGroupEvent"].guiName = txtDeploy;
         *          this.Events["ModuleAnimationGroupEvent"].guiActive = false;
         *          //StartCoroutine(ModuleAnimationGroupEventCoroutine(AnimLength, 0.001f, Deploying: false));
         *      }
         *      else
         *      {
         *          MAG.DeployModule();
         *
         *          //Update UI
         *          //chooseField.guiActiveEditor = availableInEditor;
         *          //chooseField.guiActive = availableInFlight;
         *
         *          //Debug.Log("updateConverter in 'ModuleAnimationGroupEvent'");
         *          this.Events["ModuleAnimationGroupEvent"].guiName = txtRetract;
         *          this.Events["ModuleAnimationGroupEvent"].guiActive = false;
         *          //StartCoroutine(ModuleAnimationGroupEventCoroutine(AnimLength, 0.001f, Deploying: true));
         *      }
         *  }
         *  catch
         *  {
         *      //... do nothing
         *      GTIDebug.LogError(this.GetType().Name  + " -- ModuleAnimationGroup --- Error when handling animations");
         *  }
         * }*/

        /*protected virtual IEnumerator ModuleAnimationGroupEventCoroutine(float starttime, float waitingtime, bool Deploying)
         * {
         *  GTIDebug.Log("Start of ModuleAnimationGroupEventCoroutine()", iDebugLevel.High);
         *  yield return new WaitForSeconds(starttime);
         *  int _InvokeCounter = 0;
         *  while (_InvokeCounter++ < 600)
         *  {
         *      GTIDebug.Log("Coroutine Looping while animation is playing: " + _InvokeCounter, iDebugLevel.DebugInfo);
         *      if (Anim.isPlaying == false)
         *      {
         *          GTIDebug.Log("'Animation finished playing' --> update Mode");
         *          if (Deploying)
         *          {
         *              this.Fields["ChooseOption"].guiActiveEditor = availableInEditor;
         *              this.Fields["ChooseOption"].guiActive = availableInFlight;
         *              updateMultiMode(silentUpdate: true);
         *          }
         *          else
         *          {
         *              ModuleAnimationGroupEvent_DisableModules();
         *          }
         *
         *          //Reactivate the gui button
         *          this.Events["ModuleAnimationGroupEvent"].guiActive = true;
         *          GTIDebug.Log("Coroutine should stop here", iDebugLevel.DebugInfo);
         *          break;
         *      }
         *      else
         *      {
         *          GTIDebug.Log("Coroutine will wait for " + waitingtime + " sec and run again", iDebugLevel.DebugInfo);
         *          yield return new WaitForSeconds(waitingtime);
         *          GTIDebug.Log(this.GetType().Name + " -- Coroutine have waited for " + waitingtime + " sec and continue", iDebugLevel.DebugInfo);
         *      }
         *  }
         *  //Reactivate the gui button if waiting failed
         *  if (_InvokeCounter >= 600)
         *  {
         *      this.Fields["ChooseOption"].guiActive = true;
         *      this.Events["ModuleAnimationGroupEvent"].guiActive = true;
         *      GTIDebug.LogError("ModuleAnimationGroupEventCoroutine failed to finish successfully");
         *  }
         * }*/

        protected virtual void OnModuleAnimationGroupStateChanged(ModuleAnimationGroup module, bool Deploying)
        {
            GTIDebug.Log("Animation finished 'OnAnimationGroupStateChanged' --> update Mode", iDebugLevel.High);

            if (module != null && module.part != part)
            {
                GTIDebug.Log("triggering part is not this part", iDebugLevel.DebugInfo); return;
            }

            if (Deploying)
            {
                this.Fields["ChooseOption"].guiActiveEditor = availableInEditor;
                this.Fields["ChooseOption"].guiActive       = availableInFlight;
                //updateMultiMode(silentUpdate: true);
                OnUpdateMultiMode(silentUpdate: true);
            }
            else
            {
                this.Fields["ChooseOption"].guiActiveEditor = false;
                this.Fields["ChooseOption"].guiActive       = false;
                //externalToEVAOnly
                ModuleAnimationGroupEvent_DisableModules();
            }

            //Reactivate the gui button
            //this.Events["ModuleAnimationGroupEvent"].guiActive = true;
            GTIDebug.Log("OnAnimationGroupStateChanged executed", iDebugLevel.DebugInfo);
        }
Exemple #5
0
        protected override void initializeSettings()
        {
            if (!_settingsInitialized)
            {
                GTIDebug.Log("GTI_MultiModeConverter --> initializeSettings()", iDebugLevel.DebugInfo);

                //Find all converters in the part, and order thier names into an array for reference
                MRC = part.FindModulesImplementing <ModuleResourceConverter>();

                modes = new List <MultiMode>(MRC.Count);
                for (int i = 0; i < MRC.Count; i++)
                {
                    //converterNames[i] = MRC[i].ConverterName;
                    modes.Add(new MultiMode()
                    {
                        moduleIndex = i,
                        ID          = i.ToString(),
                        Name        = MRC[i].ConverterName
                    });
                    GTIDebug.Log("mode[" + i + "].ID --> " + modes[i].ID, iDebugLevel.DebugInfo);
                    GTIDebug.Log("mode[" + i + "].Name --> " + modes[i].Name, iDebugLevel.DebugInfo);
                }

                //Disable converter actions, as these should be handled by the multimodeconverter module
                for (int i = 0; i < MRC.Count; i++)
                {
                    MRC[i].Actions["ToggleResourceConverterAction"].active = false;
                    MRC[i].Actions["StartResourceConverterAction"].active  = false;
                    MRC[i].Actions["StopResourceConverterAction"].active   = false;
                }
            }
        }
Exemple #6
0
        protected override void writeScreenMessage()
        {
            //string strOutInfo = string.Empty;
            StringBuilder strOutInfo = new StringBuilder();

            strOutInfo.AppendLine("Converter mode changed to " + modes[selectedMode]);
            strOutInfo.AppendLine("Inputs:");
            foreach (ResourceRatio input in MRC[selectedMode].Recipe.Inputs)
            {
                strOutInfo.AppendLine(input.ResourceName + " (" + input.Ratio + ")");
            }
            strOutInfo.AppendLine("Outputs:");
            foreach (ResourceRatio output in MRC[selectedMode].Recipe.Outputs)
            {
                strOutInfo.AppendLine(output.ResourceName + " (" + output.Ratio + ")");
            }

            GTIDebug.Log("\nGTI_MultiModeConverter:\n" + strOutInfo.ToString(), iDebugLevel.DebugInfo);

            writeScreenMessage(
                Message: strOutInfo.ToString(),
                messagePosition: messagePosition,
                duration: 3f
                );
        }
Exemple #7
0
        void Start()
        {
            if (!GTIConfig.CameraFocusChanger.Activate || PluginExists("CameraFocusChanger"))
            {
                Destroy(this);
                return;
            }

            GTIDebug.Log("Starting GTI_CameraFocusChanger");

            //DebugPrint("Starting Camera Focus Changer");
            flightCamera            = FlightCamera.fetch;
            pivotTranslateSharpness = 0.5f;
            hasReachedTarget        = false;
            isFocusing = false;

            PluginConfiguration config = PluginConfiguration.CreateForType <GTI_CameraFocusChanger>();

            config.load();
            actionKey         = config.GetValue <KeyCode>("actionKey", KeyCode.O);
            showUpdateMessage = config.GetValue <bool>("showUpdateMessage", true);

            GameEvents.OnCameraChange.Add(OnCameraChange);
            GameEvents.onVesselChange.Add(OnVesselChange);
            GameEvents.onVesselWillDestroy.Add(OnVesselWillDestroy);
            GameEvents.onVesselGoOnRails.Add(OnVesselGoOnRails);
            GameEvents.onStageSeparation.Add(OnStageSeparation);
            GameEvents.onUndock.Add(OnUndock);

            API.SetInstance(this);
        }
Exemple #8
0
        protected override void initializeSettings()
        {
            if (!_settingsInitialized)
            {
                GTIDebug.Log("GTI_MultiModeHarvester --> initializeSettings()", iDebugLevel.DebugInfo);
                MRH = part.FindModulesImplementing <ModuleResourceHarvester>();

                modes = new List <MultiMode>(MRH.Count);
                for (int i = 0; i < MRH.Count; i++)
                {
                    modes.Add(new MultiMode()
                    {
                        moduleIndex = i,
                        ID          = i.ToString(),
                        Name        = MRH[i].ConverterName
                    });
                    GTIDebug.Log("mode[" + i + "].ID --> " + modes[i].ID, iDebugLevel.DebugInfo);
                    GTIDebug.Log("mode[" + i + "].Name --> " + modes[i].Name, iDebugLevel.DebugInfo);
                }

                //Disable converter actions, as these should be handled by the multimodeconverter module
                for (int i = 0; i < MRH.Count; i++)
                {
                    MRH[i].Actions["ToggleResourceConverterAction"].active = false;
                    MRH[i].Actions["StartResourceConverterAction"].active  = false;
                    MRH[i].Actions["StopResourceConverterAction"].active   = false;
                }

                //initializeGUI();

                //_settingsInitialized = true;
                //updateMultiMode = update;         --> Delegate testing
            }
        }
        //public virtual List<T> GetCounterPartModules(Part thispart)
        //{
        //    List<Part> CounterParts = thispart.symmetryCounterparts;
        //    List<T> modules = new List<T>(CounterParts.Count);

        //    foreach (Part part in CounterParts)
        //    {
        //        modules.Add(part.FindModuleImplementing<T>());
        //    }

        //    return modules;
        //}

        /// <summary>
        /// Derives the selected converter as integer from the ChooseOption value
        /// </summary>
        protected virtual void FindSelectedMode()
        {
            for (int i = 0; i < modes.Count; i++)
            {
                if (modes[i].ID == ChooseOption)
                {
                    selectedMode = i;
                    //this.Fields["EVAChangeMode"].guiName = "Change mode: " + mode[selectedMode].Name;
                    this.Events[nameof(EVAChangeMode)].guiName = "Change mode: " + modes[selectedMode].Name;

                    ////Sync up all counterparts modules
                    //if (affectSymCounterpartsInFlight)
                    //{
                    //    List<GTI_MultiMode<T>> CounterModules = CounterPartModules(this.part);
                    //    foreach (GTI_MultiMode<T> module in CounterModules)
                    //    {
                    //        module.ChooseOption = ChooseOption;
                    //    }
                    //}

                    return;
                }
            }
            GTIDebug.Log("FindSelectedMode() was unsuccessful in locating current mode: " + ChooseOption, iDebugLevel.DebugInfo);
        }
 /// <summary>
 /// selModeFromChooseOption set selectedMode from ChooseOption.
 /// If ChooseOption is empty, then the first mode in moduleList is returned.
 /// Dependent on: ChooseOption, selectedMode, mode.ID
 /// </summary>
 protected virtual void selModeFromChooseOption()
 {
     GTIDebug.Log("selModeFromChooseOption() start", iDebugLevel.DebugInfo);
     if (ChooseOption == string.Empty)
     {
         GTIDebug.Log("selModeFromChooseOption() --> ChooseOption == string.Empty", iDebugLevel.DebugInfo);
         ChooseOption = modes[0].ID;
         selectedMode = 0;
         return;
     }
     else
     {
         for (int i = 0; i < modes.Count; i++)
         {
             if (ChooseOption == modes[i].ID)
             {
                 GTIDebug.Log("selModeFromChooseOption() --> ChooseOption == mode[i].ID", iDebugLevel.DebugInfo);
                 selectedMode = i;
                 return;
             }
         }
         //If mode not found, revert to first setting
         GTIDebug.Log("selModeFromChooseOption() --> Default", iDebugLevel.DebugInfo);
         ChooseOption = modes[0].ID;
         selectedMode = 0;
     }
 }
        public static void HookModule(string targetModule, string attachModule)
        {
            for (int iPart = 0; iPart < PartLoader.LoadedPartsList.Count; iPart++)
            {
                AvailablePart currentAP   = PartLoader.LoadedPartsList[iPart];
                Part          currentPart = currentAP.partPrefab;

                for (int iModule = 0; iModule < currentPart.Modules.Count; iModule++)
                {
                    if (targetModule == currentPart.Modules[iModule].moduleName)
                    {
                        if (!ModuleAttached(currentPart, attachModule))
                        {
                            GTIDebug.Log(targetModule + " found - Attaching " + attachModule, iDebugLevel.Medium);
                            PartModule newModule = currentPart.AddModule(attachModule);
                            if (null == newModule)
                            {
                                Debug.LogError(attachModule + " attachment failed.");
                            }
                            newModule.moduleName = attachModule;
                        }
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Update propulsion
        /// </summary>
        public override void updateMultiMode(bool silentUpdate = false)
        {
            //initializeSettings();
            GTIDebug.Log("GTI_MultiModeEngine: updatePropulsion() --> ChooseOption = " + ChooseOption, iDebugLevel.High);

            if (currentModuleEngine != null)
            {
                currentEngineState = currentModuleEngine.getIgnitionState;
            }
            else
            {
                GTIDebug.Log("updateMultiMode() --> currentModuleEngine is null", iDebugLevel.Low);
            }


            //FindSelectedMode();       //irrelevant when inheritting from the base class
            writeScreenMessage();

            if (ModuleEngines == null)
            {
                GTIDebug.Log("updateMultiMode() --> ModuleEngines is null", iDebugLevel.Low);
            }

            foreach (ModuleEnginesFX moduleEngine in ModuleEngines)
            {
                #region NOTES

                /* Stock GUI Elements
                 * fuelFlowGui
                 * finalThrust
                 * realIsp
                 * status
                 * thrustPercentage
                 */
                #endregion

                if (moduleEngine.engineID == ChooseOption)
                {
                    GTIDebug.Log("GTI_MultiModeEngine: Set currentModuleEngine " + moduleEngine.engineID, iDebugLevel.High);
                    currentModuleEngine = moduleEngine;
                    //Reactivate engine if it was active
                    if (currentEngineState)
                    {
                        GTIDebug.Log("GTI_MultiModeEngine: Activate() " + moduleEngine.engineID, iDebugLevel.High);
                        moduleEngine.Activate();
                    }
                    moduleEngine.manuallyOverridden = false;
                    moduleEngine.isEnabled          = true;
                }
                else
                {
                    GTIDebug.Log("GTI_MultiModeEngine: Shutdown() " + moduleEngine.engineID, iDebugLevel.High);
                    moduleEngine.Shutdown();
                    moduleEngine.manuallyOverridden = true;
                    moduleEngine.isEnabled          = false;
                }
            }
        } //END OF updatePropulsion()
 private void onVesselSwitching(Vessel fromVessel, Vessel toVessel)
 {
     //Consistency Check
     GTIDebug.Log("onVesselSwitching", iDebugLevel.DebugInfo);
     if (toVessel == null || fromVessel == null)
     {
         return;
     }
     GTIDebug.Log("isEVA: " + toVessel.isEVA, iDebugLevel.DebugInfo);
 }
 protected void onEVABoard(GameEvents.FromToAction <Part, Part> FromToData)
 {
     //Consistency Check
     GTIDebug.Log("onEVABoard", iDebugLevel.DebugInfo);
     if (FromToData.to == null || FromToData.from == null)
     {
         return;
     }
     GTIDebug.Log("Vessel: " + this.vessel.vesselName + "fromVessel: " + FromToData.from.vessel.vesselName + "toVessel: " + FromToData.to.vessel.vesselName, iDebugLevel.DebugInfo);
     GTIDebug.Log("isEVA: " + FromToData.to.vessel.isEVA, iDebugLevel.DebugInfo);
 }
        public override void OnStart(PartModule.StartState state)
        {
            GTIDebug.Log("GTI_MultiMode baseclass --> OnStart()", iDebugLevel.DebugInfo);

            //Assign update method to delegate
            OnUpdateMultiMode  = FindSelectedMode;
            OnUpdateMultiMode += updateMultiMode;

            initialize();

            this.Events["EVAChangeMode"].active = externalToEVAOnly;
        }
Exemple #16
0
        void OnDestroy()
        {
            GTIDebug.Log("GTI_CameraFocusChanger Disabled");

            GameEvents.OnCameraChange.Remove(OnCameraChange);
            GameEvents.onVesselChange.Remove(OnVesselChange);
            GameEvents.onVesselWillDestroy.Remove(OnVesselWillDestroy);
            GameEvents.onVesselGoOnRails.Remove(OnVesselGoOnRails);
            GameEvents.onStageSeparation.Remove(OnStageSeparation);
            GameEvents.onUndock.Remove(OnUndock);

            API.SetInstance(null);
        }
Exemple #17
0
 protected override void ModuleAnimationGroupEvent_DisableModules()
 {
     //for (int i = 0; i < mode.Count; i++)
     for (int i = 0; i < MRC.Count; i++)     //Disable all modules
     {
         GTIDebug.Log("GTI_MultiModeConverter: Deactivate Converter Module [" + modes[i].moduleIndex + "] --> " + MRC[modes[i].moduleIndex].ConverterName, iDebugLevel.High);
         //Deactivate the converter
         //MRC[modes[i].moduleIndex].DirtyFlag = false;    //Fix for KSP1.3.1
         MRC[modes[i].moduleIndex].DisableModule();
         //Stop the converter
         MRC[modes[i].moduleIndex].StopResourceConverter();
     }
 }
        /// <summary>
        /// Updates the selection the user uses the right click UI
        /// </summary>
        /// <param name="field"></param>
        /// <param name="oldValueObj"></param>
        protected virtual void selectMode(BaseField field, object oldValueObj)
        {
            //FindSelectedMode();

            /*updateMultiMode();*/


            foreach (Delegate d in OnUpdateMultiMode.GetInvocationList())
            {
                GTIDebug.Log(d.Method.ToString());
            }
            OnUpdateMultiMode.Invoke();
        }
        protected void onEVA(GameEvents.FromToAction <Part, Part> FromToData)
        {
            //Consistency Check
            GTIDebug.Log("onEVA", iDebugLevel.DebugInfo);
            if (FromToData.to == null || FromToData.from == null)
            {
                return;
            }
            GTIDebug.Log("Vessel: " + this.vessel.vesselName + "fromVessel: " + FromToData.from.vessel.vesselName + "toVessel: " + FromToData.to.vessel.vesselName, iDebugLevel.DebugInfo);
            GTIDebug.Log("isEVA: " + FromToData.to.vessel.isEVA, iDebugLevel.DebugInfo);

            //if (vessel.isEVA)
            //if (FlightGlobals.ActiveVessel.vesselType == VesselType.EVA)
        }
        } //END OF updatePropulsion()

        protected override void initializeGUI()
        {
            GTIDebug.Log("GTI_MultiModeEngine() --> override initializeGUI()", iDebugLevel.High);
            base.initializeGUI();
            //Get currently activated engine module
            GTIDebug.Log("override initializeGUI() --> Get currently activated engine module", iDebugLevel.High);
            for (int i = 0; i < ModuleEngines.Count; i++)
            {
                if (ModuleEngines[i].engineID == ChooseOption)
                {
                    currentModuleEngine = ModuleEngines[i];
                }
            }
        }
        //Comment: Using "OnAnimationGroupStateChanged" event, I could probably further simplify the logics and remove
        //the overriding of the "ModuleAnimationGroup" functionality
        protected virtual void initializeModuleAnimationGroup()
        {
            //Debug.Log("useModuleAnimationGroup: " + useModuleAnimationGroup);
            if (!_MAGsettingsInitialized && useModuleAnimationGroup == true)
            {
                GTIDebug.Log("useModuleAnimationGroup: Evaluated as true", iDebugLevel.DebugInfo);
                //Animation Anim = new Animation();
                //ModuleAnimationGroup MAG = new ModuleAnimationGroup();

                MAG = part.FindModuleImplementing <ModuleAnimationGroup>();

                //Anim = part.FindModelAnimator(MAG.deployAnimationName);

                //foreach (BaseEvent e in MAG.Events)
                //{
                //    e.active = false;
                //    e.guiActive = false;
                //    e.guiActiveEditor = false;
                //}
                //foreach (BaseAction a in MAG.Actions)
                //{
                //    a.active = false;
                //}

                //GTIDebug.Log("Activate 'ModuleAnimationGroupEvent'", iDebugLevel.DebugInfo);

                //Activate event in this module to trigger animations instead
                //this.Events["ModuleAnimationGroupEvent"].active = true;
                //this.Events["ModuleAnimationGroupEvent"].guiActive = true;
                //this.Events["ModuleAnimationGroupEvent"].guiActiveEditor = true;
                //Patch 2018-03-14 to fix the button showing even when module is not deployed.
                GTIDebug.Log("initializeModuleAnimationGroup: !MAG.isDeployed " + !MAG.isDeployed, iDebugLevel.DebugInfo);
                if (!MAG.isDeployed)
                {
                    ModuleAnimationGroupEvent_DisableModules();
                }

                //Register the event of Animation Groups
                if (GameEvents.OnAnimationGroupStateChanged != null && MAG != null)
                {
                    GTIDebug.Log("Subscribing to OnAnimationGroupStateChanged", iDebugLevel.DebugInfo);
                    GameEvents.OnAnimationGroupStateChanged.Add(OnModuleAnimationGroupStateChanged);
                }

                //?? Add check if the MAG isDeployed? Adjust UI accordingly?

                _MAGsettingsInitialized = true;
            }
        }
Exemple #22
0
        protected override void initializeSettings()
        {
            GTIDebug.Log("GTI_MultiModeIntake --> initializeSettings()", iDebugLevel.DebugInfo);
            GTIDebug.Log(part.GetPartModuleConfig("MODULE", "name", "GTI_MultiModeIntake").ToString(), iDebugLevel.DebugInfo);

            ConfigNode[] ResourceNodes = part.GetPartModuleConfigs("RESOURCE");
            GTIDebug.Log(ResourceNodes.ToStringExt(), iDebugLevel.DebugInfo);
            //foreach(ConfigNode n in ResourceNodes)
            //{
            //    GTIDebug.Log(n.ToString(), iDebugLevel.DebugInfo);
            //    GTIDebug.Log(n.values.GetValue("name"), iDebugLevel.DebugInfo);
            //}

            //GetPartModuleConfig(this.part, "MODULE", "name", "GTI_MultiModeEngine")

            //Find resourceIntake modules
            ModuleIntakes = part.FindModulesImplementing <ModuleResourceIntake>();

            modes = new List <IntakeModes>(ModuleIntakes.Count);
            GTIDebug.Log(this.GetType().Name + " --> ModuleIntakes.Count; " + ModuleIntakes.Count, iDebugLevel.DebugInfo);
            for (int i = 0; i < ModuleIntakes.Count; i++)
            {
                GTIDebug.Log("for (int i = 0; i < ModuleIntakes.Count; i++): " + i, iDebugLevel.DebugInfo);
                modes.Add(new IntakeModes()
                {
                    moduleIndex  = i,
                    ID           = i.ToString(),
                    Name         = ModuleIntakes[i].resourceName,
                    resourceName = ModuleIntakes[i].resourceName
                });
                GTIDebug.Log("modes[" + i + "].moduleIndex --> " + modes[i].moduleIndex, iDebugLevel.DebugInfo);
                GTIDebug.Log("modes[" + i + "].ID --> " + modes[i].ID, iDebugLevel.DebugInfo);
                GTIDebug.Log("modes[" + i + "].Name --> " + modes[i].Name, iDebugLevel.DebugInfo);
            }

            //Disable Events, as these should be handled by the multimode module
            for (int i = 0; i < ModuleIntakes.Count; i++)
            {
                ModuleIntakes[i].Events["Deactivate"].guiActive       = false;
                ModuleIntakes[i].Events["Deactivate"].guiActiveEditor = false;
                ModuleIntakes[i].Events["Activate"].guiActive         = false;
                ModuleIntakes[i].Events["Activate"].guiActiveEditor   = false;

                ModuleIntakes[i].Actions["ToggleAction"].active = false;
            }

            //force no use af animation groups (it's not imlpemented, I don't believe it's relevant)
            useModuleAnimationGroup = false;
        }
Exemple #23
0
        protected override void initializeSettings()
        {
            if (!_settingsInitialized)
            {
                GTIDebug.Log("GTI_MultiModeRCS() --> initializeSettings()", iDebugLevel.DebugInfo);

                string[] arrGUIRCSID;

                #region Split into Arrays
                //arrRCSID = RCSID.Trim().Split(';');
                GUIRCSIDEmpty = ArraySplitEvaluate(GUIRCSID, out arrGUIRCSID, ';');
                #endregion

                #region Identify ModuleRCS in Scope
                GTIDebug.Log("Find modules RCS from part", iDebugLevel.DebugInfo);
                ModuleRCSs = part.FindModulesImplementing <ModuleRCS>();

                modes = new List <MultiMode>(ModuleRCSs.Count);
                if (ModuleRCSs.Count != arrGUIRCSID.Length || GUIRCSIDEmpty)
                {
                    GTIDebug.LogError("GTI_MultiModeRCS Error in CFG configuration detected");
                }


                GTIDebug.Log("Create list of modes", iDebugLevel.DebugInfo);
                for (int i = 0; i < ModuleRCSs.Count; i++)
                {
                    modes.Add(new MultiMode()
                    {
                        moduleIndex = i,
                        ID          = i.ToString(),
                        Name        = GUIRCSIDEmpty ? ModuleRCSs[i].resourceName : arrGUIRCSID[i]
                    });
                }

                //Remove the is interactions buttons of the engines, so that it is controlled by this mod instead
                //foreach (var moduleEngine in ModuleEngines)
                for (int i = 0; i < ModuleRCSs.Count; i++)
                {
                    //Deactivate stock RCS actions
                    ModuleRCSs[i].Actions["ToggleAction"].active = false;
                }

                useModuleAnimationGroup = false;    //ModuleAnimationGroup handling, can be added if needed later
                #endregion
            }
        }
        public override string GetInfo()
        {
            StringBuilder Info = new StringBuilder();

            GTIDebug.Log("GTI_MultiModeEngineFX GetInfo");
            try
            {
                if (!_settingsInitialized)
                {
                    initializeSettings();
                    //ModuleEngines = part.FindModulesImplementing<ModuleEnginesFX>();
                }


                //Info.AppendLine("GTI MultiMode Engine FX");
                Info.AppendLine("<color=yellow>Engine Modes Available:</color>");
                Info.AppendLine(GUIengineID);
                Info.AppendLine("\nIn Flight switching is <color=yellow>" + (availableInFlight ? "available" : "not available") + "</color>");
                //foreach (ModuleEnginesFX e in ModuleEngines)
                //foreach (MultiMode m in modes)
                //{

                //    //ModuleEngines[m.moduleIndex].GetMaxThrust();

                //    Info.AppendLine("Max Trust " + ModuleEngines[m.moduleIndex].GetMaxThrust());
                //}


                //str.AppendFormat("Maximal force: {0:0.0}iN\n", maxGeneratorForce);
                //str.AppendFormat("Maximal charge time: {0:0.0}s\n\n", maxChargeTime);
                //str.AppendFormat("Requires\n");
                //str.AppendFormat("- Electric charge: {0:0.00}/s\n\n", requiredElectricalCharge);
                //str.Append("Navigational computer\n");
                //str.Append("- Required force\n");
                //str.Append("- Success probability\n");


                //return "GTI MultiMode Engine FX";
                return(Info.ToString());
            }
            catch (Exception e)
            {
                GTIDebug.LogError("GTI_MultiModeEngineFX GetInfo Error " + e.Message);
                throw;
            }
        }
Exemple #25
0
 public void GetStatus()
 {
     GTIDebug.Log("\nGetStatus() of all ModuleResourceIntakes", iDebugLevel.DebugInfo);
     foreach (ModuleResourceIntake I in ModuleIntakes)
     {
         GTIDebug.Log("\nresourceName " + I.resourceName, iDebugLevel.DebugInfo);
         GTIDebug.Log("status " + I.status, iDebugLevel.DebugInfo);
         GTIDebug.Log("intakeEnabled " + I.intakeEnabled, iDebugLevel.DebugInfo);
         GTIDebug.Log("isActiveAndEnabled " + I.isActiveAndEnabled, iDebugLevel.DebugInfo);
         GTIDebug.Log("isEnabled " + I.isEnabled, iDebugLevel.DebugInfo);
         GTIDebug.Log("enabled " + I.enabled, iDebugLevel.DebugInfo);
         GTIDebug.Log("airFlow " + I.airFlow, iDebugLevel.DebugInfo);
         GTIDebug.Log("airSpeedGui " + I.airSpeedGui, iDebugLevel.DebugInfo);
         GTIDebug.Log("area " + I.area, iDebugLevel.DebugInfo);
         GTIDebug.Log("checkForOxygen " + I.checkForOxygen, iDebugLevel.DebugInfo);
         GTIDebug.Log("kPaThreshold " + I.kPaThreshold, iDebugLevel.DebugInfo);
         GTIDebug.Log("moduleIsEnabled " + I.moduleIsEnabled, iDebugLevel.DebugInfo);
     }
 }
        /// <summary>
        /// Checks if a specific mod/plugin is loaded and return true/false
        /// </summary>
        /// <param name="ModName"></param>
        /// <returns></returns>
        public static bool PluginExists(string ModName)
        {
            //return AssemblyLoader.loadedAssemblies.Any(a => a.name == ModName);
            //foreach (var assembly in AssemblyLoader.loadedAssemblies)

            for (int i = 0; i < AssemblyLoader.loadedAssemblies.Count; i++)
            {
                //var name = assembly.assembly.ToString().Split(',')[0];
                //if (AssemblyLoader.loadedAssemblies[i].name == ModName)
                //GTIDebug.Log("ModName (split)" + AssemblyLoader.loadedAssemblies[i].assembly.ToString(),iDebugLevel.DebugInfo);
                //GTIDebug.Log("ModName " + AssemblyLoader.loadedAssemblies[i].name, iDebugLevel.DebugInfo);
                if (AssemblyLoader.loadedAssemblies[i].name == ModName)
                {
                    GTIDebug.Log("ModName '" + AssemblyLoader.loadedAssemblies[i].name + "' found", iDebugLevel.DebugInfo);
                    return(true);
                }
            }
            return(false);
        }
Exemple #27
0
        private void Start()
        {
            GTIDebug.Log("GTI_NavBallDockingAlignmentIndicator Starting", "GTI - DAI", GTIConfig.iDebugLevel.DebugInfo);
            if (!GTIConfig.NavBallDockingIndicator.Activate || PluginExists("NavBallDockingAlignmentIndicatorCE"))
            {
                if (PluginExists("NavBallDockingAlignmentIndicatorCE") && GTIConfig.NavBallDockingIndicator.Activate)
                {
                    GTIDebug.Log("NavBallDockingAlignmentIndicatorCE Detected -- Disabling GTI Alignment indicator", "GTI - DAI", GTIConfig.iDebugLevel.DebugInfo);
                }
                Destroy(this.gameObject);
            }


            GTIDebug.Log(" ======== AWAKE  ======== ", GTIConfig.iDebugLevel.Low);
            this.cfg = KSP.IO.PluginConfiguration.CreateForType <GTI_NavBallDockingAlignmentIndicator>();
            this.cfg.load();
            Vector3 tmp = cfg.GetValue <Vector3>("alignmentmarkercolor", new Vector3(1f, 0f, 0f)); // default: red

            this.color = new Color(tmp.x, tmp.y, tmp.z);
            this.cfg.save();
        }
        protected virtual void MultiModeAction(int inActionSelect)
        {
            GTIDebug.Log("Action ActionPropulsion_" + inActionSelect + " (before): " + ChooseOption, iDebugLevel.Medium);

            //Check if the selected mode is possible
            if (inActionSelect < modes.Count)
            {
                //Check if the selected mode is a change
                if (!(selectedMode == inActionSelect))
                {
                    selectedMode = inActionSelect;

                    ChooseOption = modes[selectedMode].ID;        //converterNames[selectedConverter];
                    GTIDebug.Log("MultiModeAction_" + inActionSelect + " Executed", iDebugLevel.DebugInfo);

                    //updateMultiMode();
                    OnUpdateMultiMode();
                }
            }
            GTIDebug.Log("Action MultiModeAction_" + inActionSelect + " (after): " + ChooseOption, iDebugLevel.Medium);
        }
Exemple #29
0
        public override void updateMultiMode(bool silentUpdate = false)
        {
            GTIDebug.Log("GTI_MultiModeConverter: updateMultiMode() --> Begin", iDebugLevel.High);

            //FindSelectedMode();
            if (silentUpdate == false)
            {
                writeScreenMessage();
            }

            bool MAG_isDeployed = true;

            if (MAG != null && useModuleAnimationGroup == true)
            {
                MAG_isDeployed = MAG.isDeployed;
            }

            for (int i = 0; i < modes.Count; i++)
            {
                if (i == selectedMode && MAG_isDeployed)
                {
                    GTIDebug.Log("GTI_MultiMode (" + (silentUpdate ? "silent" : "non-silent") + "): Activate Module [" + modes[i].moduleIndex + "] --> " + MRC[modes[i].moduleIndex].ConverterName, iDebugLevel.High);
                    MRC[modes[i].moduleIndex].EnableModule();
                    currentConverter = MRC[modes[i].moduleIndex];
                }
                else
                {
                    GTIDebug.Log("GTI_MultiMode (" + (silentUpdate ? "silent" : "non-silent") + "): Deactivate Module [" + modes[i].moduleIndex + "] --> " + MRC[modes[i].moduleIndex].ConverterName, iDebugLevel.High);

                    //Deactivate the converter
                    MRC[modes[i].moduleIndex].DisableModule();
                    //Stop the converter
                    MRC[modes[i].moduleIndex].StopResourceConverter();
                }
            }
            MonoUtilities.RefreshContextWindows(part);
            GTIDebug.Log("GTI_MultiModeConverter: updateMultiMode() --> Finished", iDebugLevel.DebugInfo);
        }
Exemple #30
0
        public override void OnAwake()
        {
            // Create singleton accessor.
            Instance = this;

            //Check if original mod is present. If so, then disable this.
            GTIDebug.Log("GTI_ProjectManagerScenario Starting", "GTI - PM", GTIConfig.iDebugLevel.DebugInfo);
            if (!GTIConfig.ProjectManager.Activate || PluginExists("ProjectManager"))
            {
                if (PluginExists("ProjectManager") && GTIConfig.ProjectManager.Activate)
                {
                    GTIDebug.Log("ProjectManager Detected -- Disabling GTI Project Manager", "GTI - PM", GTIConfig.iDebugLevel.DebugInfo);
                }
                Destroy(this.gameObject);
            }

            // Subscribe to launch event.
            if (!Instance.subscribed)
            {
                GameEvents.OnVesselRollout.Add(ApplyLaunchNumber);
                Debug.LogFormat("{0} Subscribed to rollout event.", DebugTag);
                Instance.subscribed = true;
            }
        }