CastBar.lua 15.6 KB
Newer Older
Azilroka's avatar
Azilroka committed
1
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
2
local UF = E:GetModule('UnitFrames');
Caedis's avatar
Caedis committed
3
local LSM = E.Libs.LSM
4

Simpy's avatar
Simpy committed
5
local unpack, tonumber, abs = unpack, tonumber, abs
Simpy's avatar
nothing  
Simpy committed
6

Simpy's avatar
stuff  
Simpy committed
7
local CreateFrame = CreateFrame
8 9 10 11 12
local UnitSpellHaste = UnitSpellHaste
local UnitIsPlayer = UnitIsPlayer
local UnitClass = UnitClass
local UnitReaction = UnitReaction
local UnitCanAttack = UnitCanAttack
13
local GetTalentInfo = GetTalentInfo
14 15 16

local _, ns = ...
local ElvUF = ns.oUF
Simpy's avatar
Simpy committed
17
assert(ElvUF, 'ElvUI was unable to locate oUF.')
18 19 20 21 22 23 24 25 26 27 28 29 30

local INVERT_ANCHORPOINT = {
	TOPLEFT = 'BOTTOMRIGHT',
	LEFT = 'RIGHT',
	BOTTOMLEFT = 'TOPRIGHT',
	RIGHT = 'LEFT',
	TOPRIGHT = 'BOTTOMLEFT',
	BOTTOMRIGHT = 'TOPLEFT',
	CENTER = 'CENTER',
	TOP = 'BOTTOM',
	BOTTOM = 'TOP',
}

31
local ticks = {}
32

33
function UF:Construct_Castbar(frame, moverName)
Simpy's avatar
Simpy committed
34
	local castbar = CreateFrame('StatusBar', '$parent_CastBar', frame, 'BackdropTemplate')
35
	castbar:SetFrameLevel(frame.RaisedElementParent:GetFrameLevel() + 30) --Make it appear above everything else
36 37 38 39 40 41 42
	UF.statusbars[castbar] = true
	castbar.CustomDelayText = UF.CustomCastDelayText
	castbar.CustomTimeText = UF.CustomTimeText
	castbar.PostCastStart = UF.PostCastStart
	castbar.PostCastStop = UF.PostCastStop
	castbar.PostCastInterruptible = UF.PostCastInterruptible
	castbar.PostCastFail = UF.PostCastFail
43
	castbar:SetClampedToScreen(true)
44
	castbar:CreateBackdrop(nil, nil, nil, nil, true)
45 46

	castbar.Time = castbar:CreateFontString(nil, 'OVERLAY')
Simpy's avatar
Simpy committed
47
	castbar.Time:Point('RIGHT', castbar, 'RIGHT', -4, 0)
48
	castbar.Time:SetTextColor(0.84, 0.75, 0.65)
Simpy's avatar
Simpy committed
49
	castbar.Time:SetJustifyH('RIGHT')
50 51

	castbar.Text = castbar:CreateFontString(nil, 'OVERLAY')
Simpy's avatar
Simpy committed
52 53
	castbar.Text:Point('LEFT', castbar, 'LEFT', 4, 0)
	castbar.Text:Point('RIGHT', castbar.Time, 'LEFT', -4, 0)
54
	castbar.Text:SetTextColor(0.84, 0.75, 0.65)
Simpy's avatar
Simpy committed
55
	castbar.Text:SetJustifyH('LEFT')
56 57
	castbar.Text:SetWordWrap(false)

58
	castbar.Spark_ = castbar:CreateTexture(nil, 'OVERLAY')
Azilroka's avatar
Azilroka committed
59
	castbar.Spark_:SetTexture([[Interface\CastingBar\UI-CastingBar-Spark]])
60 61
	castbar.Spark_:SetBlendMode('ADD')
	castbar.Spark_:SetVertexColor(1, 1, 1)
Simpy's avatar
Simpy committed
62
	castbar.Spark_:Size(20, 40)
63 64

	--Set to castbar.SafeZone
Simpy's avatar
Simpy committed
65
	castbar.LatencyTexture = castbar:CreateTexture(nil, 'OVERLAY')
Simpy's avatar
Simpy committed
66
	castbar.LatencyTexture:SetTexture(E.media.blankTex)
