示例#1
0
        private wordSplit SplitWords(string s, int i)
        {
            //given a string with the correct number of charsPerLine*2...
            //FIX!!
            string o, t = "", l = "";

            o = s.Substring(0, s.Substring(0, charsPerLine).LastIndexOf(' '));
            if (s.Length > o.Length)
            {
                int c;
                if (s.Length > o.Length + charsPerLine)
                {
                    c = s.Substring(0, o.Length + charsPerLine).LastIndexOf(' ');
                }
                else
                {
                    c = s.Substring(0).LastIndexOf(' ') + 1;
                }
                int b = c - o.Length - 1;
                t = s.Substring(s.Substring(0, charsPerLine).LastIndexOf(' ') + 1, b);
                if (s.Length > o.Length + t.Length + 2)
                {
                    l = s.Substring(s.Substring(0, o.Length + t.Length + 2).LastIndexOf(' ') + 1);
                }
            }
            s = o + "\n" + t;
            wordSplit ws = new wordSplit();

            ws.s = s;

            //return what for i????
            if (l.CompareTo("") == 0)
            {
                ws.iOff = 0;
            }
            else
            {
                ws.iOff = -l.Length;
            }
            return(ws);
        }
示例#2
0
        private wordSplit SplitWords(string s, int i)
        {
            //given a string with the correct number of charsPerLine*2...
            //FIX!!
            string o, t = "", l = "";
            o = s.Substring(0, s.Substring(0, charsPerLine).LastIndexOf(' '));
            if (s.Length > o.Length){
                int c;
                if(s.Length > o.Length + charsPerLine)
                    c = s.Substring(0, o.Length + charsPerLine).LastIndexOf(' ');
                else
                    c = s.Substring(0).LastIndexOf(' ') + 1;
                int b = c - o.Length - 1;
                t = s.Substring(s.Substring(0, charsPerLine).LastIndexOf(' ') + 1, b);
                if (s.Length > o.Length + t.Length + 2){
                    l = s.Substring(s.Substring(0, o.Length + t.Length + 2).LastIndexOf(' ') + 1);
                }
            }
            s = o + "\n" + t;
            wordSplit ws = new wordSplit();
            ws.s = s;

            //return what for i????
            if (l.CompareTo("") == 0)
                ws.iOff = 0;
            else
                ws.iOff = -l.Length;
            return ws;
        }
