Form1.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. // $Id: foo.cpp 2979 2006-01-10 00:00:04Z sommer $
  2. //
  3. // Cobble - A simple SuperTux level editor
  4. // Copyright (C) 2006 Christoph Sommer <supertux@2006.expires.deltadevelopment.de>
  5. //
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU General Public License
  8. // as published by the Free Software Foundation; either version 2
  9. // of the License, or (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. // 02111-1307, USA.
  20. using System;
  21. using System.Collections;
  22. using System.Collections.Generic;
  23. using System.ComponentModel;
  24. using System.Data;
  25. using System.Drawing;
  26. using System.Text;
  27. using System.Windows.Forms;
  28. using System.Drawing.Imaging;
  29. using System.Drawing.Drawing2D;
  30. using System.IO;
  31. namespace Cobble {
  32. public partial class Form1 : Form {
  33. Level level = null;
  34. Sector currentSector = null;
  35. Tilemap currentTilemap = null;
  36. int currentTileId = 0;
  37. TileGroup currentTilegroup = null;
  38. TileRepository tileRepository = null;
  39. string currentLevelFilename = null;
  40. Rectangle currentSelection = new Rectangle(0, 0, 0, 0);
  41. Rectangle currentFloatingTilemapPos = new Rectangle(0, 0, 0, 0);
  42. int[,] currentFloatingTilemap = null;
  43. Brush currentBrush = null;
  44. enum CanvasAction { none, drawingTiles, selecting, movingFloatingTilemap, movingObject, drawingBrush };
  45. CanvasAction currentCanvasAction = CanvasAction.none;
  46. Point canvasActionStart;
  47. SpatialGameObject currentGameObject;
  48. public Form1() {
  49. InitializeComponent();
  50. if (!File.Exists("data\\images\\tiles.strf")) {
  51. MessageBox.Show("Cobble was unable to find data\\images\\tiles.strf.\n\nMake sure your current working directory is the SuperTux main directory.\n\nAborting.", "Cobble - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  52. throw new ArgumentException("Abort");
  53. }
  54. tileRepository = new TileRepository("data\\images\\tiles.strf");
  55. currentBrush = new Brush(tileRepository);
  56. foreach (TileGroup tileGroup in tileRepository.getTileGroups()) {
  57. cbTilegroup.Items.Add(tileGroup);
  58. }
  59. if (cbTilegroup.Items.Count >= 1) cbTilegroup.SelectedIndex = 0;
  60. foreach (GameObject gameObject in GameObject.getExponents()) {
  61. lbGameObjects.Items.Add(gameObject);
  62. }
  63. if (lbGameObjects.Items.Count >= 1) lbGameObjects.SelectedIndex = 0;
  64. btnModeTileAdd_Click(null, null);
  65. }
  66. private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
  67. Close();
  68. }
  69. private void pbCanvas_Paint(object sender, PaintEventArgs e) {
  70. Graphics gr = e.Graphics;
  71. if (currentSector == null) return;
  72. if (tileRepository == null) return;
  73. foreach (Tilemap tilemap in currentSector.tilemaps) {
  74. if (!clTilemaps.CheckedItems.Contains(tilemap)) continue;
  75. for (int ty = 0; ty < tilemap.height; ty++) {
  76. for (int tx = 0; tx < tilemap.width; tx++) {
  77. int px = tx * 32;
  78. int py = ty * 32;
  79. if (px + 32 < e.ClipRectangle.Left) continue;
  80. if (px > e.ClipRectangle.Right) continue;
  81. if (py + 32 < e.ClipRectangle.Top) continue;
  82. if (py > e.ClipRectangle.Bottom) continue;
  83. int id = tilemap.getTileAt(tx, ty);
  84. Image tile = tileRepository.getTile(id);
  85. if (tile == null) continue;
  86. gr.DrawImageUnscaled(tile, px, py);
  87. }
  88. }
  89. if (currentTilemap == tilemap) {
  90. if (currentSelection.Width > 0) {
  91. gr.DrawRectangle(Pens.Red, new Rectangle(currentSelection.X * 32, currentSelection.Y * 32, currentSelection.Width * 32, currentSelection.Height * 32));
  92. }
  93. if (currentFloatingTilemap != null) {
  94. for (int ty = 0; ty < currentFloatingTilemap.GetLength(1); ty++) {
  95. for (int tx = 0; tx < currentFloatingTilemap.GetLength(0); tx++) {
  96. int px = (currentFloatingTilemapPos.X + tx) * 32;
  97. int py = (currentFloatingTilemapPos.Y + ty) * 32;
  98. if (px + 32 < e.ClipRectangle.Left) continue;
  99. if (px > e.ClipRectangle.Right) continue;
  100. if (py + 32 < e.ClipRectangle.Top) continue;
  101. if (py > e.ClipRectangle.Bottom) continue;
  102. int id = currentFloatingTilemap[tx, ty];
  103. Image tile = tileRepository.getTile(id);
  104. if (tile == null) continue;
  105. gr.DrawImageUnscaled(tile, px, py);
  106. }
  107. }
  108. gr.DrawRectangle(Pens.Lime, new Rectangle(currentFloatingTilemapPos.X * 32, currentFloatingTilemapPos.Y * 32, currentFloatingTilemapPos.Width * 32, currentFloatingTilemapPos.Height * 32));
  109. }
  110. }
  111. }
  112. foreach (GameObject gameObject in currentSector.gameObjects) {
  113. if (!(gameObject is SpatialGameObject)) continue;
  114. SpatialGameObject spatialGameObject = (SpatialGameObject)gameObject;
  115. int px = (int)spatialGameObject.X;
  116. int py = (int)spatialGameObject.Y;
  117. gr.DrawEllipse(Pens.Blue, new Rectangle(px - 16, py - 16, 32, 32));
  118. gr.DrawString(gameObject.DescriptiveText(), new Font(FontFamily.GenericSansSerif, 8), Brushes.Blue, px + 12, py - 18);
  119. }
  120. }
  121. private void anchorFloatingTilemap() {
  122. if (currentFloatingTilemap == null) return;
  123. for (int y = currentFloatingTilemapPos.Top; y < currentFloatingTilemapPos.Bottom; y++) {
  124. for (int x = currentFloatingTilemapPos.Left; x < currentFloatingTilemapPos.Right; x++) {
  125. currentTilemap.setTileAt(x, y, currentFloatingTilemap[x - currentFloatingTilemapPos.Left, y - currentFloatingTilemapPos.Top]);
  126. }
  127. }
  128. currentFloatingTilemap = null;
  129. pbCanvas.Invalidate();
  130. }
  131. private void createFloatingTilemapFromSelection(bool viaCut) {
  132. currentFloatingTilemap = new int[currentSelection.Width, currentSelection.Height];
  133. for (int y = currentSelection.Top; y < currentSelection.Bottom; y++) {
  134. for (int x = currentSelection.Left; x < currentSelection.Right; x++) {
  135. currentFloatingTilemap[x - currentSelection.Left, y - currentSelection.Top] = currentTilemap.getTileAt(x, y);
  136. if (viaCut) currentTilemap.setTileAt(x, y, 0);
  137. }
  138. }
  139. currentFloatingTilemapPos = currentSelection;
  140. currentSelection.Width = 0;
  141. pbCanvas.Invalidate();
  142. }
  143. private void eraseSelection() {
  144. for (int y = currentSelection.Top; y < currentSelection.Bottom; y++) {
  145. for (int x = currentSelection.Left; x < currentSelection.Right; x++) {
  146. currentTilemap.setTileAt(x, y, 0);
  147. }
  148. }
  149. }
  150. private SpatialGameObject getNearestGameObject(int x, int y, double maxDistance) {
  151. SpatialGameObject nearestObject = null;
  152. foreach (GameObject gameObject in currentSector.gameObjects) {
  153. if (!(gameObject is SpatialGameObject)) continue;
  154. SpatialGameObject spatialGameObject = (SpatialGameObject)gameObject;
  155. double dst = Math.Sqrt(Math.Pow((x - spatialGameObject.X), 2) + Math.Pow((y - spatialGameObject.Y), 2));
  156. if (dst <= maxDistance) {
  157. maxDistance = dst;
  158. nearestObject = spatialGameObject;
  159. }
  160. }
  161. return nearestObject;
  162. }
  163. private void pbCanvas_MouseDown(object sender, MouseEventArgs e) {
  164. int tx = e.X / 32;
  165. int ty = e.Y / 32;
  166. if (currentSector == null) return;
  167. if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTiles)) {
  168. currentCanvasAction = CanvasAction.drawingTiles;
  169. }
  170. if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTileManip)) {
  171. if ((currentFloatingTilemap != null) && (currentFloatingTilemapPos.Contains(tx,ty))) {
  172. currentCanvasAction = CanvasAction.movingFloatingTilemap;
  173. } else
  174. if (currentSelection.Contains(tx, ty)) {
  175. createFloatingTilemapFromSelection(true);
  176. currentCanvasAction = CanvasAction.movingFloatingTilemap;
  177. pbCanvas.Invalidate();
  178. } else {
  179. anchorFloatingTilemap();
  180. pbCanvas.Invalidate();
  181. currentCanvasAction = CanvasAction.selecting;
  182. currentSelection = new Rectangle(tx, ty, 0, 0);
  183. }
  184. }
  185. if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpObjects)) {
  186. GameObject selectedObject = (GameObject)lbGameObjects.SelectedItem;
  187. if ((selectedObject != null) && (selectedObject is SpatialGameObject)) {
  188. SpatialGameObject spatialGameObject = (SpatialGameObject)selectedObject.Clone();
  189. spatialGameObject.X = e.X;
  190. spatialGameObject.Y = e.Y;
  191. currentSector.gameObjects.Add(spatialGameObject);
  192. pbCanvas.Invalidate();
  193. }
  194. }
  195. if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpGameObjectManip)) {
  196. currentGameObject = getNearestGameObject(e.X, e.Y, 32);
  197. if (currentGameObject != null) {
  198. currentCanvasAction = CanvasAction.movingObject;
  199. pbCanvas.Invalidate();
  200. }
  201. }
  202. if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpBrushes)) {
  203. currentCanvasAction = CanvasAction.drawingBrush;
  204. }
  205. canvasActionStart.X = e.X;
  206. canvasActionStart.Y = e.Y;
  207. pbCanvas_MouseMove(sender, e);
  208. }
  209. private void pbCanvas_MouseMove(object sender, MouseEventArgs e) {
  210. if (currentTilemap == null) return;
  211. if (!clTilemaps.CheckedItems.Contains(currentTilemap)) return;
  212. int tx = e.X / 32;
  213. int ty = e.Y / 32;
  214. slCoordinates.Text = tx + "," + ty;
  215. slTileId.Text = currentTilemap.getTileAt(tx, ty).ToString();
  216. if (currentCanvasAction == CanvasAction.drawingTiles) {
  217. if (ModifierKeys == Keys.Shift) {
  218. currentTilemap.setTileAt(tx, ty, 0);
  219. } else {
  220. currentTilemap.setTileAt(tx, ty, currentTileId);
  221. }
  222. pbCanvas.Invalidate(new Rectangle(tx * 32, ty * 32, 32, 32));
  223. }
  224. if (currentCanvasAction == CanvasAction.selecting) {
  225. currentSelection.Width = tx - currentSelection.X + 1;
  226. currentSelection.Height = ty - currentSelection.Y + 1;
  227. pbCanvas.Invalidate();
  228. }
  229. if (currentCanvasAction == CanvasAction.movingFloatingTilemap) {
  230. int dx = tx - (canvasActionStart.X / 32);
  231. int dy = ty - (canvasActionStart.Y / 32);
  232. currentFloatingTilemapPos.Offset(dx, dy);
  233. canvasActionStart.X = e.X;
  234. canvasActionStart.Y = e.Y;
  235. pbCanvas.Invalidate();
  236. }
  237. if (currentCanvasAction == CanvasAction.movingObject) {
  238. if (ModifierKeys == Keys.Shift) {
  239. currentSector.gameObjects.Remove(currentGameObject);
  240. pbCanvas.Invalidate();
  241. currentCanvasAction = CanvasAction.none;
  242. } else {
  243. int dx = e.X - canvasActionStart.X;
  244. int dy = e.Y - canvasActionStart.Y;
  245. currentGameObject.X += dx;
  246. currentGameObject.Y += dy;
  247. canvasActionStart.X = e.X;
  248. canvasActionStart.Y = e.Y;
  249. pbCanvas.Invalidate();
  250. }
  251. }
  252. if (currentCanvasAction == CanvasAction.drawingBrush) {
  253. if (ModifierKeys == Keys.Shift) {
  254. if (currentBrush != null) currentBrush.erase(currentTilemap, tx, ty);
  255. } else if (ModifierKeys == Keys.Control) {
  256. if (currentBrush != null) {
  257. currentBrush.learn(currentTilemap, tx, ty);
  258. laBrushSize.Text = currentBrush.Length + " Patterns";
  259. }
  260. } else if (ModifierKeys == (Keys.Control | Keys.Shift)) {
  261. if (currentBrush != null) {
  262. currentBrush.forget(currentTilemap, tx, ty);
  263. laBrushSize.Text = currentBrush.Length + " Patterns";
  264. }
  265. } else {
  266. if (currentBrush != null) currentBrush.draw(currentTilemap, tx, ty);
  267. }
  268. pbCanvas.Invalidate(new Rectangle((tx - 1) * 32, (ty - 1) * 32, 32 * 3, 32 * 3));
  269. }
  270. }
  271. private void pbCanvas_MouseUp(object sender, MouseEventArgs e) {
  272. currentCanvasAction = CanvasAction.none;
  273. }
  274. private void cbTilegroup_SelectedIndexChanged(object sender, EventArgs e) {
  275. currentTilegroup = (TileGroup)cbTilegroup.SelectedItem;
  276. pbTiles.Invalidate();
  277. }
  278. private void pbTiles_Paint(object sender, PaintEventArgs e) {
  279. if (currentTilegroup == null) return;
  280. //int tilesPerRow = (pnTilesContainer.ClientSize.Width / 32);
  281. int tilesPerRow = ((pnTilesContainer.Width - 16) / 32); //FIXME: hack, can we get scrollbar width?
  282. if (tilesPerRow < 1) tilesPerRow = 1;
  283. pbTiles.Width = tilesPerRow * 32;
  284. pbTiles.Height = (int)Math.Ceiling((float)currentTilegroup.Tiles.Count / (float)tilesPerRow) * 32;
  285. Graphics gr = e.Graphics;
  286. int tx = 0;
  287. int ty = 0;
  288. int currentTilePx = -1;
  289. int currentTilePy = -1;
  290. foreach (int id in currentTilegroup.Tiles) {
  291. int px = tx * 32;
  292. int py = ty * 32;
  293. if (currentTileId == id) {
  294. currentTilePx = px;
  295. currentTilePy = py;
  296. }
  297. Image tile = tileRepository.getTile(id);
  298. if (tile == null) continue;
  299. gr.DrawImageUnscaled(pbTileBackground.Image, px, py);
  300. gr.DrawImageUnscaled(tile, px, py);
  301. tx += 1; if (tx >= tilesPerRow) { tx = 0; ty += 1; }
  302. }
  303. if ((currentTilePx >= 0) && (currentTilePy >= 0)) {
  304. gr.DrawRectangle(Pens.Red, currentTilePx-1, currentTilePy-1, 33, 33);
  305. }
  306. }
  307. private void pbTiles_MouseClick(object sender, MouseEventArgs e) {
  308. if (e.Button != MouseButtons.Left) return;
  309. if (currentTilegroup == null) return;
  310. int tilesPerRow = (pnTilesContainer.Width / 32);
  311. if (tilesPerRow < 1) tilesPerRow = 1;
  312. pbTiles.Width = tilesPerRow * 32;
  313. pbTiles.Height = (int)Math.Ceiling((float)currentTilegroup.Tiles.Count / (float)tilesPerRow) * 32;
  314. int tx = 0;
  315. int ty = 0;
  316. foreach (int id in currentTilegroup.Tiles) {
  317. int px = tx * 32;
  318. int py = ty * 32;
  319. Image tile = tileRepository.getTile(id);
  320. if (tile == null) continue;
  321. if ((e.X >= px) && (e.X < px + 32) && (e.Y >= py) && (e.Y <= py + 32)) {
  322. currentTileId = id;
  323. }
  324. tx += 1; if (tx >= tilesPerRow) { tx = 0; ty += 1; }
  325. }
  326. pbTiles.Invalidate();
  327. }
  328. private void newLevel() {
  329. level = new Level();
  330. currentLevelFilename = null;
  331. onLevelChanged();
  332. }
  333. private void loadLevel(string filename) {
  334. if (!File.Exists(filename)) throw new ArgumentException("Level file not found");
  335. level = new Level(filename);
  336. currentLevelFilename = filename;
  337. onLevelChanged();
  338. }
  339. private void saveLevel(string filename) {
  340. if (level == null) return;
  341. level.Write(filename);
  342. }
  343. private void onLevelChanged() {
  344. sectorToolStripMenuItem.Enabled = true;
  345. propertiesToolStripMenuItem.Enabled = true;
  346. saveToolStripMenuItem.Enabled = true;
  347. saveasToolStripMenuItem.Enabled = true;
  348. cbSector.Items.Clear();
  349. foreach (Sector sector in level.sectors) {
  350. cbSector.Items.Add(sector);
  351. }
  352. if (cbSector.Items.Count >= 1) cbSector.SelectedIndex = 0;
  353. }
  354. private void clTilemaps_ItemCheck(object sender, ItemCheckEventArgs e) {
  355. pbCanvas.Invalidate();
  356. }
  357. private void clTilemaps_SelectedIndexChanged(object sender, EventArgs e) {
  358. currentTilemap = (Tilemap)clTilemaps.SelectedItem;
  359. pbCanvas.Invalidate();
  360. }
  361. private void cbSector_SelectedIndexChanged(object sender, EventArgs e) {
  362. currentSector = (Sector)cbSector.SelectedItem;
  363. if (currentSector == null) return;
  364. clTilemaps.Items.Clear();
  365. int maxWidth = 1;
  366. int maxHeight = 1;
  367. foreach (Tilemap tilemap in currentSector.tilemaps) {
  368. clTilemaps.Items.Add(tilemap, true);
  369. maxWidth = Math.Max(maxWidth, tilemap.width);
  370. maxHeight = Math.Max(maxHeight, tilemap.height);
  371. }
  372. pbCanvas.Width = maxWidth * 32;
  373. pbCanvas.Height = maxHeight * 32;
  374. if (clTilemaps.Items.Count >= 2) clTilemaps.SelectedIndex = 1;
  375. pbCanvas.Invalidate();
  376. }
  377. private void loadToolStripMenuItem_Click(object sender, EventArgs e) {
  378. dgOpenLevel.InitialDirectory = "data\\levels\\";
  379. if (dgOpenLevel.ShowDialog() == DialogResult.OK) {
  380. loadLevel(dgOpenLevel.FileName);
  381. }
  382. }
  383. private void newToolStripMenuItem_Click(object sender, EventArgs e) {
  384. newLevel();
  385. }
  386. private void saveasToolStripMenuItem_Click(object sender, EventArgs e) {
  387. dgSaveLevel.InitialDirectory = "data\\levels\\";
  388. if (dgSaveLevel.ShowDialog() == DialogResult.OK) {
  389. saveLevel(dgSaveLevel.FileName);
  390. }
  391. }
  392. private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
  393. if (currentLevelFilename == null) {
  394. saveasToolStripMenuItem_Click(sender, e);
  395. } else {
  396. saveLevel(currentLevelFilename);
  397. }
  398. }
  399. private void propertiesToolStripMenuItem_Click(object sender, EventArgs e) {
  400. LevelPropertiesForm form = new LevelPropertiesForm(level);
  401. form.ShowDialog();
  402. }
  403. private void tcToolSettings_SelectedIndexChanged(object sender, EventArgs e) {
  404. anchorFloatingTilemap();
  405. currentSelection.Width = 0;
  406. pbCanvas.Invalidate();
  407. updateToolButtons();
  408. }
  409. private void btnDuplicateSelection_Click(object sender, EventArgs e) {
  410. anchorFloatingTilemap();
  411. createFloatingTilemapFromSelection(false);
  412. }
  413. private void resizeTilemapsToolStripMenuItem_Click(object sender, EventArgs e) {
  414. if (currentSector == null) return;
  415. int currentSizeX = 0;
  416. int currentSizeY = 0;
  417. foreach (Tilemap tilemap in currentSector.tilemaps) {
  418. if (tilemap.width > currentSizeX) currentSizeX = tilemap.width;
  419. if (tilemap.height > currentSizeY) currentSizeY = tilemap.height;
  420. }
  421. SectorResizeDialog srd = new SectorResizeDialog(currentSizeX, currentSizeY);
  422. if (srd.ShowDialog() == DialogResult.OK) {
  423. foreach (Tilemap tilemap in currentSector.tilemaps) {
  424. tilemap.OffsetBy(srd.OffsetX, srd.OffsetY);
  425. tilemap.ResizeTo(srd.SectorWidth, srd.SectorHeight);
  426. }
  427. foreach (GameObject go in currentSector.gameObjects) {
  428. if (!(go is SpatialGameObject)) continue;
  429. SpatialGameObject sgo = (SpatialGameObject)go;
  430. sgo.X += 32*srd.OffsetX;
  431. sgo.Y += 32*srd.OffsetY;
  432. }
  433. cbSector_SelectedIndexChanged(sender, e);
  434. }
  435. }
  436. private void updateToolButtons() {
  437. btnModeTileAdd.Checked = (tcToolSettings.SelectedTab == tpTiles);
  438. btnModeTileMove.Checked = (tcToolSettings.SelectedTab == tpTileManip);
  439. btnModeObjAdd.Checked = (tcToolSettings.SelectedTab == tpObjects);
  440. btnModeObjMove.Checked = (tcToolSettings.SelectedTab == tpGameObjectManip);
  441. btnModeBrushes.Checked = (tcToolSettings.SelectedTab == tpBrushes);
  442. }
  443. private void btnModeTileAdd_Click(object sender, EventArgs e) {
  444. tcToolSettings.SelectedTab = tpTiles;
  445. updateToolButtons();
  446. slQuickHelp.Text = "LMB adds selected tile, Shift+LMB removes tiles";
  447. }
  448. private void btnModeTileMove_Click(object sender, EventArgs e) {
  449. tcToolSettings.SelectedTab = tpTileManip;
  450. updateToolButtons();
  451. slQuickHelp.Text = "LMB-drag to select and move tiles";
  452. }
  453. private void btnModeObjAdd_Click(object sender, EventArgs e) {
  454. tcToolSettings.SelectedTab = tpObjects;
  455. updateToolButtons();
  456. slQuickHelp.Text = "LMB adds selected object";
  457. }
  458. private void btnModeObjMove_Click(object sender, EventArgs e) {
  459. tcToolSettings.SelectedTab = tpGameObjectManip;
  460. updateToolButtons();
  461. slQuickHelp.Text = "LMB-drag to move objects, Shift+LMB to delete objects";
  462. }
  463. private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
  464. AboutDialog abd = new AboutDialog();
  465. abd.ShowDialog();
  466. }
  467. private void btnModeBrushes_Click(object sender, EventArgs e) {
  468. tcToolSettings.SelectedTab = tpBrushes;
  469. updateToolButtons();
  470. slQuickHelp.Text = "LMB to draw with loaded brush, Shift+LMB to delete tiles, Ctrl+LMB to learn pattern, Ctrl+Shift+LMB to forget pattern";
  471. }
  472. private void btnLoadBrush_Click(object sender, EventArgs e) {
  473. if (dgOpenBrush.ShowDialog() == DialogResult.OK) {
  474. currentBrush = Brush.loadFromFile(tileRepository, dgOpenBrush.FileName);
  475. laBrushSize.Text = currentBrush.Length + " Patterns";
  476. }
  477. }
  478. private void btnSaveBrush_Click(object sender, EventArgs e) {
  479. if (currentBrush == null) return;
  480. if (dgSaveBrush.ShowDialog() == DialogResult.OK) {
  481. currentBrush.saveToFile(dgSaveBrush.FileName);
  482. laBrushSize.Text = currentBrush.Length + " Patterns";
  483. }
  484. }
  485. private void btnNewBrush_Click(object sender, EventArgs e) {
  486. currentBrush = new Brush(tileRepository);
  487. laBrushSize.Text = currentBrush.Length + " Patterns";
  488. }
  489. private void btnBrushLearnTM_Click(object sender, EventArgs e) {
  490. if (currentBrush == null) return;
  491. if (currentTilemap == null) return;
  492. currentBrush.learn(currentTilemap);
  493. laBrushSize.Text = currentBrush.Length + " Patterns";
  494. }
  495. private void searchAndReplaceTilesToolStripMenuItem_Click(object sender, EventArgs e) {
  496. if (currentSector == null) return;
  497. int oldId;
  498. try {
  499. oldId = int.Parse(slTileId.Text);
  500. }
  501. catch(Exception) {
  502. oldId = 0;
  503. }
  504. int newId = currentTileId;
  505. TileSearchDialog tsd = new TileSearchDialog(oldId, newId);
  506. if (tsd.ShowDialog() == DialogResult.OK) {
  507. foreach (Tilemap tilemap in currentSector.tilemaps) {
  508. tilemap.Replace(tsd.OldId, tsd.NewId);
  509. }
  510. cbSector_SelectedIndexChanged(sender, e);
  511. }
  512. }
  513. }
  514. }