Try replacing:
Code:
local isCaster
local cbCheckFrame = CreateFrame("Frame")
cbCheckFrame:RegisterEvent("PLAYER_LOGIN")
cbCheckFrame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
cbCheckFrame:SetScript("OnEvent", function()
if playerClass == 'DRUID' then
isCaster = (GetSpecialization() or 0) % 3 == 1
elseif playerClass == 'MONK' then
isCaster = GetSpecialization() == 2
elseif playerClass == 'PALADIN' then
isCaster = GetSpecialization() == 1
elseif playerClass == 'SHAMAN' then
isCaster = GetSpecialization() ~= 2
else
isCaster = playerClass == 'MAGE' or playerClass == 'PRIEST' or playerClass == 'WARLOCK'
end
print(isCaster)
end)
with:
Code:
local detectTalentChange = CreateFrame('Frame')
detectTalentChange:SetScript('OnEvent', function(self)
if not self.unitFrame then return end
local isCaster
if playerClass == 'DRUID' then
isCaster = (GetSpecialization() or 0) % 3 == 1
elseif playerClass == 'MONK' then
isCaster = GetSpecialization() == 2
elseif playerClass == 'PALADIN' then
isCaster = GetSpecialization() == 1
elseif playerClass == 'SHAMAN' then
isCaster = GetSpecialization() ~= 2
else
isCaster = playerClass == 'MAGE' or playerClass == 'PRIEST' or playerClass == 'WARLOCK'
self:UnregisterAllEvents()
self:SetScript('OnEvent', nil)
end
if isCaster ~= self.isCaster then
self.isCaster = isCaster
local Castbar = self.unitFrame.Castbar
Castbar:ClearAllPoints()
if isCaster then
Castbar:SetPoint('TOP', self.unitFrame, 'BOTTOM', 0, -68)
Castbar:SetStatusBarColor(1, 1, 1)
Castbar:SetSize(barWidth, 4)
Castbar:SetBackdrop(backdrop)
Castbar:SetBackdropColor(0, 0, 0)
if Castbar.Spark then
Castbar.Spark:Hide()
end
else
Castbar:SetAllPoints(self.unitFrame.Health)
Castbar:SetStatusBarColor(1, 1, 1, 0.5)
Castbar:SetBackdrop(nil)
if not Castbar.Spark then
local Spark = Castbar:CreateTexture(nil, 'OVERLAY')
Spark:SetSize(2, 7)
Spark:SetTexture(1, 1, 1)
Castbar.Spark = Spark
end
Castbar.Spark:Show()
end
end
end)
detectTalentChange:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED')
detectTalentChange:RegisterEvent('PLAYER_LOGIN')
And change the Castbar portion of your Shared function to:
Code:
if(unit=='player' or unit=='target') then
local Castbar = CreateFrame('StatusBar', nil, self)
Castbar:SetStatusBarTexture(statusBar)
Castbar:SetFrameStrata('HIGH')
self.Castbar = Castbar
if(unit=='player') then
detectTalentChange.unitFrame = self
else
Castbar:SetPoint('BOTTOM', UIParent, 'CENTER', 0, 200)
Castbar:SetStatusBarColor(1, 0, 0)
Castbar:SetBackdrop(backdrop)
Castbar:SetBackdropColor(0, 0, 0)
Castbar:SetSize(350, 24)
local Time = Castbar:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
Time:SetFont(nameFont, nameFontSize, 'OUTLINE')
Time:SetTextColor(1, 1, 1)
Time:SetPoint('RIGHT', Castbar)
Castbar.Time = Time
local Text = Castbar:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
Text:SetFont(nameFont, nameFontSize, 'OUTLINE')
Text:SetTextColor(1, 1, 1)
Text:SetPoint('LEFT', Castbar, 'LEFT', 4, 0)
Castbar.Text = Text
local Icon = Castbar:CreateTexture(nil, 'OVERLAY')
Icon:SetSize(24, 24)
Icon:SetPoint('RIGHT', Castbar, 'LEFT', -6, 0)
Castbar.Icon = Icon
local Shield = Castbar:CreateTexture(nil, 'OVERLAY')
Shield:SetSize(64, 64)
Shield:SetPoint('CENTER', Icon, 'CENTER', 12, 0)
Shield:SetTexture([[Interface\CastingBar\UI-CastingBar-Arena-Shield]])
Castbar.Shield = Shield
end
end
The code is untested but is headed in the right direction. It uses the correct event to detect spec changes and can actually change your Castbar when they occur. One issue I'm not sure on is what oUF does with Castbar.Spark behind the scenes and if just hiding/showing it will be sufficient. This code assumes that your unit frames are created before the PLAYER_LOGIN event occurs, if this is not the case then it will need to be adjusted accordingly.