コード例 #1
0
ファイル: HighScoreScreen.cs プロジェクト: Peewi/PuzzleGame
        /// <summary>
        /// A screen for viewing high scores
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen HighScoreScreen(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                Purpose = ScreenPurpose.Options
            };

            retVal.Escape += (sender, e) =>
            {
                g1.UI.CloseTopScreen();
            };
            var mainsp = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };

            retVal.Children.Add(mainsp);
            var scoreLabel = new TextPanel(game)
            {
                Text             = "High score",
                Width            = 128,
                SpriteBackground = false
            };

            mainsp.Children.Add(scoreLabel);
            int rank = 0;

            foreach (var item in g1.Score.Scores)
            {
                rank++;
                var scoresp = new StackPanel(game)
                {
                    Direction = LayoutDirection.Horizontal
                };
                mainsp.Children.Add(scoresp);
                var rankText = new TextPanel(game)
                {
                    Text             = rank.ToString(),
                    Height           = 8,
                    Width            = 8,
                    SpriteBackground = false
                };
                scoresp.Children.Add(rankText);
                var name = new TextPanel(game)
                {
                    Text             = item.Item1,
                    SpriteBackground = false,
                    Height           = 8
                };
                scoresp.Children.Add(name);
                var score = new TextPanel(game)
                {
                    Text             = item.Item2.ToString(),
                    SpriteBackground = false,
                    Height           = 8
                };
                scoresp.Children.Add(score);
            }
            //
            var buttonRow = new StackPanel(game)
            {
                Direction      = LayoutDirection.Vertical,
                MainNavigation = true
            };

            mainsp.Children.Add(buttonRow);
            var back = new Button(game)
            {
                Text = "Back"
            };

            buttonRow.Children.Add(back);
            back.OnClick += (snder, e) =>
            {
                retVal.InvokeEscape();
            };
            retVal.UpdateLayout(retVal.Bounds);
            return(retVal);
        }
コード例 #2
0
        /// <summary>
        /// A screen that asks if you want to save your changed options before closing
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public static UIScreen CloseOptionsConfirmationScreen(Game game)
        {
            Game1 g1     = (Game1)game;
            var   retVal = new UIScreen(game)
            {
                EscapeCloses = true
            };
            var sp = new StackPanel(game)
            {
                HAnchor          = HorizontalAnchor.Middle,
                VAnchor          = VerticalAnchor.Middle,
                SpriteBackground = true,
                Border           = 4
            };

            retVal.Children.Add(sp);
            var label1 = new TextPanel(game)
            {
                Text             = "Settings changed",
                SpriteBackground = false
            };

            sp.Children.Add(label1);
            var label2 = new TextPanel(game)
            {
                Text             = "Save changes?",
                SpriteBackground = false
            };

            sp.Children.Add(label2);
            var buttonRow = new StackPanel(game)
            {
                Direction      = LayoutDirection.Horizontal,
                MainNavigation = true
            };

            sp.Children.Add(buttonRow);
            var saveButton = new Button(game)
            {
                Text  = "Save",
                Width = 48
            };

            saveButton.OnClick += (snder, e) =>
            {
                g1.Config.Save();
                g1.ApplyGraphicsConfig();
                g1.UI.CloseTopScreen();
                g1.UI.CloseTopScreen();
            };
            buttonRow.Children.Add(saveButton);
            var discardButton = new Button(game)
            {
                Text  = "Discard",
                Width = 48
            };

            discardButton.OnClick += (snder, e) =>
            {
                g1.UI.CloseTopScreen();
                g1.UI.CloseTopScreen();
            };
            buttonRow.Children.Add(discardButton);
            var cancelButton = new Button(game)
            {
                Text  = "Cancel",
                Width = 48
            };

            cancelButton.OnClick += (snder, e) =>
            {
                g1.UI.CloseTopScreen();
            };
            buttonRow.Children.Add(cancelButton);

            retVal.UpdateLayout(retVal.Bounds);
            return(retVal);
        }