private void LoadSpawnerCategories(UnityEngine.Object[] allAssets) { foreach (ItemSpawnerCategoryDefinitions newLoadedCats in allAssets) { foreach (ItemSpawnerCategoryDefinitions.Category newCategory in newLoadedCats.Categories) { OtherLogger.Log("Loading New ItemSpawner Category! Name (" + newCategory.DisplayName + "), Value (" + newCategory.Cat + ")", OtherLogger.LogType.Loading); //If the loaded categories already contains this new category, we want to add subcategories if (IM.CDefs.Categories.Any(o => o.Cat == newCategory.Cat)) { OtherLogger.Log("Category already exists! Adding subcategories", OtherLogger.LogType.Loading); foreach (ItemSpawnerCategoryDefinitions.Category currentCat in IM.CDefs.Categories) { if (currentCat.Cat == newCategory.Cat) { foreach (ItemSpawnerCategoryDefinitions.SubCategory newSubCat in newCategory.Subcats) { //Only add this new subcategory if it is unique if (!IM.CDefSubInfo.ContainsKey(newSubCat.Subcat)) { OtherLogger.Log("Adding subcategory: " + newSubCat.DisplayName, OtherLogger.LogType.Loading); List <ItemSpawnerCategoryDefinitions.SubCategory> currSubCatList = currentCat.Subcats.ToList(); currSubCatList.Add(newSubCat); currentCat.Subcats = currSubCatList.ToArray(); IM.CDefSubs[currentCat.Cat].Add(newSubCat); if (!IM.CDefSubInfo.ContainsKey(newSubCat.Subcat)) { IM.CDefSubInfo.Add(newSubCat.Subcat, newSubCat); } if (!IM.SCD.ContainsKey(newSubCat.Subcat)) { IM.SCD.Add(newSubCat.Subcat, new List <ItemSpawnerID>()); } } else { OtherLogger.LogWarning("SubCategory type is already being used, and SubCategory will not be added! Make sure your subcategory is using a unique type! SubCategory Type: " + newSubCat.Subcat); } } } } } //If new category, we can just add the whole thing else { OtherLogger.Log("This is a new primary category", OtherLogger.LogType.Loading); List <ItemSpawnerCategoryDefinitions.Category> currentCatsList = IM.CDefs.Categories.ToList(); currentCatsList.Add(newCategory); IM.CDefs.Categories = currentCatsList.ToArray(); OtherLogger.Log("Num CDefs: " + IM.CDefs.Categories.Length, OtherLogger.LogType.Loading); if (!IM.CDefSubs.ContainsKey(newCategory.Cat)) { IM.CDefSubs.Add(newCategory.Cat, new List <ItemSpawnerCategoryDefinitions.SubCategory>()); } if (!IM.CDefInfo.ContainsKey(newCategory.Cat)) { IM.CDefInfo.Add(newCategory.Cat, newCategory); } if (!IM.CD.ContainsKey(newCategory.Cat)) { IM.CD.Add(newCategory.Cat, new List <ItemSpawnerID>()); } foreach (ItemSpawnerCategoryDefinitions.SubCategory newSubCat in newCategory.Subcats) { IM.CDefSubs[newCategory.Cat].Add(newSubCat); if (!IM.CDefSubInfo.ContainsKey(newSubCat.Subcat)) { IM.CDefSubInfo.Add(newSubCat.Subcat, newSubCat); } if (!IM.SCD.ContainsKey(newSubCat.Subcat)) { IM.SCD.Add(newSubCat.Subcat, new List <ItemSpawnerID>()); } } } } } }
private static bool RedrawDetailsCanvasPatch(ItemSpawnerV2 __instance) { OtherLogger.Log("Selected ID: " + __instance.m_selectedID, OtherLogger.LogType.General); //If there is no spawner entry for the selected ID, set everything to blank if (!OtherLoader.SpawnerEntriesByID.ContainsKey(__instance.m_selectedID)) { return(true); } else { ItemSpawnerEntry entry = OtherLoader.SpawnerEntriesByID[__instance.m_selectedID]; ItemSpawnerData data = __instance.GetComponent <ItemSpawnerData>(); OtherLogger.Log("We found an entry for it!", OtherLogger.LogType.General); //First, fill activate some of the detail and populate it with info for (int l = 0; l < __instance.IM_FavButtons.Count; l++) { __instance.IM_FavButtons[l].gameObject.SetActive(true); } __instance.IM_Detail.gameObject.SetActive(true); __instance.IM_Detail.sprite = entry.EntryIcon; __instance.TXT_Title.text = entry.DisplayName; __instance.BTN_SpawnSelectedObject.SetActive(true); __instance.TXT_Detail.text = __instance.GetDetailText(__instance.m_selectedID); //Now get all the secondary entries List <ItemSpawnerEntry> secondaryEntries = new List <ItemSpawnerEntry>(); for (int m = 0; m < entry.SecondaryObjectIDs.Count; m++) { if (!OtherLoader.SpawnerEntriesByID.ContainsKey(entry.SecondaryObjectIDs[m])) { OtherLogger.LogWarning($"Secondary ID for ({entry.MainObjectID}) was not in entry dictionary! It will not appear! Secondary ID ({entry.SecondaryObjectIDs[m]})"); continue; } ItemSpawnerEntry secondary = OtherLoader.SpawnerEntriesByID[entry.SecondaryObjectIDs[m]]; if (!secondary.IsReward || GM.Rewards.RewardUnlocks.Rewards.Contains(secondary.MainObjectID)) { secondaryEntries.Add(secondary); } } //Now we create the secondaries page //Start by drawing the tiles data.VisibleSecondaryEntries.Clear(); int startIndex = __instance.m_selectedIDRelatedPage * __instance.IM_DetailRelated.Count; for (int i = 0; i < __instance.IM_DetailRelated.Count; i++) { if (startIndex + i < secondaryEntries.Count) { ItemSpawnerEntry secondaryEntry = secondaryEntries[startIndex + i]; data.VisibleSecondaryEntries.Add(secondaryEntry); __instance.IM_DetailRelated[i].gameObject.SetActive(true); __instance.IM_DetailRelated[i].sprite = secondaryEntry.EntryIcon; } else { __instance.IM_DetailRelated[i].gameObject.SetActive(false); } } //Now handle the page selectors int numPages = (int)Math.Ceiling((double)secondaryEntries.Count / __instance.IM_DetailRelated.Count); __instance.TXT_DetailsRelatedPageNum.gameObject.SetActive(true); __instance.TXT_DetailsRelatedPageNum.text = (__instance.m_selectedIDRelatedPage + 1).ToString() + " / " + numPages.ToString(); if (__instance.m_selectedIDRelatedPage > 0) { __instance.BTN_DetailsRelatedPrevPage.SetActive(true); } else { __instance.BTN_DetailsRelatedPrevPage.SetActive(false); } if (__instance.m_selectedIDRelatedPage < numPages - 1) { __instance.BTN_DetailsRelatedNextPage.SetActive(true); } else { __instance.BTN_DetailsRelatedNextPage.SetActive(false); } //Setup the tutorials panel for (int i = 0; i < __instance.BTNS_DetailTutorial.Count; i++) { if (i < entry.TutorialBlockIDs.Count) { if (IM.TutorialBlockDic.ContainsKey(entry.TutorialBlockIDs[i])) { __instance.BTNS_DetailTutorial[i].gameObject.SetActive(true); __instance.BTNS_DetailTutorial[i].text = IM.TutorialBlockDic[entry.TutorialBlockIDs[i]].Title; } else { __instance.BTNS_DetailTutorial[i].gameObject.SetActive(false); } } else { __instance.BTNS_DetailTutorial[i].gameObject.SetActive(false); } } //Setup the favorites icons for (int i = 0; i < __instance.IM_FavButtons.Count; i++) { if (ManagerSingleton <IM> .Instance.ItemMetaDic.ContainsKey(__instance.m_selectedID) && ManagerSingleton <IM> .Instance.ItemMetaDic[__instance.m_selectedID].ContainsKey(TagType.Favorites) && ManagerSingleton <IM> .Instance.ItemMetaDic[__instance.m_selectedID][TagType.Favorites].Contains(__instance.FaveTags[i])) { __instance.IM_FavButtons[i].sprite = __instance.IM_FavButton_Faved[i]; } else { __instance.IM_FavButtons[i].sprite = __instance.IM_FavButton_UnFaved[i]; } } } return(false); }
public void LegacyPopulateFromID(ItemSpawnerV2.PageMode Page, ItemSpawnerID ID, bool IsModded) { if (ID.MainObject != null) { MainObjectID = ID.MainObject.ItemID; } else { OtherLogger.LogWarning("ItemSpawnerID has a null MainObject! ItemID: " + ID.ItemID); MainObjectID = ID.ItemID; } if (IM.OD.ContainsKey(MainObjectID)) { OtherLoader.SpawnerEntriesByID[MainObjectID] = this; } SpawnWithIDs = new List <string>(); if (ID.SecondObject != null) { SpawnWithIDs.Add(ID.SecondObject.ItemID); } //Add secondary items to entry, being careful of null values! SecondaryObjectIDs = new List <string>(); foreach (ItemSpawnerID secondary in ID.Secondaries) { if (secondary != null && secondary.MainObject != null) { SecondaryObjectIDs.Add(secondary.MainObject.ItemID); } else if (secondary == null) { OtherLogger.LogWarning("Failed to add secondary to item (" + MainObjectID + ") due to secondary item being null!"); } else { OtherLogger.LogWarning("Failed to add secondary to item (" + MainObjectID + ") due to null MainObject!, Secondary display name: " + secondary.DisplayName); } } if (ID.Secondaries_ByStringID != null) { SecondaryObjectIDs.AddRange(ID.Secondaries_ByStringID); } EntryPath = CreatePath(Page, ID); EntryIcon = ID.Sprite; DisplayName = ID.DisplayName; IsDisplayedInMainEntry = ID.IsDisplayedInMainEntry; UsesLargeSpawnPad = ID.UsesLargeSpawnPad; this.IsModded = IsModded; TutorialBlockIDs = new List <string>(); TutorialBlockIDs.AddRange(ID.TutorialBlocks); ModTags = new List <string>(); ModTags.AddRange(ID.ModTags); }