Example #1
0
        public static void DrawSelectionText(Graphics graphics, ScriptFile scriptFile, ScriptMessage message, bool alternative = false)
        {
            Color fontColor = Color.FromArgb(255, 255, 255);
            Font  font      = scriptFile.Font;
            int   left      = 15;
            int   top       = 7;

            string[] lines = null;

            if (alternative)
            {
                lines = ScriptParser.TextToLines(message.ContentAlternative);
            }
            else
            {
                lines = ScriptParser.TextToLines(message.Content);
            }

            bool open = false;

            if (lines != null)
            {
                foreach (string line in lines)
                {
                    if (line.StartsWith("%SEL:"))
                    {
                        open = true;
                        continue;
                    }

                    if (line.StartsWith("%END:"))
                    {
                        open = false;
                        continue;
                    }

                    if (open)
                    {
                        string[] splitted = line.Split(',');
                        if (splitted.Length < 3)
                        {
                            continue;
                        }

                        string displayText = splitted[2];

                        for (int i = 0; i < displayText.Length; i++)
                        {
                            char character = displayText[i];

                            if (left >= 223 || top >= 159)
                            {
                                continue;
                            }
                            if (scriptFile.IsValidChar(character))
                            {
                                i++;
                                if (i == displayText.Length)
                                {
                                    FontCharacter fontCharacter = new FontCharacter(new FontSymbol(character), font);
                                    Bitmap        bitmap        = fontCharacter.GetBitmapTransparent(fontColor);
                                    graphics.DrawImage(bitmap, new Rectangle(left, top, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel);
                                    left += 16;
                                }
                                else if (scriptFile.IsValidChar(displayText[i]))
                                {
                                    FontCharacter fontCharacter = new FontCharacter(new FontSymbol(character, displayText[i]), font);
                                    Bitmap        bitmap        = fontCharacter.GetBitmapTransparent(fontColor);
                                    graphics.DrawImage(bitmap, new Rectangle(left, top, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel);
                                    left += 16;
                                }
                                else
                                {
                                    FontCharacter fontCharacter = new FontCharacter(new FontSymbol(character), font);
                                    Bitmap        bitmap        = fontCharacter.GetBitmapTransparent(fontColor);
                                    graphics.DrawImage(bitmap, new Rectangle(left, top, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel);
                                    left += 16;
                                }
                            }
                        }
                    }
                    top += 16;
                    left = 15;
                }
            }
        }
Example #2
0
        public static void DrawDialogueText(Graphics graphics, ScriptFile scriptFile, ScriptMessage message)
        {
            Color           fontColor   = Color.FromArgb(255, 255, 255);
            int             line        = 0;
            int             left        = 15;
            int             top         = 7;
            int             windowCount = 1;
            int             matchIndex  = 0;
            MatchCollection matches     = message.Matches;

            for (int i = 0; i < message.Content.Length; i++)
            {
                if (message.Content[i] == '\n' || message.Content[i] == '\r')
                {
                    continue;
                }
                if (matchIndex < matches.Count)
                {
                    if (i == matches[matchIndex].Index + 1)
                    {
                        Match match = matches[matchIndex];
                        if (match.Groups[1].Value == "COL")
                        {
                            int colorIndex = 0;
                            int.TryParse(match.Groups[2].Value, out colorIndex);
                            if (colorIndex > 15)
                            {
                                fontColor = FontColors[0];
                            }
                            else
                            {
                                fontColor = FontColors[colorIndex];
                            }
                        }
                        else if (match.Groups[1].Value == "LF")
                        {
                            line++;
                            top += 16;
                            left = 15;
                        }
                        else if (match.Groups[1].Value == "CLR")
                        {
                            left = 15;
                            top  = windowCount * 96 + 7;
                            windowCount++;
                        }
                        matchIndex++;
                        i += match.Length - 2;
                        continue;
                    }
                }

                char character = message.Content[i];
                Font font      = scriptFile.Font;
                if (left >= 191)
                {
                    continue;
                }
                if (scriptFile.IsValidChar(character))
                {
                    i++;
                    //if (scriptFile.IsLockedChar(character))
                    //{
                    //    FontCharacter fontCharacter = new FontCharacter(new FontSymbol(character, character), font); //not accurate engine rendering
                    //    Bitmap bitmap = fontCharacter.GetBitmapTransparent(fontColor);
                    //    graphics.DrawImage(bitmap, new Rectangle(left, top, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel);
                    //    left += 16;
                    //}
                    //else
                    if (i == message.Content.Length)
                    {
                        FontCharacter fontCharacter = new FontCharacter(new FontSymbol(character), font);
                        Bitmap        bitmap        = fontCharacter.GetBitmapTransparent(fontColor);
                        graphics.DrawImage(bitmap, new Rectangle(left, top, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel);
                        left += 16;
                    }
                    else if (scriptFile.IsValidChar(message.Content[i]))
                    {
                        FontCharacter fontCharacter = new FontCharacter(new FontSymbol(character, message.Content[i]), font);
                        Bitmap        bitmap        = fontCharacter.GetBitmapTransparent(fontColor);
                        graphics.DrawImage(bitmap, new Rectangle(left, top, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel);
                        left += 16;
                    }
                    else
                    {
                        FontCharacter fontCharacter = new FontCharacter(new FontSymbol(character), font);
                        Bitmap        bitmap        = fontCharacter.GetBitmapTransparent(fontColor);
                        graphics.DrawImage(bitmap, new Rectangle(left, top, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel);
                        left += 16;
                    }
                }
                else
                {
                    continue;
                }
            }
        }