internal static void DoOnClick() { if (PhysicalClickRegistered) { SpriteManager.ClickHandledSprite = null; BanchoClient.Activity(); } SpriteManager.HandleClick(false); InputManager.TriggerEvent(InputEventType.OnClick); }
internal static void DoOnClick() { BanchoClient.Activity(); SpriteManager.ClickHandled = false; if (OnClick != null) { OnClick(null, null); } if (OnClickRepeat != null) { OnClickRepeat(null, null); } }
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))); }