//------------------------------------------------------------------------------ // Function: ItemSelector // Author: nholmes // Summary: item constructor, allows user to specify the width of the button, // the options that can be selected from, the vertical position, the // alignment and the font //------------------------------------------------------------------------------ public ItemSelector(Menu menu, Game game, string[] optionsText, int selectedOption, int y, int width, Alignment alignment, SpriteFont font, Color fontColor, int textOffset) : base(menu, game, textOffset) { // store the width of the button, options text, selected option and the font to use this.width = width; this.optionsText = optionsText; this.selectedOption = selectedOption; this.font = font; this.fontColor = fontColor; // set the vy position of this button item position.Y = y; // calculate position based on alignment provided switch (alignment) { case Alignment.left: position.X = 0; break; case Alignment.centre: position.X = (menu.ItemArea.Width / 2) - (width / 2); break; case Alignment.right: position.X = width - (int)font.MeasureString(optionsText[selectedOption]).X; break; default: position.X = 0; break; } // store the size of this button item size.X = width; size.Y = menu.ButtonTexture.Height; }
//------------------------------------------------------------------------------ // Function: ItemSlider // Author: nholmes // Summary: item constructor, allows user to specify the width of the slider, // the values that can be selected between, the vertical position, the // alignment and the font //------------------------------------------------------------------------------ public ItemSlider(Menu menu, Game game, int minValue, int maxValue, int initialValue, int y, int width, Alignment alignment, SpriteFont font, Color fontColor, int textOffset) : base(menu, game, textOffset) { // store the width of the button, options text, selected option and the font to use this.width = width; this.minValue = minValue; this.maxValue = maxValue; this.currentValue = initialValue; this.font = font; this.fontColor = fontColor; // set the vy position of this button item position.Y = y; // calculate position based on alignment provided switch (alignment) { case Alignment.left: position.X = 0; break; case Alignment.centre: position.X = (menu.ItemArea.Width / 2) - (width / 2); break; case Alignment.right: position.X = width; break; default: position.X = 0; break; } // store the size of this button item size.X = width; size.Y = menu.ButtonTexture.Height; }
//------------------------------------------------------------------------------ // Function: ItemText // Author: nholmes // Summary: item constructor, allows user to specify text, vertical position, // alignment and font as well as whether the text is selectable //------------------------------------------------------------------------------ public ItemText(Menu menu, Game game, string text, int y, Alignment alignment, SpriteFont font, Color fontColor, int textOffset, bool selectable) : base(menu, game, textOffset) { // store the text font and font color to use this.text = text; this.font = font; this.fontColor = fontColor; // store whether this item is selectable this.selectable = selectable; // set the vy position of this text item position.Y = y; // calculate position based on alignment provided switch (alignment) { case Alignment.left: position.X = 0; break; case Alignment.centre: position.X = (int)((menu.ItemArea.Width - font.MeasureString(text).X) / 2); break; case Alignment.right: position.X = (int)(menu.ItemArea.Width - font.MeasureString(text).X); break; default: position.X = 0; break; } // store the size of this text item size = font.MeasureString(text); }
//------------------------------------------------------------------------------ // Function: ItemSlider // Author: nholmes // Summary: item constructor, allows user to specify the width of the button, // the text to use, the position and the font //------------------------------------------------------------------------------ public ItemSlider(Menu menu, Game game, int minValue, int maxValue, int initialValue, int x, int y, int width, SpriteFont font, Color fontColor, int textOffset) : base(menu, game, textOffset) { // store the width of the button and the text, font and font color to use this.width = width; this.minValue = minValue; this.maxValue = maxValue; this.currentValue = initialValue; this.font = font; this.fontColor = fontColor; // set the position of this button item position.X = x; position.Y = y; // store the size of this button item size.X = width; size.Y = menu.ButtonTexture.Height; }
//------------------------------------------------------------------------------ // Function: MenuItem // Author: nholmes // Summary: item constructor, stores the menu the item belongs to //------------------------------------------------------------------------------ public MenuItem(Menu menu, Game game, int textOffset) { // store the menu that owns this item this.menu = menu; // store the game system reference this.game = game; // store the text offset this.textOffset = textOffset; // get the display manager service displayManager = (DisplayManager)game.Services.GetService(typeof(DisplayManager)); // get the timer system service timerSystem = (TimerSystem)game.Services.GetService(typeof(TimerSystem)); }
//------------------------------------------------------------------------------ // Function: ItemSelector // Author: nholmes // Summary: item constructor, allows user to specify the width of the button, // the text to use, the position and the font //------------------------------------------------------------------------------ public ItemSelector(Menu menu, Game game, string[] optionsText, int selectedOption, int x, int y, int width, SpriteFont font, Color fontColor, int textOffset) : base(menu, game, textOffset) { // store the width of the button and the text, font and font color to use this.width = width; this.optionsText = optionsText; this.selectedOption = selectedOption; this.font = font; this.fontColor = fontColor; // set the position of this button item position.X = x; position.Y = y; // store the size of this button item size.X = width; size.Y = menu.ButtonTexture.Height; }
//------------------------------------------------------------------------------ // Function: ItemText // Author: nholmes // Summary: item constructor, allows user to specify text, position and font //------------------------------------------------------------------------------ public ItemText(Menu menu, Game game, string text, int x, int y, SpriteFont font, int textOffset, bool selectable) : base(menu, game, textOffset) { // store the text and font to use this.text = text; this.font = font; // store whether this text item is selectable this.selectable = selectable; // set the position of this text item position.X = x; position.Y = y; // store the size of this text item size = font.MeasureString(text); }