Advertisement
khanggaroo

InterruptBar no txt 2 rows

Mar 23rd, 2013
1,856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.57 KB | None | 0 0
  1. ----------------------------------------------------
  2. -- Interrupt Bar by Kollektiv
  3. ----------------------------------------------------
  4.  
  5. -- Add new abilities here. Order is determined as shown.
  6. local abilities = {
  7.     {spellid = 2139,   duration = 20},   -- Counterspell
  8.     {spellid = 15487,  duration = 45},   -- Silence
  9.     {spellid = 34490,  duration = 20},   -- Silencing Shot
  10.     {spellid = 19647,  duration = 24},   -- Spell Lock
  11.     {spellid = 57994,  duration = 12},   -- Wind Shear
  12.     {spellid = 6552,   duration = 15},   -- Pummel
  13.     {spellid = 47528,  duration = 15},   -- Mind Freeze
  14.     {spellid = 1766,   duration = 15},   -- Kick
  15.     {spellid = 80965,  duration = 15},   -- Skull Bash
  16.     {spellid = 96231,  duration = 15},   -- Rebuke
  17.     {spellid = 116705, duration = 15},   -- Spear Hand Strike
  18.     {spellid = 78675,  duration = 60},   -- Solar Beam
  19. }
  20.  
  21. -----------------------------------------------------
  22. -----------------------------------------------------
  23.  
  24. InterruptBarDB = InterruptBarDB or { scale = 1, hidden = false, lock = false, }
  25.  
  26. for _,ability in ipairs(abilities) do
  27.     local _,_,spellicon = GetSpellInfo(ability.spellid)
  28.     ability.icon = spellicon
  29. end
  30.  
  31. local SPELLLOCK = 19647
  32. local OPTICALBLAST = 115782
  33.  
  34. local order
  35. local frame
  36. local bar
  37. local btns = {}
  38.  
  39. local band = bit.band
  40. local GetTime = GetTime
  41. local ipairs = ipairs
  42. local pairs = pairs
  43. local select = select
  44. local floor = floor
  45. local ceil = math.ceil
  46. local band = bit.band
  47. local GetSpellInfo = GetSpellInfo
  48.  
  49. local function InterruptBar_OnUpdate(self)
  50.     local cooldown = self.start + self.duration - GetTime()
  51.     if cooldown <= 0 then
  52.         self.deactivate()
  53.     else
  54.         self.settimeleft(ceil(cooldown))
  55.     end
  56. end
  57.  
  58. local function InterruptBar_CreateIcon(ability)
  59.     local btn = CreateFrame("Frame",nil,bar)
  60.     btn:SetWidth(30)
  61.     btn:SetHeight(30)
  62.     btn:SetFrameStrata("LOW")
  63.  
  64.     local cd = CreateFrame("Cooldown",nil,btn)
  65.     cd.noomnicc = true
  66.     cd.noCooldownCount = true
  67.     cd:SetAllPoints(true)
  68.     cd:SetFrameStrata("MEDIUM")
  69.     cd:Hide()
  70.  
  71.     local texture = btn:CreateTexture(nil,"BACKGROUND")
  72.     texture:SetAllPoints(true)
  73.     texture:SetTexture(ability.icon)
  74.     texture:SetTexCoord(0.07,0.9,0.07,0.90)
  75.  
  76.     local text = cd:CreateFontString(nil,"ARTWORK")
  77.     text:SetFont(STANDARD_TEXT_FONT,18,"OUTLINE")
  78.     text:SetTextColor(0,0,0,0)
  79.     text:SetPoint("LEFT",btn,"LEFT",2,0)
  80.  
  81.     btn.texture = texture
  82.     btn.text = text
  83.     btn.duration = ability.duration
  84.     btn.cd = cd
  85.  
  86.     btn.activate = function()
  87.         if btn.active then return end
  88.         if InterruptBarDB.hidden then btn:Show() end
  89.         btn.start = GetTime()
  90.         btn.cd:Show()
  91.         btn.cd:SetCooldown(GetTime()-0.40,btn.duration)
  92.         btn.start = GetTime()
  93.         btn.settimeleft(btn.duration)
  94.         btn:SetScript("OnUpdate", InterruptBar_OnUpdate)
  95.         btn.active = true
  96.     end
  97.  
  98.     btn.deactivate = function()
  99.         if InterruptBarDB.hidden then btn:Hide() end
  100.         btn.text:SetText("")
  101.         btn.cd:Hide()
  102.         btn:SetScript("OnUpdate", nil)
  103.         btn.active = false
  104.     end
  105.  
  106.     btn.settimeleft = function(timeleft)
  107.         if timeleft < 10 then
  108.             if timeleft <= 0.5 then
  109.                 btn.text:SetText("")
  110.             else
  111.                 btn.text:SetFormattedText(" %d",timeleft)
  112.             end
  113.         else
  114.             btn.text:SetFormattedText("%d",timeleft)
  115.         end
  116.         if timeleft < 6 then
  117.             btn.text:SetTextColor(0,0,0,0)
  118.         else
  119.             btn.text:SetTextColor(0,0,0,0)
  120.         end
  121.         if timeleft > 60 then
  122.             btn.text:SetFont(STANDARD_TEXT_FONT,14,"OUTLINE")
  123.         else
  124.             btn.text:SetFont(STANDARD_TEXT_FONT,18,"OUTLINE")
  125.         end
  126.     end
  127.  
  128.     return btn
  129. end
  130.  
  131. local function InterruptBar_AddIcons()
  132.    local y = -45
  133.    local x = 0
  134.    local height = 1    -- put height of bar here (in buttons) (default number of abilities)
  135.    local offset = 30            -- Distance between columns
  136.    local count = 0              -- Number of buttons added so far
  137.    for _,ability in ipairs(abilities) do
  138.       if count > height then
  139.          y = -45
  140.          x = x + offset
  141.          count = 0
  142.       end  
  143.       local btn = InterruptBar_CreateIcon(ability)
  144.       btn:SetPoint("CENTER", bar, "CENTER", x, y)
  145.       btns[ability.spellid] = btn
  146.       y = y + 30
  147.       count = count + 1
  148.    end
  149. end
  150.  
  151. local function InterruptBar_SavePosition()
  152.     local point, _, relativePoint, xOfs, yOfs = bar:GetPoint()
  153.     if not InterruptBarDB.Position then
  154.         InterruptBarDB.Position = {}
  155.     end
  156.     InterruptBarDB.Position.point = point
  157.     InterruptBarDB.Position.relativePoint = relativePoint
  158.     InterruptBarDB.Position.xOfs = xOfs
  159.     InterruptBarDB.Position.yOfs = yOfs
  160. end
  161.  
  162. local function InterruptBar_LoadPosition()
  163.     if InterruptBarDB.Position then
  164.         bar:SetPoint(InterruptBarDB.Position.point,UIParent,InterruptBarDB.Position.relativePoint,InterruptBarDB.Position.xOfs,InterruptBarDB.Position.yOfs)
  165.     else
  166.         bar:SetPoint("CENTER", UIParent, "CENTER")
  167.     end
  168. end
  169.  
  170. local function InterruptBar_UpdateBar()
  171.     bar:SetScale(InterruptBarDB.scale)
  172.     if InterruptBarDB.hidden then
  173.         for _,btn in pairs(btns) do btn:Hide() end
  174.     else
  175.         for _,btn in pairs(btns) do btn:Show() end
  176.     end
  177.     if InterruptBarDB.lock then
  178.         bar:EnableMouse(false)
  179.     else
  180.         bar:EnableMouse(true)
  181.     end
  182. end
  183.  
  184. local function InterruptBar_CreateBar()
  185.     bar = CreateFrame("Frame", nil, UIParent)
  186.     bar:SetMovable(true)
  187.     bar:SetWidth(120)
  188.     bar:SetHeight(30)
  189.     bar:SetClampedToScreen(true)
  190.     bar:SetScript("OnMouseDown",function(self,button) if button == "LeftButton" then self:StartMoving() end end)
  191.     bar:SetScript("OnMouseUp",function(self,button) if button == "LeftButton" then self:StopMovingOrSizing() InterruptBar_SavePosition() end end)
  192.     bar:Show()
  193.    
  194.     InterruptBar_AddIcons()
  195.     InterruptBar_UpdateBar()
  196.     InterruptBar_LoadPosition()
  197. end
  198.  
  199. local function InterruptBar_COMBAT_LOG_EVENT_UNFILTERED(_, eventtype, _, _, srcName, srcFlags, _, _, dstName, dstFlags, _, spellid)
  200.     if band(srcFlags, 0x00000040) == 0x00000040 and eventtype == "SPELL_CAST_SUCCESS" then
  201.         -- Redirect Optical Blast to Spell Lock
  202.         if spellid == OPTICALBLAST and btns[SPELLLOCK] then
  203.             spellid = SPELLLOCK
  204.         end
  205.         local btn = btns[spellid]
  206.         if btn then btn.activate() end
  207.     end
  208. end
  209.  
  210. local function InterruptBar_ResetAllTimers()
  211.     for _,btn in pairs(btns) do
  212.         btn.deactivate()
  213.     end
  214. end
  215.  
  216. local function InterruptBar_PLAYER_ENTERING_WORLD(self)
  217.     InterruptBar_ResetAllTimers()
  218. end
  219.  
  220. local function InterruptBar_Reset()
  221.     InterruptBarDB = { scale = 1, hidden = false, lock = false }
  222.     InterruptBar_UpdateBar()
  223.     InterruptBar_LoadPosition()
  224. end
  225.  
  226. local function InterruptBar_Test()
  227.     for _,btn in pairs(btns) do
  228.         btn.activate()
  229.     end
  230. end
  231.  
  232. local cmdfuncs = {
  233.     scale = function(v) InterruptBarDB.scale = v; InterruptBar_UpdateBar() end,
  234.     hidden = function() InterruptBarDB.hidden = not InterruptBarDB.hidden; InterruptBar_UpdateBar() end,
  235.     lock = function() InterruptBarDB.lock = not InterruptBarDB.lock; InterruptBar_UpdateBar() end,
  236.     reset = function() InterruptBar_Reset() end,
  237.     test = function() InterruptBar_Test() end,
  238. }
  239.  
  240. local cmdtbl = {}
  241. function InterruptBar_Command(cmd)
  242.     for k in ipairs(cmdtbl) do
  243.         cmdtbl[k] = nil
  244.     end
  245.     for v in gmatch(cmd, "[^ ]+") do
  246.     tinsert(cmdtbl, v)
  247.   end
  248.   local cb = cmdfuncs[cmdtbl[1]]
  249.   if cb then
  250.     local s = tonumber(cmdtbl[2])
  251.     cb(s)
  252.   else
  253.     ChatFrame1:AddMessage("InterruptBar Options | /ib <option>",0,1,0)     
  254.     ChatFrame1:AddMessage("-- scale <number> | value: " .. InterruptBarDB.scale,0,1,0)
  255.     ChatFrame1:AddMessage("-- hidden (toggle) | value: " .. tostring(InterruptBarDB.hidden),0,1,0)
  256.     ChatFrame1:AddMessage("-- lock (toggle) | value: " .. tostring(InterruptBarDB.lock),0,1,0)
  257.     ChatFrame1:AddMessage("-- test (execute)",0,1,0)
  258.     ChatFrame1:AddMessage("-- reset (execute)",0,1,0)
  259.   end
  260. end
  261.  
  262. local function InterruptBar_OnLoad(self)
  263.     self:RegisterEvent("PLAYER_ENTERING_WORLD")
  264.     self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  265.     if not InterruptBarDB.scale then InterruptBarDB.scale = 1 end
  266.     if not InterruptBarDB.hidden then InterruptBarDB.hidden = false end
  267.     if not InterruptBarDB.lock then InterruptBarDB.lock = false end
  268.     InterruptBar_CreateBar()
  269.    
  270.     SlashCmdList["InterruptBar"] = InterruptBar_Command
  271.     SLASH_InterruptBar1 = "/ib"
  272.    
  273.     ChatFrame1:AddMessage("Interrupt Bar by Kollektiv. Type /ib for options.",0,1,0)
  274. end
  275.  
  276. local eventhandler = {
  277.     ["VARIABLES_LOADED"] = function(self) InterruptBar_OnLoad(self) end,
  278.     ["PLAYER_ENTERING_WORLD"] = function(self) InterruptBar_PLAYER_ENTERING_WORLD(self) end,
  279.     ["COMBAT_LOG_EVENT_UNFILTERED"] = function(self,...) InterruptBar_COMBAT_LOG_EVENT_UNFILTERED(...) end,
  280. }
  281.  
  282. local function InterruptBar_OnEvent(self,event,...)
  283.     eventhandler[event](self,...)
  284. end
  285.  
  286. frame = CreateFrame("Frame",nil,UIParent)
  287. frame:SetScript("OnEvent",InterruptBar_OnEvent)
  288. frame:RegisterEvent("VARIABLES_LOADED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement