Beispiel #1
0
        public Popup(string[] text, params string[] options)
        {
            Rect = Geometry.ScaleRect(new IntRect(0, 0, width: (int)Screen.Width, height: (int)Screen.Height), 80, 80);
            Text = new PopupText()
            {
                Lines = text, FontSize = Screen.FontSize
            };
            Options      = new PopupOption[options.Length];
            IsActive     = false;
            ChosenOption = null;

            Text.LineHeight = (int)Screen.FontSize + 2;
            Text.SideMargin = 10;
            int maxHeight     = Rect.Height * 80 / 100;
            int paragraphSize = text.Length * Text.LineHeight;

            Text.TopSpace = maxHeight / 2 - paragraphSize / 2;

            var buttonRow = new IntRect(
                left: Rect.Left + Rect.Width * 5 / 100,
                top: Rect.Top + Rect.Height * 80 / 100,
                width: Rect.Width * 90 / 100,
                height: Rect.Height * 10 / 100
                );
            int width        = buttonRow.Width / options.Length;
            var buttonSpaces = new IntRect[options.Length];

            for (int i = 0; i < options.Length; ++i)
            {
                var space = buttonSpaces[i];
                space.Left   = buttonRow.Left + width * i;
                space.Top    = buttonRow.Top;
                space.Width  = width;
                space.Height = buttonRow.Height;

                Options[i] = new PopupOption()
                {
                    Rect     = Geometry.ScaleRect(space, 75, 90),
                    Text     = options[i],
                    FontSize = Screen.FontSize
                };
            }

            CreateTextures();
        }
Beispiel #2
0
        public Menu(string title, params string[] options)
        {
            Rect = Geometry.ScaleRect(new IntRect(0, 0, width: (int)Screen.Width, height: (int)Screen.Height), 60, 80);
            Text = new PopupText()
            {
                Lines    = new string[] { title },
                FontSize = Screen.FontSize * 2
            };
            Options = new PopupOption[options.Length];

            Text.LineHeight = (int)Screen.FontSize * 2 + 2;
            Text.SideMargin = 10;
            int textMaxHeight = Rect.Height * 20 / 100;

            Text.TopSpace = 0;

            var buttonBox = new IntRect(
                left: Rect.Left + Rect.Width * 10 / 100,
                top: Rect.Top + textMaxHeight + 10,
                width: Rect.Width * 80 / 100,
                height: Rect.Height * 80 / 100 - 20
                );
            int height       = buttonBox.Height / options.Length;
            var buttonSpaces = new IntRect[options.Length];

            for (int i = 0; i < options.Length; ++i)
            {
                var space = buttonSpaces[i];
                space.Left   = buttonBox.Left;
                space.Top    = buttonBox.Top + height * i;
                space.Width  = buttonBox.Width;
                space.Height = height;

                Options[i] = new PopupOption()
                {
                    Rect     = Geometry.ScaleRect(space, 90, 60),
                    Text     = options[i],
                    FontSize = Screen.FontSize
                };
            }

            CreateTextures();
        }
Beispiel #3
0
 private void OnClick(object sender, MouseButtonEventArgs mbe)
 {
     if (mbe.Button == Mouse.Button.Right)
     {
         SetChosenOption("right click");
         return;
     }
     if (mbe.Button == Mouse.Button.Left)
     {
         foreach (PopupOption opt in Options)
         {
             if (opt.Rect.Contains(mbe.X, mbe.Y))
             {
                 PreviousRect  = opt.Rect;
                 opt.Rect      = Geometry.ScaleRect(opt.Rect, 95, 95);
                 ClickedOption = opt;
                 return;
             }
         }
     }
 }
Beispiel #4
0
        private void OnRelease(object sender, MouseButtonEventArgs mbe)
        {
            if (mbe.Button == Mouse.Button.Left)
            {
                if (ClickedOption != null)
                {
                    ClickedOption.Rect = PreviousRect;
                }
                foreach (PopupOption opt in Options)
                {
                    if (opt.Rect.Contains(mbe.X, mbe.Y))
                    {
                        if (opt == ClickedOption)
                        {
                            SetChosenOption(opt.Text);
                        }

                        return;
                    }
                }
                ClickedOption = null;
            }
        }