Exemple #1
0
 internal void EmptyCrew()
 {
     List <Part> .Enumerator parts = PartsByResource[SMConditions.ResourceType.Crew.ToString()].GetEnumerator();
     while (parts.MoveNext())
     {
         if (parts.Current == null)
         {
             continue;
         }
         for (int i = parts.Current.protoModuleCrew.Count - 1; i >= 0; i--)
         {
             TransferCrew.RemoveCrewMember(parts.Current.protoModuleCrew[i], parts.Current);
         }
         SMAddon.FireEventTriggers();
     }
     parts.Dispose();
 }
Exemple #2
0
        private static void DisplayRosterListViewer()
        {
            try
            {
                GUILayout.BeginVertical();
                // Roster List Header...
                GUILayout.BeginHorizontal();
                //GUILayout.Label("", GUILayout.Width(5));
                GUILayout.Label(SMUtils.Localize("#smloc_roster_016"), GUILayout.Width(140)); // "Name"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_017"), GUILayout.Width(50));  // "Gender"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_005"), GUILayout.Width(70));  // "Profession"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_018"), GUILayout.Width(30));  // "Skill"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_019"), GUILayout.Width(220)); // "Status"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_020"), GUILayout.Width(55));  // "Edit"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_021"), GUILayout.Width(65));  // "Action"
                GUILayout.EndHorizontal();

                _scrollViewerPosition = GUILayout.BeginScrollView(_scrollViewerPosition, SMStyle.ScrollStyle,
                                                                  GUILayout.Height(230), GUILayout.Width(680));

                // vars for acton to occurs after button press
                bool            isAction     = false;
                Part            actionPart   = null;
                string          actionText   = "";
                ProtoCrewMember actionKerbal = null;

                List <ProtoCrewMember> .Enumerator kerbals = RosterList.GetEnumerator();
                while (kerbals.MoveNext())
                {
                    if (kerbals.Current == null)
                    {
                        continue;
                    }
                    if (!CanDisplayKerbal(kerbals.Current))
                    {
                        continue;
                    }
                    GUIStyle labelStyle;
                    if (kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Dead ||
                        kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Missing)
                    {
                        labelStyle = SMStyle.LabelStyleRed;
                    }
                    else if (kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
                    {
                        labelStyle = SMStyle.LabelStyleYellow;
                    }
                    else
                    {
                        labelStyle = SMStyle.LabelStyle;
                    }

                    // What vessel is this Kerbal Assigned to?
                    string rosterDetails = "";
                    if (kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
                    {
                        List <Vessel> .Enumerator theseVessels = FlightGlobals.Vessels.GetEnumerator();
                        while (theseVessels.MoveNext())
                        {
                            if (theseVessels.Current == null)
                            {
                                continue;
                            }
                            List <ProtoCrewMember> crew = theseVessels.Current.GetVesselCrew();
                            if (crew.Any(crewMember => crewMember == kerbals.Current))
                            {
                                rosterDetails = string.Format("{0} - {1}", SMUtils.Localize("#smloc_roster_011"), theseVessels.Current.GetName().Replace("(unloaded)", "")); // "Assigned"
                            }
                        }
                        theseVessels.Dispose();
                    }
                    else if (InstalledMods.IsDfInstalled && DFWrapper.APIReady && kerbals.Current.type == ProtoCrewMember.KerbalType.Unowned)
                    {
                        // This kerbal could be frozen.  Lets find out...
                        rosterDetails = GetFrozenKerbalDetails(kerbals.Current);
                        labelStyle    = SMStyle.LabelStyleCyan;
                    }
                    else
                    {
                        // Since the kerbal has no vessel assignment, lets show what their status...
                        rosterDetails = kerbals.Current.rosterStatus.ToString();
                    }
                    string buttonText;
                    string buttonToolTip;
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(kerbals.Current.name, labelStyle, GUILayout.Width(140), GUILayout.Height(20));
                    GUILayout.Label(kerbals.Current.gender.ToString(), labelStyle, GUILayout.Width(50));
                    GUILayout.Label(kerbals.Current.experienceTrait.Title, labelStyle, GUILayout.Width(70));
                    GUILayout.Label(kerbals.Current.experienceLevel.ToString(), labelStyle, GUILayout.Width(30));
                    GUILayout.Label(rosterDetails, labelStyle, GUILayout.Width(215));

                    SetupEditButton(kerbals.Current, out buttonText, out buttonToolTip);
                    if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(55), GUILayout.Height(20),
                                         GUILayout.Height(20)))
                    {
                        if (SelectedKerbal == null || SelectedKerbal.Kerbal != kerbals.Current)
                        {
                            SelectedKerbal = new ModKerbal(kerbals.Current, false);
                            SetProfessionFlag();
                        }
                        else
                        {
                            SelectedKerbal = null;
                        }
                    }
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && ShowToolTips)
                    {
                        ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, XOffset);
                    }

                    // Setup buttons with gui state, button text and tooltip.
                    SetupActionButton(kerbals.Current, out buttonText, out buttonToolTip);

                    if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(65), GUILayout.Height(20)))
                    {
                        isAction     = true;
                        actionKerbal = kerbals.Current;
                        actionText   = buttonText;
                        if (actionText == SMUtils.Localize("#smloc_roster_022")) // "Remove"
                        {
                            actionPart = SMAddon.SmVessel.FindPartByKerbal(kerbals.Current);
                        }
                    }
                    Rect rect2 = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && ShowToolTips)
                    {
                        ToolTip = SMToolTips.SetActiveToolTip(rect2, GUI.tooltip, ref ToolTipActive, XOffset);
                    }
                    GUILayout.EndHorizontal();
                    GUI.enabled = true;
                }
                kerbals.Dispose();
                GUILayout.EndVertical();
                GUILayout.EndScrollView();

                // perform action from button press.
                if (!isAction)
                {
                    return;
                }
                if (actionText == SMUtils.Localize("#smloc_roster_022")) // "Remove"
                {
                    TransferCrew.RemoveCrewMember(actionKerbal, actionPart);
                }
                else if (actionText == SMUtils.Localize("#smloc_roster_023")) // "Add"
                {
                    TransferCrew.AddCrewMember(actionKerbal, SMAddon.SmVessel.SelectedPartsSource[0]);
                }
                else if (actionText == SMUtils.Localize("#smloc_roster_024")) // "Respawn"
                {
                    RespawnKerbal(actionKerbal);
                }
                else if (actionText == SMUtils.Localize("#smloc_roster_025")) // "Thaw"
                {
                    ThawKerbal(actionKerbal.name);
                }
                else if (actionText == SMUtils.Localize("#smloc_roster_026"))// "Freeze"
                {
                    FreezeKerbal(actionKerbal);
                }
                SMAddon.FireEventTriggers();
            }
            catch (Exception ex)
            {
                if (!SMAddon.FrameErrTripped)
                {
                    SMUtils.LogMessage(string.Format(" in RosterListViewer.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true);
                }
            }
        }