public
Description: WoW Addon - Prospecting and Disenchanting Aide
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/panda.git
Click here to lend your support to: panda and make a donation at www.pledgie.com !
tekkub (author)
Fri Jun 27 20:44:44 -0700 2008
commit  0549be7ae2f3eb24cbe1079fdd19372e4586c7df
tree    4e2431039d3768d1744f442524013ae08fa1a1b2
parent  21e00a5520c69bc10efc9f3f93e7802b4b6043a5
panda / GemCutting.lua
100644 349 lines (286 sloc) 11.499 kb
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349

------------------------------
-- Are you local? --
------------------------------
 
local BC_GREEN_GEMS, BC_BLUE_GEMS, BC_EPIC_GEMS, BC_META_GEMS, CUTS = Panda.BC_GREEN_GEMS, Panda.BC_BLUE_GEMS, Panda.BC_EPIC_GEMS, Panda.BC_META_GEMS, Panda.CUTS
local HideTooltip, ShowTooltip, GS, G = Panda.HideTooltip, Panda.ShowTooltip, Panda.GS, Panda.G
local frame, epicframe, metaframe
 
 
-- Query server, we need these items!
for i,t in pairs(CUTS) do GameTooltip:SetHyperlink("item:"..i); for _,id in pairs(t) do GameTooltip:SetHyperlink("item:"..id) end end
 
 
local rawframes, cutframes, knowncombines, frame = {}, {}, {}
function Panda:CreateCutGreenBluePanel()
  local function SetupFrame(f, id, secure, notext)
    local name, link, _, _, _, _, _, _, _, texture = GetItemInfo(id)
    f.link, f.id, f.name = link, id, name
 
    f:SetHeight(32)
    f:SetWidth(32)
    if not secure then f:EnableMouse() end
    f:SetScript("OnEnter", ShowTooltip)
    f:SetScript("OnLeave", HideTooltip)
 
    local icon = f:CreateTexture(nil, "ARTWORK")
    icon:SetAllPoints(f)
    icon:SetTexture(texture)
 
    if not notext then
      f.text = f:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
      f.text:SetPoint("TOP", icon, "BOTTOM")
    end
 
    local count = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmall")
    count:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", -2, 2)
    f.count = count
 
    if secure and self.canJC then
      f:SetAlpha(knowncombines[f.name] and 1 or 0.25)
      f:SetAttribute("type", "macro")
      f:SetAttribute("macrotext", "/run CloseTradeSkill()\n/cast Jewelcrafting\n/run for i=1,GetNumTradeSkills() do if GetTradeSkillInfo(i) == '"..name.."' then DoTradeSkill(i) end end\n/run CloseTradeSkill()")
    end
 
    return f
  end
 
  frame = CreateFrame("Frame", nil, UIParent)
 
  local HGAP, VGAP = 5, -18
  local rowanchor, lastframe
  for i,rawid in ipairs(BC_GREEN_GEMS) do
    local f = CreateFrame("Frame", nil, frame)
    if i == 1 then
      f:SetPoint("BOTTOMLEFT", frame, "TOPLEFT", 0, -HGAP-VGAP)
    else
      f:SetPoint("TOPLEFT", rowanchor, "BOTTOMLEFT", 0, VGAP)
    end
    rowanchor = f
    lastframe = SetupFrame(f, rawid)
    rawframes[rawid] = f
 
    for j,id in ipairs(CUTS[rawid]) do
      local f = CreateFrame("CheckButton", nil, frame, "SecureActionButtonTemplate")
      f:SetPoint("LEFT", lastframe, "RIGHT", HGAP, 0)
      lastframe = SetupFrame(f, id, true)
      cutframes[id] = f
    end
  end
 
  for i,rawid in ipairs(BC_BLUE_GEMS) do
    local f = CreateFrame("Frame", nil, frame)
    if i == 1 then
      f:SetPoint("BOTTOMLEFT", frame, "TOPLEFT", HGAP*8 + 32*8, -HGAP-VGAP)
 
      local f2 = CreateFrame("CheckButton", nil, frame, "SecureActionButtonTemplate")
      f2:SetPoint("TOPRIGHT", f, "TOPLEFT", -HGAP*2, 0)
      SetupFrame(f2, 35945, true, true)
      cutframes[35945] = f2
    else
      f:SetPoint("TOPLEFT", rowanchor, "BOTTOMLEFT", 0, VGAP)
    end
    rowanchor = f
    lastframe = SetupFrame(f, rawid)
    rawframes[rawid] = f
 
    for j,id in ipairs(CUTS[rawid]) do
      local f = CreateFrame("CheckButton", nil, frame, "SecureActionButtonTemplate")
      f:SetPoint("LEFT", lastframe, "RIGHT", HGAP, 0)
      lastframe = SetupFrame(f, id, true)
      cutframes[id] = f
    end
  end
 
  if self.canJC then
    local b = CreateFrame("Button", nil, frame, "SecureActionButtonTemplate")
    b:SetPoint("TOPRIGHT", frame, "BOTTOMRIGHT", 4, -3)
    b:SetWidth(80) b:SetHeight(22)
 
    -- Fonts --
    b:SetDisabledFontObject(GameFontDisable)
    b:SetHighlightFontObject(GameFontHighlight)
    b:SetTextFontObject(GameFontNormal)
 
    -- Textures --
    b:SetNormalTexture("Interface\\Buttons\\UI-Panel-Button-Up")
    b:SetPushedTexture("Interface\\Buttons\\UI-Panel-Button-Down")
    b:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight")
    b:SetDisabledTexture("Interface\\Buttons\\UI-Panel-Button-Disabled")
    b:GetNormalTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetPushedTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetHighlightTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetDisabledTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetHighlightTexture():SetBlendMode("ADD")
 
    b:SetText("Refresh")
    b:SetAttribute("type", "macro")
    b:SetAttribute("macrotext", "/run CloseTradeSkill()\n/cast Jewelcrafting\n/run CloseTradeSkill()")
  end
 
  frame:Hide()
  frame:SetScript("OnShow", function()
    OpenBackpack()
    self:RegisterEvent("BAG_UPDATE", "GemCutBagUpdate")
    self:GemCutBagUpdate()
  end)
  frame:SetScript("OnHide", function() self:UnregisterEvent("BAG_UPDATE") end)
 
  self.CreateCutGreenBluePanel = nil -- Don't need this function anymore!
  return frame
