public TileControl(TileAssignment tileAssignment, bool showNoteIcon = true) { InitializeComponent(); TileAssignment = tileAssignment; if (!showNoteIcon) { noteIcon.Source = null; } }
private void TileControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { RoomPlanViewModel vm = DataContext as RoomPlanViewModel; if (sender is TileControl tileControl) { if (!vm.IsRoomDrawEnabled) { if (selectedPlaceableControl != null) { selectedPlaceableControl.Background = Brushes.Transparent; selectedPlaceableControl = null; vm.SelectedPlaceableAssignment = null; } if (selectedTileControl != null) { selectedTileControl.Background = Brushes.Transparent; } TileAssignment tileAssignment = tileControl.TileAssignment; vm.SelectedTileAssignment = tileAssignment; tileControl.Background = highlightColor; selectedTileControl = tileControl; updateTile = false; updateTile = true; vm.SelectedTabIndex = 1; if (tileAssignment.TileGuid != null) { string tileGuid = tileAssignment.TileGuid; vm.SelectedCollectionSet = App.LoadedCollections.FirstOrDefault(x => x.TileFile.Data.Any(y => y.Guid == tileGuid)); vm.SelectedAvailableTile = vm.CollectionTiles.FirstOrDefault(x => x.Guid == tileGuid); } else { vm.SelectedAvailableTile = vm.CollectionTiles.FirstOrDefault(); } } else { predictInnerRoomTimer.Stop(); predictInnerRoomTimer.Start(); if (!drawRoomSelectedTiles.Any(x => x.Tag.ToString() == tileControl.Tag.ToString())) { tileControl.Background = drawRoomColor; drawRoomSelectedTiles.Add(tileControl); confirmDrawRoom.IsEnabled = true; } } } }
public void SetTileAssignment(TileAssignment tileAssignment) { (DataContext as TileConfiguratorViewModel).TileAssignment = tileAssignment; }
private void ConfirmDrawRoom_Click(object sender, RoutedEventArgs e) { RoomPlanViewModel vm = DataContext as RoomPlanViewModel; foreach (TileControl selectedTile in drawRoomSelectedTiles) { TileControl leftTile = drawRoomSelectedTiles.FirstOrDefault(x => x.TileAssignment.X == selectedTile.TileAssignment.X - 1 && x.TileAssignment.Y == selectedTile.TileAssignment.Y); TileControl topTile = drawRoomSelectedTiles.FirstOrDefault(x => x.TileAssignment.X == selectedTile.TileAssignment.X && x.TileAssignment.Y == selectedTile.TileAssignment.Y - 1); TileControl rightTile = drawRoomSelectedTiles.FirstOrDefault(x => x.TileAssignment.X == selectedTile.TileAssignment.X + 1 && x.TileAssignment.Y == selectedTile.TileAssignment.Y); TileControl bottomTile = drawRoomSelectedTiles.FirstOrDefault(x => x.TileAssignment.X == selectedTile.TileAssignment.X && x.TileAssignment.Y == selectedTile.TileAssignment.Y + 1); TileAssignment leftInRoom = inRoomTiles.FirstOrDefault(x => x.X == selectedTile.TileAssignment.X - 1 && x.Y == selectedTile.TileAssignment.Y); TileAssignment topInRoom = inRoomTiles.FirstOrDefault(x => x.X == selectedTile.TileAssignment.X && x.Y == selectedTile.TileAssignment.Y - 1); TileAssignment rightInRoom = inRoomTiles.FirstOrDefault(x => x.X == selectedTile.TileAssignment.X + 1 && x.Y == selectedTile.TileAssignment.Y); TileAssignment bottomInRoom = inRoomTiles.FirstOrDefault(x => x.X == selectedTile.TileAssignment.X && x.Y == selectedTile.TileAssignment.Y + 1); if ((topTile != null || bottomTile != null) && leftInRoom != null && rightInRoom != null) // Vertical center wall { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Wall_Centered && (x.TileRotation == TileRotation.Degrees_90 | x.TileRotation == TileRotation.Degrees_270)); } if ((leftTile != null || rightTile != null) && topInRoom != null && bottomInRoom != null) // Horizontal center wall { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Wall_Centered && (x.TileRotation == TileRotation.Degrees_0 | x.TileRotation == TileRotation.Degrees_180)); } if (leftTile != null && rightTile != null && (topTile == null && bottomTile == null || topTile != null && bottomTile == null || topTile == null && bottomTile != null)) // Horizonzal wall { TileRotation rotation = inRoomTiles.Any(t => t.Y == selectedTile.TileAssignment.Y + 1) ? TileRotation.Degrees_0 : TileRotation.Degrees_180; selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Wall && x.TileRotation == rotation); } else if (topTile != null && bottomTile != null && (leftTile == null && rightTile == null || leftTile != null && rightTile == null || leftTile == null && rightTile != null)) // Vertical wall { TileRotation rotation = inRoomTiles.Any(t => t.X == selectedTile.TileAssignment.X + 1) ? TileRotation.Degrees_270 : TileRotation.Degrees_90; selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Wall && x.TileRotation == rotation); } else if (leftTile != null && bottomTile != null && rightTile == null && topTile == null) // Top right corner { if (inRoomTiles.Any(t => t.X == selectedTile.TileAssignment.X + 1) && inRoomTiles.Any(t => t.Y == selectedTile.TileAssignment.Y - 1)) // Corner is inner corner { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Corner_Inner && x.TileRotation == TileRotation.Degrees_270); } else { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Corner && x.TileRotation == TileRotation.Degrees_90); } } else if (rightTile != null && bottomTile != null && leftTile == null && topTile == null) // Top left corner { if (inRoomTiles.Any(t => t.X == selectedTile.TileAssignment.X - 1) && inRoomTiles.Any(t => t.Y == selectedTile.TileAssignment.Y - 1)) // Corner is inner corner { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Corner_Inner && x.TileRotation == TileRotation.Degrees_180); } else { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Corner && x.TileRotation == TileRotation.Degrees_0); } } else if (leftTile != null && topTile != null && rightTile == null && bottomTile == null) // Bottom right corner { if (inRoomTiles.Any(t => t.X == selectedTile.TileAssignment.X + 1) && inRoomTiles.Any(t => t.Y == selectedTile.TileAssignment.Y + 1)) // Corner is inner corner { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Corner_Inner && x.TileRotation == TileRotation.Degrees_0); } else { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Corner && x.TileRotation == TileRotation.Degrees_180); } } else if (rightTile != null && topTile != null && leftTile == null && bottomTile == null) // Bottom left corner { if (inRoomTiles.Any(t => t.X == selectedTile.TileAssignment.X - 1) && inRoomTiles.Any(t => t.Y == selectedTile.TileAssignment.Y + 1)) // Corner is inner corner { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Corner_Inner && x.TileRotation == TileRotation.Degrees_90); } else { selectedTile.TileAssignment.Tile = vm.SelectedCollectionSet.TileFile.Data .FirstOrDefault(x => x.TileType == TileType.Corner && x.TileRotation == TileRotation.Degrees_270); } } } vm.IsRoomDrawEnabled = false; }
private void PredictInnerRoom() { if (isClosing) { return; } foreach (TileAssignment oldInnerRoom in inRoomTiles) { if (!drawRoomSelectedTiles.Any(x => x.TileAssignment.X == oldInnerRoom.X && x.TileAssignment.Y == oldInnerRoom.Y)) { oldInnerRoom.Control.Background = Brushes.Transparent; } } inRoomTiles.Clear(); RoomPlanViewModel vm = DataContext as RoomPlanViewModel; for (int y = 1; y <= vm.RoomPlan.TilesY; y++) { for (int x = 1; x <= vm.RoomPlan.TilesX; x++) { if (!drawRoomSelectedTiles.Any(t => t.TileAssignment.X == x && t.TileAssignment.Y == y)) { TileAssignment inRoomTile = vm.RoomPlan.TileAssignments.FirstOrDefault(t => t.X == x && t.Y == y); bool hasNeighbours = vm.RoomPlan.TileAssignments.Any(t => t.X == x - 1 && t.Y == y) && vm.RoomPlan.TileAssignments.Any(t => t.X == x && t.Y == y - 1) && vm.RoomPlan.TileAssignments.Any(t => t.X == x + 1 && t.Y == y) && vm.RoomPlan.TileAssignments.Any(t => t.X == x && t.Y == y + 1); if (inRoomTile != null) { int wallCount = 0; #region Check if enclosed by top wall for (int yCheck = y - 1; yCheck >= 1; yCheck--) { if (drawRoomSelectedTiles.Any(t => t.TileAssignment.X == x && t.TileAssignment.Y == yCheck)) { wallCount++; break; } } #endregion #region Check if enclosed by bottom wall for (int yCheck = y + 1; yCheck <= vm.RoomPlan.TilesY; yCheck++) { if (drawRoomSelectedTiles.Any(t => t.TileAssignment.X == x && t.TileAssignment.Y == yCheck)) { wallCount++; break; } } #endregion #region Check if enclosed by left wall for (int xCheck = x - 1; xCheck >= 1; xCheck--) { if (drawRoomSelectedTiles.Any(t => t.TileAssignment.X == xCheck && t.TileAssignment.Y == y)) { wallCount++; break; } } #endregion #region Check if enclosed by right wall for (int xCheck = x + 1; xCheck <= vm.RoomPlan.TilesX; xCheck++) { if (drawRoomSelectedTiles.Any(t => t.TileAssignment.X == xCheck && t.TileAssignment.Y == y)) { wallCount++; break; } } #endregion if (wallCount >= 4) { inRoomTiles.Add(inRoomTile); inRoomTile.Control.Background = innerRoomPredictColor; } } } } } noRoomError.Visibility = inRoomTiles.Count > 0 ? Visibility.Collapsed : Visibility.Visible; predictInnerRoomTimer.Stop(); }