Advertisement
Guest User

Portal.lua

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