Пример #1
0
        /// <summary>
        /// Manages compatibility with Favorites Category.
        ///
        /// This method is quite hacky.
        /// </summary>
        /// <param name="totals">The totals calculated from Update.</param>
        public static void FavoritesCategoryCompat(IDictionary <Tag, CritterTotals> totals,
                                                   CritterType type)
        {
            ResourceCategoryHeader favCategory = null;
            var favTag = TagManager.Create("Favorites", "Favorites");

            if ((ResourceCategoryScreen.Instance?.DisplayedCategories?.TryGetValue(favTag,
                                                                                   out favCategory) ?? false) && favCategory != null)
            {
                // Favorites Category is installed
                foreach (var pair in favCategory.ResourcesDiscovered)
                {
                    var species      = pair.Key;
                    var entry        = pair.Value;
                    var intendedType = entry.gameObject.GetComponent <CritterResourceInfo>();
                    if (totals.TryGetValue(species, out CritterTotals quantity) &&
                        intendedType != null && intendedType.CritterType == type)
                    {
                        // A critter in Favorites Category
                        UpdateEntry(entry, quantity);
                        entry.SetName("{0} ({1})".F(species.ProperName(), type));
                    }
                }
            }
        }
Пример #2
0
 private void Update()
 {
     if (!((UnityEngine.Object)WorldInventory.Instance == (UnityEngine.Object)null))
     {
         if (HideTarget.minHeight != targetContentHideHeight)
         {
             float minHeight = HideTarget.minHeight;
             float num       = targetContentHideHeight - minHeight;
             num                 *= HideSpeedFactor * Time.unscaledDeltaTime;
             minHeight           += num;
             HideTarget.minHeight = minHeight;
         }
         for (int i = 0; i < 1; i++)
         {
             Tag tag = DisplayedCategoryKeys[categoryUpdatePacer];
             ResourceCategoryHeader resourceCategoryHeader = DisplayedCategories[tag];
             if (WorldInventory.Instance.IsDiscovered(tag) && !resourceCategoryHeader.gameObject.activeInHierarchy)
             {
                 resourceCategoryHeader.gameObject.SetActive(true);
             }
             resourceCategoryHeader.UpdateContents();
             categoryUpdatePacer = (categoryUpdatePacer + 1) % DisplayedCategoryKeys.Length;
         }
         if (HiderButton.CurrentState != 0)
         {
             targetContentHideHeight = Mathf.Min(512f, CategoryContainer.rectTransform().rect.height);
         }
         if ((UnityEngine.Object)MeterScreen.Instance != (UnityEngine.Object)null && !MeterScreen.Instance.StartValuesSet)
         {
             MeterScreen.Instance.InitializeValues();
         }
     }
 }
			/// <summary>
			/// Applied before UpdateContents runs.
			/// </summary>
			/// <param name="__instance">The current resource category header.</param>
			internal static bool Prefix(ResourceCategoryHeader __instance) {
				var info = __instance.gameObject.GetComponent<CritterResourceInfo>();
				// UpdateContents adds spurious entries (e.g. babies when only adults ever
				// discovered) on critters
				if (info != null)
					__instance.Update(info.CritterType);
				return info == null;
			}
Пример #4
0
 private void CreateTagSetHeaders(IEnumerable <Tag> set, GameUtil.MeasureUnit measure)
 {
     foreach (Tag item in set)
     {
         ResourceCategoryHeader value = NewCategoryHeader(item, measure);
         DisplayedCategories.Add(item, value);
     }
 }
Пример #5
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();
        }
Пример #6
0
    private ResourceCategoryHeader NewCategoryHeader(Tag categoryTag, GameUtil.MeasureUnit measure)
    {
        GameObject gameObject = Util.KInstantiateUI(Prefab_CategoryBar, CategoryContainer.gameObject, false);

        gameObject.name = "CategoryHeader_" + categoryTag.Name;
        ResourceCategoryHeader component = gameObject.GetComponent <ResourceCategoryHeader>();

        component.SetTag(categoryTag, measure);
        return(component);
    }
