summaryrefslogtreecommitdiff
path: root/source/ui/elements/game/PauseMenu.cs
blob: 39281ee5a4be1915082b84ff1a4dd9e31e5cf8c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Celesteia.Game.Components.Items;
using Celesteia.GUIs.Game;
using Celesteia.Resources;
using Celesteia.Screens;
using Celesteia.UI.Properties;
using Microsoft.Xna.Framework;

namespace Celesteia.UI.Elements.Game {
    public class PauseMenu : Container {
        private Image background;
        private IContainer centerMenu;
        private GameGUI _gameGui;

        private float buttonRow(int number) => number * (buttonHeight + buttonSpacing);
        private float buttonHeight = 56f;
        private float buttonSpacing = 10f;

        public PauseMenu(GameGUI gameGui, Rect rect, Button buttonTemplate) : base(rect) {
            _gameGui = gameGui;

            background = new Image(Rect.RelativeFull(rect)).SetColor(new Color(0, 0, 0, 100));
            AddChild(background);

            centerMenu = new Container(new Rect(
                new RelativeUnit(0.5f, GetRect(), RelativeUnit.Orientation.Horizontal),
                new RelativeUnit(0.5f, GetRect(), RelativeUnit.Orientation.Vertical),
                AbsoluteUnit.WithValue(350f),
                AbsoluteUnit.WithValue(2 * (buttonHeight + buttonSpacing) - buttonSpacing)
            ));
            AddChild(centerMenu);

            AddButtons(buttonTemplate);
        }

        private void AddButtons(Button template) {
            centerMenu.AddChild(new Label(new Rect(
                    AbsoluteUnit.WithValue(0f),
                    AbsoluteUnit.WithValue(buttonRow(-1)),
                    new RelativeUnit(1f, centerMenu.GetRect(), RelativeUnit.Orientation.Horizontal),
                    AbsoluteUnit.WithValue(buttonHeight)
                ))
                .SetPivotPoint(new Vector2(0.5f, 0.5f))
                .SetTextProperties(new TextProperties().SetColor(Color.White).SetFont(ResourceManager.Fonts.GetFontType("Hobo")).SetFontSize(24f).SetTextAlignment(TextAlignment.Center))
                .SetText("Paused")
            );

            centerMenu.AddChild(template.Clone()
                .SetNewRect(new Rect(
                    AbsoluteUnit.WithValue(0f),
                    AbsoluteUnit.WithValue(buttonRow(0)),
                    new RelativeUnit(1f, centerMenu.GetRect(), RelativeUnit.Orientation.Horizontal),
                    AbsoluteUnit.WithValue(buttonHeight)
                ))
                .SetText("Back to Game")
                .SetOnMouseUp((button, point) => {
                    _gameGui.TogglePause();
                })
            );

            centerMenu.AddChild(template.Clone()
                .SetNewRect(new Rect(
                    AbsoluteUnit.WithValue(0f),
                    AbsoluteUnit.WithValue(buttonRow(1)),
                    new RelativeUnit(1f, centerMenu.GetRect(), RelativeUnit.Orientation.Horizontal),
                    AbsoluteUnit.WithValue(buttonHeight)
                ))
                .SetText("Return to Title")
                .SetOnMouseUp((button, point) => {
                    _gameGui.Game.LoadScreen(new MainMenuScreen(_gameGui.Game),new MonoGame.Extended.Screens.Transitions.FadeTransition(_gameGui.Game.GraphicsDevice, Color.Black));
                })
            );
        }
    }
}