コード例 #1
0
 public GuiElementSubtitleList(ICoreClientAPI capi, ElementBounds bounds)
     : base(capi, bounds)
 {
     textTexture = new LoadedTexture(capi);
     Font        = CairoFont.WhiteSmallText();
     textUtil    = new TextDrawUtil();
     for (int i = 0; i < MAX_SOUNDS; i++)
     {
         soundList[i] = new Sound();
     }
 }
コード例 #2
0
        private string[] Paginate(string fullText, CairoFont font, double pageWidth, double pageHeight)
        {
            TextDrawUtil           textUtil  = new TextDrawUtil();
            Stack <string>         lines     = new Stack <string>();
            IEnumerable <TextLine> textlines = textUtil.Lineize(font, fullText, pageWidth).Reverse();

            foreach (var val in textlines)
            {
                lines.Push(val.Text);
            }


            double lineheight      = textUtil.GetLineHeight(font);
            int    maxlinesPerPage = (int)(pageHeight / lineheight);

            List <string> pagesTemp   = new List <string>();
            StringBuilder pageBuilder = new StringBuilder();

            while (lines.Count > 0)
            {
                int currentPageLines = 0;

                while (currentPageLines < maxlinesPerPage && lines.Count > 0)
                {
                    string   line  = lines.Pop();
                    string[] parts = line.Split(new string[] { "___NEWPAGE___" }, 2, StringSplitOptions.None);

                    if (parts.Length > 1)
                    {
                        pageBuilder.AppendLine(parts[0]);
                        if (parts[1].Length > 0)
                        {
                            lines.Push(parts[1]);
                        }
                        break;
                    }

                    currentPageLines++;
                    pageBuilder.AppendLine(line);
                }

                string pageText = pageBuilder.ToString().TrimEnd();

                if (pageText.Length > 0)
                {
                    pagesTemp.Add(pageText);
                }

                pageBuilder.Clear();
            }

            return(pagesTemp.ToArray());
        }
コード例 #3
0
        private bool onClickItem(int page)
        {
            currentLoreItemIndex = page;
            this.page            = 0;

            CairoFont     font     = CairoFont.WhiteDetailText().WithFontSize(17).WithLineHeightMultiplier(1.15f);
            TextDrawUtil  prober   = new TextDrawUtil();
            StringBuilder fulltext = new StringBuilder();

            JournalEntry entry = journalitems[currentLoreItemIndex];

            for (int p = 0; p < entry.Chapters.Count; p++)
            {
                if (p > 0)
                {
                    fulltext.AppendLine();
                }
                fulltext.Append(Lang.Get(entry.Chapters[p].Text));
            }

            pages = Paginate(fulltext.ToString(), font, GuiElement.scaled(629), GuiElement.scaled(450));


            double elemToDlgPad = GuiStyle.ElementToDialogPadding;

            ElementBounds textBounds   = ElementBounds.Fixed(0, 0, 630, 450);
            ElementBounds dialogBounds = textBounds.ForkBoundingParent(elemToDlgPad, elemToDlgPad + 20, elemToDlgPad, elemToDlgPad + 30).WithAlignment(EnumDialogArea.LeftMiddle);

            dialogBounds.fixedX = 350;


            Composers["loreItem"] =
                capi.Gui
                .CreateCompo("loreItem", dialogBounds)
                .AddShadedDialogBG(ElementBounds.Fill, true)
                .AddDialogTitleBar(Lang.Get(journalitems[page].Title), CloseIconPressedLoreItem)
                .AddRichtext(pages[0], font, textBounds, "page")
                .AddDynamicText("1 / " + pages.Length, CairoFont.WhiteSmallishText().WithOrientation(EnumTextOrientation.Center), ElementBounds.Fixed(250, 500, 100, 30), "currentpage")
                .AddButton(Lang.Get("Previous Page"), OnPrevPage, ElementBounds.Fixed(17, 500, 100, 23).WithFixedPadding(10, 4), CairoFont.WhiteSmallishText())
                .AddButton(Lang.Get("Next Page"), OnNextPage, ElementBounds.Fixed(520, 500, 100, 23).WithFixedPadding(10, 4), CairoFont.WhiteSmallishText())
                .Compose()
            ;

            return(true);
        }