public UIRecipeProgress(int index, Recipe recipe, int order, int owner)
        {
            if (drawPlayerHeadMethodInfo == null)
            {
                drawPlayerHeadMethodInfo = typeof(Main).GetMethod("DrawPlayerHead", BindingFlags.Instance | BindingFlags.NonPublic);
            }

            playerBackGroundTexture = TextureManager.Load("Images/UI/PlayerBackground");
            this.order = order;
            this.owner = owner;
            // TODO: Implement Craft Path for teammates.
            UIMockRecipeSlot create = new UIMockRecipeSlot(RecipeCatalogueUI.instance.recipeSlots[index], owner != Main.myPlayer ? .5f : 0.75f);

            create.Recalculate();
            create.Left.Set(-create.Width.Pixels - (owner != Main.myPlayer ? 23 : 0), 1f);
            var b = create.GetOuterDimensions();

            Append(create);
            int x = (owner != Main.myPlayer ? 23 : 0);

            x += (int)b.Width + 2;
            for (int j = 0; j < Recipe.maxRequirements; j++)
            {
                if (recipe.requiredItem[j].type > 0)
                {
                    Item item = new Item();
                    item.SetDefaults(recipe.requiredItem[j].type);
                    UITrackIngredientSlot ingredient = new UITrackIngredientSlot(item, recipe.requiredItem[j].stack, recipe, j, owner, owner != Main.myPlayer ? .5f : 0.75f);
                    x += (int)b.Width + 2;
                    ingredient.Left.Set(-x, 1f);

                    RecipeCatalogueUI.OverrideForGroups(recipe, ingredient.item);

                    Append(ingredient);
                }
            }
            Height.Pixels = b.Height;
            Width.Pixels  = x + 12;
        }
Example #2
0
        private int Traverse(CraftPath.CraftPathNode node, int left, ref int top, Dictionary <int, int> totalItemCost)
        {
            int count = 1;

            StringBuilder sb         = new StringBuilder();
            var           recipeNode = node as CraftPath.RecipeNode;

            if (recipeNode != null)
            {
                sb.Append(ItemHoverFixTagHandler.GenerateTag(recipeNode.recipe.createItem.type, recipeNode.recipe.createItem.stack * recipeNode.multiplier));
                sb.Append("<");
                for (int i = 0; i < recipeNode.recipe.requiredItem.Length; i++)
                {
                    Item item = recipeNode.recipe.requiredItem[i];
                    if (!item.IsAir)
                    {
                        bool check = false;
                        var  child = recipeNode.children[i];
                        if (child is CraftPath.HaveItemNode)
                        {
                            check = true;
                        }
                        string nameOverride = RecipeCatalogueUI.OverrideForGroups(recipeNode.recipe, item.type);
                        sb.Append(ItemHoverFixTagHandler.GenerateTag(item.type, item.stack * recipeNode.multiplier, nameOverride, check));
                    }
                }
            }
            else
            {
                if (node is CraftPath.HaveItemNode)
                {
                    count--;
                }
                else
                {
                    sb.Append(node.ToUITextString());
                }
            }

            var haveItemNode = node as CraftPath.HaveItemNode;

            if (haveItemNode != null)
            {
                totalItemCost.Adjust(haveItemNode.itemid, haveItemNode.stack);
            }
            var haveItemsNode = node as CraftPath.HaveItemsNode;

            if (haveItemsNode != null)
            {
                foreach (var item in haveItemsNode.listOfItems)
                {
                    totalItemCost.Adjust(item.Item1, item.Item2);
                }
            }

            if (sb.Length > 0)
            {
                var snippet = new UITextSnippet(sb.ToString());
                snippet.Top.Set(top, 0);
                snippet.Left.Set(left, 0);
                Append(snippet);

                if (recipeNode != null)
                {
                    var neededTiles = new HashSet <int>(recipeNode.recipe.requiredTile);
                    neededTiles.Remove(-1);
                    var needWater = recipeNode.recipe.needWater;
                    var needHoney = recipeNode.recipe.needHoney;
                    var needLava  = recipeNode.recipe.needLava;

                    UIRecipeInfoRightAligned simpleRecipeInfo = new UIRecipeInfoRightAligned(neededTiles.ToList(), needWater, needHoney, needLava);
                    simpleRecipeInfo.Top.Set(top, 0);
                    simpleRecipeInfo.Left.Set(-30, 1f);
                    Append(simpleRecipeInfo);

                    UICraftButton craftButton = new UICraftButton(recipeNode, recipeNode.recipe);
                    craftButton.Top.Set(top, 0);
                    craftButton.Left.Set(-26, 1f);
                    Append(craftButton);
                }
                top += verticalSpace;
            }

            if (node.children != null)
            {
                foreach (var child in node.children)
                {
                    if (child != null)
                    {
                        count += Traverse(child, left + HorizontalTab, ref top, totalItemCost);
                    }
                }
            }
            return(count);
        }