Ejemplo n.º 1
0
        public string SetText(string thetext)
        {
            string StringOut = "";
            if (thetext.Length > 0 && !(lasttext == thetext))
            {
                lasttext = thetext;
                //convert tilemap to point list
                List<tmap> instruction = new List<tmap>();
                bool ignore = false;
                int dr = 0;
                int dc = 0;
                //int maxcol = 22;//the destination...
                for (int p = 0; p < thetext.Length; p++)
                {
                    char c = thetext[p]; //support up to 4 characters/(bytes in a control code) for a single tile
                    string c2 = (thetext.Length > p + 1) ? thetext[p] + thetext[p + 1].ToString() : "~herp";
                    string c3 = (thetext.Length > p + 2) ? thetext[p] + thetext[p + 1].ToString() + thetext[p + 2].ToString() : "~herp";
                    string c4 = (thetext.Length > p + 3) ? thetext[p] + thetext[p + 1].ToString() + thetext[p + 2].ToString() + thetext[p + 3].ToString() : "~herp";

                    string used = "";

                    if (c == '[')
                    {
                        ignore = true;
                        used = c.ToString();
                    }
                    else if (c == ']')
                    {
                        ignore = false;
                        used = c.ToString();
                    }
                    else if (c == '\r')
                    {
                        dr++;
                        p++;
                        dc = 0;
                        used = "\r\n";
                    }
                    else if (c == ' ' && !ignore)
                    {
                        tmap tm = new tmap();
                        tm.Source = new Point(-1, -1);
                        tm.Dest = new Point(dc, dr);
                        instruction.Add(tm);
                        dc += (Settings.Default.VisualTileWidth / 2); //spaces are a half-width
                        used = c.ToString();
                    }
                    else if (!ignore)
                    {
                        if (tilemap.ContainsKey(c4))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c4].col, tilemap[c4].row);
                            tm.Dest = new Point(dc, dr);
                            instruction.Add(tm);
                            p += c4.Length - 1;
                            dc += tilemap[c4].width-1;
                            used = c4;
                        }
                        else if (tilemap.ContainsKey(c3))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c3].col, tilemap[c3].row);
                            tm.Dest = new Point(dc, dr);
                            instruction.Add(tm);
                            p += c3.Length - 1;
                            dc += tilemap[c3].width-1;
                            used = c3;
                        }
                        else if (tilemap.ContainsKey(c2))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c2].col, tilemap[c2].row);
                            tm.Dest = new Point(dc, dr);
                            instruction.Add(tm);
                            p += c2.Length - 1;
                            dc += tilemap[c2].width-1;
                            used = c2;
                        }
                        else if (tilemap.ContainsKey(c.ToString()))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c.ToString()].col, tilemap[c.ToString()].row);
                            tm.Dest = new Point(dc, dr);
                            instruction.Add(tm);
                            dc += tilemap[c.ToString()].width-1;
                            used = c.ToString();
                        }
                    }
                    else
                    {//character ignored by the preview
                        used = c.ToString();
                    }

                    //build the output string
                    //if max tiles per line width is exceeded, increment the dr (drawing row)
                    if (dc > (Settings.Default.MaxTilesPerLine * Settings.Default.VisualTileWidth))
                    {
                        dr++;
                        dc = 0;
                        //find the last space character and apply line break there... if none, just do it here.
                        string[] sp = StringOut.Split(' ');
                        if (sp.Length > 0)
                        {
                            StringOut = "";
                            for (int hc = 0; hc < sp.Length; hc++)
                            {
                                if (hc == sp.Length - 1)
                                {//last one
                                    StringOut += "\r\n" + sp[hc];
                                }
                                else
                                {//any other
                                    StringOut += ((StringOut == "") ? "" : " ") + sp[hc];
                                }
                            }
                            StringOut += used;
                        }
                        else
                        {
                            StringOut += "\r\n" + used;
                        }
                    }
                    else
                    {//we havent gone beyond the line width
                        StringOut += used;
                    }
                }
                DrawText(font, instruction);
            }
            return StringOut;
        }
