private void onHandBookLinkClicked(LinkTextComponent comp) { string target = comp.Href.Substring("handbook://".Length); if (!dialog.IsOpened()) { dialog.TryOpen(); } dialog.OpenDetailPageFor(target); }
private void onHandBookSearchLinkClicked(LinkTextComponent comp) { string text = comp.Href.Substring("handbooksearch://".Length); if (!dialog.IsOpened()) { dialog.TryOpen(); } dialog.Search(text); }
private void onWorldMapLinkClicked(LinkTextComponent linkcomp) { string[] xyzstr = linkcomp.Href.Substring("worldmap://".Length).Split('='); int x = xyzstr[1].ToInt(); int y = xyzstr[2].ToInt(); int z = xyzstr[3].ToInt(); string text = xyzstr.Length >= 5 ? xyzstr[4] : ""; if (worldMapDlg == null || !worldMapDlg.IsOpened() || (worldMapDlg.IsOpened() && worldMapDlg.DialogType == EnumDialogType.HUD)) { ToggleMap(EnumDialogType.Dialog); } bool exists = false; var elem = (worldMapDlg.SingleComposer.GetElement("mapElem") as GuiElementMap); var wml = (elem?.mapLayers.FirstOrDefault(ml => ml is WaypointMapLayer) as WaypointMapLayer); Vec3d pos = new Vec3d(x, y, z); if (wml != null) { foreach (var wp in wml.ownWaypoints) { if (wp.Position.Equals(pos, 0.01)) { exists = true; break; } } } if (!exists) { capi.SendChatMessage(string.Format("/waypoint addati {0} ={1} ={2} ={3} {4} {5} {6}", "circle", x, y, z, false, "steelblue", text)); } elem?.CenterMapTo(new BlockPos(x, y, z)); }
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())); } }