67 68 69
	castbar.LatencyTexture:SetVertexColor(0.69, 0.31, 0.31, 0.75)

	castbar.bg = castbar:CreateTexture(nil, 'BORDER')
Simpy's avatar
Simpy committed
70 71
	castbar.bg:SetAllPoints()
	castbar.bg:SetTexture(E.media.blankTex)
72
	castbar.bg:Show()
73

Simpy's avatar
Simpy committed
74
	local button = CreateFrame('Frame', nil, castbar, 'BackdropTemplate')
75
	local holder = CreateFrame('Frame', nil, castbar)
76
	button:SetTemplate(nil, nil, nil, nil, true)
77 78 79

	castbar.Holder = holder
	--these are placeholder so the mover can be created.. it will be changed.
80 81 82
	castbar.Holder:Point('TOPLEFT', frame, 'BOTTOMLEFT', 0, -(UF.BORDER - UF.SPACING))
	castbar:Point('BOTTOMLEFT', castbar.Holder, 'BOTTOMLEFT', UF.BORDER, UF.BORDER)
	button:Point('RIGHT', castbar, 'LEFT', -UF.SPACING*3, 0)
83 84

	if moverName then
85 86
		local name = frame:GetName()
		local configName = name:gsub('^ElvUF_', ''):lower()
87
		E:CreateMover(castbar.Holder, name..'CastbarMover', moverName, nil, -6, nil, 'ALL,SOLO', nil, 'unitframe,individualUnits,'..configName..',castbar')
88 89
	end

Simpy's avatar
Simpy committed
90
	local icon = button:CreateTexture(nil, 'ARTWORK')
91
	icon:SetInside(nil, UF.BORDER, UF.BORDER)
92 93 94 95 96 97 98 99 100 101
	icon.bg = button

	--Set to castbar.Icon
	castbar.ButtonIcon = icon

	return castbar
end

function UF:Configure_Castbar(frame)
	local castbar = frame.Castbar
Simpy's avatar
Simpy committed
102 103
	local db = frame.db.castbar

104 105
	castbar:Width(db.width - ((UF.BORDER+UF.SPACING)*2))
	castbar:Height(db.height - ((UF.BORDER+UF.SPACING)*2))
Simpy's avatar
Simpy committed
106
	castbar.Holder:Size(db.width, db.height)
Simpy's avatar
nothin'  
Simpy committed
107 108 109

	local oSC = castbar.Holder:GetScript('OnSizeChanged')
	if oSC then oSC(castbar.Holder) end
110

Simpy's avatar
Simpy committed
111 112
	if db.strataAndLevel and db.strataAndLevel.useCustomStrata then
		castbar:SetFrameStrata(db.strataAndLevel.frameStrata)
113 114
	end

Simpy's avatar
Simpy committed
115 116
	if db.strataAndLevel and db.strataAndLevel.useCustomLevel then
		castbar:SetFrameLevel(db.strataAndLevel.frameLevel)
117 118
	end

Simpy's avatar
Simpy committed
119
	castbar.timeToHold = db.timeToHold
Azilroka's avatar
Azilroka committed
120

121 122
	castbar:SetReverseFill(db.reverse)

123
	--Latency
Simpy's avatar
Simpy committed
124
	if frame.unit == 'player' and db.latency then
125 126 127 128 129 130 131
		castbar.SafeZone = castbar.LatencyTexture
		castbar.LatencyTexture:Show()
	else
		castbar.SafeZone = nil
		castbar.LatencyTexture:Hide()
	end

Caedis's avatar
Caedis committed
132
	--Font Options
Caedis's avatar
Caedis committed
133 134 135
	local customFont = db.customTextFont
	if customFont.enable then
		castbar.Text:FontTemplate(LSM:Fetch('font', customFont.font), customFont.fontSize, customFont.fontStyle)
Caedis's avatar
Caedis committed
136
	else
Caedis's avatar
Caedis committed
137
		UF:Update_FontString(castbar.Text)
Caedis's avatar
Caedis committed
138 139
	end

Caedis's avatar
Caedis committed
140 141 142
	customFont = db.customTimeFont
	if customFont.enable then
		castbar.Time:FontTemplate(LSM:Fetch('font', customFont.font), customFont.fontSize, customFont.fontStyle)
