Beispiel #1
0
 public Window(float left, float top, float width, float height, string text)
     : base()
 {
     AddComponent(ui = new UILayer(new Renderer(1, Renderer.ViewportPolicy.None, Renderer.RenderOptions.Canvas), 1));
     ui.AddComponent(new MouseHandler());
     //ui.AddComponent(new UIKeyboardHandler());
     ui.AddComponent(new WindowBackground(new Vector2(left + width * 0.5f, top + height * 0.5f), new Vector2(width * 0.5f, height * 0.5f), text));
     ui.AddComponent(new Button("close", "x", new Vector2(left + width - 9, top + 9), new OABB(new Vector2(8, 8)), DoX));
     this.Transparent = true;
     this.Propagate   = false;
 }
Beispiel #2
0
        private void SetUpPauseMenu(UILayer menu)
        {
            var gameWindowSize     = Game.GameWindow.Size;
            var standardButtonSize = new Size(100, 50);
            var buttonPadding      = 10; // padding between buttons

            var resumeButtonPosition = new Point(gameWindowSize.Width / 2 - standardButtonSize.Width / 2,
                                                 gameWindowSize.Height / 2
                                                 - standardButtonSize.Height / 2
                                                 - standardButtonSize.Height);
            var resumeButtonBounds = new Rectangle(resumeButtonPosition, standardButtonSize);
            var resumeText         = new UILabel()
            {
                Background = Color.White,
                Font       = new Font(FontFamily.GenericMonospace, 12),
                FontColor  = Color.Black,
                Text       = "Resume",
                Position   = resumeButtonBounds.Location,
            };
            var resumeButton = new UIButton(resumeText)
            {
                Background = Color.White,
                Bounds     = resumeButtonBounds
            };

            resumeButton.Click += () => _isPaused = false;
            menu.AddComponent(resumeButton);

            var exitButtonPosition = new Point(gameWindowSize.Width / 2 - standardButtonSize.Width / 2,
                                               gameWindowSize.Height / 2
                                               - standardButtonSize.Height / 2
                                               + buttonPadding);
            var exitButtonBounds = new Rectangle(exitButtonPosition, standardButtonSize);
            var exitText         = new UILabel()
            {
                Background = Color.White,
                Position   = exitButtonBounds.Location,
                Text       = "Exit",
                Font       = new Font(FontFamily.GenericMonospace, 12),
                Bounds     = exitButtonBounds
            };
            var exitButton = new UIButton()
            {
                Content = exitText, Background = Color.White, Bounds = exitButtonBounds,
            };

            exitButton.Click += Game.Exit;
            menu.AddComponent(exitButton);
        }
Beispiel #3
0
        public ScoreSheet(UILayer layer, Font font) : base(layer)
        {
            Font = font;
            fields.Clear();
            maxScale = new vec2(fullSize / smallSize);

            var rc = new ImageRenderComponent(layer.Gl, "Resource/Images/UI/Other/scorePaper2.png");

            RenderComponent       = rc;
            imgSize               = ((vec2)rc.Image.Size * smallSize).ScaleToScreen();
            Quad                  = new QuadMesh(imgSize);
            Transform.Translation = new vec2((-layer.UIFrameBuffer.BoundTexture.Size.x / 2) + (Quad.Size.x / 2) + screenPadding, smallSizeHeight);

            layer.AddComponent(this);

            Font.Size = 30 * Program.Settings.ScreenRatio.x * 1.5f;

            for (int i = 0; i < 18; i++)
            {
                var t = new SheetField(this, layer, Font, fieldFuncs[i], !nonLockableIndices.Contains(i), new vec2(fieldLocs[i * 2], -fieldLocs[i * 2 + 1]));
                fields.Add(t);
            }

            OnClick += SheetClicked;
            ClearFields();
        }
Beispiel #4
0
 public override void AddComponent(Component child)
 {
     if (child is UIElement)
     {
         ui.AddComponent(child);
     }
     else
     {
         base.AddComponent(child);
     }
 }
Beispiel #5
0
        private void SetUpHUD(UILayer hud)
        {
            var scoresLabelPosition = new Vector2D(10, 10);
            var scoresLabel         = new UILabel()
            {
                Text       = $"Scores: 0",
                FontColor  = Color.White,
                Background = Color.Transparent,
                Bounds     = new Rectangle(scoresLabelPosition, Size.Empty),
                Font       = new Font(FontFamily.GenericMonospace, 12),
            };

            hud.AddComponent(scoresLabel);

            var hpBarPosition = new Vector2D(scoresLabelPosition.X, scoresLabelPosition.Y + scoresLabel.Bounds.Height + 30);

            _hpBar = new UIBar(100, 100, Color.Red)
            {
                Position   = hpBarPosition,
                Background = Color.Transparent,
                Bounds     = new Rectangle(hpBarPosition, new Size(150, 15))
            };
            hud.AddComponent(_hpBar);
        }
Beispiel #6
0
        public SheetField(ScoreSheet sheet, UILayer layer, Font font, Func <int[], int> func, bool lockable, vec2 offset)
        {
            _sheet   = sheet;
            _offset  = offset;
            Lockable = lockable;
            _layer   = layer;
            Function = func;

            _color = Lockable ? new vec3(1, .6f, .05f) : new vec3(.05f, .7f, .2f);

            TextField = new TextComponent(layer, font, "0")
            {
                Alignment = TextAlignment.Centered,
                Color     = _color
            };
            layer.AddComponent(TextField);

            CalcLocation();
        }