示例#1
0
        public Point MeasureText(string text, float scale = 1.0f)
        {
            var dx     = 0;
            var height = 0;
            var font   = Fonts[0];

            for (var i = 0; i < text.Length; i++)
            {
                if (text[i] == '§')
                {
                    i++;
                    var code = string.Format("§{0}", text[i]);
                    if (ChatFormat.IsValid(code))
                    {
                        font = GetFont(code);
                    }
                }
                else
                {
                    var glyph = font.GetGlyph(text[i]);
                    if (glyph != null)
                    {
                        dx += (int)(glyph.XAdvance * scale);
                        if (glyph.Height > height)
                        {
                            height = glyph.Height;
                        }
                    }
                }
            }

            return(new Point(dx, height));
        }
        public ChatMessage(string text, ChatFormat format) : this(text)
        {
            if (text.Length <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(text), "使用样式代码的情况下必须要有文字.");
            }

            if (format.HasFlag(ChatFormat.Bold))
            {
                this.Bold = true;
            }
            if (format.HasFlag(ChatFormat.Italic))
            {
                this.Italic = true;
            }
            if (format.HasFlag(ChatFormat.Underline))
            {
                this.Underline = true;
            }
            if (format.HasFlag(ChatFormat.Strikethrough))
            {
                this.Strikethrough = true;
            }
            if (format.HasFlag(ChatFormat.Obfuscated))
            {
                this.Obfuscated = true;
            }
        }
示例#3
0
 /// <summary>
 /// Returns formatted <see cref="ChatFormat"/> for an Item Link
 /// </summary>
 private static ChatFormat GetChatFormatForItem(ChatFormat chatFormat, Item item)
 {
     // TODO: this probably needs to be a full item response
     return(new ChatFormat
     {
         Type = ChatFormatType.ItemItemId,
         StartIndex = chatFormat.StartIndex,
         StopIndex = chatFormat.StopIndex,
         FormatModel = new ChatFormatItemId
         {
             ItemId = item.Entry.Id
         }
     });
 }
示例#4
0
        /// <summary>
        /// Parses a <see cref="ChatFormat"/> to return a formatted <see cref="ChatFormat"/>
        /// </summary>
        private ChatFormat ParseChatFormat(WorldSession session, ChatFormat format)
        {
            switch (format.FormatModel)
            {
            case ChatFormatItemGuid chatFormatItemGuid:
            {
                Item item = session.Player.Inventory.GetItem(chatFormatItemGuid.Guid);
                return(GetChatFormatForItem(format, item));
            }

            default:
                return(format);
            }
        }
示例#5
0
        public void Read(GamePacketReader reader)
        {
            Channel  = reader.ReadEnum <ChatChannel>(14u);
            Unknown0 = reader.ReadULong();
            Message  = reader.ReadWideString();

            byte formatCount = reader.ReadByte(5u);

            for (int i = 0; i < formatCount; i++)
            {
                var format = new ChatFormat();
                format.Read(reader);
                Formats.Add(format);
            }
        }
示例#6
0
        public void DrawText(SpriteBatch spriteBatch, int x, int y, string text, float scale = 1.0f, byte alpha = 255)
        {
            var dx    = x;
            var dy    = y;
            var color = Color.White;
            var font  = Fonts[0];

            for (var i = 0; i < text.Length; i++)
            {
                if (text[i] == '§')
                {
                    i++;
                    var code = string.Format("§{0}", text[i]);
                    if (ChatFormat.IsValid(code))
                    {
                        font = GetFont(code);
                    }
                    else
                    {
                        color = GetColor(code);
                    }
                }
                else
                {
                    var glyph = font.GetGlyph(text[i]);
                    if (glyph != null)
                    {
                        var sourceRectangle = new Rectangle(glyph.X, glyph.Y, glyph.Width, glyph.Height);
                        var destRectangle   = new Rectangle(
                            dx + (int)(glyph.XOffset * scale),
                            dy + (int)(glyph.YOffset * scale),
                            (int)(glyph.Width * scale),
                            (int)(glyph.Height * scale));
                        var shadowRectangle = new Rectangle(
                            dx + (int)(glyph.XOffset * scale) + 4,
                            dy + (int)(glyph.YOffset * scale) + 4,
                            (int)(glyph.Width * scale),
                            (int)(glyph.Height * scale));

                        spriteBatch.Draw(font.GetTexture(glyph.Page), shadowRectangle, sourceRectangle,
                                         new Color(21, 21, 21, alpha));
                        spriteBatch.Draw(font.GetTexture(glyph.Page), destRectangle, sourceRectangle,
                                         new Color(color, alpha));
                        dx += (int)(glyph.XAdvance * scale);
                    }
                }
            }
        }
示例#7
0
        public void Read(GamePacketReader reader)
        {
            PlayerName = reader.ReadWideString();
            Unknown0   = reader.ReadWideString();

            Message = reader.ReadWideString();
            byte formatCount = reader.ReadByte(5u);

            for (int i = 0; i < formatCount; i++)
            {
                var format = new ChatFormat();
                format.Read(reader);
                Formats.Add(format);
            }

            Unknown1 = reader.ReadBit();
        }
 public ChatMessage(string text, ChatColor color, ChatFormat format) : this(text, format)
 {
     this.Color = color.ToString();
 }
 public ChatMessage(ReadOnlySpan <char> text, ChatFormat format) : this(text.ToString(), format)
 {
 }