Exemple #1
0
        public GameplayPauseScreen(Game1 game, GameResources resources, GameplayScreenState gameplayState, Texture2D background) : base(game)
        {
            this.gameplayState = gameplayState;
            this.background    = background;

            panel = new UIPanel(game)
            {
                Position = new Vector2(100, 100),
                Size     = Game.WindowSize - new Vector2(200, 200),
            };

            continueGameButton = new UIButton(resources)
            {
                Position = new Vector2(Game.WindowSize.X / 2, 250),
                Size     = new Vector2(200, 100),
                Text     = "Continue",
            };
            continueGameButton.OnClick += () =>
            {
                ReturnToGame();
            };

            saveButton = new UIButton(resources)
            {
                Position = new Vector2(Game.WindowSize.X / 4, 250),
                Size     = new Vector2(200, 100),
                Text     = "Save",
            };
            saveButton.OnClick += () =>
            {
                string json = JsonConvert.SerializeObject(this.gameplayState, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.Auto,
                    Formatting       = Formatting.Indented,
                });
                File.WriteAllText("save.json", json);
            };

            loadButton = new UIButton(resources)
            {
                Position = new Vector2(Game.WindowSize.X / 4, 360),
                Size     = new Vector2(200, 100),
                Text     = "Load",
            };
            loadButton.OnClick += () =>
            {
                string json = File.ReadAllText("save.json");
                this.gameplayState = JsonConvert.DeserializeObject <GameplayScreenState>(json, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.Auto
                });
                ReturnToGame();
            };

            restartGameButton = new UIButton(resources)
            {
                Position = new Vector2(Game.WindowSize.X / 2, 360),
                Size     = new Vector2(200, 100),
                Text     = "Restart",
            };
            restartGameButton.OnClick += () =>
            {
                Game.SetCurrentScreen(new GameplayScreen(game));
            };

            goBackButton = new UIButton(resources)
            {
                Position = new Vector2(Game.WindowSize.X / 2, 470),
                Size     = new Vector2(200, 100),
                Text     = "Go back",
            };
            goBackButton.OnClick += () =>
            {
                Game.SetCurrentScreen(new MainMenuScreen(game));
            };

            pausedText = new UIText(resources)
            {
                Position = new Vector2(Game.WindowSize.X / 2, 150),
                Text     = "Paused",
            };

            MediaPlayer.Pause();
        }