Ejemplo n.º 2
0
        public void SetText(string thetext)
        {
            if (thetext.Length > 0 && !(lasttext == thetext))
            {
                lasttext = thetext;
                //convert tilemap to point list
                List <tmap> instruction = new List <tmap>();
                bool        ignore      = false;
                int         dr          = 0;
                int         dc          = 0;
                //int maxcol = 22;//the destination...
                for (int p = 0; p < thetext.Length; p++)
                {
                    char   c  = thetext[p]; //support up to 4 characters in a single tile
                    string c2 = (thetext.Length > p + 1) ? thetext[p] + thetext[p + 1].ToString() : "~herp";
                    string c3 = (thetext.Length > p + 2) ?thetext[p] + thetext[p + 1].ToString() + thetext[p + 2].ToString(): "~herp";
                    string c4 = (thetext.Length > p + 3) ?thetext[p] + thetext[p + 1].ToString() + thetext[p + 2].ToString() + thetext[p + 3].ToString() : "~herp";
                    //foreach (char c in thetext)
                    //{
                    if (c == '[')
                    {
                        ignore = true;
                    }
                    else if (c == ']')
                    {
                        ignore = false;
                    }
                    else if (c == '\r')
                    {
                        dr++;
                        p++;
                        dc = 0;
                    }
                    else if (c == ' ' && !ignore)
                    {
                        tmap tm = new tmap();
                        tm.Source = new Point(-1, -1);
                        tm.Dest   = new Point(dc, dr);
                        instruction.Add(tm);
                        dc++;
                    }
                    else if (!ignore)
                    {
                        if (tilemap.ContainsKey(c4))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c4].col, tilemap[c4].row);
                            tm.Dest   = new Point(dc, dr);
                            instruction.Add(tm);
                            p += c4.Length - 1;
                            dc++;
                        }
                        else if (tilemap.ContainsKey(c3))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c3].col, tilemap[c3].row);
                            tm.Dest   = new Point(dc, dr);
                            instruction.Add(tm);
                            p += c3.Length - 1;
                            dc++;
                        }
                        else if (tilemap.ContainsKey(c2))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c2].col, tilemap[c2].row);
                            tm.Dest   = new Point(dc, dr);
                            instruction.Add(tm);
                            p += c2.Length - 1;
                            dc++;
                        }
                        else if (tilemap.ContainsKey(c.ToString()))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c.ToString()].col, tilemap[c.ToString()].row);
                            tm.Dest   = new Point(dc, dr);
                            instruction.Add(tm);
                            dc++;
                        }
                    }
                    //}
                }

                DrawText(font, instruction);
            }
        }
Ejemplo n.º 3
0
        public string SetText(string thetext)
        {
            string StringOut = "";

            if (thetext.Length > 0 && !(lasttext == thetext))
            {
                lasttext = thetext;
                //convert tilemap to point list
                List <tmap> instruction = new List <tmap>();
                bool        ignore      = false;
                int         dr          = 0;
                int         dc          = 0;
                //int maxcol = 22;//the destination...
                for (int p = 0; p < thetext.Length; p++)
                {
                    char   c  = thetext[p]; //support up to 4 characters/(bytes in a control code) for a single tile
                    string c2 = (thetext.Length > p + 1) ? thetext[p] + thetext[p + 1].ToString() : "~herp";
                    string c3 = (thetext.Length > p + 2) ? thetext[p] + thetext[p + 1].ToString() + thetext[p + 2].ToString() : "~herp";
                    string c4 = (thetext.Length > p + 3) ? thetext[p] + thetext[p + 1].ToString() + thetext[p + 2].ToString() + thetext[p + 3].ToString() : "~herp";

                    string used = "";

                    if (c == '[')
                    {
                        ignore = true;
                        used   = c.ToString();
                    }
                    else if (c == ']')
                    {
                        ignore = false;
                        used   = c.ToString();
                    }
                    else if (c == '\r')
                    {
                        dr++;
                        p++;
                        dc   = 0;
                        used = "\r\n";
                    }
                    else if (c == ' ' && !ignore)
                    {
                        tmap tm = new tmap();
                        tm.Source = new Point(-1, -1);
                        tm.Dest   = new Point(dc, dr);
                        instruction.Add(tm);
                        dc  += (Settings.Default.VisualTileWidth / 2); //spaces are a half-width
                        used = c.ToString();
                    }
                    else if (!ignore)
                    {
                        if (tilemap.ContainsKey(c4))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c4].col, tilemap[c4].row);
                            tm.Dest   = new Point(dc, dr);
                            instruction.Add(tm);
                            p   += c4.Length - 1;
                            dc  += tilemap[c4].width - 1;
                            used = c4;
                        }
                        else if (tilemap.ContainsKey(c3))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c3].col, tilemap[c3].row);
                            tm.Dest   = new Point(dc, dr);
                            instruction.Add(tm);
                            p   += c3.Length - 1;
                            dc  += tilemap[c3].width - 1;
                            used = c3;
                        }
                        else if (tilemap.ContainsKey(c2))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c2].col, tilemap[c2].row);
                            tm.Dest   = new Point(dc, dr);
                            instruction.Add(tm);
                            p   += c2.Length - 1;
                            dc  += tilemap[c2].width - 1;
                            used = c2;
                        }
                        else if (tilemap.ContainsKey(c.ToString()))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c.ToString()].col, tilemap[c.ToString()].row);
                            tm.Dest   = new Point(dc, dr);
                            instruction.Add(tm);
                            dc  += tilemap[c.ToString()].width - 1;
                            used = c.ToString();
                        }
                    }
                    else
                    {//character ignored by the preview
                        used = c.ToString();
                    }

                    //build the output string
                    //if max tiles per line width is exceeded, increment the dr (drawing row)
                    if (dc > (Settings.Default.MaxTilesPerLine * Settings.Default.VisualTileWidth))
                    {
                        dr++;
                        dc = 0;
                        //find the last space character and apply line break there... if none, just do it here.
                        string[] sp = StringOut.Split(' ');
                        if (sp.Length > 0)
                        {
                            StringOut = "";
                            for (int hc = 0; hc < sp.Length; hc++)
                            {
                                if (hc == sp.Length - 1)
                                {//last one
                                    StringOut += "\r\n" + sp[hc];
                                }
                                else
                                {//any other
                                    StringOut += ((StringOut == "") ? "" : " ") + sp[hc];
                                }
                            }
                            StringOut += used;
                        }
                        else
                        {
                            StringOut += "\r\n" + used;
                        }
                    }
                    else
                    {//we havent gone beyond the line width
                        StringOut += used;
                    }
                }
                DrawText(font, instruction);
            }
            return(StringOut);
        }