Caedis's avatar
Caedis committed
143
	else
Caedis's avatar
Caedis committed
144
		UF:Update_FontString(castbar.Time)
Caedis's avatar
Caedis committed
145
	end
146

Simpy's avatar
Simpy committed
147
	local textColor = db.textColor
148 149 150
	castbar.Text:SetTextColor(textColor.r, textColor.g, textColor.b)
	castbar.Time:SetTextColor(textColor.r, textColor.g, textColor.b)

Simpy's avatar
Simpy committed
151 152
	castbar.Text:Point('LEFT', castbar, 'LEFT', db.xOffsetText, db.yOffsetText)
	castbar.Time:Point('RIGHT', castbar, 'RIGHT', db.xOffsetTime, db.yOffsetTime)
153

154
	--Icon
Simpy's avatar
Simpy committed
155
	if db.icon then
156
		castbar.Icon = castbar.ButtonIcon
157 158
		castbar.Icon:SetTexCoord(unpack(E.TexCoords))

Simpy's avatar
:broom:  
Simpy committed
159
		if not db.iconAttached then
Simpy's avatar
Simpy committed
160
			castbar.Icon.bg:Size(db.iconSize)
161
		else
162 163
			castbar.Icon.bg:Size(db.height-UF.SPACING*2)
			castbar:Width(db.width - castbar.Icon.bg:GetWidth() - (UF.BORDER + UF.SPACING*5))
164 165 166 167 168 169 170 171
		end

		castbar.Icon.bg:Show()
	else
		castbar.ButtonIcon.bg:Hide()
		castbar.Icon = nil
	end

Simpy's avatar
Simpy committed
172
	if db.spark then
Merathilis's avatar
Merathilis committed
173
		castbar.Spark = castbar.Spark_
Simpy's avatar
Simpy committed
174
		castbar.Spark:Point('CENTER', castbar:GetStatusBarTexture(), db.reverse and 'LEFT' or 'RIGHT', 0, 0)
Simpy's avatar
Simpy committed
175
		castbar.Spark:Height(db.height * 2)
Azilroka's avatar
Azilroka committed
176 177
	elseif castbar.Spark then
		castbar.Spark:Hide()
178
		castbar.Spark = nil
179 180
	end

Simpy's avatar
Simpy committed
181
	if db.hidetext then
Merathilis's avatar
Merathilis committed
182 183 184 185 186 187 188
		castbar.Text:SetAlpha(0)
		castbar.Time:SetAlpha(0)
	else
		castbar.Text:SetAlpha(1)
		castbar.Time:SetAlpha(1)
	end

189
	castbar:ClearAllPoints()
190

Simpy's avatar
Simpy committed
191 192
	if db.overlayOnFrame ~= 'None' then
		local anchor = frame[db.overlayOnFrame]
193

Simpy's avatar
:broom:  
Simpy committed
194
		if not db.iconAttached then
195
			castbar:SetInside(anchor, 0, 0)
196
		else
Azilroka's avatar
Azilroka committed
197
			if castbar.Icon then
198
				castbar.Icon.bg:Size(anchor:GetHeight() - UF.SPACING*2)
Azilroka's avatar
Azilroka committed
199 200
			end

201
			local iconWidth = db.icon and (castbar.Icon.bg:GetWidth() - UF.BORDER) or 0
Simpy's avatar
Simpy committed
202
			if frame.ORIENTATION == 'RIGHT' then
Simpy's avatar
Simpy committed
203
				castbar:Point('TOPLEFT', anchor, 'TOPLEFT')
204
				castbar:Point('BOTTOMRIGHT', anchor, 'BOTTOMRIGHT', -iconWidth - UF.SPACING*3, 0)
205
			else
206
				castbar:Point('TOPLEFT', anchor, 'TOPLEFT',  iconWidth + UF.SPACING*3, 0)
Simpy's avatar
Simpy committed
207
				castbar:Point('BOTTOMRIGHT', anchor, 'BOTTOMRIGHT')
208 209 210
			end
		end

Simpy's avatar
Simpy committed
211
		if db.spark then
Simpy's avatar
Simpy committed
212
			castbar.Spark:Height(anchor:GetHeight() * 2)
Merathilis's avatar
whoops  
Merathilis committed
213
		end
