local addonName, addon = ... local childName = addon['childName'] local child = addon[childName] local events = child['events'] local db local evframe = CreateFrame("FRAME") local function prepareDB() db = addon['db']['profile'][childName] child['db'] = db addon['callbacks']:Fire(format("Init%s", childName)) end child['specs'] = { ['name'] = childName, ['sv'] = true, ['cfg'] = true, ['cfgReset'] = prepareDB, ['ldb'] = child['ldb'], ['defaults'] = { ['profile'] = { [childName] = { ['spells'] = {}, ['clicks'] = {}, ['mouseButton'] = 1, ['modType'] = 1 } } } } local buffButtons = {'Buff1', 'Buff2', 'Buff3', 'Debuff1', 'Debuff2', 'Debuff3', 'DispelDebuff1', 'DispelDebuff2', 'DispelDebuff3'} ClickCastFrames = ClickCastFrames or {} local castFrames = ClickCastFrames local function unregisterAttrs(frame) if(InCombatLockdown()) then return end frame['attrs'] = frame['attrs'] or {} for key, value in pairs(frame['attrs']) do frame:SetAttribute(key, nil) frame['attrs'][key] = nil end end local function registerAttrs(frame, key, value) if(InCombatLockdown()) then evframe:RegisterEvent("PLAYER_REGEN_ENABLED") else frame['attrs'] = frame['attrs'] or {} frame['attrs'][key] = value frame:SetAttribute(key, value) end end local function buffButtonSwitch(frame, switch) local fName = frame:GetName() if(strsub(fName, 1, 7) == 'Compact') then for i = 1, #buffButtons do local buffBtn = _G[format("%s%s", fName, buffButtons[i])] if(buffBtn) then buffBtn:EnableMouse(switch) end end end end local function disableFrame(frame) if(InCombatLockdown()) then evframe:RegisterEvent("PLAYER_REGEN_ENABLED") return end if(frame and frame:GetName()) then buffButtonSwitch(frame, true) unregisterAttrs(frame) registerAttrs(frame, 'type', 'target') registerAttrs(frame, 'type2', 'togglemenu') castFrames[frame] = nil end end local function gettype(v, attr) local r = format("%s%i", attr, v['btn']) if(v['mod'] ~= 1) then r = format("%s-%s", v['modName'],r) end return r end local function regAtt(frame, v) registerAttrs(frame, gettype(v, 'harmbutton'), format("nuke%i",v['btn'])) registerAttrs(frame, gettype(v, 'helpbutton'), format("heal%i",v['btn'])) registerAttrs(frame, gettype(v, 'type-heal'), 'spell') registerAttrs(frame, gettype(v, 'type-nuke'), 'spell') registerAttrs(frame, gettype(v, 'spell-nuke'), v['spell']) registerAttrs(frame, gettype(v, 'spell-heal'), v['dualSpell'] and v['spellHeal'] or v['spell']) end local function enableFrame(frame, force) if(InCombatLockdown()) then evframe:RegisterEvent("PLAYER_REGEN_ENABLED") if(not force) then return end end if(frame['unit'] and strsub(frame['unit'], 1, 9) == 'nameplate') then -- print('nameplate ignored', frame['unit']) return end if(frame and frame:GetName()) then -- print("Register ".. frame:GetName()) -- disableFrame(frame) buffButtonSwitch(frame, false) frame:RegisterForClicks('AnyDown') for k,v in pairs(db['clicks']) do -- print(" Click", v) regAtt(frame, v) end castFrames[frame] = true end end local firstRun = true function child:enableAllFrames() local frames = { 'PlayerFrame', 'TargetFrame', 'TargetFrameToT', 'FocusFrame', 'FocusFrameToT','PetFrame', } for n = 1, 8 do for i = 1, 5 do if(n==1) then if(i<5) then frames[#frames + 1] = format("PartyMemberFrame%i",i) frames[#frames + 1] = format("PartyMemberFrame%iPetFrame",i) frames[#frames + 1] = format("Boss%iTargetFrame",i) end frames[#frames + 1] = format("CompactPartyFrameMember%i",i) end frames[#frames + 1] = format("CompactRaidGroup%iMember%i",n,i) end end for k,v in pairs(castFrames) do if(v) then local frame = k:GetName() local skip = false for n = 1, #frames do if(frames[n] == frame) then skip = true break end end if(not skip and frame) then frames[#frames + 1] = frame end end end for k,frame in ipairs(frames) do if(_G[frame]) then enableFrame(_G[frame], firstRun) else -- print('skip', frame) end end firstRun = false end local racialSpells = {} -- Beta returns the old names with C_AlliedRaces.GetAllRacialAbilitiesFromID(raceID) local function isRacialSpell(spellIcon) -- Replace spellIcon with spellName once the bug is fixed -- local name, rank, icon, castTime, minRange, maxRange, spellId = GetSpellInfo(spellName) -- print('start',spellIcon) for k, v in pairs(racialSpells) do -- local nameR, rankR, iconR, castTimeR, minRangeR, maxRangeR, spellIdR = GetSpellInfo(v) -- print(' check',v) if(v == spellIcon) then return true end end end local function buildRacialSpells() local raceName, raceFile, raceID = UnitRace('player') local res = C_AlliedRaces.GetAllRacialAbilitiesFromID(raceID) if(res) then for k, v in pairs(C_AlliedRaces.GetAllRacialAbilitiesFromID(raceID)) do if(type(v)=='table') then if(not IsPassiveSpell(v['name']) and not isRacialSpell(v['icon'])) then -- Replace icon with name once the bug is fixed racialSpells[#racialSpells+1] = v['icon'] -- Replace icon with name once the bug is fixed end end end end end function child:buildSpells(self) if(InCombatLockdown()) then evframe:RegisterEvent("PLAYER_REGEN_ENABLED") return end local currentSpec = GetSpecialization() if currentSpec then local classInfo = C_CreatureInfo.GetClassInfo(select(3,UnitClass('player'))) buildRacialSpells() local _, currentSpecName = GetSpecializationInfo(currentSpec) db['spells'] = {} for tabIndex = 1, GetNumSpellTabs() do local name, texture, offset, numEntries, isGuild, offspecID = GetSpellTabInfo(tabIndex) if(name == currentSpecName or name == classInfo['className'] or tabIndex==1) then if(offspecID==0) then for spellIndex = offset + 1, offset + numEntries do local skillType, special = GetSpellBookItemInfo(spellIndex, BOOKTYPE_SPELL) if(skillType=="SPELL" and not IsPassiveSpell(spellIndex, BOOKTYPE_SPELL)) then local spellName, spellSubName = GetSpellBookItemName(spellIndex, BOOKTYPE_SPELL) -- print(spellName,spellSubName,IsPassiveSpell(spellIndex, BOOKTYPE_SPELL), raceSpell) local _, _, icon = GetSpellInfo(spellName) if(not IsAttackSpell(spellName)) then if(spellSubName and spellSubName ~= "" and not isRacialSpell(icon)) then -- db['spells'][special] = format("%s (%s)",spellName, spellSubName) db['spells'][special] = spellName -- Fix when C_AlliedRaces.GetAllRacialAbilitiesFromID(raceID) returns a value else db['spells'][special] = spellName end end end end end end end end end function evframe:PLAYER_REGEN_ENABLED(event) self:UnregisterEvent(event) child:buildSpells() child:enableAllFrames() end function events:SPELLS_CHANGED() if(InCombatLockdown()) then evframe:RegisterEvent("PLAYER_REGEN_ENABLED") return end child:buildSpells() child:enableAllFrames() end function events:PLAYER_ENTERING_WORLD(_, event) evframe:UnregisterEvent(event) end function events:GROUP_ROSTER_UPDATE() child:buildSpells() child:enableAllFrames() end function events:RAID_ROSTER_UPDATE() child:buildSpells() child:enableAllFrames() end function events:ADDON_LOADED(_, event, name) if(name == childName) then child:enableAllFrames() child:UnregisterEvent(event) end end evframe:SetScript("OnEvent" , function(self, event) evframe[event](self, event) end) hooksecurefunc("CompactUnitFrame_SetUnit", function(self, unit) if(InCombatLockdown()) then evframe:RegisterEvent("PLAYER_REGEN_ENABLED") return end if(unit and not castFrames[self]) then enableFrame(self,firstRun) end end) child:NewAddOn(...)