public ConsoleButtonString(EmueraConsole console, ConsoleStyledString[] strs)
 {
     this.parent = console;
     this.strArray = strs;
     IsButton = false;
     PointX = -1;
     Width = -1;
     ErrPos = null;
 }
 public ConsoleButtonString(EmueraConsole console, ConsoleStyledString[] strs, string inputs,ScriptPosition pos)
     : this(console, strs)
 {
     this.Inputs = inputs;
     IsButton = true;
     IsInteger = false;
     Generation = parent.NewButtonGeneration;
     console.UpdateGeneration();
     ErrPos = pos;
 }
 public ConsoleButtonString(EmueraConsole console, ConsoleStyledString[] strs, Int64 input)
     : this(console, strs)
 {
     this.Input = input;
     Inputs = input.ToString();
     IsButton = true;
     IsInteger = true;
     Generation = parent.NewButtonGeneration;
     console.UpdateGeneration();
     ErrPos = null;
 }
Beispiel #4
0
        //単一のボタンフラグ
        //public bool IsButton { get; set; }
        //indexの文字数の前方文字列とindex以降の後方文字列に分割
        public ConsoleStyledString DivideAt(int index, StringMeasure sm)
        {
            //if ((index <= 0)||(index > Str.Length)||this.Error)
            //	return null;
            ConsoleStyledString ret = DivideAt(index);

            if (ret == null)
            {
                return(null);
            }
            this.SetWidth(sm, XsubPixel);
            ret.SetWidth(sm, XsubPixel);
            return(ret);
        }
Beispiel #5
0
        private static int getDivideIndex(AConsoleDisplayPart part, StringMeasure sm)
        {
            if (!part.CanDivide)
            {
                return(-1);
            }
            ConsoleStyledString css = part as ConsoleStyledString;

            if (part == null)
            {
                return(-1);
            }
            int    widthLimit = Config.DrawableWidth - css.PointX;
            string str        = css.Str;
            Font   font       = css.Font;
            int    point      = 0;
            int    highLength = str.Length; //widthLimitを超える最低の文字index(文字数-1)。
            int    lowLength  = 0;          //超えない最大の文字index。
            //int i = (int)(widthLimit / fontDisplaySize);//およその文字数を推定
            //if (i > str.Length - 1)//配列の外を参照しないように。
            //	i = str.Length - 1;
            int i = lowLength;            //およその文字数を推定←やめた

            string test = null;

            while ((highLength - lowLength) > 1)            //差が一文字以下になるまで繰り返す。
            {
                test  = str.Substring(0, i);
                point = sm.GetDisplayLength(test, font);
                if (point <= widthLimit)                //サイズ内ならlowLengthを更新。文字数を増やす。
                {
                    lowLength = i;
                    i++;
                }
                else                //サイズ外ならhighLengthを更新。文字数を減らす。
                {
                    highLength = i;
                    i--;
                }
            }
            return(lowLength);
        }
        public ConsoleStyledString DivideAt(int index)
        {
            if (index <= 0 || index > Str.Length || Error)
            {
                return(null);
            }
            var str = Str.Substring(index, Str.Length - index);

            Str = Str.Substring(0, index);
            var ret = new ConsoleStyledString();

            ret.Font         = Font;
            ret.Str          = str;
            ret.Color        = Color;
            ret.ButtonColor  = ButtonColor;
            ret.colorChanged = colorChanged;
            ret.StringStyle  = StringStyle;
            ret.XsubPixel    = XsubPixel;
            return(ret);
        }
Beispiel #7
0
        public ConsoleStyledString DivideAt(int index)
        {
            if ((index <= 0) || (index > Str.Length) || this.Error)
            {
                return(null);
            }
            string str = Str.Substring(index, Str.Length - index);

            this.Str = Str.Substring(0, index);
            ConsoleStyledString ret = new ConsoleStyledString();

            ret.Font         = this.Font;
            ret.Str          = str;
            ret.Color        = this.Color;
            ret.ButtonColor  = this.ButtonColor;
            ret.colorChanged = this.colorChanged;
            ret.StringStyle  = this.StringStyle;
            ret.XsubPixel    = this.XsubPixel;
            return(ret);
        }
Beispiel #8
0
        /// <summary>
        /// 物理行をボタン単位に分割。引数のcssListの内容は変更される場合がある。
        /// </summary>
        /// <returns></returns>
        private ConsoleButtonString[] createButtons(List <AConsoleDisplayPart> cssList)
        {
            StringBuilder buf = new StringBuilder();

            for (int i = 0; i < cssList.Count; i++)
            {
                buf.Append(cssList[i].Str);
            }
            List <ButtonPrimitive> bpList = ButtonStringCreator.SplitButton(buf.ToString());

            ConsoleButtonString[] ret      = new ConsoleButtonString[bpList.Count];
            AConsoleDisplayPart[] cssArray = null;
            if (ret.Length == 1)
            {
                cssArray = new AConsoleDisplayPart[cssList.Count];
                cssList.CopyTo(cssArray);
                if (bpList[0].CanSelect)
                {
                    ret[0] = new ConsoleButtonString(parent, cssArray, bpList[0].Input);
                }
                else
                {
                    ret[0] = new ConsoleButtonString(parent, cssArray);
                }
                return(ret);
            }
            int cssStartCharIndex  = 0;
            int buttonEndCharIndex = 0;
            int cssIndex           = 0;
            List <AConsoleDisplayPart> buttonCssList = new List <AConsoleDisplayPart>();

            for (int i = 0; i < ret.Length; i++)
            {
                ButtonPrimitive bp = bpList[i];
                buttonEndCharIndex += bp.Str.Length;
                while (true)
                {
                    if (cssIndex >= cssList.Count)
                    {
                        break;
                    }
                    AConsoleDisplayPart css = cssList[cssIndex];
                    if (cssStartCharIndex + css.Str.Length >= buttonEndCharIndex)
                    {                    //ボタンの終端を発見
                        int used = buttonEndCharIndex - cssStartCharIndex;
                        if (used > 0 && css.CanDivide)
                        {                        //cssの区切りの途中でボタンの区切りがある。
                            ConsoleStyledString newCss = ((ConsoleStyledString)css).DivideAt(used);
                            if (newCss != null)
                            {
                                cssList.Insert(cssIndex + 1, newCss);
                                newCss.PointX = css.PointX + css.Width;
                            }
                        }
                        buttonCssList.Add(css);
                        cssStartCharIndex += css.Str.Length;
                        cssIndex++;
                        break;
                    }
                    //ボタンの終端はまだ先。
                    buttonCssList.Add(css);
                    cssStartCharIndex += css.Str.Length;
                    cssIndex++;
                }
                cssArray = new AConsoleDisplayPart[buttonCssList.Count];
                buttonCssList.CopyTo(cssArray);
                if (bp.CanSelect)
                {
                    ret[i] = new ConsoleButtonString(parent, cssArray, bp.Input);
                }
                else
                {
                    ret[i] = new ConsoleButtonString(parent, cssArray);
                }
                buttonCssList.Clear();
            }
            return(ret);
        }
