Advertisement
suicidalkatt

CoolLine - Core.lua

Apr 29th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.42 KB | None | 0 0
  1. local CoolLine = CreateFrame("Frame", "CoolLine", UIParent)
  2. local self = CoolLine
  3. self:SetScript("OnEvent", function(this, event, ...)
  4.     this[event](this, ...)
  5. end)
  6. local smed = LibStub("LibSharedMedia-3.0")
  7.  
  8. local _G = getfenv(0)
  9. local pairs, ipairs = pairs, ipairs
  10. local tinsert, tremove = tinsert, tremove
  11. local GetTime = GetTime
  12. local random = math.random
  13. local strmatch = strmatch
  14. local UnitExists, HasPetUI = UnitExists, HasPetUI
  15. local GetSpellInfo = GetSpellInfo
  16.  
  17. local db, block
  18. local backdrop = { edgeSize=16, } -- Left Unchanged
  19. local section, iconsize = 0, 0
  20. local tick0, tick1, tick3, tick10, tick30, tick120, tick300
  21. local BOOKTYPE_SPELL, BOOKTYPE_PET = BOOKTYPE_SPELL, BOOKTYPE_PET
  22. local spells = { [BOOKTYPE_SPELL] = { }, [BOOKTYPE_PET] = { }, }
  23. local frames, cooldowns, specialspells, placeholder = { }, { }, { }, { }
  24.  
  25. local SetValue, updatelook, createfs, ShowOptions, RuneCheck
  26. local function SetValueH(this, v, just)
  27.     this:SetPoint(just or "CENTER", self, "LEFT", v, 0)
  28. end
  29. local function SetValueHR(this, v, just)
  30.     this:SetPoint(just or "CENTER", self, "LEFT", db.w - v, 0)
  31. end
  32. local function SetValueV(this, v, just)
  33.     this:SetPoint(just or "CENTER", self, "BOTTOM", 0, v)
  34. end
  35. local function SetValueVR(this, v, just)
  36.     this:SetPoint(just or "CENTER", self, "BOTTOM", 0, db.h - v)
  37. end
  38.  
  39. self:RegisterEvent("ADDON_LOADED")
  40. function CoolLine:ADDON_LOADED(a1)
  41.     if a1 ~= "CoolLine" then return end
  42.     self:UnregisterEvent("ADDON_LOADED")
  43.     self.ADDON_LOADED = nil
  44.    
  45.     CoolLineDB = CoolLineDB or { }
  46.     if CoolLineDB.perchar then
  47.         CoolLineCharDB = CoolLineCharDB or CoolLineDB
  48.         db = CoolLineCharDB
  49.     else
  50.         CoolLineCharDB = nil
  51.         db = CoolLineDB
  52.     end
  53.     if db.dbinit ~= 1 then
  54.         db.dbinit = 1
  55.         for k, v in pairs({
  56.             w = 360, h = 18, x = 0, y = -240,
  57.             statusbar = "Blizzard",
  58.             bgcolor = { r = 0, g = 0, b = 0, a = 0.5, },
  59.             border = "Blizzard Dialog",
  60.             bordersize = 16, -- Added defaults
  61.             borderinset = 4, -- Added defaults
  62.             bordercolor = { r = 1, g = 1, b = 1, a = 1, },
  63.             font = "Friz Quadrata TT",
  64.             fontsize = 10,
  65.             iconplus = 4,
  66.             fontcolor = { r = 1, g = 1, b = 1, a = 0.8, },
  67.             spellcolor = { r = 0.8, g = 0.4, b = 0, a = 1, },
  68.             nospellcolor = { r = 0, g = 0, b = 0, a = 1, },
  69.             inactivealpha = 0.5,
  70.             activealpha = 1.0,
  71.             block = {  -- [spell or item name] = true,
  72.                 [GetItemInfo(6948) or "Hearthstone"] = true,  -- Hearthstone
  73.             },
  74.         }) do
  75.             db[k] = (db[k] ~= nil and db[k]) or v
  76.         end
  77.     end
  78.     block = db.block
  79.     local _, class = UnitClass("player")
  80.     if class == "DEATHKNIGHT" then
  81.         local runecd = {  -- fix by NeoSyrex
  82.             [GetSpellInfo(50977) or "Death Gate"] = 11,
  83.             [GetSpellInfo(43265) or "Death and Decay"] = 11,
  84.             [GetSpellInfo(48263) or "Frost Presence"] = 1,
  85.             [GetSpellInfo(48266) or "Blood Presence"] = 1,
  86.             [GetSpellInfo(48265) or "Unholy Presence"] = 1,
  87.             [GetSpellInfo(42650) or "Army of the Dead"] = 11,
  88.             [GetSpellInfo(49222) or "Bone Shield"] = 11,
  89.             [GetSpellInfo(47476) or "Strangulate"] = 11,
  90.             [GetSpellInfo(51052) or "Anti-Magic Zone"] = 11,
  91.             [GetSpellInfo(63560) or "Ghoul Frenzy"] = 10,
  92.             [GetSpellInfo(49184) or "Howling Blast"] = 8,
  93.             [GetSpellInfo(51271) or "Unbreakable Armor"] = 11,
  94.             [GetSpellInfo(55233) or "Vampiric Blood"] = 11,
  95.             [GetSpellInfo(49005) or "Mark of Blood"] = 11,
  96.             [GetSpellInfo(48982) or "Rune Tap"] = 11,
  97.         }
  98.         RuneCheck = function(name, duration)
  99.             local rc = runecd[name]
  100.             if not rc or (rc <= duration and (rc > 10 or rc >= duration)) then
  101.                 return true
  102.             end
  103.         end
  104.     elseif class == "MAGE" then
  105.         placeholder = { [125430] = 112948, }
  106.     elseif class == "PRIEST" then
  107.         specialspells = {
  108.             [GetSpellInfo(87151) or "blah"] = 87151,  -- Archangel
  109.             [GetSpellInfo(14751) or "blah"] = 14751,  -- Chakra
  110.             [GetSpellInfo(81209) or "blah"] = 81209,  -- Chakra
  111.             [GetSpellInfo(88684) or "blah"] = 88684,  -- Holy Word: Serenity
  112.             [GetSpellInfo(88682) or "blah"] = 88682,  -- Holy Word: Aspire
  113.             [GetSpellInfo(88685) or "blah"] = 88685,  -- Holy Word: Sanctuary
  114.             [GetSpellInfo(88625) or "blah"] = 88625,  -- Holy Word: Chastise
  115.         }
  116.     --[[elseif class == "DRUID" then
  117.         specialspells = {
  118.             [GetSpellInfo(33917) or "blah"] = 33878,  -- Mangle (Bear)
  119.             [GetSpellInfo(106830) or "blah"] = 77758,  -- Thrash (Bear)
  120.         }]]--
  121.     end
  122.    
  123.     SlashCmdList.COOLLINE = ShowOptions
  124.     SLASH_COOLLINE1 = "/coolline"
  125.     local panel = CreateFrame("Frame")
  126.     panel.name = "CoolLine"
  127.     panel:SetScript("OnShow", function(this)
  128.         local t1 = this:CreateFontString(nil, "ARTWORK")
  129.         t1:SetJustifyH("LEFT")
  130.         t1:SetJustifyV("TOP")
  131.         t1:SetFontObject(GameFontNormalLarge)
  132.         t1:SetPoint("TOPLEFT", 16, -16)
  133.         t1:SetText(this.name)
  134.        
  135.         local t2 = this:CreateFontString(nil, "ARTWORK")
  136.         t2:SetJustifyH("LEFT")
  137.         t2:SetJustifyV("TOP")
  138.         t2:SetFontObject(GameFontHighlightSmall)
  139.         t2:SetHeight(43)
  140.         t2:SetPoint("TOPLEFT", t1, "BOTTOMLEFT", 0, -8)
  141.         t2:SetPoint("RIGHT", this, "RIGHT", -32, 0)
  142.         t2:SetNonSpaceWrap(true)
  143.         t2:SetFormattedText("Notes: %s\nAuthor: %s\nVersion: %s\n"..
  144.                             "Hint: |cffffff00/coolline|r to open menu; |cffffff00/coolline SpellOrItemNameOrLink|r to add/remove filter",
  145.                              GetAddOnMetadata("CoolLine", "Notes") or "N/A",
  146.                              GetAddOnMetadata("CoolLine", "Author") or "N/A",
  147.                              GetAddOnMetadata("CoolLine", "Version") or "N/A")
  148.    
  149.         local b = CreateFrame("Button", nil, this, "UIPanelButtonTemplate")
  150.         b:SetWidth(120)
  151.         b:SetHeight(20)
  152.         b:SetText("Options Menu")
  153.         b:SetScript("OnClick", ShowOptions)
  154.         b:SetPoint("TOPLEFT", t2, "BOTTOMLEFT", -2, -8)
  155.         this:SetScript("OnShow", nil)
  156.     end)
  157.     InterfaceOptions_AddCategory(panel)
  158.  
  159.     createfs = function(f, text, offset, just)
  160.         local fs = f or self.overlay:CreateFontString(nil, "OVERLAY")
  161.         fs:SetFont(smed:Fetch("font", db.font), db.fontsize)
  162.         fs:SetTextColor(db.fontcolor.r, db.fontcolor.g, db.fontcolor.b, db.fontcolor.a)
  163.         fs:SetText(text)
  164.         fs:SetWidth(db.fontsize * 3)
  165.         fs:SetHeight(db.fontsize + 2)
  166.         fs:SetShadowColor(db.bgcolor.r, db.bgcolor.g, db.bgcolor.b, db.bgcolor.a)
  167.         fs:SetShadowOffset(1, -1)
  168.         if just then
  169.             fs:ClearAllPoints()
  170.             if db.vertical then
  171.                 fs:SetJustifyH("CENTER")
  172.                 just = db.reverse and ((just == "LEFT" and "TOP") or "BOTTOM") or ((just == "LEFT" and "BOTTOM") or "TOP")
  173.             elseif db.reverse then
  174.                 just = (just == "LEFT" and "RIGHT") or "LEFT"
  175.                 offset = offset + ((just == "LEFT" and 1) or -1)
  176.                 fs:SetJustifyH(just)
  177.             else
  178.                 offset = offset + ((just == "LEFT" and 1) or -1)
  179.                 fs:SetJustifyH(just)
  180.             end
  181.         else
  182.             fs:SetJustifyH("CENTER")
  183.         end
  184.         SetValue(fs, offset, just)
  185.         return fs
  186.     end
  187.     updatelook = function()
  188.         self:SetWidth(db.w or 130)
  189.         self:SetHeight(db.h or 18)
  190.         self:SetPoint("CENTER", UIParent, "CENTER", db.x or 0, db.y or -240)
  191.        
  192.         self.bg = self.bg or self:CreateTexture(nil, "ARTWORK")
  193.         self.bg:SetTexture(smed:Fetch("statusbar", db.statusbar))
  194.         self.bg:SetVertexColor(db.bgcolor.r, db.bgcolor.g, db.bgcolor.b, db.bgcolor.a)
  195.         self.bg:SetAllPoints(self)
  196.         if db.vertical then
  197.             self.bg:SetTexCoord(1,0, 0,0, 1,1, 0,1)
  198.         else
  199.             self.bg:SetTexCoord(0,1, 0,1)
  200.         end
  201.        
  202.         self.border = self.border or CreateFrame("Frame", nil, self)
  203.         self.border:SetPoint("TOPLEFT", -db.borderinset, db.borderinset) -- Implemented 'insets'
  204.         self.border:SetPoint("BOTTOMRIGHT", db.borderinset, -db.borderinset) -- Implemented 'insets'
  205.         backdrop = {
  206.             edgeFile = smed:Fetch("border", db.border),
  207.             edgeSize = db.bordersize,
  208.         } -- Updated backdrop table
  209.         self.border:SetBackdrop(backdrop)
  210.         self.border:SetBackdropBorderColor(db.bordercolor.r, db.bordercolor.g, db.bordercolor.b, db.bordercolor.a)
  211.        
  212.         self.overlay = self.overlay or CreateFrame("Frame", nil, self.border)
  213.         self.overlay:SetFrameLevel(24)
  214.  
  215.         section = (db.vertical and db.h or db.w) / 6
  216.         iconsize = ((db.vertical and db.w) or db.h) + (db.iconplus or 4)
  217.         SetValue = (db.vertical and (db.reverse and SetValueVR or SetValueV)) or (db.reverse and SetValueHR or SetValueH)
  218.        
  219.         tick0 = createfs(tick0, "0", 0, "LEFT")
  220.         tick1 = createfs(tick1, "1", section)
  221.         tick3 = createfs(tick3, "3", section * 2)
  222.         tick10 = createfs(tick10, "10", section * 3)
  223.         tick30 = createfs(tick30, "30", section * 4)
  224.         tick120 = createfs(tick120, "2m", section * 5)
  225.         tick300 = createfs(tick300, "6m", section * 6, "RIGHT")
  226.  
  227.         if not self.cb and (not smed:IsValid("font", db.font) or not smed:IsValid("border", db.border) or not smed:IsValid("statusbar", db.statusbar)) then
  228.             smed.RegisterCallback(self, "LibSharedMedia_Registered", updatelook)
  229.             self.cb = true
  230.         end
  231.         if db.hidepet then
  232.             self:UnregisterEvent("UNIT_PET")
  233.             self:UnregisterEvent("PET_BAR_UPDATE_COOLDOWN")
  234.         else
  235.             self:RegisterUnitEvent("UNIT_PET", "player")
  236.             self:UNIT_PET()
  237.         end
  238.         if db.hidebag and db.hideinv then
  239.             self:UnregisterEvent("BAG_UPDATE_COOLDOWN")
  240.         else
  241.             self:RegisterEvent("BAG_UPDATE_COOLDOWN")
  242.             self:BAG_UPDATE_COOLDOWN()
  243.         end
  244.         if db.hidefail then
  245.             self:UnregisterEvent("UNIT_SPELLCAST_FAILED")
  246.         else
  247.             self:RegisterUnitEvent("UNIT_SPELLCAST_FAILED", "player")
  248.         end
  249.         CoolLine:SetAlpha((CoolLine.unlock or #cooldowns > 0) and db.activealpha or db.inactivealpha)
  250.         for _, frame in ipairs(cooldowns) do
  251.             frame:SetWidth(iconsize)
  252.             frame:SetHeight(iconsize)
  253.         end
  254.     end
  255.     CoolLine.updatelook = updatelook
  256.    
  257.     if IsLoggedIn() then
  258.         CoolLine:PLAYER_LOGIN()
  259.     else
  260.         self:RegisterEvent("PLAYER_LOGIN")
  261.     end
  262. end
  263.  
  264. --------------------------------
  265. function CoolLine:PLAYER_LOGIN()
  266. --------------------------------
  267.     self.PLAYER_LOGIN = nil
  268.     self:RegisterEvent("SPELL_UPDATE_COOLDOWN")
  269.     self:RegisterEvent("SPELLS_CHANGED")
  270.     self:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", "player")
  271.     self:SPELL_UPDATE_COOLDOWN()
  272.     if UnitHasVehicleUI("player") then
  273.         self:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN")
  274.         self:RegisterUnitEvent("UNIT_EXITED_VEHICLE", "player")
  275.     end
  276.     updatelook()
  277.     self:SetAlpha((#cooldowns == 0 and db.inactivealpha) or db.activealpha)
  278.     self:RegisterEvent("PLAYER_LEAVING_WORLD")
  279. end
  280.  
  281. -----------------------------------------
  282. function CoolLine:PLAYER_ENTERING_WORLD()
  283. -----------------------------------------
  284.     self:RegisterEvent("SPELLS_CHANGED")
  285.     self:RegisterEvent("SPELL_UPDATE_COOLDOWN")
  286.     self:SPELLS_CHANGED()
  287.     self:SPELL_UPDATE_COOLDOWN()
  288. end
  289.  
  290. ----------------------------------------
  291. function CoolLine:PLAYER_LEAVING_WORLD()
  292. ----------------------------------------
  293.     self:RegisterEvent("PLAYER_ENTERING_WORLD")
  294.     self:UnregisterEvent("SPELLS_CHANGED")
  295.     self:UnregisterEvent("SPELL_UPDATE_COOLDOWN")
  296. end
  297.  
  298. local iconback = { bgFile="Interface\\AddOns\\CoolLine\\backdrop.tga" }
  299. local elapsed, throt, ptime, isactive = 0, 1.5, 0, false
  300. local function ClearCooldown(f, name)
  301.     name = name or (f and f.name)
  302.     for index, frame in ipairs(cooldowns) do
  303.         if frame.name == name then
  304.             frame:Hide()
  305.             frame.name = nil
  306.             frame.endtime = nil
  307.             tinsert(frames, tremove(cooldowns, index))
  308.             break
  309.         end
  310.     end
  311. end
  312. local function SetupIcon(frame, position, tthrot, active, fl)
  313.     throt = (throt < tthrot and throt) or tthrot
  314.     isactive = active or isactive
  315.     if fl then
  316.         frame:SetFrameLevel(random(1,5) * 2 + 2)
  317.     end
  318.     SetValue(frame, position)
  319. end
  320. local function OnUpdate(this, a1, ctime, dofl)
  321.     elapsed = elapsed + a1
  322.     if elapsed < throt then return end
  323.     elapsed = 0
  324.    
  325.     if #cooldowns == 0 then
  326.         if not CoolLine.unlock then
  327.             self:SetScript("OnUpdate", nil)
  328.             self:SetAlpha(db.inactivealpha)
  329.         end
  330.         return
  331.     end
  332.    
  333.     ctime = ctime or GetTime()
  334.     if ctime > ptime then
  335.         dofl, ptime = true, ctime + 0.4
  336.     end
  337.     isactive, throt = false, 1.5
  338.     for index, frame in pairs(cooldowns) do
  339.         local remain = frame.endtime - ctime
  340.         if remain < 3 then
  341.             if remain > 1 then
  342.                 SetupIcon(frame, section * (remain + 1) * 0.5, 0.02, true, dofl)  -- 1 + (remain - 1) / 2
  343.             elseif remain > 0.3 then
  344.                 SetupIcon(frame, section * remain, 0, true, dofl)
  345.             elseif remain > 0 then
  346.                 local size = iconsize * (0.5 - remain) * 5  -- iconsize + iconsize * (0.3 - remain) / 0.2
  347.                 frame:SetWidth(size)
  348.                 frame:SetHeight(size)
  349.                 SetupIcon(frame, section * remain, 0, true, dofl)
  350.             elseif remain > -1 then
  351.                 SetupIcon(frame, 0, 0, true, dofl)
  352.                 frame:SetAlpha(1 + remain)  -- fades
  353.             else
  354.                 throt = (throt < 0.2 and throt) or 0.2
  355.                 isactive = true
  356.                 ClearCooldown(frame)
  357.             end
  358.         elseif remain < 10 then
  359.             SetupIcon(frame, section * (remain + 11) * 0.14286, remain > 4 and 0.05 or 0.02, true, dofl)  -- 2 + (remain - 3) / 7
  360.         elseif remain < 30 then
  361.             SetupIcon(frame, section * (remain + 50) * 0.05, 0.06, true, dofl)  -- 3 + (remain - 10) / 20
  362.         elseif remain < 120 then
  363.             SetupIcon(frame, section * (remain + 330) * 0.011111, 0.18, true, dofl)  -- 4 + (remain - 30) / 90
  364.         elseif remain < 360 then
  365.             SetupIcon(frame, section * (remain + 1080) * 0.0041667, 1.2, true, dofl)  -- 5 + (remain - 120) / 240
  366.             frame:SetAlpha(1)
  367.         else
  368.             SetupIcon(frame, 6 * section, 2, false, dofl)
  369.         end
  370.     end
  371.     if not isactive and not CoolLine.unlock then
  372.         self:SetAlpha(db.inactivealpha)
  373.     end
  374. end
  375. local function NewCooldown(name, icon, endtime, isplayer)
  376.     local f
  377.     for index, frame in pairs(cooldowns) do
  378.         if frame.name == name and frame.isplayer == isplayer then
  379.             f = frame
  380.             break
  381.         elseif frame.endtime == endtime then
  382.             return
  383.         end
  384.     end
  385.     if not f then
  386.         f = f or tremove(frames)
  387.         if not f then
  388.             f = CreateFrame("Frame", nil, CoolLine.border)
  389.             f:SetBackdrop(iconback)
  390.             f.icon = f:CreateTexture(nil, "ARTWORK")
  391.             f.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
  392.             f.icon:SetPoint("TOPLEFT", 1, -1)
  393.             f.icon:SetPoint("BOTTOMRIGHT", -1, 1)
  394.         end
  395.         tinsert(cooldowns, f)
  396.     end
  397.     local ctime = GetTime()
  398.     f:SetWidth(iconsize)
  399.     f:SetHeight(iconsize)
  400.     f:SetAlpha((endtime - ctime > 360) and 0.6 or 1)
  401.     f.name, f.endtime, f.isplayer = name, endtime, isplayer
  402.     f.icon:SetTexture(icon)
  403.     local c = db[isplayer and "spellcolor" or "nospellcolor"]
  404.     f:SetBackdropColor(c.r, c.g, c.b, c.a)
  405.     f:Show()
  406.     self:SetScript("OnUpdate", OnUpdate)
  407.     self:SetAlpha(db.activealpha)
  408.     OnUpdate(self, 2, ctime)
  409. end
  410. CoolLine.NewCooldown, CoolLine.ClearCooldown = NewCooldown, ClearCooldown
  411.  
  412. do  -- cache spells that have a cooldown
  413.     local GetSpellBookItemName, GetSpellBookItemInfo, GetSpellBaseCooldown = GetSpellBookItemName, GetSpellBookItemInfo, GetSpellBaseCooldown
  414.     local function CacheBook(btype)
  415.         local lastId, spellName
  416.         local sb = spells[btype]
  417.         local _, _, offset, numSpells = GetSpellTabInfo(2)
  418.         for i = 1, offset + numSpells, 1 do
  419.             spellName = GetSpellBookItemName(i, btype)
  420.             if not spellName then break end
  421.             local slotType, spellId = GetSpellBookItemInfo(i, btype)
  422.             if spellId and slotType == "FLYOUT" then
  423.                 local _, _, numSlots, isKnown = GetFlyoutInfo(spellId)
  424.                 for fi = 1, ((isKnown and numSlots) or 0), 1 do
  425.                     local flySpellId, _, _, flySpellName, _ = GetFlyoutSlotInfo(spellId, fi)
  426.                     last = flySpellName
  427.                     if flySpellId then
  428.                         local flycd = GetSpellBaseCooldown(flySpellId)
  429.                         if flycd and flycd > 2499 then
  430.                             sb[flySpellId] = specialspells[flySpellId] or flySpellName
  431.                         end
  432.                     end
  433.                 end
  434.             elseif spellId and slotType ~= "FUTURESPELL" and spellId ~= last then
  435.                 last = spellId
  436.                 local spellcd = GetSpellBaseCooldown(placeholder[spellId] or spellId)
  437.                 if spellcd and spellcd > 2499 then
  438.                     sb[spellId] = spellName
  439.                     if specialspells[spellName] then
  440.                         sb[ specialspells[spellName] ] = spellName
  441.                     end
  442.                 end
  443.             end
  444.         end
  445.     end
  446.     ----------------------------------
  447.     function CoolLine:SPELLS_CHANGED()
  448.     ----------------------------------
  449.         CacheBook(BOOKTYPE_SPELL)
  450.         if not db.hidepet then
  451.             CacheBook(BOOKTYPE_PET)
  452.         end
  453.     end
  454. end
  455.  
  456. do  -- scans spellbook to update cooldowns, throttled since the event fires a lot
  457.     local selap = 0
  458.     local spellthrot = CreateFrame("Frame", nil, CoolLine)
  459.     local GetSpellCooldown, GetSpellTexture = GetSpellCooldown, GetSpellTexture
  460.     local function CheckSpellBook(btype)
  461.         for id, name in pairs(spells[btype]) do
  462.             local start, duration, enable = GetSpellCooldown(name)
  463.             if enable == 1 and start > 0 and not block[name] and (not RuneCheck or RuneCheck(name, duration)) then
  464.                 if duration > 2.5 then
  465.                     local _, _, texture = GetSpellInfo(id)
  466.                     NewCooldown(name, texture, start + duration, btype == BOOKTYPE_SPELL)
  467.                 else
  468.                     for index, frame in ipairs(cooldowns) do
  469.                         if frame.name == name then
  470.                             if frame.endtime > start + duration + 0.1 then
  471.                                 frame.endtime = start + duration
  472.                             end
  473.                             break
  474.                         end
  475.                     end
  476.                 end
  477.             else
  478.                 ClearCooldown(nil, name)
  479.             end
  480.         end
  481.     end
  482.     spellthrot:SetScript("OnUpdate", function(this, a1)
  483.         selap = selap + a1
  484.         if selap < 0.3 then return end
  485.         selap = 0
  486.         this:Hide()
  487.         CheckSpellBook(BOOKTYPE_SPELL)
  488.         if not db.hidepet and HasPetUI() then
  489.             CheckSpellBook(BOOKTYPE_PET)
  490.         end
  491.     end)
  492.     spellthrot:Hide()
  493.     -----------------------------------------
  494.     function CoolLine:SPELL_UPDATE_COOLDOWN()
  495.     -----------------------------------------
  496.         spellthrot:Show()
  497.     end
  498. end
  499.  
  500. do  -- scans equipments and bags for item cooldowns
  501.     local GetItemInfo = GetItemInfo
  502.     local GetInventoryItemCooldown, GetInventoryItemTexture = GetInventoryItemCooldown, GetInventoryItemTexture
  503.     local GetContainerItemCooldown, GetContainerItemInfo = GetContainerItemCooldown, GetContainerItemInfo
  504.     local GetContainerNumSlots = GetContainerNumSlots
  505.     ---------------------------------------
  506.     function CoolLine:BAG_UPDATE_COOLDOWN()
  507.     ---------------------------------------
  508.         for i = 1, (db.hideinv and 0) or 18, 1 do
  509.             local start, duration, enable = GetInventoryItemCooldown("player", i)
  510.             if enable == 1 then
  511.                 local name = GetItemInfo(GetInventoryItemLink("player", i))
  512.                 if start > 0 and not block[name] then
  513.                     if duration > 3 and duration < 3601 then
  514.                         NewCooldown(name, GetInventoryItemTexture("player", i), start + duration)
  515.                     end
  516.                 else
  517.                     ClearCooldown(nil, name)
  518.                 end
  519.             end
  520.         end
  521.         for i = 0, (db.hidebag and -1) or 4, 1 do
  522.             for j = 1, GetContainerNumSlots(i), 1 do
  523.                 local start, duration, enable = GetContainerItemCooldown(i, j)
  524.                 if enable == 1 then
  525.                     local name = GetItemInfo(GetContainerItemLink(i, j))
  526.                     if start > 0 and not block[name] then
  527.                         if duration > 3 and duration < 3601 then
  528.                             NewCooldown(name, GetContainerItemInfo(i, j), start + duration)
  529.                         end
  530.                     else
  531.                         ClearCooldown(nil, name)
  532.                     end
  533.                 end
  534.             end
  535.         end
  536.     end
  537. end
  538.  
  539. -------------------------------------------
  540. function CoolLine:PET_BAR_UPDATE_COOLDOWN()
  541. -------------------------------------------
  542.     for i = 1, 10, 1 do
  543.         local start, duration, enable = GetPetActionCooldown(i)
  544.         if enable == 1 then
  545.             local name, _, texture = GetPetActionInfo(i)
  546.             if name then
  547.                 if start > 0 and not block[name] then
  548.                     if duration > 3 then
  549.                         NewCooldown(name, texture, start + duration)
  550.                     end
  551.                 else
  552.                     ClearCooldown(nil, name)
  553.                 end
  554.             end
  555.         end
  556.     end
  557. end
  558. ------------------------------
  559. function CoolLine:UNIT_PET(a1)
  560. ------------------------------
  561.     if UnitExists("pet") and not HasPetUI() then
  562.         self:RegisterEvent("PET_BAR_UPDATE_COOLDOWN")
  563.     else
  564.         self:UnregisterEvent("PET_BAR_UPDATE_COOLDOWN")
  565.     end
  566. end
  567.  
  568. local GetActionCooldown, HasAction = GetActionCooldown, HasAction
  569. ---------------------------------------------
  570. function CoolLine:ACTIONBAR_UPDATE_COOLDOWN()  -- used only for vehicles
  571. ---------------------------------------------
  572.     for i = 1, 8, 1 do
  573.         local b = _G["OverrideActionBarButton"..i]
  574.         if b and HasAction(b.action) then
  575.             local start, duration, enable = GetActionCooldown(b.action)
  576.             if enable == 1 then
  577.                 if start > 0 and not block[GetActionInfo(b.action)] then
  578.                     if duration > 3 then
  579.                         NewCooldown("vhcle"..i, GetActionTexture(b.action), start + duration)
  580.                     end
  581.                 else
  582.                     ClearCooldown(nil, "vhcle"..i)
  583.                 end
  584.             end
  585.         end
  586.     end
  587. end
  588. ------------------------------------------
  589. function CoolLine:UNIT_ENTERED_VEHICLE()
  590. ------------------------------------------
  591.     if not UnitHasVehicleUI("player") then return end
  592.     self:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN")
  593.     self:RegisterUnitEvent("UNIT_EXITED_VEHICLE", "player")
  594.     self:ACTIONBAR_UPDATE_COOLDOWN()
  595. end
  596. -----------------------------------------
  597. function CoolLine:UNIT_EXITED_VEHICLE()
  598. -----------------------------------------
  599.     self:UnregisterEvent("ACTIONBAR_UPDATE_COOLDOWN")
  600.     for index, frame in ipairs(cooldowns) do
  601.         if strmatch(frame.name, "vhcle") then
  602.             ClearCooldown(nil, frame.name)
  603.         end
  604.     end
  605. end
  606.  
  607. local failborder
  608. ----------------------------------------------------
  609. function CoolLine:UNIT_SPELLCAST_FAILED(unit, spell)
  610. ----------------------------------------------------
  611.     if #cooldowns == 0 then return end
  612.     for index, frame in pairs(cooldowns) do
  613.         if frame.name == spell then
  614.             if frame.endtime - GetTime() > 1 then
  615.                 if not failborder then
  616.                     failborder = CreateFrame("Frame", nil, CoolLine.border)
  617.                     failborder:SetBackdrop(iconback)
  618.                     failborder:SetBackdropColor(1, 0, 0, 0.9)
  619.                     failborder:Hide()
  620.                     failborder:SetScript("OnUpdate", function(this, a1)
  621.                         this.alp = this.alp - a1
  622.                         if this.alp < 0 then return this:Hide() end
  623.                         this:SetAlpha(this.alp > 1 and 1 or this.alp)
  624.                     end)
  625.                 end
  626.                 failborder.alp = 1.2
  627.                 failborder:SetPoint("TOPLEFT", frame, "TOPLEFT", -2, 2)
  628.                 failborder:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 2, -2)
  629.                 failborder:Show()
  630.             end
  631.             break
  632.         end
  633.     end
  634.  
  635. end
  636.  
  637.  
  638. local CoolLineDD, Set
  639. local info = { }
  640. function ShowOptions(a1)
  641.     if type(a1) == "string" and a1 ~= "" and a1 ~= "menu" and a1 ~= "options" and a1 ~= "help" then
  642.         if strmatch(a1, "|H") then
  643.             a1 = strmatch(a1, "|h%[(.+)%]|h")
  644.         end
  645.         if a1 then
  646.             if block[a1] then
  647.                 block[a1] = nil
  648.                 print("|cff88ffffCool|r|cff88ff88Line|r: |cffffff00"..a1.."|r removed from filter.")
  649.             else
  650.                 block[a1] = true
  651.                 print("|cff88ffffCool|r|cff88ff88Line|r: |cffffff00"..a1.."|r added to filter.")
  652.             end
  653.         end
  654.         return
  655.     end
  656.     if not CoolLineDD then
  657.         CoolLineDD = CreateFrame("Frame", "CoolLineDD", UIParent)
  658.         CoolLineDD.displayMode = "MENU"
  659.  
  660.         Set = function(b, a1)
  661.             if a1 == "unlock" then
  662.                 if not CoolLine.resizer then
  663.                     CoolLine:SetMovable(true)
  664.                     CoolLine:SetResizable(true)
  665.                     CoolLine:RegisterForDrag("LeftButton")
  666.                     CoolLine:SetScript("OnMouseUp", function(this, a1) if a1 == "RightButton" then ShowOptions() end end)
  667.                     CoolLine:SetScript("OnDragStart", function(this) this:StartMoving() end)
  668.                     CoolLine:SetScript("OnDragStop", function(this)
  669.                         this:StopMovingOrSizing()
  670.                         local x, y = this:GetCenter()
  671.                         local ux, uy = UIParent:GetCenter()
  672.                         db.x, db.y = floor(x - ux + 0.5), floor(y - uy + 0.5)
  673.                         this:ClearAllPoints()
  674.                         updatelook()
  675.                     end)
  676.                
  677.                     CoolLine:SetMinResize(6, 6)
  678.                     CoolLine.resizer = CreateFrame("Button", nil, CoolLine.border, "UIPanelButtonTemplate")
  679.                     local resize = CoolLine.resizer
  680.                     resize:SetWidth(8)
  681.                     resize:SetHeight(8)
  682.                     resize:SetPoint("BOTTOMRIGHT", CoolLine, "BOTTOMRIGHT", 2, -2)
  683.                     resize:SetScript("OnMouseDown", function(this) CoolLine:StartSizing("BOTTOMRIGHT") end)
  684.                     resize:SetScript("OnMouseUp", function(this)
  685.                         CoolLine:StopMovingOrSizing()
  686.                         db.w, db.h = floor(CoolLine:GetWidth() + 0.5), floor(CoolLine:GetHeight() + 0.5)
  687.                         updatelook()
  688.                     end)
  689.                 end
  690.                 if not CoolLine.unlock then
  691.                     CoolLine.unlock = true
  692.                     CoolLine:EnableMouse(true)
  693.                     CoolLine.resizer:Show()
  694.                     CoolLine:SetAlpha(db.activealpha)
  695.                     print("CoolLine - drag frame to reposition or drag red corner to resize")
  696.                 else
  697.                     CoolLine.unlock = nil
  698.                     CoolLine:EnableMouse(false)
  699.                     CoolLine.resizer:Hide()
  700.                     OnUpdate(CoolLine, 2)
  701.                 end
  702.             elseif a1 then
  703.                 if a1 == "vertical" then
  704.                     local pw, ph = db.w, db.h
  705.                     db.w, db.h = ph, pw
  706.                 elseif a1 == "resetall" then
  707.                     CoolLineCharDB, CoolLineDB = nil, nil
  708.                     return ReloadUI()
  709.                 end
  710.                 db[a1] = not db[a1]
  711.                 if a1 == "perchar" then
  712.                     if db.perchar then
  713.                         CoolLineCharDB = CoolLineCharDB or CoolLineDB
  714.                     else
  715.                         CoolLineCharDB = nil
  716.                     end
  717.                     ReloadUI()
  718.                 end
  719.                 updatelook()
  720.             end
  721.         end
  722.         local function SetSelect(b, a1)
  723.             db[a1] = tonumber(b.value) or b.value
  724.             local level, num = strmatch(b:GetName(), "DropDownList(%d+)Button(%d+)")
  725.             level, num = tonumber(level) or 0, tonumber(num) or 0
  726.             for i = 2, level, 1 do
  727.                 for j = 1, UIDROPDOWNMENU_MAXBUTTONS, 1 do
  728.                     local check = _G["DropDownList"..i.."Button"..j.."Check"]
  729.                     if check and i == level and j == num then
  730.                         check:Show()
  731.                     elseif b then
  732.                         check:Hide()
  733.                     end
  734.                 end
  735.             end
  736.             updatelook()
  737.         end
  738.         local function SetColor(a1)
  739.             local dbc = db[UIDROPDOWNMENU_MENU_VALUE]
  740.             if not dbc then return end
  741.             local r, g, b, a
  742.             if a1 then
  743.                 local pv = ColorPickerFrame.previousValues
  744.                 r, g, b, a = pv.r, pv.g, pv.b, 1 - pv.opacity
  745.             else
  746.                 r, g, b = ColorPickerFrame:GetColorRGB()
  747.                 a = 1 - OpacitySliderFrame:GetValue()
  748.             end
  749.             dbc.r, dbc.g, dbc.b, dbc.a = r, g, b, a
  750.             updatelook()
  751.         end
  752.         local function HideCheck(b)
  753.             if b and b.GetName and _G[b:GetName().."Check"] then
  754.                 _G[b:GetName().."Check"]:Hide()
  755.             end
  756.         end
  757.         local function AddButton(lvl, text, keepshown)
  758.             info.text = text
  759.             info.keepShownOnClick = keepshown
  760.             UIDropDownMenu_AddButton(info, lvl)
  761.             wipe(info)
  762.         end
  763.         local function AddToggle(lvl, text, value)
  764.             info.arg1 = value
  765.             info.func = Set
  766.             if value == "unlock" then
  767.                 info.checked = CoolLine.unlock
  768.             else
  769.                 info.checked = db[value]
  770.             end
  771.             AddButton(lvl, text, 1)
  772.         end
  773.         local function AddList(lvl, text, value)
  774.             info.value = value
  775.             info.hasArrow = true
  776.             info.func = HideCheck
  777.             info.notCheckable = 1
  778.             AddButton(lvl, text, 1)
  779.         end
  780.         local function AddSelect(lvl, text, arg1, value)
  781.             info.arg1 = arg1
  782.             info.func = SetSelect
  783.             info.value = value
  784.             if tonumber(value) and tonumber(db[arg1] or "blah") then
  785.                 if floor(100 * tonumber(value)) == floor(100 * tonumber(db[arg1])) then
  786.                     info.checked = true
  787.                 end
  788.             else
  789.                 info.checked = db[arg1] == value
  790.             end
  791.             AddButton(lvl, text, 1)
  792.         end
  793.         local function AddColor(lvl, text, value)
  794.             local dbc = db[value]
  795.             if not dbc then return end
  796.             info.hasColorSwatch = true
  797.             info.hasOpacity = 1
  798.             info.r, info.g, info.b, info.opacity = dbc.r, dbc.g, dbc.b, 1 - (dbc.a or 0)
  799.             info.swatchFunc, info.opacityFunc, info.cancelFunc = SetColor, SetColor, SetColor
  800.             info.value = value
  801.             info.func = UIDropDownMenuButton_OpenColorPicker
  802.             info.notCheckable = 1
  803.             AddButton(lvl, text, nil)
  804.         end
  805.         CoolLineDD.initialize = function(self, lvl)
  806.             if lvl == 1 then
  807.                 info.isTitle = true
  808.                 info.notCheckable = 1
  809.                 AddButton(lvl, "|cff88ffffCool|r|cff88ff88Line|r")
  810.                 AddList(lvl, "Texture", "statusbar")
  811.                 AddColor(lvl, "Texture Color", "bgcolor")
  812.                 AddList(lvl, "Border", "border")
  813.                 AddList(lvl, "Border Size", "bordersize") -- Added Options
  814.                 AddList(lvl, "Border Inset", "borderinset") -- Added Options
  815.                 AddColor(lvl, "Border Color", "bordercolor")
  816.                 AddList(lvl, "Font", "font")
  817.                 AddColor(lvl, "Font Color", "fontcolor")
  818.                 AddList(lvl, "Font Size", "fontsize")
  819.                 AddColor(lvl, "My Spell Color", "spellcolor")
  820.                 AddColor(lvl, "Item/Pet Color", "nospellcolor")
  821.                 AddList(lvl, "Inactive Opacity", "inactivealpha")
  822.                 AddList(lvl, "Active Opacity", "activealpha")
  823.                 AddList(lvl, "Icon Size", "iconplus")
  824.                 AddList(lvl, "More", "More")
  825.                 AddToggle(lvl, "Unlock", "unlock")
  826.             elseif lvl and lvl > 1 then
  827.                 local sub = UIDROPDOWNMENU_MENU_VALUE
  828.                 if sub == "font" or sub == "statusbar" or sub == "border" then
  829.                     local t = smed:List(sub)
  830.                     local starti = 20 * (lvl - 2) + 1
  831.                     local endi = 20 * (lvl - 1)
  832.                     for i = starti, endi, 1 do
  833.                         if not t[i] then break end
  834.                         AddSelect(lvl, t[i], sub, t[i])
  835.                         if i == endi and t[i + 1] then
  836.                             AddList(lvl, "More", sub)
  837.                         end
  838.                     end
  839.                 elseif sub == "fontsize" then
  840.                     for i = 5, 12, 1 do
  841.                         AddSelect(lvl, i, "fontsize", i)
  842.                     end
  843.                     for i = 14, 28, 2 do
  844.                         AddSelect(lvl, i, "fontsize", i)
  845.                     end
  846.                 elseif sub == "bordersize" then -- Added options limits
  847.                     for i = 1, 16, 1 do
  848.                         AddSelect(lvl, i, "bordersize", i)
  849.                     end
  850.                 elseif sub == "borderinset" then -- Added options limits
  851.                     for i = -8, 8, 1 do
  852.                         AddSelect(lvl, i, "borderinset", i)
  853.                     end
  854.                 elseif sub == "inactivealpha" or sub == "activealpha" then
  855.                     for i = 0, 1, 0.1 do
  856.                         AddSelect(lvl, format("%.1f", i), sub, i)
  857.                     end
  858.                 elseif sub == "iconplus" then
  859.                     for i = 0, 24, 2 do
  860.                         AddSelect(lvl, format("+%d", i), sub, i)
  861.                     end
  862.                 elseif sub == "More" then
  863.                     AddToggle(lvl, "Vertical", "vertical")
  864.                     AddToggle(lvl, "Reverse", "reverse")
  865.                     AddToggle(lvl, "Disable Cast Fail", "hidefail")
  866.                     AddToggle(lvl, "Disable Equipped", "hideinv")
  867.                     AddToggle(lvl, "Disable Bags", "hidebag")
  868.                     AddToggle(lvl, "Disable Pet", "hidepet")
  869.                     AddToggle(lvl, "Save Per Char", "perchar")
  870.                     AddToggle(lvl, _G.RESET_TO_DEFAULT, "resetall")
  871.                 end
  872.             end
  873.         end
  874.     end
  875.     ToggleDropDownMenu(1, nil, CoolLineDD, "cursor")
  876. end
  877.  
  878. CONFIGMODE_CALLBACKS = CONFIGMODE_CALLBACKS or {}
  879. CONFIGMODE_CALLBACKS.CoolLine = function(action, mode)
  880.     if action == "ON" then
  881.         if not CoolLineDD then
  882.             ShowOptions()
  883.             ToggleDropDownMenu(1, nil, CoolLineDD, "cursor")
  884.         end
  885.         if CoolLineDD and not CoolLine.unlock then
  886.             Set(nil, "unlock")
  887.         end
  888.     elseif action == "OFF" then
  889.         if CoolLineDD and CoolLine.unlock then
  890.             Set(nil, "unlock")
  891.         end
  892.     end
  893. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement