PageRenderTime 66ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/MapEditor/Forms/Editor.cs

http://github.com/Concliff/Maze
C# | 668 lines | 529 code | 97 blank | 42 comment | 117 complexity | 202fcd79120a1e9c0257a7cc6dbe0bf4 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using Maze.Classes;
  11. namespace MapEditor.Forms
  12. {
  13. public partial class Editor : Form
  14. {
  15. /// <summary>
  16. /// Central position of the displayed map.
  17. /// </summary>
  18. private GPS centralGPS;
  19. private CellEdit cellEditForm;
  20. private Point capturedMousePoint;
  21. private bool isCapturingMove;
  22. private string[] mapNames;
  23. private int currentMapIndex;
  24. private int levelsCount;
  25. private bool isNewMap;
  26. private Dictionary<GridLocation, Cell> mapCells;
  27. private Dictionary<int, GridLocation> startLocations;
  28. private Dictionary<int, GridLocation> finishLocations;
  29. private int maxCellId;
  30. public Editor()
  31. {
  32. InitializeComponent();
  33. CustomInitialize();
  34. this.mapCells = new Dictionary<GridLocation, Cell>();
  35. this.startLocations = new Dictionary<int, GridLocation>();
  36. this.finishLocations = new Dictionary<int, GridLocation>();
  37. this.currentMapIndex = -1;
  38. this.pr_isMapSaved = true;
  39. LoadMapNames();
  40. if (this.mapNames.Length > 0)
  41. LoadMap(0);
  42. this.nudCurrentLevel.Value = 1;
  43. Invalidate();
  44. this.Focus();
  45. }
  46. private int pr_currentLevel;
  47. /// <summary>
  48. /// Gets or sets the current level of the map.
  49. /// </summary>
  50. private int currentLevel
  51. {
  52. get
  53. {
  54. return this.pr_currentLevel;
  55. }
  56. set
  57. {
  58. this.pr_currentLevel = value;
  59. // Return center to the Start point
  60. if (this.startLocations.ContainsKey(this.pr_currentLevel))
  61. this.centralGPS = new GPS(this.startLocations[this.pr_currentLevel], 25, 25);
  62. else
  63. this.centralGPS = new GPS(new GridLocation(0, 0, 0, this.pr_currentLevel), 25, 25);
  64. this.pbMap.Refresh();
  65. }
  66. }
  67. public int NewCellID
  68. {
  69. get
  70. {
  71. return this.maxCellId + 1;
  72. }
  73. }
  74. private bool pr_isMapSaved;
  75. private bool isMapSaved
  76. {
  77. get
  78. {
  79. return this.pr_isMapSaved;
  80. }
  81. set
  82. {
  83. if (this.pr_isMapSaved == value)
  84. return;
  85. if (value)
  86. {
  87. this.lblIsMapSaved.Text = "Saved";
  88. this.btnSave.Enabled = false;
  89. }
  90. else
  91. {
  92. this.lblIsMapSaved.Text = "";
  93. this.btnSave.Enabled = true;
  94. }
  95. this.pr_isMapSaved = value;
  96. }
  97. }
  98. private void LoadMapNames()
  99. {
  100. DirectoryInfo mapDirectory = new DirectoryInfo(GlobalConstants.MAPS_PATH);
  101. FileInfo[] mapFiles = mapDirectory.GetFiles();
  102. List<string> mapNames = new List<string>();
  103. foreach (FileInfo fi in mapFiles)
  104. {
  105. if (fi.Extension == ".map")
  106. mapNames.Add(Path.GetFileNameWithoutExtension(fi.FullName));
  107. }
  108. this.mapNames = mapNames.ToArray();
  109. this.cboCurrentMap.Items.AddRange(this.mapNames);
  110. this.cboCurrentMap.SelectedIndex = 0;
  111. }
  112. private void LoadMap(int mapIndex)
  113. {
  114. // An attempt to reload the current map.
  115. if (this.currentMapIndex == mapIndex)
  116. return;
  117. string mapName = null;
  118. if (mapIndex != -1)
  119. {
  120. try
  121. {
  122. mapName = this.mapNames[mapIndex];
  123. }
  124. catch (IndexOutOfRangeException)
  125. {
  126. MessageBox.Show("Map with index '" + mapIndex.ToString() + "' doesn't exist");
  127. return;
  128. }
  129. }
  130. this.mapCells = new Dictionary<GridLocation, Cell>();
  131. this.startLocations = new Dictionary<int, GridLocation>();
  132. this.finishLocations = new Dictionary<int, GridLocation>();
  133. this.currentMapIndex = mapIndex;
  134. this.levelsCount = 1;
  135. this.maxCellId = 0;
  136. if (mapIndex != -1)
  137. {
  138. StreamReader reader = File.OpenText(GlobalConstants.MAPS_PATH + this.mapNames[this.currentMapIndex] + ".map");
  139. string currentString;
  140. while ((currentString = reader.ReadLine()) != null)
  141. {
  142. string[] stringStruct = new string[10];
  143. stringStruct = currentString.Split(' ');
  144. Cell cell;
  145. cell.ID = Convert.ToInt32(stringStruct[0]);
  146. cell.Location.X = Convert.ToInt32(stringStruct[1]);
  147. cell.Location.Y = Convert.ToInt32(stringStruct[2]);
  148. cell.Location.Z = Convert.ToInt32(stringStruct[3]);
  149. cell.Location.Level = Convert.ToInt32(stringStruct[4]);
  150. cell.Type = Convert.ToUInt32(stringStruct[5]);
  151. cell.Attribute = Convert.ToUInt32(stringStruct[6]);
  152. cell.Option = Convert.ToUInt32(stringStruct[7]);
  153. cell.OptionValue = Convert.ToInt32(stringStruct[8]);
  154. cell.ND4 = Convert.ToInt32(stringStruct[9]);
  155. AddCell(cell);
  156. }
  157. reader.Close();
  158. this.isNewMap = false;
  159. this.tbxMapName.Text = mapName;
  160. this.isMapSaved = true;
  161. }
  162. else
  163. {
  164. this.isNewMap = true;
  165. this.tbxMapName.Text = "Enter_name";
  166. this.tbxMapName.Focus();
  167. }
  168. // Set the current Level to 0
  169. // This also changes this.currentLevel field
  170. this.nudCurrentLevel.Value = 1;
  171. this.pbMap.Invalidate();
  172. }
  173. private void SaveMap()
  174. {
  175. string mapName = this.tbxMapName.Text;
  176. if (string.IsNullOrEmpty(mapName))
  177. {
  178. MessageBox.Show("Enter Map Name", "Saving Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  179. this.tbxMapName.Focus();
  180. return;
  181. }
  182. for (int i = 0; i < this.mapNames.Length; ++i)
  183. {
  184. if (i == this.currentMapIndex)
  185. continue;
  186. if (this.mapNames[i] == mapName)
  187. {
  188. MessageBox.Show("Map \"" + mapName + "\" already exists.", "Saving Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  189. this.tbxMapName.Focus();
  190. return;
  191. }
  192. }
  193. StreamWriter writer = new StreamWriter(GlobalConstants.MAPS_PATH + mapName + ".map", false);
  194. string cellString;
  195. foreach (KeyValuePair<GridLocation, Cell> cell in this.mapCells)
  196. {
  197. cellString = cell.Value.ID.ToString() + " "
  198. + cell.Value.Location.X.ToString() + " "
  199. + cell.Value.Location.Y.ToString() + " "
  200. + cell.Value.Location.Z.ToString() + " "
  201. + cell.Value.Location.Level.ToString() + " "
  202. + cell.Value.Type.ToString() + " "
  203. + cell.Value.Attribute.ToString() + " "
  204. + cell.Value.Option.ToString() + " "
  205. + cell.Value.OptionValue.ToString() + " "
  206. + cell.Value.ND4.ToString();
  207. writer.WriteLine(cellString);
  208. }
  209. writer.Close();
  210. if (this.isNewMap)
  211. {
  212. Array.Resize<string>(ref this.mapNames, this.mapNames.Length + 1);
  213. this.currentMapIndex = this.mapNames.Length - 1;
  214. this.mapNames[this.currentMapIndex] = mapName;
  215. this.cboCurrentMap.Items.Clear();
  216. this.cboCurrentMap.Items.AddRange(this.mapNames);
  217. this.cboCurrentMap.SelectedIndex = this.currentMapIndex;
  218. this.isNewMap = false;
  219. }
  220. else
  221. {
  222. // Change displaying Map Name if it has been changed
  223. if (mapName != this.mapNames[this.currentMapIndex])
  224. {
  225. // Drop the previous map file
  226. File.Delete(GlobalConstants.MAPS_PATH + this.mapNames[this.currentMapIndex] + ".map");
  227. this.cboCurrentMap.Items[this.currentMapIndex] = mapName;
  228. this.mapNames[this.currentMapIndex] = mapName;
  229. }
  230. }
  231. // Mark that map is at newer verstion
  232. this.isMapSaved = true;
  233. }
  234. public void AddCell(Cell cell)
  235. {
  236. if (this.mapCells.ContainsKey(cell.Location))
  237. {
  238. ReplaceCell(cell);
  239. return;
  240. }
  241. this.mapCells.Add(cell.Location, cell);
  242. if (Convert.ToInt32(cell.Location.Level) >= this.levelsCount)
  243. ++this.levelsCount;
  244. if (cell.HasAttribute(CellAttributes.IsStart))
  245. this.startLocations[cell.Location.Level] = cell.Location;
  246. if (cell.HasAttribute(CellAttributes.IsFinish))
  247. this.finishLocations[cell.Location.Level] = cell.Location;
  248. if (cell.ID > this.maxCellId)
  249. this.maxCellId = cell.ID;
  250. this.isMapSaved = false;
  251. }
  252. public void RemoveCell(Cell cell)
  253. {
  254. this.mapCells.Remove(cell.Location);
  255. if (this.maxCellId == cell.ID)
  256. --this.maxCellId;
  257. if (cell.HasAttribute(CellAttributes.IsStart))
  258. this.startLocations.Remove(cell.Location.Level);
  259. if (cell.HasAttribute(CellAttributes.IsFinish))
  260. this.startLocations.Remove(cell.Location.Level);
  261. this.isMapSaved = false;
  262. }
  263. public void ReplaceCell(Cell cell)
  264. {
  265. RemoveCell(cell);
  266. AddCell(cell);
  267. }
  268. public Cell GetCell(GridLocation location)
  269. {
  270. Cell cell;
  271. if (!this.mapCells.TryGetValue(location, out cell))
  272. {
  273. // default cell
  274. cell.Initialize();
  275. // but specified location
  276. cell.Location = location;
  277. }
  278. return cell;
  279. }
  280. void pbMap_MouseClick(object sender, MouseEventArgs e)
  281. {
  282. // Only Left Mouse Button
  283. if (e.Button != System.Windows.Forms.MouseButtons.Right)
  284. return;
  285. GridLocation cursorLocation = new GridLocation();
  286. // Calculate Mouse absolute position
  287. // i.e How far it is from the cetral position
  288. cursorLocation.X = this.centralGPS.Absolute.X - (this.pbMap.Size.Width / 2 - e.Location.X);
  289. cursorLocation.Y = this.centralGPS.Absolute.Y - (this.pbMap.Size.Height / 2 - e.Location.Y);
  290. cursorLocation.Z = this.centralGPS.Absolute.Z;
  291. cursorLocation.Level = this.centralGPS.Location.Level;
  292. GPS cursorGPS = new GPS();
  293. cursorGPS.Absolute = cursorLocation;
  294. Cell cell = GetCell(cursorGPS.Location);
  295. // Prevent double BlockEdit window openning
  296. if (this.cellEditForm == null)
  297. this.cellEditForm = new CellEdit(cell);
  298. else
  299. {
  300. this.cellEditForm.Close();
  301. this.cellEditForm = new CellEdit(cell);
  302. }
  303. this.cellEditForm.FormClosing += (sender_, e_) => { this.pbMap.Refresh(); };
  304. this.cellEditForm.ShowDialog();
  305. }
  306. void pbMap_Paint(object sender, PaintEventArgs e)
  307. {
  308. Graphics gGraphic = e.Graphics;
  309. GridLocation cellLocation = new GridLocation();
  310. Cell cell = new Cell();
  311. // CellGraph
  312. int cellsCountWidth = (int)Math.Ceiling(this.pbMap.Size.Width / 2d / GlobalConstants.CELL_WIDTH) * 2 + 1;
  313. int cellsCountHeight = (int)Math.Ceiling(this.pbMap.Size.Height / 2d / GlobalConstants.CELL_HEIGHT) * 2 + 1;
  314. // HACK: Correction values because the width and height of drawing region are not a multiple of CELL_WIDTH and CELL_HEIGHT
  315. int xCorrection = ((int)Math.Ceiling(this.pbMap.Size.Height * 1d / GlobalConstants.CELL_HEIGHT) * GlobalConstants.CELL_HEIGHT - this.pbMap.Size.Height) / 2;
  316. int yCorrection = ((int)Math.Ceiling(this.pbMap.Size.Width * 1d / GlobalConstants.CELL_WIDTH) * GlobalConstants.CELL_WIDTH - this.pbMap.Size.Width) / 2;
  317. for (int i = 0; i < cellsCountWidth; ++i)
  318. for (int j = 0; j < cellsCountHeight; ++j)
  319. {
  320. int x, y;
  321. x = (i - 1) * GlobalConstants.CELL_WIDTH - this.centralGPS.X + xCorrection + 25;
  322. y = (j - 1) * GlobalConstants.CELL_HEIGHT - this.centralGPS.Y + yCorrection + 25;
  323. cellLocation.X = centralGPS.Location.X + i - cellsCountWidth / 2;
  324. cellLocation.Y = centralGPS.Location.Y + j - cellsCountHeight / 2;
  325. cellLocation.Z = centralGPS.Location.Z;
  326. cellLocation.Level = centralGPS.Location.Level;
  327. cell = GetCell(cellLocation);
  328. gGraphic.DrawImage(PictureManager.GetPictureByType(cell.Type), x, y, GlobalConstants.CELL_WIDTH, GlobalConstants.CELL_HEIGHT);
  329. // Draw Start Block
  330. if (cell.HasAttribute(CellAttributes.IsStart))
  331. {
  332. gGraphic.DrawImage(PictureManager.StartImage, x + 5, y + 5, 40, 40);
  333. }
  334. // Draw Finish Block
  335. if (cell.HasAttribute(CellAttributes.IsFinish))
  336. {
  337. gGraphic.DrawImage(PictureManager.FinishImage, x + 5, y + 5, PictureManager.FinishImage.Width, PictureManager.FinishImage.Height);
  338. }
  339. // Draw Ooze Drop
  340. if (cell.HasAttribute(CellAttributes.HasDrop))
  341. {
  342. gGraphic.DrawImage(PictureManager.DropImage, x + 15, y + 10, 20, 30);
  343. }
  344. // Portal
  345. if (cell.HasOption(CellOptions.Portal))
  346. {
  347. Image image = PictureManager.PortalImage;
  348. gGraphic.DrawImage(image,
  349. x + (GlobalConstants.CELL_WIDTH - image.Width) / 2,
  350. y + (GlobalConstants.CELL_HEIGHT - image.Height) / 2,
  351. PictureManager.PortalImage.Width, PictureManager.PortalImage.Height);
  352. }
  353. }
  354. }
  355. void nudCurrentLevel_ValueChanged(object sender, System.EventArgs e)
  356. {
  357. if (this.nudCurrentLevel.Value < 1)
  358. this.nudCurrentLevel.Value = 1;
  359. else if (this.nudCurrentLevel.Value > this.levelsCount)
  360. this.nudCurrentLevel.Value = this.levelsCount;
  361. this.currentLevel = (int)this.nudCurrentLevel.Value - 1;
  362. }
  363. void cboCurrentMap_SelectedValueChanged(object sender, System.EventArgs e)
  364. {
  365. if (!this.isMapSaved && this.currentMapIndex != this.cboCurrentMap.SelectedIndex)
  366. {
  367. System.Windows.Forms.DialogResult result = MessageBox.Show("Would you like to save the current map?", "Map Saving", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  368. if (result == System.Windows.Forms.DialogResult.Yes)
  369. SaveMap();
  370. else if (result == System.Windows.Forms.DialogResult.Cancel)
  371. this.cboCurrentMap.SelectedIndex = this.currentMapIndex;
  372. }
  373. LoadMap(this.cboCurrentMap.SelectedIndex);
  374. }
  375. private void btnAddMap_Click(object sender, System.EventArgs e)
  376. {
  377. this.cboCurrentMap.SelectedIndex = -1;
  378. }
  379. private void btnRemoveMap_Click(object sender, System.EventArgs e)
  380. {
  381. // TODO: Remove current map
  382. }
  383. private void btnAddLevel_Click(object sender, System.EventArgs e)
  384. {
  385. ++this.levelsCount;
  386. this.nudCurrentLevel.Value = (int)this.levelsCount;
  387. }
  388. private void btnRemoveLevel_Click(object sender, System.EventArgs e)
  389. {
  390. // TODO: remove current level
  391. }
  392. private void btnSave_Click(object sender, System.EventArgs e)
  393. {
  394. SaveMap();
  395. }
  396. void tbxMapName_TextChanged(object sender, System.EventArgs e)
  397. {
  398. this.isMapSaved = false;
  399. }
  400. private void pbMap_MouseDown(object sender, MouseEventArgs e)
  401. {
  402. if (e.Button != System.Windows.Forms.MouseButtons.Left)
  403. return;
  404. this.capturedMousePoint = Cursor.Position;
  405. this.isCapturingMove = true;
  406. Cursor = Cursors.Hand;
  407. }
  408. private void pbMap_MouseUp(object sender, MouseEventArgs e)
  409. {
  410. if (e.Button != System.Windows.Forms.MouseButtons.Left)
  411. return;
  412. this.isCapturingMove = false;
  413. Cursor = DefaultCursor;
  414. }
  415. private void pbMap_MouseMove(object sender, MouseEventArgs e)
  416. {
  417. if (!this.isCapturingMove)
  418. return;
  419. // Find out where the mouse were moved
  420. // and these changes apply to the new Map center
  421. GridLocation prevLocation = this.centralGPS.Absolute;
  422. prevLocation.X += this.capturedMousePoint.X - Cursor.Position.X;
  423. prevLocation.Y += this.capturedMousePoint.Y - Cursor.Position.Y;
  424. this.centralGPS.Absolute = prevLocation;
  425. //Cursor.Position = this.capturedMousePoint;
  426. this.capturedMousePoint = Cursor.Position;
  427. this.pbMap.Refresh();
  428. }
  429. private void Editor_FormClosing(object sender, FormClosingEventArgs e)
  430. {
  431. if (!this.isMapSaved)
  432. {
  433. System.Windows.Forms.DialogResult result = MessageBox.Show("Would you like to save the current map?", "Map Saving", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  434. if (result == System.Windows.Forms.DialogResult.Yes)
  435. SaveMap();
  436. else if (result == System.Windows.Forms.DialogResult.Cancel)
  437. e.Cancel = true;
  438. }
  439. }
  440. private void pbMap_MouseLeave(object sender, System.EventArgs e)
  441. {
  442. this.tbxMapName.Focus();
  443. }
  444. private void pbMap_MouseEnter(object sender, System.EventArgs e)
  445. {
  446. this.pbMap.Focus();
  447. }
  448. private void pbMap_KeyDown(object sender, KeyEventArgs e)
  449. {
  450. if (e.KeyCode != Keys.W && e.KeyCode != Keys.A && e.KeyCode != Keys.S && e.KeyCode != Keys.D && e.KeyCode != Keys.Z && e.KeyCode != Keys.R)
  451. return;
  452. // Compute the cursor GPS
  453. Point cursorPoint = this.pbMap.PointToClient(Cursor.Position);
  454. //Point cursorLocation = new Point(Cursor.Position.X - pbMapPoint.X, Cursor.Position.Y - pbMapPoint.Y);
  455. GridLocation cursorLocation = new GridLocation();
  456. // Calculate Mouse absolute position
  457. // i.e How far it is from the cetral position
  458. cursorLocation.X = this.centralGPS.Absolute.X - (this.pbMap.Size.Width / 2 - cursorPoint.X);
  459. cursorLocation.Y = this.centralGPS.Absolute.Y - (this.pbMap.Size.Height / 2 - cursorPoint.Y);
  460. cursorLocation.Z = this.centralGPS.Absolute.Z;
  461. cursorLocation.Level = this.centralGPS.Location.Level;
  462. GPS cursorGPS = new GPS();
  463. cursorGPS.Absolute = cursorLocation;
  464. Cell cell = GetCell(cursorGPS.Location);
  465. if (cell.Type == (uint)Directions.None)
  466. cell.Type = 0;
  467. byte modifiedDirection = 0;
  468. switch (e.KeyCode)
  469. {
  470. case Keys.W:
  471. modifiedDirection += (byte)Directions.Up;
  472. break;
  473. case Keys.A:
  474. modifiedDirection += (byte)Directions.Left;
  475. break;
  476. case Keys.S:
  477. modifiedDirection += (byte)Directions.Down;
  478. break;
  479. case Keys.D:
  480. modifiedDirection += (byte)Directions.Right;
  481. break;
  482. case Keys.Z:
  483. modifiedDirection += (byte)Directions.Up + (byte)Directions.Left + (byte)Directions.Down + (byte)Directions.Right;
  484. break;
  485. case Keys.R:
  486. // Mark the cell with every direction to change
  487. // then change the current cell Type to these direction
  488. // that allows to change all the neighbours and
  489. // remove the cell because it will be marked as 'no way to go'.
  490. modifiedDirection += (byte)Directions.Up + (byte)Directions.Left + (byte)Directions.Down + (byte)Directions.Right;
  491. cell.Type = modifiedDirection;
  492. break;
  493. }
  494. if ((modifiedDirection & (byte)Directions.Up) != 0)
  495. {
  496. cell.Type ^= (uint)Directions.Up;
  497. // Neighbour Cell
  498. Cell neighbourCell = GetCell(new GridLocation(cell.Location.X, cell.Location.Y - 1, cell.Location.Z, cell.Location.Level));
  499. if (neighbourCell.ID == -1)
  500. {
  501. neighbourCell.ID = NewCellID;
  502. neighbourCell.Type = 0;
  503. }
  504. if ((cell.Type & (uint)Directions.Up) != (neighbourCell.Type & (uint)Directions.Down))
  505. neighbourCell.Type ^= (uint)Directions.Down;
  506. if (neighbourCell.Type == 0)
  507. RemoveCell(neighbourCell);
  508. else
  509. AddCell(neighbourCell);
  510. }
  511. if ((modifiedDirection & (byte)Directions.Down) != 0)
  512. {
  513. cell.Type ^= (uint)Directions.Down;
  514. // Neighbour Cell
  515. Cell neighbourCell = GetCell(new GridLocation(cell.Location.X, cell.Location.Y + 1, cell.Location.Z, cell.Location.Level));
  516. if (neighbourCell.ID == -1)
  517. {
  518. neighbourCell.ID = NewCellID;
  519. neighbourCell.Type = 0;
  520. }
  521. if ((cell.Type & (uint)Directions.Down) != (neighbourCell.Type & (uint)Directions.Up))
  522. neighbourCell.Type ^= (uint)Directions.Up;
  523. if (neighbourCell.Type == 0)
  524. RemoveCell(neighbourCell);
  525. else
  526. AddCell(neighbourCell);
  527. }
  528. if ((modifiedDirection & (byte)Directions.Left) != 0)
  529. {
  530. cell.Type ^= (uint)Directions.Left;
  531. // Neighbour Cell
  532. Cell neighbourCell = GetCell(new GridLocation(cell.Location.X - 1, cell.Location.Y, cell.Location.Z, cell.Location.Level));
  533. if (neighbourCell.ID == -1)
  534. {
  535. neighbourCell.ID = NewCellID;
  536. neighbourCell.Type = 0;
  537. }
  538. if ((cell.Type & (uint)Directions.Left) != (neighbourCell.Type & (uint)Directions.Right))
  539. neighbourCell.Type ^= (uint)Directions.Right;
  540. if (neighbourCell.Type == 0)
  541. RemoveCell(neighbourCell);
  542. else
  543. AddCell(neighbourCell);
  544. }
  545. if ((modifiedDirection & (byte)Directions.Right) != 0)
  546. {
  547. cell.Type ^= (uint)Directions.Right;
  548. // Neighbour Cell
  549. Cell neighbourCell = GetCell(new GridLocation(cell.Location.X + 1, cell.Location.Y, cell.Location.Z, cell.Location.Level));
  550. if (neighbourCell.ID == -1)
  551. {
  552. neighbourCell.ID = NewCellID;
  553. neighbourCell.Type = 0;
  554. }
  555. if ((cell.Type & (uint)Directions.Right) != (neighbourCell.Type & (uint)Directions.Left))
  556. neighbourCell.Type ^= (uint)Directions.Left;
  557. if (neighbourCell.Type == 0)
  558. RemoveCell(neighbourCell);
  559. else
  560. AddCell(neighbourCell);
  561. }
  562. if (cell.ID == -1)
  563. cell.ID = NewCellID;
  564. if (cell.Type == 0)
  565. RemoveCell(cell);
  566. else
  567. AddCell(cell);
  568. this.pbMap.Refresh();
  569. }
  570. }
  571. }