Exemplo n.º 1
0
        internal void UpdateFavoritedPanel()
        {
            ShowFavoritePanel = favoritedRecipes.Count > 0;
            favoritePanel.RemoveAllChildren();

            UIGrid list = new UIGrid();

            list.Width.Set(0, 1f);
            list.Height.Set(0, 1f);
            list.ListPadding = 5f;
            favoritePanel.Append(list);
            favoritePanel.AddDragTarget(list);
            favoritePanel.AddDragTarget(list._innerList);
            int width  = 1;
            int height = 0;
            int order  = 1;

            foreach (var item in favoritedRecipes)
            {
                Recipe           r = Main.recipe[item.index];
                UIRecipeProgress s = new UIRecipeProgress(item.index, r, order);
                order++;
                s.Recalculate();
                var a = s.GetInnerDimensions();
                s.Width.Precent = 1;
                list.Add(s);
                height += (int)(a.Height + list.ListPadding);
                width   = Math.Max(width, (int)a.Width);
                favoritePanel.AddDragTarget(s);
            }
            favoritePanel.Height.Pixels = height + favoritePanel.PaddingBottom + favoritePanel.PaddingTop - list.ListPadding;
            favoritePanel.Width.Pixels  = width;
            favoritePanel.Recalculate();

            var scrollbar = new InvisibleFixedUIScrollbar(userInterface);

            scrollbar.SetView(100f, 1000f);
            scrollbar.Height.Set(0, 1f);
            scrollbar.Left.Set(-20, 1f);
            favoritePanel.Append(scrollbar);
            list.SetScrollbar(scrollbar);

            Recipe.FindRecipes();
        }
        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();
        }
Exemplo n.º 3
0
        internal void UpdateFavoritedPanel()
        {
            if (!favoritePanelUpdateNeeded)
            {
                return;
            }
            favoritePanelUpdateNeeded = false;

            // Reset All
            foreach (var recipeSlot in RecipeCatalogueUI.instance.recipeSlots)
            {
                recipeSlot.favorited = false;
            }
            foreach (var recipeIndex in localPlayerFavoritedRecipes)
            {
                RecipeCatalogueUI.instance.recipeSlots[recipeIndex].favorited = true;
            }

            ShowFavoritePanel = localPlayerFavoritedRecipes.Count > 0;
            favoritePanel.RemoveAllChildren();

            UIGrid list = new UIGrid();

            list.Width.Set(0, 1f);
            list.Height.Set(0, 1f);
            list.ListPadding    = 5f;
            list.OnScrollWheel += RecipeBrowserUI.OnScrollWheel_FixHotbarScroll;
            favoritePanel.Append(list);
            favoritePanel.AddDragTarget(list);
            favoritePanel.AddDragTarget(list._innerList);
            int width  = 1;
            int height = 0;
            int order  = 1;

            for (int i = 0; i < Main.maxPlayers; i++)
            {
                if (i != Main.myPlayer && Main.player[i].active)
                {
                    foreach (var recipeIndex in Main.player[i].GetModPlayer <RecipeBrowserPlayer>().favoritedRecipes)
                    {
                        Recipe           r = Main.recipe[recipeIndex];
                        UIRecipeProgress s = new UIRecipeProgress(recipeIndex, r, order, i);
                        order++;
                        s.Recalculate();
                        var a = s.GetInnerDimensions();
                        s.Width.Precent = 1;
                        list.Add(s);
                        height += (int)(a.Height + list.ListPadding);
                        width   = Math.Max(width, (int)a.Width);
                        favoritePanel.AddDragTarget(s);
                    }
                }
            }

            foreach (var recipeIndex in localPlayerFavoritedRecipes)
            {
                Recipe           r = Main.recipe[recipeIndex];
                UIRecipeProgress s = new UIRecipeProgress(recipeIndex, r, order, Main.myPlayer);
                order++;
                s.Recalculate();
                var a = s.GetInnerDimensions();
                s.Width.Precent = 1;
                list.Add(s);
                height += (int)(a.Height + list.ListPadding);
                width   = Math.Max(width, (int)a.Width);
                favoritePanel.AddDragTarget(s);
            }
            favoritePanel.Height.Pixels = height + favoritePanel.PaddingBottom + favoritePanel.PaddingTop - list.ListPadding;
            favoritePanel.Width.Pixels  = width;
            favoritePanel.Recalculate();

            var scrollbar = new InvisibleFixedUIScrollbar(userInterface);

            scrollbar.SetView(100f, 1000f);
            scrollbar.Height.Set(0, 1f);
            scrollbar.Left.Set(-20, 1f);
            favoritePanel.Append(scrollbar);
            list.SetScrollbar(scrollbar);

            Recipe.FindRecipes();
        }