Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.85 KB | None | 0 0
  1. if not LibStub then return end
  2.  
  3. local dewdrop = LibStub('Dewdrop-2.0', true)
  4. local icon = LibStub('LibDBIcon-1.0')
  5.  
  6. local _
  7.  
  8. local CreateFrame = CreateFrame
  9. local C_ToyBox = C_ToyBox
  10. local GetBindLocation = GetBindLocation
  11. local GetContainerItemCooldown = GetContainerItemCooldown
  12. local GetContainerItemInfo = GetContainerItemInfo
  13. local GetContainerItemLink = GetContainerItemLink
  14. local GetContainerNumSlots = GetContainerNumSlots
  15. local GetItemCooldown = GetItemCooldown
  16. local GetInventoryItemCooldown = GetInventoryItemCooldown
  17. local GetInventoryItemLink = GetInventoryItemLink
  18. local GetNumGroupMembers = GetNumGroupMembers
  19. local GetSpellBookItemName = GetSpellBookItemName
  20. local GetSpellCooldown = GetSpellCooldown
  21. local GetSpellInfo = GetSpellInfo
  22. local GetTime = GetTime
  23. local IsPlayerSpell = IsPlayerSpell
  24. local PlayerHasToy = PlayerHasToy
  25. local SecondsToTime = SecondsToTime
  26. local SendChatMessage = SendChatMessage
  27. local UnitInRaid = UnitInRaid
  28.  
  29. local addonName, addonTable = ...
  30. local L = addonTable.L
  31.  
  32. -- IDs of items usable for transportation
  33. local items = {
  34. -- Dalaran rings
  35. 40586, -- Band of the Kirin Tor
  36. 48954, -- Etched Band of the Kirin Tor
  37. 48955, -- Etched Loop of the Kirin Tor
  38. 48956, -- Etched Ring of the Kirin Tor
  39. 48957, -- Etched Signet of the Kirin Tor
  40. 45688, -- Inscribed Band of the Kirin Tor
  41. 45689, -- Inscribed Loop of the Kirin Tor
  42. 45690, -- Inscribed Ring of the Kirin Tor
  43. 45691, -- Inscribed Signet of the Kirin Tor
  44. 44934, -- Loop of the Kirin Tor
  45. 44935, -- Ring of the Kirin Tor
  46. 40585, -- Signet of the Kirin Tor
  47. 51560, -- Runed Band of the Kirin Tor
  48. 51558, -- Runed Loop of the Kirin Tor
  49. 51559, -- Runed Ring of the Kirin Tor
  50. 51557, -- Runed Signet of the Kirin Tor
  51. -- Engineering Gadgets
  52. 30542, -- Dimensional Ripper - Area 52
  53. 18984, -- Dimensional Ripper - Everlook
  54. 18986, -- Ultrasafe Transporter: Gadgetzan
  55. 30544, -- Ultrasafe Transporter: Toshley's Station
  56. 48933, -- Wormhole Generator: Northrend
  57. 87215, -- Wormhole Generator: Pandaria
  58. 112059, -- Wormhole Centrifuge
  59. -- Seasonal items
  60. 37863, -- Direbrew's Remote
  61. 21711, -- Lunar Festival Invitation
  62. -- Miscellaneous
  63. 46874, -- Argent Crusader's Tabard
  64. 32757, -- Blessed Medallion of Karabor
  65. 35230, -- Darnarian's Scroll of Teleportation
  66. 50287, -- Boots of the Bay
  67. 52251, -- Jaina's Locket
  68. 43824, -- The Schools of Arcane Magic - Mastery
  69. 58487, -- Potion of Deepholm
  70. 65274, -- Cloak of Coordination (Horde)
  71. 65360, -- Cloak of Coordination (Alliance)
  72. 63378, -- Hellscream's Reach Tabard
  73. 63379, -- Baradin's Wardens Tabard
  74. 64457, -- The Last Relic of Argus
  75. 63206, -- Wrap of Unity (Alliance)
  76. 63207, -- Wrap of Unity (Horde)
  77. 63352, -- Shroud of Cooperation (Alliance)
  78. 63353, -- Shroud of Cooperation (Horde)
  79. 95050, -- The Brassiest Knuckle (Horde)
  80. 95051, -- The Brassiest Knuckle (Alliance)
  81. 95567, -- Kirin Tor Beacon
  82. 95568, -- Sunreaver Beacon
  83. 17690, -- Frostwolf Insignia Rank 1 (Horde)
  84. 17905, -- Frostwolf Insignia Rank 2 (Horde)
  85. 17906, -- Frostwolf Insignia Rank 3 (Horde)
  86. 17907, -- Frostwolf Insignia Rank 4 (Horde)
  87. 17908, -- Frostwolf Insignia Rank 5 (Horde)
  88. 17909, -- Frostwolf Insignia Rank 6 (Horde)
  89. 17691, -- Stormpike Insignia Rank 1 (Alliance)
  90. 17900, -- Stormpike Insignia Rank 2 (Alliance)
  91. 17901, -- Stormpike Insignia Rank 3 (Alliance)
  92. 17902, -- Stormpike Insignia Rank 4 (Alliance)
  93. 17903, -- Stormpike Insignia Rank 5 (Alliance)
  94. 17904, -- Stormpike Insignia Rank 6 (Alliance)
  95. 22631, -- Atiesh, Greatstaff of the Guardian
  96. 87548, -- Lorewalker's Lodestone
  97. 54452, -- Ethereal Portal
  98. 93672, -- Dark Portal
  99. 103678, -- Time-Lost Artifact
  100. 110560, -- Garrison Hearthstone
  101. 118662, -- Bladespire Relic
  102. 118663, -- Relic of Karabor
  103. 118907, -- Pit Fighter's Punching Ring
  104. 128353, -- Admiral's Compass
  105. 128502, -- Hunter's Seeking Crystal
  106. 128503, -- Master Hunter's Seeking Crystal
  107. 136849, -- Nature's Beacon
  108. 140192 -- Dalaran Hearthstone
  109. }
  110.  
  111. -- IDs of items usable instead of hearthstone
  112. local scrolls = {
  113. 64488, -- The Innkeeper's Daughter
  114. 28585, -- Ruby Slippers
  115. 6948, -- Hearthstone
  116. 44315, -- Scroll of Recall III
  117. 44314, -- Scroll of Recall II
  118. 37118 -- Scroll of Recall
  119. }
  120.  
  121. -- Gold Challenge portals
  122. local challengeSpells = {
  123. { 131204, 'TRUE' }, -- Path of the Jade Serpent
  124. { 131205, 'TRUE' }, -- Path of the Stout Brew
  125. { 131206, 'TRUE' }, -- Path of the Shado-Pan
  126. { 131222, 'TRUE' }, -- Path of the Mogu King
  127. { 131225, 'TRUE' }, -- Path of the Setting Sun
  128. { 131231, 'TRUE' }, -- Path of the Scarlet Blade
  129. { 131229, 'TRUE' }, -- Path of the Scarlet Mitre
  130. { 131232, 'TRUE' }, -- Path of the Necromancer
  131. { 131228, 'TRUE' }, -- Path of the Black Ox
  132. { 159895, 'TRUE' }, -- Path of the Bloodmaul
  133. { 159896, 'TRUE' }, -- Path of the Iron Prow
  134. { 159897, 'TRUE' }, -- Path of the Vigilant
  135. { 159898, 'TRUE' }, -- Path of the Skies
  136. { 159899, 'TRUE' }, -- Path of the Crescent Moon
  137. { 159900, 'TRUE' }, -- Path of the Dark Rail
  138. { 159901, 'TRUE' }, -- Path of the Verdant
  139. { 159902, 'TRUE' } -- Path of the Burning Mountain
  140. }
  141.  
  142. local obj = LibStub:GetLibrary('LibDataBroker-1.1'):NewDataObject(addonName, {
  143. type = 'data source',
  144. text = L['P'],
  145. icon = 'Interface\\Icons\\INV_Misc_Rune_06',
  146. })
  147. local methods = {}
  148. local portals
  149. local frame = CreateFrame('frame')
  150.  
  151. frame:SetScript('OnEvent', function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
  152. frame:RegisterEvent('PLAYER_LOGIN')
  153. frame:RegisterEvent('SKILL_LINES_CHANGED')
  154.  
  155. local function pairsByKeys(t)
  156. local a = {}
  157. for n in pairs(t) do
  158. table.insert(a, n)
  159. end
  160. table.sort(a)
  161.  
  162. local i = 0
  163. local iter = function()
  164. i = i + 1
  165. if a[i] == nil then
  166. return nil
  167. else
  168. return a[i], t[a[i]]
  169. end
  170. end
  171. return iter
  172. end
  173.  
  174. local function tconcat(t1, t2)
  175. for i = 1, #t2 do
  176. t1[#t1 + 1] = t2[i]
  177. end
  178. return t1
  179. end
  180.  
  181. function findSpell(spellName)
  182. local i = 1
  183. while true do
  184. local s = GetSpellBookItemName(i, BOOKTYPE_SPELL)
  185. if not s then
  186. break
  187. end
  188.  
  189. if s == spellName then
  190. return i
  191. end
  192.  
  193. i = i + 1
  194. end
  195. end
  196.  
  197. -- returns true, if player has item with given ID in inventory or bags and it's not on cooldown
  198. local function hasItem(itemID)
  199. local item, found, id
  200. -- scan inventory
  201. for slotId = 1, 19 do
  202. item = GetInventoryItemLink('player', slotId)
  203. if item then
  204. found, _, id = item:find('^|c%x+|Hitem:(%d+):.+')
  205. if found and tonumber(id) == itemID then
  206. if GetInventoryItemCooldown('player', slotId) ~= 0 then
  207. return false
  208. else
  209. return true
  210. end
  211. end
  212. end
  213. end
  214. -- scan bags
  215. for bag = 0, 4 do
  216. for slot = 1, GetContainerNumSlots(bag) do
  217. item = GetContainerItemLink(bag, slot)
  218. if item then
  219. found, _, id = item:find('^|c%x+|Hitem:(%d+):.+')
  220. if found and tonumber(id) == itemID then
  221. if GetContainerItemCooldown(bag, slot) ~= 0 then
  222. return false
  223. else
  224. return true
  225. end
  226. end
  227. end
  228. end
  229. end
  230. -- check Toybox
  231. if PlayerHasToy(itemID) and C_ToyBox.IsToyUsable(itemID) then
  232. local startTime, duration, cooldown
  233. startTime, duration = GetItemCooldown(itemID)
  234. cooldown = duration - (GetTime() - startTime)
  235. if cooldown > 0 then
  236. return false
  237. else
  238. return true
  239. end
  240. end
  241.  
  242. return false
  243. end
  244.  
  245. local function getReagentCount(name)
  246. local count = 0
  247. for bag = 0, 4 do
  248. for slot = 1, GetContainerNumSlots(bag) do
  249. local item = GetContainerItemLink(bag, slot)
  250. if item then
  251. if item:find(name) then
  252. local _, itemCount = GetContainerItemInfo(bag, slot)
  253. count = count + itemCount
  254. end
  255. end
  256. end
  257. end
  258.  
  259. return count
  260. end
  261.  
  262. local function SetupSpells()
  263. local spells = {
  264. Alliance = {
  265. { 3561, 'TP_RUNE' }, -- TP:Stormwind
  266. { 3562, 'TP_RUNE' }, -- TP:Ironforge
  267. { 3565, 'TP_RUNE' }, -- TP:Darnassus
  268. { 32271, 'TP_RUNE' }, -- TP:Exodar
  269. { 49359, 'TP_RUNE' }, -- TP:Theramore
  270. { 33690, 'TP_RUNE' }, -- TP:Shattrath
  271. { 53140, 'TP_RUNE' }, -- TP:Dalaran
  272. { 88342, 'TP_RUNE' }, -- TP:Tol Barad
  273. { 132621, 'TP_RUNE' }, -- TP:Vale of Eternal Blossoms
  274. { 120145, 'TP_RUNE' }, -- TP:Ancient Dalaran
  275. { 176248, 'TP_RUNE' }, -- TP:StormShield
  276. { 193759, 'TP_RUNE' }, -- TP:Hall of the Guardian
  277. { 224869, 'TP_RUNE' }, -- TP:Dalaran - Broken Isles
  278. { 10059, 'P_RUNE' }, -- P:Stormwind
  279. { 11416, 'P_RUNE' }, -- P:Ironforge
  280. { 11419, 'P_RUNE' }, -- P:Darnassus
  281. { 32266, 'P_RUNE' }, -- P:Exodar
  282. { 49360, 'P_RUNE' }, -- P:Theramore
  283. { 33691, 'P_RUNE' }, -- P:Shattrath
  284. { 53142, 'P_RUNE' }, -- P:Dalaran
  285. { 88345, 'P_RUNE' }, -- P:Tol Barad
  286. { 120146, 'P_RUNE' }, -- P:Ancient Dalaran
  287. { 132620, 'P_RUNE' }, -- P:Vale of Eternal Blossoms
  288. { 176246, 'P_RUNE' }, -- P:StormShield
  289. { 224871, 'P_RUNE' } -- P:Dalaran - Broken Isles
  290. },
  291. Horde = {
  292. { 3563, 'TP_RUNE' }, -- TP:Undercity
  293. { 3566, 'TP_RUNE' }, -- TP:Thunder Bluff
  294. { 3567, 'TP_RUNE' }, -- TP:Orgrimmar
  295. { 32272, 'TP_RUNE' }, -- TP:Silvermoon
  296. { 49358, 'TP_RUNE' }, -- TP:Stonard
  297. { 35715, 'TP_RUNE' }, -- TP:Shattrath
  298. { 53140, 'TP_RUNE' }, -- TP:Dalaran
  299. { 88344, 'TP_RUNE' }, -- TP:Tol Barad
  300. { 132627, 'TP_RUNE' }, -- TP:Vale of Eternal Blossoms
  301. { 120145, 'TP_RUNE' }, -- TP:Ancient Dalaran
  302. { 176242, 'TP_RUNE' }, -- TP:Warspear
  303. { 193759, 'TP_RUNE' }, -- TP:Hall of the Guardian
  304. { 224869, 'TP_RUNE' }, -- TP:Dalaran - Broken Isles
  305. { 11418, 'P_RUNE' }, -- P:Undercity
  306. { 11420, 'P_RUNE' }, -- P:Thunder Bluff
  307. { 11417, 'P_RUNE' }, -- P:Orgrimmar
  308. { 32267, 'P_RUNE' }, -- P:Silvermoon
  309. { 49361, 'P_RUNE' }, -- P:Stonard
  310. { 35717, 'P_RUNE' }, -- P:Shattrath
  311. { 53142, 'P_RUNE' }, -- P:Dalaran
  312. { 88346, 'P_RUNE' }, -- P:Tol Barad
  313. { 120146, 'P_RUNE' }, -- P:Ancient Dalaran
  314. { 132626, 'P_RUNE' }, -- P:Vale of Eternal Blossoms
  315. { 176244, 'P_RUNE' }, -- P:Warspear
  316. { 224871, 'P_RUNE' } -- P:Dalaran - Broken Isles
  317. }
  318. }
  319.  
  320. local _, class = UnitClass('player')
  321. if class == 'MAGE' then
  322. portals = spells[select(1, UnitFactionGroup('player'))]
  323. elseif class == 'DEATHKNIGHT' then
  324. portals = {
  325. { 50977, 'TRUE' } -- Death Gate
  326. }
  327. elseif class == 'DRUID' then
  328. portals = {
  329. { 18960, 'TRUE' }, -- TP:Moonglade
  330. { 147420, 'TRUE' } -- TP:One with Nature
  331. }
  332. elseif class == 'SHAMAN' then
  333. portals = {
  334. { 556, 'TRUE' } -- Astral Recall
  335. }
  336. elseif class == 'MONK' then
  337. portals = {
  338. { 126892, 'TRUE' }, -- Zen Pilgrimage
  339. { 126895, 'TRUE' } -- Zen Pilgrimage: Return
  340. }
  341. else
  342. portals = {}
  343. end
  344.  
  345. wipe(spells)
  346. end
  347.  
  348. local function GenerateLinks(spells)
  349. local itemsGenerated = 0
  350.  
  351. for _, unTransSpell in ipairs(spells) do
  352. if IsPlayerSpell(unTransSpell[1]) then
  353. local spell, _, spellIcon = GetSpellInfo(unTransSpell[1])
  354. local spellid = findSpell(spell)
  355.  
  356. if spellid then
  357. methods[spell] = {
  358. spellid = spellid,
  359. text = spell,
  360. spellIcon = spellIcon,
  361. isPortal = unTransSpell[2] == 'P_RUNE',
  362. secure = {
  363. type = 'spell',
  364. spell = spell
  365. }
  366. }
  367. itemsGenerated = itemsGenerated + 1
  368. end
  369. end
  370. end
  371.  
  372. return itemsGenerated
  373. end
  374.  
  375. local function UpdateClassSpells()
  376. if not portals then
  377. SetupSpells()
  378. end
  379.  
  380. if portals then
  381. return GenerateLinks(portals)
  382. end
  383. end
  384.  
  385. local function UpdateChallengeSpells()
  386. return GenerateLinks(challengeSpells)
  387. end
  388.  
  389. local function UpdateIcon(icon)
  390. obj.icon = icon
  391. end
  392.  
  393. local function GetScrollCooldown()
  394. local cooldown, startTime, duration
  395.  
  396. for i = 1, #scrolls do
  397. if GetItemCount(scrolls[i]) > 0 or (PlayerHasToy(scrolls[i]) and C_ToyBox.IsToyUsable(scrolls[i])) then
  398. startTime, duration = GetItemCooldown(scrolls[i])
  399. cooldown = duration - (GetTime() - startTime)
  400. if cooldown <= 0 then
  401. return L['READY']
  402. else
  403. return SecondsToTime(cooldown)
  404. end
  405. end
  406. end
  407.  
  408. return L['N/A']
  409. end
  410.  
  411. local function GetItemCooldowns()
  412. local cooldown, cooldowns, hours, mins, secs
  413.  
  414. for i = 1, #items do
  415. if GetItemCount(items[i]) > 0 or (PlayerHasToy(items[i]) and C_ToyBox.IsToyUsable(items[i])) then
  416. startTime, duration = GetItemCooldown(items[i])
  417. cooldown = duration - (GetTime() - startTime)
  418. if cooldown <= 0 then
  419. cooldown = L['READY']
  420. else
  421. cooldown = SecondsToTime(cooldown)
  422. end
  423.  
  424. if cooldowns == nil then
  425. cooldowns = {}
  426. end
  427.  
  428. local name = GetItemInfo(items[i]) or select(2, C_ToyBox.GetToyInfo(items[i]))
  429. cooldowns[name] = cooldown
  430. end
  431. end
  432.  
  433. return cooldowns
  434. end
  435.  
  436. local function ShowHearthstone()
  437. local bindLoc = GetBindLocation()
  438. local secure, text, icon, name
  439.  
  440. for i = 1, #scrolls do
  441. if hasItem(scrolls[i]) then
  442. name, _, _, _, _, _, _, _, _, icon = GetItemInfo(scrolls[i])
  443. text = L['INN'] .. ' ' .. bindLoc
  444. secure = {
  445. type = 'item',
  446. item = name
  447. }
  448. break
  449. end
  450. end
  451.  
  452. if secure ~= nil then
  453. dewdrop:AddLine('text', text,
  454. 'secure', secure,
  455. 'icon', tostring(icon),
  456. 'func', function() UpdateIcon(icon) end,
  457. 'closeWhenClicked', true)
  458. dewdrop:AddLine()
  459. end
  460. end
  461.  
  462. local function ShowOtherItems()
  463. local i = 0
  464.  
  465. for i = 1, #items do
  466. if hasItem(items[i]) then
  467. local name, _, quality, _, _, _, _, _, _, icon = GetItemInfo(items[i])
  468. local secure = {
  469. type = 'item',
  470. item = name
  471. }
  472.  
  473. dewdrop:AddLine(
  474. 'text', name,
  475. 'textR', ITEM_QUALITY_COLORS[quality].r,
  476. 'textG', ITEM_QUALITY_COLORS[quality].g,
  477. 'textB', ITEM_QUALITY_COLORS[quality].b,
  478. 'secure', secure,
  479. 'icon', tostring(icon),
  480. 'func', function() UpdateIcon(icon) end,
  481. 'closeWhenClicked', true)
  482. i = i + 1
  483. end
  484. end
  485. if i > 0 then
  486. dewdrop:AddLine()
  487. end
  488. end
  489.  
  490. local function ToggleMinimap()
  491. local hide = not PortalsDB.minimap.hide
  492. PortalsDB.minimap.hide = hide
  493. if hide then
  494. icon:Hide('Broker_Portals')
  495. else
  496. icon:Show('Broker_Portals')
  497. end
  498. end
  499.  
  500. local function UpdateMenu(level, value)
  501. if level == 1 then
  502. dewdrop:AddLine('text', 'Broker_Portals', 'isTitle', true)
  503.  
  504. methods = {}
  505. local spells = UpdateClassSpells()
  506. if spells > 0 then
  507. dewdrop:AddLine()
  508. end
  509. local challengeSpells = UpdateChallengeSpells()
  510. if challengeSpells > 0 then
  511. dewdrop:AddLine()
  512. end
  513.  
  514. local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  515. local announce = PortalsDB.announce
  516. for k, v in pairsByKeys(methods) do
  517. if v.secure and GetSpellCooldown(v.text) == 0 then
  518. dewdrop:AddLine(
  519. 'text', v.text,
  520. 'secure', v.secure,
  521. 'icon', tostring(v.spellIcon),
  522. 'func', function()
  523. UpdateIcon(v.spellIcon)
  524. if announce and v.isPortal and chatType then
  525. SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  526. end
  527. end,
  528. 'closeWhenClicked', true)
  529. end
  530. end
  531.  
  532. dewdrop:AddLine()
  533.  
  534. ShowHearthstone()
  535.  
  536. if PortalsDB.showItems then
  537. ShowOtherItems()
  538. end
  539.  
  540. dewdrop:AddLine('text', L['OPTIONS'],
  541. 'hasArrow', true,
  542. 'value', 'options')
  543.  
  544. dewdrop:AddLine('text', CLOSE,
  545. 'tooltipTitle', CLOSE,
  546. 'tooltipText', CLOSE_DESC,
  547. 'closeWhenClicked', true)
  548. elseif level == 2 and value == 'options' then
  549. dewdrop:AddLine('text', L['SHOW_ITEMS'],
  550. 'checked', PortalsDB.showItems,
  551. 'func', function() PortalsDB.showItems = not PortalsDB.showItems end,
  552. 'closeWhenClicked', true)
  553. dewdrop:AddLine('text', L['SHOW_ITEM_COOLDOWNS'],
  554. 'checked', PortalsDB.showItemCooldowns,
  555. 'func', function() PortalsDB.showItemCooldowns = not PortalsDB.showItemCooldowns end,
  556. 'closeWhenClicked', true)
  557. dewdrop:AddLine('text', L['ATT_MINIMAP'],
  558. 'checked', not PortalsDB.minimap.hide,
  559. 'func', function() ToggleMinimap() end,
  560. 'closeWhenClicked', true)
  561. dewdrop:AddLine('text', L['ANNOUNCE'],
  562. 'checked', PortalsDB.announce,
  563. 'func', function() PortalsDB.announce = not PortalsDB.announce end,
  564. 'closeWhenClicked', true)
  565. end
  566. end
  567.  
  568. function frame:PLAYER_LOGIN()
  569. -- PortalsDB.minimap is there for smooth upgrade of SVs from old version
  570. if (not PortalsDB) or (PortalsDB.version == nil) then
  571. PortalsDB = {}
  572. PortalsDB.minimap = {}
  573. PortalsDB.minimap.hide = false
  574. PortalsDB.showItems = true
  575. PortalsDB.showItemCooldowns = true
  576. PortalsDB.announce = false
  577. PortalsDB.version = 4
  578. end
  579.  
  580. -- upgrade from versions
  581. if PortalsDB.version == 3 then
  582. PortalsDB.announce = false
  583. PortalsDB.version = 4
  584. elseif PortalsDB.version == 2 then
  585. PortalsDB.showItemCooldowns = true
  586. PortalsDB.announce = false
  587. PortalsDB.version = 4
  588. elseif PortalsDB.version < 2 then
  589. PortalsDB.showItems = true
  590. PortalsDB.showItemCooldowns = true
  591. PortalsDB.announce = false
  592. PortalsDB.version = 4
  593. end
  594.  
  595. if icon then
  596. icon:Register('Broker_Portals', obj, PortalsDB.minimap)
  597. end
  598.  
  599. self:UnregisterEvent('PLAYER_LOGIN')
  600. end
  601.  
  602. function frame:SKILL_LINES_CHANGED()
  603. UpdateClassSpells()
  604. UpdateChallengeSpells()
  605. end
  606.  
  607. -- All credit for this func goes to Tekkub and his picoGuild!
  608. local function GetTipAnchor(frame)
  609. local x, y = frame:GetCenter()
  610. if not x or not y then return 'TOPLEFT', 'BOTTOMLEFT' end
  611. local hhalf = (x > UIParent:GetWidth() * 2 / 3) and 'RIGHT' or (x < UIParent:GetWidth() / 3) and 'LEFT' or ''
  612. local vhalf = (y > UIParent:GetHeight() / 2) and 'TOP' or 'BOTTOM'
  613. return vhalf .. hhalf, frame, (vhalf == 'TOP' and 'BOTTOM' or 'TOP') .. hhalf
  614. end
  615.  
  616. function obj.OnClick(self, button)
  617. GameTooltip:Hide()
  618. if button == 'RightButton' then
  619. dewdrop:Open(self, 'children', function(level, value) UpdateMenu(level, value) end)
  620. end
  621. end
  622.  
  623. function obj.OnLeave()
  624. GameTooltip:Hide()
  625. end
  626.  
  627. function obj.OnEnter(self)
  628. GameTooltip:SetOwner(self, 'ANCHOR_NONE')
  629. GameTooltip:SetPoint(GetTipAnchor(self))
  630. GameTooltip:ClearLines()
  631.  
  632. GameTooltip:AddLine('Broker Portals')
  633. GameTooltip:AddDoubleLine(L['RCLICK'], L['SEE_SPELLS'], 0.9, 0.6, 0.2, 0.2, 1, 0.2)
  634. GameTooltip:AddLine(' ')
  635.  
  636. local scrollCooldown = GetScrollCooldown()
  637. if scrollCooldown == L['READY'] then
  638. GameTooltip:AddDoubleLine(L['HEARTHSTONE'] .. ': ' .. GetBindLocation(), scrollCooldown, 0.9, 0.6, 0.2, 0.2, 1, 0.2)
  639. else
  640. GameTooltip:AddDoubleLine(L['HEARTHSTONE'] .. ': ' .. GetBindLocation(), scrollCooldown, 0.9, 0.6, 0.2, 1, 1, 0.2)
  641. end
  642.  
  643. if PortalsDB.showItemCooldowns then
  644. local cooldowns = GetItemCooldowns()
  645. if cooldowns ~= nil then
  646. GameTooltip:AddLine(' ')
  647. for name, cooldown in pairs(cooldowns) do
  648. if cooldown == L['READY'] then
  649. GameTooltip:AddDoubleLine(name, cooldown, 0.9, 0.6, 0.2, 0.2, 1, 0.2)
  650. else
  651. GameTooltip:AddDoubleLine(name, cooldown, 0.9, 0.6, 0.2, 1, 1, 0.2)
  652. end
  653. end
  654. end
  655. end
  656.  
  657. GameTooltip:Show()
  658. end
  659.  
  660. -- slash command definition
  661. SlashCmdList['BROKER_PORTALS'] = function() ToggleMinimap() end
  662. SLASH_BROKER_PORTALS1 = '/portals'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement