Ejemplo n.º 1
0
        public override void OnKeyDown(Microsoft.Xna.Framework.Input.Keys key)
        {
            // HACK Write keydowns to debug box for debug purposes. Change key handling for proper release.
            System.Diagnostics.Debug.WriteLine(key.ToString());


            if (key.Equals(Keys.Back) && !keyboardHandler.Typing)
            {
                currentGame.screenManager.FocusScreen(GameScreen.TITLE_MAINMENU);
            }
        }
Ejemplo n.º 2
0
        private void createAndAddInstructionsTextBlock()
        {
            string instructionText = $"1. Press {k_StartGameKey.ToString()} to start game.{Environment.NewLine}" +
                                     $"2. Press {k_EscapeGameKey.ToString()} to exit.{Environment.NewLine}" +
                                     $"3. Press {k_MainMenuKey.ToString()} to proceed to Main Menu.";
            Vector2 textPos = CenterOfViewport + new Vector2(0, k_SpacingBetweenTextBlocks);

            m_InstructionsTextBlock = new TextBlock(Game, instructionText, textPos);
            m_InstructionsTextBlock.Initialize();
            m_InstructionsTextBlock.PositionOrigin = m_InstructionsTextBlock.TextCenter;
            this.Add(m_InstructionsTextBlock);
        }
Ejemplo n.º 3
0
        private void InputManager_KeyPressedCallback(Microsoft.Xna.Framework.Input.Keys key)
        {
            if (!HasKeyboardFocus || !IsEditable)
            {
                return;
            }
            Keys prevKey = Key;

            Key  = key;
            Text = key.ToString();
            OnTextModified.Invoke(Text);
            OnKeyModified.Invoke(prevKey, Key, this);
        }
Ejemplo n.º 4
0
        private static Keys XnaKeyToKey(XnaKeys key)
        {
            Keys kv = Keys.None;

            switch (key)
            {
            case XnaKeys.OemComma:
                kv = Keys.Oemcomma;
                break;

            case XnaKeys.OemTilde:
                kv = Keys.Oemtilde;
                break;

            case XnaKeys.OemPlus:
                kv = Keys.Oemplus;
                break;

            default:
                if (Enum.IsDefined(typeof(Keys), key.ToString()) | key.ToString().Contains(","))
                {
                    kv |= (Keys)Enum.Parse(typeof(Keys), key.ToString());
                }
                break;
            }

            if (key == XnaKeys.LeftShift)
            {
                kv = Keys.LShiftKey | Keys.Shift;
            }
            if (key == XnaKeys.RightShift)
            {
                kv = Keys.RShiftKey | Keys.Shift;
            }

            return(kv);
        }
Ejemplo n.º 5
0
        private void HandleKey(Microsoft.Xna.Framework.Input.Keys currentKey)
        {
            string keyString = currentKey.ToString();

            if (currentKey == Microsoft.Xna.Framework.Input.Keys.Space && stringInBox.Length < lenghtMax)
            {
                stringInBox += " ";
            }
            else if ((currentKey == Microsoft.Xna.Framework.Input.Keys.Back || currentKey == Microsoft.Xna.Framework.Input.Keys.Delete) && stringInBox.Length > 0)
            {
                stringInBox = stringInBox.Remove(stringInBox.Length - 1);
            }
            else if (stringInBox == null || stringInBox.Length < lenghtMax)
            {
                stringInBox += KeyInput(currentKey);
            }
            timerKey = 0;
        }
Ejemplo n.º 6
0
        private static Keys XnaKeyToKey(XnaKeys key)
        {
            Keys kv = Keys.None;

            switch (key)
            {
                case XnaKeys.OemComma:
                    kv = Keys.Oemcomma;
                    break;
                case XnaKeys.OemTilde:
                    kv = Keys.Oemtilde;
                    break;
                case XnaKeys.OemPlus:
                    kv = Keys.Oemplus;
                    break;
                default:
                    if (Enum.IsDefined(typeof(Keys), key.ToString()) | key.ToString().Contains(","))
                    {
                        kv |= (Keys)Enum.Parse(typeof(Keys), key.ToString());
                    }
                    break;
            }

            if (key == XnaKeys.LeftShift)
            {
                kv = Keys.LShiftKey | Keys.Shift;
            }
            if (key == XnaKeys.RightShift)
            {
                kv = Keys.RShiftKey | Keys.Shift;
            }

            return kv;
        }
