PageRenderTime 526ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/Core.lua

http://apheslootbrowser.googlecode.com/
Lua | 1374 lines | 1262 code | 73 blank | 39 comment | 246 complexity | 7ed1ab04370b4e0560c6ef1163959824 MD5 | raw file
  1. local BInventory = AphesLootBrowserGetBabble("LibBabble-Inventory-3.0")
  2. local BFaction = AphesLootBrowserGetBabble("LibBabble-Faction-3.0")
  3. local L = LibStub("AceLocale-3.0"):GetLocale("AphesLootBrowser")
  4. local ALB = CreateFrame("Frame", "AphesLootBrowser", UIParent)
  5. ALB:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
  6. ALB.droptext = {}
  7. BINDING_HEADER_HEADERALB = L["AphesLootBrowser"]
  8. BINDING_NAME_TOGGLEALB = L["show/hide ALB"]
  9. ALB_VERSION = 4.2
  10. ALB_REVISION = 20
  11. local tooltip = CreateFrame("GameTooltip", "ALB_Tooltip", UIParent, "GameTooltipTemplate")
  12. tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
  13. local unknownItems = {}
  14. local queryall = false
  15. local VALORSOURCE = {
  16. "Zandalari: 140/instance (7/week)",
  17. "Heroic: 70/instance (daily)",
  18. "10-man raid: 70/boss",
  19. "25-man raid: 105/boss"
  20. }
  21. local JUSTICESOURCE = {
  22. "Zandalari: 70/boss",
  23. "heroic: 70/boss",
  24. "normal: 140/instance (daily)",
  25. }
  26. local TREESOURCE = {
  27. "Molten Front daily Quests",
  28. }
  29. local GREY = "|cff999999"
  30. local RED = "|cffff0000"
  31. local WHITE = "|cffFFFFFF"
  32. local GREEN = "|cff1eff00"
  33. local PURPLE = "|cff9F3FFF"
  34. local BLUE = "|cff0070dd"
  35. local ORANGE = "|cffFF8400"
  36. local INDENT = "|TInterface\\OptionsFrame\\UI-OptionsFrame-NewFeatureIcon:0:0:0:-1|t "
  37. local HARDMODE = "|TInterface\\EncounterJournal\\UI-EJ-HeroicTextIcon:19:19:0:0|t "
  38. local ALLIANCE = "|TInterface\\BattlefieldFrame\\Battleground-Alliance:22:22:0:0|t"
  39. local HORDE = "|TInterface\\BattlefieldFrame\\Battleground-Horde:22:22:0:0|t"
  40. local ALLIANCEICON = "Interface\\BattlefieldFrame\\Battleground-Alliance"
  41. local HORDEICON = "Interface\\BattlefieldFrame\\Battleground-Horde"
  42. ALB.CLASSICON = {}
  43. for i = 1, #CLASS_SORT_ORDER do
  44. ALB.CLASSICON[CLASS_SORT_ORDER[i]] = "|TInterface\\Addons\\AphesLootBrowser\\Icons\\"..CLASS_SORT_ORDER[i]..":22:22:0:0|t"
  45. end
  46. local StatIcons = {
  47. [format("%s (%s)", _G.ITEM_MOD_SPELL_POWER_SHORT,_G.ITEM_MOD_HIT_RATING_SHORT)] = "|TInterface\\Icons\\Spell_Fire_Fireball02:30:30:0:0|t",
  48. [_G.ITEM_MOD_SPIRIT_SHORT] = "|TInterface\\Icons\\Spell_Holy_DivineSpirit:30:30:0:0|t",
  49. [_G.ITEM_MOD_SPELL_POWER_SHORT] = "|TInterface\\Icons\\Spell_Holy_Heal:30:30:0:0|t",
  50. [_G.DEFENSE] = "|TInterface\\Icons\\Ability_Warrior_DefensiveStance:30:30:0:0|t",
  51. [_G.ITEM_MOD_AGILITY_SHORT] = "|TInterface\\Icons\\Ability_Rogue_Rupture:30:30:0:0|t",
  52. [_G.ITEM_MOD_STRENGTH_SHORT] = "|TInterface\\Icons\\Ability_Warrior_OffensiveStance:30:30:0:0|t",
  53. ["?"] = "|TInterface\\Icons\\INV_Misc_QuestionMark:30:30:0:0|t",
  54. }
  55. local Sounds = {
  56. "Sound\\Character\\Human\\HumanVocalMale\\HumanMaleCheer01.wav",
  57. "Sound\\Character\\Dwarf\\DwarfVocalMale\\DwarfMaleCheer01.wav",
  58. "Sound\\Character\\Gnome\\GnomeVocalMale\\GnomeMaleCheer01.wav",
  59. "Sound\\Character\\NightElf\\NightElfVocalMale\\NightElfMaleCheer02.wav",
  60. "Sound\\Character\\Draenei\\DraeneiMaleCheer01.wav",
  61. "Sound\\Character\\Tauren\\TaurenVocalMale\\TaurenMaleCheer01.wav",
  62. "Sound\\Character\\Scourge\\ScourgeVocalMale\\UndeadMaleCheer02.wav",
  63. "Sound\\Character\\Troll\\TrollVocalMale\\TrollMaleCheer01.wav",
  64. "Sound\\Character\\Orc\\OrcVocalMale\\OrcMaleCheer01.wav",
  65. "Sound\\Character\\BloodElf\\BloodElfMaleCheer01.wav",
  66. "Sound\\Character\\Human\\HumanVocalFemale\\HumanFemaleCheer01.wav",
  67. "Sound\\Character\\Dwarf\\DwarfVocalFemale\\DwarfFemaleCheer01.wav",
  68. "Sound\\Character\\Gnome\\GnomeVocalFemale\\GnomeFemaleCheer01.wav",
  69. "Sound\\Character\\NightElf\\NightElfVocalFemale\\NightElfFemaleCheer02.wav",
  70. "Sound\\Character\\Draenei\\DraeneiFemaleCheer01.wav",
  71. "Sound\\Character\\Tauren\\TaurenVocalFemale\\TaurenFemaleCheer02.wav",
  72. "Sound\\Character\\Scourge\\ScourgeVocalFemale\\UndeadFemaleCheer01.wav",
  73. "Sound\\Character\\Troll\\TrollVocalFemale\\TrollFemaleCheer01.wav",
  74. "Sound\\Character\\Orc\\OrcVocalFemale\\OrcFemaleCheer01.wav",
  75. "Sound\\Character\\BloodElf\\BloodElfFemaleCheer01.wav",
  76. }
  77. ALB_MENUORDER = {
  78. "Raid 25",
  79. "Raid 10",
  80. "5heroic",
  81. "5normal",
  82. "ALB_Cata_Currency",
  83. "ALB_Cata_Rep",
  84. "ALB_Cata_Raids",
  85. "ALB_Cata_5Mans_hero",
  86. "ALB_Cata_5Mans_normal",
  87. "ALB_WotLK_Raids25",
  88. "ALB_WotLK_Raids10",
  89. "ALB_WotLK_5Mans_hero",
  90. "ALB_WotLK_5Mans_normal",
  91. "ALB_WotLK_Emblems",
  92. "ALB_WotLK_Tokens",
  93. "ALB_BC_5Mans_hero",
  94. "ALB_BC_5Mans_normal",
  95. "ALB_Original_5Mans",
  96. "ALB_WotLK_Crafting",
  97. --[[ "ALB_WotLK_Reputation",
  98. "ALB_WotLK_TierSets10",
  99. "ALB_WotLK_TierSets10hero",
  100. "ALB_WotLK_TierSets25",
  101. "ALB_WotLK_TierSets25hero",
  102. --]]
  103. }
  104. local ClassColor = {}
  105. for class, color in pairs(RAID_CLASS_COLORS) do
  106. ClassColor[class] = string.format("%s%02x%02x%02x", "|cFF", color.r * 255, color.g * 255, color.b * 255)
  107. end
  108. function ALB:pri(text)
  109. if text and tostring(text) then
  110. text = format("%s%s %s", PURPLE, "ALB: |r", tostring(text))
  111. if ChatFrame3 and ChatFrame3:IsVisible() then
  112. ChatFrame3:AddMessage(tostring(text))
  113. else
  114. DEFAULT_CHAT_FRAME:AddMessage(tostring(text))
  115. end
  116. end
  117. end
  118. function ALB:GetBossLocation(id) --rename this function
  119. local location, source = "", ""
  120. for instance, infos in pairs(ALB_Group) do
  121. for i = 1, #infos.sources do
  122. if infos.sources[i] == id then
  123. location = infos.name
  124. source = instance
  125. end
  126. end
  127. if location ~= "" then break end
  128. end
  129. return location, source
  130. end
  131. function ALB:GetItemGroup(id)
  132. local sourcetable = {}
  133. local cost = ALB:GetItemCost(id)
  134. if cost then table.insert(sourcetable, {text = cost}) end
  135. if id == 395 then
  136. for i = 1, #JUSTICESOURCE do
  137. table.insert(sourcetable, {text = JUSTICESOURCE[i]})
  138. end
  139. return sourcetable
  140. elseif id == 396 then
  141. for i = 1, #VALORSOURCE do
  142. table.insert(sourcetable, {text = VALORSOURCE[i]})
  143. end
  144. return sourcetable
  145. elseif id == 416 then
  146. for i = 1, #TREESOURCE do
  147. table.insert(sourcetable, {text = TREESOURCE[i]})
  148. end
  149. return sourcetable
  150. end
  151. local item, group, source
  152. for header, groups in pairs(ALB_Menu) do
  153. for g = 1, #groups do
  154. group = groups[g]
  155. local checkhm, checknorm = false, false
  156. for s = 1, #ALB_Group[group].sources do
  157. source = ALB_Group[group].sources[s]
  158. for i = 1, #ALB_Source[source].items do
  159. item = ALB_Source[source].items[i]
  160. if item == id and ALB_Source[source].type == "boss" then
  161. if ALB_Source[source].mode == "hardmode" then
  162. checkhm = true
  163. else
  164. checknorm = true
  165. end
  166. end
  167. end
  168. end
  169. if checkhm then
  170. table.insert(sourcetable, {text = format("%s %s %s", ALB:GetGroupName(group), ALB_Group[group].size, L["heroic"])})
  171. end
  172. if checknorm then
  173. table.insert(sourcetable, {text = format("%s %s", ALB:GetGroupName(group), ALB_Group[group].size)})
  174. end
  175. end
  176. end
  177. return sourcetable
  178. end
  179. function ALB:GetItemSource(id, wholetable, short)
  180. if not wholetable then
  181. local source = ALB:GetItemCost(id) or ""
  182. for sourceID, info in pairs(ALB_Source) do
  183. for i = 1, #info.items do
  184. if info.items[i] == id then
  185. if short then return sourceID end
  186. if ALB_Source[sourceID].type == "boss"
  187. or ALB_Source[sourceID].type == "crafting" then
  188. if source ~= "" then
  189. local size= strmatch(source, "^"..ALB_Source[sourceID].name.." (%d%d)")
  190. if size then
  191. local hero = strmatch(source, "^"..ALB_Source[sourceID].name.." %d%d "..L["heroic"].."$")
  192. if hero then
  193. if ALB_Source[sourceID].mode == "heroic" then
  194. source = ALB_Source[sourceID].name .. " 10/25 "..L["heroic"]
  195. else
  196. source = L["multiple"]; break
  197. end
  198. else
  199. source = ALB_Source[sourceID].name .. " 10/25"
  200. end
  201. else
  202. source = L["multiple"]; break
  203. end
  204. else
  205. source = ALB_Source[sourceID].name .. " " .. ALB:BossTypeToText(ALB_Source[sourceID])
  206. end
  207. elseif ALB_Source[sourceID].type == "faction" then
  208. if source ~= "" then source = L["multiple"]; break end
  209. source = format("%s: %s", ALB_Source[sourceID].name, ALB_Source[sourceID].rep)
  210. elseif ALB_Source[sourceID].type == "currency" then
  211. if source ~= "" then break end
  212. source = format("%s: %s", ALB_Source[sourceID].name, ALB_Source[sourceID].info)
  213. elseif ALB_Source[sourceID].type == "token" then
  214. if source ~= "" then break end
  215. source = format("%s: %s", ALB_Source[sourceID].name, ALB_Source[sourceID].info)
  216. end
  217. end
  218. end
  219. end
  220. if source == "" then source = "?" end
  221. return source
  222. else
  223. local sourcetable = {}
  224. local cost = ALB:GetItemCost(id)
  225. if cost then table.insert(sourcetable, {text = cost, token=true}) end
  226. local item, group, source
  227. for header, groups in pairs(ALB_Menu) do
  228. for g = 1, #groups do
  229. group = groups[g]
  230. for s = 1, #ALB_Group[group].sources do
  231. source = ALB_Group[group].sources[s]
  232. for i = 1, #ALB_Source[source].items do
  233. item = ALB_Source[source].items[i]
  234. if item == id then
  235. if ALB_Source[source].type == "boss" then
  236. table.insert(sourcetable, {
  237. text = "|T".. ALB_Source[source].image .. ":20:40:0:0|t"..ALB_Source[source].name .. " " .. ALB:BossTypeToText(ALB_Source[source]),
  238. ExpandedHeaders = {header, group},
  239. SelectedInstance = source,
  240. })
  241. elseif ALB_Source[source].type == "faction" then
  242. table.insert(sourcetable, {
  243. text = format("%s: %s", ALB_Source[source].name, ALB_Source[source].rep),
  244. ExpandedHeaders = {header, group},
  245. SelectedInstance = source,
  246. })
  247. elseif ALB_Source[source].type == "currency"
  248. or ALB_Source[source].type == "token" then
  249. table.insert(sourcetable, {
  250. text = format("%s: %s", ALB_Source[source].name, ALB_Source[source].info),
  251. ExpandedHeaders = {header, group},
  252. SelectedInstance = source,
  253. })
  254. end
  255. end
  256. end
  257. end
  258. end
  259. end
  260. return sourcetable
  261. end
  262. end
  263. function ALB:BossTypeToText(tab) -- rename this function
  264. if tab.type == "boss" then
  265. if tab.size > 5 then
  266. return tab.size ..
  267. (tab.mode == "heroic" and " "..L["heroic"] or "")
  268. else
  269. return tab.mode == "heroic" and L["heroic"] or "normal"
  270. end
  271. elseif tab.type == "instance" then
  272. return tab.mode == "heroic" and L["heroic"] or ""
  273. elseif tab.type == "currency" then
  274. return tab.cost
  275. elseif tab.type == "crafting" then
  276. return format("(%s)", GetSpellInfo(tab.id))
  277. end
  278. return " "
  279. end
  280. function ALB:GetGroupName(GroupId)
  281. if ALB_Group[GroupId].type == "instance" then
  282. if ALB_Group[GroupId].size < 10 then
  283. return format("%s %s", ALB_Group[GroupId].name, ALB:BossTypeToText(ALB_Group[GroupId]))
  284. else
  285. return ALB_Group[GroupId].name or ALB_Group[GroupId].name
  286. end
  287. elseif ALB_Group[GroupId].type == "currency" then
  288. return ALB_Group[GroupId].name
  289. elseif ALB_Group[GroupId].type == "token" then
  290. return ALB_Group[GroupId].name
  291. elseif ALB_Group[GroupId].type == "faction" then
  292. return format("%s%s",
  293. ALB_Group[GroupId].horde and ALB_Group[GroupId].alliance and " " or
  294. ALB_Group[GroupId].alliance and ALLIANCE or
  295. ALB_Group[GroupId].horde and HORDE
  296. or " ",
  297. ALB_Group[GroupId].name)
  298. elseif ALB_Group[GroupId].type == "set" then
  299. return ALB_Group[GroupId].name
  300. elseif ALB_Group[GroupId].type == "crafting" then
  301. return ALB_Group[GroupId].name
  302. end
  303. end
  304. function ALB:GetSourceName(source)
  305. if ALB_Source[source].type == "boss" then
  306. return format("%s%s", (ALB_Source[source].mode == "heroic") and HARDMODE or "", ALB_Source[source].name or "WTF")
  307. elseif ALB_Source[source].type == "currency" then
  308. return format("%s %s", ALB_Source[source].name, ALB_Source[source].info or ALB_Source[source].cost)
  309. elseif ALB_Source[source].type == "token" then
  310. return format("%s %s", ALB_Source[source].name, ALB_Source[source].info)
  311. elseif ALB_Source[source].type == "faction" then
  312. return format("%s %s", ALB_Source[source].name, ALB_Source[source].rep)
  313. elseif ALB_Source[source].type == "set" then
  314. return format("T%s %s %s", ALB_Source[source].tier, L[ALB_Source[source].version], ALB_Source[source].ilvl)
  315. elseif ALB_Source[source].type == "crafting" then
  316. return ALB_Source[source].name
  317. end
  318. end
  319. function ALB:GetItemCost(itemId, detailed)
  320. if not detailed then
  321. local token1icon,token1name,token2icon,token2name
  322. if itemId and ALB_Item[itemId] and ALB_Item[itemId].cost then
  323. token1icon = GetItemIcon(ALB_Item[itemId].cost[1]) or format("Interface\\Icons\\%s", select(3, GetCurrencyInfo(ALB_Item[itemId].cost[1])))
  324. if #ALB_Item[itemId].cost == 4 then
  325. token2icon = GetItemIcon(ALB_Item[itemId].cost[3]) or format("Interface\\Icons\\%s", select(3, GetCurrencyInfo(ALB_Item[itemId].cost[3])))
  326. return format("%s |T%s:17:17:0:0|t+%s |T%s:17:17:0:0|t", ALB_Item[itemId].cost[2], token1icon, ALB_Item[itemId].cost[4], token2icon)
  327. else
  328. return format("%s |T%s:17:17:0:0|t", ALB_Item[itemId].cost[2], token1icon)
  329. end
  330. end
  331. elseif itemId and ALB_Item[itemId] and ALB_Item[itemId].cost then
  332. if #ALB_Item[itemId].cost == 4 then
  333. return ALB_Item[itemId].cost[2], ALB_Item[itemId].cost[1], ALB_Item[itemId].cost[4], ALB_Item[itemId].cost[3]
  334. else
  335. return ALB_Item[itemId].cost[2], ALB_Item[itemId].cost[1]
  336. end
  337. end
  338. return nil
  339. end
  340. function ALB:GetCleverItemInfo(itemType, itemSubType, itemEquiploc, itemId)
  341. local itemtype, itemsubtype, itemequiploc, itemid = itemType, itemSubType, itemEquiploc, itemId
  342. local faction = ""
  343. if itemid and ALB_Item[itemid] and ALB_Item[itemid].faction then
  344. faction = ALB_Item[itemid].faction == "ALLIANCE" and ALLIANCE
  345. or ALB_Item[itemid].faction == "HORDE" and HORDE
  346. end
  347. if ALB_Item[itemid].class and ALB.CLASSICON[ALB_Item[itemid].class] then
  348. faction = faction .. ALB.CLASSICON[ALB_Item[itemid].class]
  349. end
  350. if itemtype == BInventory["Armor"] then
  351. if itemsubtype == BInventory["Miscellaneous"] or
  352. itemsubtype == BInventory["Shields"] or
  353. itemsubtype == BInventory["Librams"] or
  354. itemsubtype == BInventory["Idols"] or
  355. itemsubtype == BInventory["Totems"] then
  356. return format("%s %s", faction, _G[itemequiploc] or "")
  357. else
  358. return format("%s %s, %s", faction, _G[itemequiploc], itemsubtype)
  359. end
  360. elseif itemtype == BInventory["Weapon"] then
  361. if itemsubtype == BInventory["Daggers"] or
  362. itemsubtype == BInventory["Fist Weapons"] or
  363. itemsubtype == BInventory["One-Handed Axes"] or
  364. itemsubtype == BInventory["One-Handed Maces"] or
  365. itemsubtype == BInventory["One-Handed Swords"] then
  366. return format("%s %s %s", faction, itemsubtype, (_G[itemequiploc] == INVTYPE_WEAPON and "" or " (".._G[itemequiploc]..")"))
  367. elseif itemsubtype == BInventory["Miscellaneous"] then
  368. return format("%s %s (%s)", faction, itemtype, _G[itemequiploc])
  369. else
  370. return format("%s %s", faction, itemsubtype)
  371. end
  372. elseif itemtype == BInventory["Quest"] then
  373. return format("%s %s", faction, itemtype)
  374. elseif itemtype == "Money" then
  375. return CURRENCY
  376. else
  377. return format("%s %s %s", faction, itemtype, itemtype == itemsubtype and "" or " ("..itemsubtype..")")
  378. end
  379. end
  380. ------------------------------------------------------------------------
  381. ----------- Items n icons stuff -----------------
  382. ------------------------------------------------------------------------
  383. function ALB:ItemEnter()
  384. if not self:GetParent().id then return end
  385. GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  386. if self:GetParent().link then
  387. -- special case in compareframe: items with custom gems/enchants
  388. GameTooltip:SetHyperlink(
  389. "item:"..self:GetParent().id..":"..
  390. self:GetParent().enchant..":"..
  391. self:GetParent().gems[1]..":"..
  392. self:GetParent().gems[2]..":"..
  393. self:GetParent().gems[3] )
  394. GameTooltip:AddLine("|n|T"..GetItemIcon(21191)..":25:25:0:0|t"..
  395. RED.." AphesLootBrowser:")
  396. GameTooltip:AddLine(INDENT..GREEN..L["shift-click to create a chat link."])
  397. elseif type(self:GetParent().id) == "number" then
  398. -- basically all itemicons
  399. SetCursor("INSPECT_CURSOR")
  400. if self:GetParent().save then
  401. GameTooltip:SetHyperlink("item:"..self:GetParent().id)
  402. GameTooltip:AddLine("|n|T"..GetItemIcon(21191)..":25:25:0:0|t"..
  403. RED.." AphesLootBrowser:")
  404. GameTooltip:AddLine(INDENT..GREEN..L["right-click for options"])
  405. else
  406. GameTooltip:SetText(RED..L["unsave warning"])
  407. GameTooltip:AddLine("|r"..L["unsave details1"])
  408. GameTooltip:AddLine("|r"..L["unsave details2"])
  409. GameTooltip:AddLine("|n"..GREEN..L["right-click for options"])
  410. end
  411. elseif type(self:GetParent().id) == "string" then
  412. -- icons in compare menu
  413. GameTooltip:SetHyperlink(self:GetParent().id)
  414. end
  415. if IsShiftKeyDown() then GameTooltip_ShowCompareItem() end
  416. GameTooltip:Show()
  417. end
  418. local stats = {}
  419. function ALB:DetailItemTooltip()
  420. if not (self.id or self:GetParent().id) then return end
  421. local ItemId = self.id or self:GetParent().id
  422. local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, _, itemEquipLoc, itemTexture = GetItemInfo(ItemId)
  423. GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  424. if ALB_Item[ItemId] and ALB_Item[ItemId].spell then
  425. GameTooltip:SetHyperlink("spell:"..ALB_Item[ItemId].spell)
  426. GameTooltip:AddLine(" ")
  427. end
  428. if itemName then
  429. GameTooltip:AddLine(itemName, GetItemQualityColor(itemRarity))
  430. wipe(stats)
  431. GetItemStats(itemLink, stats)
  432. local stattype =
  433. stats.ITEM_MOD_SPIRIT_SHORT and _G.ITEM_MOD_SPIRIT_SHORT or
  434. stats.ITEM_MOD_INTELLECT_SHORT and stats.ITEM_MOD_HIT_RATING_SHORT and format("%s (%s)", _G.ITEM_MOD_SPELL_POWER_SHORT,_G.ITEM_MOD_HIT_RATING_SHORT) or
  435. stats.ITEM_MOD_INTELLECT_SHORT and _G.ITEM_MOD_SPELL_POWER_SHORT or
  436. (stats.ITEM_MOD_DEFENSE_SKILL_RATING_SHORT or stats.ITEM_MOD_DODGE_RATING_SHORT or stats.ITEM_MOD_PARRY_RATING_SHORT or stats.ITEM_MOD_BLOCK_RATING_SHORT) and _G.DEFENSE or
  437. stats.ITEM_MOD_AGILITY_SHORT and _G.ITEM_MOD_AGILITY_SHORT or
  438. stats.ITEM_MOD_STRENGTH_SHORT and _G.ITEM_MOD_STRENGTH_SHORT or "?"
  439. GameTooltip:AddDoubleLine(format("%s: %s", L["ilvl"], itemLevel), ALB:GetCleverItemInfo(itemType, itemSubType, itemEquipLoc, ItemId))
  440. if stattype then
  441. GameTooltip:AddLine(format("%s %s%s|r", StatIcons[stattype], GREEN, stattype))
  442. end
  443. if IsAddOnLoaded("Pawn") then --PAWN
  444. local scales = PawnGetAllScalesEx()
  445. local item
  446. local value = 0
  447. if scales then
  448. item = PawnGetItemData(itemLink)
  449. GameTooltip:AddLine("|nPawn:")
  450. for i = 1, #scales do
  451. if scales[i].IsVisible then
  452. value = format("%.1f", select(2, PawnGetSingleValueFromItem(item, scales[i].Name)) or 0)
  453. UpgradeInfo = PawnIsItemAnUpgrade(item)
  454. local ThisUpgrade, WasUpgrade = true, false
  455. if UpgradeInfo then
  456. for _, ThisUpgrade in pairs(UpgradeInfo) do
  457. if ThisUpgrade.ScaleName == scales[i].Name then
  458. WasUpgrade = true
  459. break
  460. end
  461. end
  462. end
  463. if WasUpgrade then
  464. GameTooltip:AddLine(format(" |cFF%s%s: %s |TInterface\\AddOns\\Pawn\\Textures\\UpgradeArrow:0|t|r Upgrade",PawnCommon.Scales[scales[i].Name].Color ,scales[i].LocalizedName, value))
  465. else
  466. GameTooltip:AddLine(format(" |cFF%s%s: %s|r",PawnCommon.Scales[scales[i].Name].Color ,scales[i].LocalizedName, value))
  467. end
  468. end
  469. end
  470. end
  471. end
  472. else
  473. GameTooltip:AddLine(ALB_Item[ItemId] and ALB_Item[ItemId].name or format("item: %s", ItemId), GetItemQualityColor(0))
  474. GameTooltip:AddLine(format("%s: %s", L["ilvl"], ALB_Item[ItemId] and ALB_Item[ItemId].ilvl or "?"))
  475. end
  476. local sources = ALB:GetItemSource(ItemId, true)
  477. if sources and #sources > 1 then
  478. GameTooltip:AddLine(format("|n%s:|n", L["source"]))
  479. for i = 1, 4 do
  480. if sources[i] then GameTooltip:AddLine(format(" - %s",sources[i].text)) end
  481. end
  482. if sources[5] then GameTooltip:AddLine(" ... etc") end
  483. elseif sources[1] then
  484. GameTooltip:AddLine(format("|n%s: %s", L["source"], sources[1].text))
  485. end
  486. local cost1, token1, cost2, token2 = ALB:GetItemCost(ItemId, true)
  487. if cost1 then
  488. local token1icon = GetItemIcon(token1) or format("Interface\\Icons\\%s", select(3, GetCurrencyInfo(ALB_Item[ItemId].cost[1])))
  489. local token1name = GetItemInfo(token1) or GetCurrencyInfo(ALB_Item[ItemId].cost[1])
  490. GameTooltip:AddLine("|n|n")
  491. GameTooltip:AddLine(format("|T%s:17:17:0:0|t %s:", token1icon, token1name))
  492. sources = ALB:GetItemGroup(token1)
  493. if sources and #sources > 1 then
  494. for i = 1, 4 do
  495. if sources[i] then GameTooltip:AddLine(format(" - %s",sources[i].text)) end
  496. end
  497. if sources[5] then GameTooltip:AddLine(" ...") end
  498. elseif sources[1] then
  499. GameTooltip:AddLine(format(" %s", sources[1].text))
  500. end
  501. if cost2 and token2 ~= 34518 then
  502. local token2icon = GetItemIcon(token2) or format("Interface\\Icons\\%s", select(3, GetCurrencyInfo(ALB_Item[ItemId].cost[3])))
  503. local token2name = GetItemInfo(token2) or GetCurrencyInfo(ALB_Item[ItemId].cost[3])
  504. GameTooltip:AddLine(format("|n|T%s:17:17:0:0|t %s:", token2icon, token2name))
  505. sources = ALB:GetItemGroup(token2)
  506. if sources and #sources > 1 then
  507. for i = 1, 4 do
  508. if sources[i] then GameTooltip:AddLine(format(" - %s",sources[i].text)) end
  509. end
  510. if sources[5] then GameTooltip:AddLine(" ...") end
  511. elseif sources[1] then
  512. GameTooltip:AddLine(format(" %s", sources[1].text))
  513. end
  514. end
  515. end
  516. GameTooltip:Show()
  517. end
  518. local tooltip_timer = 0
  519. function ALB:ItemTooltipUpdate(elapsed)
  520. if not (self == GameTooltip:GetOwner()) then return end
  521. tooltip_timer = tooltip_timer + elapsed
  522. if tooltip_timer > 1 then
  523. tooltip_timer = 0
  524. AphesLootBrowser.ItemEnter(self)
  525. end
  526. end
  527. local function AddToNewWishlist(self, arg1, arg2)
  528. ALB.newWishItem = tonumber(arg1)
  529. ALB:CreateNewWishlist()
  530. end
  531. local ItemMenu = {}
  532. function ALB:ItemContextMenu(level)
  533. ItemMenu = UIDropDownMenu_CreateInfo()
  534. level = level or 1
  535. ItemMenu.arg1 = self.id or self:GetParent().id
  536. if level == 1 then
  537. ItemMenu.hasArrow = false
  538. if self:GetParent().save then
  539. -- if safe:
  540. -- 1 Detail
  541. if not (ALBDetail and ALBDetail:IsVisible()) then
  542. ItemMenu.text = L["open in detail"]
  543. ItemMenu.func = AphesLootBrowser.LoadToDetailFrame
  544. UIDropDownMenu_AddButton(ItemMenu, level)
  545. end
  546. --2 Compare
  547. if not (ALBCompare and ALBCompare:IsVisible()) then
  548. ItemMenu.text = L["add to compare"]
  549. ItemMenu.func = AphesLootBrowser.AddToCompare
  550. UIDropDownMenu_AddButton(ItemMenu, level)
  551. end
  552. -- else
  553. else
  554. --query
  555. ItemMenu.text = L["query server"]
  556. ItemMenu.func = AphesLootBrowser.QueryNextItem
  557. UIDropDownMenu_AddButton(ItemMenu, level)
  558. end
  559. -- 3 Wishlist always
  560. ItemMenu.hasArrow = true
  561. ItemMenu.text = L["add to wishlist"]
  562. ItemMenu.func = nil
  563. UIDropDownMenu_AddButton(ItemMenu, level)
  564. elseif level == 2 then
  565. ItemMenu.text = NEW
  566. ItemMenu.func = AddToNewWishlist
  567. UIDropDownMenu_AddButton(ItemMenu, level)
  568. local listname, character
  569. for namecode, info in pairs(ALB_WISHLIST["#ME#"]) do
  570. listname, character = string.match(namecode, "(.+)@(.+)")
  571. if UnitName("player") == character then
  572. ItemMenu.arg2 = listname
  573. ItemMenu.text = format("%q", listname)
  574. ItemMenu.func = AphesLootBrowser.AddToWishlist
  575. UIDropDownMenu_AddButton(ItemMenu, level)
  576. end
  577. end
  578. end
  579. end
  580. function ALB:ItemClick(itemid, button, down)
  581. if not itemid then return end
  582. if type(itemid) == "number" then
  583. -- basically all itemicons
  584. if button == "LeftButton" and (self:GetParent().save or self.save) then
  585. if IsModifiedClick("DRESSUP") then
  586. DressUpItemLink(itemid)
  587. elseif IsModifiedClick("CHATLINK") then
  588. ChatEdit_InsertLink(select(2, GetItemInfo(itemid)))
  589. end
  590. elseif button == "RightButton" then
  591. local frame = self
  592. if not self:GetParent().id then frame = _G[self:GetName() .. "Icon"] end
  593. ToggleDropDownMenu(nil, nil, frame)
  594. end
  595. else
  596. -- special case in compareframe
  597. PickupItem(itemid)
  598. end
  599. end
  600. function ALB:WishlistClick(itemid)
  601. if not itemid then return end
  602. ToggleDropDownMenu(nil, nil, self)
  603. end
  604. function ALB.MainFrameLoad()
  605. ALBMainMenuBrowserText:SetText(L["browse"])
  606. ALBMainMenuSearchText:SetText(L["search"])
  607. ALBMainMenuDetailText:SetText(L["detail"])
  608. ALBMainMenuCompareText:SetText(L["compare"])
  609. ALBMainMenuWishlistText:SetText(L["wishlist"])
  610. ALBFrameOptions:SetText(L["options"])
  611. ALBMainMenuBrowserActive:Show()
  612. ALBMessageFrame:SetTimeVisible(2)
  613. ALBFrame:RegisterForDrag("LeftButton")
  614. tinsert(UISpecialFrames, "ALBFrame")
  615. end
  616. ------------------------------------------------------------------------
  617. ----------- Roll frame wishlist -----------------
  618. ------------------------------------------------------------------------
  619. local function OnRoll(f, event, id)
  620. if f.id ~= id then return end
  621. f.id = nil
  622. f:Hide()
  623. end
  624. local RollWishFrames
  625. local function CreateRollWishFrames()
  626. RollWishFrames = {}
  627. local f
  628. for i = 1, 4 do
  629. f = CreateFrame("Frame", "ALB"..i, _G["GroupLootFrame"..i], "RollWishFrame")
  630. f:SetScript("OnEvent", OnRoll)
  631. f:RegisterEvent("CANCEL_LOOT_ROLL")
  632. f.wish = _G["ALB"..i.."Wish"]
  633. f.wishframe = _G["ALB"..i.."Wishframe"]
  634. f.wishlist = _G["ALB"..i.."WishframeText"]
  635. f:Hide()
  636. table.insert(RollWishFrames, f)
  637. end
  638. end
  639. local function GetFrame(id)
  640. if not RollWishFrames then CreateRollWishFrames() end
  641. for _,f in ipairs(RollWishFrames) do
  642. if not f.id then return f end
  643. end
  644. end
  645. function ALB:START_LOOT_ROLL(self, id, timer)
  646. if ALB_SETTINGS.RollFrameWishlists or ALB_SETTINGS.PlaySounds then
  647. local itemid = tonumber(GetLootRollItemLink(id):match("item:(%d+):"))
  648. if not itemid then return end
  649. local f
  650. if ALB_SETTINGS.RollFrameWishlists then
  651. f = GetFrame(id)
  652. f.id = id
  653. f:Show()
  654. f.wish:Hide()
  655. f.wishframe:Hide()
  656. end
  657. local wishlist = nil
  658. if ALB_WISHLIST then
  659. for listname, _ in pairs(ALB_WISHLIST) do
  660. for name, info in pairs(ALB_WISHLIST[listname]) do
  661. if name ~= "#sync#" then
  662. for i = 1, #info.list do
  663. if itemid == info.list[i] then
  664. local listname, character = string.match(name, "(.+)@(.+)")
  665. if UnitExists(character) then
  666. if not wishlist then wishlist = " |cffff0000Wunschlisten:" end
  667. if character == UnitName("player") then
  668. if ALB_SETTINGS.RollFrameWishlists then f.wish:Show() end
  669. PlaySoundFile(ALB_SETTINGS.PlaySound and Sounds[ALB_SETTINGS.Sound] or "")
  670. end
  671. character = (ALDclass and ALDclass[character] and ClassColor[ALDclass[character]]..character) or character
  672. wishlist = wishlist .. "|n "..format("%s|r (%s)", character, listname)
  673. end
  674. end
  675. end
  676. end
  677. end
  678. end
  679. end
  680. if wishlist and ALB_SETTINGS.RollFrameWishlists then
  681. f.wishframe:Show()
  682. f.wishlist:SetText(wishlist)
  683. end
  684. end
  685. end
  686. ALB:RegisterEvent("START_LOOT_ROLL")
  687. ------------------------------------------------------------------------
  688. ----------- Tooltip hook -----------------
  689. ------------------------------------------------------------------------
  690. local function OnTooltipSetItem(frame, ...)
  691. if ALB_SETTINGS.ShowWishlistTooltips then
  692. local name, link = frame:GetItem()
  693. if link then
  694. local header = false
  695. local id = tonumber(link:match("item:(%d+):"))
  696. for _, lists in pairs(ALB_WISHLIST) do
  697. for name, info in pairs(lists) do
  698. if name ~= "#sync#" and info.list and type(info.list) == "table" then
  699. for i = 1, #info.list do
  700. if id == info.list[i] then
  701. if not header then
  702. frame:AddLine("|n|T"..GetItemIcon(21191)..":20:20:0:0|tALB:|n"..RED..L["wishlist"]..":|n")
  703. header = true
  704. end
  705. local listname, character = string.match(name, "(.+)@(.+)")
  706. character = (ALDclass and ALDclass[character] and ClassColor[ALDclass[character]]..character) or character
  707. frame:AddLine(INDENT..format("%s|r (%s)", character, listname))
  708. end
  709. end
  710. end
  711. end
  712. end
  713. local sources = ALB:GetItemSource(id, true)
  714. if #sources >0 then
  715. if not header then
  716. frame:AddLine("|n|T"..GetItemIcon(21191)..":20:20:0:0|tALB:|n")
  717. header = true
  718. end
  719. if #sources > 1 then
  720. frame:AddLine(format("%s:|n", RED..L["source"].."|r"))
  721. for i = 1, 4 do
  722. if sources[i] then frame:AddLine(format(" - %s",sources[i].text)) end
  723. end
  724. if sources[5] then frame:AddLine(" ... etc") end
  725. elseif sources[1] then
  726. frame:AddLine(format("|n%s: %s", L["source"], sources[1].text))
  727. end
  728. end
  729. frame:Show()
  730. end
  731. end
  732. end
  733. local tip_funcs = {
  734. "SetAuctionItem", "SetAuctionSellItem", "SetAuctionCompareItem", "SetBagItem", "SetBuybackItem", "SetCraftItem", "SetGuildBankItem", "SetHyperlink",
  735. "SetHyperlinkCompareItem", "SetInboxItem", "SetInventoryItem", "SetLootItem", "SetLootRollItem", "SetMerchantCompareItem", "SetMerchantItem", "SetQuestItem",
  736. "SetSendMailItem", "SetTradePlayerItem", "SetTradeSkillItem", "SetTradeTargetItem", "SetMerchantCostItem",}
  737. --"SetQuestLogItem"
  738. for _,frame in pairs { GameTooltip, ShoppingTooltip1, ShoppingTooltip2, ShoppingTooltip3,
  739. ItemRefTooltip, ItemRefShoppingTooltip1, ItemRefShoppingTooltip2, ItemRefShoppingTooltip3 } do
  740. for _,func in pairs(tip_funcs) do
  741. if frame and frame[func] then
  742. hooksecurefunc(frame, func, OnTooltipSetItem)
  743. end
  744. end
  745. end
  746. ------------------------------------------------------------------------
  747. ----------- MAIN MENU stuff -----------------
  748. ------------------------------------------------------------------------
  749. function ALB.MainMenuClick(self, button, down)
  750. PlaySound("igCharacterInfoTab")
  751. ALBMainMenuBrowserActive:Hide()
  752. ALBMainMenuSearchActive:Hide()
  753. ALBMainMenuDetailActive:Hide()
  754. ALBMainMenuCompareActive:Hide()
  755. ALBMainMenuWishlistActive:Hide()
  756. _G[self:GetName() .. "Active"]:Show()
  757. local id = self:GetID()
  758. ALBBrowser:Hide()
  759. CloseDropDownMenus()
  760. if ALBOptions then ALBOptions:Hide() end
  761. if ALBSearchFilterPopup and ALBSearchFilterPopup:IsVisible() then ALBSearchFilterPopupDelete:Click() end
  762. if ALBSearch then ALBSearch:Hide() end
  763. if ALBDetail then ALBDetail:Hide() end
  764. if ALBCompare then ALBCompare:Hide() end
  765. if ALBWishlist then ALBWishlist:Hide() end
  766. if id == 1 then
  767. ALBBrowser:Show()
  768. elseif id == 2 then
  769. if ALBSearch then ALBSearch:Show()
  770. else
  771. CreateFrame("Frame", "ALBSearch", ALBFrame, "ALBSearch")
  772. end
  773. elseif id == 3 then
  774. if ALBDetail then ALBDetail:Show()
  775. else
  776. CreateFrame("Frame", "ALBDetail", ALBFrame, "ALBDetail")
  777. end
  778. elseif id == 4 then
  779. if ALBCompare then ALBCompare:Show()
  780. else
  781. CreateFrame("Frame", "ALBCompare", ALBFrame, "ALBCompare")
  782. end
  783. elseif id == 5 then
  784. if ALBWishlist then ALBWishlist:Show()
  785. else
  786. CreateFrame("Frame", "ALBWishlist", ALBFrame, "ALBWishlist")
  787. end
  788. end
  789. end
  790. ----------------------
  791. -- Minimap Button --
  792. ----------------------
  793. local function moveButton(self)
  794. local centerX, centerY = Minimap:GetCenter()
  795. local x, y = GetCursorPosition()
  796. x, y = x / self:GetEffectiveScale() - centerX, y / self:GetEffectiveScale() - centerY
  797. centerX, centerY = math.abs(x), math.abs(y)
  798. centerX, centerY = (centerX / math.sqrt(centerX^2 + centerY^2)) * ALB_SETTINGS.MinimapIconRadius, (centerY / sqrt(centerX^2 + centerY^2)) * ALB_SETTINGS.MinimapIconRadius
  799. centerX = x < 0 and -centerX or centerX
  800. centerY = y < 0 and -centerY or centerY
  801. self:ClearAllPoints()
  802. self:SetPoint("CENTER", centerX, centerY)
  803. end
  804. function ALB:CreateMinimapButton()
  805. local button = CreateFrame("Button", "ALBMinimapButton", Minimap, "ALB_MinimapButton")
  806. button:SetMovable(true)
  807. button:SetUserPlaced(true)
  808. button:SetScript("OnMouseDown", function(self, button)
  809. if IsShiftKeyDown() or button == "RightButton" then
  810. self:SetScript("OnUpdate", moveButton)
  811. end
  812. end)
  813. button:SetScript("OnMouseUp", function(self)
  814. self:SetScript("OnUpdate", nil)
  815. end)
  816. button:SetScript("OnClick", function(self, button)
  817. if IsShiftKeyDown() or button == "RightButton" then return end
  818. ALB:ToggleWindow()
  819. end)
  820. button:SetScript("OnEnter", function(self)
  821. GameTooltip_SetDefaultAnchor(GameTooltip, self)
  822. GameTooltip:SetText(L["AphesLootBrowser"], 1, 1, 1)
  823. GameTooltip:AddLine(format(L["Version/Revision"], ALB_VERSION, ALB_REVISION))
  824. GameTooltip:AddLine(" ")
  825. GameTooltip:AddLine(GREEN..L["left-click to open/close ALB"])
  826. GameTooltip:AddLine(GREEN..L["right-click to move"])
  827. GameTooltip:Show()
  828. end)
  829. button:SetScript("OnLeave", function(self)
  830. GameTooltip:Hide()
  831. end)
  832. if not ALB_SETTINGS.ShowMinimapIcon then button:Hide() end
  833. end
  834. function ALB:ToggleMinimapButton()
  835. ALB_SETTINGS.ShowMinimapIcon = not ALB_SETTINGS.ShowMinimapIcon
  836. if ALB_SETTINGS.ShowMinimapIcon then
  837. if ALBMinimapButton then ALBMinimapButton:Show()
  838. else ALB:CreateMinimapButton() end
  839. else
  840. if ALBMinimapButton then ALBMinimapButton:Hide() end
  841. end
  842. end
  843. function ALB:PositionMinimapButton()
  844. ALB_SETTINGS.MinimapIconRadius = ALBOptionsMinimapRadius:GetValue()
  845. local centerX, centerY = Minimap:GetCenter()
  846. local x, y = ALBMinimapButton:GetCenter()
  847. x, y = x - centerX, y - centerY
  848. centerX, centerY = math.abs(x), math.abs(y)
  849. centerX, centerY = (centerX / math.sqrt(centerX^2 + centerY^2)) * ALB_SETTINGS.MinimapIconRadius, (centerY / sqrt(centerX^2 + centerY^2)) * ALB_SETTINGS.MinimapIconRadius
  850. centerX = x < 0 and -centerX or centerX
  851. centerY = y < 0 and -centerY or centerY
  852. ALBMinimapButton:ClearAllPoints()
  853. ALBMinimapButton:SetPoint("CENTER", centerX, centerY)
  854. end
  855. ------------------------------------------------------------------------
  856. ----------- Data-Broker stuff -----------------
  857. ------------------------------------------------------------------------
  858. LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("AphesLootBrowser", {
  859. type = "launcher",
  860. label = "ALB",
  861. OnClick = function(_, btn)
  862. ALB:ToggleWindow()
  863. end,
  864. icon = "Interface\\Icons\\INV_Holiday_Christmas_Present_01",
  865. OnTooltipShow = function(tooltip)
  866. if not tooltip or not tooltip.AddLine then return end
  867. tooltip:SetText(L["AphesLootBrowser"])
  868. tooltip:AddLine(format(L["Version/Revision"], ALB_VERSION, ALB_REVISION))
  869. tooltip:AddLine(" ")
  870. tooltip:AddLine(GREEN..L["left-click to open/close ALB"])
  871. end,
  872. })
  873. ------------------------------------------------------------------------
  874. ----------- OPTIONS -----------------
  875. ------------------------------------------------------------------------
  876. local function SoundChanged(self)
  877. for i = 1, 20 do
  878. _G["ALBOptionsRace"..i]:SetChecked(false)
  879. _G["ALBOptionsRace"..i.."Icon"]:SetDesaturated(1)
  880. end
  881. self:SetChecked(1)
  882. _G[self:GetName().."Icon"]:SetDesaturated(false)
  883. ALB_SETTINGS.Sound = self:GetID()
  884. PlaySoundFile(Sounds[self:GetID()])
  885. end
  886. function ALB:OptionsShow()
  887. if not ALBOptions then
  888. CreateFrame("Frame", "ALBOptions", ALBFrame, "ALBOptions")
  889. ALBOptionsHeader:SetText(L["options"])
  890. ALBOptionsMinimapShowText:SetText(L["show minimap button"])
  891. ALBOptionsMinimapRadiusText:SetText(L["minimap radius"])
  892. ALBOptionsTooltipText:SetText(L["show wishlists in item tooltips"])
  893. ALBOptionsAskRaidSyncText:SetText(L["ask me to import raidmember's wishlists"])
  894. --ALBOptionsQueryAll:SetText(L["query server"])
  895. ALBOptionsVersion:SetText(L["ALB versions"])
  896. ALBOptionsMinimapShow:SetChecked(ALB_SETTINGS.ShowMinimapIcon)
  897. ALBOptionsMinimapRadius:SetValue(ALB_SETTINGS.MinimapIconRadius)
  898. ALBOptionsTooltip:SetChecked(ALB_SETTINGS.ShowWishlistTooltips)
  899. ALBOptionsAskRaidSync:SetChecked(ALB_SETTINGS.AskForRaidsync)
  900. ALBOptionsMinimapRadius:SetScript("OnValueChanged", AphesLootBrowser.PositionMinimapButton)
  901. if IsAddOnLoaded("AphesLootDingen") then
  902. ALBOptionsRollFrameWishlists:Disable()
  903. ALBOptionsRollFrameWishlists:SetChecked(nil)
  904. ALBOptionsRollFrameWishlistsText:SetText(format("%s(%s) %s", GREY, ADDON_DISABLED,L["show wishlists next to lootroll frames"]))
  905. else
  906. ALBOptionsRollFrameWishlists:SetChecked(ALB_SETTINGS.RollFrameWishlists)
  907. ALBOptionsRollFrameWishlistsText:SetText(L["show wishlists next to lootroll frames"])
  908. end
  909. ALBOptionsPlaySoundsText:SetText(L["Play sound when rolling for an item on your wishlist"])
  910. ALBOptionsPlaySounds:SetChecked(ALB_SETTINGS.PlaySounds)
  911. local f
  912. local line, column = 1, 1
  913. for i = 1, 20 do
  914. f = CreateFrame("CheckButton", "ALBOptionsRace"..i, ALBOptions, "ClassButtonTemplate")
  915. f:SetPoint("TOPLEFT", i < 11 and 55 + (i * 33) or 55 + ((i- 10) * 33), i < 11 and -310 or -343)
  916. _G["ALBOptionsRace"..i.."Icon"]:SetTexCoord((column-1)*0.125, column*0.125, (line-1)*0.25 , line*0.25)
  917. f:SetChecked(i == ALB_SETTINGS.Sound)
  918. _G["ALBOptionsRace"..i.."Icon"]:SetDesaturated(i ~= ALB_SETTINGS.Sound)
  919. f:SetID(i)
  920. f:SetScript("OnClick", SoundChanged)
  921. column = column + 1
  922. if column > 5 then
  923. column = 1
  924. line = line + 1
  925. end
  926. end
  927. end
  928. ALBOptions:Show()
  929. end
  930. function ALB:OptionsChanged()
  931. ALB_SETTINGS.ShowWishlistTooltips = ALBOptionsTooltip:GetChecked() and true or false
  932. ALB_SETTINGS.AskForRaidsync = ALBOptionsAskRaidSync:GetChecked() and true or false
  933. ALB_SETTINGS.RollFrameWishlists = ALBOptionsRollFrameWishlists:GetChecked() and true or false
  934. ALB_SETTINGS.PlaySounds = ALBOptionsPlaySounds:GetChecked() and true or false
  935. if self:GetName() == "ALBOptionsPlaySounds" and ALB_SETTINGS.PlaySounds then
  936. PlaySoundFile(Sounds[ALB_SETTINGS.Sound])
  937. end
  938. end
  939. ------------------------------------------------------------------------
  940. ----------- Query ALLL items -----------------
  941. ------------------------------------------------------------------------
  942. function ALB:QueryAllTooltip()
  943. GameTooltip:SetOwner(_G["ALBOptionsQueryAll"], "ANCHOR_RIGHT")
  944. GameTooltip:SetText(L["query server"])
  945. GameTooltip:AddLine("|n"..L["Queries the server for ALL unsave items."])
  946. GameTooltip:AddLine(L["This will take ages! But you can continue playing until..."])
  947. GameTooltip:AddLine(RED..L["You may be disconnected."])
  948. GameTooltip:Show()
  949. end
  950. function ALB:QueryReallyAll()
  951. if queryall then return end
  952. queryall = true
  953. wipe(unknownItems)
  954. for id,_ in pairs(ALB_Item) do
  955. GetItemInfo(id)
  956. end
  957. ALB:pri(L["All available itemlists loaded"])
  958. collectgarbage()
  959. local f = CreateFrame("Frame", "ALBFrame", UIParent, "ALB_Main")
  960. f:SetPoint("CENTER", UIParent)
  961. CreateFrame("Frame", "ALBBrowser", f, "ALBBrowser")
  962. AphesLootBrowser.UpdateInstanceList()
  963. --end
  964. end
  965. function ALB:InitQueryReallyAll()
  966. wipe(unknownItems)
  967. for id,_ in pairs(ALB_Item) do
  968. if not GetItemInfo(id) then
  969. table.insert(unknownItems, id)
  970. end
  971. end
  972. ALB:ToggleWindow()
  973. StaticPopupDialogs["ALBQueryAll"].text = format(L["Checking %s unsave items will take approximately %s."], #unknownItems, format("%s%s|r", RED, SecondsToTime(#unknownItems * 5, false, true)))
  974. StaticPopup_Show ("ALBQueryAll")
  975. end
  976. ------------------------------------------------------------------------
  977. ----------- Synclinks in chat -----------------
  978. ------------------------------------------------------------------------
  979. local function ChatLink(link, text, button)
  980. if link and type(link) == "string" and string.find(link, "ALB#(.+)") then
  981. local _,_, player = string.find(link, "ALB#(.+)")
  982. ALB:RequestWishlist(player)
  983. return
  984. end
  985. ALB.OriHook(link, text, button)
  986. end
  987. ------------------------------------------------------------------------
  988. ----------- Frame create -----------------
  989. ------------------------------------------------------------------------
  990. local function LoadAddons()
  991. local Addon = {
  992. "ALB_Cata_Rep",
  993. "ALB_Cata_Currency",
  994. }
  995. for i = 1, #Addon do
  996. if not IsAddOnLoaded(Addon[i]) then
  997. LoadAddOn(Addon[i])
  998. end
  999. end
  1000. ALB:QueryReallyAll()
  1001. end
  1002. function ALB:ToggleWindow()
  1003. if _G.ALBEJTimer and _G.ALBEJTimer:IsShown() then return end
  1004. wipe(ALB.droptext)
  1005. if ALDDB then
  1006. local tab, itemid, day, boss
  1007. tab = {}
  1008. for i = 1, #ALDDB do
  1009. itemid = tonumber(ALDDB[i].loot:match("item:(%d+):"))
  1010. boss = ALB:GetItemSource(itemid, false, true)
  1011. _,_, day = strfind(ALDDB[i].day, "(%d%d%d%d%d%d)%d%d%d%d")
  1012. if boss and ALB_Source[boss] and ALB_Source[boss].type == "boss" then
  1013. tab[boss] = tab[boss] or {}
  1014. tab[boss].killdate = tab[boss].killdate or {}
  1015. tab[boss].kills = tab[boss].kills or 0
  1016. if not tab[boss].killdate[day] then
  1017. tab[boss].killdate[day] = true
  1018. tab[boss].kills = tab[boss].kills + 1
  1019. end
  1020. tab[boss].items = tab[boss].items or {}
  1021. tab[boss].items[itemid] = tab[boss].items[itemid] and tab[boss].items[itemid] + 1 or 1
  1022. end
  1023. end
  1024. for boss, info in pairs(tab) do
  1025. for id, count in pairs(info.items) do
  1026. ALB.droptext[id] = count.."/"..info.kills.." (".. floor(( ( count / info.kills ) * 100 )+0.5) .. "%)"
  1027. end
  1028. end
  1029. end
  1030. if not _G.ALBFrame then
  1031. LoadAddons()
  1032. else
  1033. if _G.ALBFrame:IsVisible() then
  1034. CloseDropDownMenus()
  1035. _G.ALBFrame:Hide()
  1036. else _G.ALBFrame:Show() end
  1037. end
  1038. end
  1039. local function Presets()
  1040. ALB_SETTINGS = ALB_SETTINGS or {}
  1041. ALB_SETTINGS.ShowMinimapIcon = tostring(ALB_SETTINGS.ShowMinimapIcon) == "nil" and true or ALB_SETTINGS.ShowMinimapIcon
  1042. ALB_SETTINGS.MinimapIconRadius = ALB_SETTINGS.MinimapIconRadius or 80
  1043. ALB_SETTINGS.ShowWishlistTooltips = tostring(ALB_SETTINGS.ShowWishlistTooltips) == "nil" and true or ALB_SETTINGS.ShowWishlistTooltips
  1044. ALB_SETTINGS.AskForRaidsync = tostring(ALB_SETTINGS.AskForRaidsync) == "nil" and true or ALB_SETTINGS.AskForRaidsync
  1045. ALB_SETTINGS.RollFrameWishlists = tostring(ALB_SETTINGS.RollFrameWishlists) == "nil" and true or ALB_SETTINGS.RollFrameWishlists
  1046. ALB_SETTINGS.PlaySounds = ALB_SETTINGS.PlaySounds
  1047. ALB_SETTINGS.Sound = tostring(ALB_SETTINGS.Sound) == "nil" and 13 or ALB_SETTINGS.Sound
  1048. end
  1049. function ALB:ADDON_LOADED(self, addon)
  1050. if addon ~= "AphesLootBrowser" then return end
  1051. ALB:UnregisterEvent("ADDON_LOADED")
  1052. Presets()
  1053. ALB:CreateCompareTable()
  1054. if not ALB_WISHLIST then
  1055. ALB_WISHLIST = {}
  1056. ALB_WISHLIST["#ME#"] = {}
  1057. end
  1058. ALB:CreateMinimapButton()
  1059. ALB.OriHook = SetItemRef
  1060. SetItemRef = ChatLink
  1061. -- hooksecurefunc("ChatFrame_OnHyperlinkShow", ChatLink)
  1062. end
  1063. function ALB:EJ_LOOT_DATA_RECIEVED(event, id)
  1064. if id then
  1065. ALB_Item[id] = {name = GetItemInfo(id), ilvl = select(4, GetItemInfo(id))}
  1066. end
  1067. end
  1068. function ALB:Check_EJ_Loot()
  1069. local itemcount = 0
  1070. for u = 1, 2 do
  1071. local instanceIndex = 1
  1072. local isRaid = u == 2
  1073. local instanceId, instanceName, instanceDesc, nowas, bild = EJ_GetInstanceByIndex(instanceIndex, isRaid)
  1074. local runs = 0
  1075. while instanceId do
  1076. EJ_SelectInstance(instanceId)
  1077. instanceName, instanceDesc, bild = EJ_GetInstanceInfo()
  1078. if isRaid then
  1079. runs = 4
  1080. else
  1081. runs = 2
  1082. end
  1083. for i = 1, runs do
  1084. local bossIndex = 1
  1085. local name, desc, bossId = EJ_GetEncounterInfoByIndex(bossIndex)
  1086. while name and bossIndex < 25 do
  1087. EJ_SelectEncounter(bossId)
  1088. EJ_SetDifficulty((i == 2 or i == 4), (i==1 or i==2))
  1089. for i = 1,EJ_GetNumLoot() do
  1090. itemcount = itemcount + 1
  1091. end
  1092. bossIndex = bossIndex + 1
  1093. name, desc, bossId = EJ_GetEncounterInfoByIndex(bossIndex)
  1094. end
  1095. end
  1096. instanceIndex = instanceIndex + 1
  1097. instanceId, instanceName, instanceDesc, nowas, bild = EJ_GetInstanceByIndex(instanceIndex, isRaid)
  1098. end
  1099. end
  1100. return itemcount
  1101. end
  1102. function ALB:Gather_EJ_Loot()
  1103. if not ALB_Item then ALB_Item = {} end
  1104. if not ALB_Source then ALB_Source = {} end
  1105. if not ALB_Menu then ALB_Menu = {} end
  1106. if not ALB_Group then ALB_Group = {} end
  1107. local itemcount = 0
  1108. local check = true
  1109. for u = 1, 2 do
  1110. local instanceIndex = 1
  1111. local isRaid = u == 2
  1112. local instanceId, instanceName, instanceDesc, nowas, bild = EJ_GetInstanceByIndex(instanceIndex, isRaid)
  1113. local runs = 0
  1114. while instanceId do
  1115. EJ_SelectInstance(instanceId)
  1116. instanceName, instanceDesc, bild = EJ_GetInstanceInfo()
  1117. if isRaid then
  1118. for num = 1, 2 do
  1119. local player = num == 1 and 10 or 25
  1120. ALB_Menu["Raid "..player] = ALB_Menu["Raid "..player] or {}
  1121. table.insert(ALB_Menu["Raid "..player], instanceName..player)
  1122. ALB_Group[instanceName..player] = {
  1123. name = instanceName,
  1124. type = "instance",
  1125. size = player,
  1126. mode = "hardmode",
  1127. instanceId = instanceId,
  1128. sources = {},
  1129. image = bild,
  1130. }
  1131. end
  1132. runs = 4
  1133. else
  1134. for num = 1, 2 do
  1135. local mode = num == 1 and "normal" or "heroic"
  1136. ALB_Menu["5"..mode] = ALB_Menu["5"..mode] or {}
  1137. table.insert(ALB_Menu["5"..mode], instanceName.."5"..mode)
  1138. ALB_Group[instanceName.."5"..mode] = {
  1139. name = instanceName,
  1140. type = "instance",
  1141. size = 5,
  1142. mode = mode,
  1143. instanceId = instanceId,
  1144. sources = {},
  1145. image = bild,
  1146. }
  1147. end
  1148. runs = 2
  1149. end
  1150. for i = 1, runs do
  1151. local bossIndex = 1
  1152. local name, desc, bossId = EJ_GetEncounterInfoByIndex(bossIndex)
  1153. while name and bossIndex < 25 do
  1154. local size = (runs==2 and "5" or i<3 and "10" or "25")
  1155. local version = (i==2 or i==4) and "heroic" or "normal"
  1156. table.insert(ALB_Group[instanceName..size..(size == "5" and version or "")].sources, name..size..version)
  1157. local _, _, _, _, bossImage = EJ_GetCreatureInfo(bossIndex, bossId)
  1158. bossImage = bossImage or select(5,EJ_GetCreatureInfo(1, bossId, instanceId))
  1159. bossImage = bossImage or "Interface\\EncounterJournal\\UI-EJ-BOSS-Default"
  1160. EJ_SelectEncounter(bossId)
  1161. ALB_Source[name..size..version] = {
  1162. name = name,
  1163. type = "boss",
  1164. bossId = bossId,
  1165. instanceID = instanceId,
  1166. size = tonumber(size),
  1167. mode = (i==2 or i==4) and "heroic" or "normal",
  1168. items = {},
  1169. image = bossImage,
  1170. }
  1171. --EJ_SetDifficulty(EncounterJournal.isHeroic, EncounterJournal.is10Man)
  1172. EJ_SetDifficulty((i == 2 or i == 4), (i==1 or i==2))
  1173. for i = 1,EJ_GetNumLoot() do
  1174. local iname, _, _, _, itemID = EJ_GetLootInfoByIndex(i)
  1175. check = true
  1176. for x = 1, #ALB_Source[name..size..version].items do
  1177. if ALB_Source[name..size..version].items[x] == itemID then check = false end
  1178. end
  1179. if check then
  1180. itemcount = itemcount + 1
  1181. table.insert(ALB_Source[name..size..version].items, itemID)
  1182. if iname ~= RETRIEVING_ITEM_INFO then
  1183. ALB_Item[itemID] = {name = GetItemInfo(itemID), ilvl = select(4, GetItemInfo(itemID))}
  1184. else
  1185. ALB_Item[itemID] = {name = iname, ilvl = 0}
  1186. end
  1187. end
  1188. end
  1189. bossIndex = bossIndex + 1
  1190. name, desc, bossId = EJ_GetEncounterInfoByIndex(bossIndex)
  1191. end
  1192. end
  1193. instanceIndex = instanceIndex + 1
  1194. instanceId, instanceName, instanceDesc, nowas, bild = EJ_GetInstanceByIndex(instanceIndex, isRaid)
  1195. end
  1196. end
  1197. return itemcount
  1198. end
  1199. function ALB:FirstLoad(self)
  1200. local timer = CreateFrame("Frame", "ALBEJTimer", UIParent)
  1201. timer:Hide()
  1202. timer.time = 0
  1203. timer.count = 0
  1204. timer:SetScript("OnUpdate", function (this, elapsed)
  1205. timer.time = timer.time + elapsed
  1206. if timer.time > 1 then
  1207. timer.count = timer.count + 1
  1208. timer.time = 0
  1209. local count = ALB:Check_EJ_Loot()
  1210. if count > 2850 then
  1211. ALB:Gather_EJ_Loot()
  1212. timer:Hide()
  1213. end
  1214. end
  1215. end)
  1216. timer:Show()
  1217. end
  1218. StaticPopupDialogs["ALBQueryAll"] = {
  1219. button1 = ACCEPT,
  1220. button2 = CANCEL,
  1221. sound = "JewelcraftingFinalize",
  1222. whileDead = 1,
  1223. hideOnEscape = 1,
  1224. timeout = 0,
  1225. OnAccept = function() ALB:QueryReallyAll() end,
  1226. OnCancel = function() ALB:ToggleWindow() end
  1227. }
  1228. SLASH_APHESLOOTBROWSER1 = "/ALB"
  1229. SLASH_APHESLOOTBROWSER2 = "/AphesLootBrowser"
  1230. SlashCmdList["APHESLOOTBROWSER"] = function(arg)
  1231. ALB:ToggleWindow()
  1232. end
  1233. SLASH_APHESLOOTBROWSERVERSIONCHECK1 = "/ALBversion"
  1234. SlashCmdList["APHESLOOTBROWSERVERSIONCHECK"] = function(arg)
  1235. ALB:CheckVersions()
  1236. end
  1237. ALB:RegisterEvent("ADDON_LOADED")
  1238. --ALB:RegisterEvent("PLAYER_ALIVE")
  1239. ALB:RegisterEvent("EJ_LOOT_DATA_RECIEVED")