public AuctionCellEntry(ICoreClientAPI capi, ElementBounds bounds, Auction auction, Action <int> onClick) : base(capi, bounds)
        {
            iconSize = (float)scaled(unscaledIconSize);

            dummySlot    = new DummySlot(auction.ItemStack);
            this.onClick = onClick;
            this.auction = auction;

            CairoFont font = CairoFont.WhiteDetailText();
            double    offY = (unScaledCellHeight - font.UnscaledFontsize) / 2;

            scissorBounds = ElementBounds.FixedSize(unscaledIconSize, unscaledIconSize).WithParent(Bounds);
            var stackNameTextBounds = ElementBounds.Fixed(0, offY, 270, 25).WithParent(Bounds).FixedRightOf(scissorBounds, 10);
            var priceTextBounds     = ElementBounds.Fixed(0, offY, 75, 25).WithParent(Bounds).FixedRightOf(stackNameTextBounds, 10);
            var expireTextBounds    = ElementBounds.Fixed(0, 0, 160, 25).WithParent(Bounds).FixedRightOf(priceTextBounds, 10);
            var sellerTextBounds    = ElementBounds.Fixed(0, offY, 110, 25).WithParent(Bounds).FixedRightOf(expireTextBounds, 10);



            stackNameTextElem = new GuiElementRichtext(capi, VtmlUtil.Richtextify(capi, dummySlot.Itemstack.GetName(), font), stackNameTextBounds);

            double    fl        = font.UnscaledFontsize;
            ItemStack gearStack = capi.ModLoader.GetModSystem <ModSystemAuction>().SingleCurrencyStack;
            var       comps     = new RichTextComponentBase[] {
                new RichTextComponent(capi, "" + auction.Price, font)
                {
                    PaddingRight = 10, VerticalAlign = EnumVerticalAlign.Top
                },
                new ItemstackTextComponent(capi, gearStack, fl * 2.5f, 0, EnumFloat.Inline)
                {
                    VerticalAlign = EnumVerticalAlign.Top, offX = -scaled(fl * 0.5f), offY = -scaled(fl * 0.75f)
                }
            };

            priceTextElem  = new GuiElementRichtext(capi, comps, priceTextBounds);
            expireTextElem = new GuiElementRichtext(capi, VtmlUtil.Richtextify(capi, prevExpireText = auction.GetExpireText(capi), font.Clone().WithFontSize(14)), expireTextBounds);
            expireTextElem.BeforeCalcBounds();
            expireTextBounds.fixedY = 5 + (25 - expireTextElem.TotalHeight / RuntimeEnv.GUIScale) / 2;


            sellerTextElem = new GuiElementRichtext(capi, VtmlUtil.Richtextify(capi, auction.SellerName, font.Clone().WithOrientation(EnumTextOrientation.Right)), sellerTextBounds);

            hoverTexture = new LoadedTexture(capi);
        }