end
 
 
function Panda:CreateCutMetaPanel()
  local function SetupFrame(f, id, secure)
    local name, link, _, _, _, _, _, _, _, texture = GetItemInfo(id)
    f.link, f.id, f.name = link, id, name
 
    f:SetHeight(32)
    f:SetWidth(32)
    if not secure then f:EnableMouse() end
    f:SetScript("OnEnter", ShowTooltip)
    f:SetScript("OnLeave", HideTooltip)
 
    local icon = f:CreateTexture(nil, "ARTWORK")
    icon:SetAllPoints(f)
    icon:SetTexture(texture)
 
    f.text = f:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
    f.text:SetPoint("TOP", icon, "BOTTOM")
 
    local count = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmall")
    count:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", -2, 2)
    f.count = count
 
    if secure and self.canJC then
      f:SetAlpha(knowncombines[f.name] and 1 or 0.25)
      f:SetAttribute("type", "macro")
      f:SetAttribute("macrotext", "/run CloseTradeSkill()\n/cast Jewelcrafting\n/run for i=1,GetNumTradeSkills() do if GetTradeSkillInfo(i) == '"..name.."' then DoTradeSkill(i) end end\n/run CloseTradeSkill()")
    end
 
    return f
  end
 
  metaframe = CreateFrame("Frame", nil, UIParent)
 
  local HGAP, VGAP = 5, -18
  local rowanchor, lastframe
  for i,rawid in ipairs(BC_META_GEMS) do
    local f = CreateFrame("Frame", nil, metaframe)
    if i == 1 then
      f:SetPoint("TOPLEFT", metaframe, "TOPLEFT", HGAP, -HGAP)
    else
      f:SetPoint("TOPLEFT", rowanchor, "BOTTOMLEFT", 0, VGAP)
    end
    rowanchor = f
    lastframe = SetupFrame(f, rawid)
    rawframes[rawid] = f
 
    for j,id in ipairs(CUTS[rawid]) do
      local f = CreateFrame("CheckButton", nil, metaframe, "SecureActionButtonTemplate")
      f:SetPoint("LEFT", lastframe, "RIGHT", HGAP, 0)
      lastframe = SetupFrame(f, id, true)
      cutframes[id] = f
    end
  end
 
  if self.canJC then
    local b = CreateFrame("Button", nil, metaframe, "SecureActionButtonTemplate")
    b:SetPoint("TOPRIGHT", metaframe, "BOTTOMRIGHT", 4, -3)
    b:SetWidth(80) b:SetHeight(22)
 
    -- Fonts --
    b:SetDisabledFontObject(GameFontDisable)
    b:SetHighlightFontObject(GameFontHighlight)
    b:SetTextFontObject(GameFontNormal)
 
    -- Textures --
    b:SetNormalTexture("Interface\\Buttons\\UI-Panel-Button-Up")
    b:SetPushedTexture("Interface\\Buttons\\UI-Panel-Button-Down")
    b:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight")
    b:SetDisabledTexture("Interface\\Buttons\\UI-Panel-Button-Disabled")
    b:GetNormalTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetPushedTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetHighlightTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetDisabledTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetHighlightTexture():SetBlendMode("ADD")
 
    b:SetText("Refresh")
    b:SetAttribute("type", "macro")
    b:SetAttribute("macrotext", "/run CloseTradeSkill()\n/cast Jewelcrafting\n/run CloseTradeSkill()")
  end
 
  metaframe:Hide()
  metaframe:SetScript("OnShow", function()
    OpenBackpack()
    self:RegisterEvent("BAG_UPDATE", "GemCutBagUpdate")
    self:GemCutBagUpdate()
  end)
  metaframe:SetScript("OnHide", function() self:UnregisterEvent("BAG_UPDATE") end)
 
  self.CreateCutMetaPanel = nil -- Don't need this function anymore!
  return metaframe
