Exemplo n.º 1
0
        /// <summary>
        /// Applied before GetStressedMinions runs.
        /// </summary>
        internal static bool Prefix(MeterScreen __instance, ref IList <MinionIdentity> __result)
        {
            var stressAmount = Db.Get().Amounts.Stress;
            var duplicants   = __instance.GetWorldMinionIdentities();
            var result       = CACHED_LIST;
            int n            = duplicants.Count;
            var byStress     = ListPool <StressEntry, MeterScreen> .Allocate();

            result.Clear();
            // The previous comparer looked up the stress on every comparison!
            for (int i = 0; i < n; i++)
            {
                var duplicant = duplicants[i];
                if (!duplicant.IsNullOrDestroyed())
                {
                    // These are equatable structs which will not allocate (owned by byStress)
                    byStress.Add(new StressEntry(duplicant, stressAmount.Lookup(duplicant).
                                                 value));
                }
            }
            byStress.Sort();
            for (int i = 0; i < n; i++)
            {
                // Copies the struct on deref, but using an array would require reallocation
                // every time the count changes
                result.Add(byStress[i].identity);
            }
            byStress.Recycle();
            __result = result;
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Applied before RefreshMinions runs.
        /// </summary>
        internal static bool Prefix(MeterScreen __instance)
        {
            int living         = Components.LiveMinionIdentities.Count;
            int identities     = __instance.GetWorldMinionIdentities().Count;
            var currentMinions = __instance.currentMinions;
            var tt             = __instance.MinionsTooltip;

            if (identities != __instance.cachedMinionCount && currentMinions != null && tt !=
                null)
            {
                string         ttText;
                WorldContainer activeWorld;
                __instance.cachedMinionCount = identities;
                string alive = living.ToString();
                if (DlcManager.FeatureClusterSpaceEnabled() && (activeWorld = ClusterManager.
                                                                              Instance.activeWorld) != null && activeWorld.TryGetComponent(
                        out ClusterGridEntity world))
                {
                    var    text = CACHED_BUILDER;
                    string ids  = identities.ToString();
                    text.Clear().Append(STRINGS.UI.TOOLTIPS.METERSCREEN_POPULATION_CLUSTER);
                    ttText = text.Replace("{0}", world.Name).Replace("{1}", ids).Replace(
                        "{2}", alive).ToString();
                    text.Clear().Append(ids).Append('/').Append(alive);
                    currentMinions.SetText(text);
                }
                else
                {
                    ttText = STRINGS.UI.TOOLTIPS.METERSCREEN_POPULATION.Format(alive);
                    currentMinions.SetText(alive);
                }
                tt.ClearMultiStringTooltip();
                tt.AddMultiStringTooltip(ttText, __instance.ToolTipStyle_Header);
            }
            return(false);
        }