示例#3
0
        public void Next()
        {
            string res = "";

            //Given a queue of text, need to keep track of where we're showing text from
            //and when to stop showing, as well as when we hit an options menu
            //when it comes across an open tag, it should process it and then delete it
            //from the text.
            if (nextVisibleChar == -1)
            {
                text        = "";
                visibleText = "";
                visible     = false;
                if (usedOp && command != null)
                {
                    res          = options[optionCursor];
                    options      = null;
                    usedOp       = false;
                    optionCursor = 0;
                    //is not letting you get that option in thurr
                    if (command != null)
                    {
                        command = command(res);
                    }
                    //what happens is that the first command gets here, drops the second one, which returns (it shouldn't...)
                    //and the third command is overriden by null here... I think command should return the next command??
                }
                return;
            }
            int j = 0;

            for (int i = nextVisibleChar; i < text.Length; i++)
            {
                //Found option tag!!
                if (i + startOp.Length < text.Length && text.Substring(i, startOp.Length).CompareTo(startOp) == 0)
                {
                    //problem is youre setting up the option but split word chops off that last end
                    //You get in here when you hit the startOp
                    //then you wanna make a temp string minus the op and split it
                    //if the string is done, use op, else, send the op
                    //to the beginning of the nextVisibleChar
                    string debug     = text.Substring(nextVisibleChar);
                    int    cutoutLen = text.Substring(i).IndexOf(endOp) + endOp.Length;
                    string temp      = text.Substring(nextVisibleChar).Remove(i - nextVisibleChar, cutoutLen);
                    //temp has removed option data... split it!! see if it fits...


                    string option  = text.Substring(i + startOp.Length, text.Substring(i + startOp.Length).IndexOf(endOp));
                    string textPt1 = text.Substring(0, i);
                    visibleText = temp;
                    if (visibleText.Length > charsPerLine)
                    {
                        wordSplit s = SplitWords(visibleText, i);
                        visibleText = s.s;
                        //there is either leftover or not
                        //if leftover, then def proceed and adjust nextVisibleChar AND send option to next piece
                        //if no leftover, then you either got a clean break or really are done AND do option...
                        if (s.iOff < 0)
                        {
                            nextVisibleChar += visibleText.Length;//for newline

                            if (text.Length > i + startOp.Length + cutoutLen + endOp.Length)
                            {
                                textPt1 += text.Substring(i + startOp.Length + cutoutLen + endOp.Length);
                            }
                            text = textPt1.Trim();
                            //then add option back in..
                            text = text.Insert(nextVisibleChar, startOp + option + endOp);
                        }
                        else
                        {
                            string d = text.Substring(nextVisibleChar + visibleText.Length);
                            int    a = nextVisibleChar + visibleText.Length - 1 + text.Count((c) => {
                                return(c == ' ');
                            });
                            int b = text.Length - 1 - startOp.Length - cutoutLen - endOp.Length;
                            if (a < b)
                            {
                                nextVisibleChar += visibleText.Length - 1;
                                if (text.Length > i + startOp.Length + cutoutLen + endOp.Length)
                                {
                                    textPt1 += text.Substring(i + startOp.Length + cutoutLen + endOp.Length);
                                }
                                text = textPt1.Trim();
                                //then add option back in..
                                text = text.Insert(nextVisibleChar, startOp + option + endOp);
                            }
                            else
                            {
                                nextVisibleChar = -1;
                                usedOp          = true;
                                options         = option.Split(new char[1] {
                                    ';'
                                });
                                //this is the modification of text to remove the option once it has been processed..
                                if (text.Length > i + startOp.Length + cutoutLen + endOp.Length)
                                {
                                    textPt1 += text.Substring(i + startOp.Length + cutoutLen + endOp.Length);
                                }
                                text = textPt1.Trim();
                            }
                        }
                        //it is going to break and return here to command = null check.
                        //proceed with next command here??
                        return;
                    }
                    else
                    {
                        usedOp  = true;
                        options = option.Split(new char[1] {
                            ';'
                        });
                        //this is the modification of text to remove the option once it has been processed..
                        int m = i + cutoutLen;
                        if (text.Length > m)
                        {
                            textPt1 += text.Substring(i + cutoutLen);
                        }
                        text            = textPt1.Trim();
                        visibleText     = text.Substring(nextVisibleChar);
                        nextVisibleChar = -1;
                        break;
                    }
                }
                if (i >= text.Length - 1)
                {
                    visibleText = text.Substring(nextVisibleChar);
                    if (visibleText.Length > charsPerLine)
                    {
                        wordSplit s = SplitWords(visibleText, i);
                        visibleText = s.s;
                        //there is either leftover or not
                        //if leftover, then def proceed and adjust nextVisibleChar
                        //if no leftover, then you either got a clean break or really are done
                        if (s.iOff < 0)
                        {
                            nextVisibleChar += visibleText.Length;//for newline
                        }
                        else
                        {
                            if (nextVisibleChar + visibleText.Length - 1 < text.Length - 1)
                            {
                                nextVisibleChar += visibleText.Length - 1;
                            }
                            else
                            {
                                nextVisibleChar = -1;
                            }
                        }
                    }
                    else
                    {
                        //DONE!!!!
                        nextVisibleChar = -1;
                        break;
                    }
                    break;
                }
                else if (j > (charsPerLine * 2))
                {
                    visibleText     = text.Substring(nextVisibleChar, j);
                    nextVisibleChar = i;
                    wordSplit s = SplitWords(visibleText, i);
                    visibleText = s.s;
                    //if leftover, then def proceed and adjust nextVisibleChar
                    //if no leftover, then you either got a clean break or really are done
                    nextVisibleChar += s.iOff;
                    break;
                }
                j++;
            }

            return;
        }