Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 25th, 2013  |  syntax: Lua  |  size: 8.21 KB  |  views: 43  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -- SpellNotReadyYet v1.1. Created by Shadowmagé - Stormrage EU
  2.  
  3. -- CONFIG
  4. local iconsize;
  5. local xoff;
  6. local yoff;
  7. local tfont;
  8. local fontsize = 16;
  9. local fdur = 0.7;
  10.  
  11. local function snr_saveall()
  12.         saved = {}
  13.         saved["iconsize"] = iconsize
  14.         saved["xoff"] = xoff
  15.         saved["yoff"] = yoff
  16.         saved["tfont"] = tfont
  17.         saved["fontsize"] = fontsize
  18.         saved["fdur"] = fdur
  19. end
  20.  
  21. iconsize = 40   -- Changes the size of the icon
  22. xoff = 0 -- Increase to move right, decrease to move left (note: you can go into minus numbers)
  23. yoff = 0 -- Increase to move up, decrease to move down (note: you can go into minus numbers)
  24. tfont = "Fonts\\FRIZQT__.TTF" -- The file path for the font you wish to use
  25. fontsize = 16 -- Font size
  26. fdur = 0.7 -- Duration of the icon appearing on the screen (range between 0.1 and 1, anything above 1 and stuff gets funky)
  27.  
  28. SLASH_SNR1 = '/snr';
  29. function SlashCmdList.SNR(msg)
  30.         local command, rest = msg:match("^(%S*)%s*(.-)$");
  31.         print(command.."-"..rest);
  32.         if command == "x" and rest ~= "" then
  33.                 xoff = tonumber(rest);
  34.         elseif command == "y"  and rest ~= "" then
  35.                 yoff = tonumber(rest);
  36.         end
  37.         snr_saveall();
  38. end
  39.  
  40. -----------------
  41.  
  42. local _;
  43.  
  44.  
  45. local frameFlashManager = CreateFrame("FRAME");
  46.  
  47. local FLASHFRAMES = {};
  48. local UIFrameFlashTimers = {};
  49. local UIFrameFlashTimerRefCount = {};
  50.  
  51. -- Function to see if a frame is already flashing
  52. local function UIFrameIsFlashing(frame)
  53.     for index, value in pairs(FLASHFRAMES) do
  54.         if ( value == frame ) then
  55.             return 1;
  56.         end
  57.     end
  58.     return nil;
  59. end
  60.  
  61. -- Function to stop flashing
  62. local function UIFrameFlashStop(frame)
  63.     tDeleteItem(FLASHFRAMES, frame);
  64.     frame:SetAlpha(1.0);
  65.     frame.flashTimer = nil;
  66.     if (frame.syncId) then
  67.         UIFrameFlashTimerRefCount[frame.syncId] = UIFrameFlashTimerRefCount[frame.syncId]-1;
  68.         if (UIFrameFlashTimerRefCount[frame.syncId] == 0) then
  69.             UIFrameFlashTimers[frame.syncId] = nil;
  70.             UIFrameFlashTimerRefCount[frame.syncId] = nil;
  71.         end
  72.         frame.syncId = nil;
  73.     end
  74.     if ( frame.showWhenDone ) then
  75.         frame:Show();
  76.     else
  77.         frame:Hide();
  78.     end
  79. end
  80.  
  81. -- Called every frame to update flashing frames
  82. local function UIFrameFlash_OnUpdate(self, elapsed)
  83.     local frame;
  84.     local index = #FLASHFRAMES;
  85.  
  86.     -- Update timers for all synced frames
  87.     for syncId, timer in pairs(UIFrameFlashTimers) do
  88.         UIFrameFlashTimers[syncId] = timer + elapsed;
  89.     end
  90.  
  91.     while FLASHFRAMES[index] do
  92.         frame = FLASHFRAMES[index];
  93.         frame.flashTimer = frame.flashTimer + elapsed;
  94.  
  95.         if ( (frame.flashTimer > frame.flashDuration) and frame.flashDuration ~= -1 ) then
  96.             UIFrameFlashStop(frame);
  97.         else
  98.             local flashTime = frame.flashTimer;
  99.             local alpha;
  100.  
  101.             if (frame.syncId) then
  102.                 flashTime = UIFrameFlashTimers[frame.syncId];
  103.             end
  104.  
  105.             flashTime = flashTime%(frame.fadeInTime+frame.fadeOutTime+(frame.flashInHoldTime or 0)+(frame.flashOutHoldTime or 0));
  106.             if (flashTime < frame.fadeInTime) then
  107.                 alpha = flashTime/frame.fadeInTime;
  108.             elseif (flashTime < frame.fadeInTime+(frame.flashInHoldTime or 0)) then
  109.                 alpha = 1;
  110.             elseif (flashTime < frame.fadeInTime+(frame.flashInHoldTime or 0)+frame.fadeOutTime) then
  111.                 alpha = 1 - ((flashTime - frame.fadeInTime - (frame.flashInHoldTime or 0))/frame.fadeOutTime);
  112.             else
  113.                 alpha = 0;
  114.             end
  115.  
  116.             frame:SetAlpha(alpha);
  117.             frame:Show();
  118.         end
  119.  
  120.         -- Loop in reverse so that removing frames is safe
  121.         index = index - 1;
  122.     end
  123.  
  124.     if ( #FLASHFRAMES == 0 ) then
  125.         self:SetScript("OnUpdate", nil);
  126.     end
  127. end
  128.  
  129. -- Function to start a frame flashing
  130. local function UIFrameFlash(frame, fadeInTime, fadeOutTime, flashDuration, showWhenDone, flashInHoldTime, flashOutHoldTime, syncId)
  131.     if ( frame ) then
  132.         local index = 1;
  133.         -- If frame is already set to flash then return
  134.         while FLASHFRAMES[index] do
  135.             if ( FLASHFRAMES[index] == frame ) then
  136.                 return;
  137.             end
  138.             index = index + 1;
  139.         end
  140.  
  141.         if (syncId) then
  142.             frame.syncId = syncId;
  143.             if (UIFrameFlashTimers[syncId] == nil) then
  144.                 UIFrameFlashTimers[syncId] = 0;
  145.                 UIFrameFlashTimerRefCount[syncId] = 0;
  146.             end
  147.             UIFrameFlashTimerRefCount[syncId] = UIFrameFlashTimerRefCount[syncId]+1;
  148.         else
  149.             frame.syncId = nil;
  150.         end
  151.  
  152.         -- Time it takes to fade in a flashing frame
  153.         frame.fadeInTime = fadeInTime;
  154.         -- Time it takes to fade out a flashing frame
  155.         frame.fadeOutTime = fadeOutTime;
  156.         -- How long to keep the frame flashing
  157.         frame.flashDuration = flashDuration;
  158.         -- Show the flashing frame when the fadeOutTime has passed
  159.         frame.showWhenDone = showWhenDone;
  160.         -- Internal timer
  161.         frame.flashTimer = 0;
  162.         -- How long to hold the faded in state
  163.         frame.flashInHoldTime = flashInHoldTime;
  164.         -- How long to hold the faded out state
  165.         frame.flashOutHoldTime = flashOutHoldTime;
  166.  
  167.         tinsert(FLASHFRAMES, frame);
  168.  
  169.         frameFlashManager:SetScript("OnUpdate", UIFrameFlash_OnUpdate);
  170.     end
  171. end
  172.  
  173.  
  174.  
  175.  
  176. local formatTime = function(s)
  177.         local day, hour, minute = 86400, 3600, 60
  178.         if s >= day then
  179.                 return format("%dd", floor(s/day + 0.5)), s % day
  180.         elseif s >= hour then
  181.                 return format("%dh", floor(s/hour + 0.5)), s % hour
  182.         elseif s >= minute then
  183.                 return format("%dm", floor(s/minute + 0.5)), s % minute
  184.         elseif s >= minute / 12 then
  185.                 return floor(s + 0.5), (s * 100 - floor(s * 100))/100
  186.         end
  187.         return format("%.1f", s), (s * 100 - floor(s * 100))/100
  188. end
  189.  
  190. -- Hides standard UI error spam frame, since we are
  191. -- replacing it by our icons
  192. UIErrorsFrame:Hide();
  193.  
  194. local frame = CreateFrame("Frame");
  195. frame:RegisterEvent("UNIT_SPELLCAST_FAILED");
  196. frame:RegisterEvent("UI_ERROR_MESSAGE");
  197. -- frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  198. frame:RegisterEvent("ADDON_LOADED");
  199.  
  200. local function eventHandler(self, event, ...)
  201.  
  202.         -- Fires on spellcast (either suceeded or failed because of cooldown, etc)
  203.         if event == "UNIT_SPELLCAST_FAILED" or event == "UNIT_SPELLCAST_SUCCEEDED" then
  204.                 local unit, spellname, spellrank, spellidcounter, id = ...;
  205.                 local start, duration, enabled = GetSpellCooldown(id);
  206.                 local name, rank, icon, cost, isFunnel, powerType, castTime, minRange, maxRange = GetSpellInfo(id)
  207.                 local seconds = GetTime();
  208.                 local timeleft = (start + duration - seconds);
  209.  
  210.                 if name == "Synapse Springs" then else
  211.                         if unit == "player" then
  212.                                 local iconframe = CreateFrame("Frame", nil, UIParent)
  213.                                 UIFrameFlash(iconframe, 0, fdur, fdur, false, 0, 0)
  214.                                 iconframe:SetPoint("CENTER", xoff, yoff)
  215.                                 iconframe:SetSize(iconsize, iconsize)
  216.                                 iconframe:SetBackdrop({
  217.                                         bgFile = icon
  218.                                         })
  219.                                 if event == "UNIT_SPELLCAST_FAILED" then
  220.                                         iconframe:SetBackdropColor(1,0.2,0.2);
  221.                                         local tr = iconframe:CreateFontString()
  222.                                         tr:SetPoint("BOTTOM", 0, 0)
  223.                                         tr:SetSize(40, 40)
  224.                                         tr:SetFont(tfont, fontsize, "OUTLINE")
  225.                                         tr:SetTextColor(1,0.7,0.7)
  226.                                         if timeleft < 0 then
  227.                                          tr:SetText("ERR")
  228.                                         else
  229.                                                 tr:SetText(formatTime(timeleft))
  230.                                         end
  231.                                 end
  232.                                 iconframe:SetFrameStrata("BACKGROUND")
  233.                         end
  234.                 end
  235.                
  236.         -- fires on UI Error "I need a target!"
  237.         elseif event == "UI_ERROR_MESSAGE" then
  238.                 local iconframe = CreateFrame("Frame", nil, UIParent)
  239.                 UIFrameFlash(iconframe, 0, fdur, fdur, false, 0, 0)
  240.                 iconframe:SetPoint("CENTER", xoff, yoff)
  241.                 iconframe:SetSize(iconsize, iconsize)
  242.                 iconframe:SetBackdrop({
  243.                         bgFile = "Interface\\TargetingFrame\\UI-RaidTargetingIcon_7"
  244.                 })
  245.                 -- iconframe:SetBackdropColor(1,0.2,0.2);
  246.                 iconframe:SetFrameStrata("BACKGROUND")
  247.                
  248.         -- load options
  249.         elseif event == "ADDON_LOADED" then
  250.                 if saved then
  251.                         iconsize = saved["iconsize"]
  252.                         xoff = saved["xoff"]
  253.                         yoff = saved["yoff"]
  254.                         tfont = saved["tfont"]
  255.                         fontsize = saved["fontsize"]
  256.                         fdur = saved["fdur"]
  257.                 end
  258.         end
  259. end
  260.  
  261. frame:SetScript("OnEvent", eventHandler);
clone this paste RAW Paste Data