Example #1
0
        public void Update()
        {
            units = new List <UnitDesc>();

            var Buttons = display_line.Buttons;

            for (int i = 0; i < Buttons.Length; ++i)
            {
                var btn         = Buttons[i];
                var ud          = new UnitDesc();
                var fontname    = FontUtils.default_fontname;
                var btnlength   = btn.StrArray.Length;
                var validstr    = 0;
                var validlength = 0;
                var richedit    = false;
                ud.width      = 0;
                ud.color      = FontColor;
                ud.monospaced = true;
                StringBuilder content = new StringBuilder();
                for (int si = 0; si < btnlength; ++si)
                {
                    var s = btn.StrArray[si];
                    if (string.IsNullOrEmpty(s.Str.Trim()))
                    {
                        continue;
                    }
                    if (validstr == 0)
                    {
                        validstr = 1;
                    }
                    else
                    {
                        validstr += 1;
                        break;
                    }
                }
                for (int si = 0; si < btnlength; ++si)
                {
                    var s = btn.StrArray[si];
                    if (s is MinorShift.Emuera.GameView.ConsoleImagePart)
                    {
                        var cp = s as MinorShift.Emuera.GameView.ConsoleImagePart;
                        if (cp.cropped_image != null)
                        {
                            if (ud.image_indices == null)
                            {
                                ud.image_indices = new List <int>();
                            }
                            ud.image_indices.Add(si);
                            continue;
                        }
                    }

                    var str = s.Str;
                    validlength += str.Trim().Length;
                    if (string.IsNullOrEmpty(str))
                    {
                        continue;
                    }
                    var fontsize  = (float)FontSize;
                    var fontstyle = uEmuera.Drawing.FontStyle.Regular;
                    var fontcolor = FontColor;

                    if (s is MinorShift.Emuera.GameView.ConsoleStyledString)
                    {
                        var u = (MinorShift.Emuera.GameView.ConsoleStyledString)s;
                        fontsize      = u.Font.Size;
                        fontstyle     = u.Font.Style;
                        fontname      = u.Font.FontFamily.Name;
                        ud.monospaced = u.Font.Monospaced;
                    }
                    if (s is MinorShift.Emuera.GameView.AConsoleColoredPart)
                    {
                        var u = (MinorShift.Emuera.GameView.AConsoleColoredPart)s;
                        fontcolor = GenericUtils.ToUnityColor(u.pColor);
                    }
                    if (fontstyle != uEmuera.Drawing.FontStyle.Regular)
                    {
                        if ((fontstyle & uEmuera.Drawing.FontStyle.Bold) > 0)
                        {
                            str      = string.Format("<b>{0}</b>", str);
                            richedit = true;
                        }
                        if ((fontstyle & uEmuera.Drawing.FontStyle.Italic) > 0)
                        {
                            str      = string.Format("<i>{0}</i>", str);
                            richedit = true;
                        }
                        if ((fontstyle & uEmuera.Drawing.FontStyle.Underline) > 0)
                        {
                            ud.underline = true;
                        }
                        if ((fontstyle & uEmuera.Drawing.FontStyle.Strikeout) > 0)
                        {
                            ud.strickout = true;
                        }
                    }
                    if (fontsize != FontSize)
                    {
                        str      = string.Format("<size={0}>{1}</size>", (int)fontsize, str);
                        richedit = true;
                    }
                    if (fontcolor != FontColor)
                    {
                        if (validstr != 1)
                        {
                            str      = string.Format("<color=#{0}>{1}</color>", GenericUtils.GetColorCode(fontcolor), str);
                            richedit = true;
                        }
                        else
                        {
                            ud.color = fontcolor;
                        }
                    }
                    content.Append(str);
                    ud.width += uEmuera.Utils.GetDisplayLength(s.Str, fontsize);
                }
                ud.empty = (validlength == 0);
                if (ud.empty)
                {
                    ud.content = null;
                }
                else
                {
                    ud.content = content.ToString();
                }
                ud.isbutton      = btn.IsButton;
                ud.generation    = (int)btn.Generation;
                ud.code          = btn.Inputs;
                ud.posx          = btn.PointX;
                ud.relative_posx = btn.RelativePointX;
                if (fontname != FontUtils.default_fontname)
                {
                    ud.fontname = fontname;
                }
                else
                {
                    ud.fontname = null;
                }
                ud.richedit = richedit;

                units.Add(ud);
            }
        }