Exemplo n.º 1
0
        /// <summary>
        /// Cycles through critters of this type.
        /// </summary>
        internal void OnCycleThrough()
        {
            int id       = ClusterManager.Instance.activeWorldId;
            var matching = ListPool <KPrefabID, PinnedCritterEntry> .Allocate();

            var type = CritterType;

            // Compile a list of critters matching this species
            CritterInventoryUtils.GetCritters(id, (kpid) => {
                if (kpid.GetCritterType() == type)
                {
                    matching.Add(kpid);
                }
            }, Species);
            int n = matching.Count;

            if (selectionIndex >= n)
            {
                selectionIndex = 0;
            }
            else
            {
                selectionIndex = (selectionIndex + 1) % n;
            }
            if (n > 0)
            {
                PGameUtils.CenterAndSelect(matching[selectionIndex]);
            }
            matching.Recycle();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called to select and center the mismatched wires.
        /// </summary>
        private void OnFindMismatched()
        {
            var enet = GetNetwork();

            if (wire != null && enet != null)
            {
                var wattageRating = wire.MaxWattageRating;
                // Just locate the first wire with a mismatched wattage that is less than
                // this wire and select it
                foreach (var badWire in enet.allWires)
                {
                    if (badWire.MaxWattageRating < wattageRating && badWire != wire)
                    {
                        PGameUtils.CenterAndSelect(badWire);
                        break;
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called to select and center the mismatched pipes.
        /// </summary>
        private void OnFindMismatched()
        {
            var cnet = GetNetwork();

            if (pe != null && cnet != null)
            {
                var element = pe.ElementID;
                var type    = conduit.ConduitType;
                foreach (var conduit in cnet.conduits)
                {
                    var otherPE = conduit.GameObject.GetComponentSafe <PrimaryElement>();
                    if (((otherPE != null && otherPE.ElementID != element) || conduit.
                         ConduitType != type) && otherPE != pe)
                    {
                        PGameUtils.CenterAndSelect(otherPE);
                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
            /// <summary>
            /// Applied before OnClick runs.
            /// </summary>
            internal static bool Prefix(ResourceEntry __instance, ref int ___selectionIdx)
            {
                var  entry = __instance.gameObject.GetComponentSafe <CritterResourceEntry>();
                bool cont  = entry == null;

                if (!cont)
                {
                    var creaturesOfType = entry.CachedCritters;
                    // Build list if empty
                    entry.UpdateLastClick();
                    if (creaturesOfType == null)
                    {
                        creaturesOfType = entry.PopulateCache();
                        entry.StartCoroutine(entry.ClearCacheAfterThreshold());
                    }
                    int count = creaturesOfType.Count;
                    if (count > 0)
                    {
                        // Rotate through valid indexes
                        PGameUtils.CenterAndSelect(creaturesOfType[___selectionIdx++ % count]);
                    }
                }
                return(cont);
            }