コード例 #1
0
        static bool Prefix(SGBarracksRosterList __instance, List <SGBarracksRosterSlot> inventory)
        {
            if (ModState.SimGameState == null)
            {
                return(true);                               // Only patch if we're in SimGame
            }
            // TODO: Apply a logical sort here
            Mod.Log.Info?.Write($"Sorting {inventory?.Count} pilot slots");

            List <SGBarracksRosterSlot> sortedSlots = new List <SGBarracksRosterSlot>(inventory);

            sortedSlots.Sort(SGBarracksRosterSlotComparisons.CompareByCrewTypeAndValue);

            int index = 0;

            foreach (SGBarracksRosterSlot slot in sortedSlots)
            {
                Mod.Log.Debug?.Write($" -- pilot: {slot.Pilot.Name} has index: {index}");
                slot.gameObject.transform.SetSiblingIndex(index);
                index++;
            }

            __instance.ForceRefreshImmediate();

            return(false);
        }
コード例 #2
0
            public static void Postfix(SGBarracksRosterList __instance, Dictionary <string, SGBarracksRosterSlot> ___currentRoster)
            {
                foreach (var pilot in ___currentRoster.Values)
                {
                    var timeoutIcon = pilot.GetComponentsInChildren <RectTransform>(true)
                                      .FirstOrDefault(x => x.name == "mw_TimeOutIcon");
                    if (timeoutIcon == null)
                    {
                        return;
                    }

                    if (!AdjustedIcons.Contains(timeoutIcon))
                    {
                        if (pilot.Pilot.pilotDef.PilotTags.Contains("pilot_fatigued"))
                        {
                            AdjustedIcons.Add(timeoutIcon);
                            // mw_TimeOutIcon (SVGImporter.SVGImage)
                            timeoutIcon.sizeDelta        /= SizeDeltaFactor;
                            timeoutIcon.anchoredPosition += AnchoredPositionOffset;
                        }
                    }
                    else
                    {
                        if (!pilot.Pilot.pilotDef.PilotTags.Contains("pilot_fatigued"))
                        {
                            AdjustedIcons.Remove(timeoutIcon);
                            timeoutIcon.sizeDelta        *= SizeDeltaFactor;
                            timeoutIcon.anchoredPosition -= AnchoredPositionOffset;
                        }
                    }
                }

                __instance.ForceRefreshImmediate();
            }
コード例 #3
0
            public static void Postfix(SGBarracksRosterList __instance)
            {
                SGBarracksWidget b  = Traverse.Create(__instance).Field("barracks").GetValue <SGBarracksWidget>();
                ScrollRect       sr = b?.gameObject?.GetComponentInChildren <ScrollRect>(false);

                if (sr != null)
                {
                    Log($"setting barracks scroll {m_rosterScroll}");
                    sr.verticalNormalizedPosition = Mathf.Clamp(m_rosterScroll, 0f, 1f);
                }
            }
コード例 #4
0
        static bool Prefix(SGBarracksRosterList __instance, LocalizableText ___mechWarriorCount)
        {
            if (ModState.SimGameState == null)
            {
                return(true);                               // Only patch if we're in SimGame
            }
            int usedBerths = CrewHelper.UsedBerths(ModState.SimGameState.PilotRoster);

            Mod.Log.Debug?.Write($"Berths => used: {usedBerths}  available: {ModState.SimGameState.GetMaxMechWarriors()}");

            string text = new Localize.Text(Mod.LocalizedText.Labels[ModText.LT_Crew_Berths_Used],
                                            new object[] { usedBerths, ModState.SimGameState.GetMaxMechWarriors() }).ToString();

            ___mechWarriorCount.SetText(text);

            return(false);
        }
コード例 #5
0
        static bool Prefix(SGBarracksRosterList __instance,
                           Pilot pilot, UnityAction <SGBarracksRosterSlot> pilotSelectedOnClick, bool isInHireHall,
                           Dictionary <string, SGBarracksRosterSlot> ___currentRoster)
        {
            if (ModState.SimGameState == null)
            {
                return(true);                               // Only patch if we're in SimGame
            }
            Mod.Log.Debug?.Write($"Adding pilot {pilot.Callsign} to roster list.");

            if (!___currentRoster.ContainsKey(pilot.GUID))
            {
                SGBarracksRosterSlot slot = __instance.GetSlot();
                if (isInHireHall)
                {
                    slot.InitNoDrag(pilot, ModState.SimGameState, pilotSelectedOnClick, showTheCost: true);
                    slot.SetDraggable(isDraggable: false);

                    // Update the pilot's contract end date
                    CrewDetails details = ModState.GetCrewDetails(pilot.pilotDef);
                    details.ExpirationDay = ModState.SimGameState.DaysPassed + details.ContractTerm;
                    Mod.Log.Debug?.Write($"  - pilot's contract ends on day: {details.ExpirationDay}");
                    ModState.UpdateOrCreateCrewDetails(pilot.pilotDef, details);
                }
                else
                {
                    slot.Init(pilot, __instance, pilotSelectedOnClick);
                }
                ___currentRoster.Add(pilot.GUID, slot);
                slot.AddToRadioSet(__instance.listRadioSet);

                // Performance tweak; skip
                //ForceRefreshImmediate();
            }

            return(false);
        }