vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --default options db Mendeleev |
2 | local MENDELEEV_DEFAULT_OPTIONS = { |
||
3 | ["Cats"] = { |
||
4 | ["Zul'Gurub Enchants"] = 1, |
||
5 | ["stacksize"] = 1, |
||
6 | ["Zul'Gurub Classes"] = 1, |
||
7 | ["itemid"] = 1, |
||
8 | ["Ahn'Qiraj Classes CC"] = 1, |
||
9 | ["Ahn'Qiraj Classes BON"] = 1, |
||
10 | }, |
||
11 | } |
||
12 | |||
13 | --Regester new addon object |
||
14 | Mendeleev = AceAddonClass:new({ |
||
15 | name = MendeleevLocals.Title, |
||
16 | version = MendeleevLocals.Version, |
||
17 | author = MendeleevLocals.Author, |
||
18 | authorEmail = MendeleevLocals.Email , |
||
19 | aceCompatible = "100", |
||
20 | category = ACE_CATEGORY_INTERFACE, |
||
21 | defaults = MENDELEEV_DEFAULT_OPTIONS, |
||
22 | db = AceDbClass:new("MendeleevDB"), |
||
23 | cmd = AceChatCmdClass:new(MendeleevLocals.cmd,MendeleevLocals.cmdOptions), |
||
24 | }) |
||
25 | |||
26 | ------------ |
||
27 | -- HOOKS --- |
||
28 | ------------ |
||
29 | |||
30 | local linkFuncs = { |
||
31 | SetAuctionItem = GetAuctionItemLink, |
||
32 | SetBagItem = GetContainerItemLink, |
||
33 | SetCraftItem = function(skill, id) return (id) and GetCraftReagentItemLink(skill, id) or GetCraftItemLink(skill) end, |
||
34 | SetHyperlink = function(link) return link end, |
||
35 | SetInventoryItem = function(type, slot) return (type) and GetInventoryItemLink(type, slot) or GetContainerItemLink(BANK_CONTAINER,this:GetID()) end, |
||
36 | SetLootItem = GetLootSlotLink, |
||
37 | SetMerchantItem = GetMerchantItemLink, |
||
38 | SetQuestItem = GetQuestItemLink, |
||
39 | SetQuestLogItem = GetQuestLogItemLink, |
||
40 | SetTradePlayerItem = GetTradePlayerItemLink, |
||
41 | SetTradeSkillItem = function(skill, id) return (id) and GetTradeSkillReagentItemLink(skill, id) or GetTradeSkillItemLink(skill) end, |
||
42 | SetTradeTargetItem = GetTradeTargetItemLink, |
||
43 | SetInboxItem = function(index) return Mendeleev:FindItemID(GetInboxItem(index)) end, |
||
44 | SetLootRollItem = function(index) return GetLootRollItemLink(index) end, |
||
45 | } |
||
46 | function Mendeleev:SetItemRef(link, text, button) |
||
47 | self:CallHook("SetItemRef", link, text, button) |
||
48 | if (not strfind(link, "item") or IsControlKeyDown() or IsShiftKeyDown()) then return; end |
||
49 | self:ParseTooltip(ItemRefTooltip, link) |
||
50 | end |
||
51 | |||
52 | function Mendeleev:FindItemID(name) |
||
53 | if not name then return end |
||
54 | if self.linkcache[name] then return self.linkcache[name] end |
||
55 | |||
56 | local i, max = 1, 50000 |
||
57 | |||
58 | repeat |
||
59 | if GetItemInfo(i) == name then |
||
60 | local _, link = GetItemInfo(i) |
||
61 | self.linkcache[name] = link |
||
62 | return link |
||
63 | end |
||
64 | i = i+1 |
||
65 | until i > max |
||
66 | end |
||
67 | |||
68 | function Mendeleev:HookTooltips() |
||
69 | for key, value in linkFuncs do |
||
70 | local orig, linkFunc = key,value -- I cant leave this out, dont ask me why. |
||
71 | local func = function(tooltip,a,b,c) |
||
72 | local r1,r2,r3 = self.Hooks[tooltip][orig].orig(tooltip,a,b,c) |
||
73 | self:ParseTooltip(tooltip,linkFunc(a,b,c)) |
||
74 | return r1,r2,r3 |
||
75 | end |
||
76 | self:Hook(GameTooltip,orig,func) |
||
77 | end |
||
78 | self:Hook("SetItemRef") |
||
79 | end |
||
80 | |||
81 | --Ace methods |
||
82 | function Mendeleev:Enable() |
||
83 | function Mendeleev:Get(var) |
||
84 | if type(self) == "string" then |
||
85 | ace:print("! ERROR: "..self) |
||
86 | end |
||
87 | return self.db:get({self.profilePath,"Cats"}, var) |
||
88 | end |
||
89 | |||
90 | function Mendeleev:Set(var,val) |
||
91 | self.db:set({self.profilePath,"Cats"}, var,val) |
||
92 | end |
||
93 | |||
94 | function Mendeleev:OGet(var) |
||
95 | if type(self) == "string" then |
||
96 | ace:print("! ERROR: "..self) |
||
97 | end |
||
98 | return self.db:get({self.profilePath,"Options"}, var) |
||
99 | end |
||
100 | |||
101 | function Mendeleev:OSet(var,val) |
||
102 | self.db:set({self.profilePath,"Options"}, var,val) |
||
103 | end |
||
104 | |||
105 | if (KC_Items and KC_Items.tooltip and self:OGet("KCI"))then |
||
106 | KC_Items.tooltip:RegisterFunc(self, "DisplayTooltip") |
||
107 | else |
||
108 | self:HookTooltips() |
||
109 | end |
||
110 | |||
111 | self.link = "" |
||
112 | self.TT = {} |
||
113 | self.linkcache = {} |
||
114 | setmetatable(self.linkcache, {__mode = "k"}) |
||
115 | |||
116 | self.compost = CompostLib:GetInstance("compost-1") |
||
117 | self.PT = PeriodicTableEmbed:GetInstance("1") |
||
118 | self.PTTrade = PTTradeskillsEmbed:GetInstance("1") |
||
119 | end |
||
120 | |||
121 | function Mendeleev:Disable() |
||
122 | if (KC_Items and KC_Items.tooltip and not self:OGet("KCI"))then |
||
123 | KC_Items.tooltip:UnregisterFunc(self, "DisplayTooltip") |
||
124 | else |
||
125 | self:UnhookAll() |
||
126 | end |
||
127 | end |
||
128 | |||
129 | --Mendeleev methods |
||
130 | function Mendeleev:DrawTooltip(frame) |
||
131 | |||
132 | for _,z in ipairs(self.TT) do |
||
133 | if (KC_Items and KC_Items.tooltip) then |
||
134 | KC_Tooltip:AddTextLine(frame, z.Stringa, z.Stringb, " ", "|cffffffff") |
||
135 | else |
||
136 | frame:AddDoubleLine(z.Stringa,z.Stringb,1,1,1,1,1,1) |
||
137 | end |
||
138 | end |
||
139 | frame:Show() |
||
140 | end |
||
141 | |||
142 | function Mendeleev:DisplayTooltip(tooltip, code, lcode, qty, hooker) |
||
143 | self:ParseTooltip(tooltip,"item:"..lcode) |
||
144 | end |
||
145 | |||
146 | function Mendeleev:AddLine(Stringa,Stringb) |
||
147 | local i = table.getn(self.TT) + 1 |
||
148 | local t = self.compost:Acquire() |
||
149 | t.Stringa = Stringa |
||
150 | t.Stringb = Stringb |
||
151 | table.insert(self.TT, t) |
||
152 | end |
||
153 | |||
154 | function Mendeleev:ParseTooltip(frame,link,id) |
||
155 | if(link == nil) then |
||
156 | return |
||
157 | end |
||
158 | |||
159 | local _, _, tid = string.find(link, "item:(%d+):%d+:%d+:%d+") |
||
160 | local id = tonumber(tid) |
||
161 | |||
162 | if(link == self.link) then |
||
163 | self:DrawTooltip(frame) |
||
164 | return |
||
165 | elseif(tid == nil) then |
||
166 | self:debug("malformed link") |
||
167 | return |
||
168 | else |
||
169 | self.link = link |
||
170 | self.compost:Reclaim(self.TT, 1) |
||
171 | self.TT = self.compost:Acquire() |
||
172 | end |
||
173 | |||
174 | Mendeleev:DoTooltip(frame,link,id) |
||
175 | |||
176 | self:DrawTooltip(frame) |
||
177 | end |
||
178 | |||
179 | function Mendeleev:DoTooltip(frame,link,id) |
||
180 | --Add the fixed Category information, Can be found in MendeleevGlobals.ua |
||
181 | for _,v in ipairs(MendeleevLocals.infosets) do |
||
182 | if(not self:Get(v.name)) then |
||
183 | local z = self.PT:ItemInSets(link, v.setindex) |
||
184 | local filter = v.filter and not self.PT:ItemInSet(link, v.filter) |
||
185 | if z and not filter then |
||
186 | local tline, header |
||
187 | local colour = v.colour or "|cffffffff" |
||
188 | |||
189 | for t,tt in pairs(z) do |
||
190 | if v.sets[tt] then |
||
191 | local val = self.PT:ItemInSet(link, tt) |
||
192 | local valstr = val and v.useval and v.useval(val, link) or "" |
||
193 | tline = (not tline and "") or tline..", " |
||
194 | tline = tline.. v.sets[tt].. valstr |
||
195 | else self:debug(MendeleevLocals.Misc.NoClue..tt) |
||
196 | end |
||
197 | |||
198 | if( t <= 2) then |
||
199 | header = v.header |
||
200 | else |
||
201 | header = " " |
||
202 | end |
||
203 | header = colour..header.."|r" |
||
204 | |||
205 | if(math.mod(t,2) == 0 and tline ~= nil) then |
||
206 | self:AddLine(header,colour..tline.."|r") |
||
207 | tline = nil |
||
208 | end |
||
209 | end |
||
210 | if(tline and string.len(tline) > 0) then |
||
211 | self:AddLine(header,colour..tline.."|r") |
||
212 | end |
||
213 | header = nil |
||
214 | end |
||
215 | self.compost:Reclaim(z) |
||
216 | end |
||
217 | end |
||
218 | |||
219 | if(not self:Get("crafting")) then |
||
220 | self.rid2data = self.compost:Acquire() |
||
221 | self.inTree = self.compost:Acquire() |
||
222 | local t = self:GetUsedInTree(id) |
||
223 | local l = self:GetUsedInList(t[2], 1) |
||
224 | local header = MendeleevLocals.Category.TradeRep |
||
225 | local ln = table.getn(l) |
||
226 | if ln > 15 then ln = 14 end |
||
227 | for i = 1, ln do |
||
228 | if header then |
||
229 | self:AddLine(header) |
||
230 | header = nil |
||
231 | end |
||
232 | self:AddLine(l[i]) |
||
233 | end |
||
234 | if table.getn(l) > 15 then |
||
235 | self:AddLine(" ...") |
||
236 | end |
||
237 | self.compost:Reclaim(t) |
||
238 | self.compost:Reclaim(l) |
||
239 | self.compost:Reclaim(self.rid2data) |
||
240 | self.rid2data = nil |
||
241 | self.compost:Reclaim(self.inTree) |
||
242 | self.inTree = nil |
||
243 | end |
||
244 | |||
245 | if(not self:Get("stacksize")) then |
||
246 | local _,_,_,_,_,_,stack = GetItemInfo(id) |
||
247 | if(stack and stack > 1)then |
||
248 | self:AddLine(MendeleevLocals.Misc.Stack,stack) |
||
249 | end |
||
250 | end |
||
251 | |||
252 | if(not self:Get("itemid")) then |
||
253 | self:AddLine(MendeleevLocals.Misc.ItemId,id) |
||
254 | end |
||
255 | end |
||
256 | |||
257 | local function SortUsedInTree(a,b) |
||
258 | if (not a or not b) then |
||
259 | return true |
||
260 | end |
||
261 | if (a[3] > b[3]) then |
||
262 | return true |
||
263 | end |
||
264 | if (a[3] < b[3]) then |
||
265 | return false |
||
266 | end |
||
267 | if (a[1] < b[1]) then |
||
268 | return true |
||
269 | else |
||
270 | return false |
||
271 | end |
||
272 | end |
||
273 | |||
274 | function Mendeleev:GetUsedInTree(id, selfskill) |
||
275 | local rt = self.compost:Acquire() |
||
276 | local z = self.PTTrade:GetRecepieUse(id) |
||
277 | local skill = selfskill or 0 |
||
278 | if z then |
||
279 | for x,y in z do |
||
280 | if not self.rid2data[x] then |
||
281 | self.rid2data[x] = y |
||
282 | end |
||
283 | if y[2] > skill then |
||
284 | skill = y[2] |
||
285 | end |
||
286 | if not self.inTree[x] then |
||
287 | self.inTree[x] = true |
||
288 | local data = self:GetUsedInTree(x, y[2]) |
||
289 | table.insert(rt, data) |
||
290 | self.inTree[x] = nil |
||
291 | if data[3] > skill then |
||
292 | skill = data[3] |
||
293 | end |
||
294 | else |
||
295 | table.insert(rt, self.compost:Acquire(x, "...", y[2])) |
||
296 | end |
||
297 | end |
||
298 | end |
||
299 | table.sort(rt, SortUsedInTree) |
||
300 | return self.compost:Acquire(id, rt, skill) |
||
301 | end |
||
302 | |||
303 | function Mendeleev:GetUsedInList(tree, level) |
||
304 | local colour = {[0] = "|cffbbbbbb", |
||
305 | [1] = "|cff00cc00", |
||
306 | [2] = "|cffffff00", |
||
307 | [3] = "|cffFF6600", |
||
308 | [4] = "|cffff0000",} |
||
309 | |||
310 | local list = self.compost:Acquire() |
||
311 | for _, v in tree do |
||
312 | if level < 2 or v[3] > 0 then |
||
313 | table.insert(list, string.rep(" ", level).."- "..colour[self.rid2data[v[1]][2]]..self.rid2data[v[1]][1].."|r") |
||
314 | if type(v[2]) == "table" then |
||
315 | local slist = self:GetUsedInList(v[2], level+1) |
||
316 | if table.getn(slist) > 0 then |
||
317 | if v[3] > 0 then |
||
318 | for _, line in slist do |
||
319 | table.insert(list, line) |
||
320 | end |
||
321 | else |
||
322 | table.insert(list, string.rep(" ", level+1).."- "..colour[0].."...|r") |
||
323 | end |
||
324 | end |
||
325 | elseif v[2] == "..." then |
||
326 | table.insert(list, string.rep(" ", level+1).." ...") |
||
327 | end |
||
328 | end |
||
329 | end |
||
330 | return list |
||
331 | end |
||
332 | |||
333 | --chat commands |
||
334 | function Mendeleev:CMDtoggle(name) |
||
335 | for _,v in ipairs(MendeleevLocals.infosets) do |
||
336 | if(v.name == name)then |
||
337 | if(self:Get(name))then |
||
338 | self:Set(name,nil) |
||
339 | self.cmd:status(name, TRUE, ACEG_MAP_ONOFF) |
||
340 | return |
||
341 | else |
||
342 | self:Set(name,TRUE) |
||
343 | self.cmd:status(name, FALSE, ACEG_MAP_ONOFF) |
||
344 | return |
||
345 | end |
||
346 | end |
||
347 | end |
||
348 | for _,v in MendeleevLocals.custominfosets do |
||
349 | if(v == name)then |
||
350 | if(self:Get(name))then |
||
351 | self:Set(name,nil) |
||
352 | self.cmd:status(name, TRUE, ACEG_MAP_ONOFF) |
||
353 | return |
||
354 | else |
||
355 | self:Set(name,TRUE) |
||
356 | self.cmd:status(name, FALSE, ACEG_MAP_ONOFF) |
||
357 | return |
||
358 | end |
||
359 | end |
||
360 | end |
||
361 | self.cmd:msg(MendeleevLocals.Cmdstrings.NotThere) |
||
362 | end |
||
363 | |||
364 | function Mendeleev:KCItoggle(argument) |
||
365 | if(argument == "toggle" or argument == "Toggle") then |
||
366 | if (KC_Items and KC_Items.tooltip) then |
||
367 | if(self:OGet("KCI")) then |
||
368 | self:OSet("KCI",nil) |
||
369 | self.cmd:status(MendeleevLocals.Cmdstrings.IntStat, FALSE, ACEG_MAP_ONOFF) |
||
370 | else |
||
371 | self:OSet("KCI",TRUE) |
||
372 | self.cmd:status(MendeleevLocals.Cmdstrings.IntStat, TRUE, ACEG_MAP_ONOFF) |
||
373 | end |
||
374 | self:Disable() |
||
375 | self:Enable() |
||
376 | else |
||
377 | self.cmd:msg(MendeleevLocals.Cmdstrings.KCINotThere) |
||
378 | end |
||
379 | elseif(argument == "report" or argument == "Report") then |
||
380 | self.cmd:status(MendeleevLocals.Cmdstrings.IntStat, self:OGet("KCI"), ACEG_MAP_ONOFF) |
||
381 | end |
||
382 | end |
||
383 | |||
384 | |||
385 | |||
386 | function Mendeleev:Report() |
||
387 | for _,v in ipairs(MendeleevLocals.infosets) do |
||
388 | local status, sindex |
||
389 | sindex = v.name |
||
390 | |||
391 | if(self:Get(sindex)) then |
||
392 | status = FALSE |
||
393 | else |
||
394 | status = TRUE |
||
395 | end |
||
396 | |||
397 | self.cmd:status(sindex, status, ACEG_MAP_ONOFF) |
||
398 | end |
||
399 | for _,v in MendeleevLocals.custominfosets do |
||
400 | local status |
||
401 | if(self:Get(v)) then |
||
402 | status = FALSE |
||
403 | else |
||
404 | status = TRUE |
||
405 | end |
||
406 | self.cmd:status(v, status, ACEG_MAP_ONOFF) |
||
407 | end |
||
408 | end |
||
409 | |||
410 | --Register in ace |
||
411 | Mendeleev:RegisterForLoad() |