Ejemplo n.º 7
0
        private string HandleShift(KeyboardState keyboard, Microsoft.Xna.Framework.Input.Keys key)
        {
            if (key.ToString().Length == 1)
            {
                return(key.ToString().ToUpper());
            }

            if ((keyboard.GetPressedKeys()[0] == Microsoft.Xna.Framework.Input.Keys.LeftShift ||
                 keyboard.GetPressedKeys()[0] == Microsoft.Xna.Framework.Input.Keys.RightShift) && (keyboard.GetPressedKeys().Count() > 1))
            {
                key = keyboard.GetPressedKeys()[1];
            }

            switch (key)
            {
            case Microsoft.Xna.Framework.Input.Keys.D0:
                return(")");

            case Microsoft.Xna.Framework.Input.Keys.D1:
                return("!");

            case Microsoft.Xna.Framework.Input.Keys.D2:
                return("@");

            case Microsoft.Xna.Framework.Input.Keys.D3:
                return("#");

            case Microsoft.Xna.Framework.Input.Keys.D4:
                return("$");

            case Microsoft.Xna.Framework.Input.Keys.D5:
                return("%");

            case Microsoft.Xna.Framework.Input.Keys.D6:
                return("^");

            case Microsoft.Xna.Framework.Input.Keys.D7:
                return("&");

            case Microsoft.Xna.Framework.Input.Keys.D8:
                return("*");

            case Microsoft.Xna.Framework.Input.Keys.D9:
                return("(");

            case Microsoft.Xna.Framework.Input.Keys.OemPipe:
                return("|");

            case Microsoft.Xna.Framework.Input.Keys.OemCloseBrackets:
                return("}");

            case Microsoft.Xna.Framework.Input.Keys.OemComma:
                return("<");

            case Microsoft.Xna.Framework.Input.Keys.OemMinus:
                return("_");

            case Microsoft.Xna.Framework.Input.Keys.OemOpenBrackets:
                return("{");

            case Microsoft.Xna.Framework.Input.Keys.OemPeriod:
                return(">");

            case Microsoft.Xna.Framework.Input.Keys.OemPlus:
                return("+");

            case Microsoft.Xna.Framework.Input.Keys.OemQuestion:
                return("?");

            case Microsoft.Xna.Framework.Input.Keys.OemQuotes:
                return("\"");

            case Microsoft.Xna.Framework.Input.Keys.OemSemicolon:
                return(":");

            case Microsoft.Xna.Framework.Input.Keys.OemTilde:
                return("~");
            }

            return("");
        }
Ejemplo n.º 8
0
        public void Update(GameTime gameTime)
        {
            if (cursorBlinkTimer.QueryWaitTime(gameTime))
            {
                showCursor = !showCursor;
            }

            cursorRectangle.Y = DrawRectangle.Y + CURSOR_SPACING;

            cursorBlinkTimer.Update(gameTime);

            textPos.X = DrawRectangle.X + TEXT_EDGE_SPACING_X;
            textPos.Y = DrawRectangle.Y + TEXT_EDGE_SPACING_Y;
            if (checkForClickButton != null)
            {
                checkForClickButton.X = this.X;
                checkForClickButton.Y = this.Y;
                checkForClickButton.Update(gameTime);
            }

            if (Active)
            {
                keyboard    = Keyboard.GetState();
                pressedKeys = keyboard.GetPressedKeys();
                key         = Microsoft.Xna.Framework.Input.Keys.None;
                if (pressedKeys.Count() > 0)
                {
                    var keys = pressedKeys.Where(x => x != Microsoft.Xna.Framework.Input.Keys.LeftShift &&
                                                 x != Microsoft.Xna.Framework.Input.Keys.RightShift &&
                                                 x != Microsoft.Xna.Framework.Input.Keys.LeftControl &&
                                                 x != Microsoft.Xna.Framework.Input.Keys.RightControl && !lastKeys.Contains(x)).ToList();
                    if (keys.Count > 0)
                    {
                        key = keys[0];
                    }
                    else if (pressedKeys.Contains(lastKey))
                    {
                        // Only allow key spamming if there is only one character key pressed
                        key = lastKey;
                    }
                }
                keyName = key.ToString();
                if (key != Microsoft.Xna.Framework.Input.Keys.None)
                {
                    // We know at this point that we are typing a key, like Enter or Backspace or a letter, number, or symbol
                    if (!spammingKey)
                    {
                        // We must first check to see if we have been pressing the key before
                        if (lastKeys.Contains(key))
                        {
                            // We have to check the long timer
                            typeTimerLong.Update(gameTime);
                            if (typeTimerLong.QueryWaitTime(gameTime))
                            {
                                spammingKey = true;
                                HandleKey(key);
                            }
                        }
                        else
                        {
                            typeTimerLong.Reset();
                            HandleKey(key);
                        }
                    }
                    else
                    {
                        if (lastKeys.Contains(key))
                        {
                            typeTimerShort.Update(gameTime);
                            if (typeTimerShort.QueryWaitTime(gameTime))
                            {
                                // We are pressing & holding a key and can now "spam" it
                                HandleKey(key);
                            }
                        }
                        else
                        {
                            spammingKey = false;
                        }
                    }
                }
                lastKey = key;

                #region Handle Caret Moving

                if (keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left) && !arrowKeyPrevDown)
                {
                    arrowKeyPrevDown = true;
                    if (cursorPosition > 0)
                    {
                        cursorRectangle.X -= (int)font.MeasureString(text[cursorPosition - 1].ToString()).X + cursorRectangle.Width;
                        cursorPosition--;
                    }
                }
                else if (keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right) && !arrowKeyPrevDown)
                {
                    arrowKeyPrevDown = true;
                    if (cursorPosition < text.Length)
                    {
                        cursorRectangle.X += (int)font.MeasureString(text[cursorPosition].ToString()).X + cursorRectangle.Width;
                        cursorPosition++;
                    }
                }
                else if (!(keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left) || keyboard.IsKeyDown
                               (Microsoft.Xna.Framework.Input.Keys.Right)))
                {
                    arrowKeyPrevDown = false;
                }

                if (keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Home))
                {
                    cursorPosition    = 0;
                    cursorRectangle.X = DrawRectangle.X + TEXT_EDGE_SPACING_X;
                }
                else if (keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.End))
                {
                    cursorPosition    = text.Length;
                    cursorRectangle.X = DrawRectangle.X + ((int)font.MeasureString(text).X + cursorRectangle.Width);
                }

                #endregion

                #region Paste Support

                if ((keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) || keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.RightControl)) &&
                    keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.V) && !shortcutPreviouslyPressed)
                {
                    string clipboardText = Clipboard.GetText();
                    if (!(font.MeasureString(text + clipboardText).X > DrawRectangle.Width))
                    {
                        // The clipboard text is short enough, and will not extend past the textbox's length
                        text += clipboardText;
                    }
                    shortcutPreviouslyPressed = true;
                }
                else if (!((keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) || keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.RightControl)) &&
                           keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.V)))
                {
                    shortcutPreviouslyPressed = false;
                }

                #endregion

                MouseState mouse     = Mouse.GetState();
                Rectangle  mouseRect = new Rectangle(mouse.X, mouse.Y, 1, 1);
                if (!(DrawRectangle.Intersects(mouseRect)) && mouse.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    Active = false;
                }

                lastKeys = pressedKeys;
            }
        }
