Esempio n. 1
0
        private Bitmap DrawNameBox(string charName)
        {
            //Get character name and width
            string name      = charName == "username" ? PlayerName : CharacterData.GetLocalizedName(activeChar) ?? activeChar;
            int    nameWidth = PreviewFont.GetStringWidth(name);

            //Text to namebox
            return((Bitmap)PreviewFont.DrawString(Resources.Properties.Resources.NameBox, name, Color.FromArgb(253, 234, 177), Resources.Properties.Resources.NameBox.Width / 2 - nameWidth / 2, 1));
        }
Esempio n. 2
0
        private Bitmap RenderSpecifiedPreview(int index, PreviewFormat pFormat)
        {
            //Grab and set up the line text
            string topLine, bottomLine;
            string text = topLine = bottomLine = string.Empty;

            if (pFormat == PreviewFormat.TopBottom)
            {
                ResetCommands();
            }

            for (int i = pFormat == PreviewFormat.TopBottom ? 0 : index; i <= index; i++)
            {
                UpdatePageCommands(i);

                text = ParseInlineCommands(string.Join(Environment.NewLine, FileCont.Messages[messageIndex].Pages[i].SpokenLine));

                if (pFormat == PreviewFormat.TopBottom && activeChar == charA)
                {
                    topLine = text;
                }
                else if (pFormat == PreviewFormat.TopBottom)
                {
                    bottomLine = text;
                }
            }

            //Halfbox preview
            if (pFormat == PreviewFormat.HalfBox)
            {
                Bitmap[] hb      = { Resources.Properties.Resources.HalfBox, Resources.Properties.Resources.HalfBox_Nohr, Resources.Properties.Resources.HalfBox_Hoshido };
                var      halfbox = (Bitmap)hb[TextboxIndex].Clone();

                using (Graphics g = Graphics.FromImage(halfbox))
                {
                    var halfText = (Bitmap)PreviewFont.DrawString(new Bitmap(165, 50), text, Color.FromArgb(68, 8, 0), 0, 22);
                    g.DrawImage(halfText, new Point(10, 0));
                    g.DrawImage(Resources.Properties.Resources.KeyPress, new Point(168, 32));
                }

                return(halfbox);
            }

            //Preview setup
            var baseImage = new Bitmap(400, 240);

            using (Graphics g = Graphics.FromImage(baseImage))
            {
                //Draw a background
                if (pFormat == PreviewFormat.Skinship)
                {
                    g.DrawImage(Resources.Properties.Resources.AmieBG, new Point(0, 0));
                }
                else if (backgroundEnabled)
                {
                    g.DrawImage(BackgroundImage, new Point(0, 0));
                }

                //Draw characters
                if (pFormat == PreviewFormat.Normal && charA != string.Empty)
                {
                    Bitmap imageA = CharacterData.DrawCharacterImage(charA, charAEmotions, true, PlayerGender);
                    g.DrawImage(activeChar == charA ? imageA : CharacterData.ColorizeImage(imageA, Color.Black, SkiaSharp.SKBlendMode.Multiply, 128), new Point(-28, baseImage.Height - imageA.Height + 14));
                }
                if (pFormat == PreviewFormat.Normal && charB != string.Empty)
                {
                    Bitmap imageB = CharacterData.DrawCharacterImage(charB, charBEmotions, false, PlayerGender);
                    g.DrawImage(activeChar == charB ? imageB : CharacterData.ColorizeImage(imageB, Color.Black, SkiaSharp.SKBlendMode.Multiply, 128), new Point(baseImage.Width - imageB.Width + 28, baseImage.Height - imageB.Height + 14));
                }

                //Draw textbox
                switch (pFormat)
                {
                case PreviewFormat.Normal:
                    //Text box
                    var normTextbox = (Bitmap)Textboxes[TextboxIndex].Clone();                                     //Grab the textbox
                    var textBounds  = new Bitmap(310, 50);                                                         //Text bounding box
                    textBounds = (Bitmap)PreviewFont.DrawString(textBounds, text, Color.FromArgb(68, 8, 0), 0, 7); //Draw string to bounding box
                    //Draw text to textbox
                    using (Graphics gr = Graphics.FromImage(normTextbox))
                        gr.DrawImage(textBounds, new Point(29, 0));
                    //Textbox to base image
                    g.DrawImage(normTextbox, new Point(10, baseImage.Height - normTextbox.Height + 2));

                    //Name box
                    if (activeChar != string.Empty)
                    {
                        Bitmap namebox = DrawNameBox(activeChar);
                        g.DrawImage(namebox, activeChar == charB ? new Point(baseImage.Width - namebox.Width - 6, baseImage.Height - normTextbox.Height - 14) : new Point(7, baseImage.Height - normTextbox.Height - 14));
                    }

                    //Arrow
                    if (index < FileCont.Messages[messageIndex].Pages.Count - 1)
                    {
                        g.DrawImage(Resources.Properties.Resources.KeyPress, new Point(baseImage.Width - 33, baseImage.Height - normTextbox.Height + 32));
                    }
                    break;

                case PreviewFormat.TopBottom:
                    //Top textbox
                    if (topLine != string.Empty && charA != string.Empty)
                    {
                        var topTextbox = (Bitmap)Textboxes[TextboxIndex].Clone();
                        using (Graphics gr = Graphics.FromImage(topTextbox))
                        {
                            //Character and text
                            gr.DrawImage(CharacterData.DrawCharacterCloseUpImage(charA, charAEmotions, playerGender), new Point(2, 3));
                            gr.DrawImage(PreviewFont.DrawString(new Bitmap(282, 50), topLine, Color.FromArgb(68, 8, 0), 0, 7), new Point(76, 2));

                            //Arrow
                            if (index < FileCont.Messages[messageIndex].Pages.Count - 1 && activeChar == charA)
                            {
                                gr.DrawImage(Resources.Properties.Resources.KeyPress, new Point(topTextbox.Width - 22, 32));
                            }
                        }

                        //Add to base
                        g.DrawImage(topTextbox, new Point(10, -2));

                        //Name box
                        Bitmap topNamebox = DrawNameBox(charA);
                        g.DrawImage(topNamebox, new Point(7, topTextbox.Height - (topNamebox.Height - 15)));
                    }

                    //Bottom textbox
                    if (bottomLine != string.Empty && charB != string.Empty)
                    {
                        var botTextbox = (Bitmap)Textboxes[TextboxIndex].Clone();
                        using (Graphics gr = Graphics.FromImage(botTextbox))
                        {
                            //Character and text
                            gr.DrawImage(CharacterData.DrawCharacterCloseUpImage(charB, charBEmotions, playerGender), new Point(2, 3));
                            gr.DrawImage(PreviewFont.DrawString(new Bitmap(282, 50), bottomLine, Color.FromArgb(68, 8, 0), 0, 7), new Point(76, 2));

                            //Arrow
                            if (index < FileCont.Messages[messageIndex].Pages.Count - 1 && activeChar == charB)
                            {
                                gr.DrawImage(Resources.Properties.Resources.KeyPress, new Point(botTextbox.Width - 22, 32));
                            }
                        }

                        //Add to base
                        g.DrawImage(botTextbox, new Point(10, baseImage.Height - botTextbox.Height - 2));

                        //Name box on top
                        Bitmap botNameBox = DrawNameBox(charB);
                        g.DrawImage(botNameBox, new Point(7, baseImage.Height - botTextbox.Height - 18));
                    }
                    break;

                case PreviewFormat.Skinship:
                    //Textbox
                    var      amieTextbox = (Bitmap)Resources.Properties.Resources.AmieTextbox.Clone();
                    string[] lines       = text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                    var      lineWidths  = new int[lines.Length];
                    for (int i = 0; i < lineWidths.Length; i++)
                    {
                        lineWidths[i] = PreviewFont.GetStringWidth(lines[i]);
                    }

                    var amieTextImage = new Bitmap(lineWidths.Max(), lines.Length * 25);
                    for (int i = 0; i < lines.Length; i++)
                    {
                        amieTextImage = (Bitmap)PreviewFont.DrawString(amieTextImage, lines[i], Color.FromArgb(68, 8, 0), amieTextImage.Width / 2 - lineWidths[i] / 2, amieTextImage.Height / lines.Length - 25 / 2);
                    }

                    using (Graphics gr = Graphics.FromImage(amieTextbox))
                        gr.DrawImage(amieTextImage, new Point(amieTextbox.Width / 2 - amieTextImage.Width / 2, amieTextbox.Height / 2 - amieTextImage.Height / 2));

                    //TODO: Figure out where the textbox should be
                    break;
                }
            }

            return(baseImage);
        }