public void InitializeLayout(int ResizeIteration) { if (ResizeIteration > 1) { this.SlotSize = Math.Min(OriginalSlotSize, Math.Max(24, OriginalSlotSize - (ResizeIteration - 1) * 8)); } HoveredSlot = null; SecondaryActionButtonPressedTime = null; SecondaryActionButtonPressedLocation = null; int ColumnHeaderHeight = SlotSize; int GroupWidth = ColumnsPerGroup * SlotSize; int RequiredWidth = GroupsPerRow * ColumnsPerGroup * SlotSize + Padding * 2 + (GroupsPerRow - 1) * HorizontalMarginBetweenGroups; int RequiredHeight = RowCount * SlotSize + Padding * 2 + ColumnHeaderHeight; this.RelativeBounds = new Rectangle(0, 0, RequiredWidth, RequiredHeight); // Create the cells within each row/column OrderedDictionary <int, Dictionary <ColumnType, Rectangle> > SlotBounds = new OrderedDictionary <int, Dictionary <ColumnType, Rectangle> >(); for (int i = 0; i < GroupedObjects.Count; i++) { AllowedObject Group = GroupedObjects[i]; int Row = i / GroupsPerRow; int Column = i - Row * GroupsPerRow; int GroupStartX = Column * GroupWidth + Padding + (i % GroupsPerRow) * HorizontalMarginBetweenGroups; Dictionary <ColumnType, Rectangle> GroupSlots = new Dictionary <ColumnType, Rectangle>(); for (int j = 0; j < ColumnsPerGroup; j++) { ColumnType ColumnType = (ColumnType)j; int X = GroupStartX + j * SlotSize; Rectangle Slot = new Rectangle(X, Row * SlotSize + Padding + ColumnHeaderHeight, SlotSize, SlotSize); GroupSlots.Add(ColumnType, Slot); } SlotBounds.Add(Group.Id, GroupSlots); } RelativeSlotBounds = SlotBounds; // Create column headers List <Rectangle> ColumnHeaderBounds = new List <Rectangle>(); for (int i = 0; i < GroupsPerRow; i++) { int GroupStartX = i * GroupWidth + Padding + i * HorizontalMarginBetweenGroups; for (int j = 0; j < ColumnsPerGroup; j++) { ColumnHeaderBounds.Add(new Rectangle(GroupStartX + j * SlotSize, Padding, ColumnHeaderHeight, ColumnHeaderHeight)); } } RelativeColumnHeaderBounds = new ReadOnlyCollection <Rectangle>(ColumnHeaderBounds); }
public override void HandleInput(InputState input) { mousePoint = new Point((int)(input.CurrentMouseStates[(int)PlayerIndex.One].X), (int)(input.CurrentMouseStates[(int)PlayerIndex.One].Y)); if (zoomScale > 1.0f || zoomScale < 1.0f) { #region Move Zoomed Screen if (input.CurrentMouseStates[(int)PlayerIndex.One].LeftButton == ButtonState.Pressed) { if (input.CurrentMouseStates[(int)PlayerIndex.One].X != input.PreviousMouseStates[(int)PlayerIndex.One].X) { cameraPosition -= new Vector2(input.CurrentMouseStates[(int)PlayerIndex.One].X - input.PreviousMouseStates[(int)PlayerIndex.One].X, input.CurrentMouseStates[(int)PlayerIndex.One].Y - input.PreviousMouseStates[(int)PlayerIndex.One].Y); } } #endregion } else { #region Pause KeyboardState keyboardState = input.CurrentKeyboardStates[(int)PlayerIndex.One]; GamePadState gamePadState = input.CurrentGamePadStates[(int)PlayerIndex.One]; bool playerOneGamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[(int)PlayerIndex.One]; //...if so then pause and wait if (input.IsPauseGame(PlayerIndex.One) || playerOneGamePadDisconnected) { if (LevelName != null) { ScreenManager.AddScreen(new PauseMenuScreen(Tiles, Backgrounds, LevelName, scrollOffset), PlayerIndex.One); } else { ScreenManager.AddScreen(new PauseMenuScreen(Tiles, Backgrounds, String.Empty, scrollOffset), PlayerIndex.One); } } #endregion #region GetTiles //add references here if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.LeftShift) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.LeftShift)) { ScreenManager.AddScreen(new ObjectSelection(tileReferenceBlocks, tileReferenceSceneries, tileReferenceSlopes, tileSelectionBox, fileReferences, SpriteBatch), PlayerIndex.One); } #endregion #region GetBackgrounds if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.RightShift) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.RightShift)) { //do this for background creation ScreenManager.AddScreen(new ObjectSelectionBackgrounds(normalBackgroundReferences, otherBackgroundReferences, backgroundFileReferences, tileSelectionBox, SpriteBatch), PlayerIndex.One); } #endregion #region SelectAllowedObject if (!tileSelected && !backgroundSelected) { if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.D1) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.D1)) { allowedObject = AllowedObject.Tile; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.D2) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.D2)) { allowedObject = AllowedObject.Background; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.D3) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.D3)) { allowedObject = AllowedObject.Scenery; } if (input.CurrentMouseStates[(int)PlayerIndex.One].ScrollWheelValue > input.PreviousMouseStates[(int)PlayerIndex.One].ScrollWheelValue) { allowedObject--; if (allowedObject < 0) allowedObject = AllowedObject.Scenery; } if (input.CurrentMouseStates[(int)PlayerIndex.One].ScrollWheelValue < input.PreviousMouseStates[(int)PlayerIndex.One].ScrollWheelValue) { allowedObject++; if (allowedObject > AllowedObject.Scenery) allowedObject = 0; } if (allowedObject == AllowedObject.Tile) { numberOneColor = Color.Red; numberTwoColor = Color.White; numberThreeColor = Color.White; } else if (allowedObject == AllowedObject.Background) { numberOneColor = Color.White; numberTwoColor = Color.Red; numberThreeColor = Color.White; } else if (allowedObject == AllowedObject.Scenery) { numberOneColor = Color.White; numberTwoColor = Color.White; numberThreeColor = Color.Red; } } #endregion if (!toggleCameraMove) { #region SelectObjects Mouse if (input.CurrentMouseStates[(int)PlayerIndex.One].LeftButton == ButtonState.Pressed && input.PreviousMouseStates[(int)PlayerIndex.One].LeftButton == ButtonState.Released || input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.Space) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.Space)) { if (allowedObject == AllowedObject.Tile || allowedObject == AllowedObject.Scenery) { if (!tileSelected) { for (int i = Tiles.Count - 1; i >= 0; i--) { if (Tiles[i].type == TileType.Scenery && allowedObject == AllowedObject.Scenery) { if (Tiles[i].objectNumber == 15 || Tiles[i].objectNumber == 16) { tileRectangles[i] = new Rectangle((int)(Tiles[i].position.X + scrollOffset.X), (int)(Tiles[i].position.Y + scrollOffset.Y), 10, 10); } else { tileRectangles[i] = new Rectangle((int)(Tiles[i].position.X + scrollOffset.X), (int)(Tiles[i].position.Y + scrollOffset.Y), Tiles[i].sprite.Width, Tiles[i].sprite.Height); } if (tileRectangles[i].Contains(mousePoint)) { tileSelected = true; tileNumber = i; break; } } if (Tiles[i].type != TileType.Scenery && allowedObject == AllowedObject.Tile) { tileRectangles[i] = new Rectangle((int)(Tiles[i].position.X + scrollOffset.X), (int)(Tiles[i].position.Y + scrollOffset.Y), Tiles[i].sprite.Width, Tiles[i].sprite.Height); if (tileRectangles[i].Contains(mousePoint)) { tileSelected = true; tileNumber = i; break; } } } } else { tileSelected = false; tileRectangles[tileNumber] = new Rectangle((int)(Tiles[tileNumber].position.X + scrollOffset.X), (int)(Tiles[tileNumber].position.Y + scrollOffset.Y), Tiles[tileNumber].sprite.Width, Tiles[tileNumber].sprite.Height); return; } } if (allowedObject == AllowedObject.Background) { if (!backgroundSelected) { for (int i = Backgrounds.Count - 1; i >= 0; i--) { backgroundRectangles[i] = new Rectangle((int)(Backgrounds[i].position.X + scrollOffset.X), (int)(Backgrounds[i].position.Y + scrollOffset.Y), Backgrounds[i].sprite.Width, Backgrounds[i].sprite.Height); if (backgroundRectangles[i].Contains(mousePoint)) { backgroundSelected = true; tileNumber = i; break; } } } else { backgroundSelected = false; backgroundRectangles[tileNumber] = new Rectangle((int)(Backgrounds[tileNumber].position.X + scrollOffset.X), (int)(Backgrounds[tileNumber].position.Y + scrollOffset.Y), Backgrounds[tileNumber].sprite.Width, Backgrounds[tileNumber].sprite.Height); return; } } } #endregion } else { #region MoveCamera if (input.CurrentMouseStates[(int)PlayerIndex.One].LeftButton == ButtonState.Pressed) { if (input.CurrentMouseStates[(int)PlayerIndex.One].X != input.PreviousMouseStates[(int)PlayerIndex.One].X) { cameraPosition -= new Vector2(input.CurrentMouseStates[(int)PlayerIndex.One].X - input.PreviousMouseStates[(int)PlayerIndex.One].X, input.CurrentMouseStates[(int)PlayerIndex.One].Y - input.PreviousMouseStates[(int)PlayerIndex.One].Y); } } #endregion } #region Move Tile if (tileSelected) { if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.A) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.A)) { Tiles[tileNumber].position.X -= 1; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.D) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.D)) { Tiles[tileNumber].position.X += 1; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.W) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.W)) { Tiles[tileNumber].position.Y -= 1; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.S) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.S)) { Tiles[tileNumber].position.Y += 1; } Tiles[tileNumber].position += new Vector2(input.CurrentMouseStates[(int)PlayerIndex.One].X - input.PreviousMouseStates[(int)PlayerIndex.One].X, input.CurrentMouseStates[(int)PlayerIndex.One].Y - input.PreviousMouseStates[(int)PlayerIndex.One].Y); } #endregion #region MoveBackground if (backgroundSelected) { if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.A) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.A)) { Backgrounds[tileNumber].position.X -= 1; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.D) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.D)) { Backgrounds[tileNumber].position.X += 1; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.W) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.W)) { Backgrounds[tileNumber].position.Y -= 1; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.S) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.S)) { Backgrounds[tileNumber].position.Y += 1; } Backgrounds[tileNumber].position += new Vector2(input.CurrentMouseStates[(int)PlayerIndex.One].X - input.PreviousMouseStates[(int)PlayerIndex.One].X, input.CurrentMouseStates[(int)PlayerIndex.One].Y - input.PreviousMouseStates[(int)PlayerIndex.One].Y); } #endregion #region CopyTile if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.C) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.C)) { if (tileSelected) { tileSelected = false; LoadTile(Tiles[tileNumber].type, Tiles[tileNumber].objectNumber, Tiles[tileNumber].layerNumber); } if (backgroundSelected) { backgroundSelected = false; LoadBackground(Backgrounds[tileNumber].type, Backgrounds[tileNumber].objectNumber, Backgrounds[tileNumber].layerNumber); } } #endregion #region DeleteTile if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.Delete) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.Delete)) { if (tileSelected) { tileSelected = false; Tiles.RemoveAt(tileNumber); } if (backgroundSelected) { backgroundSelected = false; Backgrounds.RemoveAt(tileNumber); } } #endregion } #region Zoom Screen if (!tileSelected && !backgroundSelected) { if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.OemPlus) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.OemPlus)) { zoomScale += 0.1f; if (zoomScale > 2.0f) zoomScale -= 0.1f; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.OemMinus) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.OemMinus)) { zoomScale -= 0.1f; if (zoomScale < 0.0f) zoomScale += 0.1f; } if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.D0) && input.PreviousKeyboardStates[(int)PlayerIndex.One].IsKeyUp(Keys.D0)) { zoomScale = 1.0f; } } #endregion #region ToggleCamera if (input.CurrentKeyboardStates[(int)PlayerIndex.One].IsKeyDown(Keys.LeftControl)) { toggleCameraMove = true; } else { toggleCameraMove = false; } #endregion }