public static void SelectTile(int xPos, int yPos, TileTab tab, int clicks) { var ti = TileHandler.GetTileImage(tab); var tileSize = ti.TileSize; int originalIndex = TileHandler.GetTileIndex(xPos, yPos, tab); int index = ti.ColumnsPerRow * yPos + xPos; if (xPos >= ti.Image.Width / tileSize || yPos >= ti.Image.Height / tileSize) { return; } if (clicks == 1) { if (SelectedTiles.Contains(index)) { SelectedTiles.Remove(index); } else { SelectedTiles.Add(index); } } else { switch (tab) { case TileTab.Source: { TileHandler.SelectedTile = originalIndex; break; } case TileTab.Randomized: { TileHandler.SelectedTile = RandomizedMap[xPos, yPos]; break; } case TileTab.RuleTest: { TileHandler.SelectedTile = RuleTestMap[xPos, yPos]; break; } } } }
public static void DrawTiles(PictureBox pctb, TileTab tab) { var img = new Bitmap(pctb.Image); var graphics = Graphics.FromImage(img); graphics.Clear(Color.White); var tileSize = TileHandler.TileSize; var grid = tab == TileTab.Randomized ? RandomizedMap : RuleTestMap; for (int x = 0; x <= grid.GetLength(0) - 1; x++) { for (int y = 0; y <= grid.GetLength(1) - 1; y++) { int srcX = grid[x, y] % TileHandler.GetTileImage(TileTab.Source).ColumnsPerRow; int srcY = (grid[x, y] - srcX) / TileHandler.GetTileImage(TileTab.Source).ColumnsPerRow; var dest = new Rectangle(x * tileSize, y * tileSize, tileSize, tileSize); var src = new Rectangle(srcX * tileSize, srcY * tileSize, tileSize, tileSize); if (grid[x, y] == -1) { graphics.DrawImage(_Blank, dest.X, dest.Y); } else { graphics.DrawImage(SourceImages[SelectedSource].Image, dest, src, GraphicsUnit.Pixel); } } } pctb.Image = img; }
public static int GetTileIndex(int index, TileTab tab) { var ti = GetTileImage(tab); int x = index % ti.ColumnsPerRow; int y = index / ti.ColumnsPerRow; return(GetTileIndex(x, y, tab)); }
public static void SelectAll(TileTab tab) { DeselectAll(tab); for (int i = 0; i <= GetTileImage(tab).NumberOfTiles - 1; i++) { SelectedTiles.Add(i); } }
public static void GroupSelectedTiles(TileTab tab, TileSelectionGroups tsg) { var ti = TileHandler.GetTileImage(tab); foreach (var i in SelectedTiles) { ti.SetSelectionGroup(i, tsg); } }
public static void DisallowEverythingNotAttributed(TileTab tab) { var ti = GetTileImage(tab); for (int i = 0; i < ti.NumberOfTiles; i++) { if (!ti.GetTiles().Exists(item => i == item.Index)) { ti.SetSelectionGroup(i, TileSelectionGroups.Red); } } }
/// <summary> /// The 'true' index of a tile is based on its location in the source image, /// so we need to convert from one tab's coordinate system to the source tab's. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public static int GetTileIndex(int x, int y, TileTab tab) { switch (tab) { case TileTab.Source: return(SourceImages[SelectedSource].Image.Width / SourceImages[SelectedSource].TileSize * y + x); case TileTab.Randomized: return(RandomizedMap[x, y]); case TileTab.RuleTest: return(RuleTestMap[x, y]); default: goto case 0; } }
public static TileImage GetTileImage(TileTab tab) { switch (tab) { case TileTab.Source: { return(SourceImages[SelectedSource]); } case TileTab.Randomized: { return(_RandomizedMapImage); } case TileTab.RuleTest: { return(_RuleTestMapImage); } default: { return(SourceImages[SelectedSource]); } } }
public static void DisallowAllAroundSelected(TileTab tab) { var ti = GetTileImage(tab); foreach (var t in ti.GetTiles(t => t.SelectionGroup != TileSelectionGroups.None)) { //West. ti.SetSelectionGroup(t.Index - 1, TileSelectionGroups.Red); //East. ti.SetSelectionGroup(t.Index + 1, TileSelectionGroups.Red); //North. ti.SetSelectionGroup(t.Index - ti.ColumnsPerRow, TileSelectionGroups.Red); //South. ti.SetSelectionGroup(t.Index + ti.ColumnsPerRow, TileSelectionGroups.Red); } }
public static void CreateRule(TileTab tab) { var ti = GetTileImage(tab); //Blue is selected tile, green allowed neighbors, red disallowed neighbors. foreach (var t in ti.GetTiles()) { var index = GetTileIndex(t.Index, tab); var west = t.Index - 1; var east = t.Index + 1; var north = t.Index - ti.ColumnsPerRow; var south = t.Index + ti.ColumnsPerRow; var rt = RuleType.None; //West. if (ti.GetSelectionGroup(west) == TileSelectionGroups.Green || ti.GetSelectionGroup(west) == TileSelectionGroups.Red) { rt = ti.GetSelectionGroup(west) == TileSelectionGroups.Green ? RuleType.Allowed : RuleType.Disallowed; AddRule(new TileRule(index, GetTileIndex(west, tab), Direction.West, ti.Identifier, rt)); } //East. if (ti.GetSelectionGroup(east) == TileSelectionGroups.Green || ti.GetSelectionGroup(east) == TileSelectionGroups.Red) { rt = ti.GetSelectionGroup(east) == TileSelectionGroups.Green ? RuleType.Allowed : RuleType.Disallowed; AddRule(new TileRule(index, GetTileIndex(east, tab), Direction.East, ti.Identifier, rt)); } //North. if (ti.GetSelectionGroup(north) == TileSelectionGroups.Green || ti.GetSelectionGroup(north) == TileSelectionGroups.Red) { rt = ti.GetSelectionGroup(north) == TileSelectionGroups.Green ? RuleType.Allowed : RuleType.Disallowed; AddRule(new TileRule(index, GetTileIndex(north, tab), Direction.North, ti.Identifier, rt)); } //South. if (ti.GetSelectionGroup(south) == TileSelectionGroups.Green || ti.GetSelectionGroup(south) == TileSelectionGroups.Red) { rt = ti.GetSelectionGroup(south) == TileSelectionGroups.Green ? RuleType.Allowed : RuleType.Disallowed; AddRule(new TileRule(index, GetTileIndex(south, tab), Direction.South, ti.Identifier, rt)); } } }
public static int GetHeight(TileTab tab) { return(GetTileImage(tab).Image.Height); }
public static int GetWidth(TileTab tab) { return(GetTileImage(tab).Image.Width); }
public static void CreateRulesFromDisallowAllBetweenGroups(TileTab tab, BackgroundWorker worker) { var ti = GetTileImage(tab); var group1 = ti.GetTiles(); var group2 = ti.GetTiles(t => t.SelectionGroup == TileSelectionGroups.Green); var group3 = ti.GetTiles(t => t.SelectionGroup == TileSelectionGroups.Red); int max = group1.Count + group2.Count; float count = 0; foreach (var t1 in group1) { int index1 = GetTileIndex(t1.Index, tab); worker.ReportProgress((int)(100 * (count++ / max))); foreach (var t2 in group2) { int index2 = GetTileIndex(t2.Index, tab); //West. AddRule(new TileRule(index1, index2, Direction.West, ti.Identifier, RuleType.Disallowed)); //East. AddRule(new TileRule(index1, index2, Direction.East, ti.Identifier, RuleType.Disallowed)); //North. AddRule(new TileRule(index1, index2, Direction.North, ti.Identifier, RuleType.Disallowed)); //South. AddRule(new TileRule(index1, index2, Direction.South, ti.Identifier, RuleType.Disallowed)); } foreach (var t3 in group3) { int index3 = GetTileIndex(t3.Index, tab); //West. AddRule(new TileRule(index1, index3, Direction.West, ti.Identifier, RuleType.Disallowed)); //East. AddRule(new TileRule(index1, index3, Direction.East, ti.Identifier, RuleType.Disallowed)); //North. AddRule(new TileRule(index1, index3, Direction.North, ti.Identifier, RuleType.Disallowed)); //South. AddRule(new TileRule(index1, index3, Direction.South, ti.Identifier, RuleType.Disallowed)); } } foreach (var t2 in group2) { int index2 = GetTileIndex(t2.Index, tab); worker.ReportProgress((int)(100 * (count++ / max))); foreach (var t3 in group3) { int index3 = GetTileIndex(t3.Index, tab); //West. AddRule(new TileRule(index2, index3, Direction.West, ti.Identifier, RuleType.Disallowed)); //East. AddRule(new TileRule(index2, index3, Direction.East, ti.Identifier, RuleType.Disallowed)); //North. AddRule(new TileRule(index2, index3, Direction.North, ti.Identifier, RuleType.Disallowed)); //South. AddRule(new TileRule(index2, index3, Direction.South, ti.Identifier, RuleType.Disallowed)); } } }
public static void DeselectAll(TileTab tab) { SelectedTiles.Clear(); }