예제 #1
0
 /// <summary>
 /// Updates any input
 /// </summary>
 /// <param name="input"></param>
 public override void HandleInput(Handlers.InputHandler input)
 {
     /*
      * if (input.isPressed(Keys.Up))
      *  atmosphere.SunDirection += 5f * (float)delta;
      * if (input.isPressed(Keys.Down))
      *  atmosphere.SunDirection -= 5f * (float)delta; */
     if (input.isPressed(Keys.F1))
     {
         CameraManager.SetActiveCamera((int)CameraManager.CameraType.Overhead);
     }
     if (input.isPressed(Keys.F2))
     {
         CameraManager.SetActiveCamera((int)CameraManager.CameraType.FirstPerson);
     }
     if (input.isPressed(Keys.T))
     {
         CameraManager.ActiveCamera.Translate(new Vector3(0, 100f * (float)delta, 0.0f));
     }
     if (input.isHeld(Keys.C))
     {
         CameraManager.ActiveCamera.RotateX(input.MouseMoved.Y);
         CameraManager.ActiveCamera.RotateY(input.MouseMoved.X);
     }
 }
예제 #2
0
        /// <summary>
        /// Handles keyboard/mouse input if typing is enabled
        /// </summary>
        private void handleInput(Handlers.InputHandler input)
        {
#if !XBOX || !XBOX360
            //Do we have text to edit that doesnt match our initial text?
            if (!String.IsNullOrEmpty(text) && text != previousText)
            {
                int characterPos = (int)((input.CurrentMouse.X - Position.X) / (GameManager.Font.Spacing));

                //Have we clicked on a position in our text?
                if (input.hasPressed)
                {
                    //Get caret position
                    if (characterPos > text.Length)
                    {
                        caretPos = text.Length;
                    }
                    else if (characterPos < 0)
                    {
                        caretPos = 0;
                    }
                    else
                    {
                        caretPos = characterPos;
                    }
                }

                //Is this the first time we are holding down the mouse?
                else if (input.isHolding && releasedMouse)
                {
                    releasedMouse  = false;
                    caretPos       = characterPos;
                    selectionStart = caretPos;
                    selectionEnd   = caretPos;
                }

                //Are we finally letting go of the mouse?
                else if (input.hasReleased && !releasedMouse)
                {
                    releasedMouse = true;
                }

                else
                {
                    //We must be still holding our mouse, lets update
                    if (!releasedMouse)
                    {
                        if (characterPos > caretPos &&
                            caretPos < text.Length)
                        {
                            caretPos++;
                            selectionEnd = caretPos;
                        }

                        if (characterPos < caretPos &&
                            caretPos > 0)
                        {
                            caretPos--;
                            selectionStart = caretPos;
                        }
                    }
                }
            }
#endif

            if ((input.isPressed(Keys.Back) || input.isHeld(Keys.Back)) &&
                caretPos > 0)
            {
                text = text.Remove(--caretPos, 1);
            }
            else if ((input.isPressed(Keys.Delete) || input.isHeld(Keys.Delete)) &&
                     caretPos < text.Length)
            {
                text = text.Remove(caretPos, 1);
            }
            else if (input.isPressed(Keys.Left) && caretPos > 0)
            {
                caretPos--;
            }
            else if (input.isPressed(Keys.Right) && caretPos < text.Length)
            {
                caretPos++;
            }
            else if (input.isPressed(Keys.Home))
            {
                caretPos = 0;
            }
            else if (input.isPressed(Keys.End))
            {
                caretPos = text.Length;
            }
            else
            {
                string letter = input.GetTypedInput;
                if (!String.IsNullOrEmpty(letter))
                {
                    if (GameManager.Font.MeasureString(text + letter).X < Size.Width)
                    {
                        if (caretPos == text.Length)
                        {
                            text += letter;
                        }
                        else
                        {
                            text = text.Insert(caretPos, letter);
                        }
                        caretPos++;
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Responds to user input, changing the entry.
        /// </summary>
        /// <param name="input"></param>
        public override void HandleInput(Handlers.InputHandler input)
        {
            //Move to the previous entry?
            if (input.MenuUp)
            {
                _selectedButton--;
                if (_selectedButton < 0)
                {
                    _selectedButton = _buttonEntries.Count - 1;
                }
            }

            //Move to the next entry?
            if (input.MenuDown)
            {
                _selectedButton++;
                if (_selectedButton >= _buttonEntries.Count)
                {
                    _selectedButton = 0;
                }
            }

            //Move to the previous box?
            if (input.MenuLeft)
            {
                _selectedBox--;
                if (_selectedBox < 0)
                {
                    _selectedBox = _boxEntries.Count - 1;
                }
            }

            //Move to the next box?
            if (input.MenuRight)
            {
                _selectedBox++;
                if (_selectedBox >= _boxEntries.Count)
                {
                    _selectedBox = 0;
                }
            }

            //Now search for mouse hovering and input
#if !XBOX || !XBOX360
            int i = 0;
            foreach (ButtonEntry entry in _buttonEntries)
            {
                if (input.isHighlighting(entry.GetRectangle))
                {
                    _selectedButton = i;
                    if (input.hasClickedOn(entry.GetRectangle))
                    {
                        OnSelectButton(_selectedButton);
                    }
                }

                i++;
            }

            i = 0;
            foreach (BoxEntry entry in _boxEntries)
            {
                if (input.isHighlighting(entry.GetRectangle))
                {
                    _selectedBox = i;
                    if (input.hasClickedOn(entry.GetRectangle))
                    {
                        OnSelectBox(_selectedBox);
                    }
                }

                i++;
            }

            i = 0;
            foreach (CheckBoxEntry entry in _checkboxEntries)
            {
                if (input.isHighlighting(entry.GetRectangle))
                {
                    _selectedCheckBox = i;
                    if (input.hasClickedOn(entry.GetRectangle))
                    {
                        OnSelectCheckBox(_selectedCheckBox);
                    }
                }

                i++;
            }
#endif
            //Accept or cancel the entry?
            if (input.MenuSelect)
            {
                OnSelectButton(_selectedButton);
                OnSelectBox(_selectedBox);
            }
            else if (input.MenuCancel)
            {
                OnCancel();
            }
        }
예제 #4
0
        /// <summary>
        /// Handles user input for our message box
        /// </summary>
        /// <param name="input"></param>
        public override void HandleInput(Handlers.InputHandler input)
        {
            if (input.MenuUp)
            {
                okSelected = true;
            }
            else if (input.MenuDown)
            {
                okSelected = false;
            }

            if (input.MenuSelect && !okSelected)
            {
                //Raises the cancelled event then exits
                if (Cancelled != null)
                {
                    Cancelled(this, EventArgs.Empty);
                }

                ExitScreen();
            }

            else if (input.MenuSelect)
            {
                //Raises the accepted event call then exits
                if (Accepted != null)
                {
                    Accepted(this, EventArgs.Empty);
                }

                ExitScreen();
            }
            else if (input.MenuCancel)
            {
                //Raises the cancelled event call then exits
                if (Cancelled != null)
                {
                    Cancelled(this, EventArgs.Empty);
                }

                ExitScreen();
            }

            //Check mouse input
#if !XBOX || !XBOX360
            if (input.isHighlighting(OK))
            {
                okSelected = true;
                if (input.hasClickedOn(OK))
                {
                    if (Accepted != null)
                    {
                        Accepted(this, EventArgs.Empty);
                    }
                    ExitScreen();
                }
            }

            if (!okOnly && input.isHighlighting(Cancel))
            {
                okSelected = false;
                if (input.hasClickedOn(Cancel))
                {
                    if (Cancelled != null)
                    {
                        Cancelled(this, EventArgs.Empty);
                    }
                    ExitScreen();
                }
            }
#endif
        }