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

Annotation of /trunk/MorrowindCustomClothingSlotCreator/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (hide annotations) (download)
Sat Jul 30 14:20:13 2011 UTC (8 years, 5 months ago) by william
File size: 9592 byte(s)
** handle the lower byte for clothing slots

Each type would be as follows:
0x0X-0xfX (where x is 0x0-0x9 clothing type)

construct the commited values as such, but also include the upper 3 bytes

1 william 4 using System;
2     using System.Collections.Generic;
3     using System.ComponentModel;
4     using System.Data;
5     using System.Drawing;
6     using System.Text;
7     using System.Windows.Forms;
8     using libTES3FileFormat;
9    
10     namespace MorrowindCustomClothingSlotCreator
11     {
12    
13     public partial class Form1 : Form
14     {
15     public static MorrowindPathHelper MorrowindData = new MorrowindPathHelper();
16     public static string MorrowindPath = MorrowindData.MorrowindInstallPath;
17     public static string MorrowindDataFilesPath = MorrowindPath + "\\Data Files\\";
18    
19     private TES3PluginLoader TES3PluginLoader;
20    
21     public Form1()
22     {
23     InitializeComponent();
24     this.TES3PluginLoader = new TES3PluginLoader();
25 william 32
26     foreach (int val in Enum.GetValues(typeof(ClothingTypes))) { comboClothingType.Items.Add(Enum.GetName(typeof(ClothingTypes), val)); }
27 william 38 comboCustomClothingSlotIndex.Items.Add("Default");
28     for (int i = 1; i < 0x10; i++) { comboCustomClothingSlotIndex.Items.Add("0x" + i.ToString("X2")); }
29 william 32
30 william 4 }
31    
32     public bool LoadPlugin(string pluginFile)
33     {
34     bool loaded = this.TES3PluginLoader.Load();
35    
36     if (loaded)
37     {
38 william 31 foreach (KeyValuePair<string,ClothingEntry> entry in this.TES3PluginLoader.ClothingSection.ClothingEntries)
39 william 23 {
40 william 31 lstClothingEntries.Items.Add(entry.Key);
41 william 23 }
42 william 4 MessageBox.Show("Successfully Loaded Plugin: " + pluginFile, "Successfully Loaded File:", MessageBoxButtons.OK, MessageBoxIcon.Information);
43     }
44    
45     return loaded;
46     }
47    
48    
49     private void mnuItemExit_Click(object sender, EventArgs e)
50     {
51     this.Close();
52     }
53 william 35 private void mnuItemSavePlugin_Click(object sender, EventArgs e)
54     {
55     if (!this.TES3PluginLoader.PluginLoaded) return;
56     if (!this.TES3PluginLoader.PluginSavingIsImplemented)
57     {
58     MessageBox.Show("Plugin Saving has not been implemetned", "Unimplemented Function:", MessageBoxButtons.OK, MessageBoxIcon.Error);
59     return;
60     }
61     if (!this.TES3PluginLoader.Save())
62     {
63     MessageBox.Show("Failed to Save Plugin: " + this.TES3PluginLoader.PluginFile + "\n\nReason: \n\n" + this.TES3PluginLoader.PluginLoadFailureReason, "Failed to Save File:", MessageBoxButtons.OK, MessageBoxIcon.Error);
64     }
65     else
66     {
67     MessageBox.Show("Successfully Saved Plugin: " + this.TES3PluginLoader.PluginFile, "Successfully Saved File:", MessageBoxButtons.OK, MessageBoxIcon.Information);
68     }
69     }
70     private void mnuItemSavePluginAs_Click(object sender, EventArgs e)
71     {
72     if (!this.TES3PluginLoader.PluginLoaded) return;
73 william 4
74 william 35 if (!this.TES3PluginLoader.PluginSavingIsImplemented)
75     {
76     MessageBox.Show("Plugin Saving has not been implemetned", "Unimplemented Function:", MessageBoxButtons.OK, MessageBoxIcon.Error);
77     return;
78     }
79    
80     DialogResult result = PluginSaver.ShowDialog();
81     string PluginFile = PluginSaver.FileName;
82     if (result != DialogResult.OK) return;
83    
84     if (!this.TES3PluginLoader.SaveAs(PluginFile))
85     {
86     MessageBox.Show("Failed to Save Plugin As: " + PluginFile + "\n\nReason: \n\n" + this.TES3PluginLoader.PluginLoadFailureReason, "Failed to Save File As:", MessageBoxButtons.OK, MessageBoxIcon.Error);
87     }
88     else
89     {
90     MessageBox.Show("Successfully Saved Plugin: " + PluginFile, "Successfully Saved File:", MessageBoxButtons.OK, MessageBoxIcon.Information);
91     }
92     }
93 william 4 private void mnuItemOpenPlugin_Click(object sender, EventArgs e)
94     {
95 william 17 this.log.Clear();
96 william 4 PluginLoader.InitialDirectory = MorrowindDataFilesPath;
97     DialogResult result = PluginLoader.ShowDialog();
98     string PluginFile = PluginLoader.FileName;
99     if (result != DialogResult.OK) return;
100     //MessageBox.Show("Load Plugin: " + PluginLoader.FileName);
101 william 8 this.TES3PluginLoader = new TES3PluginLoader(PluginFile, this.log);
102 william 4 if (!this.LoadPlugin(PluginFile))
103     {
104     MessageBox.Show("Failed to Load Plugin: " + PluginFile + "\n\nReason: \n\n" + this.TES3PluginLoader.PluginLoadFailureReason, "Failed to Load File:", MessageBoxButtons.OK, MessageBoxIcon.Error);
105     }
106     }
107 william 23
108     private void lstClothingEntries_SelectedIndexChanged(object sender, EventArgs e)
109     {
110 william 31 ClothingEntry chosen_entry = null;
111 william 32 editor_flow.Enabled = false;
112 william 35 btnCommitEntry.Tag = null;
113 william 31 foreach (KeyValuePair<string, ClothingEntry> entry in this.TES3PluginLoader.ClothingSection.ClothingEntries)
114     {
115     string key = lstClothingEntries.Items[lstClothingEntries.SelectedIndex].ToString();
116     if (key == entry.Key) { chosen_entry = entry.Value; break; }
117     }
118     if (chosen_entry == null) return;
119 william 32 this.PopulateEditorData(chosen_entry);
120 william 23 }
121 william 32
122     private void PopulateEditorData(ClothingEntry entry)
123     {
124     if (entry == null) return;
125     editor_flow.Enabled = true;
126 william 35
127     btnCommitEntry.Tag = entry;
128    
129 william 32 txtClothingName.Text = entry.CLOT_NAME;
130    
131 william 39 //int actual_type = entry.CLOT_CTDT_TYPE;
132     int actual_type = 0x00000F9;
133 william 32
134 william 39 byte type = (byte)(actual_type & 0x0000000F);
135     byte index = (byte)((actual_type & 0x000000F0) >> 4);
136 william 32
137     // Set the clothing type in the drop down
138     foreach (string item in comboClothingType.Items)
139     {
140     string type_name = Enum.GetName(typeof(ClothingTypes), type);
141     bool HaveUnknownType = false;
142     foreach (int val in Enum.GetValues(typeof(ClothingTypes)))
143     {
144     if (type == val) { HaveUnknownType = false; break; }
145     else { HaveUnknownType = true; }
146     }
147     if (HaveUnknownType) { comboClothingType.Text = "Unknown"; break; }
148     if (item == type_name)
149     {
150     comboClothingType.SelectedIndex = comboClothingType.Items.IndexOf(item);
151     comboClothingType.Text = item;
152     break;
153     }
154     }
155     foreach (string item_index in comboCustomClothingSlotIndex.Items)
156     {
157     if (index == 0) { comboCustomClothingSlotIndex.Text = "Default"; break; }
158     else if (item_index == string.Format("0x{0:X2}",index))
159     {
160     comboCustomClothingSlotIndex.SelectedIndex = comboCustomClothingSlotIndex.Items.IndexOf(item_index);
161     comboCustomClothingSlotIndex.Text = item_index.ToString();
162     break;
163     }
164     }
165     }
166    
167     private void Form1_Shown(object sender, EventArgs e) { editor_flow.Enabled = false; }
168 william 35
169     private void btnCommitEntry_Click(object sender, EventArgs e)
170     {
171     ClothingEntry entry = (btnCommitEntry.Tag as ClothingEntry);
172     if (entry == null) return;
173    
174 william 39
175     int unknown1 = 0;
176 william 35 byte type = 0;
177     byte index = 0;
178    
179 william 39 unknown1 = entry.CLOT_CTDT_TYPE;
180     //unknown1 = 0x12345609;
181    
182 william 35 if (comboClothingType.Items[comboClothingType.SelectedIndex].ToString() == "Unknown")
183     {
184 william 39 type = (byte)(unknown1 & 0x0000000F);
185 william 35 }
186     else
187     {
188     string type_name = comboClothingType.Items[comboClothingType.SelectedIndex].ToString();
189     byte type_value = (byte)((entry.CLOT_CTDT_TYPE & 0x000000FF) >> 0);
190     foreach (int val in Enum.GetValues(typeof(ClothingTypes)))
191     {
192     if (Enum.GetName(typeof(ClothingTypes), val) == type_name) { type_value = (byte)val; break; }
193     }
194     type = Convert.ToByte(type_value);
195     }
196    
197    
198     if (comboCustomClothingSlotIndex.Items[comboCustomClothingSlotIndex.SelectedIndex].ToString() == "Default") { index = 0; }
199     else { index = Convert.ToByte(comboCustomClothingSlotIndex.Items[comboCustomClothingSlotIndex.SelectedIndex].ToString(),16); }
200    
201 william 39 //int SlotIndex = (index << 24) | type;
202     int SlotIndex = (index << 4) | type | (int)(unknown1 & 0xFFFFFF00);
203 william 35
204    
205     if (CommitClothingEntry(entry, SlotIndex))
206     {
207     MessageBox.Show("Successfully Commited: " + entry.CLOT_NAME, "Clothing Entry Commit:", MessageBoxButtons.OK, MessageBoxIcon.Information);
208     }
209     else
210     {
211     MessageBox.Show("Failed to Commit: " + entry.CLOT_NAME, "Clothing Entry Commit:", MessageBoxButtons.OK, MessageBoxIcon.Error);
212     }
213     }
214    
215     private bool CommitClothingEntry(ClothingEntry entry, int SlotIndex)
216     {
217     bool ret = false;
218     entry.CLOT_CTDT_TYPE = SlotIndex;
219     ret = entry.Commit(this.TES3PluginLoader);
220     return ret;
221     }
222 william 4 }
223     }

  ViewVC Help
Powered by ViewVC 1.1.22