public void AddOptions(Screen screen, string[] newMenuOptions) { //Add all the options to the menu foreach (string s in newMenuOptions) { //measure the current string to find the largest string (we use this as the size of the buttons) Vector2 measure = ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(fontKey)).MeasureString(s.ToUpper()); if (measure.X > optionsBound.Width) optionsBound.Width = (int)Math.Ceiling(measure.X); if (measure.Y > optionsBound.Height) optionsBound.Height = (int)Math.Ceiling(measure.Y); //add to option list optionsMenu.Add(s.ToUpper()); } }
/// <summary> /// Replace a screen with another one. Useful when there is only one screen active and the screens contain the same assets. /// </summary> public void ReplaceScreen(Screen screen) { //remove old screen Screens.Remove(Screens[0]); //start loading the new screen screen.ScreenManager = this; if (screen.RendertargetWidth == 0 && screen.RendertargetHeight == 0) { screen.RendertargetWidth = ScreenBounds.Width; screen.RendertargetHeight = ScreenBounds.Height; } screen.RenderTarget = new RenderTarget2D(this.GraphicsDevice, screen.RendertargetWidth, screen.RendertargetHeight); Screens.Insert(0, screen); AssetsManager.AddScreensAssets(screen.Assets); //remove the old screens assets AssetsManager.RemoveScreensAssets(screen.Assets); Screens[0].Initialize(); }
public void Draw(Screen screen) { //Reset button state optionPressed = null; //Update every button and see if any is pressed for (int s = 0; s < optionsMenu.Count; s++) { Rectangle bound = optionsBound; Vector2 position = new Vector2((startPosition.X) - bound.Width / 2f, startPosition.Y + (s * (optionsBound.Height * spacing))); bound.X = (int)position.X; bound.Y = (int)position.Y; //Check what alignment we want on the button text float orginX; switch (align) { case MenuAlign.Center: orginX = ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(fontKey)).MeasureString(optionsMenu[s]).X / 2 - bound.Width / 2f; break; case MenuAlign.Right: orginX = ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(fontKey)).MeasureString(optionsMenu[s]).X - bound.Width; break; default: orginX = 0; break; } //Add a draw of the button screen.AddText(fontKey, optionsMenu[s], position, new Vector2(orginX, 0), Vector2.One, 0, Color.White, 0); //check if any button was pressed if (Touch == null) return; foreach (TouchLocation t in Touch) { if (bound.Contains(t.Position)) { optionPressed = optionsMenu[s]; break; } if (optionPressed != null) break; } } }
/// <summary> /// Removes a screen from the screen manager. /// </summary> public void RemoveScreen(Screen screen) { Screens.Remove(screen); AssetsManager.RemoveScreensAssets(screen.Assets); }
/// <summary> /// Adds a new screen to the screen manager. /// </summary> public void AddScreen(Screen screen) { screen.ScreenManager = this; if (screen.RendertargetWidth == 0 && screen.RendertargetHeight == 0) { screen.RendertargetWidth = ScreenBounds.Width; screen.RendertargetHeight = ScreenBounds.Height; } screen.RenderTarget = new RenderTarget2D(this.GraphicsDevice, screen.RendertargetWidth, screen.RendertargetHeight); Screens.Insert(0, screen); AssetsManager.AddScreensAssets(screen.Assets); Screens[0].Initialize(); }
public void Draw(Screen screen, GameTime time) { DrawTextfields(screen, time); for (int y = 2; y < _r.GetLength(0); y++) for (int x = 0; x < _r.GetLength(1); x++) DrawButton(x, y, screen); }
private void DrawTextfields(Screen screen, GameTime time) { //Draw field background int buttonW = (int)(_buttonWidth * 0.2f); Rectangle left = new Rectangle(_r[1, 0].X, _r[1, 0].Y, buttonW, _r[1, 0].Height); Rectangle center = new Rectangle(_r[1, 0].X + buttonW, _r[1, 0].Y, (_r[1, 0].Width * (_r.GetLength(1) + 1)) - (buttonW * 2), _r[1, 0].Height); Rectangle right = new Rectangle(_r[1, 0].X + center.Width + buttonW, _r[1, 0].Y, buttonW, _r[1, 0].Height); screen.AddSprite(true, _textureKeys[3], left, Vector2.Zero, 0, Color.White, 1, null, false); screen.AddSprite(true, _textureKeys[4], center, Vector2.Zero, 0, Color.White, 1, null, false); screen.AddSprite(true, _textureKeys[5], right, Vector2.Zero, 0, Color.White, 1, null, false); screen.AddText(_fontKey, _descriptionText, new Vector2( _r[0, 0].X + buttonW, (_r[0, 0].Y + (_textfield.Height / 2)) - ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).MeasureString(_descriptionText).Y / 2), Vector2.Zero, Vector2.One, 0, Color.White, 0); //this is the input string that is drawn //its the same as _inputText but with a few modifications string drawString = _inputText; //do the password thing if (_passwordMode) { int stars = drawString.Length - 0; if (stars < 0) stars = 0; string s = ""; for (int i = 0; i < stars; i++) s += "*"; } //add the flashing indicator if (time.TotalGameTime.Milliseconds / 500 % 2 == 0) drawString += "|"; //format the string so its not to long for the textfield while (((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).MeasureString(drawString).X > center.Width) drawString = drawString.Remove(0, 1); screen.AddText(_fontKey, drawString, new Vector2( _r[1, 0].X + buttonW, (_r[1, 0].Y + (_textfield.Height / 2)) - ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).MeasureString(drawString).Y / 2), Vector2.Zero, Vector2.One, 0, Color.White, 0); }
private void DrawButton(int x, int y, Screen screen) { int buttonW = (int)(_buttonWidth * 0.2f); Rectangle left = new Rectangle( _r[y,x].X, _r[y, x].Y, buttonW, _r[y, x].Height); Rectangle center = new Rectangle( _r[y, x].X + buttonW, _r[y, x].Y, _r[y, x].Width - (buttonW * 2), _r[y, x].Height); Rectangle right = new Rectangle( _r[y, x].X + _r[y, x].Width - buttonW, _r[y, x].Y, buttonW, _r[y, x].Height); screen.AddSprite(true, _textureKeys[0], left, Vector2.Zero, 0, Color.White, 1, null, false); screen.AddSprite(true, _textureKeys[1], center, Vector2.Zero, 0, Color.White, 1, null, false); screen.AddSprite(true, _textureKeys[2], right, Vector2.Zero, 0, Color.White, 1, null, false); screen.AddText(_fontKey, _c[y, x], new Vector2( (_r[y, x].X + (_r[y, x].Width / 2)) - ((SpriteFont) screen.ScreenManager.AssetsManager.GetAsset(_fontKey)). MeasureString(_c[y, x]).X / 2, (_r[y, x].Y + (_r[y, x].Height / 2)) - ((SpriteFont) screen.ScreenManager.AssetsManager.GetAsset(_fontKey)). MeasureString(_c[y, x]).Y / 2), Vector2.Zero, Vector2.One, 0, Color.White, 0); }