Esempio n. 1
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.SmTags["#smloc_roster_003"], SmUtils.SmTags["#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.SmTags["#smloc_roster_004"], SmUtils.SmTags["#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();
        }
Esempio n. 2
0
        internal static void Display(int windowId)
        {
            Title = SMUtils.Localize("#smloc_roster_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"
            {
                OnCreate       = false;
                SelectedKerbal = null;
                ToolTip        = "";
                if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
                {
                    SMAddon.OnSmRosterClicked();
                }
                else
                {
                    ShowWindow = false;
                }
            }

            if (Event.current.type == EventType.Repaint && ShowToolTips)
            {
                ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);
            }
            try
            {
                GUILayout.BeginVertical();
                DisplayRosterFilter();

                DisplayRosterListViewer();

                if (OnCreate)
                {
                    CreateKerbalViewer();
                }
                else if (SelectedKerbal != null)
                {
                    EditKerbalViewer();
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUI.enabled = SMSettings.EnableCrewModify;
                    GUIContent guilabel = new GUIContent(SMUtils.Localize("#smloc_roster_002"), GUI.enabled // "Create Kerbal"
            ? SMUtils.Localize("#smloc_roster_tt_001")                                                      // Realistic Control is On.  Create a Kerbal is disabled.
            : SMUtils.Localize("#smloc_roster_tt_022"));                                                    // "Opens the Kerbal creation editor."
                    if (GUILayout.Button(guilabel, GUILayout.MaxWidth(120), GUILayout.Height(20)))
                    {
                        OnCreate = true;
                    }
                    rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && ShowToolTips)
                    {
                        ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);
                    }
                    GUILayout.EndHorizontal();
                    GUI.enabled = true;
                }

                GUILayout.EndVertical();
                GUI.DragWindow(new Rect(0, 0, Screen.width, 30));
                SMAddon.RepositionWindow(ref Position);
            }
            catch (Exception ex)
            {
                SMUtils.LogMessage(string.Format(" in Roster Window.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace),
                                   SMUtils.LogType.Error, true);
            }
        }
Esempio n. 3
0
        private static void EditKerbalViewer()
        {
            //GUILayout.Label(SelectedKerbal.IsNew ? "Create Kerbal" : "Edit Kerbal");
            GUILayout.Label(SelectedKerbal.IsNew ? SMUtils.Localize("#smloc_roster_002") : SMUtils.Localize("#smloc_roster_027"));
            if (SMSettings.EnableKerbalRename)
            {
                GUILayout.BeginHorizontal();
                SelectedKerbal.Name = GUILayout.TextField(SelectedKerbal.Name, GUILayout.MaxWidth(300));
                GUILayout.Label(" - (" + SelectedKerbal.Kerbal.experienceTrait.Title + ")");
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.Label(SelectedKerbal.Name + " - (" + SelectedKerbal.Trait + ")", SMStyle.LabelStyleBold,
                                GUILayout.MaxWidth(300));
            }

            if (!string.IsNullOrEmpty(SMAddon.SaveMessage))
            {
                GUILayout.Label(SMAddon.SaveMessage, SMStyle.ErrorLabelRedStyle);
            }
            if (SMSettings.EnableKerbalRename && SMSettings.EnableChangeProfession)
            {
                DisplaySelectProfession();
            }
            bool isMale = ProtoCrewMember.Gender.Male == SelectedKerbal.Gender;

            GUILayout.BeginHorizontal();
            GUILayout.Label(SMUtils.Localize("#smloc_roster_017"), GUILayout.Width(85)); // "Gender"
            isMale = GUILayout.Toggle(isMale, ProtoCrewMember.Gender.Male.ToString(), GUILayout.Width(90));
            isMale = GUILayout.Toggle(!isMale, ProtoCrewMember.Gender.Female.ToString());
            SelectedKerbal.Gender = isMale ? ProtoCrewMember.Gender.Female : ProtoCrewMember.Gender.Male;
            GUILayout.EndHorizontal();

            GUILayout.Label(SMUtils.Localize("#smloc_roster_029")); // "Courage"
            SelectedKerbal.Courage = GUILayout.HorizontalSlider(SelectedKerbal.Courage, 0, 1, GUILayout.MaxWidth(300));

            GUILayout.Label(SMUtils.Localize("#smloc_roster_030")); // "Stupidity"
            SelectedKerbal.Stupidity = GUILayout.HorizontalSlider(SelectedKerbal.Stupidity, 0, 1, GUILayout.MaxWidth(300));

            SelectedKerbal.Badass = GUILayout.Toggle(SelectedKerbal.Badass, SMUtils.Localize("#smloc_roster_031"), GUILayout.Height(30)); // "Badass"

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(SMUtils.Localize("#smloc_roster_004"), GUILayout.MaxWidth(50))) // "Cancel"
            {
                SelectedKerbal = null;
            }
            string label = SMUtils.Localize("#smloc_roster_028"); // "Apply"
            //string toolTip = "Applies the changes made to this Kerbal.\r\nDesired Name and Profession will be Retained after save.";
            string toolTip = SMUtils.Localize("#smloc_roster_tt_006");

            if (GUILayout.Button(new GUIContent(label, toolTip), GUILayout.MaxWidth(50)))
            {
                if (SMSettings.EnableKerbalRename && SMSettings.EnableChangeProfession)
                {
                    if (SelectedKerbal != null)
                    {
                        SelectedKerbal.Trait = KerbalProfession.ToString();
                    }
                }
                if (SelectedKerbal != null)
                {
                    SMAddon.SaveMessage = SelectedKerbal.SubmitChanges();
                    GetRosterList();
                    if (string.IsNullOrEmpty(SMAddon.SaveMessage))
                    {
                        SelectedKerbal = null;
                    }
                }
            }
            Rect rect = GUILayoutUtility.GetLastRect();

            if (Event.current.type == EventType.Repaint && ShowToolTips)
            {
                ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, 10);
            }
            GUILayout.EndHorizontal();
        }
Esempio n. 4
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);
                }
            }
        }