public static Vector2 DrawBorderString(SpriteBatch sb, string text, Vector2 pos, Color color, float scale = 1f, float anchorx = 0f, float anchory = 0f, int maxCharactersDisplayed = -1) { if (maxCharactersDisplayed != -1 && text.Length > maxCharactersDisplayed) { text.Substring(0, maxCharactersDisplayed); } DynamicSpriteFont fontMouseText = Main.fontMouseText; Vector2 vector = fontMouseText.MeasureString(text); TextSnippet[] snippets = ChatManager.ParseMessage(text, Color.White).ToArray(); ChatManager.ConvertNormalSnippets(snippets); int cum; ChatManager.DrawColorCodedString(sb, fontMouseText, snippets, pos, color, 0f, new Vector2(anchorx, anchory) * vector, new Vector2(scale), out cum, 1f); return(vector * scale); }
protected override void DrawSelf(SpriteBatch spriteBatch) { base.DrawSelf(spriteBatch); //spriteBatch.Draw(Main.magicPixel, GetDimensions().ToRectangle(), Color.Red * 0.5f); CalculatedStyle innerDimensions = base.GetInnerDimensions(); Vector2 pos = innerDimensions.Position(); if (this._isLarge) { pos.Y -= 10f * this._textScale; } else { pos.Y -= 2f * this._textScale; } pos.X += (innerDimensions.Width - this._textSize.X) * 0.5f; //if (this._isLarge) //{ // Utils.DrawBorderStringBig(spriteBatch, this.Text, pos, this._color, this._textScale, 0f, 0f, -1); // return; //} //Utils.DrawBorderString(spriteBatch, this.Text, pos, this._color, this._textScale, 0f, 0f, -1); if (IsMouseHovering) { Main.hoverItemName = HoverText; } var font = _isLarge ? Main.fontDeathText : Main.fontMouseText; int hoveredSnippet = -1; TextSnippet[] textSnippets = ChatManager.ParseMessage(Text, Color.White).ToArray(); ChatManager.ConvertNormalSnippets(textSnippets); ChatManager.DrawColorCodedStringWithShadow(spriteBatch, font, textSnippets, pos, 0f, Vector2.Zero, new Vector2(_textScale), out hoveredSnippet); if (hoveredSnippet > -1) { // annoying click. Main.NewText(hoveredSnippet); textSnippets[hoveredSnippet].OnHover(); //if (Main.mouseLeft && Main.mouseLeftRelease) //{ // textSnippets[hoveredSnippet].OnClick(); //} } }
public void DrawText(int a, int b, String text) { Rectangle hitbox = GetInnerDimensions().ToRectangle(); int hoveredSnippet = -1; TextSnippet[] textSnippets = ChatManager.ParseMessage(text, Color.White).ToArray(); ChatManager.ConvertNormalSnippets(textSnippets); for (int i = 0; i < ChatManager.ShadowDirections.Length; i++) { ChatManager.DrawColorCodedStringShadow(Main.spriteBatch, Main.fontMouseText, textSnippets, new Vector2(2 + a, 15 + 3 + b) + hitbox.TopLeft() + ChatManager.ShadowDirections[i] * 1, Color.Black, 0f, Vector2.Zero, new Vector2(1f, 1f), hitbox.Width - (7 * 2), 1); } Vector2 size = ChatManager.DrawColorCodedString(Main.spriteBatch, Main.fontMouseText, textSnippets, new Vector2(2 + a, 15 + 3 + b) + hitbox.TopLeft(), Color.White, 0f, Vector2.Zero, new Vector2(1f, 1f), out hoveredSnippet, hitbox.Width - (7 * 2), false); }
protected override void DrawSelf(SpriteBatch spriteBatch) { base.DrawSelf(spriteBatch); Rectangle hitbox = GetInnerDimensions().ToRectangle(); //Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.Red * 0.6f); if (expanded) { string info = boss.info ?? "No info available"; int hoveredSnippet = -1; TextSnippet[] textSnippets = ChatManager.ParseMessage(info, Color.White).ToArray(); ChatManager.ConvertNormalSnippets(textSnippets); for (int i = 0; i < ChatManager.ShadowDirections.Length; i++) { ChatManager.DrawColorCodedStringShadow(Main.spriteBatch, Main.fontMouseText, textSnippets, new Vector2(2, 15 + 3) + hitbox.TopLeft() + ChatManager.ShadowDirections[i] * 1, Color.Black, 0f, Vector2.Zero, new Vector2(infoScaleX, infoScaleY), hitbox.Width - (7 * 2), 1); } Vector2 size = ChatManager.DrawColorCodedString(Main.spriteBatch, Main.fontMouseText, textSnippets, new Vector2(2, 15 + 3) + hitbox.TopLeft(), Color.White, 0f, Vector2.Zero, new Vector2(infoScaleX, infoScaleY), out hoveredSnippet, hitbox.Width - (7 * 2), false); if (hoveredSnippet > -1) { // because of draw order, we'll do the hover later. BossChecklist.instance.bossChecklistUI.hoveredTextSnippet = textSnippets[hoveredSnippet]; //array[hoveredSnippet].OnHover(); //if (Main.mouseLeft && Main.mouseLeftRelease) //{ // array[hoveredSnippet].OnClick(); //} } float newSize = size.Y - hitbox.Y; if (newSize != descriptionHeight) { descriptionHeight = newSize; Height.Pixels = 15 + (2 * 3) + descriptionHeight; Recalculate(); } } }
public void Draw(SpriteBatch spriteBatch, ref float y) { var builder = new StringBuilder(); Color c = QuestManager.GetCategoryInfo(Quest.QuestCategory).Color; string hex = $"{c.R:X2}{c.G:X2}{c.B:X2}"; builder.Append("[c/").Append(hex).Append(":").Append(Quest.QuestName).AppendLine("]"); if (Quest.IsActive) { string currentObjectives = Quest.GetObjectivesHUD(); builder.Append(currentObjectives); _prevText = builder.ToString(); } TextSnippet[] allSnippets = ChatManager.ParseMessage(_prevText, Color.White * _opacity).ToArray(); ChatManager.ConvertNormalSnippets(allSnippets); string text = QuestUtils.WrapText(Main.fontMouseText, allSnippets, _prevText, 260f, 0.8f); string[] lines = text.Split('\n'); float x = Main.screenWidth - (Main.playerInventory ? 450 : 298); float lineHeight = Main.fontMouseText.MeasureString(" ").Y * 0.8f - 1f; foreach (string line in lines) { TextSnippet[] snips = ChatManager.ParseMessage(line, Color.White * _opacity).ToArray(); ChatManager.ConvertNormalSnippets(snips); for (int i = 0; i < snips.Length; i++) { snips[i].Color *= _opacity; } ChatManager.DrawColorCodedStringShadow(spriteBatch, Main.fontMouseText, snips, new Vector2(x, y), Color.Black * _opacity, 0f, Vector2.Zero, new Vector2(0.8f)); ChatManager.DrawColorCodedString(spriteBatch, Main.fontMouseText, snips, new Vector2(x, y), Color.White, 0f, Vector2.Zero, new Vector2(0.8f), out int h, -1f); y += lineHeight; } }
protected override void DrawChildren(SpriteBatch spriteBatch) { base.DrawChildren(spriteBatch); CalculatedStyle space = GetInnerDimensions(); //Main.spriteBatch.Draw(Main.magicPixel, space.ToRectangle(), Color.Yellow * .7f); //Main.spriteBatch.Draw(Main.magicPixel, GetOuterDimensions().ToRectangle(), Color.Red * .7f); DynamicSpriteFont font = Main.fontMouseText; float position = 0f; if (this._scrollbar != null) { position = -this._scrollbar.GetValue(); } //foreach (var drawtext in drawtexts) //{ // if (position + drawtext.Item2 > space.Height) // break; // if (position >= 0) // Utils.DrawBorderString(spriteBatch, drawtext.Item1, new Vector2(space.X, space.Y + position), Color.White, 1f); // position += drawtext.Item2; //} //float offset = 0; TextSnippet[] texts; foreach (var snippetList in drawTextSnippets) { texts = snippetList.ToArray(); float snippetListHeight = ChatManager.GetStringSize(font, texts, Vector2.One).Y; //Main.NewText($"Y: {ChatManager.GetStringSize(font, texts, Vector2.One).X}"); if (position > -snippetListHeight) { //foreach (var snippet in snippetList) //{ int hoveredSnippet = -1; ChatManager.ConvertNormalSnippets(texts); ChatManager.DrawColorCodedStringWithShadow(spriteBatch, font, texts, new Vector2(space.X + 2, space.Y + position /*+ offset*/), 0f, Vector2.Zero, Vector2.One, out hoveredSnippet); //offset += 20; //offset += texts.Max(t => (int)ChatManager.GetStringSize(Main.fontMouseText, texts, Vector2.One).X); if (hoveredSnippet > -1 && IsMouseHovering) { texts[hoveredSnippet].OnHover(); if (Main.mouseLeft && Main.mouseLeftRelease /* && Terraria.GameInput.PlayerInput.Triggers.JustReleased.MouseLeft*/) { texts[hoveredSnippet].OnClick(); } } } position += snippetListHeight; if (position > space.Height) { break; } //} } //if (drawTextSnippets.Count > 0) //{ // //ChatManager.DrawColorCodedStringShadow() // int hoveredSnippet = -1; // ChatManager.DrawColorCodedStringWithShadow(spriteBatch, font, drawTextSnippets[0].ToArray(), new Vector2(space.X, space.Y + position), 0f, Vector2.Zero, Vector2.One, out hoveredSnippet); // if (hoveredSnippet > -1) // { // //array[hoveredSnippet].OnHover(); // } //} }
public override void Draw(SpriteBatch spriteBatch) { Player player = Main.LocalPlayer; EntrogicPlayer ePlayer = player.GetModPlayer <EntrogicPlayer>(); if (IsActive) { base.Draw(spriteBatch); Vector2 bookPos = new Vector2((Main.screenWidth - bookSize.X) / 2, (Main.screenHeight - bookSize.Y) / 2); Rectangle rectLeft = new Rectangle((int)bookPos.X, (int)(bookPos.Y + bookSize.Y - 117), 72, 117); Rectangle rectRight = new Rectangle((int)(bookPos.X + bookSize.X - 72), (int)(bookPos.Y + bookSize.Y - 117), 72, 117); if (mouseRect.Intersects(rectLeft) && ePlayer.PageNum > 1) { spriteBatch.Draw(Entrogic.Instance.GetTexture("UI/Books/书本_03"), new Vector2(rectLeft.X, rectLeft.Y), null, Color.White, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f); } else { string page = (ePlayer.PageNum * 2 - 1).ToString(); Vector2 size = Main.fontMouseText.MeasureString(page) * 0.5f; ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontItemStack, page, new Vector2(bookPos.X + 34 - size.X, bookPos.Y + bookSize.Y - 86 - size.Y), Color.White, 0f, Vector2.Zero, new Vector2(1f)); } int MaxPage = 1; if (ePlayer.GetHoldItem() != null) { if (ePlayer.GetHoldItem().GetGlobalItem <EntrogicItem>().book) { MaxPage = ((ModBook)ePlayer.GetHoldItem().modItem).MaxPage; } } if (mouseRect.Intersects(rectRight) && ePlayer.PageNum < MaxPage) { spriteBatch.Draw(Entrogic.Instance.GetTexture("UI/Books/书本_02"), new Vector2(rectRight.X, rectRight.Y), null, Color.White, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f); } else { string page = (ePlayer.PageNum * 2).ToString(); Vector2 size = Main.fontMouseText.MeasureString(page) * 0.5f; ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontItemStack, page, new Vector2(bookPos.X + bookSize.X - 34 - size.X, bookPos.Y + bookSize.Y - 86 - size.Y), Color.White, 0f, Vector2.Zero, new Vector2(1f)); } #region Draw Text Vector2 space = new Vector2((Main.screenWidth - bookSize.X) / 2 + 38, (Main.screenHeight - bookSize.Y) / 2 + 46); //Main.spriteBatch.Draw(Main.magicPixel, space.ToRectangle(), Color.Yellow * .7f); //Main.spriteBatch.Draw(Main.magicPixel, GetOuterDimensions().ToRectangle(), Color.Red * .7f); DynamicSpriteFont font = Entrogic.PixelFont; float scale = 1f; string text = " "; Color baseColor = Color.White; float lineDistance = 0f; Item playerHeldItem = player.HeldItem; if (Entrogic.ItemSafe(playerHeldItem)) { if (playerHeldItem.GetGlobalItem <EntrogicItem>().book) { ModBook itemBook = (ModBook)playerHeldItem.modItem; if (itemBook.PageText[ePlayer.PageNum * 2 - 1] != null) { text = itemBook.PageText[ePlayer.PageNum * 2 - 1]; } //if (((ModBook)ePlayer.GetHoldItem().modItem).font != null) // font = ((ModBook)ePlayer.GetHoldItem().modItem).font; if (itemBook.textBaseColor != null) { baseColor = itemBook.textBaseColor; } lineDistance = itemBook.lineDistance[ePlayer.PageNum * 2 - 1]; scale = itemBook.textScale[ePlayer.PageNum * 2 - 1]; } } float baseLineDistance = 46f * scale; { // 左书页文字 List <List <TextSnippet> > drawTextSnippets = WordwrapStringSmart(text, scale, baseColor, font, (int)(bookSize.X * 0.5f) - 72, -1); float position = 0f; TextSnippet[] texts; foreach (var snippetList in drawTextSnippets) { texts = snippetList.ToArray(); //float snippetListHeight = ChatManager.GetStringSize(font, texts, new Vector2(scale)).Y + lineDistance; //Main.NewText($"Y: {ChatManager.GetStringSize(font, texts, Vector2.One).X}"); if (position > -baseLineDistance + lineDistance /*snippetListHeight*/) { //foreach (var snippet in snippetList) //{ int hoveredSnippet = -1; ChatManager.ConvertNormalSnippets(texts); ChatManager.DrawColorCodedString(spriteBatch, font, texts, new Vector2(space.X, space.Y + position /*+ offset*/), baseColor, 0f, Vector2.Zero, new Vector2(scale), out hoveredSnippet, -1f); //offset += 20; //offset += texts.Max(t => (int)ChatManager.GetStringSize(Main.fontMouseText, texts, Vector2.One).X); //if (hoveredSnippet > -1 && IsMouseHovering) //{ // BossChecklist.instance.BossLog.hoveredTextSnippet = texts[hoveredSnippet]; // // BossChecklist change: Use hoveredTextSnippet to bypass clippingRectangle and draw order issues. // //texts[hoveredSnippet].OnHover(); // //if (Main.mouseLeft && Main.mouseLeftRelease/* && Terraria.GameInput.PlayerInput.Triggers.JustReleased.MouseLeft*/) { // // texts[hoveredSnippet].OnClick(); // //} //} } position += baseLineDistance + lineDistance /*snippetListHeight*/; if (position > bookSize.Y - 48) { break; } //} } } { // 右书页文字 if (ePlayer.GetHoldItem() != null) { if (ePlayer.GetHoldItem().GetGlobalItem <EntrogicItem>().book) { if (((ModBook)ePlayer.GetHoldItem().modItem).PageText[ePlayer.PageNum * 2] != null) { text = ((ModBook)ePlayer.GetHoldItem().modItem).PageText[ePlayer.PageNum * 2]; } lineDistance = ((ModBook)ePlayer.GetHoldItem().modItem).lineDistance[ePlayer.PageNum * 2]; scale = ((ModBook)ePlayer.GetHoldItem().modItem).textScale[ePlayer.PageNum * 2]; } } List <List <TextSnippet> > drawTextSnippets = WordwrapStringSmart(text, scale, baseColor, font, (int)(bookSize.X * 0.5f) - 78, -1); float position = 0f; TextSnippet[] texts; foreach (var snippetList in drawTextSnippets) { texts = snippetList.ToArray(); //float snippetListHeight = ChatManager.GetStringSize(font, texts, new Vector2(scale)).Y + lineDistance; //Main.NewText($"Y: {ChatManager.GetStringSize(font, texts, Vector2.One).X}"); if (position > -baseLineDistance + lineDistance /*snippetListHeight*/) { //foreach (var snippet in snippetList) //{ int hoveredSnippet = -1; ChatManager.ConvertNormalSnippets(texts); ChatManager.DrawColorCodedString(spriteBatch, font, texts, new Vector2(space.X + bookSize.X * 0.5f, space.Y + position /*+ offset*/), baseColor, 0f, Vector2.Zero, new Vector2(scale), out hoveredSnippet, -1f); //offset += 20; //offset += texts.Max(t => (int)ChatManager.GetStringSize(Main.fontMouseText, texts, Vector2.One).X); //if (hoveredSnippet > -1 && IsMouseHovering) //{ // BossChecklist.instance.BossLog.hoveredTextSnippet = texts[hoveredSnippet]; // // BossChecklist change: Use hoveredTextSnippet to bypass clippingRectangle and draw order issues. // //texts[hoveredSnippet].OnHover(); // //if (Main.mouseLeft && Main.mouseLeftRelease/* && Terraria.GameInput.PlayerInput.Triggers.JustReleased.MouseLeft*/) { // // texts[hoveredSnippet].OnClick(); // //} //} } position += baseLineDistance + lineDistance /*snippetListHeight*/; if (position > bookSize.Y - 48) { break; } //} } } #endregion } }