コード例 #1
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(
                    string.Format("in CrewTransferAction.  Error moving crewmember.  Error:  {0} \r\n\r\n{1}", ex.Message,
                                  ex.StackTrace), SMUtils.LogType.Error, true);
            }
        }
コード例 #2
0
ファイル: WindowRoster.cs プロジェクト: h0yer/ShipManifest
 private static string GetFrozenKerbalDetails(ProtoCrewMember kerbal)
 {
     try
     {
         string rosterDetails = "";
         if (!DFWrapper.APIReady)
         {
             DFWrapper.InitDFWrapper();
         }
         if (DFWrapper.APIReady)
         {
             if (DFWrapper.DeepFreezeAPI.FrozenKerbals.ContainsKey(kerbal.name)) // "Frozen"
             {
                 rosterDetails = string.Format("{0} - {1}", SMUtils.Localize("#smloc_roster_015"),
                                               DFWrapper.DeepFreezeAPI.FrozenKerbals[kerbal.name].vesselName.Replace("(unloaded)", ""));
             }
             else
             {
                 rosterDetails = SMUtils.Localize("#smloc_roster_015"); // "Frozen";
             }
         }
         return(rosterDetails);
     }
     catch (Exception ex)
     {
         if (!SMAddon.FrameErrTripped)
         {
             SMUtils.LogMessage(string.Format(" in GetRosterList().\r\nError:  {0}", ex), SMUtils.LogType.Error, true);
         }
         return(string.Format("{0}:", SMUtils.Localize("#smloc_error_001"))); // "Display Error"
     }
 }
コード例 #3
0
ファイル: CLSClient.cs プロジェクト: h0yer/ShipManifest
        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);
            }
        }
コード例 #4
0
ファイル: WindowRoster.cs プロジェクト: h0yer/ShipManifest
 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(string.Format(" in FreezeKerbal.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                            SMUtils.LogType.Error, true);
     }
 }
コード例 #5
0
ファイル: WindowRoster.cs プロジェクト: h0yer/ShipManifest
        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();
        }
コード例 #6
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(string.Format(" in Savelog.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error,
                                   true);
            }
        }
コード例 #7
0
ファイル: TabScienceLabs.cs プロジェクト: h0yer/ShipManifest
        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;
                    }
                    bool isEnabled = true;

                    step        = "gui enable";
                    GUI.enabled = isEnabled;
                    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.IsMouseOver    = true;
                        SMHighlighter.MouseOverRect  = new Rect(scrollX + rect.x, scrollY + rect.y, rect.width, rect.height);
                        SMHighlighter.MouseOverPart  = iLabs.Current.part;
                        SMHighlighter.MouseOverParts = null;
                    }
                }
                iLabs.Dispose();

                // Display MouseOverHighlighting, if any
                SMHighlighter.MouseOverHighlight();
            }
            catch (Exception ex)
            {
                SMUtils.LogMessage(
                    string.Format(" in Solar Panel Tab at step {0}.  Error:  {1} \r\n\r\n{2}", step, ex.Message, ex.StackTrace),
                    SMUtils.LogType.Error, true);
            }
            GUILayout.EndVertical();
        }
コード例 #8
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);
            }
        }
コード例 #9
0
ファイル: WindowRoster.cs プロジェクト: h0yer/ShipManifest
        private static void DisplayRosterFilter()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(string.Format("{0}:", 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();
        }
コード例 #10
0
ファイル: WindowSettings.cs プロジェクト: h0yer/ShipManifest
        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);
        }
コード例 #11
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(
                        string.Format(" in CanShowShipManifest (repeating error).  Error:  {0} \r\n\r\n{1}\r\n\r\nValues:  {2}",
                                      ex.Message, ex.StackTrace, values), SMUtils.LogType.Error, true);
                    SMAddon.FrameErrTripped = true;
                }
                return(false);
            }
        }
コード例 #12
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);
            }
        }
