comparison Tek.lua @ 4:8ace773d6bfc

suppress castbar latency logic on non-player units
author Nenue
date Tue, 15 Dec 2015 10:09:20 -0500
parents 766d8a40a1d6
children
comparison
equal deleted inserted replaced
3:9de4a810fda7 4:8ace773d6bfc
1 addon, T_ = ... 1 addon, T_ = ...
2 -- User: Krakyn 2 -- User: Krakyn
3 -- Created: 12/4/2015 11:17 PM 3 -- Created: 12/4/2015 11:17 PM
4 local T = LibStub("AceAddon-3.0"):GetAddon("Turok") 4 local T = LibStub("AceAddon-3.0"):GetAddon("Turok")
5 local db = T.db
5 local TL = 'Tek' 6 local TL = 'Tek'
6 local mod = T:NewModule("Tek") 7 local mod = T:NewModule("Tek")
7 local print = function(...) 8 local print = function(...)
8 _G.print('Tek', ...) 9 _G.print('Tek', ...)
9 end 10 end
12 -- events & units 13 -- events & units
13 local TRACKED_UNITS = {'player', 'target', 'focus', 'pet'} 14 local TRACKED_UNITS = {'player', 'target', 'focus', 'pet'}
14 local TRACKED_EVENTS = {'UNIT_SPELLCAST_START', 'UNIT_SPELLCAST_DELAYED', 'UNIT_SPELLCAST_STOP', 'UNIT_SPELLCAST_FAILED', 'UNIT_SPELLCAST_FAILED_QUIET', 15 local TRACKED_EVENTS = {'UNIT_SPELLCAST_START', 'UNIT_SPELLCAST_DELAYED', 'UNIT_SPELLCAST_STOP', 'UNIT_SPELLCAST_FAILED', 'UNIT_SPELLCAST_FAILED_QUIET',
15 'UNIT_SPELLCAST_INTERRUPTED', 'UNIT_SPELLCAST_SUCCEEDED', 'UNIT_SPELLCAST_CHANNEL_START', 'UNIT_SPELLCAST_CHANNEL_STOP', 'UNIT_SPELLCAST_CHANNEL_UPDATE' } 16 'UNIT_SPELLCAST_INTERRUPTED', 'UNIT_SPELLCAST_SUCCEEDED', 'UNIT_SPELLCAST_CHANNEL_START', 'UNIT_SPELLCAST_CHANNEL_STOP', 'UNIT_SPELLCAST_CHANNEL_UPDATE' }
16 17
17 local FADE_OUT_TIME, FADE_IN_TIME = 1000, 200 -- animation timings 18 -- animations are a little different here
19 local FADE_OUT_TIME, FADE_IN_TIME = 1000, 200
18 20
19 -- values MUST be in chronological order 21 -- values MUST be in chronological order
20 local CHANNEL_START, CAST_START, CAST_INTERRUPTED, CAST_SUCCEEDED, CAST_STOPPED, CAST_FAILED, CHANNEL_STOPPED = 1, 2, 3, 4, 5, 6, 7 22 local CHANNEL_START, CAST_START, CAST_INTERRUPTED, CAST_SUCCEEDED, CAST_STOPPED, CAST_FAILED, CHANNEL_STOPPED = 1, 2, 3, 4, 5, 6, 7
21 local TEXTURE_SUFFIX = { 23 local TEXTURE_SUFFIX = {
22 [CHANNEL_START] = '_channeling', 24 [CHANNEL_START] = '_channeling',
25 [CAST_SUCCEEDED] = '_finished', 27 [CAST_SUCCEEDED] = '_finished',
26 [CAST_STOPPED] = '_failed', 28 [CAST_STOPPED] = '_failed',
27 [CAST_FAILED] = '_failed', 29 [CAST_FAILED] = '_failed',
28 [CHANNEL_STOPPED] = '' 30 [CHANNEL_STOPPED] = ''
29 } 31 }
32
33 -- defaults
34 db.castbar = {
35 --T.defaults.castbar = {
36 width = 300, height = 24,
37 anchor = 'CENTER', parent = 'UIParent', anchorTo = 'CENTER',
38 posX = 0, posY = 0,
39 foreground_casting = {0.80784313725, 0.87843137254, 0.0156862745, 1},
40 background_casting = {0,0,0,0.4},
41 background_interrupted = {1,0,0,1},
42 background_failed = {0.60784313725, 0.87843137254, 0.0156862745, 1},
43 foreground_interrupted = {1, 0.5, 0, 1},
44 foreground_failed = {0,0,0,1},
45 foreground_finished = {0.60784313725, 0.87843137254, 0.0156862745, 1},
46 background_finished = {0.60784313725, 0.87843137254, 0.0156862745, 1},
47 foreground_inset = -1,
48 fill_direction = 'RIGHT',
49 fill_inverse = false,
50 glow_texture = "Tooltip-BigBorder",
51 glow_size = 2,
52 spark_texture = "Tooltip-BigBorder",
53 spark_size = 2,
54 ['player'] = {
55 width = 400, height = 36,
56 anchor = 'TOP', parent = 'TkFocusBar', anchorTo = 'BOTTOM',
57 posX = 0, posY = 2,
58 },
59 ['target'] = {
60 width = 400, height = 36,
61 anchor = 'BOTTOMLEFT', parent = 'TkplayerCastBar', anchorTo = 'TOPRIGHT',
62 posX = -30, posY = 4,
63 },
64 ['focus'] = {
65 width = 200, height = 36,
66 anchor = 'TOPLEFT', parent = 'TkplayerCastBar', anchorTo='BOTTOMRIGHT',
67 posX = 2, posY = -2
68 },
69 ['pet'] = {
70 width = 300, height = 24,
71 anchor = 'TOPRIGHT', parent = 'TkFocusBar', anchorTo='TOPLEFT',
72 posX = -2, posY = 0
73 },
74 }
75
30 local inv = T.anchor_inverse 76 local inv = T.anchor_inverse
31 local d = T.direction_coord 77 local d = T.direction_coord
32 local a = T.anchor_direction 78 local a = T.anchor_direction
33 local c = {} 79 local c = {}
34 -- c[unit]=nil is used by frame update, thus any indexing from a valid frame is implied to be for new casting info 80 -- c[unit]=nil is used by frame update, thus any indexing from a valid frame is implied to be for new casting info
40 }) 86 })
41 87
42 function mod:OnEnable() 88 function mod:OnEnable()
43 local db = T.db 89 local db = T.db
44 90
45 db.castbar = {
46 --T.defaults.castbar = {
47 width = 300, height = 24,
48 anchor = 'TOP', parent = 'TkFocusBar', anchorTo = 'BOTTOM',
49 posX = 0, posY = -2,
50 foreground_casting = {0.80784313725, 0.87843137254, 0.0156862745, 1},
51 background_casting = {0,0,0,0.4},
52 background_interrupted = {1,0,0,1},
53 background_failed = {0.60784313725, 0.87843137254, 0.0156862745, 1},
54 foreground_interrupted = {1, 0.5, 0, 1},
55 foreground_failed = {0,0,0,1},
56 foreground_finished = {0.60784313725, 0.87843137254, 0.0156862745, 1},
57 background_finished = {0.60784313725, 0.87843137254, 0.0156862745, 1},
58 foreground_inset = -1,
59 fill_direction = 'RIGHT',
60 fill_inverse = false,
61 glow_texture = "Tooltip-BigBorder",
62 glow_size = 2,
63 spark_texture = "Tooltip-BigBorder",
64 spark_size = 2,
65 ['player'] = {},
66 ['target'] = {
67 width = 300, height = 24,
68 anchor = 'BOTTOMLEFT', parent = 'TkplayerCastBar', anchorTo = 'TOPRIGHT',
69 posX = 4, posY = 4,
70 },
71 ['focus'] = {
72 width = 300, height = 24,
73 anchor = 'TOPLEFT', parent = 'TkplayerCastBar', anchorTo='BOTTOMRIGHT',
74 posX = 2, posY = -2
75 },
76 ['pet'] = {
77 width = 300, height = 24,
78 anchor = 'TOPRIGHT', parent = 'TkFocusBar', anchorTo='TOPLEFT',
79 posX = -2, posY = 0
80 },
81 }
82
83 self.casting = c 91 self.casting = c
84 self.castbar = {} 92 self.castbar = {}
85 93
86 94
87 for _, unit in pairs(TRACKED_UNITS) do 95 for _, unit in pairs(TRACKED_UNITS) do
99 pc:Hide() 107 pc:Hide()
100 pc:SetAlpha(0) 108 pc:SetAlpha(0)
101 109
102 T:AddLabel(pc, cdb, 'spelltext') 110 T:AddLabel(pc, cdb, 'spelltext')
103 local casttime = T:AddLabel(pc, cdb, 'casttime') 111 local casttime = T:AddLabel(pc, cdb, 'casttime')
104 local latency = T:AddLabel(pc, cdb, 'latency')
105 pc.foreground:SetWidth(0) 112 pc.foreground:SetWidth(0)
106 113
107 casttime:SetPoint('RIGHT', pc, 'RIGHT') 114 casttime:SetPoint('RIGHT', pc, 'RIGHT')
108 casttime:SetJustifyH('RIGHT') 115 casttime:SetJustifyH('RIGHT')
109 latency:SetPoint('TOPRIGHT', pc.casttime, 'BOTTOMRIGHT') 116
110 latency:SetJustifyH('RIGHT') 117 if unit == 'player' then
118 local lb = pc:CreateTexture('latency', 'OVERLAY')
119 local lt = T:AddLabel(pc, cdb, 'latency')
120 lt:SetPoint('TOPRIGHT', pc.casttime, 'BOTTOMRIGHT')
121 lt:SetJustifyH('RIGHT')
122 pc.latency = lb
123 lb.text = lt
124 end
111 125
112 pc.transpt = a[cdb.fill_direction] 126 pc.transpt = a[cdb.fill_direction]
113 pc.xtrans = function() return math.min((cdb.width + cdb.foreground_inset) * pc.percent * d[pc.transpt][1], cdb.width) end 127 pc.xtrans = function() return math.min((cdb.width + cdb.foreground_inset) * pc.percent * d[pc.transpt][1], cdb.width) end
114 pc.ytrans = function() return math.min((cdb.height + cdb.foreground_inset) * pc.percent * d[pc.transpt][2], cdb.height) end 128 pc.ytrans = function() return math.min((cdb.height + cdb.foreground_inset) * pc.percent * d[pc.transpt][2], cdb.height) end
115 129
129 icon:SetTexture(0,0,0,1) 143 icon:SetTexture(0,0,0,1)
130 pc.icon = icon 144 pc.icon = icon
131 145
132 pc.unit = unit 146 pc.unit = unit
133 T:Bar_SetUpdateHandler(pc, self.TekUpdate) 147 T:Bar_SetUpdateHandler(pc, self.TekUpdate)
134
135
136
137 --print('created', fn)
138 end 148 end
139 149
140 -- Casting table events 150 -- Casting table events
141 for i, event in pairs(TRACKED_EVENTS) do 151 for i, event in pairs(TRACKED_EVENTS) do
142 print('listening to |cFF00FFFF' .. event .. '|r') 152 print('listening to |cFF00FFFF' .. event .. '|r')
145 155
146 -- Extra events 156 -- Extra events
147 self:RegisterEvent('PLAYER_TARGET_CHANGED') 157 self:RegisterEvent('PLAYER_TARGET_CHANGED')
148 self:RegisterEvent('PLAYER_FOCUS_CHANGED') 158 self:RegisterEvent('PLAYER_FOCUS_CHANGED')
149 159
160 -- kill default casting bar
161 -- T.cbscripts = {CastingBarFrame:GetScript('OnUpdate'), CastingBarFrame:GetScript('OnEvent')}
150 CastingBarFrame:SetScript('OnUpdate', nil) 162 CastingBarFrame:SetScript('OnUpdate', nil)
151 CastingBarFrame:SetScript('OnEvent', nil) 163 CastingBarFrame:SetScript('OnEvent', nil)
152 CastingBarFrame:Hide() 164 CastingBarFrame:Hide()
153 end 165 end
154 166
174 -- start = true whenever a new spell cast could be active (i.e. target switching) 186 -- start = true whenever a new spell cast could be active (i.e. target switching)
175 if s.init then 187 if s.init then
176 print('|cFFDD77DD'..u..'|r init_cast (spell='..s.displayName..', startTime='..s.startTime..', endTime='..s.endTime..', channel=',s.channel,')') 188 print('|cFFDD77DD'..u..'|r init_cast (spell='..s.displayName..', startTime='..s.startTime..', endTime='..s.endTime..', channel=',s.channel,')')
177 print(self:GetName(), self:IsVisible(), self:IsShown()) 189 print(self:GetName(), self:IsVisible(), self:IsShown())
178 190
191 if u == 'player' then
192 self.latency.text:SetText(s.latency)
193 end
194
179 -- update translation point 195 -- update translation point
180 if s.casting == CHANNEL_START and not cdb.fill_inverse then 196 if s.casting == CHANNEL_START and not cdb.fill_inverse then
181 self.transpt = inv[a[cdb.fill_direction]] 197 self.transpt = inv[a[cdb.fill_direction]]
182 else 198 else
183 self.transpt = a[cdb.fill_direction] 199 self.transpt = a[cdb.fill_direction]
187 foreground:SetTexture(unpack(cdb['foreground' .. TEXTURE_SUFFIX[s.casting]] and cdb['foreground' .. TEXTURE_SUFFIX[s.casting]] or cdb.foreground_color)) 203 foreground:SetTexture(unpack(cdb['foreground' .. TEXTURE_SUFFIX[s.casting]] and cdb['foreground' .. TEXTURE_SUFFIX[s.casting]] or cdb.foreground_color))
188 background:SetTexture(unpack(cdb['background' .. TEXTURE_SUFFIX[s.casting]] and cdb['background' .. TEXTURE_SUFFIX[s.casting]] or cdb.background_color)) 204 background:SetTexture(unpack(cdb['background' .. TEXTURE_SUFFIX[s.casting]] and cdb['background' .. TEXTURE_SUFFIX[s.casting]] or cdb.background_color))
189 205
190 self.icon:SetTexture(s.texture) 206 self.icon:SetTexture(s.texture)
191 spelltext:SetText(s.displayName) 207 spelltext:SetText(s.displayName)
192 latency:SetText(s.latency)
193 self.duration = s.endTime - s.startTime 208 self.duration = s.endTime - s.startTime
194 self.fadeIn = s.startTime + (1-alpha) * FADE_IN_TIME 209 self.fadeIn = s.startTime + (1-alpha) * FADE_IN_TIME
195 self.fadeOut = s.endTime + FADE_OUT_TIME -- needs to exist for target changes 210 self.fadeOut = s.endTime + FADE_OUT_TIME -- needs to exist for target changes
196 211
197 print(s.startTime, self.fadeIn, self.fadeIn - s.startTime) 212 print(s.startTime, self.fadeIn, self.fadeIn - s.startTime)
230 alpha = 0 245 alpha = 0
231 self:Hide() 246 self:Hide()
232 self:SetAlpha(alpha) 247 self:SetAlpha(alpha)
233 self.casttime:SetText(nil) 248 self.casttime:SetText(nil)
234 self.spelltext:SetText(nil) 249 self.spelltext:SetText(nil)
235 self.latency:SetText(nil)
236 self.debugged = false 250 self.debugged = false
237 self.percent = 0 251 self.percent = 0
252 if u == 'player' then
253 self.latency.text:SetText(nil)
254 end
238 mod.casting[self.unit] = nil 255 mod.casting[self.unit] = nil
239 print('|cFFDD77DD'..u..'|r work complete, hiding...') 256 print('|cFFDD77DD'..u..'|r work complete, hiding...')
240 end 257 end
241 -- hide and wait until we're pulled out again 258 -- hide and wait until we're pulled out again
242 end 259 end
328 c[unit].fade = true 345 c[unit].fade = true
329 end 346 end
330 347
331 function mod:UNIT_SPELLCAST_SUCCEEDED(e, unit, spellname, rank, castID, target) -- Server says: they stopped because they're done 348 function mod:UNIT_SPELLCAST_SUCCEEDED(e, unit, spellname, rank, castID, target) -- Server says: they stopped because they're done
332 349
333 if c[unit].castID == castID and c[unit].casting ~= CHANNEL_START then 350 if c[unit].castID == castID and c[unit].casting ~= CHANNEL_START then
334 c[unit].casting = CAST_SUCCEEDED 351 c[unit].casting = CAST_SUCCEEDED
335 c[unit].fade = true 352 c[unit].fade = true
336 end 353 end
337 end 354 end
338 355