/// <summary> /// Constructs a new screen manager component. /// </summary> public ScreenManager(Game game, ContentManager contentManager, MenuInputState menuInputState) : base(game) { content = contentManager; _menuInputState = menuInputState; graphicsDeviceService = (IGraphicsDeviceService)game.Services.GetService( typeof(IGraphicsDeviceService)); if (graphicsDeviceService == null) throw new InvalidOperationException("No graphics device service."); }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(MenuInputState input) { if (input == null) throw new ArgumentNullException("input"); if (!IsExiting) { if (input.PauseGame) { // If they pressed pause, bring up the pause menu screen. const string message = "Exit the game?"; MessageBoxScreen messageBox = _screenFactory.MakeMessageBoxScreen(message); //messageBox.Accepted += (sender, e) => base.ExitScreen(); messageBox.Accepted += ExitScreen; } } base.HandleInput(input); }
/// <summary> /// Responds to user input, accepting or cancelling the message box. /// </summary> public override void HandleInput(MenuInputState input) { if (input.MenuSelect && (!pauseMenu || (input.CurrentGamePadState.Buttons.A == ButtonState.Pressed))) { // Raise the accepted event, then exit the message box. if (Accepted != null) Accepted(this, EventArgs.Empty); ExitScreen(); } else if (input.MenuCancel || (input.MenuSelect && pauseMenu && (input.CurrentGamePadState.Buttons.A == ButtonState.Released))) { // Raise the cancelled event, then exit the message box. if (Cancelled != null) Cancelled(this, EventArgs.Empty); ExitScreen(); } }
/// <summary> /// Allows the screen to handle user input. Unlike Update, this method /// is only called when the screen is active, and not when some other /// screen has taken the focus. /// </summary> public virtual void HandleInput(MenuInputState input) { }
public void SetUp() { stubKeyboard = MockRepository.GenerateStub<IKeyboard>(); menuInputState = new MenuInputState(stubKeyboard); }