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

Contents of /trunk/MorrowindCustomClothingSlotCreator/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 40 - (show annotations) (download)
Sat Jul 30 14:21:44 2011 UTC (8 years, 1 month ago) by william
File size: 9592 byte(s)
int actual_type = entry.CLOT_CTDT_TYPE; (uncommeted this)
//int actual_type = 0x00000F9; (commented this, was for testing bit shifts)

1 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
26 foreach (int val in Enum.GetValues(typeof(ClothingTypes))) { comboClothingType.Items.Add(Enum.GetName(typeof(ClothingTypes), val)); }
27 comboCustomClothingSlotIndex.Items.Add("Default");
28 for (int i = 1; i < 0x10; i++) { comboCustomClothingSlotIndex.Items.Add("0x" + i.ToString("X2")); }
29
30 }
31
32 public bool LoadPlugin(string pluginFile)
33 {
34 bool loaded = this.TES3PluginLoader.Load();
35
36 if (loaded)
37 {
38 foreach (KeyValuePair<string,ClothingEntry> entry in this.TES3PluginLoader.ClothingSection.ClothingEntries)
39 {
40 lstClothingEntries.Items.Add(entry.Key);
41 }
42 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 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
74 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 private void mnuItemOpenPlugin_Click(object sender, EventArgs e)
94 {
95 this.log.Clear();
96 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 this.TES3PluginLoader = new TES3PluginLoader(PluginFile, this.log);
102 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
108 private void lstClothingEntries_SelectedIndexChanged(object sender, EventArgs e)
109 {
110 ClothingEntry chosen_entry = null;
111 editor_flow.Enabled = false;
112 btnCommitEntry.Tag = null;
113 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 this.PopulateEditorData(chosen_entry);
120 }
121
122 private void PopulateEditorData(ClothingEntry entry)
123 {
124 if (entry == null) return;
125 editor_flow.Enabled = true;
126
127 btnCommitEntry.Tag = entry;
128
129 txtClothingName.Text = entry.CLOT_NAME;
130
131 int actual_type = entry.CLOT_CTDT_TYPE;
132 //int actual_type = 0x00000F9;
133
134 byte type = (byte)(actual_type & 0x0000000F);
135 byte index = (byte)((actual_type & 0x000000F0) >> 4);
136
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
169 private void btnCommitEntry_Click(object sender, EventArgs e)
170 {
171 ClothingEntry entry = (btnCommitEntry.Tag as ClothingEntry);
172 if (entry == null) return;
173
174
175 int unknown1 = 0;
176 byte type = 0;
177 byte index = 0;
178
179 unknown1 = entry.CLOT_CTDT_TYPE;
180 //unknown1 = 0x12345609;
181
182 if (comboClothingType.Items[comboClothingType.SelectedIndex].ToString() == "Unknown")
183 {
184 type = (byte)(unknown1 & 0x0000000F);
185 }
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 //int SlotIndex = (index << 24) | type;
202 int SlotIndex = (index << 4) | type | (int)(unknown1 & 0xFFFFFF00);
203
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 }
223 }

  ViewVC Help
Powered by ViewVC 1.1.22