/
EquipMeGui.cs
253 lines (212 loc) · 7.59 KB
/
EquipMeGui.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//!CompilerOption:AddRef:System.Design.dll
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using Styx;
using Styx.Helpers;
using Styx.Logic.Inventory;
namespace EquipMe
{
public partial class EquipMeGui : Form
{
public EquipMeGui()
{
InitializeComponent();
}
private void EquipMeGui_Load(object sender, EventArgs e)
{
EquipMeSettings.Instance.LoadSettings();
UpdatePropertyGrids();
}
private void EquipMeGui_FormClosing(object sender, FormClosingEventArgs e)
{
EquipMeSettings.Instance.SaveSettings();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
UpdatePropertyGrids();
}
private void button1_Click(object sender, EventArgs e)
{
EquipMe.Log("Updating weights from wowhead");
EquipMe.UpdateWowhead();
UpdatePropertyGrids();
}
private void button2_Click(object sender, EventArgs e)
{
EquipMe.Log("Reloading settings from file");
EquipMeSettings.Instance.LoadSettings();
UpdatePropertyGrids();
}
private void button3_Click(object sender, EventArgs e)
{
try
{
var ofd = new OpenFileDialog();
ofd.InitialDirectory = Logging.ApplicationPath;
if (ofd.ShowDialog() == DialogResult.OK)
{
EquipMe.Log("Loading new weightset data from: {0}", ofd.FileName);
var loadedset = EquipMe.LoadWeightSetFromXML(ofd.FileName);
if (loadedset == null)
{
return;
}
EquipMeSettings.Instance.WeightSet_Current = loadedset;
}
}
catch (Exception ex)
{
EquipMe.Log("Error loading weighset, exception\n{0}", ex);
}
}
void UpdatePropertyGrids()
{
propertyGrid1.SelectedObject = EquipMeSettings.Instance;
propertyGrid2.SelectedObject = new DictionaryPropertyGridAdapter<Stat, float>(EquipMeSettings.Instance.WeightSet_Current.Weights, checkBox1.Checked);
}
#region DictionaryPropertyGridAdapter
// used to display weightset dictionary in propertygrid, don't touch!
class DictionaryPropertyGridAdapter<TKey, TValue> : ICustomTypeDescriptor
{
IDictionary<TKey, TValue> _dictionary;
bool _show0;
public DictionaryPropertyGridAdapter(IDictionary<TKey, TValue> d, bool b)
{
_dictionary = d;
_show0 = b;
}
public string GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
public string GetClassName()
{
return TypeDescriptor.GetClassName(this, true);
}
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
EventDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
public object GetPropertyOwner(PropertyDescriptor pd)
{
return _dictionary;
}
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(this, true);
}
public object GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType, true);
}
public PropertyDescriptor GetDefaultProperty()
{
return null;
}
PropertyDescriptorCollection
System.ComponentModel.ICustomTypeDescriptor.GetProperties()
{
return ((ICustomTypeDescriptor)this).GetProperties(new Attribute[0]);
}
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
ArrayList properties = new ArrayList();
foreach (KeyValuePair<TKey, TValue> e in _dictionary)
{
if (!_show0 && EquipMe.ToFloat(_dictionary[e.Key].ToString()) == 0)
{
continue;
}
properties.Add(new DictionaryPropertyDescriptor<TKey, TValue>(_dictionary, e.Key));
}
PropertyDescriptor[] props =
(PropertyDescriptor[])properties.ToArray(typeof(PropertyDescriptor));
return new PropertyDescriptorCollection(props);
}
}
class DictionaryPropertyDescriptor<TKey, TValue> : PropertyDescriptor
{
IDictionary<TKey, TValue> _dictionary;
TKey _key;
public override string Category
{
get
{
return "Weightset";
}
}
internal DictionaryPropertyDescriptor(IDictionary<TKey, TValue> d, TKey key)
: base(key.ToString(), null)
{
_dictionary = d;
_key = key;
}
public override Type PropertyType
{
get { return _dictionary[_key].GetType(); }
}
public override void SetValue(object component, object value)
{
_dictionary[_key] = (TValue)value;
}
public override object GetValue(object component)
{
return _dictionary[_key];
}
public override bool IsReadOnly
{
get { return false; }
}
public override Type ComponentType
{
get { return null; }
}
public override bool CanResetValue(object component)
{
return false;
}
public override void ResetValue(object component)
{
}
public override bool ShouldSerializeValue(object component)
{
return false;
}
}
#endregion
private void button4_Click(object sender, EventArgs e)
{
foreach (var item in StyxWoW.Me.Inventory.Equipped.Items)
{
if (item == null)
{
continue;
}
EquipMe.Log("Equipped: {0}, score: {1}, inv type: {2}, wep class: {3}", item.Name, EquipMe.CalcScore(item), item.ItemInfo.InventoryType, item.ItemInfo.WeaponClass);
}
foreach (var item in StyxWoW.Me.BagItems)
{
if (item == null)
{
continue;
}
EquipMe.Log("Bag: {0}, score: {1}, inv type: {2}, wep class: {3}", item.Name, EquipMe.CalcScore(item), item.ItemInfo.InventoryType, item.ItemInfo.WeaponClass);
}
}
}
}