/// <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()); }
/// <summary> /// Updates the contents of the critter inventory. /// </summary> public void Render200ms(float _) { int id = GetWorldID(); var clusterManager = ClusterManager.Instance; if (clusterManager != null && clusterManager.activeWorldId == id) { // Reset existing count to zero foreach (var typePair in counts) { foreach (var speciesPair in typePair.Value) { var species = speciesPair.Value; species.Reserved = 0; species.Total = 0; } } discovered = false; CritterInventoryUtils.GetCritters(id, AddCritter); var inst = AllResourcesScreen.Instance; if (discovered && inst != null) { inst.Populate(null); } } }
/// <summary> /// Applied after OnClick runs. /// </summary> /// <param name="__instance">The current resource entry.</param> /// <param name="___selectionIdx">The current selection index.</param> internal static void Postfix(ResourceEntry __instance, ref int ___selectionIdx) { var info = __instance.gameObject.GetComponentSafe <CritterResourceInfo>(); if (info != null) { var creaturesOfType = ListPool <CreatureBrain, ResourceCategoryHeader> . Allocate(); CritterType type = info.CritterType; var species = __instance.Resource; // Get a list of creatures that match this type CritterInventoryUtils.IterateCreatures((creature) => { if (creature.PrefabID() == species && type.Matches(creature)) { creaturesOfType.Add(creature); } }); int count = creaturesOfType.Count; if (count > 0) { // Rotate through valid indexes // Select the object and center it PUtil.CenterAndSelect(creaturesOfType[___selectionIdx++ % count]); } creaturesOfType.Recycle(); } }
/// <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(); }
/// <summary> /// Applied after Hover runs. /// </summary> /// <param name="__instance">The current resource entry.</param> /// <param name="is_hovering">true if the user is hovering, or false otherwise</param> /// <param name="___HighlightColor">The highlight color from the instance.</param> internal static void Postfix(ResourceEntry __instance, bool is_hovering, Color ___HighlightColor) { var info = __instance.gameObject.GetComponent<CritterResourceInfo>(); if (info != null) { var hlc = ___HighlightColor; CritterType type = info.CritterType; Tag species = __instance.Resource; CritterInventoryUtils.IterateCreatures((creature) => { if (creature.PrefabID() == species && type.Matches(creature)) PUtil.HighlightEntity(creature, is_hovering ? hlc : Color.black); }); } }
/// <summary> /// Applied after Hover runs. /// </summary> /// <param name="__instance">The current resource category header.</param> /// <param name="is_hovering">true if the user is hovering, or false otherwise.</param> /// <param name="___highlightColour">The highlight color from the instance.</param> internal static void Postfix(ResourceCategoryHeader __instance, bool is_hovering, Color ___highlightColour) { var info = __instance.gameObject.GetComponent<CritterResourceInfo>(); if (info != null) { CritterType type = info.CritterType; // It is a creature header, highlight all matching CritterInventoryUtils.IterateCreatures((creature) => { if (type.Matches(creature)) PUtil.HighlightEntity(creature, is_hovering ? ___highlightColour : Color.black); }); } }
/// <summary> /// Updates the contents of the critter inventory. /// </summary> public void Update() { // Reset existing count to zero foreach (var typePair in counts) { foreach (var speciesPair in typePair.Value) { var species = speciesPair.Value; species.Reserved = 0; species.Total = 0; } } discovered = false; CritterInventoryUtils.GetCritters(GetWorldID(), AddCritter); var inst = AllResourcesScreen.Instance; if (discovered && inst != null) { inst.Populate(null); } }