/* * Util.MenuButton.cs * Authors: Adam Nabinger * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace Util { // TODO: Add support for binding keyboard buttons to MenuButtons /// /// A piece of code to run when the button is pressed /// /// The current game screen in which the scripted code is run in public delegate void Code(GameScreen game); /// /// A simple button for use in a menu. /// public class MenuButton { #region Fields // The file path name of the texture to load protected readonly string mTextureName; // The code to execute when the button is pressed protected readonly Code mExecute; // The location and dimensions of the button protected readonly Rectangle mLocation; // The texture to render the button with protected Texture2D mTexture; #endregion #region Properties /// /// Gets the Location for the button. /// public Rectangle Location { get { return mLocation; } } #endregion #region Creation /// /// Constructor /// /// The file path name for the texture to render with /// The location of the button and its dimensions /// Code to execute for when the button is pressed public MenuButton(string textureName, Rectangle location, Code exe) { mTextureName = textureName; mLocation = location; mExecute = exe; } #endregion #region Management /// /// Loads in all the necessary information for content dependent objects /// /// Reference to the current content manager for loading internal virtual void LoadContent(ContentManager content) { mTexture = content.Load(mTextureName); } #endregion #region Render /// /// Renders the menu button /// /// The current sprite batch object to render with internal virtual void Draw(SpriteBatch sb) { sb.Draw(mTexture, Location, Color.White); } #endregion #region Events /// /// Execute this button's action. /// /// Reference to the current gamescreen public void Execute(GameScreen game) { mExecute.Invoke(game); } #endregion } }