/// <summary> /// Adds a rich text element to the GUI /// </summary> /// <param name="composer"></param> /// <param name="vtmlCode"></param> /// <param name="baseFont"></param> /// <param name="bounds"></param> /// <param name="didClickLink"></param> /// <param name="key"></param> /// <returns></returns> public static GuiComposer AddRichtext(this GuiComposer composer, string vtmlCode, CairoFont baseFont, ElementBounds bounds, Action <LinkTextComponent> didClickLink, string key = null) { if (!composer.Composed) { composer.AddInteractiveElement(new GuiElementRichtext(composer.Api, VtmlUtil.Richtextify(composer.Api, vtmlCode, baseFont, didClickLink), bounds), key); } return(composer); }
public void OnRenderInteractiveElements(ICoreClientAPI api, float deltaTime) { if (!composed) { Recompose(); } accum1Sec += deltaTime; if (accum1Sec > 1) { var expireText = auction.GetExpireText(api); if (expireText != prevExpireText) { expireTextElem.Components = VtmlUtil.Richtextify(api, expireText, CairoFont.WhiteDetailText().WithFontSize(14)); expireTextElem.RecomposeText(); prevExpireText = expireText; } } if (scissorBounds.InnerWidth <= 0 || scissorBounds.InnerHeight <= 0) { return; } // 1. Itemstack api.Render.PushScissor(scissorBounds, true); api.Render.RenderItemstackToGui(dummySlot, scissorBounds.renderX + iconSize / 2, scissorBounds.renderY + iconSize / 2, 100, iconSize * 0.55f, ColorUtil.WhiteArgb, true, false, true); api.Render.PopScissor(); api.Render.Render2DTexturePremultipliedAlpha(hoverTexture.TextureId, scissorBounds.renderX, scissorBounds.renderY, scissorBounds.OuterWidth, scissorBounds.OuterHeight); // 2. ItemStack name, price and expire stackNameTextElem.RenderInteractiveElements(deltaTime); priceTextElem.RenderInteractiveElements(deltaTime); expireTextElem.RenderInteractiveElements(deltaTime); MouseOverCursor = expireTextElem.MouseOverCursor; sellerTextElem.RenderInteractiveElements(deltaTime); // 5. Hover overlay int dx = api.Input.MouseX; int dy = api.Input.MouseY; Vec2d pos = Bounds.PositionInside(dx, dy); if (Selected || (pos != null && IsPositionInside(api.Input.MouseX, api.Input.MouseY))) { api.Render.Render2DTexturePremultipliedAlpha(hoverTexture.TextureId, Bounds.absX, Bounds.absY, Bounds.OuterWidth, Bounds.OuterHeight); if (Selected) { api.Render.Render2DTexturePremultipliedAlpha(hoverTexture.TextureId, Bounds.absX, Bounds.absY, Bounds.OuterWidth, Bounds.OuterHeight); } } }
public void Init(ICoreClientAPI capi) { if (Text.Length < 255) { Text = Lang.Get(Text); } comps = VtmlUtil.Richtextify(capi, Text, CairoFont.WhiteSmallText().WithLineHeightMultiplier(1.2)); titleCached = Lang.Get(Title); }
public void SetNewTextWithoutRecompose(string vtmlCode, CairoFont baseFont, Common.Action <LinkTextComponent> didClickLink = null) { if (this.Components != null) { foreach (var val in Components) { val?.Dispose(); } } this.Components = VtmlUtil.Richtextify(api, vtmlCode, baseFont, didClickLink); }
public void SetNewTextWithoutRecompose(string vtmlCode, CairoFont baseFont, Action <LinkTextComponent> didClickLink = null, bool recalcBounds = false) { if (this.Components != null) { foreach (var val in Components) { val?.Dispose(); } } this.Components = VtmlUtil.Richtextify(api, vtmlCode, baseFont, didClickLink); if (recalcBounds) { CalcHeightAndPositions(); Bounds.CalcWorldBounds(); } }
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); }
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; }