214
	else
Azilroka's avatar
Azilroka committed
215 216
		if db.positionsGroup then
			castbar.Holder:ClearAllPoints()
Simpy's avatar
Simpy committed
217
			castbar.Holder:Point(INVERT_ANCHORPOINT[db.positionsGroup.anchorPoint], frame, db.positionsGroup.anchorPoint, db.positionsGroup.xOffset, db.positionsGroup.yOffset)
Azilroka's avatar
Azilroka committed
218 219
		end

Simpy's avatar
Simpy committed
220
		if frame.ORIENTATION ~= 'RIGHT' then
221
			castbar:Point('BOTTOMRIGHT', castbar.Holder, 'BOTTOMRIGHT', -(UF.BORDER+UF.SPACING), UF.BORDER+UF.SPACING)
222
		else
223
			castbar:Point('BOTTOMLEFT', castbar.Holder, 'BOTTOMLEFT', UF.BORDER+UF.SPACING, UF.BORDER+UF.SPACING)
224 225 226
		end
	end

Simpy's avatar
Simpy committed
227
	if not db.iconAttached and db.icon then
Simpy's avatar
Simpy committed
228
		local attachPoint = db.iconAttachedTo == 'Frame' and frame or frame.Castbar
Simpy's avatar
Simpy committed
229
		local anchorPoint = db.iconPosition
230
		castbar.Icon.bg:ClearAllPoints()
Simpy's avatar
Simpy committed
231
		castbar.Icon.bg:Point(INVERT_ANCHORPOINT[anchorPoint], attachPoint, anchorPoint, db.iconXOffset, db.iconYOffset)
Simpy's avatar
:broom:  
Simpy committed
232
	elseif db.icon then
233
		castbar.Icon.bg:ClearAllPoints()
Simpy's avatar
Simpy committed
234
		if frame.ORIENTATION == 'RIGHT' then
235
			castbar.Icon.bg:Point('LEFT', castbar, 'RIGHT', UF.SPACING*3, 0)
236
		else
237
			castbar.Icon.bg:Point('RIGHT', castbar, 'LEFT', -UF.SPACING*3, 0)
238 239 240
		end
	end

241
	--Adjust tick heights
242
	castbar.tickHeight = castbar:GetHeight()
Rubgrsch's avatar
Rubgrsch committed
243

Simpy's avatar
Simpy committed
244
	if db.ticks then --Only player unitframe has this
Blazeflack's avatar
Blazeflack committed
245
		--Set tick width and color
Simpy's avatar
Simpy committed
246 247
		castbar.tickWidth = db.tickWidth
		castbar.tickColor = db.tickColor
Rubgrsch's avatar
Rubgrsch committed
248

249 250
		for i = 1, #ticks do
			ticks[i]:SetVertexColor(castbar.tickColor.r, castbar.tickColor.g, castbar.tickColor.b, castbar.tickColor.a)
Simpy's avatar
Simpy committed
251
			ticks[i]:Width(castbar.tickWidth)
252
		end
253
	end
254

255
	castbar.custom_backdrop = UF.db.colors.customcastbarbackdrop and UF.db.colors.castbar_backdrop
256
	UF:ToggleTransparentStatusBar(UF.db.colors.transparentCastbar, castbar, castbar.bg, nil, UF.db.colors.invertCastbar)
Simpy's avatar
Simpy committed
257

258
	if castbar.Holder.mover then
Simpy's avatar
Simpy committed
259
		if db.overlayOnFrame ~= 'None' or not db.enable then
260
			E:DisableMover(castbar.Holder.mover:GetName())
Simpy's avatar
Simpy committed
261 262
		else
			E:EnableMover(castbar.Holder.mover:GetName())
263 264 265
		end
	end

Simpy's avatar
Simpy committed
266
	if db.enable and not frame:IsElementEnabled('Castbar') then
267
		frame:EnableElement('Castbar')
Simpy's avatar
Simpy committed
268
	elseif not db.enable and frame:IsElementEnabled('Castbar') then
269 270 271 272 273 274
		frame:DisableElement('Castbar')
	end
end

function UF:CustomCastDelayText(duration)
	local db = self:GetParent().db
Simpy's avatar
Simpy committed
275
	if not (db and db.castbar) then return end
Rubgrsch's avatar
Rubgrsch committed
276
	db = db.castbar.format
277 278

	if self.channeling then
Rubgrsch's avatar
Rubgrsch committed
279
		if db == 'CURRENT' then
Simpy's avatar
Simpy committed
280
			self.Time:SetFormattedText('%.1f |cffaf5050%.1f|r', abs(duration - self.max), self.delay)
Rubgrsch's avatar
Rubgrsch committed
281
		elseif db == 'CURRENTMAX' then
Simpy's avatar
Simpy committed
282
			self.Time:SetFormattedText('%.1f / %.1f |cffaf5050%.1f|r', duration, self.max, self.delay)
Rubgrsch's avatar
Rubgrsch committed
283
		elseif db == 'REMAINING' then
Simpy's avatar
Simpy committed
284
			self.Time:SetFormattedText('%.1f |cffaf5050%.1f|r', duration, self.delay)
Rubgrsch's avatar
Rubgrsch committed
285
		elseif db == 'REMAININGMAX' then
Simpy's avatar
Simpy committed
286
			self.Time:SetFormattedText('%.1f / %.1f |cffaf5050%.1f|r', abs(duration - self.max), self.max, self.delay)
287 288
		end
	else
Rubgrsch's avatar
Rubgrsch committed
289
		if db == 'CURRENT' then
Simpy's avatar
Simpy committed
290
			self.Time:SetFormattedText('%.1f |cffaf5050%s %.1f|r', duration, '+', self.delay)
Rubgrsch's avatar
Rubgrsch committed
291
		elseif db == 'CURRENTMAX' then
Simpy's avatar
Simpy committed
292
			self.Time:SetFormattedText('%.1f / %.1f |cffaf5050%s %.1f|r', duration, self.max, '+', self.delay)
Rubgrsch's avatar
Rubgrsch committed
293
		elseif db == 'REMAINING' then
Simpy's avatar
Simpy committed
294
			self.Time:SetFormattedText('%.1f |cffaf5050%s %.1f|r', abs(duration - self.max), '+', self.delay)
Rubgrsch's avatar
Rubgrsch committed
295
		elseif db == 'REMAININGMAX' then
Simpy's avatar
Simpy committed
296
			self.Time:SetFormattedText('%.1f / %.1f |cffaf5050%s %.1f|r', abs(duration - self.max), self.max, '+', self.delay)
297 298
		end
	end
299

Simpy's avatar
Simpy committed
300
	self.Time:Width(self.Time:GetStringWidth())
301 302 303 304
end

function UF:CustomTimeText(duration)
	local db = self:GetParent().db
Simpy's avatar
Simpy committed
305
	if not (db and db.castbar) then return end
Rubgrsch's avatar
Rubgrsch committed
306
	db = db.castbar.format
307 308

	if self.channeling then
Rubgrsch's avatar
Rubgrsch committed
309
		if db == 'CURRENT' then
Simpy's avatar
Simpy committed
310
			self.Time:SetFormattedText('%.1f', abs(duration - self.max))
Rubgrsch's avatar
Rubgrsch committed
311
		elseif db == 'CURRENTMAX' then
Simpy's avatar
Simpy committed
312
			self.Time:SetFormattedText('%.1f / %.1f', abs(duration - self.max), self.max)
Rubgrsch's avatar
Rubgrsch committed
313
		elseif db == 'REMAINING' then
Simpy's avatar
Simpy committed
314
			self.Time:SetFormattedText('%.1f', duration)
Rubgrsch's avatar
Rubgrsch committed
315
		elseif db == 'REMAININGMAX' then
Simpy's avatar
Simpy committed
316
			self.Time:SetFormattedText('%.1f / %.1f', duration, self.max)
317 318
		end
	else
Rubgrsch's avatar
Rubgrsch committed
319
		if db == 'CURRENT' then
Simpy's avatar
Simpy committed
320
			self.Time:SetFormattedText('%.1f', duration)
Rubgrsch's avatar
Rubgrsch committed
321
		elseif db == 'CURRENTMAX' then
Simpy's avatar
Simpy committed
322
			self.Time:SetFormattedText('%.1f / %.1f', duration, self.max)
Rubgrsch's avatar
Rubgrsch committed
323
		elseif db == 'REMAINING' then
Simpy's avatar
Simpy committed
324
			self.Time:SetFormattedText('%.1f', abs(duration - self.max))
Rubgrsch's avatar
Rubgrsch committed
325
		elseif db == 'REMAININGMAX' then
Simpy's avatar
Simpy committed
326
			self.Time:SetFormattedText('%.1f / %.1f', abs(duration - self.max), self.max)
327 328
		end
	end
329

Simpy's avatar
Simpy committed
330
	self.Time:Width(self.Time:GetStringWidth())
331 332 333 334 335 336 337 338 339 340 341
end

function UF:HideTicks()
	for i=1, #ticks do
		ticks[i]:Hide()
	end
end

function UF:SetCastTicks(frame, numTicks, extraTickRatio)
	extraTickRatio = extraTickRatio or 0
	UF:HideTicks()
342 343 344

	if numTicks and numTicks <= 0 then return end

345 346
	local w = frame:GetWidth()
	local d = w / (numTicks + extraTickRatio)
347 348

	for i = 1, numTicks - 1 do
349 350
		if not ticks[i] then
			ticks[i] = frame:CreateTexture(nil, 'OVERLAY')
Simpy's avatar
Simpy committed
351
			ticks[i]:SetTexture(E.media.normTex)
352
			ticks[i]:SetVertexColor(frame.tickColor.r, frame.tickColor.g, frame.tickColor.b, frame.tickColor.a)
Simpy's avatar
Simpy committed
353
			ticks[i]:Width(frame.tickWidth)
354 355 356
		end

		ticks[i]:ClearAllPoints()
Simpy's avatar
Simpy committed
357 358
		ticks[i]:Point('RIGHT', frame, 'LEFT', d * i, 0)
		ticks[i]:Height(frame.tickHeight)
359 360 361 362
		ticks[i]:Show()
	end
end

363 364 365 366 367
function UF:GetTalentTicks(info)
	local _, _, _, selected = GetTalentInfo(info.tier, info.column, 1)
	return selected and info.ticks
end

Azilroka's avatar
Azilroka committed
368
function UF:PostCastStart(unit)
369 370 371
	local db = self:GetParent().db
	if not db or not db.castbar then return; end

Simpy's avatar
Simpy committed
372
	if unit == 'vehicle' then unit = 'player' end
373

374 375
	self.unit = unit

376
	if db.castbar.displayTarget and self.curTarget then
377
		self.Text:SetText(self.spellName..' > '..self.curTarget)
378 379
	end

Simpy's avatar
Simpy committed
380
	if self.channeling and db.castbar.ticks and unit == 'player' then
381
		local unitframe = E.global.unitframe
Azilroka's avatar
Azilroka committed
382
		local baseTicks = unitframe.ChannelTicks[self.spellID]
383 384 385 386 387 388 389 390 391 392
		local ticksSize = baseTicks and unitframe.ChannelTicksSize[self.spellID]
		local hasteTicks = ticksSize and unitframe.HastedChannelTicks[self.spellID]
		local talentTicks = baseTicks and unitframe.TalentChannelTicks[self.spellID]

		-- Separate group, so they can be effected by haste or size if needed
		if talentTicks then
			local selectedTicks = UF:GetTalentTicks(talentTicks)
			if selectedTicks then
				baseTicks = selectedTicks
			end
393 394
		end

Simpy's avatar
Simpy committed
395
		-- hasteTicks require a tickSize
396
		if hasteTicks then
397
			local tickIncRate = 1 / baseTicks
Simpy's avatar
Simpy committed
398
			local curHaste = UnitSpellHaste('player') * 0.01
399 400 401 402 403 404 405 406 407 408 409 410 411 412
			local firstTickInc = tickIncRate / 2
			local bonusTicks = 0
			if curHaste >= firstTickInc then
				bonusTicks = bonusTicks + 1
			end

			local x = tonumber(E:Round(firstTickInc + tickIncRate, 2))
			while curHaste >= x do
				x = tonumber(E:Round(firstTickInc + (tickIncRate * bonusTicks), 2))
				if curHaste >= x then
					bonusTicks = bonusTicks + 1
				end
			end

413
			local baseTickSize = ticksSize
