/// <summary> /// /// </summary> /// <param name="content"></param> /// <param name="stageWidth"></param> /// <param name="stageHeight"></param> /// <param name="scale"></param> public Menu(ContentManager content, int stageWidth, int stageHeight) { this.stageHeight = stageHeight; this.stageWidth = stageWidth; this.content = content; spriteFont = this.content.Load <SpriteFont>("MenuFont"); menuScreen = MenuScreen.Main; arrowLocation = ArrowLocation.Top; currentKeyboardState = previousKeyboardState = Keyboard.GetState(); }
/// <summary> /// Create a new image picker option. They underlying value is the <c>uint</c> that is the index /// passed to the <paramref name="drawImage"/> and <paramref name="label"/> functions. /// </summary> /// <param name="getValue">Get the current value from the mod config.</param> /// <param name="setValue">Set a new value in the mod config.</param> /// <param name="getMaxValue"> /// The maximum value this option can have, and thus the maximum value that will be passed to /// <paramref name="drawImage"/> and <paramref name="label"/>. Note that this is a function, so /// theoretically the number of options does not have to be fixed. Should this function return a /// value greater than the option's current value then the option's current value will be clamped. /// In common usage, this parameter should be a function that returns one less than the number /// of images. /// </param> /// <param name="maxImageHeight"> /// A function that returns the maximum image height. Used to center /// arrows vertically in the <c cref="ImageOptionArrowLocation.Sides">Sides</c> arrow placement option. /// </param> /// <param name="maxImageWidth"> /// A function that returns the maximum image width. This is used to place the arrows and label. /// </param> /// <param name="drawImage">A function which draws the image for the given index at the given location</param> /// <param name="label">A function to return the string to display given the image index, or <c>null</c> to disable that display.</param> /// <param name="arrowLocation">Where to draw the arrows in relation to the image.</param> /// <param name="labelLocation">Where to draw the label in relation to the image.</param> public ImagePickerOption(Func <uint> getValue, Action <uint> setValue, Func <uint> getMaxValue, Func <int> maxImageHeight, Func <int> maxImageWidth, Action <uint, SpriteBatch, Vector2> drawImage, Func <uint, String> label = null, ArrowLocation arrowLocation = ArrowLocation.Top, LabelLocation labelLocation = LabelLocation.Top) { GetValue = getValue; SetValue = setValue; GetMaxValue = getMaxValue; MaxImageHeight = maxImageHeight; MaxImageWidth = maxImageWidth; DrawImage = drawImage; Label = label; this.arrowLocation = arrowLocation; this.labelLocation = label is not null ? labelLocation : LabelLocation.None; leftButton = new IconButton(Game1.mouseCursors, LeftArrow, "", LeftButtonClicked, false); rightButton = new IconButton(Game1.mouseCursors, RightArrow, "", RightButtonClicked, false); arrowButtonHeight = Math.Max(leftButton.Height, rightButton.Height); }
/// <summary> /// These are the actions that take place for each menu entry. /// </summary> /// <param name="gameTime"></param> /// <param name="curKeyPress"></param> /// <param name="lastKeyPress"></param> /// <param name="numItems"></param> private void MenuControl(GameTime gameTime, KeyboardState curKeyPress, KeyboardState lastKeyPress) { if (menuScreen == MenuScreen.Options || menuScreen == MenuScreen.Players) { if (arrowLocation == ArrowLocation.Top && curKeyPress.IsKeyDown(Keys.Down) && !lastKeyPress.IsKeyDown(Keys.Down)) { arrowLocation = ArrowLocation.Center; } else if (arrowLocation == ArrowLocation.Center && curKeyPress.IsKeyDown(Keys.Up) && !lastKeyPress.IsKeyDown(Keys.Up)) { arrowLocation = ArrowLocation.Top; } } else { if (arrowLocation == ArrowLocation.Center && curKeyPress.IsKeyDown(Keys.Up) && !lastKeyPress.IsKeyDown(Keys.Up)) { arrowLocation = ArrowLocation.Top; } else if (arrowLocation == ArrowLocation.Bottom && curKeyPress.IsKeyDown(Keys.Up) && !lastKeyPress.IsKeyDown(Keys.Up)) { arrowLocation = ArrowLocation.Center; } else if (arrowLocation == ArrowLocation.Center && curKeyPress.IsKeyDown(Keys.Down) && !lastKeyPress.IsKeyDown(Keys.Down)) { arrowLocation = ArrowLocation.Bottom; } else if (arrowLocation == ArrowLocation.Top && curKeyPress.IsKeyDown(Keys.Down) && !lastKeyPress.IsKeyDown(Keys.Down)) { arrowLocation = ArrowLocation.Center; } } }
/// <summary> /// /// </summary> public void Reset() { menuScreen = MenuScreen.Main; arrowLocation = ArrowLocation.Top; }
/// <summary> /// Navigates the red arrow on the screen and changes the menu screen. /// </summary> /// <param name="gameTime"></param> /// <param name="curKeyPress"></param> /// <param name="lastKeyPress"></param> private void MenuSelect(GameTime gameTime, KeyboardState curKeyPress, KeyboardState lastKeyPress, ref bool start) { if (curKeyPress.IsKeyDown(Keys.Enter) && !lastKeyPress.IsKeyDown(Keys.Enter)) { if (arrowLocation == ArrowLocation.Top) { if (menuScreen == MenuScreen.Main) { arrowLocation = ArrowLocation.Top; menuScreen = MenuScreen.SaveSelect; // start game } else if (menuScreen == MenuScreen.Options) { Options.Sound = !Options.Sound; // handle sound on/off } else if (menuScreen == MenuScreen.SaveSelect) { arrowLocation = ArrowLocation.Top; menuScreen = MenuScreen.Players; // number of players } else if (menuScreen == MenuScreen.GameSelect) { LoadGame(); // load a saved game } else if (menuScreen == MenuScreen.Players) { Options.Players = 1; start = true; // will have to change this later, 1 player } } else if (arrowLocation == ArrowLocation.Center) { if (menuScreen == MenuScreen.Main) { arrowLocation = ArrowLocation.Top; menuScreen = MenuScreen.Options; // select options } else if (menuScreen == MenuScreen.SaveSelect) { arrowLocation = ArrowLocation.Top; menuScreen = MenuScreen.GameSelect; // select save } else if (menuScreen == MenuScreen.Options) { Options.Text = !Options.Text; // handle status line on/off } else if (menuScreen == MenuScreen.GameSelect) { LoadGame(); // load a saved game } else if (menuScreen == MenuScreen.Players) { Options.Players = 2; start = true; // will have to change this later, 2 players } } else if (arrowLocation == ArrowLocation.Bottom) { if (menuScreen == MenuScreen.Main) { Platform.ExitGame = true; // exit game } else if (menuScreen == MenuScreen.SaveSelect) { arrowLocation = ArrowLocation.Top; menuScreen = MenuScreen.GameSelect; // select a game } else if (menuScreen == MenuScreen.GameSelect) { LoadGame(); // load a saved game } } } else if (curKeyPress.IsKeyDown(Keys.Escape) && !lastKeyPress.IsKeyDown(Keys.Escape)) { if (menuScreen == MenuScreen.Main) { Platform.ExitGame = true; // exit the game } else if (menuScreen == MenuScreen.SaveSelect || menuScreen == MenuScreen.Options) { menuScreen = MenuScreen.Main; // return to main } else if (menuScreen == MenuScreen.Players || menuScreen == MenuScreen.GameSelect) { menuScreen = MenuScreen.SaveSelect; // return to save selections } arrowLocation = ArrowLocation.Top; } }