/// <summary> /// /// </summary> /// <param name="parent"></param> public KeyBindingsScreen(GameScreen parent, KeyboardController controller) : base() { _parent = parent; _parent.Exiting += new EventHandler(_parent_Exiting); _controller = controller; _bindKeyTaskCancel = new CancellationTokenSource(); _bindKeyTask = Task<Keys>.Factory.StartNew(() => { return Keys.None; }, _bindKeyTaskCancel.Token); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _pauseScreen_Exited(object sender, EventArgs e) { _popupScreen = null; _timeline.Resume(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _replayScreen_Exited(object sender, EventArgs e) { if (this.IsExiting) return; _isRewinding = true; _timeline.Enabled = true; _popupScreen = null; }
/// <summary> /// Handle input /// </summary> /// <param name="gameTime">Snapshot of timing values</param> public override void HandleInput(GameTime gameTime) { base.HandleInput(gameTime); if (InputManager.Keyboard.IsKeyReleased(Keys.Escape) && _popupScreen == null) { _timeline.Stop(); _popupScreen = new PauseScreen(this, _controller); this.ScreenManager.AddScreen(_popupScreen); _popupScreen.Exited += new EventHandler(_pauseScreen_Exited); return; } // Don't process game if ended if (_field.HasEnded) return; if (_controller.Action == ControllerAction.Time && _field.Score > 0) _timeline.RewindFrame(); // Don't process if rewinding if (_timeline.IsRewindActive) return; // Action from the controller switch (_controller.Action) { case ControllerAction.Down: _field.CurrentBlock.MoveDown(); break; case ControllerAction.Left: _field.CurrentBlock.MoveLeft(); break; case ControllerAction.Right: _field.CurrentBlock.MoveRight(); break; case ControllerAction.Drop: _field.CurrentBlock.Drop(); break; case ControllerAction.RotateCW: if (_field.CurrentBlock.RotateRight()) _rotateSound.Play(); break; case ControllerAction.RotateCCW: if (_field.CurrentBlock.RotateLeft()) _rotateSound.Play(); break; case ControllerAction.Hold: var oldHoldBlock = _field.HoldBlock; if (_field.SwitchHoldingBlock()) { var holdBlock = _field.HoldBlock; _timeline.Add(new Event() { Apply = () => { _spriteHoldBlock.SetBlock(holdBlock); HoldBlock_OnTypeChanged(holdBlock.Type); }, Undo = () => { _spriteHoldBlock.SetBlock(oldHoldBlock); if (oldHoldBlock != null) HoldBlock_OnTypeChanged(oldHoldBlock.Type); } }); } break; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _field_OnGameEnded(object sender, EventArgs e) { _popupScreen = new ReplayScreen(this); _popupScreen.Exited += new EventHandler(_replayScreen_Exited); this.ScreenManager.AddScreen(_popupScreen); }
/// <summary> /// Removes a screen from the screen manager. You should normally /// use <see cref="GameScreen"/>.ExitScreen instead of calling this directly, so /// the screen can gradually transition off rather than just being /// instantly removed. /// </summary> public void RemoveScreen(GameScreen screen) { // If we have a graphics device, tell the screen to unload content. if ((_graphicsDeviceService != null) && (_graphicsDeviceService.GraphicsDevice != null)) { screen.UnloadContent(); } // Remove the screen from the arrays lock (_screens) _screens.Remove(screen); lock (_screensToUpdate) _screensToUpdate.Remove(screen); // Dispose the Screen (Release it's Content) screen.Dispose(); }
/// <summary> /// Removes all screens but argument screen /// </summary> /// <param name="excluded_screen"></param> public void RemoveAllBut(GameScreen excludedScreen) { List<GameScreen> i_screensToRemove = new List<GameScreen>(); lock (_screens) foreach (GameScreen i_screen in _screens) if (i_screen != excludedScreen) i_screensToRemove.Add(i_screen); foreach (GameScreen i_screen in i_screensToRemove) RemoveScreen(i_screen); i_screensToRemove.Clear(); }
/// <summary> /// Exits all screens /// </summary> public void ExitAll() { GameScreen[] to_remove = null; lock (_screens) { to_remove = new GameScreen[_screens.Count]; _screens.CopyTo(to_remove); } foreach (GameScreen i_screen in to_remove) i_screen.ExitScreen(); }
/// <summary> /// Adds a new screen to the screen manager. /// </summary> public void AddScreen(GameScreen screen) { screen.ScreenManager = this; screen.Game = this.Game; // Initialize this Screen screen.Initialize(); // If we have a graphics device, tell the screen to load content. if ((_graphicsDeviceService != null) && (_graphicsDeviceService.GraphicsDevice != null)) { // Load the Content screen.LoadContent(new ContentManager(Game.Services, "Content")); } // Actually Add the screen to the list lock (_screens) _screens.Add(screen); // Process post actions screen.PostProcessing(); }
public ReplayScreen(GameScreen parent) : base() { _parent = parent; _parent.Exiting += new EventHandler(_parent_Exiting); }