public void Update() { //Clear button release events leftMouseReleased = false; rightMouseReleased = false; spawnTreeButtonReleased = false; spawnRockButtonReleased = false; escapeButtonReleased = false; if (leftMouseDragEnd) { leftMouseDragEnd = false; mouseTileStartDrag.X = 0; mouseTileStartDrag.Y = 0; mouseTileEndDrag.X = 0; mouseTileEndDrag.Y = 0; } if (!mouseLostFocus) { //Check mouse down conditions if (Mouse.GetState().LeftButton == ButtonState.Pressed) { //Start Drag if (this.MouseOverMap()) { Vector2 currentMouseTile = associatedMap.getTileFromMousePosition(Mouse.GetState().X, Mouse.GetState().Y, GlobalVariables.TILE_SIZE, 0, 0, associatedUIManager.GetGameWindowWidth(), associatedUIManager.GetGameWindowHeight()); if (!leftMousePressed) { mouseTileStartDrag = currentMouseTile; } if (mouseTileStartDrag.X != currentMouseTile.X || mouseTileStartDrag.Y != currentMouseTile.Y) { leftMouseDragStart = true; } if (mouseTileStartDrag.X == currentMouseTile.X && mouseTileStartDrag.Y == currentMouseTile.Y) { leftMouseDragStart = false; } } else { mouseLostFocus = false; leftMouseDragStart = false; leftMouseDragEnd = false; mouseTileStartDrag.X = 0; mouseTileStartDrag.Y = 0; mouseTileEndDrag.X = 0; mouseTileEndDrag.Y = 0; leftMousePressed = false; leftMouseReleased = false; rightMousePressed = false; rightMouseReleased = false; } //Basic click leftMousePressed = true; } if (Mouse.GetState().RightButton == ButtonState.Pressed) { rightMousePressed = true; } //Check for button down events if (Keyboard.GetState().IsKeyDown(Keys.T)) { spawnTreeButtonPressed = true; } if (Keyboard.GetState().IsKeyDown(Keys.R)) { spawnRockButtonPressed = true; } if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { escapeButtonPressed = true; } //Check for button release events if (Mouse.GetState().LeftButton == ButtonState.Released && leftMousePressed) { leftMousePressed = false; leftMouseReleased = true; if (leftMouseDragStart && this.MouseOverMap()) { mouseTileEndDrag = associatedMap.getTileFromMousePosition(Mouse.GetState().X, Mouse.GetState().Y, GlobalVariables.TILE_SIZE, 0, 0, associatedUIManager.GetGameWindowWidth(), associatedUIManager.GetGameWindowHeight()); if (mouseTileStartDrag.X != mouseTileEndDrag.X || mouseTileStartDrag.Y != mouseTileEndDrag.Y) { leftMouseDragEnd = true; } leftMouseDragStart = false; } else { //clear out drag data leftMouseDragStart = false; leftMouseDragEnd = false; mouseTileStartDrag.X = 0; mouseTileStartDrag.Y = 0; mouseTileEndDrag.X = 0; mouseTileEndDrag.Y = 0; } } if (Mouse.GetState().RightButton == ButtonState.Released && rightMousePressed) { rightMousePressed = false; rightMouseReleased = true; } if (Keyboard.GetState().IsKeyUp(Keys.T) && spawnTreeButtonPressed) { spawnTreeButtonPressed = false; spawnTreeButtonReleased = true; } if (Keyboard.GetState().IsKeyUp(Keys.R) && spawnRockButtonPressed) { spawnRockButtonPressed = false; spawnRockButtonReleased = true; } if (Keyboard.GetState().IsKeyUp(Keys.Escape) && escapeButtonPressed) { escapeButtonPressed = false; escapeButtonReleased = true; } } else { if (Mouse.GetState().LeftButton == ButtonState.Released) { mouseLostFocus = false; } } }
public Vector2 GetCurrentMouseTile(mapManager mapIn) { MouseState mouseState = Mouse.GetState(); return(mapIn.getTileFromMousePosition(mouseState.X, mouseState.Y, GlobalVariables.TILE_SIZE, 0, 0, associatedUIManager.GetGameWindowWidth(), associatedUIManager.GetGameWindowHeight())); }