local _,ns = ...
SetCVar("ShakeStrengthUI",1)
--------------施法条-------------
local castevent =CreateFrame("frame")
castevent:RegisterEvent('UNIT_SPELLCAST_EMPOWER_START')	--蓄力
castevent:RegisterEvent('UNIT_SPELLCAST_CHANNEL_START')	--引导
castevent:RegisterEvent('UNIT_SPELLCAST_START')	--读条
castevent:SetScript("OnEvent",function (_,event,castunit)
	if not AddUIDB.cast then return end
	if castunit ~= "player"  then return end	--判断是不是自己的施法条

	-------------------------------------
	--自身施法条修改
	PlayerCastingBarFrame:SetHeight(AddUIDB.castHeight)			--施法条高度
	PlayerCastingBarFrame:SetWidth(AddUIDB.castWidth)			--施法条宽度
	PlayerCastingBarFrame.Spark:SetSize(2,33)		--施法条闪光大小
	PlayerCastingBarFrame.Icon:Show()				--施法条图标显示
	PlayerCastingBarFrame.Icon:SetSize(22,22)		--施法条图标大小
	PlayerCastingBarFrame.TextBorder:SetTexture(nil)	--文字框大背景
	PlayerCastingBarFrame.Border:SetTexture(nil)	--施法条边框
	PlayerCastingBarFrame.BorderShield:SetTexture(nil)	--不知道是什么鬼
	PlayerCastingBarFrame.BorderMask:SetTexture(nil)	--施法闪光尾迹
	PlayerCastingBarFrame:SetFrameStrata("TOOLTIP")	--施法条框架优先级
	PlayerCastingBarFrame.Text:ClearAllPoints()
	PlayerCastingBarFrame.Text:SetPoint("CENTER",PlayerCastingBarFrame,"CENTER",0,0)

	if not AddUIDB.SCastTexture then return end
	PlayerCastingBarFrame.Background:SetPoint("TOPLEFT",0,0)
	PlayerCastingBarFrame.Background:SetPoint("BOTTOMRIGHT",0,0)
	--PlayerCastingBarFrame.Flash.Show= PlayerCastingBarFrame.Flash.Hide
	--PlayerCastingBarFrame.InterruptShakeAnim.Play = PlayerCastingBarFrame.InterruptShakeAnim.Stop
	--PlayerCastingBarFrame.InterruptSparkAnim.Play = PlayerCastingBarFrame.InterruptSparkAnim.Stop
	PlayerCastingBarFrame.InterruptGlowAnim.Play = PlayerCastingBarFrame.InterruptGlowAnim.Stop--打断填充
	PlayerCastingBarFrame.FlashAnim.Play = PlayerCastingBarFrame.FlashAnim.Stop	--结束
	PlayerCastingBarFrame.StageFinish.Play = PlayerCastingBarFrame.StageFinish.Stop--最后蓄力
	PlayerCastingBarFrame.Background:SetTexture(130937)
	PlayerCastingBarFrame.Background:SetColorTexture(0,0,0,.5)
	
	
	if event == 'UNIT_SPELLCAST_EMPOWER_START' then 
		if not PlayerCastingBarFrame.ChargeTierPool.ChargeTier1 then return end
		PlayerCastingBarFrame.ChargeTierPool.ChargeTier1.Normal:SetVertexColor(1, 0, 0 )
		PlayerCastingBarFrame.ChargeTierPool.ChargeTier1.Disabled:SetVertexColor(1, 0, 0)
		PlayerCastingBarFrame.ChargeTierPool.ChargeTier1.Glow:SetVertexColor(1, 0, 0)
		if not PlayerCastingBarFrame.ChargeTierPool.ChargeTier2 then return end
		PlayerCastingBarFrame.ChargeTierPool.ChargeTier2.Normal:SetVertexColor(0, 1, 0)
		PlayerCastingBarFrame.ChargeTierPool.ChargeTier2.Disabled:SetVertexColor(0, 1, 0)
		PlayerCastingBarFrame.ChargeTierPool.ChargeTier2.Glow:SetVertexColor(0, 1, 0)
		if not PlayerCastingBarFrame.ChargeTierPool.ChargeTier2 then return end
		PlayerCastingBarFrame.ChargeTierPool.ChargeTier3.Normal:SetVertexColor(1, 1, 0)
		PlayerCastingBarFrame.ChargeTierPool.ChargeTier3.Disabled:SetVertexColor(1, 1, 0)
		PlayerCastingBarFrame.ChargeTierPool.ChargeTier3.Glow:SetVertexColor(1, 1, 0)
		return
	end
	PlayerCastingBarFrame.SetStatusBarTexture = ns.PS
	if AddUIDB.CastTexture == "随机使用材质" then
		PlayerCastingBarFrame:SetStatusBarTexture(ns.CastBarTextrue[ns.RerollTextrue[math.random(1, #ns.RerollTextrue)]])
	else
		PlayerCastingBarFrame:SetStatusBarTexture(ns.CastBarTextrue[AddUIDB.CastTexture])
	end

	PlayerCastingBarFrame.SetStatusBarTexture = ns.ADDUISET
end)
--施法条计时
local function ShowMyCasting(self)
if not AddUIDB.cast then return end
if not self.maxValue or ns.MM(self.maxValue) then return end
if not self.Cooldown  then
	self.Cooldown = self:CreateFontString(nil)
    self.Cooldown:SetFont(SystemFont_Outline_Small:GetFont(), 16, "OUTLINE")	--施法时间文字大小
    self.Cooldown:SetJustifyH("RIGHT")
    self.Cooldown:SetPoint("RIGHT", self, "RIGHT", 0, 0)
elseif self.maxValue-self.value < 0 then
	self.Cooldown:SetText(" ")
elseif UnitCastingInfo(self.unit) then
	self.Cooldown:SetText(format("%.1f/%.1f",self.maxValue-self.value,self.maxValue))
elseif UnitChannelInfo(self.unit) then
	self.Cooldown:SetText(format("%.1f",self.value,0))
else
	self.Cooldown:SetText(" ")
end
end
PlayerCastingBarFrame:HookScript("OnUpdate", ShowMyCasting)