Пример #1
0
        private static int EmitDialoguePage(string dialogue, int start, int linesPerPage, Font font, float maxWidth, List <string> o_results)
        {
            // Count the number of lines needed to emit the dialogue
            int endPos = start;
            int lines  = 0;

            while (endPos < dialogue.Length)
            {
                endPos += font.WordWrap(dialogue, endPos, true, maxWidth);
                endPos += Font.AdvanceWhitespace(dialogue, endPos);
                if ((++lines) == linesPerPage)
                {
                    break;
                }
            }

            if (endPos < dialogue.Length)
            {
                // Clip to the end of the previous sentence
                int sentenceStart = start;
                while (sentenceStart < endPos)
                {
                    int sentenceEnd = sentenceStart + Font.AdvanceSentence(dialogue, sentenceStart);
                    if (sentenceEnd > endPos)
                    {
                        break;
                    }
                    else
                    {
                        sentenceStart = sentenceEnd + Font.AdvanceWhitespace(dialogue, sentenceEnd);
                    }
                }
                if (sentenceStart > start)
                {
                    endPos = sentenceStart;
                }
            }

            // Emit the lines
            int pos  = start;
            int line = 0;

            while (pos < endPos && line < linesPerPage)
            {
                int lineLen = font.WordWrap(dialogue, pos, (endPos - pos), true, maxWidth);
                o_results.Add(dialogue.Substring(pos, lineLen));
                pos += lineLen;
                pos += Font.AdvanceWhitespace(dialogue, pos);
                ++line;
            }
            while (line < linesPerPage)
            {
                o_results.Add("");
                ++line;
            }
            return(endPos - start);
        }
Пример #2
0
            public void AddLine(string text, Font font, Vector4 colour)
            {
                var maxWidth = m_screen.Width * 0.75f;
                var pos      = 0;

                while (true)
                {
                    var partLength = font.WordWrap(text, pos, true, maxWidth);
                    var line       = new Text(font, text.Substring(pos, partLength), colour, TextAlignment.Center);
                    line.Visible       = m_visible;
                    line.LocalPosition = new Vector2(0.0f, m_height);
                    line.Init(m_screen);
                    m_lines.Add(line);
                    m_height += line.Height;
                    pos      += partLength + Font.AdvanceWhitespace(text, pos + partLength);
                    if (pos >= text.Length)
                    {
                        break;
                    }
                }
            }
Пример #3
0
        public LuaArgs wrapTextForOverlay(LuaArgs args)
        {
            var line = args.GetString(0);
            int pos  = m_state.WrapTerminalLine(line, 0);

            if (pos < line.Length)
            {
                var results = new List <LuaValue>();
                results.Add(line.Substring(0, pos));
                pos += Font.AdvanceWhitespace(line, pos);
                while (pos < line.Length)
                {
                    var partLen = m_state.WrapTerminalLine(line, pos);
                    results.Add(line.Substring(pos, partLen));
                    pos += partLen;
                    pos += Font.AdvanceWhitespace(line, pos);
                }
                return(new LuaArgs(results.ToArray()));
            }
            else
            {
                return(new LuaArgs(line));
            }
        }
Пример #4
0
        // Creates a simple YES/NO, OK/CANCEL or just plain OK type box
        public static DialogBox CreateQueryBox(Screen screen, string title, string info, string[] options, bool important)
        {
            // Calculate dimensions
            float width = 256.0f;

            width = Math.Max(width, UIFonts.Smaller.Measure(title, true) + 72.0f);

            // Word wrap
            var           infoFont     = UIFonts.Smaller;
            List <string> infoLines    = new List <string>();
            var           maxInfoWidth = screen.Width - 64.0f - LEFT_MARGIN_SIZE - RIGHT_MARGIN_SIZE;
            int           pos          = 0;

            while (pos < info.Length)
            {
                var lineLength = infoFont.WordWrap(info, pos, true, maxInfoWidth);
                var line       = info.Substring(pos, lineLength);
                infoLines.Add(line);
                width = Math.Max(width, infoFont.Measure(line, true) + LEFT_MARGIN_SIZE + RIGHT_MARGIN_SIZE + 16.0f);
                pos  += lineLength + Font.AdvanceWhitespace(info, pos + lineLength);
            }

            float height =
                TOP_MARGIN_SIZE +
                infoLines.Count * infoFont.Height +
                3.0f +
                UIFonts.Smaller.Height +
                BOTTOM_MARGIN_SIZE;

            // Create dialog
            var dialog = new DialogBox(title, width, height);

            dialog.Important = important;

            // Populate dialog
            float yPos = -0.5f * height + TOP_MARGIN_SIZE;

            for (int i = 0; i < infoLines.Count; ++i)
            {
                var infoText = new Text(infoFont, infoLines[i], UIColours.Text, TextAlignment.Center);
                infoText.Anchor        = Anchor.CentreMiddle;
                infoText.LocalPosition = new Vector2(0.0f, yPos);
                dialog.Elements.Add(infoText);
                yPos += infoText.Font.Height;
            }
            yPos += 3.0f;

            var optionsMenu = new TextMenu(UIFonts.Smaller, options, TextAlignment.Center, MenuDirection.Horizontal);

            optionsMenu.ShowBackground = true;
            optionsMenu.Anchor         = Anchor.CentreMiddle;
            optionsMenu.LocalPosition  = new Vector2(0.0f, yPos);
            optionsMenu.OnClicked     += delegate(object sender, TextMenuClickedEventArgs e)
            {
                if (e.Index >= 0)
                {
                    dialog.Close(e.Index);
                }
            };
            dialog.Elements.Add(optionsMenu);

            return(dialog);
        }