forked from wowgaming/3.3.5-interface-files
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CoinPickupFrame.lua
248 lines (214 loc) · 6.35 KB
/
CoinPickupFrame.lua
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
COINFRAME_BINDING_CACHE = {}
function OpenCoinPickupFrame(multiplier, maxMoney, parent)
if ( CoinPickupFrame.owner ) then
CoinPickupFrame.owner.hasPickup = 0;
end
if ( GetCursorMoney() > 0 ) then
if ( CoinPickupFrame.owner ) then
MoneyTypeInfo[parent.moneyType].DropFunc(CoinPickupFrame);
PlaySound("igBackPackCoinSelect");
end
CoinPickupFrame:Hide();
return;
end
CoinPickupFrame.multiplier = multiplier;
CoinPickupFrame.maxMoney = floor(maxMoney / multiplier);
if ( CoinPickupFrame.maxMoney == 0 ) then
CoinPickupFrame:Hide();
return;
end
if ( ENABLE_COLORBLIND_MODE == "1" ) then
if ( not CoinPickupFrame.colorBlind ) then
CoinPickupCopperIcon:Hide();
CoinPickupSilverIcon:Hide();
CoinPickupGoldIcon:Hide();
CoinPickupText:SetPoint("RIGHT", -38, 18);
CoinPickupFrame.colorBlind = true;
end
if ( multiplier == 1 ) then
CoinPickupFrame.symbol = COPPER_AMOUNT_SYMBOL;
elseif ( multiplier == COPPER_PER_SILVER ) then
CoinPickupFrame.symbol = SILVER_AMOUNT_SYMBOL;
elseif ( multiplier == COPPER_PER_GOLD ) then
CoinPickupFrame.symbol = GOLD_AMOUNT_SYMBOL;
end
else
CoinPickupFrame.symbol = "";
if ( CoinPickupFrame.colorBlind ) then
CoinPickupText:SetPoint("RIGHT", -38, 18);
CoinPickupFrame.colorBlind = nil;
end
if ( multiplier == 1 ) then
CoinPickupCopperIcon:Show();
else
CoinPickupCopperIcon:Hide();
end
if ( multiplier == COPPER_PER_SILVER ) then
CoinPickupSilverIcon:Show();
else
CoinPickupSilverIcon:Hide();
end
if ( multiplier == (COPPER_PER_GOLD) ) then
CoinPickupGoldIcon:Show();
else
CoinPickupGoldIcon:Hide();
end
end
CoinPickupFrame.owner = parent;
CoinPickupFrame.money = 1;
CoinPickupFrame.typing = 0;
CoinPickupText:SetText(CoinPickupFrame.money .. CoinPickupFrame.symbol);
CoinPickupLeftButton:Disable();
CoinPickupRightButton:Enable();
CoinPickupFrame:SetPoint("BOTTOMRIGHT", parent, "TOPRIGHT", 0, 0);
CoinPickupFrame:Show();
PlaySound("igBackPackCoinSelect");
end
function UpdateCoinPickupFrame(maxMoney)
if ( not CoinPickupFrame.multiplier ) then
return;
end
CoinPickupFrame.maxMoney = floor(maxMoney / CoinPickupFrame.multiplier);
if ( CoinPickupFrame.maxMoney == 0 ) then
if ( CoinPickupFrame.owner ) then
CoinPickupFrame.owner.hasPickup = 0;
end
CoinPickupFrame:Hide();
return;
end
if ( not CoinPickupFrame.money or not CoinPickupFrame.maxMoney ) then
-- Failsafe
return;
end
if ( CoinPickupFrame.money > CoinPickupFrame.maxMoney ) then
CoinPickupFrame.money = CoinPickupFrame.maxMoney;
CoinPickupText:SetText(CoinPickupFrame.money .. CoinPickupFrame.symbol);
end
if ( CoinPickupFrame.money == CoinPickupFrame.maxMoney ) then
CoinPickupRightButton:Disable();
else
CoinPickupRightButton:Enable();
end
if ( CoinPickupFrame.money == 1 ) then
CoinPickupLeftButton:Disable();
else
CoinPickupLeftButton:Enable();
end
end
function CoinPickupFrame_OnChar(self, text)
if ( text < "0" or text > "9" ) then
return;
end
if ( self.typing == 0 ) then
self.typing = 1;
self.money = 0;
end
local money = (self.money * 10) + text;
if ( money == self.money ) then
if( self.money == 0 ) then
self.money = 1;
end
return;
end
if ( money <= self.maxMoney ) then
self.money = money;
CoinPickupText:SetText(money .. CoinPickupFrame.symbol);
if ( money == self.maxMoney ) then
CoinPickupRightButton:Disable();
else
CoinPickupRightButton:Enable();
end
if ( money == 1 ) then
CoinPickupLeftButton:Disable();
else
CoinPickupLeftButton:Enable();
end
elseif ( money == 0 ) then
self.money = 1;
end
end
function CoinPickupFrame_OnKeyDown(self, key)
if ( key == "BACKSPACE" or key == "DELETE" ) then
if ( self.typing == 0 or self.money == 1 ) then
return;
end
self.money = floor(self.money / 10);
if ( self.money <= 1 ) then
self.money = 1;
self.typing = 0;
CoinPickupLeftButton:Disable();
else
CoinPickupLeftButton:Enable();
end
CoinPickupText:SetText(self.money .. self.symbol);
if ( self.money == self.maxMoney ) then
CoinPickupRightButton:Disable();
else
CoinPickupRightButton:Enable();
end
elseif ( key == "ENTER" ) then
CoinPickupFrameOkay_Click();
elseif ( GetBindingFromClick(key) == "TOGGLEGAMEMENU" ) then
CoinPickupFrameCancel_Click();
elseif ( key == "LEFT" or key == "DOWN" ) then
CoinPickupFrameLeft_Click();
elseif ( key == "RIGHT" or key == "UP" ) then
CoinPickupFrameRight_Click();
elseif ( not ( tonumber(key) ) and GetBindingAction(key) ) then
--Running bindings not used by the CoinPickup frame allows players to retain control of their characters.
RunBinding(GetBindingAction(key));
end
COINFRAME_BINDING_CACHE[key] = true;
end
function CoinPickupFrame_OnKeyUp(self, key)
if ( not ( tonumber(key) ) and GetBindingAction(key) ) then
--If we don't run the up bindings as well, interesting things happen (like you never stop moving)
RunBinding(GetBindingAction(key), "up");
end
COINFRAME_BINDING_CACHE[key] = nil;
end
function CoinPickupFrameLeft_Click()
if ( CoinPickupFrame.money == 1 ) then
return;
end
CoinPickupFrame.money = CoinPickupFrame.money - 1;
CoinPickupText:SetText(CoinPickupFrame.money .. CoinPickupFrame.symbol);
if ( CoinPickupFrame.money == 1 ) then
CoinPickupLeftButton:Disable();
end
CoinPickupRightButton:Enable();
end
function CoinPickupFrameRight_Click()
if ( CoinPickupFrame.money == CoinPickupFrame.maxMoney ) then
return;
end
CoinPickupFrame.money = CoinPickupFrame.money + 1;
CoinPickupText:SetText(CoinPickupFrame.money .. CoinPickupFrame.symbol);
if ( CoinPickupFrame.money == CoinPickupFrame.maxMoney ) then
CoinPickupRightButton:Disable();
end
CoinPickupLeftButton:Enable();
end
function CoinPickupFrameOkay_Click()
if ( (CoinPickupFrame.money > 0) and CoinPickupFrame.owner ) then
MoneyTypeInfo[CoinPickupFrame.owner.moneyType].PickupFunc(CoinPickupFrame, CoinPickupFrame.money * CoinPickupFrame.multiplier);
end
CoinPickupFrame:Hide();
PlaySound("igBackPackCoinOK");
end
function CoinPickupFrameCancel_Click()
CoinPickupFrame:Hide();
PlaySound("igBackPackCoinCancel");
end
function CoinPickupFrame_OnHide()
if ( CoinPickupFrame.owner ) then
CoinPickupFrame.owner.hasPickup = 0;
end
for key in next, COINFRAME_BINDING_CACHE do
if ( GetBindingAction(key) ) then
RunBinding(GetBindingAction(key), "up");
end
COINFRAME_BINDING_CACHE[key] = nil;
end
PlaySound("MONEYFRAMECLOSE");
end