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

Contents of /trunk/MorrowindCustomClothingSlotCreator/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Sat Jul 30 09:59:11 2011 UTC (8 years, 6 months ago) by william
File size: 5256 byte(s)
*** implement populating editor with clothing entry data

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
53 private void mnuItemOpenPlugin_Click(object sender, EventArgs e)
54 {
55 this.log.Clear();
56 PluginLoader.InitialDirectory = MorrowindDataFilesPath;
57 DialogResult result = PluginLoader.ShowDialog();
58 string PluginFile = PluginLoader.FileName;
59 if (result != DialogResult.OK) return;
60 //MessageBox.Show("Load Plugin: " + PluginLoader.FileName);
61 this.TES3PluginLoader = new TES3PluginLoader(PluginFile, this.log);
62 if (!this.LoadPlugin(PluginFile))
63 {
64 MessageBox.Show("Failed to Load Plugin: " + PluginFile + "\n\nReason: \n\n" + this.TES3PluginLoader.PluginLoadFailureReason, "Failed to Load File:", MessageBoxButtons.OK, MessageBoxIcon.Error);
65 }
66 }
67
68 private void lstClothingEntries_SelectedIndexChanged(object sender, EventArgs e)
69 {
70 ClothingEntry chosen_entry = null;
71 editor_flow.Enabled = false;
72 foreach (KeyValuePair<string, ClothingEntry> entry in this.TES3PluginLoader.ClothingSection.ClothingEntries)
73 {
74 string key = lstClothingEntries.Items[lstClothingEntries.SelectedIndex].ToString();
75 if (key == entry.Key) { chosen_entry = entry.Value; break; }
76 }
77 if (chosen_entry == null) return;
78 this.PopulateEditorData(chosen_entry);
79 }
80
81 private void PopulateEditorData(ClothingEntry entry)
82 {
83 if (entry == null) return;
84 editor_flow.Enabled = true;
85 txtClothingName.Text = entry.CLOT_NAME;
86
87 int actual_type = entry.CLOT_CTDT_TYPE;
88 //int actual_type = 0x01020309;
89
90 int type = (actual_type & 0x000000FF) >> 0;
91 int unknown2 = (actual_type & 0x0000FF00) >> 8;
92 int unknown1 = (actual_type & 0x00FF0000) >> 16;
93 int index = (int)(actual_type & 0xFF000000) >> 24;
94
95 // Set the clothing type in the drop down
96 foreach (string item in comboClothingType.Items)
97 {
98 string type_name = Enum.GetName(typeof(ClothingTypes), type);
99 bool HaveUnknownType = false;
100 foreach (int val in Enum.GetValues(typeof(ClothingTypes)))
101 {
102 if (type == val) { HaveUnknownType = false; break; }
103 else { HaveUnknownType = true; }
104 }
105 if (HaveUnknownType) { comboClothingType.Text = "Unknown"; break; }
106 if (item == type_name)
107 {
108 comboClothingType.SelectedIndex = comboClothingType.Items.IndexOf(item);
109 comboClothingType.Text = item;
110 break;
111 }
112 }
113 foreach (string item_index in comboCustomClothingSlotIndex.Items)
114 {
115 if (index == 0) { comboCustomClothingSlotIndex.Text = "Default"; break; }
116 else if (item_index == string.Format("0x{0:X2}",index))
117 {
118 comboCustomClothingSlotIndex.SelectedIndex = comboCustomClothingSlotIndex.Items.IndexOf(item_index);
119 comboCustomClothingSlotIndex.Text = item_index.ToString();
120 break;
121 }
122 }
123 }
124
125 private void Form1_Shown(object sender, EventArgs e) { editor_flow.Enabled = false; }
126 }
127 }

  ViewVC Help
Powered by ViewVC 1.1.22