Ejemplo n.º 9
0
        internal static void UpdateFrame()
        {
            if (GameBase.MenuActive)
            {
                return;
            }

            MouseHandler.UpdateWindowsMouse();

            if (doubleClickTime > 0)
            {
                doubleClickTime = (int)Math.Max(0, doubleClickTime - GameBase.ElapsedMilliseconds);
            }

            //Initialises the current input/processing loop frame.  In the case of 2x replays, up to two frames may be processed in a single game tick.
            int loopFrame = 0;

            if (ConfigManager.sMouseSpeed != 1 && GameBase.Mode != Modes.Edit)
            {
                //Handle mouse velocity setting.

                MouseState newState = Mouse.GetState();

                if (Game.IsActive && newState.X >= 0 && newState.X < GameBase.WindowWidth && newState.Y >= 0 &&
                    newState.Y < GameBase.WindowHeight)
                {
#if newmouse
                    Vector2 newMouseVelocityFloat = new Vector2((float)(mouseVelocityFloat.X + (newState.X - mouseVelocityFloat.X) * ConfigManager.sMouseSpeed),
                                                                (float)(mouseVelocityFloat.Y + (newState.Y - mouseVelocityFloat.Y) * ConfigManager.sMouseSpeed));

                    if (mouseVelocityPoint.X != newState.X || mouseVelocityPoint.Y != newState.Y)
                    {
                        mouseVelocityFloat = newMouseVelocityFloat;
                        mouseVelocityPoint = new Point((int)Math.Round(mouseVelocityFloat.X),
                                                       (int)Math.Round(mouseVelocityFloat.Y));
                        if (GameBase.WindowRectangle.Contains(mouseVelocityPoint))
                        {
                            Mouse.SetPosition(mouseVelocityPoint.X, mouseVelocityPoint.Y);
                        }
                    }
#else
                    Mouse.SetPosition((int)Math.Round(mouse.X + (newState.X - mouse.X) * ConfigManager.sMouseSpeed),
                                      (int)Math.Round(mouse.Y + (newState.Y - mouse.Y) * ConfigManager.sMouseSpeed));
#endif

                    /*MouseHandler.MousePoint.X += (int)((newState.X - mouse.X) * MouseHandler.mouseSpeed);
                     * MouseHandler.MousePoint.Y += (int)((newState.Y - mouse.Y) * MouseHandler.mouseSpeed);
                     *
                     * if (!Player.Playing && !GameBase.graphics.IsFullScreen && ( MouseHandler.MousePoint.X < 0 || MouseHandler.MousePoint.X >= GameBase.WindowWidth || MouseHandler.MousePoint.Y < 0 || MouseHandler.MousePoint.Y >= GameBase.WindowHeight))
                     *  Mouse.SetPosition(MouseHandler.MousePoint.X, MouseHandler.MousePoint.Y);
                     *
                     * mouse = newState;*/


                    mouse = Mouse.GetState();
                    MouseHandler.MousePosition.X = mouse.X;
                    MouseHandler.MousePosition.Y = mouse.Y;
                    MouseHandler.MousePoint.X    = mouse.X;
                    MouseHandler.MousePoint.Y    = mouse.Y;
                }
                else
                {
                    mouse = newState;
                    MouseHandler.MousePosition.X = mouse.X;
                    MouseHandler.MousePosition.Y = mouse.Y;
                    MouseHandler.MousePoint.X    = mouse.X;
                    MouseHandler.MousePoint.Y    = mouse.Y;
                }
            }
            else
            {
                mouse = Mouse.GetState();
                MouseHandler.MousePosition.X = mouse.X;
                MouseHandler.MousePosition.Y = mouse.Y;
                MouseHandler.MousePoint.X    = mouse.X;
                MouseHandler.MousePoint.Y    = mouse.Y;
            }


            if (!Player.Playing || !ConfigManager.sMouseDisableButtons)
            {
                MouseHandler.mouseLeft = mouse.LeftButton;

                if (TabletHandler.pendingTabletUpdate)
                {
                    //Make sure we accept a tablet click even when it is release in under 16ms.
                    MouseHandler.mouseLeft            = ButtonState.Pressed;
                    TabletHandler.pendingTabletUpdate = false;
                }
                else if (TabletHandler.tabletLeft == ButtonState.Pressed)
                {
                    MouseHandler.mouseLeft = TabletHandler.tabletLeft;
                }

                MouseHandler.mouseRight  = mouse.RightButton;
                MouseHandler.mouseMiddle = mouse.MiddleButton;
                MouseHandler.mouseBack   = mouse.XButton1;


                if (Game.IsActive && GameBase.Mode != Modes.Edit && GameBase.Mode != Modes.Menu)
                {
                    if (MouseHandler.mouseBack == ButtonState.Pressed && MouseHandler.mouseBackLast != MouseHandler.mouseBack)
                    {
                        KeyboardHandler.DoKeyPressed(Keys.Escape);
                    }
                    MouseHandler.mouseBackLast = MouseHandler.mouseBack;
                }
            }
            else
            {
                MouseHandler.mouseLeft  = ButtonState.Released;
                MouseHandler.mouseRight = ButtonState.Released;
            }

            bool runningSlow = false;

            do
            {
                AudioEngine.Update();
                lock (StreamingManager.LockReplayScore)
                {
                    if (ReplayMode && ReplayScore != null && ReplayScore.replay != null)
                    {
                        int count = ReplayScore.replay.Count;
                        if (GameBase.Mode == Modes.Play && Player.currentScore != null &&
                            count > 0 &&
                            ReplayFrame < count - 2 &&
                            (ReplayToEnd || !ReplayStreaming ||
                             ReplayScore.replay[count - 1].time - AudioEngine.Time > 1000))
                        {
                            Buffering = false;

/*                            if (ReplayStreaming && !Player.IsFailed && Player.Paused)
 *                              Buffering = false;
 *                          else
 *                          {*/
                            if (ReplayFrame < count - 2 &&
                                (ReplayScore.replay[ReplayFrame + 1].time <= AudioEngine.Time))
                            // && (Math.Abs(ReplayScore.replay[ReplayFrame + 1].time - AudioEngine.Time) < 10 || AudioEngine.Time - ReplayScore.replay[ReplayFrame + 1].time > 0))
                            {
                                ReplayFrame++;
                                ReplayOk = true;
                            }
                            else
                            {
                                ReplayOk = false;
                            }

                            runningSlow = AudioEngine.Time - ReplayScore.replay[ReplayFrame].time > 16 && ReplayOk;

                            //skip unnecessary frames
                            if (runningSlow)
                            {
                                while (ReplayFrame < count - 2 && !ReplayScore.replay[ReplayFrame].mouseLeft &&
                                       !ReplayScore.replay[ReplayFrame].mouseRight &&
                                       ReplayScore.replay[ReplayFrame + 1].time <= AudioEngine.Time &&
                                       ReplayScore.replay[ReplayFrame].mouseLeft == leftButtonLastBool &&
                                       ReplayScore.replay[ReplayFrame].mouseRight == rightButtonLastBool &&
                                       ReplayScore.replay[ReplayFrame].buttonState == lastButtonState &&
                                       !Player.IsSpinning)
                                {
                                    Console.WriteLine("replay frame {0} skipped!!!!", ReplayFrame);
                                    ReplayFrame++;
                                }
                            }

                            Vector2 pos;

                            if (MouseButtonInstantRelease)
                            {
                                leftButton1i  = false;
                                leftButton2i  = false;
                                rightButton1i = false;
                                rightButton2i = false;
                                leftButton    = ButtonState.Released;
                                rightButton   = ButtonState.Released;
                            }

                            if (ReplayOk &&
                                (ReplayScore.replay[ReplayFrame].mouseLeft ||
                                 ReplayScore.replay[ReplayFrame].mouseRight ||
                                 ReplayScore.replay[ReplayFrame].buttonState != lastButtonState ||
                                 Player.IsSpinning))
                            {
                                AudioEngine.Time = ReplayScore.replay[ReplayFrame].time;

                                leftButton1i = (!MouseButtonInstantRelease || !leftButton1) && ReplayScore.replay[ReplayFrame].mouseLeft1;
                                leftButton1  = ReplayScore.replay[ReplayFrame].mouseLeft1;

                                leftButton2i = (!MouseButtonInstantRelease || !leftButton2) && ReplayScore.replay[ReplayFrame].mouseLeft2;
                                leftButton2  = ReplayScore.replay[ReplayFrame].mouseLeft2;

                                rightButton1i = (!MouseButtonInstantRelease || !rightButton1) && ReplayScore.replay[ReplayFrame].mouseRight1;
                                rightButton1  = ReplayScore.replay[ReplayFrame].mouseRight1;

                                rightButton2i = (!MouseButtonInstantRelease || !rightButton2) && ReplayScore.replay[ReplayFrame].mouseRight2;
                                rightButton2  = ReplayScore.replay[ReplayFrame].mouseRight2;

                                leftButton  = leftButton1i || leftButton2i ? ButtonState.Pressed : ButtonState.Released;
                                rightButton = rightButton1i || rightButton2i ? ButtonState.Pressed : ButtonState.Released;

                                pos =
                                    GameBase.GamefieldToDisplay(
                                        new Vector2(ReplayScore.replay[ReplayFrame].mouseX,
                                                    ReplayScore.replay[ReplayFrame].mouseY));
                                // *WindowWidth / ReplayScore.resolution;

                                lastButtonState = ReplayScore.replay[ReplayFrame].buttonState;
                            }
                            else if (ReplayScore.replay[ReplayFrame].time == ReplayScore.replay[ReplayFrame + 1].time)
                            {
                                pos =
                                    GameBase.GamefieldToDisplay(
                                        new Vector2(ReplayScore.replay[ReplayFrame].mouseX,
                                                    ReplayScore.replay[ReplayFrame].mouseY));
                            }
                            else if (ReplayScore.replay[ReplayFrame].time >= AudioEngine.Time)
                            {
                                int p1 = Math.Max(0, ReplayFrame - 1);
                                int p2 = ReplayFrame;

                                pos =
                                    Vector2.Lerp(
                                        GameBase.GamefieldToDisplay(
                                            new Vector2(ReplayScore.replay[p1].mouseX, ReplayScore.replay[p1].mouseY)),
                                        GameBase.GamefieldToDisplay(
                                            new Vector2(ReplayScore.replay[p2].mouseX, ReplayScore.replay[p2].mouseY)),
                                        Math.Max(0,
                                                 (
                                                     1 - (float)(ReplayScore.replay[p2].time - AudioEngine.Time) /
                                                     (ReplayScore.replay[p2].time - ReplayScore.replay[p1].time))));
                                if (!MouseButtonInstantRelease)
                                {
                                    leftButton = ReplayScore.replay[p2].mouseLeft
                                                     ? ButtonState.Pressed
                                                     : ButtonState.Released;
                                    rightButton = ReplayScore.replay[p2].mouseRight
                                                      ? ButtonState.Pressed
                                                      : ButtonState.Released;
                                }
                            }
                            else
                            {
                                int p1 = ReplayFrame;
                                int p2 = Math.Min(count - 1, ReplayFrame + 1);

                                pos =
                                    Vector2.Lerp(
                                        GameBase.GamefieldToDisplay(
                                            new Vector2(ReplayScore.replay[p1].mouseX, ReplayScore.replay[p1].mouseY)),
                                        GameBase.GamefieldToDisplay(
                                            new Vector2(ReplayScore.replay[p2].mouseX, ReplayScore.replay[p2].mouseY)),
                                        Math.Max(0,
                                                 1 - ((float)(ReplayScore.replay[p2].time - AudioEngine.Time) /
                                                      (ReplayScore.replay[p2].time - ReplayScore.replay[p1].time))));
                                if (!MouseButtonInstantRelease)
                                {
                                    leftButton = ReplayScore.replay[p1].mouseLeft
                                                     ? ButtonState.Pressed
                                                     : ButtonState.Released;
                                    rightButton = ReplayScore.replay[p1].mouseRight
                                                      ? ButtonState.Pressed
                                                      : ButtonState.Released;
                                }
                            }

                            CursorPosition = pos;
                            CursorPoint    = new Point((int)CursorPosition.X, (int)CursorPosition.Y);

                            Player.Playing = false;
                        }
                        else if (ReplayStreaming)
                        {
                            Player.Playing = false;

                            if (ReplayToEnd)
                            {
                                if (Player.Paused && !Player.Failed)
                                {
                                    Buffering = false;
                                }

                                if (Player.ReplayBufferText != null && Player.Failed)
                                {
                                    Player.ReplayBufferText.Text = "User Failed";
                                }
                            }
                            else

                            /*if (HitObjectManager.hitObjects != null &&
                             * AudioEngine.Time >= HitObjectManager.hitObjects[0].StartTime - HitObjectManager.PreEmpt)*/
                            {
                                Buffering = true;

                                float percent;

                                if (count == 0)
                                {
                                    percent = 0;
                                }
                                else
                                {
                                    percent =
                                        MathHelper.Clamp(
                                            (float)(ReplayScore.replay[count - 1].time - AudioEngine.Time) / 10, 0, 100);
                                }

                                if (Player.ReplayBufferText != null)
                                {
                                    if (Player.Failed)
                                    {
                                        Player.ReplayBufferText.Text = "Failed";
                                    }
                                    else
                                    {
                                        Player.ReplayBufferText.Text =
                                            string.Format("Buffering {0:0.0}%...", percent);
                                    }
                                }
                            }
                        }
                    }
                }
                if (!ReplayMode)
                {
                    //todo: move this to the outer loop?
                    Player.Playing = GameBase.Mode == Modes.Play &&
                                     AudioEngine.Time >= Player.skipBoundary &&
                                     !Player.Failed && !Player.Paused && !EventManager.BreakMode &&
                                     Game.IsActive && !Player.currentScore.pass;

                    if (Player.Playing && !GameBase.graphics.IsFullScreen)
                    {
                        if (Cursor.Clip == cursorOriginalBounds)
                        {
                            Cursor.Clip = GameBase.Form.RectangleToScreen(GameBase.Form.ClientRectangle);
                        }
                    }
                    else if (Cursor.Clip != cursorOriginalBounds)
                    {
                        Cursor.Clip = cursorOriginalBounds;
                    }

                    CursorPosition = MouseHandler.MousePosition;
                    CursorPoint    = MouseHandler.MousePoint;
                    leftButton     = MouseHandler.mouseLeft;
                    leftButton1i   = leftButton == ButtonState.Pressed && !leftButtonLastBool;
                    leftButton1    = leftButton == ButtonState.Pressed;
                    leftButton2i   = leftButton == ButtonState.Pressed && !leftButtonLastBool;
                    leftButton2    = leftButton == ButtonState.Pressed;

                    rightButton   = MouseHandler.mouseRight;
                    rightButton1i = rightButton == ButtonState.Pressed && !rightButtonLastBool;
                    rightButton1  = rightButton == ButtonState.Pressed;
                    rightButton2i = rightButton == ButtonState.Pressed && !rightButtonLastBool;
                    rightButton2  = rightButton == ButtonState.Pressed;
                }

                //Update mouse cursor position, except in editor mode where we use the windows cursor.
                if (!GameBase.MenuVisible)
                {
                    if (spriteCursor.IsVisible && GameBase.SixtyFramesPerSecondFrame)
                    {
                        pSprite trail =
                            new pSprite(SkinManager.Load("cursortrail"), FieldTypes.WindowScaleOnly,
                                        (SkinManager.Current.CursorCentre ? OriginTypes.Centre : OriginTypes.TopLeft),
                                        ClockTypes.Game, CursorPosition, spriteCursor.Depth - 0.001F,
                                        false,
                                        Color.White);
                        trail.FadeOut(150);
                        trail.CurrentScale = spriteCursor.CurrentScale;
                        if (SkinManager.Current.CursorTrailRotate)
                        {
                            trail.CurrentRotation = spriteCursor.CurrentRotation;
                        }
                        GameBase.spriteManagerOverlay.Add(trail);
                    }

                    spriteCursor.CurrentPosition = CursorPosition;
                }

                //Only do actions on the input if the window is active.
                if (Game.IsActive || ReplayMode)
                {
                    //Mouse wheel
                    MouseHandler.MouseWheelHandled = false;
                    if (mouse.ScrollWheelValue != scrollWheel)
                    {
                        /*if (ChatEngine.IsVisible)
                         * {
                         *  if (mouse.ScrollWheelValue > scrollWheel)
                         *      ChatEngine.MouseHandler_OnMouseWheelUp(null, null);
                         *  else
                         *      ChatEngine.MouseHandler_OnMouseWheelDown(null, null);
                         * }
                         * else
                         * {*/
                        if (mouse.ScrollWheelValue > scrollWheel)
                        {
                            MouseHandler.DoMouseWheelUp();
                        }
                        else
                        {
                            MouseHandler.DoMouseWheelDown();
                        }
                        /*}*/
                        scrollWheel = mouse.ScrollWheelValue;
                    }

                    try
                    {
                        keyboard = Keyboard.GetState();
                    }
                    catch (InvalidOperationException)
                    {
                    }

                    if (!ReplayMode)
                    {
                        MouseViaKeyboardControls();
                    }


                    Keys[] newKeys = (Keys[])keyboard.GetPressedKeys().Clone();

                    if (pressedKeys != null && !keyboard.IsKeyDown(Keys.Scroll))
                    {
                        KeyboardHandler.ControlPressed = (keyboard.IsKeyDown(Keys.LeftControl) ||
                                                          keyboard.IsKeyDown(Keys.RightControl));
                        KeyboardHandler.AltPressed = (keyboard.IsKeyDown(Keys.LeftAlt) ||
                                                      keyboard.IsKeyDown(Keys.RightAlt));
                        KeyboardHandler.ShiftPressed = (keyboard.IsKeyDown(Keys.LeftShift) ||
                                                        keyboard.IsKeyDown(Keys.RightShift));

                        for (int i = 0; i < newKeys.Length; i++)
                        {
                            Keys k      = newKeys[i];
                            bool bFound = false;


                            for (int j = 0; j < pressedKeys.Length; j++)
                            {
                                if (k == pressedKeys[j])
                                {
                                    bFound = true;
                                    break;
                                }
                            }

                            if (!bFound && GameBase.FadeState != FadeStates.FadeOut)
                            {
                                repeatTickCurrent = -100;
                                BanchoClient.Activity();
                                GameBase.KeyboardHandler_OnKeyPressed(null, k);
                                if (ChatEngine.IsVisible)
                                {
                                    string ks = k.ToString();
                                    if (ks.Length == 2 && ks[0] == 'F' && ks[1] >= '0' && ks[1] <= '9')
                                    {
                                        KeyboardHandler.DoKeyPressed(k);
                                    }
                                    else
                                    {
                                        ChatEngine.GameBase_OnKeyRepeat(null, k, true);
                                    }
                                }
                                else if (GameBase.ActiveDialog != null)
                                {
                                    GameBase.ActiveDialog.HandleKey(k);
                                }
                                else if (!thisBlockKey)
                                {
                                    KeyboardHandler.DoKeyPressed(k);
                                }
                            }
                        }
                    }

                    pressedKeys = newKeys;

                    repeatTickCurrent += GameBase.ElapsedMilliseconds;

                    if (repeatTickCurrent >= repeatTickRate)
                    {
                        repeatTickCurrent -= repeatTickRate;

                        if (pressedKeys != null && !keyboard.IsKeyDown(Keys.Scroll))
                        {
                            foreach (Keys k in newKeys)
                            {
                                bool bFound = false;

                                foreach (Keys k2 in pressedKeys)
                                {
                                    if (k == k2)
                                    {
                                        bFound = true;
                                        break;
                                    }
                                }

                                if (ChatEngine.IsVisible)
                                {
                                    ChatEngine.GameBase_OnKeyRepeat(null, k, false);
                                }
                                else if (GameBase.ActiveDialog == null && bFound && GameBase.FadeState == FadeStates.Idle &&
                                         !thisBlockKey)
                                {
                                    KeyboardHandler.DoOnKeyRepeat(k);
                                }
                            }
                        }
                        if (leftButton == ButtonState.Pressed &&
                            MouseHandler.MouseDown && GameBase.FadeState != FadeStates.FadeOut)
                        {
                            MouseHandler.DoOnClickRepeat();
                        }
                    }

                    MouseHandler.actualClickRegistered = (MouseHandler.mouseLeft == ButtonState.Pressed &&
                                                          mouseLeftActualPrev != ButtonState.Pressed) || (MouseHandler.mouseRight == ButtonState.Pressed &&
                                                                                                          mouseRightActualPrev != ButtonState.Pressed);

                    if (leftButtonLast != leftButton || rightButtonLast != rightButton)
                    {
                        MouseHandler.LastButton2 = MouseHandler.LastButton;
                        MouseHandler.LastButton  = MouseHandler.MouseDownButton;

                        MouseHandler.MouseDownButton = MouseButtons.None;
                        if (leftButton == ButtonState.Pressed)
                        {
                            MouseHandler.MouseDownButton |= MouseButtons.Left;
                        }
                        if (rightButton == ButtonState.Pressed)
                        {
                            MouseHandler.MouseDownButton |= MouseButtons.Right;
                        }
                    }

                    //We don't have a replay click, so lets check for physical mouse clicks.
                    //In the case that there is a replay and actual click the same frame, doOnClick will be called only once (above).
                    if (MouseHandler.actualClickRegistered && ReplayMode && GameBase.FadeState != FadeStates.FadeOut)
                    {
                        bool old = MouseHandler.gamePressedRegistered;
                        MouseHandler.gamePressedRegistered = false;
                        MouseHandler.DoOnClick();
                        MouseHandler.gamePressedRegistered = old;
                    }

                    leftCond   = leftButton == ButtonState.Pressed && leftButtonLast != leftButton;
                    rightCond  = rightButton == ButtonState.Pressed && rightButtonLast != rightButton;
                    middleCond = MouseHandler.mouseMiddle == ButtonState.Pressed &&
                                 mouseMiddlePrev != MouseHandler.mouseMiddle;

                    MouseHandler.gameClickRegistered = false;

                    if (leftCond || rightCond || middleCond)
                    {
                        if (!middleCond)
                        {
                            if (SkinManager.Current.CursorExpand)
                            {
                                spriteCursor.Transformations.RemoveAll(
                                    delegate(Transformation tr) { return(tr.Type != TransformationType.Rotation); });
                                Transformation t =
                                    new Transformation(TransformationType.Scale, 1, 1.3F, GameBase.Time,
                                                       GameBase.Time + 100);
                                t.Easing = EasingTypes.In;
                                spriteCursor.Transformations.Add(t);
                            }
                            MouseHandler.clickPosition = new Vector2(mouse.X, mouse.Y);

                            MouseHandler.gamePressedRegistered = true;
                            MouseHandler.gameClickRegistered   = true;

                            if (doubleClickTime > 0 && GameBase.FadeState != FadeStates.FadeOut)
                            {
                                MouseHandler.DoOnDoubleClick();
                            }
                        }

                        if (GameBase.FadeState != FadeStates.FadeOut)
                        {
                            MouseHandler.DoOnClick();
                            repeatTickCurrent = 0;
                            doubleClickTime   = 250;
                        }
                    }
                    else if (leftButton == ButtonState.Released &&
                             rightButton == ButtonState.Released &&
                             MouseHandler.gamePressedRegistered)
                    {
                        if (SkinManager.Current.CursorExpand)
                        {
                            spriteCursor.Transformations.RemoveAll(
                                delegate(Transformation tr) { return(tr.Type != TransformationType.Rotation); });
                            Transformation t =
                                new Transformation(TransformationType.Scale, spriteCursor.CurrentScale, 1, GameBase.Time,
                                                   GameBase.Time + 100);
                            t.Easing = EasingTypes.In;
                            spriteCursor.Transformations.Add(t);
                        }
                        MouseHandler.gamePressedRegistered = false;
                        MouseHandler.DoOnClickUp();
                    }

                    if (MouseHandler.mouseLeft == ButtonState.Pressed &&
                        GameBase.FadeState != FadeStates.FadeOut)
                    {
                        MouseHandler.MouseDown = true;
                        if (mouse.X != MouseHandler.clickPosition.X ||
                            mouse.Y != MouseHandler.clickPosition.Y)
                        {
                            MouseHandler.DoOnDrag();
                        }
                    }
                    else
                    {
                        MouseHandler.MouseDown = false;
                        if (IsDragging)
                        {
                            MouseHandler.DoOnEndDrag();
                        }
                    }
                }
                else
                {
                    leftButton  = ButtonState.Released;
                    rightButton = ButtonState.Released;
                }


                GameBase.Instance.UpdateChildren();

                leftButtonLast  = leftButton;
                rightButtonLast = rightButton;

                leftButtonLastBool  = leftButton == ButtonState.Pressed;
                rightButtonLastBool = rightButton == ButtonState.Pressed;

                mouseLeftActualPrev  = MouseHandler.mouseLeft;
                mouseRightActualPrev = MouseHandler.mouseRight;
                mouseMiddlePrev      = MouseHandler.mouseMiddle;

                keyboardLast = keyboard;

                thisBlockKey = false;
            } while (ReplayMode && ((ReplayModeFF && loopFrame++ < 1) || (runningSlow && loopFrame++ < 4)));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Key to char helper conversion method.
        /// Note: If the keys are mapped other than on a default QWERTY
        /// keyboard, this method will not work properly. Most keyboards
        /// will return the same for A-Z and 0-9, but the special keys
        /// might be different.
        /// </summary>
        internal static char KeyToChar(Keys key, bool shiftPressed)
        {
            // TODO: Use another way to get input to allow multi-language keyboards.

            // If key will not be found, just return space
            char ret    = ' ';
            int  keyNum = (int)key;

            if (keyNum >= (int)Keys.A && keyNum <= (int)Keys.Z)
            {
                if (shiftPressed)
                {
                    ret = key.ToString()[0];
                }
                else
                {
                    ret = key.ToString().ToLower()[0];
                }
            }
            else if (keyNum >= (int)Keys.D0 && keyNum <= (int)Keys.D9 &&
                     shiftPressed == false)
            {
                ret = (char)((int)'0' + (keyNum - Keys.D0));
            }
            else if (key == Keys.D1 && shiftPressed)
            {
                ret = '!';
            }
            else if (key == Keys.D2 && shiftPressed)
            {
                ret = '@';
            }
            else if (key == Keys.D3 && shiftPressed)
            {
                ret = '#';
            }
            else if (key == Keys.D4 && shiftPressed)
            {
                ret = '$';
            }
            else if (key == Keys.D5 && shiftPressed)
            {
                ret = '%';
            }
            else if (key == Keys.D6 && shiftPressed)
            {
                ret = '^';
            }
            else if (key == Keys.D7 && shiftPressed)
            {
                ret = '&';
            }
            else if (key == Keys.D8 && shiftPressed)
            {
                ret = '*';
            }
            else if (key == Keys.D9 && shiftPressed)
            {
                ret = '(';
            }
            else if (key == Keys.D0 && shiftPressed)
            {
                ret = ')';
            }
            else if (key == Keys.OemTilde)
            {
                ret = shiftPressed ? '~' : '`';
            }
            else if (key == Keys.OemMinus)
            {
                ret = shiftPressed ? '_' : '-';
            }
            else if (key == Keys.OemPipe)
            {
                ret = shiftPressed ? '|' : '\\';
            }
            else if (key == Keys.OemOpenBrackets)
            {
                ret = shiftPressed ? '{' : '[';
            }
            else if (key == Keys.OemCloseBrackets)
            {
                ret = shiftPressed ? '}' : ']';
            }
            else if (key == Keys.OemSemicolon)
            {
                ret = shiftPressed ? ':' : ';';
            }
            else if (key == Keys.OemQuotes)
            {
                ret = shiftPressed ? '"' : '\'';
            }
            else if (key == Keys.OemComma)
            {
                ret = shiftPressed ? '<' : ',';
            }
            else if (key == Keys.OemPeriod)
            {
                ret = shiftPressed ? '>' : '.';
            }
            else if (key == Keys.OemQuestion)
            {
                ret = shiftPressed ? '?' : '/';
            }
            else if (key == Keys.OemPlus)
            {
                ret = shiftPressed ? '+' : '=';
            }

            // Return result
            return(ret);
        }
Ejemplo n.º 11
0
 public override void OnKeyDown(Microsoft.Xna.Framework.Input.Keys key)
 {
     // HACK Write keydowns to debug box for debug purposes. Change key handling for proper release.
     System.Diagnostics.Debug.WriteLine(key.ToString());
 }