Beispiel #1
0
        internal static void Display(Vector2 displayViewerPosition)
        {
            //float scrollX = WindowControl.Position.x + 20;
            //float scrollY = WindowControl.Position.y + 50 - displayViewerPosition.y;
            float scrollX = 20;
            float scrollY = displayViewerPosition.y;

            // Reset Tooltip active flag...
            ToolTipActive             = false;
            SMHighlighter.IsMouseOver = false;

            GUILayout.BeginVertical();
            GUI.enabled = true;
            //GUILayout.Label("External Light Control Center ", SMStyle.LabelTabHeader);
            GUILayout.Label(SmUtils.Localize("#smloc_control_light_000"), SMStyle.LabelTabHeader);
            GUILayout.Label("____________________________________________________________________________________________",
                            SMStyle.LabelStyleHardRule, GUILayout.Height(10), GUILayout.Width(guiRuleWidth));
            string step = "start";

            try
            {
                // Display all Lights
                List <ModLight> .Enumerator iLights = SMAddon.SmVessel.Lights.GetEnumerator();
                while (iLights.MoveNext())
                {
                    if (iLights.Current == null)
                    {
                        continue;
                    }
                    string label      = $"{iLights.Current.Status} - {iLights.Current.Title}";
                    bool   onState    = iLights.Current.IsOn;
                    bool   newOnState = GUILayout.Toggle(onState, label, GUILayout.Width(guiToggleWidth), GUILayout.Height(40));
                    step = "button toggle check";
                    if (!onState && newOnState)
                    {
                        iLights.Current.TurnOnLight();
                    }
                    else if (onState && !newOnState)
                    {
                        iLights.Current.TurnOffLight();
                    }
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    {
                        SMHighlighter.SetMouseOverData(rect, scrollY, scrollX, WindowControl.TabBox.height, iLights.Current.SPart, Event.current.mousePosition);
                    }
                }
                iLights.Dispose();

                // Display MouseOverHighlighting, if any
                SMHighlighter.MouseOverHighlight();
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage(
                    $" in Light Tab at step {step}.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", SmUtils.LogType.Error,
                    true);
            }
            GUILayout.EndVertical();
        }
Beispiel #2
0
 internal static void FreezeKerbal(ProtoCrewMember kerbal)
 {
     try
     {
         if (!InstalledMods.IsDfApiReady)
         {
             return;
         }
         List <Part> .Enumerator cryofreezers = SmUtils.GetFreezerParts().GetEnumerator();
         while (cryofreezers.MoveNext())
         {
             if (cryofreezers.Current == null)
             {
                 continue;
             }
             if (!cryofreezers.Current.protoModuleCrew.Contains(kerbal))
             {
                 continue;
             }
             // ReSharper disable once SuspiciousTypeConversion.Global
             PartModule deepFreezer = SMConditions.GetFreezerModule(cryofreezers.Current);
             if (deepFreezer != null)
             {
                 new DfWrapper.DeepFreezer(deepFreezer).BeginFreezeKerbal(kerbal);
             }
             break;
         }
         cryofreezers.Dispose();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($" in FreezeKerbal.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                            SmUtils.LogType.Error, true);
     }
 }
Beispiel #3
0
        static ClsClient()
        {
            try
            {
                // Original call.  deep dives into all assemblies...
                //Type cls_type = AssemblyLoader
                //  .loadedAssemblies
                //  .SelectMany(a => a.assembly.GetExportedTypes())
                //  .SingleOrDefault(t => t.FullName == "ConnectedLivingSpace.CLSAddon");

                // this replacement call attempts to filter dynamic assemblies...  Dot.Net 2.0 vs Dot.Net 4.0
                //Type newType = AssemblyLoader
                //  .loadedAssemblies.Where(a => a.assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder == false)
                //  .SelectMany(a => a.assembly.GetExportedTypes())
                //  .SingleOrDefault(t => t.FullName == "ConnectedLivingSpace.CLSAddon");

                // Lighter weight, and should not "dive into" assemblies unnecessarily.
                Type clsType =
                    AssemblyLoader.loadedAssemblies.Where(a => a.name.Contains("ConnectedLivingSpace"))
                    .SelectMany(a => a.assembly.GetExportedTypes())
                    .SingleOrDefault(t => t.FullName == "ConnectedLivingSpace.CLSAddon");

                if (clsType != null)
                {
                    _cls = clsType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static);
                }
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($"Cannot load CLS assembly.  Error:  {ex}", SmUtils.LogType.Error, false);
            }
        }
