/[MorrowindCustomClothingSlotCreator]/trunk/MorrowindCustomClothingSlotCreator/Form1.cs
ViewVC logotype

Diff of /trunk/MorrowindCustomClothingSlotCreator/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/MorrowindCustomClothingSlotCreator/Form1.cs	2011/07/29 09:23:17	4
+++ trunk/MorrowindCustomClothingSlotCreator/Form1.cs	2011/07/30 14:21:44	40
@@ -22,6 +22,11 @@
         {
             InitializeComponent();
             this.TES3PluginLoader = new TES3PluginLoader();
+
+            foreach (int val in Enum.GetValues(typeof(ClothingTypes))) { comboClothingType.Items.Add(Enum.GetName(typeof(ClothingTypes), val)); }
+            comboCustomClothingSlotIndex.Items.Add("Default"); 
+            for (int i = 1; i < 0x10; i++) { comboCustomClothingSlotIndex.Items.Add("0x" + i.ToString("X2")); }
+
         }
 
         public bool LoadPlugin(string pluginFile)
@@ -30,6 +35,10 @@
 
             if (loaded)
             {
+                foreach (KeyValuePair<string,ClothingEntry> entry in this.TES3PluginLoader.ClothingSection.ClothingEntries)
+                {
+                    lstClothingEntries.Items.Add(entry.Key);
+                }
                 MessageBox.Show("Successfully Loaded Plugin: " + pluginFile, "Successfully Loaded File:", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
 
@@ -41,19 +50,174 @@
         {
             this.Close();
         }
+        private void mnuItemSavePlugin_Click(object sender, EventArgs e)
+        {
+            if (!this.TES3PluginLoader.PluginLoaded) return;
+            if (!this.TES3PluginLoader.PluginSavingIsImplemented)
+            {
+                MessageBox.Show("Plugin Saving has not been implemetned", "Unimplemented Function:", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                return;
+            }
+            if (!this.TES3PluginLoader.Save())
+            {
+                MessageBox.Show("Failed to Save Plugin: " + this.TES3PluginLoader.PluginFile + "\n\nReason: \n\n" + this.TES3PluginLoader.PluginLoadFailureReason, "Failed to Save File:", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+            else
+            {
+                MessageBox.Show("Successfully Saved Plugin: " + this.TES3PluginLoader.PluginFile, "Successfully Saved File:", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            }
+        }
+        private void mnuItemSavePluginAs_Click(object sender, EventArgs e)
+        {
+            if (!this.TES3PluginLoader.PluginLoaded) return;
+
+            if (!this.TES3PluginLoader.PluginSavingIsImplemented)
+            {
+                MessageBox.Show("Plugin Saving has not been implemetned", "Unimplemented Function:", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                return;
+            }
+
+            DialogResult result = PluginSaver.ShowDialog();
+            string PluginFile = PluginSaver.FileName;
+            if (result != DialogResult.OK) return;
 
+            if (!this.TES3PluginLoader.SaveAs(PluginFile))
+            {
+                MessageBox.Show("Failed to Save Plugin As: " + PluginFile + "\n\nReason: \n\n" + this.TES3PluginLoader.PluginLoadFailureReason, "Failed to Save File As:", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+            else
+            {
+                MessageBox.Show("Successfully Saved Plugin: " + PluginFile, "Successfully Saved File:", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            }
+        }
         private void mnuItemOpenPlugin_Click(object sender, EventArgs e)
         {
+            this.log.Clear();
             PluginLoader.InitialDirectory = MorrowindDataFilesPath;
             DialogResult result = PluginLoader.ShowDialog();
             string PluginFile = PluginLoader.FileName;
             if (result != DialogResult.OK) return;
             //MessageBox.Show("Load Plugin: " + PluginLoader.FileName);
-            this.TES3PluginLoader = new TES3PluginLoader(PluginFile);
+            this.TES3PluginLoader = new TES3PluginLoader(PluginFile, this.log);
             if (!this.LoadPlugin(PluginFile))
             {
                 MessageBox.Show("Failed to Load Plugin: " + PluginFile + "\n\nReason: \n\n" + this.TES3PluginLoader.PluginLoadFailureReason, "Failed to Load File:", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
+
+        private void lstClothingEntries_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            ClothingEntry chosen_entry = null;
+            editor_flow.Enabled = false;
+            btnCommitEntry.Tag = null;
+            foreach (KeyValuePair<string, ClothingEntry> entry in this.TES3PluginLoader.ClothingSection.ClothingEntries)
+            {
+                string key = lstClothingEntries.Items[lstClothingEntries.SelectedIndex].ToString();
+                if (key == entry.Key) { chosen_entry = entry.Value; break; }
+            }
+            if (chosen_entry == null) return;
+            this.PopulateEditorData(chosen_entry);
+        }
+
+        private void PopulateEditorData(ClothingEntry entry)
+        {
+            if (entry == null) return;
+            editor_flow.Enabled = true;
+
+            btnCommitEntry.Tag = entry;
+
+            txtClothingName.Text = entry.CLOT_NAME;
+
+            int actual_type = entry.CLOT_CTDT_TYPE;
+            //int actual_type = 0x00000F9;         
+
+            byte type = (byte)(actual_type & 0x0000000F);
+            byte index = (byte)((actual_type & 0x000000F0) >> 4);
+
+            // Set the clothing type in the drop down
+            foreach (string item in comboClothingType.Items)
+            {
+                string type_name = Enum.GetName(typeof(ClothingTypes), type);
+                bool HaveUnknownType = false;
+                foreach (int val in Enum.GetValues(typeof(ClothingTypes)))
+                {
+                    if (type == val) { HaveUnknownType = false; break; }
+                    else { HaveUnknownType = true; }
+                }
+                if (HaveUnknownType) { comboClothingType.Text = "Unknown"; break; }
+                if (item == type_name)
+                {
+                    comboClothingType.SelectedIndex = comboClothingType.Items.IndexOf(item);
+                    comboClothingType.Text = item;
+                    break;
+                }
+            }
+            foreach (string item_index in comboCustomClothingSlotIndex.Items)
+            {
+                if (index == 0) { comboCustomClothingSlotIndex.Text = "Default"; break; }
+                else if (item_index == string.Format("0x{0:X2}",index))
+                {
+                    comboCustomClothingSlotIndex.SelectedIndex = comboCustomClothingSlotIndex.Items.IndexOf(item_index);
+                    comboCustomClothingSlotIndex.Text = item_index.ToString();
+                    break;
+                }
+            }
+        }
+
+        private void Form1_Shown(object sender, EventArgs e) { editor_flow.Enabled = false; }
+
+        private void btnCommitEntry_Click(object sender, EventArgs e)
+        {
+            ClothingEntry entry = (btnCommitEntry.Tag as ClothingEntry);
+            if (entry == null) return;
+
+
+            int unknown1 = 0;
+            byte type = 0;
+            byte index = 0;
+
+            unknown1 = entry.CLOT_CTDT_TYPE;
+            //unknown1 = 0x12345609;
+
+            if (comboClothingType.Items[comboClothingType.SelectedIndex].ToString() == "Unknown")
+            {
+                type = (byte)(unknown1 & 0x0000000F);
+            }
+            else
+            {
+                string type_name = comboClothingType.Items[comboClothingType.SelectedIndex].ToString();
+                byte type_value = (byte)((entry.CLOT_CTDT_TYPE & 0x000000FF) >> 0);
+                foreach (int val in Enum.GetValues(typeof(ClothingTypes)))
+                {
+                    if (Enum.GetName(typeof(ClothingTypes), val) == type_name) { type_value = (byte)val; break; }
+                }
+                type = Convert.ToByte(type_value);
+            }
+
+
+            if (comboCustomClothingSlotIndex.Items[comboCustomClothingSlotIndex.SelectedIndex].ToString() == "Default") { index = 0; }
+            else { index = Convert.ToByte(comboCustomClothingSlotIndex.Items[comboCustomClothingSlotIndex.SelectedIndex].ToString(),16); }
+            
+            //int SlotIndex = (index << 24) | type;
+            int SlotIndex = (index << 4) | type | (int)(unknown1 & 0xFFFFFF00);
+
+
+            if (CommitClothingEntry(entry, SlotIndex))
+            {
+                MessageBox.Show("Successfully Commited: " + entry.CLOT_NAME, "Clothing Entry Commit:", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            }
+            else
+            {
+                MessageBox.Show("Failed to Commit: " + entry.CLOT_NAME, "Clothing Entry Commit:", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+        }
+
+        private bool CommitClothingEntry(ClothingEntry entry, int SlotIndex)
+        {
+            bool ret = false;
+            entry.CLOT_CTDT_TYPE = SlotIndex;
+            ret = entry.Commit(this.TES3PluginLoader);
+            return ret;
+        }   
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22