Ejemplo n.º 4
0
        public void SetText(string thetext)
        {
            if (thetext.Length > 0 && !(lasttext == thetext))
            {
                lasttext = thetext;
                //convert tilemap to point list
                List<tmap> instruction = new List<tmap>();
                bool ignore = false;
                int dr = 0;
                int dc = 0;
                //int maxcol = 22;//the destination...
                for (int p = 0; p < thetext.Length; p++)
                {
                    char c = thetext[p]; //support up to 4 characters in a single tile
                    string c2 = (thetext.Length > p + 1) ? thetext[p] + thetext[p + 1].ToString() : "~herp";
                    string c3 = (thetext.Length > p + 2) ?thetext[p] + thetext[p + 1].ToString() + thetext[p + 2].ToString(): "~herp";
                    string c4 = (thetext.Length > p + 3) ?thetext[p] + thetext[p + 1].ToString() + thetext[p + 2].ToString() + thetext[p + 3].ToString() : "~herp";
                    //foreach (char c in thetext)
                    //{
                    if (c == '[')
                    {
                        ignore = true;
                    }
                    else if (c == ']')
                    {
                        ignore = false;
                    }
                    else if (c == '\r')
                    {
                        dr++;
                        p++;
                        dc = 0;
                    }
                    else if (c == ' ' && !ignore)
                    {
                        tmap tm = new tmap();
                        tm.Source = new Point(-1, -1);
                        tm.Dest = new Point(dc, dr);
                        instruction.Add(tm);
                        dc++;
                    }
                    else if (!ignore)
                    {
                        if (tilemap.ContainsKey(c4))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c4].col, tilemap[c4].row);
                            tm.Dest = new Point(dc, dr);
                            instruction.Add(tm);
                            p += c4.Length - 1;
                            dc++;
                        }
                        else if (tilemap.ContainsKey(c3))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c3].col, tilemap[c3].row);
                            tm.Dest = new Point(dc, dr);
                            instruction.Add(tm);
                            p += c3.Length - 1;
                            dc++;
                        }
                        else if (tilemap.ContainsKey(c2))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c2].col, tilemap[c2].row);
                            tm.Dest = new Point(dc, dr);
                            instruction.Add(tm);
                            p += c2.Length - 1;
                            dc++;
                        }
                        else if (tilemap.ContainsKey(c.ToString()))
                        {
                            tmap tm = new tmap();
                            tm.Source = new Point(tilemap[c.ToString()].col, tilemap[c.ToString()].row);
                            tm.Dest = new Point(dc, dr);
                            instruction.Add(tm);
                            dc++;
                        }
                    }
                    //}
                }

                DrawText(font, instruction);
            }
        }