Advertisement
Guest User

portals.lua

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