414 415
			local hastedTickSize = baseTickSize / (1 + curHaste)
			local extraTick = self.max - hastedTickSize * (baseTicks + bonusTicks)
Azilroka's avatar
Azilroka committed
416 417 418
			local extraTickRatio = extraTick / hastedTickSize
			UF:SetCastTicks(self, baseTicks + bonusTicks, extraTickRatio)
			self.hadTicks = true
419
		elseif ticksSize then
Simpy's avatar
Simpy committed
420
			local curHaste = UnitSpellHaste('player') * 0.01
421
			local baseTickSize = ticksSize
Azilroka's avatar
Azilroka committed
422
			local hastedTickSize = baseTickSize / (1 +  curHaste)
423
			local extraTick = self.max - hastedTickSize * (baseTicks)
Azilroka's avatar
Azilroka committed
424
			local extraTickRatio = extraTick / hastedTickSize
425

Azilroka's avatar
Azilroka committed
426 427
			UF:SetCastTicks(self, baseTicks, extraTickRatio)
			self.hadTicks = true
428 429
		elseif baseTicks then
			UF:SetCastTicks(self, baseTicks)
Azilroka's avatar
Azilroka committed
430
			self.hadTicks = true
431 432 433
		else
			UF:HideTicks()
		end
Azilroka's avatar
Azilroka committed
434 435 436 437 438
	end

	local colors = ElvUF.colors
	local r, g, b = colors.castColor[1], colors.castColor[2], colors.castColor[3]

Simpy's avatar
:broom:  
Simpy committed
439
	if self.notInterruptible and unit ~= 'player' and UnitCanAttack('player', unit) then
Azilroka's avatar
Azilroka committed
440
		r, g, b = colors.castNoInterrupt[1], colors.castNoInterrupt[2], colors.castNoInterrupt[3]
441 442 443 444 445 446 447 448
	elseif UF.db.colors.castClassColor and UnitIsPlayer(unit) then
		local _, Class = UnitClass(unit)
		local t = Class and ElvUF.colors.class[Class]
		if t then r, g, b = t[1], t[2], t[3] end
	elseif UF.db.colors.castReactionColor then
		local Reaction = UnitReaction(unit, 'player')
		local t = Reaction and ElvUF.colors.reaction[Reaction]
		if t then r, g, b = t[1], t[2], t[3] end
Azilroka's avatar
Azilroka committed
449 450
	end

451 452 453
	if self.SafeZone then
		self.SafeZone:Show()
	end
Azilroka's avatar
Azilroka committed
454 455 456 457 458
	self:SetStatusBarColor(r, g, b)
end

function UF:PostCastStop(unit)
	if self.hadTicks and unit == 'player' then
459
		UF:HideTicks()
Azilroka's avatar
Azilroka committed
460
		self.hadTicks = false
461 462 463
	end
end

464 465 466 467 468 469 470
function UF:PostCastFail()
	self:SetStatusBarColor(UF.db.colors.castInterruptedColor.r, UF.db.colors.castInterruptedColor.g, UF.db.colors.castInterruptedColor.b)
	if self.SafeZone then
		self.SafeZone:Hide()
	end
end

471
function UF:PostCastInterruptible(unit)
Simpy's avatar
Simpy committed
472
	if unit == 'vehicle' or unit == 'player' then return end
473 474 475 476

	local colors = ElvUF.colors
	local r, g, b = colors.castColor[1], colors.castColor[2], colors.castColor[3]

Simpy's avatar
Simpy committed
477
	if self.notInterruptible and UnitCanAttack('player', unit) then
478
		r, g, b = colors.castNoInterrupt[1], colors.castNoInterrupt[2], colors.castNoInterrupt[3]
479 480 481 482 483 484 485 486
	elseif UF.db.colors.castClassColor and UnitIsPlayer(unit) then
		local _, Class = UnitClass(unit)
		local t = Class and ElvUF.colors.class[Class]
		if t then r, g, b = t[1], t[2], t[3] end
	elseif UF.db.colors.castReactionColor then
		local Reaction = UnitReaction(unit, 'player')
		local t = Reaction and ElvUF.colors.reaction[Reaction]
		if t then r, g, b = t[1], t[2], t[3] end
487 488 489 490
	end

	self:SetStatusBarColor(r, g, b)
end