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

Contents of /trunk/MorrowindCustomClothingSlotCreator/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 38 - (show annotations) (download)
Sat Jul 30 13:58:26 2011 UTC (9 years ago) by william
File size: 9557 byte(s)
comboCustomClothingSlotIndex
** add 'Default' entry
** make index from 0x1 to 0xf

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 = 0x01020309;
133
134 byte type = (byte)( (actual_type & 0x000000FF) >> 0);
135 byte unknown2 = (byte)((actual_type & 0x0000FF00) >> 8);
136 byte unknown1 = (byte)((actual_type & 0x00FF0000) >> 16);
137 byte index = (byte)((uint)(actual_type & 0xFF000000) >> 24);
138
139 // Set the clothing type in the drop down
140 foreach (string item in comboClothingType.Items)
141 {
142 string type_name = Enum.GetName(typeof(ClothingTypes), type);
143 bool HaveUnknownType = false;
144 foreach (int val in Enum.GetValues(typeof(ClothingTypes)))
145 {
146 if (type == val) { HaveUnknownType = false; break; }
147 else { HaveUnknownType = true; }
148 }
149 if (HaveUnknownType) { comboClothingType.Text = "Unknown"; break; }
150 if (item == type_name)
151 {
152 comboClothingType.SelectedIndex = comboClothingType.Items.IndexOf(item);
153 comboClothingType.Text = item;
154 break;
155 }
156 }
157 foreach (string item_index in comboCustomClothingSlotIndex.Items)
158 {
159 if (index == 0) { comboCustomClothingSlotIndex.Text = "Default"; break; }
160 else if (item_index == string.Format("0x{0:X2}",index))
161 {
162 comboCustomClothingSlotIndex.SelectedIndex = comboCustomClothingSlotIndex.Items.IndexOf(item_index);
163 comboCustomClothingSlotIndex.Text = item_index.ToString();
164 break;
165 }
166 }
167 }
168
169 private void Form1_Shown(object sender, EventArgs e) { editor_flow.Enabled = false; }
170
171 private void btnCommitEntry_Click(object sender, EventArgs e)
172 {
173 ClothingEntry entry = (btnCommitEntry.Tag as ClothingEntry);
174 if (entry == null) return;
175
176 byte type = 0;
177 byte index = 0;
178
179 if (comboClothingType.Items[comboClothingType.SelectedIndex].ToString() == "Unknown")
180 {
181 type = (byte)((entry.CLOT_CTDT_TYPE & 0x000000FF) >> 0);
182 }
183 else
184 {
185 string type_name = comboClothingType.Items[comboClothingType.SelectedIndex].ToString();
186 byte type_value = (byte)((entry.CLOT_CTDT_TYPE & 0x000000FF) >> 0);
187 foreach (int val in Enum.GetValues(typeof(ClothingTypes)))
188 {
189 if (Enum.GetName(typeof(ClothingTypes), val) == type_name) { type_value = (byte)val; break; }
190 }
191 type = Convert.ToByte(type_value);
192 }
193
194
195 if (comboCustomClothingSlotIndex.Items[comboCustomClothingSlotIndex.SelectedIndex].ToString() == "Default") { index = 0; }
196 else { index = Convert.ToByte(comboCustomClothingSlotIndex.Items[comboCustomClothingSlotIndex.SelectedIndex].ToString(),16); }
197
198
199
200 int SlotIndex = (index << 24) | type;
201 if (CommitClothingEntry(entry, SlotIndex))
202 {
203 MessageBox.Show("Successfully Commited: " + entry.CLOT_NAME, "Clothing Entry Commit:", MessageBoxButtons.OK, MessageBoxIcon.Information);
204 }
205 else
206 {
207 MessageBox.Show("Failed to Commit: " + entry.CLOT_NAME, "Clothing Entry Commit:", MessageBoxButtons.OK, MessageBoxIcon.Error);
208 }
209 }
210
211 private bool CommitClothingEntry(ClothingEntry entry, int SlotIndex)
212 {
213 bool ret = false;
214 entry.CLOT_CTDT_TYPE = SlotIndex;
215 ret = entry.Commit(this.TES3PluginLoader);
216 return ret;
217 }
218 }
219 }

  ViewVC Help
Powered by ViewVC 1.1.22