Exemplo n.º 1
0
        private void LateUpdate()
        {
            if (!astronautComplexSpawned || updateDone)
            {
                return;
            }
            // ReSharper disable once Unity.PerformanceCriticalCodeInvocation
            // ReSharper disable once Unity.PerformanceCriticalCodeInvocation;
            List <CrewListItem> crewToOverwrite = GetCrewToOverwrite(FindObjectsOfType <CrewListItem>().ToList());

            if (HighLogic.CurrentGame.CrewRoster.GetAvailableCrewCount() == 0)
            {
                updateDone = true;
            }
            // ReSharper disable once Unity.PerformanceCriticalCodeInvocation
            Debug.Log("[EarnYourStripes]: Attempting to override AstronautComplex UI");
            for (int i = 0; i < crewToOverwrite.Count; i++)
            {
                CrewListItem    crewContainer = crewToOverwrite.ElementAt(i);
                ProtoCrewMember p             = crewContainer.GetCrewRef();
                string          kerbalName    = p.name;
                double          flightTime    = FlightTrackerApi.Instance.GetRecordedMissionTimeSeconds(kerbalName);
                kerbalName = p.name + " (" + ConvertUtToString(flightTime) + " hrs)";
                if (crewContainer.GetName() == kerbalName)
                {
                    updateDone = true;
                }
                if (p.rosterStatus == ProtoCrewMember.RosterStatus.Available)
                {
                    crewContainer.SetName(kerbalName);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return value positive means left > right, return value negative means left < right
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        static int UIList_Cmp(UIListItem left, UIListItem right)
        {
            CrewListItem ldata = null;
            CrewListItem rdata = null;

            try { ldata = left.GetComponent <CrewListItem>(); } catch { return(1); }
            try { rdata = right.GetComponent <CrewListItem>(); } catch { return(-1); }

#if DEBUG
            if (ldata == null)
            {
                return(1);
            }
            if (rdata == null)
            {
                return(-1);
            }
#endif

            bool ltourist = ldata.GetCrewRef().type == ProtoCrewMember.KerbalType.Tourist;
            bool rtourist = rdata.GetCrewRef().type == ProtoCrewMember.KerbalType.Tourist;

            if (ltourist && !rtourist)
            {
                return(1);
            }                                        // tourists are also sorted to the end
            if (!ltourist && rtourist)
            {
                return(-1);
            }                                         // tourists are also sorted to the end

            return(ldata.GetName().CompareTo(rdata.GetName()));
        }
Exemplo n.º 3
0
        static void UIList_DebugPrint(UIList list, int li, int ri, string msg)
        {
#if DEBUG
            string outmsg = msg + " -- ";

            for (int i = li; i < ri + 1; i++)
            {
                UIListItem   curitem = list.GetUilistItemAt(i);
                CrewListItem crew    = curitem.GetComponent <CrewListItem>();
                outmsg = outmsg + crew.GetName().Split(' ')[0] + "[" + i.ToString() + "], ";
            }

            print(outmsg);
#endif
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sorts Kerbals, but first checks the list to make sure it's not already sorted.
        /// Overall, this ends up using more resources than just blind-sorting, but in cases
        /// where the list is almost always going to be correctly sorted, it may save some time.
        /// </summary>
        /// <returns>success</returns>
        static public bool Sort_Kerbals_If_Needed()
        {
            if (CrewAssignmentDialog.Instance == null)
            {
                print("OnEditorCrewOpened has no CrewAssignmentDialog yet...");
                return(false);
            }
            else
            {
                UIList avail    = CrewAssignmentDialog.Instance.scrollListAvail;
                bool   unsorted = false;

                int i = 0;
                for (; i < (avail.Count - 1); i++)
                {
                    UIListItem   li   = avail.GetUilistItemAt(i);
                    UIListItem   li2  = avail.GetUilistItemAt(i + 1);
                    CrewListItem crew = li.GetComponent <CrewListItem>();
                    if (UIList_Cmp(li, li2) > 0)
                    {
                        unsorted = true;

                        break;
                    }
                }

                if (unsorted)
                {
                    print("Change in Kerbal List detected, re-sorting");
#if DEBUG
                    print("Sort_If_Needed: Sort IS needed due to i = " + i.ToString());
                    for (i = 0; i < avail.Count; i++)
                    {
                        UIListItem   li   = avail.GetUilistItemAt(i);
                        CrewListItem crew = li.GetComponent <CrewListItem>();
                        print("BEFORE SORT = " + crew.GetName());
                    }
#endif
                    Sort_Kerbals();
                }
                return(true);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sorts the kerbals in the CrewAssignmentDialog
        /// Will not work on dialogs that do not use the CrewAssignmentDialog GUI element
        /// </summary>
        /// <returns>success</returns>
        static public bool Sort_Kerbals()
        {
            if (CrewAssignmentDialog.Instance == null)
            {
                print("OnEditorCrewOpened has no CrewAssignmentDialog yet...");
            }
            else
            {
                UIList avail = CrewAssignmentDialog.Instance.scrollListAvail;

                UIList_QSort(avail, 0, avail.Count - 1);

#if DEBUG
                for (int i = 0; i < avail.Count; i++)
                {
                    UIListItem   li   = avail.GetUilistItemAt(i);
                    CrewListItem crew = li.GetComponent <CrewListItem>();
                    print("AFTER SORT = " + crew.GetName());
                }
#endif

                return(true);

                /*
                 * for (int i = 0; i < comps.Length; ++i)
                 * {
                 *  print($"Component {i}: {comps[i].GetType()}");
                 * }
                 *
                 * foreach (Component comp in firstdata)
                 * {
                 *  print("Got a component");
                 *  print("Component name is " + comp.name);
                 *  print("Component type is " + comp.GetType().Name);
                 *  print("Component string is " + comp.ToString());
                 * }
                 */
            }


            return(false);
        }
Exemplo n.º 6
0
        private void FixAstronauComplexUI()
        {
            if (_astronautComplex == null)
            {
                AstronautComplex[] mbs = FindObjectsOfType <AstronautComplex>();
                int maxCount           = -1;
                foreach (AstronautComplex c in mbs)
                {
                    int count = c.ScrollListApplicants.Count + c.ScrollListAssigned.Count + c.ScrollListAvailable.Count + c.ScrollListKia.Count;
                    if (count > maxCount)
                    {
                        maxCount          = count;
                        _astronautComplex = c;
                    }
                }

                if (_astronautComplex == null)
                {
                    return;
                }
            }
            int newAv   = _astronautComplex.ScrollListAvailable.Count;
            int newAsgn = _astronautComplex.ScrollListAssigned.Count;
            int newKIA  = _astronautComplex.ScrollListKia.Count;

            if (newAv != _countAvailable || newKIA != _countKIA || newAsgn != _countAssigned)
            {
                _countAvailable = newAv;
                _countAssigned  = newAsgn;
                _countKIA       = newKIA;

                foreach (UIListData <UIListItem> u in _astronautComplex.ScrollListAvailable)
                {
                    CrewListItem cli = u.listItem.GetComponent <CrewListItem>();
                    if (cli == null)
                    {
                        continue;
                    }

                    FixTooltip(cli);
                    if (cli.GetCrewRef().inactive)
                    {
                        cli.MouseoverEnabled = false;
                        bool notTraining = true;
                        for (int i = ActiveCourses.Count; i-- > 0 && notTraining;)
                        {
                            foreach (ProtoCrewMember pcm in ActiveCourses[i].Students)
                            {
                                if (pcm == cli.GetCrewRef())
                                {
                                    notTraining = false;
                                    cli.SetLabel("Training, done " + KSPUtil.PrintDate(ActiveCourses[i].startTime + ActiveCourses[i].GetTime(ActiveCourses[i].Students), false));
                                    break;
                                }
                            }
                        }
                        if (notTraining)
                        {
                            cli.SetLabel("Recovering");
                        }
                    }
                }

                foreach (UIListData <UIListItem> u in _astronautComplex.ScrollListAssigned)
                {
                    CrewListItem cli = u.listItem.GetComponent <CrewListItem>();
                    if (cli != null)
                    {
                        FixTooltip(cli);
                    }
                }

                foreach (UIListData <UIListItem> u in _astronautComplex.ScrollListKia)
                {
                    CrewListItem cli = u.listItem.GetComponent <CrewListItem>();
                    if (cli != null)
                    {
                        if (_retirees.Contains(cli.GetName()))
                        {
                            cli.SetLabel("Retired");
                            cli.MouseoverEnabled = false;
                        }
                    }
                }
            }
        }