/[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/30 09:59:11	32
+++ trunk/MorrowindCustomClothingSlotCreator/Form1.cs	2011/07/30 14:21:44	40
@@ -24,7 +24,8 @@
             this.TES3PluginLoader = new TES3PluginLoader();
 
             foreach (int val in Enum.GetValues(typeof(ClothingTypes))) { comboClothingType.Items.Add(Enum.GetName(typeof(ClothingTypes), val)); }
-            for (int i = 1; i < 0x100; i++) { comboCustomClothingSlotIndex.Items.Add("0x" + i.ToString("X2")); }
+            comboCustomClothingSlotIndex.Items.Add("Default"); 
+            for (int i = 1; i < 0x10; i++) { comboCustomClothingSlotIndex.Items.Add("0x" + i.ToString("X2")); }
 
         }
 
@@ -49,7 +50,46 @@
         {
             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();
@@ -69,6 +109,7 @@
         {
             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();
@@ -82,15 +123,16 @@
         {
             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 = 0x01020309;
+            //int actual_type = 0x00000F9;         
 
-            int type = (actual_type & 0x000000FF) >> 0;
-            int unknown2 = (actual_type & 0x0000FF00) >> 8;
-            int unknown1 = (actual_type & 0x00FF0000) >> 16;
-            int index = (int)(actual_type & 0xFF000000) >> 24;
+            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)
@@ -123,5 +165,59 @@
         }
 
         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