Beispiel #9
0
        /// <summary>
        /// 表示行からhtmlへの変換
        /// </summary>
        /// <param name="lines"></param>
        /// <returns></returns>
        public static string DisplayLine2Html(ConsoleDisplayLine[] lines, bool needPandN)
        {
            if (lines == null || lines.Length == 0)
            {
                return("");
            }
            StringBuilder b = new StringBuilder();

            if (needPandN)
            {
                switch (lines[0].Align)
                {
                case DisplayLineAlignment.LEFT:
                    b.Append("<p align='left'>");
                    break;

                case DisplayLineAlignment.CENTER:
                    b.Append("<p align='center'>");
                    break;

                case DisplayLineAlignment.RIGHT:
                    b.Append("<p align='right'>");
                    break;
                }
                b.Append("<nobr>");
            }
            for (int dispCounter = 0; dispCounter < lines.Length; dispCounter++)
            {
                if (dispCounter != 0)
                {
                    b.Append("<br>");
                }
                ConsoleButtonString[] buttons = lines[dispCounter].Buttons;
                for (int buttonCounter = 0; buttonCounter < buttons.Length; buttonCounter++)
                {
                    string titleValue = null;
                    if (!string.IsNullOrEmpty(buttons[buttonCounter].Title))
                    {
                        titleValue = Escape(buttons[buttonCounter].Title);
                    }
                    bool hasTag = buttons[buttonCounter].IsButton || titleValue != null ||
                                  buttons[buttonCounter].PointXisLocked;
                    if (hasTag)
                    {
                        if (buttons[buttonCounter].IsButton)
                        {
                            string attrValue = Escape(buttons[buttonCounter].Inputs);
                            b.Append("<button value='");
                            b.Append(attrValue);
                            b.Append("'");
                        }
                        else
                        {
                            b.Append("<nonbutton");
                        }
                        if (titleValue != null)
                        {
                            b.Append(" title='");
                            b.Append(titleValue);
                            b.Append("'");
                        }
                        if (buttons[buttonCounter].PointXisLocked)
                        {
                            b.Append(" pos='");
                            b.Append(buttons[buttonCounter].RelativePointX.ToString());
                            b.Append("'");
                        }
                        b.Append(">");
                    }
                    AConsoleDisplayPart[] parts = buttons[buttonCounter].StrArray;
                    for (int cssCounter = 0; cssCounter < parts.Length; cssCounter++)
                    {
                        if (parts[cssCounter] is ConsoleStyledString)
                        {
                            ConsoleStyledString css = parts[cssCounter] as ConsoleStyledString;
                            b.Append(getStringStyleStartingTag(css.StringStyle));
                            b.Append(Escape(css.Str));
                            b.Append(getClosingStyleStartingTag(css.StringStyle));
                        }
                        else if (parts[cssCounter] is ConsoleImagePart)
                        {
                            b.Append(parts[cssCounter].AltText);
                            //ConsoleImagePart img = (ConsoleImagePart)parts[cssCounter];
                            //b.Append("<img src='");
                            //b.Append(Escape(img.ResourceName));
                            //if(img.ButtonResourceName != null)
                            //{
                            //	b.Append("' srcb='");
                            //	b.Append(Escape(img.ButtonResourceName));
                            //}
                            //b.Append("'>");
                        }
                        else if (parts[cssCounter] is ConsoleShapePart)
                        {
                            b.Append(parts[cssCounter].AltText);
                        }
                    }
                    if (hasTag)
                    {
                        if (buttons[buttonCounter].IsButton)
                        {
                            b.Append("</button>");
                        }
                        else
                        {
                            b.Append("</nonbutton>");
                        }
                    }
                }
            }
            if (needPandN)
            {
                b.Append("</nobr>");
                b.Append("</p>");
            }
            return(b.ToString());
        }
        //indexの文字数の前方文字列とindex以降の後方文字列に分割
        public ConsoleButtonString DivideAt(int divIndex, StringMeasure sm)
        {
            if (divIndex <= 0)
            {
                return(null);
            }
            List <AConsoleDisplayPart> cssListA = new List <AConsoleDisplayPart>();
            List <AConsoleDisplayPart> cssListB = new List <AConsoleDisplayPart>();
            int  index    = 0;
            int  cssIndex = 0;
            bool b        = false;

            for (cssIndex = 0; cssIndex < strArray.Length; cssIndex++)
            {
                if (b)
                {
                    cssListB.Add(strArray[cssIndex]);
                    continue;
                }
                int length = strArray[cssIndex].Str.Length;
                if (divIndex < index + length)
                {
                    ConsoleStyledString oldcss = strArray[cssIndex] as ConsoleStyledString;
                    if (oldcss == null || !oldcss.CanDivide)
                    {
                        throw new ExeEE("文字列分割異常");
                    }
                    ConsoleStyledString newCss = oldcss.DivideAt(divIndex - index, sm);
                    cssListA.Add(oldcss);
                    if (newCss != null)
                    {
                        cssListB.Add(newCss);
                    }
                    b = true;
                    continue;
                }
                else if (divIndex == index + length)
                {
                    cssListA.Add(strArray[cssIndex]);
                    b = true;
                    continue;
                }
                index += length;
                cssListA.Add(strArray[cssIndex]);
            }
            if ((cssIndex >= strArray.Length) && (cssListB.Count == 0))
            {
                return(null);
            }
            AConsoleDisplayPart[] cssArrayA = new AConsoleDisplayPart[cssListA.Count];
            AConsoleDisplayPart[] cssArrayB = new AConsoleDisplayPart[cssListB.Count];
            cssListA.CopyTo(cssArrayA);
            cssListB.CopyTo(cssArrayB);
            this.strArray = cssArrayA;
            ConsoleButtonString ret = new ConsoleButtonString(null, cssArrayB);

            this.CalcWidth(sm, XsubPixel);
            ret.CalcWidth(sm, 0);
            this.CalcPointX(this.PointX);
            ret.CalcPointX(this.PointX + this.Width);
            ret.parent     = this.parent;
            ret.ParentLine = this.ParentLine;
            ret.IsButton   = this.IsButton;
            ret.IsInteger  = this.IsInteger;
            ret.Input      = this.Input;
            ret.Inputs     = this.Inputs;
            ret.Generation = this.Generation;
            ret.ErrPos     = this.ErrPos;
            ret.Title      = this.Title;
            return(ret);
        }
 private int getDivideIndex(ConsoleStyledString css, StringMeasure sm)
 {
     int widthLimit = Config.WindowX - css.PointX;
     string str = css.Str;
     Font font = css.Font;
     int point = 0;
     int highLength = str.Length - 1;//widthLimitを超える最低の文字index(文字数-1)。
     int lowLength = 0;//超えない最大の文字index。
     //int i = (int)(widthLimit / fontDisplaySize);//およその文字数を推定
     int i = 0;//およその文字数を推定
     if (i > str.Length - 1)//配列の外を参照しないように。
         i = str.Length - 1;
     string test = null;
     while ((highLength - lowLength) > 1)//差が一文字以下になるまで繰り返す。
     {
         test = str.Substring(0, i);
         point = sm.GetDisplayLength(test, font);
         if (point <= widthLimit)//サイズ内ならlowLengthを更新。文字数を増やす。
         {
             lowLength = i;
             i++;
         }
         else//サイズ外ならhighLengthを更新。文字数を減らす。
         {
             highLength = i;
             i--;
         }
     }
     return lowLength;
 }
 private ConsoleButtonString createPlainButton(List<ConsoleStyledString> cssList)
 {
     ConsoleStyledString[] cssArray = new ConsoleStyledString[cssList.Count];
     cssList.CopyTo(cssArray);
     cssList.Clear();
     return new ConsoleButtonString(parent, cssArray);
 }
 /// <summary>
 /// 物理行をボタン単位に分割。引数のcssListの内容は変更される場合がある。
 /// </summary>
 /// <returns></returns>
 private ConsoleButtonString[] createButtons(List<ConsoleStyledString> cssList)
 {
     StringBuilder buf = new StringBuilder();
     for (int i = 0; i < cssList.Count; i++)
     {
         buf.Append(cssList[i].Str);
     }
     List<ButtonPrimitive> bpList = ButtonStringCreator.SplitButton(buf.ToString());
     ConsoleButtonString[] ret = new ConsoleButtonString[bpList.Count];
     ConsoleStyledString[] cssArray = null;
     if (ret.Length == 1)
     {
         cssArray = new ConsoleStyledString[cssList.Count];
         cssList.CopyTo(cssArray);
         if (bpList[0].CanSelect)
             ret[0] = new ConsoleButtonString(parent, cssArray, bpList[0].Input);
         else
             ret[0] = new ConsoleButtonString(parent, cssArray);
         return ret;
     }
     int cssStartCharIndex = 0;
     int buttonEndCharIndex = 0;
     int cssIndex = 0;
     List<ConsoleStyledString> buttonCssList = new List<ConsoleStyledString>();
     for (int i = 0; i < ret.Length; i++)
     {
         ButtonPrimitive bp = bpList[i];
         buttonEndCharIndex += bp.Str.Length;
         while (true)
         {
             if (cssIndex >= cssList.Count)
                 break;
             ConsoleStyledString css = cssList[cssIndex];
             if (cssStartCharIndex + css.Str.Length >= buttonEndCharIndex)
             {//ボタンの終端を発見
                 int used = buttonEndCharIndex - cssStartCharIndex;
                 if (used > 0)
                 {//cssの区切りの途中でボタンの区切りがある。
                     ConsoleStyledString newCss = css.DivideAt(used);
                     if (newCss != null)
                     {
                         cssList.Insert(cssIndex + 1, newCss);
                         newCss.PointX = css.PointX + css.Width;
                     }
                 }
                 buttonCssList.Add(css);
                 cssStartCharIndex += css.Str.Length;
                 cssIndex++;
                 break;
             }
             //ボタンの終端はまだ先。
             buttonCssList.Add(css);
             cssStartCharIndex += css.Str.Length;
             cssIndex++;
         }
         cssArray = new ConsoleStyledString[buttonCssList.Count];
         buttonCssList.CopyTo(cssArray);
         if (bp.CanSelect)
             ret[i] = new ConsoleButtonString(parent, cssArray, bp.Input);
         else
             ret[i] = new ConsoleButtonString(parent, cssArray);
         buttonCssList.Clear();
     }
     return ret;
 }
 private ConsoleButtonString createButton(List<ConsoleStyledString> cssList, string input, ScriptPosition pos)
 {
     ConsoleStyledString[] cssArray = new ConsoleStyledString[cssList.Count];
     cssList.CopyTo(cssArray);
     cssList.Clear();
     return new ConsoleButtonString(parent, cssArray, input, pos);
 }
 //indexの文字数の前方文字列とindex以降の後方文字列に分割
 public ConsoleButtonString DivideAt(int divIndex, StringMeasure sm)
 {
     if (divIndex <= 0)
         return null;
     List<ConsoleStyledString> cssListA = new List<ConsoleStyledString>();
     List<ConsoleStyledString> cssListB = new List<ConsoleStyledString>();
     int index = 0;
     int cssIndex = 0;
     bool b = false;
     for (cssIndex = 0; cssIndex < strArray.Length; cssIndex++)
     {
         if (b)
         {
             cssListB.Add(strArray[cssIndex]);
             continue;
         }
         int length = strArray[cssIndex].Str.Length;
         if (divIndex < index + length)
         {
             ConsoleStyledString newCss = strArray[cssIndex].DivideAt(divIndex - index, sm);
             cssListA.Add(strArray[cssIndex]);
             if (newCss != null)
                 cssListB.Add(newCss);
             b = true;
             continue;
         }
         else if (divIndex == index + length)
         {
             cssListA.Add(strArray[cssIndex]);
             b = true;
             continue;
         }
         index += length;
         cssListA.Add(strArray[cssIndex]);
     }
     if((cssIndex >= strArray.Length) && (cssListB.Count == 0))
         return null;
     ConsoleStyledString[] cssArrayA = new ConsoleStyledString[cssListA.Count];
     ConsoleStyledString[] cssArrayB = new ConsoleStyledString[cssListB.Count];
     cssListA.CopyTo(cssArrayA);
     cssListB.CopyTo(cssArrayB);
     this.strArray = cssArrayA;
     ConsoleButtonString ret = null;
     if (this.IsButton)
         ret = new ConsoleButtonString(this.parent, cssArrayB, this.Input);
     else
         ret = new ConsoleButtonString(this.parent, cssArrayB);
     this.SetWidth(sm);
     ret.SetWidth(sm);
     return ret;
 }
 public ConsoleStyledString DivideAt(int index)
 {
     if ((index <= 0) || (index > Str.Length))
         return null;
     string str = Str.Substring(index, Str.Length - index);
     this.Str = Str.Substring(0, index);
     ConsoleStyledString ret = new ConsoleStyledString();
     ret.Font = this.Font;
     ret.Str = str;
     ret.Color = this.Color;
     ret.colorChanged = this.colorChanged;
     return ret;
 }