From aa0f7e7be10a4b50c130a2048df4d3438d727165 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Tue, 3 Dec 2019 21:34:58 -0500 Subject: [PATCH] Remember Selected Path --- .gitignore | 1 + selector.Designer.cs | 44 +++++++++++++++++++++++++++++++++++++++++--- selector.cs | 40 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 61d2508..50d8879 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bin/ *.exe *.pdb *.zip +cdda_data_path diff --git a/selector.Designer.cs b/selector.Designer.cs index ed9b7ea..cbded4a 100644 --- a/selector.Designer.cs +++ b/selector.Designer.cs @@ -32,11 +32,14 @@ private void InitializeComponent() this.createMonster_button = new System.Windows.Forms.Button(); this.cddaFolderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); this.viewLoadedItemsButton = new System.Windows.Forms.Button(); + this.loadGameDialog = new System.Windows.Forms.Button(); + this.currentPathLabelLabel = new System.Windows.Forms.Label(); + this.currentPathLabel = new System.Windows.Forms.Label(); this.SuspendLayout(); // // spellButton // - this.spellButton.Location = new System.Drawing.Point(12, 12); + this.spellButton.Location = new System.Drawing.Point(93, 79); this.spellButton.Name = "spellButton"; this.spellButton.Size = new System.Drawing.Size(75, 61); this.spellButton.TabIndex = 0; @@ -46,7 +49,7 @@ private void InitializeComponent() // // createMonster_button // - this.createMonster_button.Location = new System.Drawing.Point(103, 12); + this.createMonster_button.Location = new System.Drawing.Point(174, 79); this.createMonster_button.Name = "createMonster_button"; this.createMonster_button.Size = new System.Drawing.Size(75, 61); this.createMonster_button.TabIndex = 1; @@ -68,17 +71,49 @@ private void InitializeComponent() this.viewLoadedItemsButton.UseVisualStyleBackColor = true; this.viewLoadedItemsButton.Click += new System.EventHandler(this.viewLoadedItemsButton_Click); // + // loadGameDialog + // + this.loadGameDialog.Location = new System.Drawing.Point(12, 12); + this.loadGameDialog.Name = "loadGameDialog"; + this.loadGameDialog.Size = new System.Drawing.Size(75, 44); + this.loadGameDialog.TabIndex = 3; + this.loadGameDialog.Text = "Pick C:DDA Folder"; + this.loadGameDialog.UseVisualStyleBackColor = true; + this.loadGameDialog.Click += new System.EventHandler(this.loadGameDialog_Click); + // + // currentPathLabelLabel + // + this.currentPathLabelLabel.AutoSize = true; + this.currentPathLabelLabel.Location = new System.Drawing.Point(94, 13); + this.currentPathLabelLabel.Name = "currentPathLabelLabel"; + this.currentPathLabelLabel.Size = new System.Drawing.Size(69, 13); + this.currentPathLabelLabel.TabIndex = 4; + this.currentPathLabelLabel.Text = "Current Path:"; + // + // currentPathLabel + // + this.currentPathLabel.AutoSize = true; + this.currentPathLabel.Location = new System.Drawing.Point(97, 30); + this.currentPathLabel.MaximumSize = new System.Drawing.Size(150, 0); + this.currentPathLabel.Name = "currentPathLabel"; + this.currentPathLabel.Size = new System.Drawing.Size(0, 13); + this.currentPathLabel.TabIndex = 5; + // // SelectorForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(192, 146); + this.ClientSize = new System.Drawing.Size(256, 146); + this.Controls.Add(this.currentPathLabel); + this.Controls.Add(this.currentPathLabelLabel); + this.Controls.Add(this.loadGameDialog); this.Controls.Add(this.viewLoadedItemsButton); this.Controls.Add(this.createMonster_button); this.Controls.Add(this.spellButton); this.Name = "SelectorForm"; this.Text = "SelectorForm"; this.ResumeLayout(false); + this.PerformLayout(); } @@ -88,5 +123,8 @@ private void InitializeComponent() private System.Windows.Forms.Button createMonster_button; private System.Windows.Forms.FolderBrowserDialog cddaFolderBrowserDialog; private System.Windows.Forms.Button viewLoadedItemsButton; + private System.Windows.Forms.Button loadGameDialog; + private System.Windows.Forms.Label currentPathLabelLabel; + private System.Windows.Forms.Label currentPathLabel; } } \ No newline at end of file diff --git a/selector.cs b/selector.cs index 19549ec..22a6d62 100644 --- a/selector.cs +++ b/selector.cs @@ -17,12 +17,27 @@ public partial class SelectorForm : Form { private void TryLoadObjectLists() { - cddaFolderBrowserDialog.ShowDialog(); - if(cddaFolderBrowserDialog.SelectedPath == "") + string cdda_path; + try + { + string cdda_path_file = System.Windows.Forms.Application.StartupPath + "\\cdda_data_path"; + cdda_path = File.ReadAllText(cdda_path_file); + } + catch + { + cddaFolderBrowserDialog.ShowDialog(); + cdda_path = cddaFolderBrowserDialog.SelectedPath; + } + currentPathLabel.Text = cdda_path; + if (cdda_path == "") { return; } - DirectoryInfo dir = new DirectoryInfo(cddaFolderBrowserDialog.SelectedPath); + else + { + File.WriteAllText(Application.StartupPath + "\\cdda_data_path", cdda_path); + } + DirectoryInfo dir = new DirectoryInfo(cdda_path); foreach (FileInfo file in dir.GetFiles("*.json", SearchOption.AllDirectories)) { string file_text = File.ReadAllText(file.FullName); @@ -39,7 +54,8 @@ private void TryLoadObjectLists() switch (generic_object.Type) { case "MONSTER": - Program.LoadedObjectDictionary.Add(generic_object.Id, (Mtype)obj.ToObject(typeof(Mtype))); + Mtype temp = (Mtype)obj.ToObject(typeof(Mtype)); + Program.LoadedObjectDictionary.Add(generic_object.Id, temp); break; case "SPELL": Program.LoadedObjectDictionary.Add(generic_object.Id, (spell.spell_type)obj.ToObject(typeof(spell.spell_type))); @@ -86,6 +102,22 @@ private void viewLoadedItemsButton_Click(object sender, EventArgs e) form.ShowDialog(); this.Show(); } + + private void loadGameDialog_Click(object sender, EventArgs e) + { + string cdda_path; + cddaFolderBrowserDialog.ShowDialog(); + cdda_path = cddaFolderBrowserDialog.SelectedPath; + currentPathLabel.Text = cdda_path; + if (cdda_path == "") + { + return; + } + else + { + File.WriteAllText(Application.StartupPath + "\\cdda_data_path", cdda_path); + } + } } public class GenericTypedObject {