Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.45 KB | None | 0 0
  1. MaxDps.Spells = {};
  2. MaxDps.Flags = {};
  3. MaxDps.SpellsGlowing = {};
  4. MaxDps.FramePool = {};
  5. MaxDps.Frames = {};
  6.  
  7. --- Creates frame overlay over a specific frame, it doesn't need to be a button.
  8. -- @param parent - frame that is suppose to be attached to
  9. -- @param id - string id of overlay because frame can have multiple overlays
  10. -- @param texture - optional custom texture
  11. -- @param type - optional type of overlay, standard types are 'normal' and 'cooldown' - used to select overlay color
  12. -- @param color - optional custom color in standard structure {r = 1, g = 1, b = 1, a = 1}
  13. function MaxDps:CreateOverlay(parent, id, texture, type, color)
  14.     local frame = tremove(self.FramePool);
  15.     if not frame then
  16.         frame = CreateFrame('Frame', 'MaxDps_Overlay_' .. id, parent);
  17.     end
  18.  
  19.     local sizeMult = self.db.global.sizeMult or 1.4;
  20.     frame:SetParent(parent);
  21.     frame:SetFrameStrata('HIGH');
  22.     frame:SetPoint('CENTER', 0, 0);
  23.     frame:SetWidth(parent:GetWidth() * sizeMult);
  24.     frame:SetHeight(parent:GetHeight() * sizeMult);
  25.  
  26.     local t = frame.texture;
  27.     if not t then
  28.         t = frame:CreateTexture('GlowOverlay', 'OVERLAY');
  29.         t:SetTexture(texture or MaxDps:GetTexture());
  30.         t:SetBlendMode('ADD');
  31.         frame.texture = t;
  32.     end
  33.  
  34.     t:SetAllPoints(frame);
  35.  
  36.     if type then
  37.         frame.ovType = type;
  38.         if type == 'normal' then
  39.             local c = self.db.global.highlightColor;
  40.             t:SetVertexColor(c.r, c.g, c.b, c.a);
  41.         elseif type == 'cooldown' then
  42.             local c = self.db.global.cooldownColor;
  43.             t:SetVertexColor(c.r, c.g, c.b, c.a);
  44.         else
  45.             t:SetVertexColor(color.r, color.r, color.r, color.r);
  46.         end
  47.     else
  48.         t:SetVertexColor(color.r, color.g, color.b, color.a);
  49.     end
  50.  
  51.     tinsert(self.Frames, frame);
  52.     return frame;
  53. end
  54.  
  55. function MaxDps:DestroyAllOverlays()
  56.     for key, frame in pairs(self.Frames) do
  57.         frame:GetParent().MaxDpsOverlays = nil;
  58.         frame:ClearAllPoints();
  59.         frame:Hide();
  60.         frame:SetParent(UIParent);
  61.         frame.width = nil;
  62.         frame.height = nil;
  63.     end
  64.  
  65.     for key, frame in pairs(self.Frames) do
  66.         tinsert(self.FramePool, frame);
  67.         self.Frames[key] = nil;
  68.     end
  69. end
  70.  
  71. function MaxDps:ApplyOverlayChanges()
  72.     for key, frame in pairs(self.Frames) do
  73.         local sizeMult = self.db.global.sizeMult or 1.4;
  74.         frame:SetWidth(frame:GetParent():GetWidth() * sizeMult);
  75.         frame:SetHeight(frame:GetParent():GetHeight() * sizeMult);
  76.         frame.texture:SetTexture(MaxDps:GetTexture());
  77.         frame.texture:SetAllPoints(frame);
  78.  
  79.         if frame.ovType == 'normal' then
  80.             local c = self.db.global.highlightColor;
  81.             frame.texture:SetVertexColor(c.r, c.g, c.b, c.a);
  82.         elseif frame.ovType == 'cooldown' then
  83.             local c = self.db.global.cooldownColor;
  84.             frame.texture:SetVertexColor(c.r, c.g, c.b, c.a);
  85.         end
  86.     end
  87. end
  88.  
  89. function MaxDps:UpdateButtonGlow()
  90.     local LAB;
  91.     local LBG;
  92.     local origShow;
  93.     local noFunction = function() end;
  94.  
  95.     if IsAddOnLoaded('ElvUI') then
  96.         LAB = LibStub:GetLibrary('LibActionButton-1.0-ElvUI');
  97.         LBG = LibStub:GetLibrary('LibButtonGlow-1.0');
  98.         origShow = LBG.ShowOverlayGlow;
  99.     elseif IsAddOnLoaded('Bartender4') then
  100.         LAB = LibStub:GetLibrary('LibActionButton-1.0');
  101.     end
  102.  
  103.     if self.db.global.disableButtonGlow then
  104.         ActionBarActionEventsFrame:UnregisterEvent('SPELL_ACTIVATION_OVERLAY_GLOW_SHOW');
  105.         if LAB then
  106.             LAB.eventFrame:UnregisterEvent('SPELL_ACTIVATION_OVERLAY_GLOW_SHOW');
  107.         end
  108.  
  109.         if LBG then
  110.             LBG.ShowOverlayGlow = noFunction;
  111.         end
  112.     else
  113.         ActionBarActionEventsFrame:RegisterEvent('SPELL_ACTIVATION_OVERLAY_GLOW_SHOW');
  114.         if LAB then
  115.             LAB.eventFrame:RegisterEvent('SPELL_ACTIVATION_OVERLAY_GLOW_SHOW');
  116.         end
  117.  
  118.         if LBG then
  119.             LBG.ShowOverlayGlow = origShow;
  120.         end
  121.     end
  122. end
  123.  
  124. function MaxDps:Glow(button, id, texture, type, color)
  125.     if button.MaxDpsOverlays and button.MaxDpsOverlays[id] then
  126.         button.MaxDpsOverlays[id]:Show();
  127.     else
  128.         if not button.MaxDpsOverlays then
  129.             button.MaxDpsOverlays = {};
  130.         end
  131.  
  132.         button.MaxDpsOverlays[id] = self:CreateOverlay(button, id, texture, type, color);
  133.         button.MaxDpsOverlays[id]:Show();
  134.     end
  135. end
  136.  
  137. function MaxDps:HideGlow(button, id)
  138.     if button.MaxDpsOverlays and button.MaxDpsOverlays[id] then
  139.         button.MaxDpsOverlays[id]:Hide();
  140.     end
  141. end
  142.  
  143. function MaxDps:AddButton(spellId, button)
  144.     if spellId then
  145.         if self.Spells[spellId] == nil then
  146.             self.Spells[spellId] = {};
  147.         end
  148.         tinsert(self.Spells[spellId], button);
  149.     end
  150. end
  151.  
  152. function MaxDps:AddStandardButton(button)
  153.     local type = button:GetAttribute('type');
  154.     if type then
  155.         local actionType = button:GetAttribute(type);
  156.         local id;
  157.         local spellId;
  158.  
  159.         if type == 'action' then
  160.             local slot = button:GetAttribute('action');
  161.             if not slot or slot == 0 then
  162.                 slot = ActionButton_GetPagedID(button);
  163.             end
  164.             if not slot or slot == 0 then
  165.                 slot = ActionButton_CalculateAction(button);
  166.             end
  167.  
  168.             if HasAction(slot) then
  169.                 type, actionType = GetActionInfo(slot);
  170.             else
  171.                 return;
  172.             end
  173.         end
  174.  
  175.         if type == 'macro' then
  176.             spellId = GetMacroSpell(actionType);
  177.             if not spellId then
  178.                 return;
  179.             end
  180.         elseif type == 'item' then
  181.             actionName = GetItemInfo(actionType);
  182.         elseif type == 'spell' then
  183.             spellId = select(7, GetSpellInfo(actionType));
  184.         end
  185.  
  186.         self:AddButton(spellId, button);
  187.     end
  188. end
  189.  
  190. function MaxDps:Fetch()
  191.     self = MaxDps;
  192.     if self.rotationEnabled then
  193.         self:DisableRotationTimer();
  194.     end
  195.     self.Spell = nil;
  196.  
  197.     self:GlowClear();
  198.     self.Spells = {};
  199.     self.Flags = {};
  200.     self.SpellsGlowing = {};
  201.  
  202.     self:FetchLibActionButton();
  203.     self:FetchBlizzard();
  204.  
  205.     -- It does not alter original button frames so it needs to be fetched too
  206.     if IsAddOnLoaded('ButtonForge') then
  207.         self:FetchButtonForge();
  208.     end
  209.  
  210.     if IsAddOnLoaded('G15Buttons') then
  211.         self:FetchG15Buttons();
  212.     end
  213.  
  214.     if IsAddOnLoaded('SyncUI') then
  215.         self:FetchSyncUI();
  216.     end
  217.  
  218.     if IsAddOnLoaded('LUI') then
  219.         self:FetchLUI();
  220.     end
  221.  
  222.     if IsAddOnLoaded('Dominos') then
  223.         self:FetchDominos();
  224.     end
  225.  
  226.     if IsAddOnLoaded('DiabolicUI') then
  227.         self:FetchDiabolic();
  228.     end
  229.  
  230.     if IsAddOnLoaded('AzeriteUI') then
  231.         self:FetchAzeriteUI();
  232.     end
  233.  
  234.     if self.rotationEnabled then
  235.         self:EnableRotationTimer();
  236.         self:InvokeNextSpell();
  237.     end
  238. end
  239.  
  240. function MaxDps:FetchDiabolic()
  241.     local diabolicBars = {'EngineBar1', 'EngineBar2', 'EngineBar3', 'EngineBar4', 'EngineBar5'};
  242.     for _, bar in pairs(diabolicBars) do
  243.         for i = 1, 12 do
  244.             local button = _G[bar .. 'Button' .. i];
  245.             if button then
  246.                 self:AddStandardButton(button);
  247.             end
  248.         end
  249.     end
  250. end
  251.  
  252. function MaxDps:FetchDominos()
  253.     -- Dominos is using half of the blizzard frames so we just fetch the missing one
  254.  
  255.     for i = 1, 60 do
  256.         local button = _G['DominosActionButton' .. i];
  257.         if button then
  258.             self:AddStandardButton(button);
  259.         end
  260.     end
  261. end
  262.  
  263.  
  264. function MaxDps:FetchAzeriteUI()
  265.     for i = 1, 24 do
  266.         local button = _G['AzeriteUIActionButton' .. i];
  267.         if button then
  268.             self:AddStandardButton(button);
  269.         end
  270.     end
  271. end
  272.  
  273. function MaxDps:FetchLUI()
  274.     local luiBars = {
  275.         'LUIBarBottom1', 'LUIBarBottom2', 'LUIBarBottom3', 'LUIBarBottom4', 'LUIBarBottom5', 'LUIBarBottom6',
  276.         'LUIBarRight1', 'LUIBarRight2', 'LUIBarLeft1', 'LUIBarLeft2'
  277.     };
  278.  
  279.     for _, bar in pairs(luiBars) do
  280.         for i = 1, 12 do
  281.             local button = _G[bar .. 'Button' .. i];
  282.             if button then
  283.                 self:AddStandardButton(button);
  284.             end
  285.         end
  286.     end
  287. end
  288.  
  289. function MaxDps:FetchSyncUI()
  290.     local syncbars = {};
  291.  
  292.     syncbars[1] = SyncUI_ActionBar;
  293.     syncbars[2] = SyncUI_MultiBar;
  294.     syncbars[3] = SyncUI_SideBar.Bar1;
  295.     syncbars[4] = SyncUI_SideBar.Bar2;
  296.     syncbars[5] = SyncUI_SideBar.Bar3;
  297.     syncbars[6] = SyncUI_PetBar;
  298.  
  299.     for _, bar in pairs(syncbars) do
  300.         for i = 1, 12 do
  301.             local button = bar['Button' .. i];
  302.             if button then
  303.                 self:AddStandardButton(button);
  304.             end
  305.         end
  306.     end
  307. end
  308.  
  309. function MaxDps:FetchLibActionButton()
  310.     local LAB = {
  311.         original = LibStub:GetLibrary('LibActionButton-1.0', true),
  312.         elvui = LibStub:GetLibrary('LibActionButton-1.0-ElvUI', true),
  313.     }
  314.  
  315.     for _, lib in pairs(LAB) do
  316.         if lib and lib.GetAllButtons then
  317.             for button in pairs(lib:GetAllButtons()) do
  318.                 local spellId = button:GetSpellId();
  319.                 self:AddButton(spellId, button);
  320.             end
  321.         end
  322.     end
  323. end
  324.  
  325. function MaxDps:FetchBlizzard()
  326.     local BlizzardBars = {'Action', 'MultiBarBottomLeft', 'MultiBarBottomRight', 'MultiBarRight', 'MultiBarLeft'};
  327.     for _, barName in pairs(BlizzardBars) do
  328.         for i = 1, 12 do
  329.             local button = _G[barName .. 'Button' .. i];
  330.             self:AddStandardButton(button);
  331.         end
  332.     end
  333. end
  334.  
  335. function MaxDps:FetchG15Buttons()
  336.     local i = 2; -- it starts from 2
  337.     while true do
  338.         local button = _G['objG15_btn_' .. i];
  339.         if not button then
  340.             break;
  341.         end
  342.         i = i + 1;
  343.  
  344.         self:AddStandardButton(button);
  345.     end
  346. end
  347.  
  348. function MaxDps:FetchButtonForge()
  349.     local i = 1;
  350.     while true do
  351.         local button = _G['ButtonForge' .. i];
  352.         if not button then
  353.             break;
  354.         end
  355.         i = i + 1;
  356.  
  357.         MaxDps:AddStandardButton(button)
  358.     end
  359. end
  360.  
  361. function MaxDps:Dump()
  362.     for k, v in pairs(self.Spells) do
  363.         print(k);
  364.     end
  365. end
  366.  
  367. function MaxDps:FindSpell(spellId)
  368.     return self.Spells[spellId];
  369. end
  370.  
  371. function MaxDps:GlowIndependent(spellId, id, texture, color)
  372.     if self.Spells[spellId] ~= nil then
  373.         for k, button in pairs(self.Spells[spellId]) do
  374.             self:Glow(button, id, texture, 'cooldown', color);
  375.         end
  376.     end
  377. end
  378.  
  379. function MaxDps:ClearGlowIndependent(spellId, id)
  380.     if self.Spells[spellId] ~= nil then
  381.         for k, button in pairs(self.Spells[spellId]) do
  382.             self:HideGlow(button, id);
  383.         end
  384.     end
  385. end
  386.  
  387. function MaxDps:GlowCooldown(spellId, condition)
  388.     if self.Flags[spellId] == nil then
  389.         self.Flags[spellId] = false;
  390.     end
  391.     if condition and not self.Flags[spellId] then
  392.         self.Flags[spellId] = true;
  393.         self:GlowIndependent(spellId, spellId);
  394.     end
  395.     if not condition and self.Flags[spellId] then
  396.         self.Flags[spellId] = false;
  397.         self:ClearGlowIndependent(spellId, spellId);
  398.     end
  399. end
  400.  
  401. function MaxDps:GlowSpell(spellId)
  402.     if self.Spells[spellId] ~= nil then
  403.         for k, button in pairs(self.Spells[spellId]) do
  404.             self:Glow(button, 'next', nil, 'normal');
  405.         end
  406.  
  407.         self.SpellsGlowing[spellId] = 1;
  408.     else
  409.         local spellName = GetSpellInfo(spellId);
  410.         self:Print(self.Colors.Error .. 'Spell not found on action bars: ' .. spellName .. '(' .. spellId .. ')');
  411.     end
  412. end
  413.  
  414. function MaxDps:GlowNextSpell(spellId)
  415.     self:GlowClear();
  416.     self:GlowSpell(spellId);
  417. end
  418.  
  419. function MaxDps:GlowClear()
  420.     for spellId, v in pairs(self.SpellsGlowing) do
  421.         if v == 1 then
  422.             for k, button in pairs(self.Spells[spellId]) do
  423.                 self:HideGlow(button, 'next');
  424.             end
  425.             self.SpellsGlowing[spellId] = 0;
  426.         end
  427.     end
  428. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement