/// <summary> Remakes the raw texture containg all the chat lines. </summary> /// <remarks> Also updates the dimensions of the widget. </remarks> public virtual void RemakeTexture() { int totalHeight = 0, maxWidth = 0; for (int i = 0; i < UsedLines; i++) { totalHeight += lineSizes[i].Height; maxWidth = Math.Max(maxWidth, lineSizes[i].Width); } Size size = new Size(maxWidth, totalHeight); caretAccumulator = 0; int realHeight = 0; using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) using (IDrawer2D drawer = game.Drawer2D) { drawer.SetBitmap(bmp); DrawTextArgs args = new DrawTextArgs(null, font, true); if (Prefix != null) { args.Text = Prefix; drawer.DrawText(ref args, 0, 0); } for (int i = 0; i < lines.Length; i++) { if (lines[i] == null) { break; } args.Text = lines[i]; char lastCol = GetLastColour(0, i); if (!IDrawer2D.IsWhiteCol(lastCol)) { args.Text = "&" + lastCol + args.Text; } int offset = i == 0 ? prefixWidth : 0; drawer.DrawText(ref args, offset, realHeight); realHeight += lineSizes[i].Height; } inputTex = drawer.Make2DTexture(bmp, size, 0, 0); } Width = size.Width; Height = realHeight == 0 ? prefixHeight : realHeight; Reposition(); inputTex.X1 = X + Padding; inputTex.Y1 = Y; }
void AddChat(string text) { text = text.TrimEnd().Replace('%', '&'); if (!IDrawer2D.IsWhiteCol(lastCol)) { text = "&" + lastCol + text; } char col = IDrawer2D.LastCol(text, text.Length); if (col != '\0') { lastCol = col; } game.Chat.Add(text, MessageType.Normal); }