//public void Update() { //if (Main.Ins.GameBattleEx != null && Main.Ins.GameBattleEx.BattleFinished()) // return; //if (CombatData.Ins.Replay && FrameReplay.Instance.Started) { //} else { // if (Main.Ins.LocalPlayer != null) { // if (Main.Ins.LocalPlayer.meteorController.InputLocked) // return; // } // getButtons(); //} //getAxis(); //} public void ProcessKey(KeyState keyState) { Pressed.Clear(); Released.Clear(); Pressing.Clear(); if (keyMapping.ContainsKey(keyState.Key)) { JoyKeyState js = keyMapping[keyState.Key]; bool old = js.PointDown; js.PointDown = Input.GetKey(js.key); if (old && !js.PointDown) { Released.Add(js); } if (!old && js.PointDown) { Pressed.Add(js); } if (old && js.PointDown) { Pressing.Add(js); } //先按下 for (int i = 0; i < Pressed.Count; i++) { if (Pressed[i].OnPress != null) { Pressed[i].OnPress.Invoke(); } } //再蓄力 for (int i = 0; i < Pressing.Count; i++) { if (Pressing[i].OnPressing != null) { Pressing[i].OnPressing.Invoke(); } } //再弹起 for (int i = 0; i < Released.Count; i++) { if (Released[i].OnRelease != null) { Released[i].OnRelease.Invoke(); } } } }
// update // - check for mouse hovering and click (select) public void Update(GameTime gameTime, KeyboardState keyboardState, Camera camera, GameState state) { // update tile? IsGlowing = false; IsPreviewingRoad = false; #region MOUSE INTERACTION LOGIC var currentMouse = Mouse.GetState(); // convert mouse screen position to world position var m_screenPosition = new Vector2(currentMouse.X, currentMouse.Y); var m_worldPosition = Vector2.Zero; camera.ToWorld(ref m_screenPosition, out m_worldPosition); // apply offset (why the f**k this is needed I absolutely do not know but I randomly f*****g figured out this formula and somehow it works so for the love of f**k - do not change this until a superior solution is TESTED and delivered m_worldPosition.X -= camera.Width / 2f; m_worldPosition.Y -= camera.Height / 2f; //m_worldPosition.X += (GraphicsDevice_.Viewport.Width * 0.25f); //m_worldPosition.Y += (GraphicsDevice_.Viewport.Height * 0.25f); // get bounds for mouse world position var mouseRectangle = new Rectangle((int)m_worldPosition.X, (int)m_worldPosition.Y, 1, 1); // check if mouse bounds intersects with tile touchbox bounds if (mouseRectangle.Intersects(TouchHitbox) && IsVisible.Equals(true)) { state.CurrentlyHoveredTile = this; //Console.WriteLine($"Hover:: Mp=>{currentMouse.Position.ToString()} :: Mwp=>{m_worldPosition.ToString()} :: Tp=>{Position.ToString()}"); //Console.WriteLine($"Hovering Over Tile: {TileIndex.ToString()}"); switch (currentMouse.LeftButton) { case ButtonState.Pressed when _previousMouseState.LeftButton == ButtonState.Pressed: if (!(state.CurrentlyPressedTile.TileIndex.Equals(TileIndex))) { Pressing?.Invoke(this, new EventArgs()); } break; case ButtonState.Pressed when _previousMouseState.LeftButton == ButtonState.Released: Pressed?.Invoke(this, new EventArgs()); break; case ButtonState.Released when _previousMouseState.LeftButton == ButtonState.Pressed: Click?.Invoke(this, new EventArgs()); break; } if (currentMouse.RightButton == ButtonState.Released && _previousMouseState.RightButton == ButtonState.Pressed) { //camera.Position = Position + new Vector2(0, 150); RightClick?.Invoke(this, new EventArgs()); } } #endregion if (Object is Residence r) { //Console.Out.WriteLine("Listing residents for tile: {0}", TileIndex.ToString()); foreach (var res in r.Residents) { //Console.Out.WriteLine("res.Name = {0}", res.Name); } } if (HasAnimatedTexture == false) { CheckForAnimatedTexture(); } // save mouse state as previous mousestate for next update call _previousMouseState = currentMouse; _gameState = state; }