PageRenderTime 62ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/WorldView/FormWorldView.cs

#
C# | 1998 lines | 1533 code | 397 blank | 68 comment | 278 complexity | 912b23247c741bd790ccebee9cc73e18 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Windows.Forms;
  7. using System.Windows.Forms.VisualStyles;
  8. using System.IO;
  9. using System.Timers;
  10. using MoreTerra.Properties;
  11. using MoreTerra.Structures;
  12. using MoreTerra.Utilities;
  13. using MoreTerra.Structures.TerraInfo;
  14. namespace MoreTerra
  15. {
  16. public partial class FormWorldView : Form
  17. {
  18. private delegate void PopulateWorldTreeDelegate();
  19. private delegate void PopulateChestTreeDelegate(TreeNode[] node_array);
  20. private delegate DialogResult MessageBoxShowDelegate(String text);
  21. private delegate DialogResult MessageBoxShowFullDelegate(String text, String caption,
  22. MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);
  23. private delegate DialogResult MessageBoxWithCheckBoxShowDelegate(FormMessageBoxWithCheckBox box);
  24. #region Variable definitions
  25. private WorldMapper mapper = null;
  26. private BackgroundWorker mapperWorker = null;
  27. private System.Timers.Timer tmrMapperProgress;
  28. // Used to store the images for our TreeView marker list.
  29. private ImageList markerImageList;
  30. private ImageList markerThreeStateList;
  31. private ImageList chestImageList;
  32. private ImageList colorImageList;
  33. private ImageList buttonImageList;
  34. private string worldPath = string.Empty;
  35. // Used to store the real names of each .WLD file in the chosen directory.
  36. private Dictionary<String, String> worldNames = new Dictionary<String, String>();
  37. // This stores the nodes for easy lookup. Only the subnodes are stored.
  38. private Dictionary<String, TreeNode> markerNodes;
  39. // We use this to see if something new got added to the item list when we are done
  40. // drawing/loading information.
  41. private Int32 filterCount;
  42. // We'll use this to refilter the list on the World Information page if we've
  43. // changed what's in the filter since we switched tabs.
  44. private Boolean filterUpdated;
  45. // This is used to hold the data for the color TreeView item.
  46. private ColorListData colorData;
  47. private FormProgressDialog progForm;
  48. #endregion
  49. public FormWorldView()
  50. {
  51. FormWorldView.Form = this;
  52. InitializeComponent();
  53. RegisterEventHandlers();
  54. this.Icon = Properties.Resources.Cannon;
  55. }
  56. // Done here instead of by the automatic code generator as I'm tired of the code
  57. // Generator removing my event handlers when I try to move items around.
  58. private void RegisterEventHandlers()
  59. {
  60. #region Global Handlers
  61. this.Load += new System.EventHandler(this.WorldViewForm_Load);
  62. // Select World groupbox
  63. this.comboBoxWorldFilePath.SelectedIndexChanged += new System.EventHandler(this.comboBoxWorldFilePath_TextChanged);
  64. this.comboBoxWorldFilePath.TextChanged += new System.EventHandler(this.comboBoxWorldFilePath_TextChanged);
  65. this.buttonBrowseWorld.Click += new System.EventHandler(this.buttonBrowseWorld_Click);
  66. // Settings groupbox
  67. this.comboBoxSettings.SelectedIndexChanged += new System.EventHandler(this.comboBoxSettings_SelectedIndexChanged);
  68. this.buttonSettingsAddNew.Click += new System.EventHandler(this.buttonSettingsAddNew_Click);
  69. this.buttonSettingsDelete.Click += new System.EventHandler(this.buttonSettingsDelete_Click);
  70. // Tab Control
  71. this.tabControlSettings.SelectedIndexChanged += new System.EventHandler(this.tabControlSettings_SelectedIndexChanged);
  72. #endregion
  73. #region Draw World tabPage Handlers
  74. // Output Image groupbox
  75. this.buttonBrowseOutput.Click += new System.EventHandler(this.buttonBrowseOutput_Click);
  76. this.checkBoxOfficialColors.CheckedChanged += new System.EventHandler(this.checkBoxOfficialColors_CheckedChanged);
  77. this.checkBoxDrawWires.CheckedChanged += new System.EventHandler(this.checkBoxDrawWires_CheckedChanged);
  78. this.checkBoxDrawWalls.CheckedChanged += new System.EventHandler(this.checkBoxDrawWalls_CheckedChanged);
  79. this.checkBoxOpenImage.CheckedChanged += new System.EventHandler(this.checkBoxOpenImage_CheckedChanged);
  80. this.comboBoxCropImage.SelectedIndexChanged += new System.EventHandler(this.comboBoxCropImage_SelectedIndexChanged);
  81. this.buttonDrawWorld.Click += new System.EventHandler(this.buttonDrawWorld_Click);
  82. // Unsupported World Version groupbox
  83. #endregion
  84. #region Markers tabPage Handlers
  85. this.checkBoxShowChestTypes.CheckedChanged += new System.EventHandler(this.checkBoxShowChestTypes_CheckedChanged);
  86. this.treeViewMarkerList.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewMarkerList_AfterCheck);
  87. this.treeViewMarkerList.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeViewMarkerList_NodeMouseClick);
  88. this.treeViewMarkerList.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.treeViewMarkerList_KeyPress);
  89. // Use Custom Images groupbox
  90. this.checkBoxCustomMarkers.CheckedChanged += new System.EventHandler(this.checkBoxCustomMarkers_CheckedChanged);
  91. this.buttonResetCustomImages.Click += new System.EventHandler(this.buttonResetCustomImages_Click);
  92. this.buttonCustomResources.Click += new System.EventHandler(this.buttonCustomResources_Click);
  93. // ContextMenu for treeViewmarkerList
  94. this.selectAllToolStripMenuItem.Click += new System.EventHandler(this.selectAllToolStripMenuItem_Click);
  95. this.selectNoneToolStripMenuItem.Click += new System.EventHandler(this.selectNoneToolStripMenuItem_Click);
  96. this.invertSelectionToolStripMenuItem.Click += new System.EventHandler(this.invertSelectionToolStripMenuItem_Click);
  97. #endregion
  98. #region Colors tabPage Handlers
  99. this.treeViewColorList.AfterSelect += new TreeViewEventHandler(treeViewColorList_AfterSelect);
  100. this.radioButtonColorDefault.CheckedChanged += new EventHandler(radioButtonColorDefault_CheckedChanged);
  101. this.radioButtonColorPreset.CheckedChanged += new EventHandler(radioButtonColorName_CheckedChanged);
  102. this.radioButtonColorColor.CheckedChanged += new EventHandler(radioButtonColorColor_CheckedChanged);
  103. this.textBoxColorColor.TextChanged += new EventHandler(textBoxColorColor_TextChanged);
  104. this.comboBoxColorName.SelectedIndexChanged += new EventHandler(comboBoxColorName_SelectedIndexChanged);
  105. this.buttonColorColor.Click += buttonColorColor_Click;
  106. #endregion
  107. #region Chest Finder tabPage Handlers
  108. this.checkBoxFilterChests.CheckedChanged += new System.EventHandler(this.checkBoxFilterChests_CheckedChanged);
  109. this.checkBoxShowChestItems.CheckedChanged +=new EventHandler(checkBoxShowChestItems_CheckedChanged);
  110. this.checkBoxShowNormalItems.CheckedChanged +=new EventHandler(checkBoxShowNormalItems_CheckedChanged);
  111. this.lstAvailableItems.DoubleClick += new System.EventHandler(this.lstAvailableItems_DoubleClick);
  112. this.buttonMoveAllToFiltered.Click += new System.EventHandler(this.buttonMoveAllToFiltered_Click);
  113. this.lstFilteredItems.DoubleClick += new System.EventHandler(this.lstFilteredItems_DoubleClick);
  114. this.lstFilteredItems.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lstFilteredItems_KeyDown);
  115. this.buttonMoveAllToAvailable.Click += new System.EventHandler(this.buttonMoveAllToAvailable_Click);
  116. #endregion
  117. #region World Information tabPage Handlers
  118. this.buttonLoadInformation.Click += new System.EventHandler(this.buttonLoadInformation_Click);
  119. // Sort By groupBox
  120. this.radioButtonSortByNone.CheckedChanged += new System.EventHandler(this.radioButtonSortByNone_CheckedChanged);
  121. this.radioButtonSortByX.CheckedChanged += new System.EventHandler(this.radioButtonSortByX_CheckedChanged);
  122. this.radioButtonSortByY.CheckedChanged += new System.EventHandler(this.radioButtonSortByY_CheckedChanged);
  123. // ContextMenu for Chest list
  124. this.saveToTextToolStripMenuItem.Click += new System.EventHandler(this.saveToTextToolStripMenuItem_Click);
  125. this.saveToCSVToolStripMenuItem.Click += new System.EventHandler(this.saveToCSVToolStripMenuItem_Click);
  126. this.saveToXMLToolStripMenuItem.Click += new System.EventHandler(this.saveToXMLtToolStripMenuItem_Click);
  127. #endregion
  128. #region About tabPage Handlers
  129. this.linkLabelHomepage.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabelHomepage_LinkClicked);
  130. #endregion
  131. }
  132. void buttonColorColor_Click(object sender, EventArgs e)
  133. {
  134. if (colorDialog.ShowDialog() == DialogResult.OK)
  135. {
  136. var rgb = new byte[]{colorDialog.Color.R,colorDialog.Color.G, colorDialog.Color.B};
  137. textBoxColorColor.Text = string.Format("#{0}", BitConverter.ToString(rgb).Replace("-", string.Empty));
  138. }
  139. }
  140. private void WorldViewForm_Load(object sender, EventArgs e)
  141. {
  142. Int32 i;
  143. for (i = 0; i < SettingsManager.Instance.SettingsCount; i++)
  144. {
  145. comboBoxSettings.Items.Add(SettingsManager.Instance.SettingsName(i));
  146. }
  147. if (SettingsManager.Instance.SettingsName(SettingsManager.Instance.CurrentSettings) == "Default")
  148. buttonSettingsDelete.Enabled = false;
  149. else
  150. buttonSettingsDelete.Enabled = true;
  151. comboBoxSettings.SelectedIndex = SettingsManager.Instance.CurrentSettings;
  152. labelSpecialThanks.Text = Global.Credits;
  153. lblVersion.Text = "Version: " + GetVersion();
  154. tmrMapperProgress = new System.Timers.Timer();
  155. tmrMapperProgress.Elapsed += new ElapsedEventHandler(tmrMapperProgress_Tick);
  156. tmrMapperProgress.Enabled = false;
  157. tmrMapperProgress.Interval = 333;
  158. // If we've updated the software push it into the settings file.
  159. if (SettingsManager.Instance.TopVersion < Global.CurrentVersion)
  160. SettingsManager.Instance.TopVersion = Global.CurrentVersion;
  161. // These two lines are outside of SetupMainForm as they get called by event
  162. // handlers in there, but the handlers do not fire until the everything is fully
  163. // loaded. So to keep them from getting double called they are here.
  164. ResourceManager.Instance.Custom = SettingsManager.Instance.CustomMarkers;
  165. SetupColorNames();
  166. SetupColorData();
  167. SetupImageLists();
  168. SetupColorButtons();
  169. SetupMainForm();
  170. }
  171. // This is everything that needs to get reset if the current settings have changed.
  172. private void SetupMainForm()
  173. {
  174. // These event handlers do nothing except ironically set SettingsManager back.
  175. checkBoxOfficialColors.Checked = SettingsManager.Instance.OfficialColors;
  176. checkBoxDrawWires.Checked = SettingsManager.Instance.DrawWires;
  177. checkBoxDrawWalls.Checked = SettingsManager.Instance.DrawWalls;
  178. checkBoxOpenImage.Checked = SettingsManager.Instance.OpenImage;
  179. checkBoxShowChestTypes.Checked = SettingsManager.Instance.ShowChestTypes;
  180. checkBoxFilterChests.Checked = SettingsManager.Instance.FilterChests;
  181. checkBoxShowChestItems.Checked = SettingsManager.Instance.ShowChestItems;
  182. checkBoxShowNormalItems.Checked = SettingsManager.Instance.ShowNormalItems;
  183. comboBoxCropImage.SelectedIndex = SettingsManager.Instance.CropImageUsing;
  184. // This event handler sets both ResourceManager.Custom but also calls
  185. // SetupImageLists. SetupImageLists always needs to be called before
  186. // SetupMarkerList.
  187. checkBoxCustomMarkers.Checked = SettingsManager.Instance.CustomMarkers;
  188. string folder = string.Empty;
  189. if (Directory.Exists(SettingsManager.Instance.InputWorldDirectory))
  190. {
  191. folder = SettingsManager.Instance.InputWorldDirectory;
  192. }
  193. else if (Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games\\Terraria")))
  194. {
  195. folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games\\Terraria");
  196. SettingsManager.Instance.InputWorldDirectory = folder;
  197. }
  198. if (folder != string.Empty)
  199. this.worldDirectoryChanged();
  200. // SetupImageLists does all boxes so it needs to come before
  201. // the Marker list and the Chest list.
  202. SetupMarkerListBox();
  203. SetupColorListBox();
  204. if (SettingsManager.Instance.FilterItemStates != null)
  205. ResetFilterLists();
  206. switch (SettingsManager.Instance.SortChestsBy)
  207. {
  208. case 1:
  209. radioButtonSortByX.Checked = true;
  210. break;
  211. case 2:
  212. radioButtonSortByY.Checked = true;
  213. break;
  214. default:
  215. radioButtonSortByNone.Checked = true;
  216. break;
  217. }
  218. }
  219. #region SelectWorld groupBox functions
  220. private void buttonBrowseWorld_Click(object sender, EventArgs e)
  221. {
  222. OpenFileDialog dialog = new OpenFileDialog();
  223. dialog.Filter = "Terraria World (*.wld)|*.wld|Terraria Backup World (*.wld.bak)|*.wld.bak";
  224. dialog.Title = "Select World File";
  225. dialog.InitialDirectory = SettingsManager.Instance.InputWorldDirectory;
  226. string filePath = (dialog.ShowDialog() == DialogResult.OK) ? dialog.FileName : string.Empty;
  227. if (filePath == string.Empty) return;
  228. comboBoxWorldFilePath.Text = filePath;
  229. if (!(SettingsManager.Instance.InputWorldDirectory == Path.GetDirectoryName(filePath)))
  230. {
  231. SettingsManager.Instance.InputWorldDirectory = Path.GetDirectoryName(filePath);
  232. worldDirectoryChanged(filePath);
  233. }
  234. }
  235. private void comboBoxWorldFilePath_TextChanged(object sender, EventArgs e)
  236. {
  237. worldPath = comboBoxWorldFilePath.Text;
  238. if (File.Exists(comboBoxWorldFilePath.Text) && Directory.Exists(SettingsManager.Instance.OutputPreviewDirectory))
  239. {
  240. textBoxOutputFile.Text = Path.Combine(SettingsManager.Instance.OutputPreviewDirectory, Path.GetFileNameWithoutExtension(comboBoxWorldFilePath.Text) + ".png");
  241. }
  242. if (worldNames.ContainsKey(worldPath) == true)
  243. {
  244. labelWorldName.Text = "World Name: " + worldNames[worldPath];
  245. }
  246. else
  247. {
  248. labelWorldName.Text = "World Name: ";
  249. }
  250. }
  251. private void worldDirectoryChanged(String selectedFile = null)
  252. {
  253. worldNames.Clear();
  254. Int32 i = 0;
  255. Int32 selection = 0;
  256. World w;
  257. comboBoxWorldFilePath.Items.Clear();
  258. w = new World();
  259. foreach (String file in Directory.GetFiles(SettingsManager.Instance.InputWorldDirectory, "*.wld"))
  260. {
  261. worldNames.Add(file, w.GetWorldName(file));
  262. comboBoxWorldFilePath.Items.Add(file);
  263. if (String.IsNullOrEmpty(selectedFile) != true && file == selectedFile)
  264. {
  265. selection = i;
  266. }
  267. i++;
  268. }
  269. if (comboBoxWorldFilePath.Items.Count > 0)
  270. comboBoxWorldFilePath.SelectedIndex = selection;
  271. }
  272. #endregion
  273. #region Settings groupBox functions
  274. private void buttonSettingsAddNew_Click(object sender, EventArgs e)
  275. {
  276. Boolean mainLoop = true;
  277. DialogResult result;
  278. FormEntryBox nameEntryBox = new FormEntryBox();
  279. nameEntryBox.FormText = "Add New Settings Preset";
  280. nameEntryBox.LabelText = "Enter the a name for a new settings preset:";
  281. while (mainLoop == true)
  282. {
  283. result = nameEntryBox.ShowDialog(this);
  284. if (result == DialogResult.Cancel)
  285. return;
  286. else
  287. {
  288. if (!SettingsManager.Instance.AddNewSettings(nameEntryBox.EntryItem))
  289. {
  290. MessageBox.Show(String.Format("Preset {0} already exists.", nameEntryBox.EntryItem),
  291. "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
  292. }
  293. else
  294. {
  295. mainLoop = false;
  296. }
  297. }
  298. }
  299. comboBoxSettings.Items.Add(nameEntryBox.EntryItem);
  300. }
  301. private void buttonSettingsDelete_Click(object sender, EventArgs e)
  302. {
  303. Int32 toDelete = comboBoxSettings.SelectedIndex;
  304. String deleteName = SettingsManager.Instance.SettingsName(toDelete);
  305. if ((deleteName == "Default") || (deleteName == String.Empty))
  306. return;
  307. SettingsManager.Instance.DeleteSettings(toDelete);
  308. comboBoxSettings.Items.RemoveAt(toDelete);
  309. if (toDelete >= comboBoxSettings.Items.Count)
  310. toDelete = comboBoxSettings.Items.Count - 1;
  311. comboBoxSettings.SelectedIndex = toDelete;
  312. }
  313. private void comboBoxSettings_SelectedIndexChanged(object sender, EventArgs e)
  314. {
  315. Int32 index = comboBoxSettings.SelectedIndex;
  316. if ((index == SettingsManager.Instance.CurrentSettings) || (index < 0))
  317. return;
  318. if (SettingsManager.Instance.SettingsName(index) == "Default")
  319. buttonSettingsDelete.Enabled = false;
  320. else
  321. buttonSettingsDelete.Enabled = true;
  322. SettingsManager.Instance.CurrentSettings = comboBoxSettings.SelectedIndex;
  323. SetupMainForm();
  324. }
  325. #endregion
  326. #region Draw World tabPage functions
  327. private void checkBoxOfficialColors_CheckedChanged(object sender, EventArgs e)
  328. {
  329. SettingsManager.Instance.OfficialColors = checkBoxOfficialColors.Checked;
  330. }
  331. private void checkBoxDrawWires_CheckedChanged(object sender, EventArgs e)
  332. {
  333. SettingsManager.Instance.DrawWires = checkBoxDrawWires.Checked;
  334. }
  335. private void checkBoxDrawWalls_CheckedChanged(object sender, EventArgs e)
  336. {
  337. SettingsManager.Instance.DrawWalls = checkBoxDrawWalls.Checked;
  338. }
  339. private void checkBoxOpenImage_CheckedChanged(object sender, EventArgs e)
  340. {
  341. SettingsManager.Instance.OpenImage = checkBoxOpenImage.Checked;
  342. }
  343. private void buttonBrowseOutput_Click(object sender, EventArgs e)
  344. {
  345. SaveFileDialog dialog = new SaveFileDialog();
  346. dialog.Filter = "PNG (*.png)|*.png";
  347. dialog.Title = "Select World File";
  348. dialog.InitialDirectory = SettingsManager.Instance.OutputPreviewDirectory;
  349. if (comboBoxWorldFilePath.Text != string.Empty)
  350. {
  351. dialog.FileName = string.Format("{0}.png", System.IO.Path.GetFileNameWithoutExtension(comboBoxWorldFilePath.Text));
  352. }
  353. if (dialog.ShowDialog() != DialogResult.OK) return;
  354. SettingsManager.Instance.OutputPreviewDirectory = Path.GetDirectoryName(dialog.FileName);
  355. textBoxOutputFile.Text = dialog.FileName;
  356. }
  357. private void buttonDrawWorld_Click(object sender, EventArgs e)
  358. {
  359. if (SettingsManager.Instance.FilterChests && !SettingsManager.Instance.DrawMarker("Chest"))
  360. {
  361. DialogResult markers = MessageBox.Show("You have enabled Chest Filtering but have disabled drawing Chest Markers. " +
  362. "No Chests will show up, even if they contain the items you are looking for.\r\n\r\n" +
  363. "Would you like to enable Markers for Chests before continuing?", "Chest Markers disabled",
  364. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
  365. if (markers == System.Windows.Forms.DialogResult.Yes)
  366. {
  367. SettingsManager.Instance.MarkerVisible("Chest", true);
  368. markerNodes["Chest"].Checked = true;
  369. treeViewMarkerList_updateParentNode(markerNodes["Chest"]);
  370. }
  371. else if (markers == System.Windows.Forms.DialogResult.Cancel)
  372. {
  373. return;
  374. }
  375. }
  376. if (SettingsManager.Instance.FilterChests && lstFilteredItems.Items.Count == 0)
  377. {
  378. DialogResult markers = MessageBox.Show("You have enabled Chest Filtering but have not selected any items. " +
  379. "No Chests will show up, even if they are empty.\r\n\r\n" +
  380. "Would you like to disable Chest Filtering before continuing?", "Chest Finder list is empty",
  381. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
  382. if (markers == System.Windows.Forms.DialogResult.Yes)
  383. {
  384. SettingsManager.Instance.FilterChests = false;
  385. checkBoxFilterChests.Checked = false;
  386. }
  387. else if (markers == System.Windows.Forms.DialogResult.Cancel)
  388. {
  389. return;
  390. }
  391. }
  392. if (checkValidPaths(true))
  393. {
  394. if (SettingsManager.Instance.ShowChestTypes)
  395. treeViewChestInformation.ImageList = chestImageList;
  396. buttonDrawWorld.Enabled = false;
  397. filterCount = SettingsManager.Instance.FilterItemStates.Count();
  398. groupBoxSelectWorld.Enabled = false;
  399. groupBoxImageOutput.Enabled = false;
  400. (this.tabPageMarkers as Control).Enabled = false;
  401. (this.tabPageWorldInformation as Control).Enabled = false;
  402. Point pt = this.Location;
  403. pt.X += (this.Size.Width / 2);
  404. pt.Y += (this.Size.Height / 2);
  405. mapper = new WorldMapper();
  406. mapper.Initialize();
  407. if (textBoxOutputFile.Text.Substring(textBoxOutputFile.Text.Length - 4).CompareTo(".png") != 0)
  408. {
  409. textBoxOutputFile.Text += ".png";
  410. }
  411. mapperWorker = new BackgroundWorker();
  412. progForm = new FormProgressDialog("Draw World", false, mapperWorker);
  413. mapperWorker.WorkerReportsProgress = true;
  414. mapperWorker.WorkerSupportsCancellation = true;
  415. mapperWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(progForm.worker_Completed);
  416. mapperWorker.ProgressChanged += new ProgressChangedEventHandler(progForm.worker_ProgressChanged);
  417. mapperWorker.DoWork += new DoWorkEventHandler(worker_GenerateMap);
  418. mapperWorker.RunWorkerAsync(true);
  419. progForm.FormClosed += new FormClosedEventHandler(worker_Completed);
  420. progForm.Show(this);
  421. }
  422. }
  423. private void worker_GenerateMap(object sender, DoWorkEventArgs e)
  424. {
  425. BackgroundWorker bw = (BackgroundWorker)sender;
  426. tmrMapperProgress.Start();
  427. #if (!DEBUG)
  428. try
  429. {
  430. #endif
  431. mapper.OpenWorld();
  432. //we're drawing a map
  433. if ((bool)e.Argument == true)
  434. mapper.ProcessWorld(worldPath, bw);
  435. else
  436. mapper.ReadChests(worldPath, bw);
  437. TreeNode[] chests = GetChests();
  438. PopulateWorldTree();
  439. PopulateChestTree(chests);
  440. //we're drawing a map
  441. if ((bool)e.Argument == true)
  442. {
  443. // pictureBox.BackgroundImageLayout = ImageLayout.
  444. pictureBox.Image = mapper.CreatePreviewPNG(textBoxOutputFile.Text, bw);
  445. pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
  446. // pictureBox.Update();
  447. if (SettingsManager.Instance.OpenImage)
  448. System.Diagnostics.Process.Start(textBoxOutputFile.Text);
  449. }
  450. tmrMapperProgress.Stop();
  451. #if (!DEBUG)
  452. }
  453. catch (Exception ex)
  454. {
  455. tmrMapperProgress.Stop();
  456. FormWorldView.MessageBoxShow(ex.Message + Environment.NewLine + Environment.NewLine +
  457. "Details: " + ex.ToString() + Environment.NewLine + "Version: " + GetVersion(),
  458. "Error Opening World", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
  459. return;
  460. }
  461. #endif
  462. }
  463. private void tmrMapperProgress_Tick(object sender, EventArgs e)
  464. {
  465. mapperWorker.ReportProgress(mapper.progress);
  466. }
  467. private void worker_Completed(object sender, FormClosedEventArgs e)
  468. {
  469. Boolean v = progForm.Success;
  470. mapper.Cleanup();
  471. GC.Collect();
  472. if (filterCount != SettingsManager.Instance.FilterItemStates.Count())
  473. ResetFilterLists();
  474. buttonDrawWorld.Enabled = true;
  475. groupBoxSelectWorld.Enabled = true;
  476. groupBoxImageOutput.Enabled = true;
  477. (this.tabPageMarkers as Control).Enabled = true;
  478. (this.tabPageWorldInformation as Control).Enabled = true;
  479. }
  480. private void PopulateWorldTree()
  481. {
  482. if (worldPropertyGrid.InvokeRequired)
  483. {
  484. PopulateWorldTreeDelegate del = new PopulateWorldTreeDelegate(PopulateWorldTree);
  485. worldPropertyGrid.Invoke(del);
  486. return;
  487. }
  488. worldPropertyGrid.SelectedObject = mapper.World.Header;
  489. }
  490. private TreeNode[] GetChests()
  491. {
  492. List<Chest> chests;
  493. List<TreeNode> chestNodes;
  494. chestNodes = new List<TreeNode>();
  495. if (this.mapper == null)
  496. return chestNodes.ToArray();
  497. if (SettingsManager.Instance.FilterChests == true)
  498. {
  499. chests = applyChestFilter(this.mapper.Chests);
  500. }
  501. else
  502. {
  503. chests = this.mapper.Chests;
  504. }
  505. // chestNodes = new List<TreeNode>(chests.Count);
  506. foreach (Chest c in chests)
  507. {
  508. TreeNode node = new TreeNode(string.Format("Chest at ({0},{1})", c.Coordinates.X, c.Coordinates.Y, c.ChestId));
  509. node.ImageIndex = (Int32) c.Type + 1;
  510. node.SelectedImageIndex = (Int32)c.Type + 1;
  511. foreach (Item i in c.Items)
  512. {
  513. node.Nodes.Add(i.ToString());
  514. }
  515. chestNodes.Add(node);
  516. }
  517. return chestNodes.ToArray();
  518. }
  519. private void PopulateChestTree(TreeNode[] node_array)
  520. {
  521. if (treeViewChestInformation.InvokeRequired)
  522. {
  523. PopulateChestTreeDelegate del = new PopulateChestTreeDelegate(PopulateChestTree);
  524. treeViewChestInformation.Invoke(del, new object[] { node_array });
  525. return;
  526. }
  527. treeViewChestInformation.SuspendLayout();
  528. treeViewChestInformation.Nodes.Clear();
  529. //nodes have to be added in this fairly awkward way, because this
  530. //fixes a bug with the TreeView control that will cause the last node
  531. //to have its lower half cut off at the bottom of the control,
  532. //and it won't allow the user to scroll further down...
  533. treeViewChestInformation.Nodes.AddRange(node_array);
  534. treeViewChestInformation.ResumeLayout(true);
  535. }
  536. private bool checkValidPaths(bool checkOutput)
  537. {
  538. if (comboBoxWorldFilePath.Text == string.Empty || !File.Exists(comboBoxWorldFilePath.Text))
  539. {
  540. MessageBox.Show("The World file could not be found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  541. return false;
  542. }
  543. else if (checkOutput && textBoxOutputFile.Text == string.Empty)
  544. {
  545. MessageBox.Show("Please enter desired output image path.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  546. return false;
  547. }
  548. else
  549. {
  550. return true;
  551. }
  552. }
  553. #endregion
  554. #region Marker tabPage functions
  555. // This handles pressing space to check/uncheck boxes.
  556. private void treeViewMarkerList_KeyPress(object sender, KeyPressEventArgs e)
  557. {
  558. if (e.KeyChar != ' ')
  559. return;
  560. if (treeViewMarkerList.SelectedNode != null)
  561. {
  562. treeViewMarkerList.SelectedNode.Checked = !treeViewMarkerList.SelectedNode.Checked;
  563. this.treeViewMarkerList_AfterCheck(this.treeViewMarkerList,
  564. new TreeViewEventArgs(treeViewMarkerList.SelectedNode, TreeViewAction.ByMouse));
  565. }
  566. }
  567. // This handles clicking on the check box part of the nodes.
  568. private void treeViewMarkerList_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  569. {
  570. Int32 xSpot = e.X - e.Node.Bounds.Left;
  571. if (treeViewMarkerList.ImageList != null)
  572. {
  573. if (xSpot < -34 || xSpot > -19)
  574. return;
  575. }
  576. else
  577. {
  578. if (xSpot < -16 || xSpot > -1)
  579. return;
  580. }
  581. e.Node.Checked = !e.Node.Checked;
  582. this.treeViewMarkerList_AfterCheck(this.treeViewMarkerList,
  583. new TreeViewEventArgs(e.Node, TreeViewAction.ByMouse));
  584. }
  585. // This takes a node that was clicked and goes down the list to update the parent to
  586. // it's correct state.
  587. private void treeViewMarkerList_updateParentNode(TreeNode e)
  588. {
  589. Int32 count, set;
  590. count = 0;
  591. set = 0;
  592. foreach (TreeNode n in e.Parent.Nodes)
  593. {
  594. count++;
  595. if (n.Checked == true)
  596. set++;
  597. }
  598. if (set == count)
  599. e.Parent.Checked = true;
  600. else
  601. e.Parent.Checked = false;
  602. if (set == 0)
  603. e.Parent.StateImageIndex = (Int32)CheckState.Unchecked;
  604. else if (set != count)
  605. e.Parent.StateImageIndex = (Int32)CheckState.Indeterminate;
  606. else
  607. e.Parent.StateImageIndex = (Int32)CheckState.Checked;
  608. }
  609. // This handles clicking a checkbox and correctly sets the child nodes, if there are any.
  610. private void treeViewMarkerList_AfterCheck(object sender, TreeViewEventArgs e)
  611. {
  612. // Don't do anything unless it was the user who set the checked state.
  613. if (e.Action == TreeViewAction.Unknown)
  614. return;
  615. if (markerNodes.ContainsKey(e.Node.Text))
  616. {
  617. SettingsManager.Instance.MarkerVisible(e.Node.Text, e.Node.Checked);
  618. treeViewMarkerList_updateParentNode(e.Node);
  619. }
  620. else
  621. {
  622. foreach (TreeNode n in e.Node.Nodes)
  623. {
  624. n.Checked = e.Node.Checked;
  625. SettingsManager.Instance.MarkerVisible(n.Text, e.Node.Checked);
  626. }
  627. }
  628. }
  629. private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
  630. {
  631. if (contextMenuStripListOperations.SourceControl is TreeView)
  632. {
  633. foreach (TreeNode p in (contextMenuStripListOperations.SourceControl as TreeView).Nodes)
  634. {
  635. p.Checked = true;
  636. foreach (TreeNode n in p.Nodes)
  637. {
  638. n.Checked = true;
  639. SettingsManager.Instance.MarkerVisible(n.Text, true);
  640. }
  641. }
  642. }
  643. }
  644. private void selectNoneToolStripMenuItem_Click(object sender, EventArgs e)
  645. {
  646. if (contextMenuStripListOperations.SourceControl is TreeView)
  647. {
  648. foreach (TreeNode p in (contextMenuStripListOperations.SourceControl as TreeView).Nodes)
  649. {
  650. p.Checked = false;
  651. foreach (TreeNode n in p.Nodes)
  652. {
  653. n.Checked = false;
  654. SettingsManager.Instance.MarkerVisible(n.Text, false);
  655. }
  656. }
  657. }
  658. }
  659. private void invertSelectionToolStripMenuItem_Click(object sender, EventArgs e)
  660. {
  661. Boolean nodeFlip;
  662. Int32 count, set;
  663. if (contextMenuStripListOperations.SourceControl is TreeView)
  664. {
  665. foreach (TreeNode p in (contextMenuStripListOperations.SourceControl as TreeView).Nodes)
  666. {
  667. count = 0;
  668. set = 0;
  669. foreach (TreeNode n in p.Nodes)
  670. {
  671. count++;
  672. nodeFlip = !n.Checked;
  673. SettingsManager.Instance.MarkerVisible(n.Text, nodeFlip);
  674. n.Checked = nodeFlip;
  675. if (nodeFlip == true)
  676. set++;
  677. }
  678. if (set == count)
  679. p.Checked = true;
  680. else
  681. p.Checked = false;
  682. if (set == 0)
  683. p.StateImageIndex = (Int32)CheckState.Unchecked;
  684. else if (set != count)
  685. p.StateImageIndex = (Int32)CheckState.Indeterminate;
  686. else
  687. p.StateImageIndex = (Int32)CheckState.Checked;
  688. }
  689. }
  690. }
  691. private void buttonCustomResources_Click(object sender, EventArgs e)
  692. {
  693. System.Diagnostics.Process.Start(Global.ApplicationResourceDirectory);
  694. }
  695. private void checkBoxShowChestTypes_CheckedChanged(object sender, EventArgs e)
  696. {
  697. SettingsManager.Instance.ShowChestTypes = checkBoxShowChestTypes.Checked;
  698. }
  699. private void checkBoxCustomMarkers_CheckedChanged(object sender, EventArgs e)
  700. {
  701. SettingsManager.Instance.CustomMarkers = checkBoxCustomMarkers.Checked;
  702. ResourceManager.Instance.Custom = checkBoxCustomMarkers.Checked;
  703. SetupImageLists();
  704. }
  705. private void buttonResetCustomImages_Click(object sender, EventArgs e)
  706. {
  707. DialogResult res = MessageBox.Show("This will overwrite all files in the Resources directory. If you have made changes to them they will be lost. Continue?",
  708. "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  709. if (res == DialogResult.No)
  710. return;
  711. ResourceManager.Instance.ResetCustomMarkers();
  712. if (SettingsManager.Instance.CustomMarkers)
  713. SetupImageLists();
  714. }
  715. private void SetupImageLists()
  716. {
  717. Graphics graph;
  718. Bitmap bmp;
  719. if (markerThreeStateList == null)
  720. {
  721. markerThreeStateList = new ImageList();
  722. // Set up the images for the three-state box.
  723. bmp = new Bitmap(16, 16);
  724. graph = Graphics.FromImage(bmp);
  725. CheckBoxRenderer.DrawCheckBox(graph, new Point(1, 1), CheckBoxState.UncheckedNormal);
  726. markerThreeStateList.Images.Add(bmp);
  727. bmp = new Bitmap(16, 16);
  728. graph = Graphics.FromImage(bmp);
  729. CheckBoxRenderer.DrawCheckBox(graph, new Point(1, 1), CheckBoxState.CheckedNormal);
  730. markerThreeStateList.Images.Add(bmp);
  731. bmp = new Bitmap(16, 16);
  732. graph = Graphics.FromImage(bmp);
  733. CheckBoxRenderer.DrawCheckBox(graph, new Point(1, 1), CheckBoxState.MixedNormal);
  734. markerThreeStateList.Images.Add(bmp);
  735. }
  736. if (chestImageList == null)
  737. chestImageList = new ImageList();
  738. if (markerImageList == null)
  739. markerImageList = new ImageList();
  740. if (colorImageList == null)
  741. {
  742. colorImageList = new ImageList();
  743. // This is the empty one we'll use for parent objects.
  744. colorImageList.Images.Add(new Bitmap(16, 16));
  745. bmp = new Bitmap(16, 16);
  746. graph = Graphics.FromImage(bmp);
  747. graph.DrawRectangle(new Pen(Color.Black, 1), 1, 1, 14, 14);
  748. // We filled the image list with as many copies of the empty square bitmap as
  749. // we needed.
  750. for (Int32 i = 0; i < colorData.Count; i++)
  751. {
  752. colorImageList.Images.Add(new Bitmap(bmp));
  753. }
  754. }
  755. if (buttonImageList == null)
  756. {
  757. buttonImageList = new ImageList();
  758. buttonImageList.ImageSize = new Size(51, 23);
  759. bmp = new Bitmap(50, 22);
  760. buttonImageList.Images.Add(bmp);
  761. buttonImageList.Images.Add(new Bitmap(bmp));
  762. }
  763. markerImageList.Images.Clear();
  764. chestImageList.Images.Clear();
  765. // This is our blank image to keep chest list items from having images.
  766. bmp = new Bitmap(16, 16);
  767. chestImageList.Images.Add(bmp);
  768. foreach (KeyValuePair<String, List<MarkerInfo>> kvp in Global.Instance.Info.MarkerSets)
  769. {
  770. bmp = ResourceManager.Instance.GetMarker(kvp.Key);
  771. markerImageList.Images.Add(bmp);
  772. foreach (MarkerInfo mi in kvp.Value)
  773. {
  774. bmp = ResourceManager.Instance.GetMarker(mi.markerImage);
  775. markerImageList.Images.Add(bmp);
  776. if (kvp.Key == "Containers")
  777. chestImageList.Images.Add(bmp);
  778. }
  779. }
  780. }
  781. private void SetupMarkerListBox()
  782. {
  783. Dictionary<String, MarkerSettings> markerStates = SettingsManager.Instance.MarkerStates;
  784. Boolean[] expList = null;
  785. // This section sets up the Marker list box. The first part draws the three
  786. // states of our checkboxes and then it populates the TreeView.
  787. Int32 index = 0;
  788. TreeNode node;
  789. if (treeViewMarkerList.Nodes.Count > 0)
  790. {
  791. expList = new Boolean[treeViewMarkerList.Nodes.Count];
  792. Int32 count = 0;
  793. foreach (TreeNode n in treeViewMarkerList.Nodes)
  794. {
  795. if (n.Parent == null)
  796. expList[count++] = n.IsExpanded;
  797. }
  798. }
  799. treeViewMarkerList.Nodes.Clear();
  800. treeViewMarkerList.StateImageList = markerThreeStateList;
  801. treeViewMarkerList.ImageList = markerImageList;
  802. markerNodes = new Dictionary<String, TreeNode>();
  803. Dictionary<String, TreeNode> parentNodes = new Dictionary<String, TreeNode>();
  804. foreach (KeyValuePair<String, List<MarkerInfo>> kvp in Global.Instance.Info.MarkerSets)
  805. {
  806. node = new TreeNode(kvp.Key);
  807. node.ImageIndex = index;
  808. node.SelectedImageIndex = index;
  809. parentNodes.Add(kvp.Key, node);
  810. foreach (MarkerInfo mi in kvp.Value)
  811. {
  812. index++;
  813. node = new TreeNode(mi.name);
  814. node.ImageIndex = index;
  815. node.SelectedImageIndex = index;
  816. markerNodes.Add(mi.name, node);
  817. if (markerStates[mi.name].Drawing)
  818. {
  819. node.Checked = true;
  820. node.StateImageIndex = (Int32)CheckState.Checked;
  821. }
  822. else
  823. {
  824. node.Checked = false;
  825. node.StateImageIndex = (Int32)CheckState.Unchecked;
  826. }
  827. }
  828. index++;
  829. }
  830. // We parse the list again, this time to set the parent/child heirarchy up.
  831. // This makes it so that we do not have to have them in the exact order in the XML file.
  832. foreach(KeyValuePair<Int32, MarkerInfo> kvp in Global.Instance.Info.Markers)
  833. {
  834. parentNodes[kvp.Value.markerSet].Nodes.Add(markerNodes[kvp.Value.name]);
  835. }
  836. // Now that it is set up so all child nodes are in the right spot we add them to the
  837. // treeNode and force it to update the checked state.
  838. foreach(KeyValuePair<String, TreeNode> kvp in parentNodes)
  839. {
  840. treeViewMarkerList.Nodes.Add(kvp.Value);
  841. treeViewMarkerList_updateParentNode(kvp.Value.Nodes[0]);
  842. }
  843. if (expList != null)
  844. {
  845. Int32 count = 0;
  846. foreach (TreeNode n in treeViewMarkerList.Nodes)
  847. {
  848. if ((n.Parent == null) && (expList[count++] == true))
  849. n.Expand();
  850. }
  851. }
  852. }
  853. #endregion
  854. #region Color tabPage functions
  855. private void treeViewColorList_AfterSelect(object sender, TreeViewEventArgs e)
  856. {
  857. Global.Instance.SkipEvents = true;
  858. if ((e.Node == null) || (e.Node.Parent == null))
  859. {
  860. radioButtonColorDefault.Checked = true;
  861. comboBoxColorName.SelectedIndex = -1;
  862. textBoxColorColor.Text = String.Empty;
  863. groupBoxColor.Enabled = false;
  864. Global.Instance.SkipEvents = false;
  865. return;
  866. }
  867. groupBoxColor.Enabled = true;
  868. ColorListDataNode data = colorData.GetNode(e.Node.Text, e.Node.Parent.Text);
  869. if (data == null)
  870. {
  871. Global.Instance.SkipEvents = false;
  872. return;
  873. }
  874. if (data.defaultColor == data.currentColor)
  875. radioButtonColorDefault.Checked = true;
  876. else if (data.currentColorName != String.Empty)
  877. radioButtonColorPreset.Checked = true;
  878. else
  879. radioButtonColorColor.Checked = true;
  880. if (data.currentColorName == String.Empty)
  881. comboBoxColorName.SelectedIndex = -1;
  882. else
  883. {
  884. if (comboBoxColorName.Items.Contains(data.currentColorName))
  885. comboBoxColorName.SelectedItem = data.currentColorName;
  886. else
  887. comboBoxColorName.SelectedIndex = -1;
  888. }
  889. textBoxColorColor.Text = Global.ToColorString(data.currentColor);
  890. Global.Instance.SkipEvents = false;
  891. }
  892. private void radioButtonColorDefault_CheckedChanged(object sender, EventArgs e)
  893. {
  894. if (Global.Instance.SkipEvents)
  895. return;
  896. //MessageBox.Show("radioButtonColorDefault_CheckedChanged");
  897. }
  898. private void radioButtonColorName_CheckedChanged(object sender, EventArgs e)
  899. {
  900. if (Global.Instance.SkipEvents)
  901. return;
  902. //MessageBox.Show("radioButtonColorName_CheckedChanged");
  903. }
  904. private void radioButtonColorColor_CheckedChanged(object sender, EventArgs e)
  905. {
  906. if (Global.Instance.SkipEvents)
  907. return;
  908. //MessageBox.Show("radioButtonColorColor_CheckedChanged");
  909. }
  910. private void comboBoxColorName_SelectedIndexChanged(object sender, EventArgs e)
  911. {
  912. if (Global.Instance.SkipEvents)
  913. return;
  914. MessageBox.Show("comboBoxColorName_SelectedIndexChanged");
  915. }
  916. private void textBoxColorColor_TextChanged(object sender, EventArgs e)
  917. {
  918. if (Global.Instance.SkipEvents)
  919. return;
  920. }
  921. private void SetupColorButtons()
  922. {
  923. buttonColorColor.ImageList = buttonImageList;
  924. buttonColorColor.ImageIndex = 0;
  925. buttonColorNameColor.ImageList = buttonImageList;
  926. buttonColorNameColor.ImageIndex = 1;
  927. }
  928. private void SetupColorNames()
  929. {
  930. Dictionary<String, ColorInfo> colors = Global.Instance.Info.Colors;
  931. comboBoxColorName.Items.Clear();
  932. comboBoxColorNamesName.Items.Clear();
  933. foreach (KeyValuePair<String, ColorInfo> kvp in colors)
  934. {
  935. comboBoxColorName.Items.Add(kvp.Key);
  936. comboBoxColorNamesName.Items.Add(kvp.Key);
  937. }
  938. comboBoxColorNamesName.SelectedIndex = 0;
  939. }
  940. private void SetupColorData()
  941. {
  942. treeViewColorList.Nodes.Clear();
  943. treeViewColorList.ImageList = colorImageList;
  944. if (colorData == null)
  945. colorData = new ColorListData();
  946. else
  947. colorData.Clear();
  948. String parent = "Tiles";
  949. Int32 id = 1;
  950. foreach (KeyValuePair<Int32, TileInfo> kvp in Global.Instance.Info.Tiles)
  951. {
  952. colorData.AddNewNode(kvp.Value.name, parent, kvp.Value.color,
  953. kvp.Value.colorName, id + kvp.Value.tileImage);
  954. }
  955. id += Global.Instance.Info.Tiles.Count - 1;
  956. parent = "Walls";
  957. foreach (KeyValuePair<Int32, WallInfo> kvp in Global.Instance.Info.Walls)
  958. {
  959. colorData.AddNewNode(kvp.Value.name, parent, kvp.Value.color,
  960. kvp.Value.colorName, id + kvp.Value.wallImage);
  961. }
  962. id += Global.Instance.Info.Walls.Count + 1;
  963. foreach (KeyValuePair<String, List<SpecialObjectInfo>> kvp in Global.Instance.Info.SpecialObjects)
  964. {
  965. parent = kvp.Key + "s";
  966. foreach (SpecialObjectInfo soi in kvp.Value)
  967. {
  968. colorData.AddNewNode(soi.name, parent, soi.color,
  969. soi.colorName, id);
  970. id++;
  971. }
  972. }
  973. }
  974. private void SetupColorListBox()
  975. {
  976. Boolean[] expList = null;
  977. TreeNode node, parent;
  978. if (treeViewColorList.Nodes.Count > 0)
  979. {
  980. expList = new Boolean[treeViewColorList.Nodes.Count];
  981. Int32 count = 0;
  982. foreach (TreeNode n in treeViewColorList.Nodes)
  983. {
  984. if (n.Parent == null)
  985. expList[count++] = n.IsExpanded;
  986. }
  987. }
  988. treeViewColorList.Nodes.Clear();
  989. treeViewColorList.ImageList = colorImageList;
  990. foreach (KeyValuePair<String, Dictionary<String, ColorListDataNode>> kvp in colorData.Data)
  991. {
  992. parent = new TreeNode(kvp.Key);
  993. parent.ImageIndex = -1;
  994. parent.SelectedImageIndex = -1;
  995. treeViewColorList.Nodes.Add(parent);
  996. foreach (KeyValuePair<String, ColorListDataNode> kvp2 in kvp.Value)
  997. {
  998. node = new TreeNode(kvp2.Key);
  999. node.SelectedImageIndex = kvp2.Value.nodeId;
  1000. node.ImageIndex = node.SelectedImageIndex;
  1001. UpdateColorImage(node.ImageIndex, kvp2.Value.currentColor);
  1002. parent.Nodes.Add(node);
  1003. }
  1004. }
  1005. if (expList != null)
  1006. {
  1007. Int32 count = 0;
  1008. foreach (TreeNode n in treeViewColorList.Nodes)
  1009. {
  1010. if ((n.Parent == null) && (expList[count++] == true))
  1011. n.Expand();
  1012. }
  1013. }
  1014. }
  1015. private void UpdateColorImage(Int32 useImage, Color newColor)
  1016. {
  1017. if ((useImage < 0) || (useImage >= colorImageList.Images.Count))
  1018. return;
  1019. Image image = colorImageList.Images[useImage];
  1020. Graphics graph = Graphics.FromImage(image);
  1021. graph.FillRectangle(new SolidBrush(newColor), 2, 2, 13, 13);
  1022. colorImageList.Images[useImage] = image;
  1023. }
  1024. private void UpdateColorButton(Int32 useButton, Color newColor)
  1025. {
  1026. if ((useButton < 0) || (useButton >= buttonImageList.Images.Count))
  1027. return;
  1028. Image image = buttonImageList.Images[useButton];
  1029. Graphics graph = Graphics.FromImage(image);
  1030. graph.FillRectangle(new SolidBrush(newColor), 0, 0, image.Width - 1, image.Height - 1);
  1031. buttonImageList.Images[useButton] = image;
  1032. }
  1033. #endregion
  1034. #region ChestFinder tabPage functions
  1035. private void checkBoxFilterChests_CheckedChanged(object sender, EventArgs e)
  1036. {
  1037. SettingsManager.Instance.FilterChests = checkBoxFilterChests.Checked;
  1038. lstAvailableItems.Enabled = checkBoxFilterChests.Checked;
  1039. lstFilteredItems.Enabled = checkBoxFilterChests.Checked;
  1040. filterUpdated = true;
  1041. }
  1042. private void checkBoxShowChestItems_CheckedChanged(object sender, EventArgs e)
  1043. {
  1044. SettingsManager.Instance.ShowChestItems = checkBoxShowChestItems.Checked;
  1045. ResetFilterLists();
  1046. }
  1047. private void checkBoxShowNormalItems_CheckedChanged(object sender, EventArgs e)
  1048. {
  1049. SettingsManager.Instance.ShowNormalItems = checkBoxShowNormalItems.Checked;
  1050. ResetFilterLists();
  1051. }
  1052. private void lstFilteredItems_DoubleClick(object sender, EventArgs e)
  1053. {
  1054. lstFilteredItems_KeyDown(sender, new KeyEventArgs(Keys.Delete));
  1055. }
  1056. private void lstAvailableItems_DoubleClick(object sender, EventArgs e)
  1057. {
  1058. String si;
  1059. int selected = lstAvailableItems.SelectedIndex;
  1060. if (selected == -1) return;
  1061. si = lstAvailableItems.SelectedItem.ToString();
  1062. lstFilteredItems.Items.Add(si);
  1063. lstAvailableItems.Items.Remove(si);
  1064. lstAvailableItems.SelectedIndex = Math.Min(selected, lstAvailableItems.Items.Count - 1);
  1065. SettingsManager.Instance.FilterItem(si, true);
  1066. filterUpdated = true;
  1067. buttonMoveAllToAvailable.Enabled = (lstFilteredItems.Items.Count != 0);
  1068. buttonMoveAllToFiltered.Enabled = (lstAvailableItems.Items.Count != 0);
  1069. }
  1070. private void lstFilteredItems_KeyDown(object sender, KeyEventArgs e)
  1071. {
  1072. ItemInfo ii;
  1073. String si;
  1074. int selected = lstFilteredItems.SelectedIndex;
  1075. if (selected == -1) return;
  1076. if (e.KeyCode == Keys.Delete)
  1077. {
  1078. si = lstFilteredItems.SelectedItem.ToString();
  1079. ii = Global.Instance.Info.GetItem(si);
  1080. if (ii.foundIn == "Chest")
  1081. {
  1082. if (SettingsManager.Instance.ShowChestItems)
  1083. lstAvailableItems.Items.Add(si);
  1084. } else if (SettingsManager.Instance.ShowNormalItems)
  1085. lstAvailableItems.Items.Add(si);
  1086. lstFilteredItems.Items.Remove(lstFilteredItems.SelectedItem);
  1087. lstFilteredItems.SelectedIndex = Math.Min(selected, lstFilteredItems.Items.Count - 1);
  1088. SettingsManager.Instance.FilterItem(si, false);
  1089. filterUpdated = true;
  1090. buttonMoveAllToAvailable.Enabled = (lstFilteredItems.Items.Count != 0);
  1091. buttonMoveAllToFiltered.Enabled = (lstAvailableItems.Items.Count != 0);
  1092. }
  1093. }
  1094. private void buttonMoveAllToFiltered_Click(object sender, EventArgs e)
  1095. {
  1096. List<String> filter;
  1097. if (lstAvailableItems.Items.Count == 0)
  1098. return;
  1099. filter = SettingsManager.Instance.FilterItemStates;
  1100. foreach (String s in lstAvailableItems.Items)
  1101. {
  1102. filter.Add(s);
  1103. }
  1104. ResetFilterLists();
  1105. }
  1106. private void buttonMoveAllToAvailable_Click(object sender, EventArgs e)
  1107. {
  1108. if (lstFilteredItems.Items.Count == 0)
  1109. return;
  1110. SettingsManager.Instance.FilterItemStates.Clear();
  1111. ResetFilterLists();
  1112. }
  1113. private void ResetFilterLists()
  1114. {
  1115. String lstItem;
  1116. List<String> filterList;
  1117. Boolean showInChest = SettingsManager.Instance.ShowChestItems;
  1118. Boolean showNormal = SettingsManager.Instance.ShowNormalItems;
  1119. lstFilteredItems.Items.Clear();
  1120. lstAvailableItems.Items.Clear();
  1121. filterList = SettingsManager.Instance.FilterItemStates;
  1122. foreach (KeyValuePair<String, ItemInfo> kvp in Global.Instance.Info.Items)
  1123. {
  1124. lstItem = kvp.Key;
  1125. if (filterList.Contains(kvp.Key))
  1126. {
  1127. lstFilteredItems.Items.Add(kvp.Key);
  1128. }
  1129. else
  1130. {
  1131. if (kvp.Value.foundIn == "Chest")
  1132. {
  1133. if (showInChest == false)
  1134. continue;
  1135. }
  1136. else if (showNormal == false)
  1137. {
  1138. continue;
  1139. }
  1140. lstAvailableItems.Items.Add(lstItem);
  1141. }
  1142. }
  1143. buttonMoveAllToAvailable.Enabled = (lstFilteredItems.Items.Count != 0);
  1144. buttonMoveAllToFiltered.Enabled = (lstAvailableItems.Items.Count != 0);
  1145. filterUpdated = true;
  1146. }
  1147. #endregion
  1148. #region World Information tabPage functions
  1149. private void buttonLoadInformation_Click(object sender, EventArgs e)
  1150. {
  1151. if (checkValidPaths(false))
  1152. {
  1153. treeViewChestInformation.ImageList = null;
  1154. filterCount = SettingsManager.Instance.FilterItemStates.Count;
  1155. buttonDrawWorld.Enabled = false;
  1156. groupBoxSelectWorld.Enabled = false;
  1157. groupBoxImageOutput.Enabled = false;
  1158. (this.tabPageMarkers as Control).Enabled = false;
  1159. (this.tabPageWorldInformation as Control).Enabled = false;
  1160. Point pt = this.Location;
  1161. pt.X += (this.Size.Width / 2);
  1162. pt.Y += (this.Size.Height / 2);
  1163. mapper = new WorldMapper();
  1164. mapper.Initialize();
  1165. mapperWorker = new BackgroundWorker();
  1166. progForm = new FormProgressDialog("Load World Information", false, mapperWorker);
  1167. mapperWorker.WorkerReportsProgress = true;
  1168. mapperWorker.WorkerSupportsCancellation = false;
  1169. mapperWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(progForm.worker_Completed);
  1170. mapperWorker.ProgressChanged += new ProgressChangedEventHandler(progForm.worker_ProgressChanged);
  1171. mapperWorker.DoWork += new DoWorkEventHandler(worker_GenerateMap);
  1172. mapperWorker.RunWorkerAsync(false);
  1173. progForm.FormClosed += new FormClosedEventHandler(worker_Completed);
  1174. progForm.Show(this);
  1175. }
  1176. }
  1177. private void radioButtonSortByNone_CheckedChanged(object sender, EventArgs e)
  1178. {
  1179. SettingsManager.Instance.SortChestsBy = 0;
  1180. treeViewChestInformation.TreeViewNodeSorter = null;
  1181. treeViewChestInformation.Sorted = false;
  1182. PopulateChestTree(GetChests());
  1183. }
  1184. private void radioButtonSortByX_CheckedChanged(object sender, EventArgs e)
  1185. {
  1186. SettingsManager.Instance.SortChestsBy = 1;
  1187. treeViewChestInformation.TreeViewNodeSorter = new ChestComparerX();
  1188. }
  1189. private void radioButtonSortByY_CheckedChanged(object sender, EventArgs e)
  1190. {
  1191. SettingsManager.Instance.SortChestsBy = 2;
  1192. treeViewChestInformation.TreeViewNodeSorter = new ChestComparerY();
  1193. }
  1194. private List<Chest> applyChestFilter(List<Chest> chests)
  1195. {
  1196. List<String> itemFilters = SettingsManager.Instance.FilterItemStates;
  1197. List<Chest> filteredChests = new List<Chest>();
  1198. foreach(Chest c in chests)
  1199. {
  1200. // If we are checking the chest node itself.
  1201. foreach (Item item in c.Items)
  1202. {
  1203. if (itemFilters.Contains(item.Name))
  1204. {
  1205. filteredChests.Add(c);
  1206. break;
  1207. }
  1208. }
  1209. }
  1210. return filteredChests;
  1211. }
  1212. private void tabControlSettings_SelectedIndexChanged(object sender, EventArgs e)
  1213. {
  1214. if (tabControlSettings.SelectedTab.Text == "World Information")
  1215. {
  1216. if (this.mapper == null)
  1217. return;
  1218. if (filterUpdated == true)
  1219. {
  1220. PopulateChestTree(GetChests());
  1221. filterUpdated = false;
  1222. }
  1223. }
  1224. }
  1225. private void saveToTextToolStripMenuItem_Click(object sender, EventArgs e)
  1226. {
  1227. SaveFileDialog dialog = new SaveFileDialog();
  1228. DialogResult result;
  1229. if (treeViewChestInformation.Nodes.Count == 0)
  1230. {
  1231. MessageBox.Show("No chests to save!");
  1232. return;
  1233. }
  1234. dialog.FileName = String.Format("{0}Chests.txt",
  1235. Path.GetFileNameWithoutExtension(comboBoxWorldFilePath.SelectedItem.ToString()));
  1236. dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
  1237. dialog.FilterIndex = 1;
  1238. dialog.RestoreDirectory = true;
  1239. result = dialog.ShowDialog();
  1240. if (result == DialogResult.Cancel)
  1241. return;
  1242. SaveChestsAsText(dialog.FileN

Large files files are truncated, but you can click here to view the full file