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

Contents of /trunk/MorrowindCustomClothingSlotCreator/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Sat Jul 30 12:34:22 2011 UTC (8 years, 5 months ago) by william
File size: 9493 byte(s)
*** report sucess if Save or SaveAs succeds

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

  ViewVC Help
Powered by ViewVC 1.1.22