コード例 #13
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(
                    string.Format(" in  ProcessController.DumpResources.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                    SMUtils.LogType.Error, true);
            }
        }
コード例 #14
0
ファイル: SMHighlighter.cs プロジェクト: h0yer/ShipManifest
        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(string.Format(" in SMHighlighter.MouseOverHighlight at step {0}.  Error:  {1}", step, ex),
                                   SMUtils.LogType.Error, true);
            }
        }
コード例 #15
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(
                    string.Format(" in  ProcessController.TransferResources.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                    SMUtils.LogType.Error, true);
            }
        }
コード例 #16
0
ファイル: WindowRoster.cs プロジェクト: h0yer/ShipManifest
 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(string.Format("Error in GetRosterList().\r\nError:  {0}", ex), SMUtils.LogType.Error, true);
     }
 }
コード例 #17
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(
                        string.Format(" in PreLaunchGui.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                        SMUtils.LogType.Error, true);
                    SMAddon.FrameErrTripped = true;
                }
            }
        }
コード例 #18
0
ファイル: WindowRoster.cs プロジェクト: h0yer/ShipManifest
        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";
            }
        }
コード例 #19
0
ファイル: SMHighlighter.cs プロジェクト: h0yer/ShipManifest
 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(
             string.Format(" in  SetPartHighlight.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true);
     }
 }
コード例 #20
0
ファイル: WindowRoster.cs プロジェクト: h0yer/ShipManifest
        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(string.Format("ThawKerbal.  IsDFInstalled:  {0}", InstalledMods.IsDfInstalled), SMUtils.LogType.Info,
                                       true);
                }
            }
            catch (Exception ex)
            {
                SMUtils.LogMessage(string.Format(" in ThawKerbal.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                                   SMUtils.LogType.Error, true);
            }
        }
コード例 #21
0
ファイル: WindowRoster.cs プロジェクト: h0yer/ShipManifest
        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;
                while (!kerbalFound)
                {
                    SelectedKerbal = ModKerbal.CreateKerbal();
                    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();
        }
コード例 #22
0
ファイル: SMHighlighter.cs プロジェクト: h0yer/ShipManifest
 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(
                 string.Format(" in HighlightCLSVessel (repeating error).  Error:  {0} \r\n\r\n{1}", ex.Message,
                               ex.StackTrace), SMUtils.LogType.Error, true);
             SMAddon.FrameErrTripped = true;
         }
     }
 }
コード例 #23
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(
             string.Format("in CrewTransferStartAction.  Error moving crewmember.  Error:  {0} \r\n\r\n{1}", ex.Message,
                           ex.StackTrace), SMUtils.LogType.Error, true);
     }
 }
コード例 #24
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(200), GUILayout.Width(380));
            DisplaySelectedTab(_displayViewerPosition);
            GUILayout.EndScrollView();

            DisplayTabActions();
            GUILayout.EndVertical();

            GUI.DragWindow(new Rect(0, 0, Screen.width, 30));
            SMAddon.RepositionWindow(ref Position);
        }
