コード例 #1
0
        private void LoadFontPart(SpriteReference sprite, int index)
        {
            Texture2D tex = sprite.Texture;

            Color[] blah = new Color[tex.Width * tex.Height];
            tex.GetData <Color>(0, new Rectangle(0, 0, tex.Width, tex.Height), blah, 0, blah.Length);

            for (int i = 0; i < FontUtil.CharsPerPage; i++)
            {
                FontUtil.RegisterChar(blah, tex.Width, tex.Height, (char)(index * FontUtil.CharsPerPage + i), i);
            }
        }
コード例 #2
0
        public void DrawMessageHistory(SceneGame scene, MessageHistory history)
        {
            int offsetY = 150;

            foreach (var message in history.Messages.Reverse <Message>())
            {
                var    parameters = new TextParameters().SetColor(Color.White, Color.Black).SetBold(true).SetConstraints(scene.Viewport.Width, 128).SetIcons(scene, message.Icons);
                string fitString  = FontUtil.FitString(message.RenderText(Player), parameters);
                var    height     = FontUtil.GetStringHeight(fitString);
                offsetY -= height;
                if (offsetY + height < 0)
                {
                    break;
                }
                scene.DrawText(fitString, new Vector2(0, offsetY), Alignment.Right, parameters);
            }
        }
コード例 #3
0
        private void DrawTextLine(string str, Vector2 drawpos, int totalindex, TextParameters parameters)
        {
            int pos = 0;

            foreach (char chr in str)
            {
                if (totalindex > parameters.DialogIndex)
                {
                    break;
                }
                switch (chr)
                {
                case (FORMAT_BOLD):
                    parameters.Bold = !parameters.Bold;
                    break;

                case (FORMAT_UNDERLINE):
                    parameters.Underline = !parameters.Underline;
                    break;

                case (FORMAT_SUBSCRIPT):
                    parameters.ScriptOffset += 8;
                    break;

                case (FORMAT_SUPERSCRIPT):
                    parameters.ScriptOffset -= 8;
                    break;
                }
                Texture2D tex    = FontSprites[chr / FontUtil.CharsPerPage].Texture;
                int       index  = chr % FontUtil.CharsPerPage;
                int       offset = FontUtil.GetCharOffset(chr);
                int       width  = FontUtil.GetCharWidth(chr);

                var color      = parameters.Color(totalindex);
                var border     = parameters.Border(totalindex);
                var charOffset = parameters.Offset(totalindex);

                if (border.A > 0)
                { //Only draw outline if it's actually non-transparent
                    SpriteBatch.Draw(tex, drawpos + charOffset + new Vector2(pos - offset - 1, parameters.ScriptOffset + 0), FontUtil.GetCharRect(index), border);
                    SpriteBatch.Draw(tex, drawpos + charOffset + new Vector2(pos - offset, parameters.ScriptOffset + 1), FontUtil.GetCharRect(index), border);
                    SpriteBatch.Draw(tex, drawpos + charOffset + new Vector2(pos - offset, parameters.ScriptOffset - 1), FontUtil.GetCharRect(index), border);
                    if (parameters.Bold)
                    {
                        SpriteBatch.Draw(tex, drawpos + charOffset + new Vector2(pos - offset + 2, parameters.ScriptOffset + 0), FontUtil.GetCharRect(index), border);
                        SpriteBatch.Draw(tex, drawpos + charOffset + new Vector2(pos - offset + 1, parameters.ScriptOffset + 1), FontUtil.GetCharRect(index), border);
                        SpriteBatch.Draw(tex, drawpos + charOffset + new Vector2(pos - offset + 1, parameters.ScriptOffset - 1), FontUtil.GetCharRect(index), border);
                    }
                    else
                    {
                        SpriteBatch.Draw(tex, drawpos + charOffset + new Vector2(pos - offset + 1, parameters.ScriptOffset), FontUtil.GetCharRect(index), border);
                    }
                }

                SpriteBatch.Draw(tex, drawpos + charOffset + new Vector2(pos - offset, parameters.ScriptOffset), FontUtil.GetCharRect(index), color);
                if (parameters.Bold)
                {
                    SpriteBatch.Draw(tex, drawpos + charOffset + new Vector2(pos - offset + 1, parameters.ScriptOffset), FontUtil.GetCharRect(index), color);
                }

                if (chr == FORMAT_ICON)
                {
                    parameters.Icons[parameters.IconIndex].Draw(drawpos + charOffset + new Vector2(pos - offset, parameters.ScriptOffset) + new Vector2(8, 8));
                    parameters.IconIndex++;
                }

                pos += width + parameters.CharSeperator + (parameters.Bold ? 1 : 0);
                totalindex++;
            }
        }