end
 
 
function Panda:CreateCutPurplePanel()
  local function SetupFrame(f, id, secure)
    local name, link, _, _, _, _, _, _, _, texture = GetItemInfo(id)
    f.link, f.id, f.name = link, id, name
 
    f:SetHeight(32)
    f:SetWidth(32)
    if not secure then f:EnableMouse() end
    f:SetScript("OnEnter", ShowTooltip)
    f:SetScript("OnLeave", HideTooltip)
 
    local icon = f:CreateTexture(nil, "ARTWORK")
    icon:SetAllPoints(f)
    icon:SetTexture(texture)
 
    f.text = f:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
    f.text:SetPoint("TOP", icon, "BOTTOM")
 
    local count = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmall")
    count:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", -2, 2)
    f.count = count
 
    if secure and self.canJC then
      f:SetAlpha(knowncombines[f.name] and 1 or 0.25)
      f:SetAttribute("type", "macro")
      f:SetAttribute("macrotext", "/run CloseTradeSkill()\n/cast Jewelcrafting\n/run for i=1,GetNumTradeSkills() do if GetTradeSkillInfo(i) == '"..name.."' then DoTradeSkill(i) end end\n/run CloseTradeSkill()")
    end
 
    return f
  end
 
  epicframe = CreateFrame("Frame", nil, UIParent)
 
  local HGAP, VGAP = 5, -18
  local rowanchor, lastframe
  for i,rawid in ipairs(BC_EPIC_GEMS) do
    local f = CreateFrame("Frame", nil, epicframe)
    if i == 1 then
      f:SetPoint("TOPLEFT", epicframe, "TOPLEFT", HGAP, -HGAP)
    else
      f:SetPoint("TOPLEFT", rowanchor, "BOTTOMLEFT", 0, VGAP)
    end
    rowanchor = f
    lastframe = SetupFrame(f, rawid)
    rawframes[rawid] = f
 
    for j,id in ipairs(CUTS[rawid]) do
      local f = CreateFrame("CheckButton", nil, epicframe, "SecureActionButtonTemplate")
      f:SetPoint("LEFT", lastframe, "RIGHT", HGAP, 0)
      lastframe = SetupFrame(f, id, true)
      cutframes[id] = f
    end
  end
 
  if self.canJC then
    local b = CreateFrame("Button", nil, epicframe, "SecureActionButtonTemplate")
    b:SetPoint("TOPRIGHT", epicframe, "BOTTOMRIGHT", 4, -3)
    b:SetWidth(80) b:SetHeight(22)
 
    -- Fonts --
    b:SetDisabledFontObject(GameFontDisable)
    b:SetHighlightFontObject(GameFontHighlight)
    b:SetTextFontObject(GameFontNormal)
 
    -- Textures --
    b:SetNormalTexture("Interface\\Buttons\\UI-Panel-Button-Up")
    b:SetPushedTexture("Interface\\Buttons\\UI-Panel-Button-Down")
    b:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight")
    b:SetDisabledTexture("Interface\\Buttons\\UI-Panel-Button-Disabled")
    b:GetNormalTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetPushedTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetHighlightTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetDisabledTexture():SetTexCoord(0, 0.625, 0, 0.6875)
    b:GetHighlightTexture():SetBlendMode("ADD")
 
    b:SetText("Refresh")
    b:SetAttribute("type", "macro")
    b:SetAttribute("macrotext", "/run CloseTradeSkill()\n/cast Jewelcrafting\n/run CloseTradeSkill()")
  end
 
  epicframe:Hide()
  epicframe:SetScript("OnShow", function()
    OpenBackpack()
    self:RegisterEvent("BAG_UPDATE", "GemCutBagUpdate")
    self:GemCutBagUpdate()
  end)
  epicframe:SetScript("OnHide", function() self:UnregisterEvent("BAG_UPDATE") end)
 
  self.CreateCutPurplePanel = nil -- Don't need this function anymore!
  return epicframe
end
 
 
function Panda:TRADE_SKILL_SHOW()
  for i=1,GetNumTradeSkills() do
    local name, rowtype = GetTradeSkillInfo(i)
    if rowtype ~= "header" then knowncombines[name] = true end
  end
  for id,f in pairs(cutframes) do f:SetAlpha((not self.canJC or knowncombines[f.name]) and 1 or 0.25) end
end
 
 
function Panda:GemCutBagUpdate()
  for id,f in pairs(cutframes) do
    local count = GetItemCount(id)
    f.count:SetText(count > 0 and count or "")
    if f.text then
      local price = Panda:GetAHBuyout(id)
      f.text:SetText(GS(price))
    end
  end
 
  for id,f in pairs(rawframes) do
    local count = GetItemCount(id)
    f.count:SetText(count > 0 and count or "")
    if f.text then
      local price = Panda:GetAHBuyout(id)
      f.text:SetText(GS(price))
    end
  end
end