Example #2
0
        static void Richtextify(ICoreClientAPI capi, VtmlToken token, ref List <RichTextComponentBase> elems, Stack <CairoFont> fontStack, Action <LinkTextComponent> didClickLink)
        {
            if (token is VtmlTagToken)
            {
                VtmlTagToken tagToken = token as VtmlTagToken;

                switch (tagToken.Name)
                {
                case "br":
                    elems.Add(new RichTextComponent(capi, "\r\n", fontStack.Peek()));
                    break;

                case "i":
                    CairoFont font = fontStack.Peek().Clone();
                    font.Slant = FontSlant.Italic;
                    fontStack.Push(font);
                    foreach (var val in tagToken.ChildElements)
                    {
                        Richtextify(capi, val, ref elems, fontStack, didClickLink);
                    }
                    fontStack.Pop();
                    break;

                case "a":
                    LinkTextComponent cmp = new LinkTextComponent(capi, tagToken.ContentText, fontStack.Peek(), didClickLink);
                    tagToken.Attributes.TryGetValue("href", out cmp.Href);

                    elems.Add(cmp);
                    break;

                case "icon":
                    string iconName;
                    tagToken.Attributes.TryGetValue("name", out iconName);
                    IconComponent iconcmp = new IconComponent(capi, iconName, fontStack.Peek());
                    elems.Add(iconcmp);
                    break;

                case "itemstack":
                    string    code;
                    string    type;
                    float     size      = (float)fontStack.Peek().GetFontExtents().Height;
                    EnumFloat floatType = EnumFloat.Inline;
                    string    floattypestr;
                    if (tagToken.Attributes.TryGetValue("floattype", out floattypestr))
                    {
                        if (!Enum.TryParse(floattypestr, out floatType))
                        {
                            floatType = EnumFloat.Inline;
                        }
                    }

                    tagToken.Attributes.TryGetValue("code", out code);
                    if (!tagToken.Attributes.TryGetValue("type", out type))
                    {
                        type = "block";
                    }

                    ItemStack stack;
                    if (type == "item")
                    {
                        stack = new ItemStack(capi.World.GetItem(new AssetLocation(code)));
                    }
                    else
                    {
                        stack = new ItemStack(capi.World.GetBlock(new AssetLocation(code)));
                    }

                    float sizemul = 1f;
                    if (tagToken.Attributes.TryGetValue("rsize", out var sizemulstr))
                    {
                        sizemul = sizemulstr.ToFloat();
                    }

                    SlideshowItemstackTextComponent stckcmp = new SlideshowItemstackTextComponent(capi, new ItemStack[] { stack }, size / RuntimeEnv.GUIScale, floatType);
                    stckcmp.renderSize   *= sizemul;
                    stckcmp.VerticalAlign = EnumVerticalAlign.Middle;

                    if (tagToken.Attributes.TryGetValue("offx", out var offxstr))
                    {
                        stckcmp.offX = GuiElement.scaled(offxstr.ToFloat(0));
                    }
                    if (tagToken.Attributes.TryGetValue("offy", out var offystr))
                    {
                        stckcmp.offY = GuiElement.scaled(offystr.ToFloat(0));
                    }

                    elems.Add(stckcmp);
                    break;

                case "font":
                    fontStack.Push(getFont(tagToken, fontStack));
                    foreach (var val in tagToken.ChildElements)
                    {
                        Richtextify(capi, val, ref elems, fontStack, didClickLink);
                    }
                    fontStack.Pop();
                    break;

                case "clear":
                    elems.Add(new ClearFloatTextComponent(capi));
                    break;

                case "strong":
                    fontStack.Push(fontStack.Peek().Clone().WithWeight(Cairo.FontWeight.Bold));
                    foreach (var val in tagToken.ChildElements)
                    {
                        Richtextify(capi, val, ref elems, fontStack, didClickLink);
                    }
                    fontStack.Pop();
                    break;
                }


                if (tagToken.Name != null && TagConverters.ContainsKey(tagToken.Name))
                {
                    RichTextComponentBase elem = TagConverters[tagToken.Name](capi, tagToken, fontStack, didClickLink);
                    if (elem != null)
                    {
                        elems.Add(elem);
                    }
                }
            }
            else
            {
                VtmlTextToken textToken = token as VtmlTextToken;
                elems.Add(new RichTextComponent(capi, textToken.Text, fontStack.Peek()));
            }
        }