Пример #7
0
            /// <summary>
            /// Applied after Hover runs.
            /// </summary>
            internal static void Postfix(ResourceCategoryHeader __instance,
                                         bool is_hovering, Color ___highlightColour)
            {
                var info = __instance.GetComponent <CritterResourceHeader>();

                if (info != null)
                {
                    info.HighlightAllMatching(is_hovering ? ___highlightColour : Color.black);
                }
            }
Пример #8
0
 /// <summary>
 /// Activates a resource category heading.
 /// </summary>
 /// <param name="header">The heading to activate.</param>
 public static void Activate(this ResourceCategoryHeader header)
 {
     if (header != null)
     {
         var go = header.gameObject;
         if (!go.activeInHierarchy)
         {
             go.SetActive(true);
         }
     }
 }
Пример #9
0
            /// <summary>
            /// Applied before RefreshChart runs.
            /// </summary>
            internal static bool Prefix(ResourceCategoryHeader __instance,
                                        GameObject ___sparkChart)
            {
                var info = __instance.GetComponent <CritterResourceHeader>();

                if (info != null)
                {
                    info.UpdateChart(___sparkChart);
                }
                return(info == null);
            }
Пример #10
0
        /// <summary>
        /// Creates a new resource entry.
        /// </summary>
        /// <param name="parent">The parent category of the entry.</param>
        /// <param name="species">The critter species of this entry.</param>
        /// <param name="type">The critter type of this entry.</param>
        /// <returns>The created resource entry (already added to the resource list).</returns>
        private static ResourceEntry NewResourceEntry(ResourceCategoryHeader parent,
                                                      Tag species, CritterType type)
        {
            var re = Util.KInstantiateUI(parent.Prefab_ResourceEntry, parent.
                                         EntryContainer.gameObject, true);
            var entry = re.GetComponent <ResourceEntry>();

            entry.SetTag(species, GameUtil.MeasureUnit.quantity);
            entry.SetName(species.ProperNameStripLink());
            // Add component to tag it as wild/tame
            re.AddComponent <CritterResourceEntry>().CritterType = type;
            return(entry);
        }
			/// <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);
					});
				}
			}
Пример #12
0
            /// <summary>
            /// Applied before UpdateContents runs.
            /// </summary>
            internal static bool Prefix(ResourceCategoryHeader __instance,
                                        ref bool ___anyDiscovered)
            {
                var info = __instance.GetComponent <CritterResourceHeader>();

                // UpdateContents adds spurious entries (e.g. babies when only adults ever
                // discovered) on critters so it must be skipped
                if (info != null)
                {
                    info.UpdateHeader(ref ___anyDiscovered);
                }
                return(info == null);
            }
Пример #13
0
    protected override void OnActivate()
    {
        base.OnActivate();
        Instance           = this;
        ConsumeMouseScroll = true;
        MultiToggle hiderButton = HiderButton;

        hiderButton.onClick = (System.Action)Delegate.Combine(hiderButton.onClick, new System.Action(OnHiderClick));
        CreateTagSetHeaders(GameTags.MaterialCategories, GameUtil.MeasureUnit.mass);
        CreateTagSetHeaders(GameTags.CalorieCategories, GameUtil.MeasureUnit.kcal);
        CreateTagSetHeaders(GameTags.UnitCategories, GameUtil.MeasureUnit.quantity);
        if (!DisplayedCategories.ContainsKey(GameTags.Miscellaneous))
        {
            ResourceCategoryHeader value = NewCategoryHeader(GameTags.Miscellaneous, GameUtil.MeasureUnit.mass);
            DisplayedCategories.Add(GameTags.Miscellaneous, value);
        }
        DisplayedCategoryKeys = DisplayedCategories.Keys.ToArray();
    }