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 !
panda / Disenchanting.lua
100644 213 lines (168 sloc) 6.201 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

 
local tip = DEATinyGratuity
DEATinyGratuity = nil
 
 
local ICONSIZE = 32
local NUM_LINES = math.floor(305/ICONSIZE)
local OFFSET = math.floor((305 - NUM_LINES*ICONSIZE)/(NUM_LINES+1))
local BUTTON_WIDTH = math.floor((630 - OFFSET*2-15)/2)
 
local showBOP, nocompare, buttons = false
local notDEable = {
  ["32540"] = true,
  ["32541"] = true,
  ["18665"] = true,
  ["21766"] = true,
  ["5004"] = true,
  ["20408"] = true,
  ["20406"] = true,
  ["20407"] = true,
  ["14812"] = true,
  ["31336"] = true,
  ["32660"] = true,
  ["32662"] = true,
  ["11288"] = true,
  ["11290"] = true,
  ["12772"] = true,
  ["11287"] = true,
  ["11289"] = true,
  ["29378"] = true,
}
 
local GS = Panda.GS
local function IsBound(bag, slot)
  tip:SetBagItem(bag, slot)
  for i=1,30 do
    if tip.L[i] == "Soulbound" then return true end
  end
end
 
 
function Panda:DEable(link)
  local id = type(link) == "number" and link or select(3, link:find("item:(%d+):"))
  if id and notDEable[id] then return end
 
  local _, _, qual, itemLevel, _, itemType = GetItemInfo(link)
  if (itemType == "Armor" or itemType == "Weapon") and qual > 1 and qual < 5 then return true end
end
 
 
local function GSC(cash)
  if not cash then return end
  local g, s, c = floor(cash/10000), floor((cash/100)%100), cash%100
  if g > 0 then return string.format("|cffffd700%d.|cffc7c7cf%02d.|cffeda55f%02d", g, s, c)
  elseif s > 0 then return string.format("|cffc7c7cf%d.|cffeda55f%02d", s, c)
  else return string.format("|cffc7c7cf%d", c) end
end
 
 
local function cfs(frame, a1, a2, a3, ...)
  local fs = frame:CreateFontString(a1, a2, a3)
  fs:SetPoint(...)
  return fs
end
 
 
local gii = GetItemInfo
local function GetItemInfo(i)
  if i then return gii(i) end
end
 
 
local tipinframe
local function ShowItemDetails(self)
  if not (self.bag and self.slot) then return end
 
  nocompare = true
  tipinframe = self
  GameTooltip:SetOwner(self, "ANCHOR_NONE")
  GameTooltip:SetPoint("TOPLEFT", self.icon, "BOTTOMRIGHT")
  GameTooltip:SetBagItem(self.bag, self.slot)
 
  local link = GetContainerItemLink(self.bag, self.slot)
  if not link then return end
 
  local id1, _, _, _, perc1, id2, _, _, _, perc2, id3, _, _, _, perc3 = Panda:GetPossibleDisenchants(link)
  if id1 then
    for i,f in pairs(buttons) do f:SetAlpha(.1) end
    if buttons[id1] then buttons[id1]:SetAlpha(.5 + perc1/2) end
    if id2 and buttons[id2] then buttons[id2]:SetAlpha(.5 + perc2/2) end
    if id3 and buttons[id3] then buttons[id3]:SetAlpha(.5 + perc3/2) end
  end
end
 
 
local function HideItemDetails(self)
  nocompare, tipinframe = nil
  GameTooltip:Hide()
  for i,f in pairs(buttons) do f:SetAlpha(1) end
end
 
 
local function HideCompareTooltip(self)
  if nocompare then self:Hide() end
end
 
 
 
local frame = CreateFrame("Frame", nil, UIParent)
Panda.panel:RegisterFrame("Disenchanting", frame)
frame:Hide()
 
