Пример #1
0
        private void changeKerbalIcon(KSP.UI.CrewListItem cic)
        {
            if (cic.GetCrewRef() == null)
            {
                return;
            }

            ConfigNode data = null;

            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("KERBALRENAMER"))
            {
                data = node;
            }
            List <Culture> ctemp = new List <Culture>();

            ConfigNode[] cultureclub = data.GetNodes("Culture");
            for (int i = 0; i < cultureclub.Length; i++)
            {
                Culture c = new Culture(cultureclub[i]);
                ctemp.Add(c);
            }
            Culture[] cultures = ctemp.ToArray();

            FlightLog.Entry flight = cic.GetCrewRef().flightLog.Entries.FirstOrDefault(e => e.type == KerbalRenamer.Instance.cultureDescriptor);
            if (flight != null)
            {
                FieldInfo fi      = typeof(KSP.UI.CrewListItem).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(c => c.FieldType == typeof(RawImage));
                RawImage  image   = (RawImage)fi.GetValue(cic);
                Culture   culture = Randomizer.getCultureByName(flight.target, cultures);
                if (culture != null)
                {
                    image.texture = (Texture)GameDatabase.Instance.GetTexture("KerbalRenamer/Icons/" + culture.cultureName, false);
                }
            }
        }
Пример #2
0
 private void changeKerbalIcon(KSP.UI.CrewListItem cic)
 {
     if ((object)cic.GetCrewRef() == null)
     {
         return;
     }
     FlightLog.Entry flight = cic.GetCrewRef().flightLog.Entries.FirstOrDefault(e => e.type == KerbalRenamer.Instance.cultureDescriptor);
     if ((object)flight != null)
     {
         FieldInfo fi      = typeof(KSP.UI.CrewListItem).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(c => c.FieldType == typeof(RawImage));
         RawImage  foo     = (RawImage)fi.GetValue(cic);
         Culture   culture = KerbalRenamer.Instance.getCultureByName(flight.target);
         if ((object)culture != null)
         {
             foo.texture = (Texture)GameDatabase.Instance.GetTexture("KerbalRenamer/Icons/" + culture.cultureName, false);
         }
     }
 }
Пример #3
0
        protected void FixTooltip(KSP.UI.CrewListItem cli)
        {
            ProtoCrewMember pcm = cli.GetCrewRef();
            double          retTime;

            if (retirementEnabled && kerbalRetireTimes.TryGetValue(pcm.name, out retTime))
            {
                cli.SetTooltip(pcm);
                KSP.UI.TooltipTypes.TooltipController_CrewAC ttc = cliTooltip.GetValue(cli) as KSP.UI.TooltipTypes.TooltipController_CrewAC;
                ttc.descriptionString += "\n\nRetires no earlier than " + KSPUtil.PrintDate(retTime, false);

                // Training

                string trainingStr = GetTrainingString(pcm);
                if (!string.IsNullOrEmpty(trainingStr))
                {
                    ttc.descriptionString += trainingStr;
                }
            }
        }
Пример #4
0
 public void RebuildCrewAssignmentDialogue(KSP.UI.CrewListItem.ButtonTypes type, KSP.UI.CrewListItem cic)
 {
     StartCoroutine(CallbackUtil.DelayedCallback(1, BuildCrewAssignmentDialogue));
 }
Пример #5
0
 public void RebuildAstronautComplex(KSP.UI.CrewListItem.ButtonTypes type, KSP.UI.CrewListItem cic)
 {
     StartCoroutine(CallbackUtil.DelayedCallback(1, BuildAstronautComplex));
 }
