コード例 #1
0
        /// <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(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];

            if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            else
            {
                gameController.HandleInput(input);
            }
        }
コード例 #2
0
 /// <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(InputState input)
 {
 }
コード例 #3
0
        public override void HandleInput(InputState input)
        {
            base.HandleInput(input);

            if (input.GetMouseDown())
            {
                if(closeButtonPosition.Contains(input.GetMousePosition()))
                {
                    this.ExitScreen();
                }
            }
        }
コード例 #4
0
        private void HandleInputReal(InputState input)
        {
            if (realTimeState == RealTimeState.SelectingDestionation)
            {
                if (input.GetMouseDown())
                {
                    Point? mousePoint = grid.GetGridPointFromMousePosition(input.GetMousePosition());
                    if(mousePoint.HasValue)
                    {
                        Rectangle actualPosition = grid.GetGridRectangleFromGridPoint(mousePoint.Value);
                        actionToPoint.PlaceAction(actionToPointLocation, mousePoint.Value, new Vector2(actualPosition.X, actualPosition.Y), buckets);

                        realTimeState = RealTimeState.Idle;

                        --actionsRemaining;

                        //And replensh the ui
                        actions.Add(GameAction.CreateNewActionFromAction(actionToPoint, GetUiPosition(actionToPoint.ActionType)));

                        //Are we done for today?
                        if (actionsRemaining == 0)
                        {
                            EndDay();
                        }
                    }
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Lets the game respond to player input. Unlike the Update method,
 /// this will only be called when the gameplay screen is active.
 /// </summary>
 private void HandleInputDecision(InputState gamePadState)
 {
 }
コード例 #6
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
コード例 #7
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }
コード例 #8
0
        /// <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 void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            /*if (gamePadState.Buttons.Y == ButtonState.Pressed)
                this.missionRunning = false;*/

            IEnumerable<Draggable> actions = null;
            if (this.gameMode == GameMode.REALTIME)
            {
                actions = GetRealDraggables();
            }
            else
            {
                actions = GetDecisionDraggble();
            }

            if (currentState == DragState.Idle)
            {
                if (input.GetMouseDown())
                {
                    //Check if mouse is within any of the dropoff boxes
                    foreach (Draggable draggable in actions)
                    {
                        if (draggable.AttemptBeginDrag(input.GetMousePosition()))
                        {
                            currentState = DragState.Dragging;
                            currentlyDragging = draggable;
                            break;
                        }
                    }
                }
            }
            else if (currentState == DragState.Dragging)
            {
                if (input.GetMouseDown())
                {
                    //Move the one we are dragging
                    Point? gridPoint = grid.GetGridPointFromMousePosition(input.GetMousePosition());
                    Rectangle? lockedRectangle = null;
                    if (gridPoint.HasValue)
                    {
                        lockedRectangle = grid.GetGridRectangleFromGridPoint(gridPoint.Value);
                    }
                    currentlyDragging.UpdateDrag(input.GetMouseDelta(), lockedRectangle);
                }
                else
                {
                    Point? gridPoint = grid.GetGridPointFromMousePosition(input.GetMousePosition());
                    if (gridPoint.HasValue)
                    {
                        //Drop the dropoff in this grid#
                        Rectangle cellRect = grid.GetGridRectangleFromGridPoint(gridPoint.Value);
                        currentlyDragging.EndDrag(cellRect);
                        currentState = DragState.Idle;
                        /*this.buckets.addWater(cellRect.X + (cellRect.Width / 2),
                            cellRect.Y + (cellRect.Height / 2));*/
                        //this.buckets.addWater(cellRect.X + (cellRect.Width / 2),
                        //    cellRect.Y + (cellRect.Height / 2));

                        if (gameMode == GameMode.REALTIME)
                        {
                            ActionPlaced((Actions.GameAction)currentlyDragging, gridPoint.Value, cellRect);
                        }
                        else
                        {
                            DropoffPlaced((Dropoffs.Dropoff)currentlyDragging, cellRect, gridPoint.Value);
                        }
                    }
                    else
                    {
                        EndDrag();
                    }
                }
            }

            if (gameMode == GameMode.REALTIME)
            {
                HandleInputReal(input);
            }
            else
            {
                HandleInputDecision(input);
            }
        }