local _,ns = ...
local originalSetStatusBarTexture = PlayerCastingBarFrame.SetStatusBarTexture
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(20)			--施法条高度
	PlayerCastingBarFrame:SetWidth(280)			--施法条宽度
	PlayerCastingBarFrame.Spark:SetSize(2,45)		--施法条闪光大小
	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.ChargeTier1 then return end
		PlayerCastingBarFrame.ChargeTier1.Normal:SetVertexColor(1, 0, 0 ,1)
		PlayerCastingBarFrame.ChargeTier1.Disabled:SetVertexColor(1, 0, 0, 0.2)
		if not PlayerCastingBarFrame.ChargeTier2 then return end
		PlayerCastingBarFrame.ChargeTier2.Normal:SetVertexColor(0, 1, 0 ,1)
		PlayerCastingBarFrame.ChargeTier2.Disabled:SetVertexColor(0, 1, 0, 0.2)
		if not PlayerCastingBarFrame.ChargeTier3 then return end
		PlayerCastingBarFrame.ChargeTier3.Normal:SetVertexColor(1, 1, 0 ,1)
		PlayerCastingBarFrame.ChargeTier3.Disabled:SetVertexColor(1, 1, 0, 0.2)
		return
	end
	PlayerCastingBarFrame.SetStatusBarTexture = originalSetStatusBarTexture
	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 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)