Пример #6
0
        public void Update()
        {
            if (HighLogic.CurrentGame == null || HighLogic.CurrentGame.CrewRoster == null)
            {
                return;
            }

            // Catch earlies
            if (firstLoad)
            {
                firstLoad = false;
                List <string> newHires = new List <string>();

                foreach (ProtoCrewMember pcm in HighLogic.CurrentGame.CrewRoster.Crew)
                {
                    if ((pcm.rosterStatus == ProtoCrewMember.RosterStatus.Assigned || pcm.rosterStatus == ProtoCrewMember.RosterStatus.Available) && !kerbalRetireTimes.ContainsKey(pcm.name))
                    {
                        newHires.Add(pcm.name);
                        OnCrewHired(pcm, int.MinValue);
                    }
                }
                if (newHires.Count > 0)
                {
                    string msgStr = "Crew will retire as follows:";
                    foreach (string s in newHires)
                    {
                        msgStr += "\n" + s + ", no earlier than " + KSPUtil.PrintDate(kerbalRetireTimes[s], false);
                    }

                    PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
                                                 new Vector2(0.5f, 0.5f),
                                                 "InitialRetirementDateNotification",
                                                 "Initial Retirement Date",
                                                 msgStr
                                                 + "\n(Retirement will be delayed the more interesting flights they fly.)",
                                                 "OK",
                                                 false,
                                                 HighLogic.UISkin);
                }
            }

            // Retirements
            double time = Planetarium.GetUniversalTime();

            if (nextUpdate < time)
            {
                // Ensure that CrewHandler updates happen at predictable times so that accurate KAC alarms can be set.
                do
                {
                    nextUpdate += updateInterval;
                }while (nextUpdate < time);

                if (retirementEnabled)
                {
                    foreach (KeyValuePair <string, double> kvp in kerbalRetireTimes)
                    {
                        ProtoCrewMember pcm = HighLogic.CurrentGame.CrewRoster[kvp.Key];
                        if (pcm == null)
                        {
                            toRemove.Add(kvp.Key);
                        }
                        else
                        {
                            if (pcm.rosterStatus != ProtoCrewMember.RosterStatus.Available)
                            {
                                if (pcm.rosterStatus != ProtoCrewMember.RosterStatus.Assigned)
                                {
                                    toRemove.Add(kvp.Key);
                                }

                                continue;
                            }

                            if (pcm.inactive)
                            {
                                continue;
                            }

                            if (time > kvp.Value)
                            {
                                toRemove.Add(kvp.Key);
                                retirees.Add(kvp.Key);
                                pcm.rosterStatus = ProtoCrewMember.RosterStatus.Dead;
                            }
                        }
                    }
                }

                bool anyCourseEnded = false;
                for (int i = ActiveCourses.Count; i-- > 0;)
                {
                    ActiveCourse course = ActiveCourses[i];
                    if (course.ProgressTime(time)) //returns true when the course completes
                    {
                        ActiveCourses.RemoveAt(i);
                        anyCourseEnded = true;
                    }
                }

                for (int i = expireTimes.Count; i-- > 0;)
                {
                    TrainingExpiration e = expireTimes[i];
                    if (time > e.expiration)
                    {
                        ProtoCrewMember pcm = HighLogic.CurrentGame.CrewRoster[e.pcmName];
                        if (pcm != null)
                        {
                            for (int j = pcm.careerLog.Entries.Count; j-- > 0;)
                            {
                                int eC = e.entries.Count;
                                if (eC == 0)
                                {
                                    break;
                                }
                                FlightLog.Entry ent = pcm.careerLog[j];
                                for (int k = eC; k-- > 0;)
                                {
                                    // Allow only mission trainings to expire.
                                    // This check is actually only needed for old savegames as only these can have expirations on proficiencies.
                                    if (ent.type == "TRAINING_mission" && e.Compare(k, ent))
                                    {
                                        ScreenMessages.PostScreenMessage(pcm.name + ": Expired: " + GetPrettyCourseName(ent.type) + ent.target);
                                        ent.type = "expired_" + ent.type;
                                        e.entries.RemoveAt(k);
                                    }
                                }
                            }
                        }
                        expireTimes.RemoveAt(i);
                    }
                }

                // TODO remove from courses? Except I think they won't retire if inactive either so that's ok.
                if (toRemove.Count > 0)
                {
                    string msgStr = string.Empty;
                    foreach (string s in toRemove)
                    {
                        kerbalRetireTimes.Remove(s);
                        if (HighLogic.CurrentGame.CrewRoster[s] != null)
                        {
                            msgStr += "\n" + s;
                        }
                    }
                    if (!string.IsNullOrEmpty(msgStr))
                    {
                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
                                                     new Vector2(0.5f, 0.5f),
                                                     "CrewRetirementNotification",
                                                     "Crew Retirement",
                                                     "The following retirements have occurred:\n" + msgStr,
                                                     "OK",
                                                     true,
                                                     HighLogic.UISkin);
                    }

                    toRemove.Clear();
                }

                if (anyCourseEnded || toRemove.Count > 0)
                {
                    MaintenanceHandler.Instance.UpdateUpkeep();
                }
            }

            // UI fixing
            if (inAC)
            {
                if (astronautComplex == null)
                {
                    KSP.UI.Screens.AstronautComplex[] mbs = GameObject.FindObjectsOfType <KSP.UI.Screens.AstronautComplex>();
                    int maxCount = -1;
                    foreach (KSP.UI.Screens.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 (KSP.UI.UIListData <KSP.UI.UIListItem> u in astronautComplex.ScrollListAvailable)
                    {
                        KSP.UI.CrewListItem cli = u.listItem.GetComponent <KSP.UI.CrewListItem>();
                        if (cli != null)
                        {
                            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 (KSP.UI.UIListData <KSP.UI.UIListItem> u in astronautComplex.ScrollListAssigned)
                    {
                        KSP.UI.CrewListItem cli = u.listItem.GetComponent <KSP.UI.CrewListItem>();
                        if (cli != null)
                        {
                            FixTooltip(cli);
                        }
                    }

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