#region File Description //----------------------------------------------------------------------------- // OptionsMenuScreen.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #endregion #region Using Statements using Microsoft.Xna.Framework; #endregion namespace GameStateManagement { /// /// The options screen is brought up over the top of the main menu /// screen, and gives the user a chance to configure the game /// in various hopefully useful ways. /// class OptionsMenuScreen : MenuScreen { #region Fields MenuEntry ungulateMenuEntry; MenuEntry languageMenuEntry; MenuEntry frobnicateMenuEntry; MenuEntry elfMenuEntry; enum Ungulate { BactrianCamel, Dromedary, Llama, } static Ungulate currentUngulate = Ungulate.Dromedary; static string[] languages = { "C#", "French", "Deoxyribonucleic acid" }; static int currentLanguage = 0; static bool frobnicate = true; static int elf = 23; #endregion #region Initialization /// /// Constructor. /// public OptionsMenuScreen() : base("Options") { // Create our menu entries. ungulateMenuEntry = new MenuEntry(string.Empty); languageMenuEntry = new MenuEntry(string.Empty); frobnicateMenuEntry = new MenuEntry(string.Empty); elfMenuEntry = new MenuEntry(string.Empty); SetMenuEntryText(); MenuEntry back = new MenuEntry("Back"); // Hook up menu event handlers. ungulateMenuEntry.Selected += UngulateMenuEntrySelected; languageMenuEntry.Selected += LanguageMenuEntrySelected; frobnicateMenuEntry.Selected += FrobnicateMenuEntrySelected; elfMenuEntry.Selected += ElfMenuEntrySelected; back.Selected += OnCancel; // Add entries to the menu. MenuEntries.Add(ungulateMenuEntry); MenuEntries.Add(languageMenuEntry); MenuEntries.Add(frobnicateMenuEntry); MenuEntries.Add(elfMenuEntry); MenuEntries.Add(back); } /// /// Fills in the latest values for the options screen menu text. /// void SetMenuEntryText() { ungulateMenuEntry.Text = "Preferred ungulate: " + currentUngulate; languageMenuEntry.Text = "Language: " + languages[currentLanguage]; frobnicateMenuEntry.Text = "Frobnicate: " + (frobnicate ? "on" : "off"); elfMenuEntry.Text = "elf: " + elf; } #endregion #region Handle Input /// /// Event handler for when the Ungulate menu entry is selected. /// void UngulateMenuEntrySelected(object sender, PlayerIndexEventArgs e) { currentUngulate++; if (currentUngulate > Ungulate.Llama) currentUngulate = 0; SetMenuEntryText(); } /// /// Event handler for when the Language menu entry is selected. /// void LanguageMenuEntrySelected(object sender, PlayerIndexEventArgs e) { currentLanguage = (currentLanguage + 1) % languages.Length; SetMenuEntryText(); } /// /// Event handler for when the Frobnicate menu entry is selected. /// void FrobnicateMenuEntrySelected(object sender, PlayerIndexEventArgs e) { frobnicate = !frobnicate; SetMenuEntryText(); } /// /// Event handler for when the Elf menu entry is selected. /// void ElfMenuEntrySelected(object sender, PlayerIndexEventArgs e) { elf++; SetMenuEntryText(); } #endregion } }