Exemplo n.º 1
0
        /// <summary>
        /// Updates an individual resource entry with the critters found.
        /// </summary>
        /// <param name="entry">The entry to update.</param>
        /// <param name="quantity">The quantity of this critter which is present.</param>
        private static void UpdateEntry(ResourceEntry entry, CritterTotals quantity)
        {
            var trEntry = Traverse.Create(entry);
            // Update the tool tip text
            var tooltip = trEntry.GetField <ToolTip>("tooltip");

            if (tooltip != null)
            {
                tooltip.OnToolTip = null;
                tooltip.toolTip   = CritterInventoryUtils.FormatTooltip(entry.NameLabel.text,
                                                                        quantity);
            }
            // Determine the color for the labels
            var color = trEntry.GetField <Color>("AvailableColor");

            if (quantity.Available <= 0)
            {
                color = trEntry.GetField <Color>("UnavailableColor");
            }
            LocText qLabel = entry.QuantityLabel, nLabel = entry.NameLabel;

            if (qLabel.color != color)
            {
                qLabel.color = color;
            }
            if (nLabel.color != color)
            {
                nLabel.color = color;
            }
            // Add up overall totals
            qLabel.SetText(quantity.Available.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates a critter resource category header.
        /// </summary>
        /// <param name="header">The category header to update.</param>
        /// <param name="type">The critter type it contains (can be pulled from the CritterResourceInfo component).</param>
        public static void Update(this ResourceCategoryHeader header, CritterType type)
        {
            var totals = DictionaryPool <Tag, CritterTotals, ResourceCategoryHeader> .Allocate();

            var all        = CritterInventoryUtils.FindCreatures(totals, type);
            var discovered = header.ResourcesDiscovered;
            var trCategory = Traverse.Create(header);

            // Previously discovered but now extinct critters need an empty entry
            foreach (var pair in discovered)
            {
                var species = pair.Key;
                if (!totals.ContainsKey(species))
                {
                    totals.Add(species, new CritterTotals());
                }
            }
            // Go through resource entries for each species and update them
            foreach (var pair in totals)
            {
                var quantity = pair.Value;
                var species  = pair.Key;
                // Look up the species to see if we have found it already
                if (!discovered.TryGetValue(species, out ResourceEntry entry))
                {
                    entry = trCategory.CallMethod <ResourceEntry>("NewResourceEntry",
                                                                  species, GameUtil.MeasureUnit.quantity);
                    entry.SetName(species.ProperName());
                    // Add component to tag it as wild/tame
                    entry.gameObject.AddComponent <CritterResourceInfo>().CritterType = type;
                    discovered.Add(species, entry);
                }
                UpdateEntry(entry, quantity);
            }
            bool anyDiscovered = discovered.Count > 0;

            // Enable display and open/close based on critter presence
            header.elements.QuantityText.SetText(all.Available.ToString());
            trCategory.CallMethod("SetActiveColor", all.HasAny);
            trCategory.CallMethod("SetInteractable", anyDiscovered);
            // Still need to set this for expand/contract to work
            trCategory.SetField("anyDiscovered", anyDiscovered);
            // Update category tooltip
            var tooltip = trCategory.GetField <ToolTip>("tooltip");

            if (tooltip != null)
            {
                tooltip.OnToolTip = null;
                tooltip.toolTip   = CritterInventoryUtils.FormatTooltip(header.elements.
                                                                        LabelText.text, all);
            }
            // Disabled until coolazura's tags are up to date
#if false
            FavoritesCategoryCompat(totals, type);
#endif
            totals.Recycle();
        }