-
Notifications
You must be signed in to change notification settings - Fork 15
/
FormItemInstance.cs
208 lines (194 loc) · 7.28 KB
/
FormItemInstance.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
using System;
using System.Windows.Forms;
using System.Drawing;
namespace Rawr
{
public partial class FormItemInstance : Form, IFormItemSelectionProvider
{
private FormItemSelection _formItemSelection;
public FormItemSelection FormItemSelection
{
get
{
if (_formItemSelection == null || _formItemSelection.IsDisposed)
{
_formItemSelection = new FormItemSelection();
_formItemSelection.Character = FormMain.Instance.FormItemSelection.Character;
_formItemSelection.CurrentCalculations = FormMain.Instance.FormItemSelection.CurrentCalculations;
}
return _formItemSelection;
}
}
public FormItemInstance()
{
InitializeComponent();
}
public CharacterSlot CharacterSlot
{
get
{
return itemButtonWithEnchant.CharacterSlot;
}
set
{
itemButtonWithEnchant.CharacterSlot = value;
}
}
public ItemInstance ItemInstance
{
get
{
return itemButtonWithEnchant.SelectedItem;
}
set
{
if (value != null)
{
itemButtonWithEnchant.SelectedItem = value;
gem1Button.SelectedItem = value.Gem1;
gem2Button.SelectedItem = value.Gem2;
gem3Button.SelectedItem = value.Gem3;
}
else
{
itemButtonWithEnchant.SelectedItem = null;
gem1Button.SelectedItem = null;
gem2Button.SelectedItem = null;
gem3Button.SelectedItem = null;
}
UpdateSockets();
}
}
private void gem1Button_Leave(object sender, EventArgs e)
{
if (ItemInstance != null)
{
ItemInstance copy = ItemInstance.Clone();
copy.Gem1 = gem1Button.SelectedItem;
itemButtonWithEnchant.SelectedItem = copy;
}
}
private void gem2Button_Leave(object sender, EventArgs e)
{
if (ItemInstance != null)
{
ItemInstance copy = ItemInstance.Clone();
copy.Gem2 = gem2Button.SelectedItem;
itemButtonWithEnchant.SelectedItem = copy;
}
}
private void gem3Button_Leave(object sender, EventArgs e)
{
if (ItemInstance != null)
{
ItemInstance copy = ItemInstance.Clone();
copy.Gem3 = gem3Button.SelectedItem;
itemButtonWithEnchant.SelectedItem = copy;
}
}
private void itemButtonWithEnchant_Leave(object sender, EventArgs e)
{
UpdateSockets();
}
private void UpdateSockets()
{
if (ItemInstance != null && ItemInstance.Item != null)
{
Item item = ItemInstance.Item;
bool blacksmithingSocket = true;
Character character = FormItemSelection.Character;
if ((itemButtonWithEnchant.CharacterSlot == CharacterSlot.Waist && character.WaistBlacksmithingSocketEnabled)
|| (itemButtonWithEnchant.CharacterSlot == CharacterSlot.Waist && character.WaistBlacksmithingSocketEnabled)
|| (itemButtonWithEnchant.CharacterSlot == CharacterSlot.Waist && character.WaistBlacksmithingSocketEnabled))
{
blacksmithingSocket = true;
}
ItemSlot slot = item.SocketColor1;
if (slot == ItemSlot.None && blacksmithingSocket)
{
slot = ItemSlot.Prismatic;
blacksmithingSocket = false;
}
SetSocketColor(gem1Button, slot);
slot = item.SocketColor2;
if (slot == ItemSlot.None && blacksmithingSocket)
{
slot = ItemSlot.Prismatic;
blacksmithingSocket = false;
}
SetSocketColor(gem2Button, slot);
slot = item.SocketColor3;
if (slot == ItemSlot.None && blacksmithingSocket)
{
slot = ItemSlot.Prismatic;
blacksmithingSocket = false;
}
SetSocketColor(gem3Button, slot);
}
else
{
SetSocketColor(gem1Button, ItemSlot.None);
SetSocketColor(gem2Button, ItemSlot.None);
SetSocketColor(gem3Button, ItemSlot.None);
}
}
private void SetSocketColor(ItemButton button, ItemSlot slot)
{
switch (slot)
{
case ItemSlot.Blue:
button.BackColor = Color.FromKnownColor(KnownColor.Blue);
button.CharacterSlot = CharacterSlot.Gems;
break;
case ItemSlot.Red:
button.BackColor = Color.FromKnownColor(KnownColor.Red);
button.CharacterSlot = CharacterSlot.Gems;
break;
case ItemSlot.Yellow:
button.BackColor = Color.FromKnownColor(KnownColor.Yellow);
button.CharacterSlot = CharacterSlot.Gems;
break;
case ItemSlot.Prismatic:
button.BackColor = Color.FromKnownColor(KnownColor.Silver);
button.CharacterSlot = CharacterSlot.Gems;
break;
case ItemSlot.Meta:
button.BackColor = Color.FromKnownColor(KnownColor.Gray);
button.CharacterSlot = CharacterSlot.Metas;
break;
default:
button.BackColor = SystemColors.Control;
button.CharacterSlot = CharacterSlot.Gems;
break;
}
}
private void gem1Button_Click(object sender, EventArgs e)
{
ItemInstance item = ItemInstance.Clone();
item.Gem1 = null;
SetFormItemSelection(item);
}
private void gem2Button_Click(object sender, EventArgs e)
{
ItemInstance item = ItemInstance.Clone();
item.Gem2 = null;
SetFormItemSelection(item);
}
private void gem3Button_Click(object sender, EventArgs e)
{
ItemInstance item = ItemInstance.Clone();
item.Gem3 = null;
SetFormItemSelection(item);
}
private void SetFormItemSelection(ItemInstance item)
{
if (FormMain.Instance.FormItemSelection.Character != null)
{
Character emptyGemCharacter = FormMain.Instance.FormItemSelection.Character.Clone();
emptyGemCharacter[CharacterSlot] = item;
_formItemSelection.Character = emptyGemCharacter;
_formItemSelection.CurrentCalculations = Calculations.GetCharacterCalculations(emptyGemCharacter);
}
}
}
}