/[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 12:33:46	34
+++ trunk/MorrowindCustomClothingSlotCreator/Form1.cs	2011/07/30 12:34:22	35
@@ -49,7 +49,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 +108,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 +122,18 @@
         {
             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 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 & 0x000000FF) >> 0);
+            byte unknown2 = (byte)((actual_type & 0x0000FF00) >> 8);
+            byte unknown1 = (byte)((actual_type & 0x00FF0000) >> 16);
+            byte index = (byte)((uint)(actual_type & 0xFF000000) >> 24);
 
             // Set the clothing type in the drop down
             foreach (string item in comboClothingType.Items)
@@ -123,5 +166,53 @@
         }
 
         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;
+
+            byte type = 0;
+            byte index = 0;
+
+            if (comboClothingType.Items[comboClothingType.SelectedIndex].ToString() == "Unknown")
+            {
+                type = (byte)((entry.CLOT_CTDT_TYPE & 0x000000FF) >> 0);
+            }
+            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;
+            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