Beispiel #1
0
        // Creates a simple YES/NO, OK/CANCEL or just plain OK type box
        public static DialogBox CreateImageQueryBox(string title, ITexture imageTexture, float imageWidth, float imageHeight, string[] options)
        {
            // Calculate dimensions
            float width = 256.0f;

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

            float height =
                TOP_MARGIN_SIZE +
                imageHeight +
                10.0f +
                UIFonts.Smaller.Height +
                BOTTOM_MARGIN_SIZE;

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

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

            var imageBox = new Box(Core.Render.Texture.Get("gui/inset_border.png", true), imageWidth + 6.0f, imageHeight + 6.0f);

            imageBox.Anchor        = Anchor.CentreMiddle;
            imageBox.LocalPosition = new Vector2(-0.5f * imageWidth - 3.0f, yPos);
            dialog.Elements.Add(imageBox);

            var image = new Image(imageTexture, imageWidth, imageHeight);

            image.Anchor        = Anchor.CentreMiddle;
            image.LocalPosition = new Vector2(-0.5f * imageWidth, yPos + 3.0f);
            dialog.Elements.Add(image);
            yPos += imageHeight;
            yPos += 10.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);
        }
Beispiel #2
0
        // Creates a vertical list of options
        public static DialogBox CreateMenuBox(string title, string[] options, bool important)
        {
            // Calculate dimensions
            float width = 300.0f;

            width = Math.Max(width, UIFonts.Smaller.Measure(title, true) + 72.0f);
            for (int i = 0; i < options.Length; ++i)
            {
                var textLength = UIFonts.Default.Measure(options[i], true);
                width = Math.Max(width, LEFT_MARGIN_SIZE + TextMenu.MARGIN + textLength + TextMenu.MARGIN + RIGHT_MARGIN_SIZE);
            }

            float height =
                TOP_MARGIN_SIZE +
                ((float)options.Length * UIFonts.Default.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;
            var   optionsMenu = new TextMenu(UIFonts.Default, options, TextAlignment.Center, MenuDirection.Vertical);

            optionsMenu.ShowBackground = true;
            optionsMenu.MinimumWidth   = (width - LEFT_MARGIN_SIZE - RIGHT_MARGIN_SIZE);
            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);
                }
                else
                {
                    dialog.Close(-1);
                }
            };
            dialog.Elements.Add(optionsMenu);

            return(dialog);
        }
Beispiel #3
0
 public TextMenuOptionSet(TextMenu owner)
 {
     m_owner = owner;
 }
Beispiel #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);
        }
        // Creates a box for entering one line of text
        public static TextEntryDialogBox Create(string title, string defaultText, string textRegex, float textWidth, string[] options)
        {
            // Calculate dimensions
            float width = 256.0f;

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

            float height =
                TOP_MARGIN_SIZE +
                1.2f * UIFonts.Default.Height +
                4.0f +
                UIFonts.Smaller.Height +
                BOTTOM_MARGIN_SIZE;

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

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

            var textBox = new TextBox(width - LEFT_MARGIN_SIZE - RIGHT_MARGIN_SIZE, 1.2f * UIFonts.Default.Height);

            textBox.Anchor        = Anchor.CentreMiddle;
            textBox.LocalPosition = new Vector2(-0.5f * textBox.Width, yPos);
            textBox.Text          = defaultText;
            textBox.Focus         = true;
            dialog.Elements.Add(textBox);
            yPos += textBox.Height + 4.0f;

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

            optionsMenu.ShowBackground = true;
            optionsMenu.Anchor         = Anchor.CentreMiddle;
            optionsMenu.Parent         = dialog;
            optionsMenu.LocalPosition  = new Vector2(0.0f, yPos);
            optionsMenu.OnClicked     += delegate(object sender, TextMenuClickedEventArgs e)
            {
                switch (e.Index)
                {
                case 0:
                {
                    if (Regex.IsMatch(textBox.Text, textRegex))
                    {
                        dialog.EnteredText = textBox.Text;
                        dialog.Close(e.Index);
                    }
                    break;
                }

                default:
                {
                    dialog.Close(e.Index);
                    break;
                }
                }
            };
            dialog.Elements.Add(optionsMenu);

            return(dialog);
        }