Example #3
0
        public void Init()
        {
            var descBounds = ElementBounds.Fixed(0, 30, 400, 80);

            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            dialogBounds        = ElementStdBounds
                                  .AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle)
                                  .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0);

            bgBounds.verticalSizing   = ElementSizing.FitToChildren;
            bgBounds.horizontalSizing = ElementSizing.Fixed;
            bgBounds.fixedWidth       = 300;


            #region Text
            var deliveryCosts = auctionSys.DeliveryCostsByDistance(traderEntity.Pos.XYZ, auction.SrcAuctioneerEntityPos);

            RichTextComponentBase[] stackComps = new RichTextComponentBase[] {
                new ItemstackTextComponent(capi, auction.ItemStack, 60, 10),
                new RichTextComponent(capi, auction.ItemStack.GetName() + "\r\n", CairoFont.WhiteSmallText())
            };

            stackComps = stackComps.Append(VtmlUtil.Richtextify(capi, auction.ItemStack.GetDescription(capi.World, new DummySlot(auction.ItemStack)), CairoFont.WhiteDetailText()));


            var       font              = CairoFont.WhiteDetailText();
            double    fl                = font.UnscaledFontsize;
            ItemStack gearStack         = auctionSys.SingleCurrencyStack;
            var       deliveryCostComps = new RichTextComponentBase[] {
                new RichTextComponent(capi, Lang.Get("Delivery: {0}", deliveryCosts), font)
                {
                    PaddingRight = 10, VerticalAlign = EnumVerticalAlign.Top
                },
                new ItemstackTextComponent(capi, gearStack, fl * 2.5f, 0, EnumFloat.Inline)
                {
                    VerticalAlign = EnumVerticalAlign.Top, offX = -GuiElement.scaled(fl * 0.5f), offY = -GuiElement.scaled(fl * 0.75f)
                }
            };



            RichTextComponentBase[] totalCostComps = new RichTextComponentBase[]
            {
                new RichTextComponent(capi, Lang.Get("Total Cost: {0}", auction.Price + deliveryCosts), font)
                {
                    PaddingRight = 10, VerticalAlign = EnumVerticalAlign.Top
                },
                new ItemstackTextComponent(capi, gearStack, fl * 2.5f, 0, EnumFloat.Inline)
                {
                    VerticalAlign = EnumVerticalAlign.Top, offX = -GuiElement.scaled(fl * 0.5f), offY = -GuiElement.scaled(fl * 0.75f)
                }
            };
            #endregion



            Composers["confirmauctionpurchase"] = capi.Gui
                                                  .CreateCompo("tradercreateauction-" + buyerEntity.EntityId, dialogBounds)
                                                  .AddShadedDialogBG(bgBounds, true)
                                                  .AddDialogTitleBar(Lang.Get("Purchase this item?"), OnCreateAuctionClose)
                                                  .BeginChildElements(bgBounds)
                                                  .AddRichtext(stackComps, descBounds, "itemstack")
            ;

            var ri = Composers["confirmauctionpurchase"].GetRichtext("itemstack");
            ri.BeforeCalcBounds();

            double y = Math.Max(110, descBounds.fixedHeight + 20);

            ElementBounds deliverySwitchBounds = ElementBounds.Fixed(0, y, 35, 25);
            ElementBounds deliveryTextBounds   = ElementBounds.Fixed(0, y + 3, 250, 25).FixedRightOf(deliverySwitchBounds, 0);


            ElementBounds deliveryCostBounds = ElementBounds.Fixed(0, 0, 200, 30).FixedUnder(deliveryTextBounds, 20);
            ElementBounds totalCostBounds    = ElementBounds.Fixed(0, 0, 150, 30).FixedUnder(deliveryCostBounds, 0);

            ElementBounds leftButton  = ElementBounds.Fixed(EnumDialogArea.LeftFixed, 0, 0, 0, 0).WithFixedPadding(8, 5).FixedUnder(totalCostBounds, 15);
            ElementBounds rightButton = ElementBounds.Fixed(EnumDialogArea.RightFixed, 0, 0, 0, 0).WithFixedPadding(8, 5).FixedUnder(totalCostBounds, 15);


            Composers["confirmauctionpurchase"]
            .AddSwitch(onDeliveryModeChanged, deliverySwitchBounds, "delivery", 25)
            .AddStaticText(Lang.Get("Deliver to current trader"), CairoFont.WhiteSmallText(), deliveryTextBounds)


            .AddRichtext(deliveryCostComps, deliveryCostBounds, "deliveryCost")
            .AddRichtext(totalCostComps, totalCostBounds, "totalCost")

            .AddSmallButton(Lang.Get("Cancel"), OnCancel, leftButton)
            .AddSmallButton(Lang.Get("Purchase"), OnPurchase, rightButton, EnumButtonStyle.Normal, EnumTextOrientation.Left, "buysellButton")
            .EndChildElements()
            .Compose()
            ;

            Composers["confirmauctionpurchase"].GetSwitch("delivery").On = true;
        }