diff --git a/MonsterForm.Designer.cs b/MonsterForm.Designer.cs index 13a9f9a..e88c86e 100644 --- a/MonsterForm.Designer.cs +++ b/MonsterForm.Designer.cs @@ -1295,6 +1295,7 @@ private void InitializeComponent() this.flagsListBox.Margin = new System.Windows.Forms.Padding(2); this.flagsListBox.Name = "flagsListBox"; this.flagsListBox.Size = new System.Drawing.Size(182, 319); + this.flagsListBox.Sorted = true; this.flagsListBox.TabIndex = 76; this.flagsListBox.SelectedIndexChanged += new System.EventHandler(this.flagsListBox_SelectedIndexChanged); // diff --git a/Program.cs b/Program.cs index 4c95941..9ae6846 100644 --- a/Program.cs +++ b/Program.cs @@ -8,6 +8,35 @@ namespace cdda_item_creator { static class Program { + // the container for the lists of CDDA objects by type + public static class LoadedObjectDictionary + { + static Dictionary> ids_by_type = new Dictionary> { }; + + static public void Add(string type, string id) + { + List temp_list; + if(ids_by_type.TryGetValue(type, out temp_list)) + { + temp_list.Add(id); + ids_by_type[type] = temp_list; + } else + { + temp_list = new List { id }; + ids_by_type.Add(type, temp_list); + } + } + static public Dictionary>.KeyCollection Keys() + { + return ids_by_type.Keys; + } + static public List GetList(string key) + { + List ret; + ids_by_type.TryGetValue(key, out ret); + return ret; + } + } /// /// The main entry point for the application. /// diff --git a/ViewerForm.Designer.cs b/ViewerForm.Designer.cs new file mode 100644 index 0000000..f00c2d8 --- /dev/null +++ b/ViewerForm.Designer.cs @@ -0,0 +1,73 @@ +namespace cdda_item_creator +{ + partial class ViewerForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.typeListBox = new System.Windows.Forms.ListBox(); + this.idListBox = new System.Windows.Forms.ListBox(); + this.SuspendLayout(); + // + // typeListBox + // + this.typeListBox.FormattingEnabled = true; + this.typeListBox.Location = new System.Drawing.Point(12, 12); + this.typeListBox.Name = "typeListBox"; + this.typeListBox.Size = new System.Drawing.Size(208, 420); + this.typeListBox.Sorted = true; + this.typeListBox.TabIndex = 0; + this.typeListBox.SelectedIndexChanged += new System.EventHandler(this.typeListBox_SelectedIndexChanged); + // + // idListBox + // + this.idListBox.FormattingEnabled = true; + this.idListBox.Location = new System.Drawing.Point(226, 12); + this.idListBox.Name = "idListBox"; + this.idListBox.Size = new System.Drawing.Size(208, 420); + this.idListBox.Sorted = true; + this.idListBox.TabIndex = 1; + this.idListBox.SelectedIndexChanged += new System.EventHandler(this.idListBox_SelectedIndexChanged); + // + // ViewerForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(454, 450); + this.Controls.Add(this.idListBox); + this.Controls.Add(this.typeListBox); + this.Name = "ViewerForm"; + this.Text = "ViewerForm"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListBox typeListBox; + private System.Windows.Forms.ListBox idListBox; + } +} \ No newline at end of file diff --git a/ViewerForm.cs b/ViewerForm.cs new file mode 100644 index 0000000..c351ac9 --- /dev/null +++ b/ViewerForm.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace cdda_item_creator +{ + public partial class ViewerForm : Form + { + private void InitializeTypeList() + { + foreach(string type in Program.LoadedObjectDictionary.Keys()) + { + typeListBox.Items.Add(type); + } + } + public ViewerForm() + { + InitializeComponent(); + InitializeTypeList(); + } + + private void idListBox_SelectedIndexChanged(object sender, EventArgs e) + { + } + + private void typeListBox_SelectedIndexChanged(object sender, EventArgs e) + { + idListBox.Items.Clear(); + foreach (string id in Program.LoadedObjectDictionary.GetList((string)typeListBox.SelectedItem)) + { + idListBox.Items.Add(id); + } + } + } +} diff --git a/ViewerForm.resx b/ViewerForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ViewerForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/cdda-item-creator.csproj b/cdda-item-creator.csproj index a08ac88..f6b2a14 100644 --- a/cdda-item-creator.csproj +++ b/cdda-item-creator.csproj @@ -72,6 +72,12 @@ + + Form + + + ViewerForm.cs + MonsterForm.cs @@ -90,6 +96,9 @@ spell_form.cs + + ViewerForm.cs + diff --git a/selector.Designer.cs b/selector.Designer.cs index 10c5687..ed9b7ea 100644 --- a/selector.Designer.cs +++ b/selector.Designer.cs @@ -30,6 +30,8 @@ private void InitializeComponent() { this.spellButton = new System.Windows.Forms.Button(); this.createMonster_button = new System.Windows.Forms.Button(); + this.cddaFolderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); + this.viewLoadedItemsButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // // spellButton @@ -52,11 +54,26 @@ private void InitializeComponent() this.createMonster_button.UseVisualStyleBackColor = true; this.createMonster_button.Click += new System.EventHandler(this.createMonster_button_Click); // + // cddaFolderBrowserDialog + // + this.cddaFolderBrowserDialog.Description = "Choose the folder where C:DDA is located:"; + // + // viewLoadedItemsButton + // + this.viewLoadedItemsButton.Location = new System.Drawing.Point(12, 79); + this.viewLoadedItemsButton.Name = "viewLoadedItemsButton"; + this.viewLoadedItemsButton.Size = new System.Drawing.Size(75, 61); + this.viewLoadedItemsButton.TabIndex = 2; + this.viewLoadedItemsButton.Text = "View Loaded Items"; + this.viewLoadedItemsButton.UseVisualStyleBackColor = true; + this.viewLoadedItemsButton.Click += new System.EventHandler(this.viewLoadedItemsButton_Click); + // // SelectorForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(192, 82); + this.ClientSize = new System.Drawing.Size(192, 146); + this.Controls.Add(this.viewLoadedItemsButton); this.Controls.Add(this.createMonster_button); this.Controls.Add(this.spellButton); this.Name = "SelectorForm"; @@ -69,5 +86,7 @@ private void InitializeComponent() private System.Windows.Forms.Button spellButton; private System.Windows.Forms.Button createMonster_button; + private System.Windows.Forms.FolderBrowserDialog cddaFolderBrowserDialog; + private System.Windows.Forms.Button viewLoadedItemsButton; } } \ No newline at end of file diff --git a/selector.cs b/selector.cs index c245202..674dcaf 100644 --- a/selector.cs +++ b/selector.cs @@ -1,8 +1,11 @@ -using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,9 +15,38 @@ namespace cdda_item_creator { public partial class SelectorForm : Form { + private void TryLoadObjectLists() + { + cddaFolderBrowserDialog.ShowDialog(); + if(cddaFolderBrowserDialog.SelectedPath == "") + { + return; + } + DirectoryInfo dir = new DirectoryInfo(cddaFolderBrowserDialog.SelectedPath); + foreach (FileInfo file in dir.GetFiles("*.json", SearchOption.AllDirectories)) + { + string file_text = File.ReadAllText(file.FullName); + try + { + JArray ja = JArray.Parse(file_text); + List temp_list = (List)ja.ToObject(typeof(List)); + foreach (GenericTypedObject obj in temp_list) + { + if (obj.valid()) + { + Program.LoadedObjectDictionary.Add(obj.Type, obj.Id); + } + } + } catch + { + + } + } + } public SelectorForm() { InitializeComponent(); + TryLoadObjectLists(); } private void spellButton_Click(object sender, EventArgs e) @@ -32,5 +64,22 @@ private void createMonster_button_Click(object sender, EventArgs e) form.ShowDialog(); this.Show(); } + + private void viewLoadedItemsButton_Click(object sender, EventArgs e) + { + ViewerForm form = new ViewerForm(); + this.Hide(); + form.ShowDialog(); + this.Show(); + } + } + public class GenericTypedObject + { + public string Type { get; set; } + public string Id { get; set; } + public bool valid() + { + return Type != null && Id != null; + } } } diff --git a/selector.resx b/selector.resx index 1af7de1..85ead32 100644 --- a/selector.resx +++ b/selector.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file