frame:SetScript("OnShow", function(self)
  local canDE = GetSpellInfo(GetSpellInfo(13262))
 
  local NoItems = cfs(self, nil, "ARTWORK", "GameFontNormalHuge", "CENTER", -self:GetWidth()/4, 0)
  NoItems:SetText("Nothing to disenchant!")
 
  self.lines = {}
  for i=1,NUM_LINES do
    local f = CreateFrame("CheckButton", "PandaDEFrame"..i, self, "SecureActionButtonTemplate")
    f:SetPoint("TOPLEFT", self, OFFSET, ICONSIZE-i*(ICONSIZE+OFFSET))
    f:SetHeight(ICONSIZE)
    f:SetWidth(BUTTON_WIDTH)
    f:SetScript("OnEnter", ShowItemDetails)
    f:SetScript("OnLeave", HideItemDetails)
    if canDE then f:SetAttribute("type", "macro") end
 
    f.icon = f:CreateTexture(nil, "ARTWORK")
    f.icon:SetPoint("TOPLEFT")
    f.icon:SetWidth(ICONSIZE)
    f.icon:SetHeight(ICONSIZE)
 
    f.name = cfs(f, nil, "ARTWORK", "GameFontHighlightSmall", "TOPLEFT", f.icon, "TOPRIGHT", 5, 0)
    f.type = cfs(f, nil, "ARTWORK", "GameFontHighlightSmall", "TOPLEFT", f.icon, "TOPRIGHT", 5, -12)
    f.bind = cfs(f, nil, "ARTWORK", "GameFontHighlightSmall", "TOPRIGHT", f, "TOPRIGHT", -5, -12)
 
    self.lines[i] = f
  end
 
  local function OnEvent(self)
    local i = 1
    NoItems:Hide()
 
    for bag=0,4 do
      for slot=1,GetContainerNumSlots(bag) do
        local link = GetContainerItemLink(bag, slot)
        if link and Panda:DEable(link) then
          local bound = IsBound(bag, slot)
          if showBOP or not bound then
            local name, _, _, itemLevel, _, itemType, itemSubType, _, _, texture = GetItemInfo(link)
 
            local l = frame.lines[i]
            if canDE then l:SetAttribute("macrotext", string.format("/cast Disenchant\n/use %s %s", bag, slot)) end
            l.bag, l.slot = bag, slot
            l.icon:SetTexture(texture)
            l.name:SetText(link)
            l.type:SetText(itemType)
            l.bind:SetText(bound and "Soulbound" or "Bind on Equip")
            l:Show()
 
            if l == tipinframe then ShowItemDetails(tipinframe) end
 
            i = i + 1
            if i > NUM_LINES then return end
          end
        end
      end
    end
 
    if i == 1 then NoItems:Show() end
    for j=i,NUM_LINES do frame.lines[j]:Hide() end
  end
 
  local BOP = CreateFrame("CheckButton", "DEAFrameDEShowBOP", self, "OptionsCheckButtonTemplate")
  BOP:SetWidth(22)
  BOP:SetHeight(22)
  BOP:SetPoint("TOPLEFT", self, "BOTTOMLEFT", 0, -4)
  BOP:SetScript("OnClick", function() showBOP = not showBOP; OnEvent(self) end)
 
  local BOPlabel = cfs(BOP, nil, "ARTWORK", "GameFontNormalSmall", "LEFT", BOP, "RIGHT", 5, 0)
  BOPlabel:SetText("Show soulbound items")
 
  self:SetScript("OnEvent", OnEvent)
  self:RegisterEvent("BAG_UPDATE")
  OnEvent(self)
  OpenBackpack()
 
  self:SetScript("OnShow", function(self)
    self:RegisterEvent("BAG_UPDATE")
    OnEvent(self)
    OpenBackpack()
  end)
  self:SetScript("OnHide", self.UnregisterAllEvents)
 
  -- Block compare tips when showing tip
  ShoppingTooltip1:SetScript("OnShow", HideCompareTooltip)
  ShoppingTooltip2:SetScript("OnShow", HideCompareTooltip)
 
  -- Set up price panel
  local frame = CreateFrame("Frame", nil, self)
  frame:SetPoint("TOPLEFT", self, "TOP", 20, 0)
  frame:SetPoint("BOTTOMRIGHT")
  frame.itemids = [[10940 11083 11137 11176 16204 22445 34054
   10938 10998 11134 11174 16202 22447 34056
   10939 11082 11135 11175 16203 22446 34055
   0 10978 11138 11177 14343 22448 34053
   0 11084 11139 11178 14344 22449 34052
   0 0 0 0 20725 22450 34057]]
  buttons = Panda.PanelFiller(frame)
end)