コード例 #25
0
ファイル: SMHighlighter.cs プロジェクト: h0yer/ShipManifest
 internal static void SetPartsHighlight(List <Part> parts, Color color, bool force = false)
 {
     try
     {
         List <Part> .Enumerator list = parts.GetEnumerator();
         while (list.MoveNext())
         {
             if (list.Current == null)
             {
                 continue;
             }
             if (!list.Current.HighlightActive || force)
             {
                 SetPartHighlight(list.Current, color);
             }
         }
         list.Dispose();
     }
     catch (Exception ex)
     {
         SMUtils.LogMessage(
             string.Format(" in  SetPartsHighlight.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true);
     }
 }
コード例 #26
0
        internal static void ResolveResourcePartSelections(List <string> resourceNames)
        {
            try
            {
                if (resourceNames.Count > 0)
                {
                    List <Part> newSources = new List <Part>();
                    List <Part> newTargets = new List <Part>();
                    if (WindowTransfer.ShowSourceVessels &&
                        SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources))
                    {
                        SMAddon.SmVessel.SelectedPartsSource =
                            SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsSource, resourceNames);
                        if (!WindowTransfer.ShowTargetVessels)
                        {
                            List <Part> .Enumerator srcParts = SMAddon.SmVessel.SelectedPartsSource.GetEnumerator();
                            while (srcParts.MoveNext())
                            {
                                if (srcParts.Current == null)
                                {
                                    continue;
                                }
                                if (!SMAddon.SmVessel.SelectedPartsTarget.Contains(srcParts.Current))
                                {
                                    continue;
                                }
                                SMAddon.SmVessel.SelectedPartsTarget.Remove(srcParts.Current);
                            }
                            srcParts.Dispose();
                        }
                    }
                    else
                    {
                        List <Part> .Enumerator parts = SMAddon.SmVessel.SelectedPartsSource.GetEnumerator();
                        while (parts.MoveNext())
                        {
                            if (parts.Current == null)
                            {
                                continue;
                            }
                            if (resourceNames.Count > 1)
                            {
                                if (parts.Current.Resources.Contains(resourceNames[0]) && parts.Current.Resources.Contains(resourceNames[1]))
                                {
                                    newSources.Add(parts.Current);
                                }
                            }
                            else
                            {
                                if (resourceNames[0] == SMConditions.ResourceType.Crew.ToString() && parts.Current.CrewCapacity > 0)
                                {
                                    newSources.Add(parts.Current);
                                }
                                else if (resourceNames[0] == SMConditions.ResourceType.Science.ToString() &&
                                         parts.Current.FindModulesImplementing <IScienceDataContainer>().Count > 0)
                                {
                                    newSources.Add(parts.Current);
                                }
                                else if (parts.Current.Resources.Contains(resourceNames[0]))
                                {
                                    newSources.Add(parts.Current);
                                }
                            }
                        }
                        parts.Dispose();
                        SMAddon.SmVessel.SelectedPartsSource.Clear();
                        SMAddon.SmVessel.SelectedPartsSource = newSources;
                    }

                    if (WindowTransfer.ShowTargetVessels &&
                        SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources))
                    {
                        SMAddon.SmVessel.SelectedPartsTarget =
                            SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsTarget, resourceNames);
                        if (!WindowTransfer.ShowSourceVessels)
                        {
                            List <Part> .Enumerator tgtParts = SMAddon.SmVessel.SelectedPartsTarget.GetEnumerator();
                            while (tgtParts.MoveNext())
                            {
                                if (tgtParts.Current == null)
                                {
                                    continue;
                                }
                                if (!SMAddon.SmVessel.SelectedPartsSource.Contains(tgtParts.Current))
                                {
                                    continue;
                                }
                                SMAddon.SmVessel.SelectedPartsSource.Remove(tgtParts.Current);
                            }
                            tgtParts.Dispose();
                        }
                    }
                    else
                    {
                        List <Part> .Enumerator tgtParts = SMAddon.SmVessel.SelectedPartsTarget.GetEnumerator();
                        while (tgtParts.MoveNext())
                        {
                            if (tgtParts.Current == null)
                            {
                                continue;
                            }
                            if (resourceNames.Count > 1)
                            {
                                if (tgtParts.Current.Resources.Contains(resourceNames[0]) && tgtParts.Current.Resources.Contains(resourceNames[1]))
                                {
                                    newTargets.Add(tgtParts.Current);
                                }
                            }
                            else
                            {
                                if (resourceNames[0] == SMConditions.ResourceType.Crew.ToString() && tgtParts.Current.CrewCapacity > 0)
                                {
                                    newTargets.Add(tgtParts.Current);
                                }
                                else if (resourceNames[0] == SMConditions.ResourceType.Science.ToString() &&
                                         tgtParts.Current.FindModulesImplementing <IScienceDataContainer>().Count > 0)
                                {
                                    newTargets.Add(tgtParts.Current);
                                }
                                else if (tgtParts.Current.Resources.Contains(resourceNames[0]))
                                {
                                    newTargets.Add(tgtParts.Current);
                                }
                            }
                        }
                        tgtParts.Dispose();
                        SMAddon.SmVessel.SelectedPartsTarget.Clear();
                        SMAddon.SmVessel.SelectedPartsTarget = newTargets;
                    }

                    if (SMConditions.AreSelectedResourcesTypeOther(resourceNames))
                    {
                        TransferPump.CreateDisplayPumps();
                        return;
                    }

                    SMAddon.SmVessel.SelectedVesselsSource.Clear();
                    SMAddon.SmVessel.SelectedVesselsTarget.Clear();
                }
                else
                {
                    SMAddon.SmVessel.SelectedPartsSource.Clear();
                    SMAddon.SmVessel.SelectedPartsTarget.Clear();
                    SMAddon.SmVessel.SelectedVesselsSource.Clear();
                    SMAddon.SmVessel.SelectedVesselsTarget.Clear();
                }
            }
            catch (Exception ex)
            {
                SMUtils.LogMessage(
                    string.Format(" in WindowManifest.ReconcileSelectedXferParts.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                    SMUtils.LogType.Error, true); // in, Error
            }
        }
コード例 #27
0
        private static void WindowToggleButtons()
        {
            GUILayout.BeginHorizontal();

            GUIStyle settingsStyle = WindowSettings.ShowWindow ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle;

            if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_012"), settingsStyle, GUILayout.Height(20))) // "Settings"
            {
                try
                {
                    WindowSettings.ShowWindow = !WindowSettings.ShowWindow;
                    if (WindowSettings.ShowWindow)
                    {
                        // Store settings in case we cancel later...
                        SMSettings.MemStoreTempSettings();
                    }
                }
                catch (Exception ex)
                {
                    SMUtils.LogMessage(
                        string.Format(" opening Settings Window.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error,
                        true);
                }
            }

            GUIStyle rosterStyle = WindowRoster.ShowWindow ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle;

            if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_013"), rosterStyle, GUILayout.Height(20))) // "Roster"
            {
                try
                {
                    WindowRoster.ShowWindow = !WindowRoster.ShowWindow;
                    if (WindowRoster.ShowWindow)
                    {
                        WindowRoster.GetRosterList();
                    }
                    else
                    {
                        WindowRoster.SelectedKerbal = null;
                        WindowRoster.ToolTip        = "";
                    }
                }
                catch (Exception ex)
                {
                    SMUtils.LogMessage(
                        string.Format(" opening Roster Window.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error,
                        true);
                }
            }

            GUIStyle controlStyle = WindowControl.ShowWindow ? SMStyle.ButtonToggledStyle : SMStyle.ButtonStyle;

            if (GUILayout.Button(SMUtils.Localize("#smloc_manifest_014"), controlStyle, GUILayout.Height(20))) // "Control"
            {
                try
                {
                    WindowControl.ShowWindow = !WindowControl.ShowWindow;
                }
                catch (Exception ex)
                {
                    SMUtils.LogMessage(
                        string.Format(" opening Control Window.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error,
                        true);
                }
            }
            GUILayout.EndHorizontal();
        }
コード例 #28
0
        internal static void Display(int windowId)
        {
            Title = string.Format("{0} {1} - {2}", SMUtils.Localize("#smloc_manifest_002"), SMSettings.CurVersion, SMAddon.SmVessel.Vessel.vesselName);

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

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

            //GUIContent label = new GUIContent("", "Close Window");
            GUIContent label = new GUIContent("", SMUtils.Localize("#smloc_window_tt_001"));

            if (SMConditions.IsTransferInProgress())
            {
                //label = new GUIContent("", "Action in progress.  Cannot close window");
                label       = new GUIContent("", SMUtils.Localize("#smloc_window_tt_002"));
                GUI.enabled = false;
            }
            Rect rect = new Rect(Position.width - 20, 4, 16, 16);

            if (GUI.Button(rect, label))
            {
                SMAddon.OnSmButtonClicked();
                ToolTip = "";
                SMHighlighter.Update_Highlighter();
            }
            if (Event.current.type == EventType.Repaint && ShowToolTips)
            {
                ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);
            }
            GUI.enabled = true;
            try
            {
                GUILayout.BeginVertical();
                _smScrollViewerPosition = GUILayout.BeginScrollView(_smScrollViewerPosition, SMStyle.ScrollStyle,
                                                                    GUILayout.Height(100), GUILayout.Width(300));
                GUILayout.BeginVertical();

                // Prelaunch (landed) Gui
                if (SMConditions.IsInPreflight())
                {
                    PreLaunchGui();
                }

                // Now the Resource Buttons
                ResourceButtonsList();

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

                //string resLabel = "No Resource Selected";
                string resLabel = SMUtils.Localize("#smloc_manifest_003");
                if (SMAddon.SmVessel.SelectedResources.Count == 1)
                {
                    resLabel = SMAddon.SmVessel.SelectedResources[0];
                }
                else if (SMAddon.SmVessel.SelectedResources.Count == 2)
                {
                    //resLabel = "Multiple Resources selected";
                    resLabel = SMUtils.Localize("#smloc_manifest_004");
                }
                GUILayout.Label(string.Format("{0}", resLabel), GUILayout.Width(300), GUILayout.Height(20));

                // Resource Details List Viewer
                ResourceDetailsViewer();

                // Window toggle Button List
                WindowToggleButtons();

                GUILayout.EndVertical();
                GUI.DragWindow(new Rect(0, 0, Screen.width, 30));
                SMAddon.RepositionWindow(ref Position);
            }
            catch (Exception ex)
            {
                if (!SMAddon.FrameErrTripped)
                {
                    SMUtils.LogMessage(
                        string.Format(" in WindowManifest.Display.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                        SMUtils.LogType.Error, true);
                    SMAddon.FrameErrTripped = true;
                }
            }
        }
コード例 #29
0
        private static void ResourceDetailsViewer()
        {
            try
            {
                _resourceScrollViewerPosition = GUILayout.BeginScrollView(_resourceScrollViewerPosition, SMStyle.ScrollStyle,
                                                                          GUILayout.Height(100), GUILayout.Width(300));
                GUILayout.BeginVertical();

                if (SMAddon.SmVessel.SelectedResources.Count > 0)
                {
                    List <Part> .Enumerator pParts = SMAddon.SmVessel.SelectedResourcesParts.GetEnumerator();
                    while (pParts.MoveNext())
                    {
                        if (pParts.Current == null)
                        {
                            continue;
                        }
                        Part part = pParts.Current;
                        if (SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources))
                        {
                            GUIStyle noWrap = SMStyle.LabelStyleNoWrap;
                            GUILayout.Label(string.Format("{0}", part.partInfo.title), noWrap, GUILayout.Width(265),
                                            GUILayout.Height(18));
                            GUIStyle noPad = SMStyle.LabelStyleNoPad;
                            List <string> .Enumerator sResources = SMAddon.SmVessel.SelectedResources.GetEnumerator();
                            while (sResources.MoveNext())
                            {
                                if (sResources.Current == null)
                                {
                                    continue;
                                }
                                GUILayout.Label(
                                    string.Format(" - {0}:  ({1:######0.####}/{2:######0.####})", sResources.Current, part.Resources[sResources.Current].amount, part.Resources[sResources.Current].maxAmount), noPad, GUILayout.Width(265),
                                    GUILayout.Height(16));
                            }
                            sResources.Dispose();
                        }
                        else if (SMAddon.SmVessel.SelectedResources.Contains(SMConditions.ResourceType.Crew.ToString()))
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Label(
                                string.Format("{0}, ({1}/{2})", part.partInfo.title, SMUtils.GetPartCrewCount(part), part.CrewCapacity),
                                GUILayout.Width(265), GUILayout.Height(20));
                            GUILayout.EndHorizontal();
                        }
                        else if (SMAddon.SmVessel.SelectedResources.Contains(SMConditions.ResourceType.Science.ToString()))
                        {
                            int         scienceCount = 0;
                            IEnumerator pModules     = part.Modules.GetEnumerator();
                            while (pModules.MoveNext())
                            {
                                if (pModules.Current == null)
                                {
                                    continue;
                                }
                                PartModule             pm        = (PartModule)pModules.Current;
                                ModuleScienceContainer container = pm as ModuleScienceContainer;
                                if (container != null)
                                {
                                    scienceCount += container.GetScienceCount();
                                }
                                else if (pm is ModuleScienceExperiment)
                                {
                                    scienceCount += ((ModuleScienceExperiment)pm).GetScienceCount();
                                }
                            }
                            GUILayout.BeginHorizontal();
                            GUILayout.Label(string.Format("{0}, ({1})", part.partInfo.title, scienceCount), GUILayout.Width(265));
                            GUILayout.EndHorizontal();
                        }
                    }
                    pParts.Dispose();
                }
            }
            catch (Exception ex)
            {
                if (!SMAddon.FrameErrTripped)
                {
                    SMUtils.LogMessage(
                        string.Format(" in WindowManifest.ResourceDetailsViewer.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                        SMUtils.LogType.Error, true); // in, Error
                    SMAddon.FrameErrTripped = true;
                }
            }
            GUILayout.EndVertical();
            GUILayout.EndScrollView();
        }
コード例 #30
0
        private static void ResourceButtonToggled(string resourceName)
        {
            try
            {
                if (SMConditions.IsTransferInProgress())
                {
                    return;
                }

                // First, lets clear any highlighting...
                SMHighlighter.ClearResourceHighlighting(SMAddon.SmVessel.SelectedResourcesParts);

                // Now let's update our lists...
                SMAddon.SmVessel.RefreshLists();
                if (!SMAddon.SmVessel.SelectedResources.Contains(resourceName))
                {
                    // now lets determine what to do with selection
                    if (SMConditions.ResourceIsSingleton(resourceName))
                    {
                        SMAddon.SmVessel.SelectedResources.Clear();
                        SMAddon.SmVessel.SelectedResources.Add(resourceName);
                    }
                    else
                    {
                        if (SMConditions.ResourcesContainSingleton(SMAddon.SmVessel.SelectedResources))
                        {
                            SMAddon.SmVessel.SelectedResources.Clear();
                            SMAddon.SmVessel.SelectedResources.Add(resourceName);
                        }
                        else if (SMAddon.SmVessel.SelectedResources.Count > 1)
                        {
                            SMAddon.SmVessel.SelectedResources.RemoveRange(0, 1);
                            SMAddon.SmVessel.SelectedResources.Add(resourceName);
                        }
                        else
                        {
                            SMAddon.SmVessel.SelectedResources.Add(resourceName);
                        }
                    }
                }
                else if (SMAddon.SmVessel.SelectedResources.Contains(resourceName))
                {
                    SMAddon.SmVessel.SelectedResources.Remove(resourceName);
                }

                // Now, refresh the resources parts list
                SMAddon.SmVessel.GetSelectedResourcesParts();

                // now lets reconcile the selected parts based on the new list of resources...
                ResolveResourcePartSelections(SMAddon.SmVessel.SelectedResources);

                // Now, based on the resourceselection, do we show the Transfer window?
                WindowTransfer.ShowWindow = SMAddon.SmVessel.SelectedResources.Count > 0;
            }
            catch (Exception ex)
            {
                SMUtils.LogMessage(
                    string.Format(" in WindowManifest.ResourceButtonToggled.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                    SMUtils.LogType.Error, true); // in, Error
            }
            SMAddon.SmVessel.RefreshLists();
        }