| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- //-----------------------------------------------------------------------------
- // MainMenuScreen.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Text;
- using GameStateManagement;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- namespace Blackjack
- {
- class MainMenuScreen : MenuScreen
- {
- public static string Theme { get; set; } = "Red";
- private bool needsRefresh = false;
- /// <summary>
- /// Initializes a new instance of the screen.
- /// </summary>
- public MainMenuScreen()
- : base("")
- {
- // Load theme from settings
- Theme = GameSettings.Instance.Theme;
- }
- public override void LoadContent()
- {
- BuildMenuEntries();
- base.LoadContent();
- }
- public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
- {
- // If we were covered and now we're not, refresh the menu entries
- // to pick up any language changes from the settings screen
- if (!coveredByOtherScreen && needsRefresh)
- {
- BuildMenuEntries();
- needsRefresh = false;
- }
- else if (coveredByOtherScreen)
- {
- needsRefresh = true;
- }
- base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
- }
- private void BuildMenuEntries()
- {
- // Clear existing entries
- MenuEntries.Clear();
- // Create our menu entries.
- MenuEntry startGameMenuEntry = new MenuEntry(Resources.Play);
- MenuEntry settingsMenuEntry = new MenuEntry(Resources.Settings);
- MenuEntry exitMenuEntry = new MenuEntry(Resources.Exit);
- // Hook up menu event handlers.
- startGameMenuEntry.Selected += StartGameMenuEntrySelected;
- settingsMenuEntry.Selected += SettingsMenuEntrySelected;
- exitMenuEntry.Selected += OnCancel;
- // Add entries to the menu.
- MenuEntries.Add(startGameMenuEntry);
- MenuEntries.Add(settingsMenuEntry);
- MenuEntries.Add(exitMenuEntry);
- }
- /// <summary>
- /// Respond to "Play" Item Selection
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void StartGameMenuEntrySelected(object sender, EventArgs e)
- {
- foreach (GameScreen screen in ScreenManager.GetScreens())
- screen.ExitScreen();
- // Don't add BackgroundScreen - we don't want the logo on the session browser
- ScreenManager.AddScreen(new SessionBrowserScreen(), null);
- }
- /// <summary>
- /// Respond to "Settings" Item Selection
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void SettingsMenuEntrySelected(object sender, EventArgs e)
- {
- ScreenManager.AddScreen(new SettingsScreen(), null);
- }
- /// <summary>
- /// Respond to "Exit" Item Selection
- /// </summary>
- /// <param name="playerIndex"></param>
- protected override void OnCancel(PlayerIndex playerIndex)
- {
- ScreenManager.Game.Exit();
- }
- }
- }
|