Ejemplo n.º 1
0
        // Using Chat Tags is cool, but I can't assign individual code to them.
        // They are first and foremost just Text, made to look like things.
        // Word Wrap is possible with UIMessageBox code, but scrollbar is needed? With UIGrid, I could probably do this better
        public UIRecipePath(CraftPath path)
        {
            this.path = path;

            SetPadding(6);
            Width.Set(0, 1f);
            int top = 0;
            // Craftable
            // Total Money Cost
            var totalItemCost = new Dictionary <int, int>();
            // Does all the other lines.
            int count = Traverse(path.root, 0, ref top, totalItemCost);

            var neededTiles = new HashSet <int>(path.root.GetAllChildrenPreOrder().OfType <CraftPath.RecipeNode>().SelectMany(x => x.recipe.requiredTile));

            neededTiles.Remove(-1);
            var needWater = path.root.GetAllChildrenPreOrder().OfType <CraftPath.RecipeNode>().Any(x => x.recipe.needWater);
            var needHoney = path.root.GetAllChildrenPreOrder().OfType <CraftPath.RecipeNode>().Any(x => x.recipe.needHoney);
            var needLava  = path.root.GetAllChildrenPreOrder().OfType <CraftPath.RecipeNode>().Any(x => x.recipe.needLava);

            var missingTiles = neededTiles.Where(x => !Main.LocalPlayer.adjTile[x]);

            StringBuilder sb = new StringBuilder();

            sb.Append("Cost: ");
            foreach (var data in totalItemCost)
            {
                sb.Append(ItemHoverFixTagHandler.GenerateTag(data.Key, data.Value));
            }

            // Maybe have a summary tiles needed if Full Craft implemented

            var drawTextSnippets = UIMessageBox.WordwrapStringSmart(sb.ToString(), Color.White, Main.fontMouseText, 300, -1);

            foreach (var textSnippet in drawTextSnippets)
            {
                string        s       = string.Concat(textSnippet.Select(x => x.TextOriginal));
                UITextSnippet snippet = new UITextSnippet(s);
                snippet.Top.Set(top, 0);
                snippet.Left.Set(0, 0);
                Append(snippet);
                top += verticalSpace;
                count++;
            }

            Height.Set(count * verticalSpace + PaddingBottom + PaddingTop, 0f);

            // TODO: Full Craft Button
            //var craftButton = new UITextPanel<string>("Craft");
            //craftButton.Top.Set(-38, 1f);
            //craftButton.Left.Set(-63, 1f);
            //craftButton.OnClick += CraftButton_OnClick;
            //Append(craftButton);
        }