Beispiel #4
0
        private static void DisplaySelectProfession()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(SmUtils.Localize("#smloc_roster_005"), GUILayout.Width(85));                                                        // "Profession:"
            bool isPilot = GUILayout.Toggle(KerbalProfession == Professions.Pilot, SmUtils.Localize("#smloc_roster_006"), GUILayout.Width(90)); // "Pilot"

            if (isPilot)
            {
                KerbalProfession = Professions.Pilot;
            }

            bool isEngineer = GUILayout.Toggle(KerbalProfession == Professions.Engineer, SmUtils.Localize("#smloc_roster_007"), GUILayout.Width(90)); // "Engineer"

            if (isEngineer)
            {
                KerbalProfession = Professions.Engineer;
            }

            bool isScientist = GUILayout.Toggle(KerbalProfession == Professions.Scientist, SmUtils.Localize("#smloc_roster_008"), GUILayout.Width(90)); // "Scientist"

            if (isScientist)
            {
                KerbalProfession = Professions.Scientist;
            }
            GUILayout.EndHorizontal();
        }
Beispiel #5
0
 private static string GetFrozenKerbalDetails(ProtoCrewMember kerbal)
 {
     try
     {
         string rosterDetails = "";
         if (!DfWrapper.ApiReady)
         {
             DfWrapper.InitDfWrapper();
         }
         if (DfWrapper.ApiReady)
         {
             rosterDetails = DfWrapper.DeepFreezeApi.FrozenKerbals.ContainsKey(kerbal.name)
     ? $"{SmUtils.SmTags["#smloc_roster_015"]} - {DfWrapper.DeepFreezeApi.FrozenKerbals[kerbal.name].VesselName.Replace("(unloaded)", "")}"
     : SmUtils.SmTags["#smloc_roster_015"];
         }
         return(rosterDetails);
     }
     catch (Exception ex)
     {
         if (!SMAddon.FrameErrTripped)
         {
             SmUtils.LogMessage($" in GetRosterList().\r\nError:  {ex}", SmUtils.LogType.Error, true);
         }
         return($"{SmUtils.SmTags["#smloc_error_001"]}:"); // "Display Error"
     }
 }
Beispiel #6
0
        internal void CrewTransferStopAction()
        {
            // This adds the kerbal(s) to the destination part(s)
            try
            {
                // Add Source Crewmember to target part
                if (FromCrewMember != null && ToPart.CrewCapacity > ToPart.protoModuleCrew.Count)
                {
                    AddCrewMember(FromCrewMember, ToPart, ToSeat);
                }

                // Add Target Crewmember to source part
                if (ToCrewMember != null && FromPart.CrewCapacity > FromPart.protoModuleCrew.Count)
                {
                    AddCrewMember(ToCrewMember, FromPart, FromSeat);
                }

                SMAddon.SmVessel.TransferCrewObj.IvaDelayActive = true;
                SMAddon.FireEventTriggers();
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage(
                    $"in CrewTransferAction.  Error moving crewmember.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", SmUtils.LogType.Error, true);
            }
        }
Beispiel #7
0
        internal static void TransferScienceLab(PartModule source, PartModule target, Selection sel)
        {
            try
            {
                // Create lookup list to avoid a slow linear search for each item
                // Value is number of labs that have processed it
                // (would allow to only move data not processed in all labs if there are multiple)
                Dictionary <string, int>            processedScience = new Dictionary <string, int>();
                List <ModuleScienceLab> .Enumerator labs             = SMAddon.SmVessel.Vessel.FindPartModulesImplementing <ModuleScienceLab>().GetEnumerator();
                while (labs.MoveNext())
                {
                    List <string> .Enumerator dataitems = labs.Current.ExperimentData.GetEnumerator();
                    while (dataitems.MoveNext())
                    {
                        if (!processedScience.ContainsKey(dataitems.Current))
                        {
                            processedScience.Add(dataitems.Current, 1);
                        }
                        else
                        {
                            processedScience[dataitems.Current]++;
                        }
                    }
                    dataitems.Dispose();
                }
                labs.Dispose();

                ScienceData[] moduleScience = (IScienceDataContainer)source != null ? ((IScienceDataContainer)source).GetData() : null;

                if (moduleScience == null || moduleScience.Length <= 0)
                {
                    return;
                }
                IEnumerator dataItems = moduleScience.GetEnumerator();
                while (dataItems.MoveNext())
                {
                    if (dataItems.Current == null)
                    {
                        continue;
                    }
                    ScienceData data      = (ScienceData)dataItems.Current;
                    bool        processed = processedScience.ContainsKey(data.subjectID);

                    if ((sel == Selection.OnlyProcessed && processed) ||
                        (sel == Selection.OnlyUnprocessed && !processed))
                    {
                        if (((ModuleScienceContainer)target).AddData(data))
                        {
                            ((IScienceDataContainer)source).DumpData(data);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($" in ProcessController.TransferScienceLab:  Error:  {ex}", SmUtils.LogType.Info, SMSettings.VerboseLogging);
            }
        }
Beispiel #8
0
        internal static void Display(Vector2 displayViewerPosition)
        {
            //float scrollX = WindowControl.Position.x + 10;
            //float scrollY = WindowControl.Position.y + 50 - displayViewerPosition.y;
            float scrollX = 10;
            float scrollY = 50 - displayViewerPosition.y;

            // Reset Tooltip active flag...
            ToolTipActive             = false;
            SMHighlighter.IsMouseOver = false;

            GUILayout.BeginVertical();
            GUI.enabled = true;
            //GUILayout.Label("Science Lab Control Center ", SMStyle.LabelTabHeader);
            GUILayout.Label(SmUtils.Localize("#smloc_control_lab_000"), SMStyle.LabelTabHeader);
            GUILayout.Label("____________________________________________________________________________________________",
                            SMStyle.LabelStyleHardRule, GUILayout.Height(10), GUILayout.Width(350));
            string step = "start";

            try
            {
                // Display all Labs
                List <ModuleScienceLab> .Enumerator iLabs = SMAddon.SmVessel.Labs.GetEnumerator();
                while (iLabs.MoveNext())
                {
                    if (iLabs.Current == null)
                    {
                        continue;
                    }

                    step        = "gui enable";
                    GUI.enabled = true;
                    string label = $"{iLabs.Current.name} - ({(iLabs.Current.IsOperational() ? SmUtils.Localize("#smloc_control_lab_001") : SmUtils.Localize("#smloc_control_lab_002"))})"; // Operational, InOp
                    GUILayout.Label(label, GUILayout.Width(260), GUILayout.Height(40));

                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition))
                    {
                        SMHighlighter.SetMouseOverData(rect, scrollY, scrollX, WindowControl.TabBox.height, iLabs.Current.part);
                    }
                }
                iLabs.Dispose();

                // Display MouseOverHighlighting, if any
                SMHighlighter.MouseOverHighlight();
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage(
                    $" in Solar Panel Tab at step {step}.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                    SmUtils.LogType.Error, true);
            }
            GUILayout.EndVertical();
        }
Beispiel #9
0
        internal static void Savelog()
        {
            try
            {
                // time to create a file...
                string filename = $"DebugLog_{DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace(" ", "_").Replace("/", "").Replace(":", "")}.txt";

                string path = Directory.GetCurrentDirectory() + @"\GameData\ShipManifest\";
                if (SMSettings.DebugLogPath.StartsWith(@"\\"))
                {
                    SMSettings.DebugLogPath = SMSettings.DebugLogPath.Substring(2, SMSettings.DebugLogPath.Length - 2);
                }
                else if (SMSettings.DebugLogPath.StartsWith(@"\"))
                {
                    SMSettings.DebugLogPath = SMSettings.DebugLogPath.Substring(1, SMSettings.DebugLogPath.Length - 1);
                }

                if (!SMSettings.DebugLogPath.EndsWith(@"\"))
                {
                    SMSettings.DebugLogPath += @"\";
                }

                filename = path + SMSettings.DebugLogPath + filename;
                SmUtils.LogMessage($"File Name = {filename}", SmUtils.LogType.Info, true);

                try
                {
                    StringBuilder             sb    = new StringBuilder();
                    List <string> .Enumerator lines = SmUtils.LogItemList.GetEnumerator();
                    while (lines.MoveNext())
                    {
                        if (lines.Current == null)
                        {
                            continue;
                        }
                        sb.AppendLine(lines.Current);
                    }
                    lines.Dispose();

                    File.WriteAllText(filename, sb.ToString());

                    SmUtils.LogMessage("File written", SmUtils.LogType.Info, true);
                }
                catch (Exception ex)
                {
                    SmUtils.LogMessage($"Error Writing File:  {ex}", SmUtils.LogType.Error, true);
                }
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($" in Savelog.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", SmUtils.LogType.Error,
                                   true);
            }
        }
Beispiel #10
0
        private static void DisplayRosterFilter()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label($"{SmUtils.Localize("#smloc_roster_009")}:", GUILayout.Width(40));                                             // Filter

            bool isAll = GUILayout.Toggle(CurrentFilter == KerbalFilters.All, SmUtils.Localize("#smloc_roster_010"), GUILayout.Width(60)); // "All"

            if (isAll)
            {
                CurrentFilter = KerbalFilters.All;
            }

            bool isAssign = GUILayout.Toggle(CurrentFilter == KerbalFilters.Assigned, SmUtils.Localize("#smloc_roster_011"), GUILayout.Width(95)); // "Assigned"

            if (isAssign)
            {
                CurrentFilter = KerbalFilters.Assigned;
            }

            if (HighLogic.LoadedSceneIsFlight)
            {
                bool isVessel = GUILayout.Toggle(CurrentFilter == KerbalFilters.Vessel, SmUtils.Localize("#smloc_roster_012"), GUILayout.Width(80)); // "Vessel"
                if (isVessel)
                {
                    CurrentFilter = KerbalFilters.Vessel;
                }
            }

            bool isAvail = GUILayout.Toggle(CurrentFilter == KerbalFilters.Available, SmUtils.Localize("#smloc_roster_013"), GUILayout.Width(95)); // "Available"

            if (isAvail)
            {
                CurrentFilter = KerbalFilters.Available;
            }

            bool isDead = GUILayout.Toggle(CurrentFilter == KerbalFilters.Dead, SmUtils.Localize("#smloc_roster_014"), GUILayout.Width(130)); // "Dead/Missing"

            if (isDead)
            {
                CurrentFilter = KerbalFilters.Dead;
            }

            if (InstalledMods.IsDfInstalled)
            {
                bool isFrozen = GUILayout.Toggle(CurrentFilter == KerbalFilters.Frozen, SmUtils.Localize("#smloc_roster_015"), GUILayout.Width(80)); // "Frozen"
                if (isFrozen)
                {
                    CurrentFilter = KerbalFilters.Frozen;
                }
            }
            GUILayout.EndHorizontal();
        }
Beispiel #11
0
        internal static void TransferScience(PartModule source, PartModule target)
        {
            try
            {
                ScienceData[] moduleScience = (IScienceDataContainer)source != null ? ((IScienceDataContainer)source).GetData() : null;

                if (moduleScience == null || moduleScience.Length <= 0)
                {
                    return;
                }
                //Utilities.LogMessage("ProcessController.TransferScience:  moduleScience has data...", Utilities.LogType.Info,
                //  SMSettings.VerboseLogging);

                if ((IScienceDataContainer)target == null)
                {
                    return;
                }
                // Lets store the data from the source.
                if (!((ModuleScienceContainer)target).StoreData(
                        new List <IScienceDataContainer> {
                    (IScienceDataContainer)source
                }, false))
                {
                    return;
                }

                //Utilities.LogMessage("ProcessController.TransferScience:  ((ModuleScienceContainer)source) data stored",
                //  "Info", SMSettings.VerboseLogging);
                IEnumerator dataItems = moduleScience.GetEnumerator();
                while (dataItems.MoveNext())
                {
                    if (dataItems.Current == null)
                    {
                        continue;
                    }
                    ScienceData data = (ScienceData)dataItems.Current;
                    ((IScienceDataContainer)source).DumpData(data);
                }

                if (!SMSettings.RealControl)
                {
                    ((ModuleScienceExperiment)source).ResetExperiment();
                }
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($" in ProcessController.TransferScience:  Error:  {ex}", SmUtils.LogType.Info, SMSettings.VerboseLogging);
            }
        }
Beispiel #12
0
        internal static void DumpResources(List <TransferPump> pumps)
        {
            // This initiates the Dump process and with realism off, does the dump immediately; with realism on, initiates the real time process.
            try
            {
                if (SMSettings.RealXfers)
                {
                    // Turn on Pumps for timed process...
                    List <TransferPump> .Enumerator epumps = pumps.GetEnumerator();
                    while (epumps.MoveNext())
                    {
                        if (epumps.Current == null)
                        {
                            continue;
                        }
                        TransferPump pump = epumps.Current;
                        pump.PumpRatio = 1;
                        pump.IsPumpOn  = true;
                    }
                    epumps.Dispose();
                    // Add pumps to pump queue
                    SMAddon.SmVessel.TransferPumps.AddRange(pumps);

                    // Start the process.  This flag is checked in SMAddon.Update()
                    TransferPump.PumpProcessOn = true;
                }
                else
                {
                    List <TransferPump> .Enumerator epumps = pumps.GetEnumerator();
                    while (epumps.MoveNext())
                    {
                        if (epumps.Current == null)
                        {
                            continue;
                        }
                        TransferPump pump = epumps.Current;
                        pump.RunPumpCycle(pump.PumpAmount);
                    }
                    epumps.Dispose();
                    SMAddon.SmVessel.TransferPumps.Clear();
                }
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage(
                    $" in  ProcessController.DumpResources.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                    SmUtils.LogType.Error, true);
            }
        }
Beispiel #13
0
        private static void DisplayActionButtons()
        {
            GUILayout.BeginHorizontal();

              // Save
              //GUIContent label = new GUIContent("Save", "Save the current settings to file.");
              GUIContent label = new GUIContent(SmUtils.Localize("#smloc_settings_002"), SmUtils.Localize("#smloc_settings_tt_002"));
              if (GUILayout.Button(label, GUILayout.Height(20)))
              {
            ToolTip = "";
            SMSettings.SaveIntervalSec = int.Parse(TabConfig.TxtSaveInterval);
            SMSettings.SaveSettings();

            // Sync SM to CLS override settings with CLS
            if (SMSettings.EnableCls && HighLogic.LoadedSceneIsFlight)
            {
              SMSettings.UpdateClsOverride();
            }

            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
              SMAddon.OnSmSettingsClicked();
            else
              ShowWindow = false;
              }
              Rect rect = GUILayoutUtility.GetLastRect();
              if (Event.current.type == EventType.Repaint && ShowToolTips)
            ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);

              // Cancel
              //label = new GUIContent("Cancel", "Cancel the changes made.\nSettings will revert to before changes were made.");
              label = new GUIContent(SmUtils.Localize("#smloc_settings_003"), SmUtils.Localize("#smloc_settings_tt_003"));
              if (GUILayout.Button(label, GUILayout.Height(20)))
              {
            ToolTip = "";
            // We've canclled, so restore original settings.
            SMSettings.MemRestoreTempSettings();

            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
              SMAddon.OnSmSettingsClicked();
            else
              ShowWindow = false;
              }
              rect = GUILayoutUtility.GetLastRect();
              if (Event.current.type == EventType.Repaint && ShowToolTips)
            ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);

              GUILayout.EndHorizontal();
        }
Beispiel #14
0
 internal static void HireKerbal(ProtoCrewMember kerbal)
 {
     try
     {
         if (kerbal.type != ProtoCrewMember.KerbalType.Applicant)
         {
             throw new Exception("Tried to hire a kerbal which isn't an Applicant: " + kerbal.ToString());
         }
         HighLogic.CurrentGame.CrewRoster.HireApplicant(kerbal);
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($" in HireKerbal.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                            SmUtils.LogType.Error, true);
     }
 }
Beispiel #15
0
        internal static void MouseOverHighlight(Part part)
        {
            string step = "begin";

            try
            {
                step = "inside box - Part Selection?";
                SetPartHighlight(part, SMSettings.Colors[SMSettings.MouseOverColor]);
                EdgeHighight(part, true);
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($" in SMHighlighter.MouseOverHighlight at step {step}.  Error:  {ex}",
                                   SmUtils.LogType.Error, true);
            }
        }
Beispiel #16
0
 internal static void GetRosterList()
 {
     try
     {
         RosterList.Clear();
         RosterList = HighLogic.CurrentGame.CrewRoster.Crew.ToList();
         // Support for DeepFreeze
         if (InstalledMods.IsDfInstalled && DfWrapper.ApiReady)
         {
             RosterList.AddRange(HighLogic.CurrentGame.CrewRoster.Unowned);
         }
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($"Error in GetRosterList().\r\nError:  {ex}", SmUtils.LogType.Error, true);
     }
 }
Beispiel #17
0
        internal static bool CanShowShipManifest(bool ignoreShowSm = false)
        {
            try
            {
                bool canShow = false;
                if (SMAddon.ShowUi &&
                    HighLogic.LoadedScene == GameScenes.FLIGHT &&
                    !IsPauseMenuOpen() &&
                    !IsFlightDialogDisplaying() &&
                    FlightGlobals.fetch != null &&
                    FlightGlobals.ActiveVessel != null &&
                    !FlightGlobals.ActiveVessel.isEVA &&
                    FlightGlobals.ActiveVessel.vesselType != VesselType.Flag
                    //&& FlightGlobals.ActiveVessel.vesselType != VesselType.Debris
                    //&& FlightGlobals.ActiveVessel.vesselType != VesselType.Unknown
                    //&& CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA
                    )
                {
                    canShow = ignoreShowSm || WindowManifest.ShowWindow;
                }
                return(canShow);
            }
            catch (Exception ex)
            {
                if (!SMAddon.FrameErrTripped)
                {
                    string values = $"SmAddon.ShowUI = {SMAddon.ShowUi}\r\n";
                    values += $"HighLogic.LoadedScene = {HighLogic.LoadedScene}\r\n";
                    values += $"PauseMenu.isOpen = {IsPauseMenuOpen()}\r\n";
                    values += $"FlightResultsDialog.isDisplaying = {IsFlightDialogDisplaying()}\r\n";
                    values += $"FlightGlobals.fetch != null = {(FlightGlobals.fetch != null)}\r\n";
                    values += $"FlightGlobals.ActiveVessel != null = {(FlightGlobals.ActiveVessel != null)}\r\n";
                    values += $"!FlightGlobals.ActiveVessel.isEVA = {(FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.isEVA)}\r\n";
                    if (FlightGlobals.ActiveVessel != null)
                    {
                        values += $"FlightGlobals.ActiveVessel.vesselType = {FlightGlobals.ActiveVessel.vesselType}\r\n";
                    }
                    values += $"CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA = {(CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA)}";

                    SmUtils.LogMessage(
                        $" in CanShowShipManifest (repeating error).  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}\r\n\r\nValues:  {values}", SmUtils.LogType.Error, true);
                    SMAddon.FrameErrTripped = true;
                }
                return(false);
            }
        }
Beispiel #18
0
 internal static void RepairKerbal(ProtoCrewMember kerbal)
 {
     try
     {
         if (!SMConditions.KerbalIsBroken(kerbal))
         {
             throw new Exception("Tried to repair an unbroken kerbal: " + kerbal.ToString());
         }
         // For now, the only broken Kerbals are "Assigned" but for some reason are still Applicants. So we convert them to Crew.
         kerbal.type = ProtoCrewMember.KerbalType.Crew;
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($" in RepairKerbal.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                            SmUtils.LogType.Error, true);
     }
 }
Beispiel #19
0
        public string SubmitChanges()
        {
            if (NameExists())
            {
                return(SmUtils.Localize("#smloc_module_002")); // "That name is in use!";
            }

            SyncKerbal();

            if (IsNew)
            {
                // Add to roster.
                Kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                HighLogic.CurrentGame.CrewRoster.AddCrewMember(Kerbal);
            }
            return(string.Empty);
        }
Beispiel #20
0
        /// <summary>
        ///   This method is called by WindowTransfer.Xferbutton press.
        /// </summary>
        /// <param name="xferPumps"></param>
        internal static void TransferResources(List <TransferPump> xferPumps)
        {
            try
            {
                if (SMSettings.RealXfers)
                {
                    List <TransferPump> .Enumerator pumps = xferPumps.GetEnumerator();
                    while (pumps.MoveNext())
                    {
                        if (pumps.Current == null)
                        {
                            continue;
                        }
                        TransferPump pump = pumps.Current;
                        pump.IsPumpOn = true;
                    }
                    pumps.Dispose();
                    // now lets start the pumping process...
                    SMAddon.SmVessel.TransferPumps.AddRange(xferPumps);

                    // Start the process.  This flag is checked in SMAddon.Update()
                    TransferPump.PumpProcessOn = true;
                }
                else
                {
                    //Not in Realism mode, so just move the resource...
                    List <TransferPump> .Enumerator pumps = xferPumps.GetEnumerator();
                    while (pumps.MoveNext())
                    {
                        if (pumps.Current == null)
                        {
                            continue;
                        }
                        TransferPump pump = pumps.Current;
                        pump.RunPumpCycle(pump.PumpAmount);
                    }
                    pumps.Dispose();
                }
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage(
                    $" in  ProcessController.TransferResources.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                    SmUtils.LogType.Error, true);
            }
        }
Beispiel #21
0
        internal static void Display(int windowId)
        {
            Title = SmUtils.Localize("#smloc_settings_001");
              // set input locks when mouseover window...
              //_inputLocked = GuiUtils.PreventClickthrough(ShowWindow, Position, _inputLocked);

              // Reset Tooltip active flag...
              ToolTipActive = false;

              Rect rect = new Rect(Position.width - 20, 4, 16, 16);
              // "Close Window.\r\nSettings will not be immediately saved,\r\n but will be remembered while in game.")))
              if (GUI.Button(rect, new GUIContent("", SmUtils.Localize("#smloc_settings_tt_001"))))
              {
            ToolTip = "";
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
              SMAddon.OnSmSettingsClicked();
            else
            {
              SMSettings.MemStoreTempSettings();
              ShowWindow = false;
            }
              }
              if (Event.current.type == EventType.Repaint && ShowToolTips)
            ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);

              GUILayout.BeginVertical();

              DisplayTabButtons();

              _displayViewerPosition = GUILayout.BeginScrollView(_displayViewerPosition, SMStyle.ScrollStyle,
            GUILayout.Height(300), GUILayout.Width(380));
              GUILayout.BeginVertical();

              DisplaySelectedTab(_displayViewerPosition);

              GUILayout.EndVertical();
              GUILayout.EndScrollView();

              DisplayActionButtons();

              GUILayout.EndVertical();

              GUI.DragWindow(new Rect(0, 0, Screen.width, 30));
              SMAddon.RepositionWindow(ref Position);
        }
Beispiel #22
0
        private static void PreLaunchGui()
        {
            try
            {
                if (SMSettings.EnablePfCrews)
                {
                    GUILayout.BeginHorizontal();
                    // Realism Mode is desirable, as there is a cost associated with a kerbal on a flight.   No cheating!
                    if (GUILayout.Button(SmUtils.Localize("#smloc_manifest_005"), SMStyle.ButtonStyle, GUILayout.Width(134), GUILayout.Height(20))) // "Fill Crew"
                    {
                        SMAddon.SmVessel.FillCrew();
                    }
                    if (GUILayout.Button(SmUtils.Localize("#smloc_manifest_006"), SMStyle.ButtonStyle, GUILayout.Width(134), GUILayout.Height(20))) // "Empty Crew"
                    {
                        SMAddon.SmVessel.EmptyCrew();
                    }
                    GUILayout.EndHorizontal();
                }

                if (!SMSettings.EnablePfResources)
                {
                    return;
                }
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(SmUtils.Localize("#smloc_manifest_007"), SMStyle.ButtonStyle, GUILayout.Width(134), GUILayout.Height(20))) // "Fill Resources"
                {
                    SMAddon.SmVessel.FillResources();
                }
                if (GUILayout.Button(SmUtils.Localize("#smloc_manifest_008"), SMStyle.ButtonStyle, GUILayout.Width(134), GUILayout.Height(20))) // "Empty Resources"
                {
                    SMAddon.SmVessel.DumpAllResources();
                }
                GUILayout.EndHorizontal();
            }
            catch (Exception ex)
            {
                if (!SMAddon.FrameErrTripped)
                {
                    SmUtils.LogMessage(
                        $" in PreLaunchGui.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                        SmUtils.LogType.Error, true);
                    SMAddon.FrameErrTripped = true;
                }
            }
        }
 internal void CrewTransferStartAction()
 {
     // This removes the kerbal(s) from the current (source) part(s)
     if (FromCrewMember != null)
     {
         try
         {
             if (FromCrewMember != null)
             {
                 RemoveCrewMember(FromCrewMember, FromPart);
             }
             if (ToCrewMember != null)
             {
                 RemoveCrewMember(ToCrewMember, ToPart);
             }
             //SMAddon.FireEventTriggers();
         }
         catch (Exception ex)
         {
             SmUtils.LogMessage(
                 $"in CrewTransferStartAction.  Error moving crewmember.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                 SmUtils.LogType.Error, true);
         }
     }
     else
     {
         // Must be multi-crew...
         try
         {
             foreach (var xferCrew in CrewMembersToTransfer)
             {
                 //RemoveCrewMember(xferCrew.kerbal, xferCrew.partSource);
             }
             //if (FromCrewMembers != null) RemoveCrewMembers(FromCrewMembers, FromParts);
             //SMAddon.FireEventTriggers();
         }
         catch (Exception ex)
         {
             SmUtils.LogMessage(
                 $"in CrewTransferStartAction.  Error moving crewmember.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                 SmUtils.LogType.Error, true);
         }
     }
 }
Beispiel #24
0
        private static void CreateKerbalViewer()
        {
            DisplaySelectProfession();
            GUILayout.BeginHorizontal();
            // "Create", "Creates a Kerbal with profession selected above.\r\nAdds him/her to the Roster."
            GUIContent guilabel = new GUIContent(SmUtils.Localize("#smloc_roster_003"), SmUtils.Localize("#smloc_roster_tt_002"));

            if (GUILayout.Button(guilabel, GUILayout.MaxWidth(80), GUILayout.Height(20)))
            {
                bool kerbalFound = false;
                ProtoCrewMember.KerbalType kerbalType = KerbalProfession == Professions.Tourist
          ? ProtoCrewMember.KerbalType.Tourist
          : ProtoCrewMember.KerbalType.Crew;
                while (!kerbalFound)
                {
                    SelectedKerbal = ModKerbal.CreateKerbal(kerbalType);
                    if (SelectedKerbal.Trait == KerbalProfession.ToString())
                    {
                        kerbalFound = true;
                    }
                }
                OnCreate = false;
            }
            Rect rect = GUILayoutUtility.GetLastRect();

            if (Event.current.type == EventType.Repaint && ShowToolTips)
            {
                ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);
            }
            //guilabel = new GUIContent("Cancel", "Cancels current creation and exit editor.");
            guilabel = new GUIContent(SmUtils.Localize("#smloc_roster_004"), SmUtils.Localize("#smloc_roster_tt_003"));
            if (GUILayout.Button(guilabel, GUILayout.MaxWidth(80), GUILayout.Height(20)))
            {
                OnCreate       = false;
                SelectedKerbal = null;
            }
            rect = GUILayoutUtility.GetLastRect();
            if (Event.current.type == EventType.Repaint && ShowToolTips)
            {
                ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);
            }
            GUILayout.EndHorizontal();
        }
Beispiel #25
0
        private static void SetupEditButton(ProtoCrewMember kerbal, out string buttonText, out string buttonToolTip)
        {
            GUI.enabled = kerbal.rosterStatus == ProtoCrewMember.RosterStatus.Available && SMSettings.EnableCrewModify;

            //buttonText = SelectedKerbal == null || SelectedKerbal.Kerbal != kerbal ? "Edit" : "Cancel";
            buttonText = SelectedKerbal == null || SelectedKerbal.Kerbal != kerbal?SmUtils.Localize("#smloc_roster_020") : SmUtils.Localize("#smloc_roster_004");

            if (GUI.enabled)
            {
                buttonToolTip = SelectedKerbal == null || SelectedKerbal.Kerbal != kerbal
          ? SmUtils.Localize("#smloc_roster_tt_007")  // "Edit this Kerbal's attributes"
          : SmUtils.Localize("#smloc_roster_tt_008"); // "Cancel any changes to this Kerbal"
            }
            else
            {
                buttonToolTip = kerbal.rosterStatus != ProtoCrewMember.RosterStatus.Available
          ? SmUtils.Localize("#smloc_roster_tt_009")  // "Kerbal is not available at this time.\r\nEditing is disabled";
          : SmUtils.Localize("#smloc_roster_tt_021"); // "Realistic Control is On.\r\nEditing is disabled";
            }
        }
Beispiel #26
0
 internal void CrewTransferStartAction()
 {
     // This removes the kerbal(s) from the current (source) part(s)
     try
     {
         if (FromCrewMember != null)
         {
             RemoveCrewMember(FromCrewMember, FromPart);
         }
         if (ToCrewMember != null)
         {
             RemoveCrewMember(ToCrewMember, ToPart);
         }
         SMAddon.FireEventTriggers();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage(
             $"in CrewTransferStartAction.  Error moving crewmember.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", SmUtils.LogType.Error, true);
     }
 }
 internal static void SetPartHighlight(Part part, Color color)
 {
     if (part == null)
     {
         return;
     }
     try
     {
         if (!part.HighlightActive)
         {
             part.SetHighlight(true, false);
         }
         part.highlightType = Part.HighlightType.AlwaysOn;
         part.SetHighlightColor(color);
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage(
             $" in  SetPartHighlight.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", SmUtils.LogType.Error, true);
     }
 }
Beispiel #28
0
        internal static void ThawKerbal(string kerbalName)
        {
            try
            {
                if (InstalledMods.IsDfApiReady)
                {
                    DfWrapper.KerbalInfo iKerbal = DfWrapper.DeepFreezeApi.FrozenKerbals[kerbalName];

                    List <Part> .Enumerator cryofreezers = SmUtils.GetFreezerParts().GetEnumerator();
                    while (cryofreezers.MoveNext())
                    {
                        if (cryofreezers.Current == null)
                        {
                            continue;
                        }
                        if (cryofreezers.Current.flightID == iKerbal.PartId)
                        {
                            // ReSharper disable once SuspiciousTypeConversion.Global
                            PartModule deepFreezer = SMConditions.GetFreezerModule(cryofreezers.Current);
                            if (deepFreezer != null)
                            {
                                new DfWrapper.DeepFreezer(deepFreezer).BeginThawKerbal(kerbalName);
                            }
                            break;
                        }
                    }
                    cryofreezers.Dispose();
                }
                else
                {
                    SmUtils.LogMessage($"ThawKerbal.  IsDFInstalled:  {InstalledMods.IsDfInstalled}", SmUtils.LogType.Info,
                                       true);
                }
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($" in ThawKerbal.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                                   SmUtils.LogType.Error, true);
            }
        }
Beispiel #29
0
        internal static void Display(int windowId)
        {
            Title = SmUtils.Localize("#smloc_control_001");

            // set input locks when mouseover window...
            //_inputLocked = GuiUtils.PreventClickthrough(ShowWindow, Position, _inputLocked);

            // Reset Tooltip active flag...
            ToolTipActive = false;

            Rect rect = new Rect(Position.width - 20, 4, 16, 16);

            if (GUI.Button(rect, new GUIContent("", SmUtils.Localize("#smloc_window_tt_001")))) // "Close Window"
            {
                ShowWindow = false;
                ToolTip    = "";
            }
            if (Event.current.type == EventType.Repaint && ShowToolTips)
            {
                ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);
            }

            // This is a scroll panel (we are using it to make button lists...)
            GUILayout.BeginVertical();
            DisplayWindowTabs();

            // This is a scroll panel (we are using it to make button lists...)
            _displayViewerPosition = GUILayout.BeginScrollView(_displayViewerPosition, SMStyle.ScrollStyle,
                                                               GUILayout.Height(TabBox.height), GUILayout.Width(TabBox.width));
            DisplaySelectedTab(_displayViewerPosition);
            GUILayout.EndScrollView();

            DisplayTabActions();
            GUILayout.EndVertical();

            GUI.DragWindow(new Rect(0, 0, Screen.width, 30));
            SMAddon.RepositionWindow(ref Position);
        }
 internal static void HighlightClsVessel(bool enabled, bool force = false)
 {
     try
     {
         if (SMAddon.ClsAddon.Vessel == null)
         {
             SMAddon.UpdateClsSpaces();
         }
         if (SMAddon.ClsAddon.Vessel == null)
         {
             return;
         }
         List <ICLSSpace> .Enumerator spaces = SMAddon.ClsAddon.Vessel.Spaces.GetEnumerator();
         while (spaces.MoveNext())
         {
             if (spaces.Current == null)
             {
                 continue;
             }
             List <ICLSPart> .Enumerator parts = spaces.Current.Parts.GetEnumerator();
             while (parts.MoveNext())
             {
                 parts.Current?.Highlight(enabled, force);
             }
             parts.Dispose();
         }
         spaces.Dispose();
     }
     catch (Exception ex)
     {
         if (!SMAddon.FrameErrTripped)
         {
             SmUtils.LogMessage(
                 $" in HighlightCLSVessel (repeating error).  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", SmUtils.LogType.Error, true);
             SMAddon.FrameErrTripped = true;
         }
     }
 }