internal void Update() { if (!updateNeeded) { return; } updateNeeded = false; if (itemSlots.Count == 0) { // should only happen once craftResults = new bool[ItemLoader.ItemCount]; isLoot = new bool[ItemLoader.ItemCount]; itemSlots.Clear(); for (int type = 1; type < ItemLoader.ItemCount; type++) { Item item = new Item(); item.SetDefaults(type, false); // 300 ms vs 30 ms if (item.type == 0) { continue; } var slot = new UIItemCatalogueItemSlot(item); itemSlots.Add(slot); } for (int i = 0; i < Recipe.numRecipes; i++) { Recipe recipe = Main.recipe[i]; craftResults[recipe.createItem.type] = true; } foreach (var kvp in LootCache.instance.lootInfos) { //if (kvp.Key.id == 0 && kvp.Key.mod == "Terraria") // Console.WriteLine(); int id = kvp.Key.GetID(); if (id > 0) { isLoot[id] = true; } } } itemGrid.Clear(); foreach (var slot in itemSlots) { if (PassItemFilters(slot)) { itemGrid._items.Add(slot); itemGrid._innerList.Append(slot); } } itemGrid.UpdateOrder(); itemGrid._innerList.Recalculate(); }
internal void Update() { if (NPCLoader.NPCCount - 1 != npcSlots.Count) { // should only happen once npcSlots.Clear(); for (int type = 1; type < NPCLoader.NPCCount; type++) { NPC npc = new NPC(); npc.SetDefaults(type); var slot = new UINPCSlot(npc); npcSlots.Add(slot); } } if (!updateNeeded) { return; } updateNeeded = false; npcGrid.Clear(); for (int type = 1; type < NPCLoader.NPCCount; type++) { var slot = npcSlots[type - 1]; if (PassNPCFilters(slot)) { npcGrid._items.Add(slot); npcGrid._innerList.Append(slot); } } npcGrid.UpdateOrder(); npcGrid._innerList.Recalculate(); lootGrid.Clear(); if (queryLootNPC != null) { var drops = queryLootNPC.GetDrops(); if (NewLootOnlyRadioButton.Selected && RecipeBrowserUI.instance.foundItems != null) { drops.RemoveWhere(x => RecipeBrowserUI.instance.foundItems[x]); } foreach (var dropitem in drops) { Item item = new Item(); item.SetDefaults(dropitem, false); var slot = new UIBestiaryItemSlot(item); lootGrid._items.Add(slot); lootGrid._innerList.Append(slot); } } lootGrid.UpdateOrder(); lootGrid._innerList.Recalculate(); }
private void UpdateGrid() { if (Recipe.numRecipes != recipeSlots.Count) { recipeSlots.Clear(); for (int i = 0; i < Recipe.numRecipes; i++) { recipeSlots.Add(new UIRecipeSlot(i)); } tileChooserGrid.Clear(); var tileUsageCounts = new Dictionary <int, int>(); int currentCount; for (int i = 0; i < Recipe.numRecipes; i++) { for (int j = 0; j < 15; j++) { if (Main.recipe[i].requiredTile[j] == -1) { break; } tileUsageCounts.TryGetValue(Main.recipe[i].requiredTile[j], out currentCount); tileUsageCounts[Main.recipe[i].requiredTile[j]] = currentCount + 1; } } // sort var sorted = tileUsageCounts.OrderBy(kvp => kvp.Value); foreach (var tileUsage in sorted) { var tileSlot = new UITileSlot(tileUsage.Key, tileUsage.Value); tileChooserGrid.Add(tileSlot); tileSlots.Add(tileSlot); } craftingTiles = tileUsageCounts.Select(x => x.Key).ToList(); RecipeBrowserUI.instance.UpdateFavoritedPanel(); } if (!updateNeeded) { return; } updateNeeded = false; List <int> groups = new List <int>(); if (queryItem.item.stack > 0) { int type = queryItem.item.type; foreach (var group in RecipeGroup.recipeGroups) { if (group.Value.ValidItems.Contains(type)) { groups.Add(group.Key); } } } lootSourceGrid.Clear(); if (queryLootItem != null) { //var jsonitem = new JSONItem(queryLootItem.modItem?.mod.Name ?? "Terraria", Lang.GetItemNameValue(queryLootItem.type), queryLootItem.modItem != null ? 0 : queryLootItem.type); var jsonitem = new JSONItem(queryLootItem.modItem?.mod.Name ?? "Terraria", queryLootItem.modItem?.Name ?? Lang.GetItemNameValue(queryLootItem.type), queryLootItem.modItem != null ? 0 : queryLootItem.type); List <JSONNPC> npcsthatdropme; if (LootCache.instance.lootInfos.TryGetValue(jsonitem, out npcsthatdropme)) { foreach (var dropper in npcsthatdropme) { int id = dropper.GetID(); if (id == 0) { continue; } /*int id = dropper.id; * if (id == 0) * { * //it's a * Mod m = ModLoader.GetMod(dropper.mod); * if (m == null) continue; * id = m.NPCType(dropper.name); * }*/ NPC npc = new NPC(); npc.SetDefaults(id); var slot = new UINPCSlot(npc); //lootSourceGrid.Add(slot); lootSourceGrid._items.Add(slot); lootSourceGrid._innerList.Append(slot); } } } lootSourceGrid.UpdateOrder(); lootSourceGrid._innerList.Recalculate(); recipeGrid.Clear(); for (int i = 0; i < Recipe.numRecipes; i++) { if (PassRecipeFilters(Main.recipe[i], groups)) // all the filters //if (Main.projName[i].ToLower().IndexOf(searchFilter.Text, StringComparison.OrdinalIgnoreCase) != -1) { var box = recipeSlots[i]; // if (newestItem > 0) { Recipe recipe = Main.recipe[i]; box.recentlyDiscovered = false; if (recipe.requiredItem.Any(x => x.type == newestItem)) { box.recentlyDiscovered = true; } } recipeGrid._items.Add(box); recipeGrid._innerList.Append(box); } } recipeGrid.UpdateOrder(); recipeGrid._innerList.Recalculate(); }
internal void Update() { // TODO: investigate why this Update is slower than RecipeCatalogueUI if (!RecipeBrowserUI.instance.ShowRecipeBrowser || RecipeBrowserUI.instance.CurrentPanel != RecipeBrowserUI.ItemCatalogue) { return; } if (slowUpdateNeeded > 0) { slowUpdateNeeded--; if (slowUpdateNeeded == 0) { updateNeeded = true; } } if (!updateNeeded) { return; } updateNeeded = false; slowUpdateNeeded = 0; if (itemSlots.Count == 0) { // should only happen once craftResults = new bool[ItemLoader.ItemCount]; isLoot = new bool[ItemLoader.ItemCount]; itemSlots.Clear(); for (int type = 1; type < ItemLoader.ItemCount; type++) { Item item = new Item(); item.SetDefaults(type, false); // 300 ms vs 30 ms if (item.type == 0) { continue; } var slot = new UIItemCatalogueItemSlot(item); itemSlots.Add(slot); } for (int i = 0; i < Recipe.numRecipes; i++) { Recipe recipe = Main.recipe[i]; craftResults[recipe.createItem.type] = true; } foreach (var kvp in LootCache.instance.lootInfos) { //if (kvp.Key.id == 0 && kvp.Key.mod == "Terraria") // Console.WriteLine(); int id = kvp.Key.GetID(); if (id > 0) { isLoot[id] = true; } } } itemGrid.Clear(); List <UIItemCatalogueItemSlot> slotsToUse = itemSlots; if (SharedUI.instance.SelectedCategory.name == ArmorSetFeatureHelper.ArmorSetsHoverTest) { if (ArmorSetFeatureHelper.armorSetSlots == null) { ArmorSetFeatureHelper.CalculateArmorSets(); } slotsToUse = ArmorSetFeatureHelper.armorSetSlots.Cast <UIItemCatalogueItemSlot>().ToList(); ArmorSetFeatureHelper.AppendSpecialUI(itemGrid); } foreach (var slot in slotsToUse) { if (PassItemFilters(slot)) { itemGrid._items.Add(slot); itemGrid._innerList.Append(slot); } } itemGrid.UpdateOrder(); itemGrid._innerList.Recalculate(); }
private void UpdateGrid() { if (Recipe.numRecipes != recipeSlots.Count) { recipeSlots.Clear(); for (int i = 0; i < Recipe.numRecipes; i++) { recipeSlots.Add(new UIRecipeSlot(i)); } } if (!updateNeeded) { return; } updateNeeded = false; List <int> groups = new List <int>(); if (queryItem.item.stack > 0 && !TileLookupRadioButton.Selected) { int type = queryItem.item.type; foreach (var group in RecipeGroup.recipeGroups) { if (group.Value.ValidItems.Contains(type)) { groups.Add(group.Key); } } } lootSourceGrid.Clear(); if (queryLootItem != null) { //var jsonitem = new JSONItem(queryLootItem.modItem?.mod.Name ?? "Terraria", Lang.GetItemNameValue(queryLootItem.type), queryLootItem.modItem != null ? 0 : queryLootItem.type); var jsonitem = new JSONItem(queryLootItem.modItem?.mod.Name ?? "Terraria", queryLootItem.modItem?.Name ?? Lang.GetItemNameValue(queryLootItem.type), queryLootItem.modItem != null ? 0 : queryLootItem.type); List <JSONNPC> npcsthatdropme; if (LootCache.instance.lootInfos.TryGetValue(jsonitem, out npcsthatdropme)) { foreach (var dropper in npcsthatdropme) { int id = dropper.GetID(); if (id == 0) { continue; } /*int id = dropper.id; * if (id == 0) * { * //it's a * Mod m = ModLoader.GetMod(dropper.mod); * if (m == null) continue; * id = m.NPCType(dropper.name); * }*/ NPC npc = new NPC(); npc.SetDefaults(id); var slot = new UINPCSlot(npc); //lootSourceGrid.Add(slot); lootSourceGrid._items.Add(slot); lootSourceGrid._innerList.Append(slot); } } } lootSourceGrid.UpdateOrder(); lootSourceGrid._innerList.Recalculate(); recipeGrid.Clear(); for (int i = 0; i < Recipe.numRecipes; i++) { if (PassRecipeFilters(Main.recipe[i], groups)) // all the filters //if (Main.projName[i].ToLower().IndexOf(searchFilter.Text, StringComparison.OrdinalIgnoreCase) != -1) { var box = recipeSlots[i]; // if (newestItem > 0) { Recipe recipe = Main.recipe[i]; box.recentlyDiscovered = false; if (recipe.requiredItem.Any(x => x.type == newestItem)) { box.recentlyDiscovered = true; } } recipeGrid._items.Add(box); recipeGrid._innerList.Append(box); } } recipeGrid.UpdateOrder(); recipeGrid._innerList.Recalculate(); }