File src/ChorusCastFrameTemplate.lua changed (mode: 100644) (index 21fcc6e..c234ef8) |
... |
... |
local SecureButton_GetUnit = SecureButton_GetUnit |
8 |
8 |
|
|
9 |
9 |
local Chorus = Chorus |
local Chorus = Chorus |
10 |
10 |
|
|
|
11 |
|
local function getDurationRemainingSec(nowMili, startInstanceMili, endInstanceMili) |
|
12 |
|
assert(nowMili ~= nil) |
|
13 |
|
assert('number' == type(nowMili)) |
|
14 |
|
|
|
15 |
|
assert(startInstanceMili ~= nil) |
|
16 |
|
assert('number' == type(startInstanceMili)) |
|
17 |
|
|
|
18 |
|
assert(endInstanceMili ~= nil) |
|
19 |
|
assert('number' == type(endInstanceMili)) |
|
20 |
|
|
|
21 |
|
local durationRemainingSec = (endInstanceMili - nowMili) / 1000 |
|
22 |
|
|
|
23 |
|
assert(durationRemainingSec ~= nil) |
|
24 |
|
assert('number' == type(durationRemainingSec)) |
|
25 |
|
assert(durationRemainingSec >= 0 or durationRemainingSec <= 0) |
|
26 |
|
|
|
27 |
|
return durationRemainingSec |
|
28 |
|
end |
|
29 |
|
|
|
30 |
|
local function getCastInfo(unitDesignation) |
|
31 |
|
assert(unitDesignation ~= nil) |
|
32 |
|
|
|
33 |
|
local spellName = UnitCastingInfo(unitDesignation) |
|
34 |
|
if spellName then |
|
35 |
|
return UnitCastingInfo(unitDesignation) |
|
36 |
|
else |
|
37 |
|
return UnitChannelInfo(unitDesignation) |
|
38 |
|
end |
|
39 |
|
end |
|
40 |
|
|
11 |
41 |
local function castFrameEventIsRelevant(self, eventCategory, ...) |
local function castFrameEventIsRelevant(self, eventCategory, ...) |
12 |
42 |
assert(self ~= nil) |
assert(self ~= nil) |
13 |
43 |
assert(eventCategory ~= nil) |
assert(eventCategory ~= nil) |
|
... |
... |
local function castFrameEventIsRelevant(self, eventCategory, ...) |
21 |
51 |
end |
end |
22 |
52 |
end |
end |
23 |
53 |
|
|
24 |
|
local function castFrameEventProcessor(self, eventCategory, ...) |
|
|
54 |
|
local function applyArtworkSpellIcon(self, pictureFile) |
25 |
55 |
assert(self ~= nil) |
assert(self ~= nil) |
26 |
56 |
|
|
27 |
|
if not castFrameEventIsRelevant(self, eventCategory, ...) then |
|
28 |
|
return |
|
|
57 |
|
if not pictureFile then |
|
58 |
|
pictureFile = 'Interface\\Icons\\INV_Misc_QuestionMark' |
29 |
59 |
end |
end |
30 |
60 |
|
|
31 |
|
--print(self:GetName(), eventCategory, ...) |
|
32 |
|
|
|
33 |
|
local u = SecureButton_GetUnit(self) |
|
34 |
|
if not u or not UnitExists(u) then |
|
35 |
|
self:Hide() |
|
36 |
|
return |
|
37 |
|
end |
|
|
61 |
|
assert(pictureFile ~= nil) |
|
62 |
|
assert('string' == type(pictureFile)) |
|
63 |
|
pictureFile = strtrim(pictureFile) |
|
64 |
|
assert(string.len(pictureFile) >= 1) |
|
65 |
|
assert(string.len(pictureFile) <= 8192) |
38 |
66 |
|
|
|
67 |
|
--[[ Artwork1: spell icon ]]-- |
39 |
68 |
local artwork1 = self.artwork1 or _G[self:GetName() .. 'Artwork1'] |
local artwork1 = self.artwork1 or _G[self:GetName() .. 'Artwork1'] |
40 |
69 |
assert(artwork1 ~= nil) |
assert(artwork1 ~= nil) |
41 |
70 |
|
|
42 |
|
local artwork2 = self.artwork2 or _G[self:GetName() .. 'Artwork2'] |
|
43 |
|
assert(artwork2 ~= nil) |
|
|
71 |
|
artwork1:SetTexture(pictureFile) |
|
72 |
|
end |
|
73 |
|
|
|
74 |
|
local function applySpellName(self, spellName) |
|
75 |
|
assert(self ~= nil) |
|
76 |
|
|
|
77 |
|
if not spellName then |
|
78 |
|
spellName = 'Unknown' |
|
79 |
|
end |
|
80 |
|
|
|
81 |
|
assert(spellName ~= nil) |
|
82 |
|
assert('string' == type(spellName)) |
|
83 |
|
spellName = strtrim(spellName) |
|
84 |
|
assert(string.len(spellName) >= 1) |
|
85 |
|
assert(string.len(spellName) <= 8192) |
44 |
86 |
|
|
45 |
87 |
local label1 = self.label1 or _G[self:GetName() .. 'Text1'] |
local label1 = self.label1 or _G[self:GetName() .. 'Text1'] |
46 |
88 |
assert(label1 ~= nil) |
assert(label1 ~= nil) |
47 |
89 |
|
|
|
90 |
|
label1:SetText(spellName) |
|
91 |
|
end |
|
92 |
|
|
|
93 |
|
local function applyArtworkCastBar(self, unitDesignation, shieldedFlag) |
|
94 |
|
assert(self ~= nil) |
|
95 |
|
|
|
96 |
|
assert(unitDesignation ~= nil) |
|
97 |
|
assert('string' == type(unitDesignation)) |
|
98 |
|
unitDesignation = string.lower(strtrim(unitDesignation)) |
|
99 |
|
assert(string.len(unitDesignation) >= 1) |
|
100 |
|
assert(string.len(unitDesignation) <= 256) |
|
101 |
|
|
|
102 |
|
local label1 = self.label1 or _G[self:GetName() .. 'Text1'] |
|
103 |
|
assert(label1 ~= nil) |
|
104 |
|
|
|
105 |
|
--[[ Artwork2: bar texture ]]-- |
|
106 |
|
local artwork2 = self.artwork2 or _G[self:GetName() .. 'Artwork2'] |
|
107 |
|
assert(artwork2 ~= nil) |
|
108 |
|
|
|
109 |
|
if shieldedFlag then |
|
110 |
|
artwork2:SetVertexColor(248 / 255, 248 / 255, 1) |
|
111 |
|
label1:SetTextColor(1, 215 / 255, 0) |
|
112 |
|
elseif UnitIsFriend('player', unitDesignation) then |
|
113 |
|
artwork2:SetVertexColor(143 / 255, 188 / 255, 143 / 255) |
|
114 |
|
label1:SetTextColor(248 / 255, 248 / 255, 1) |
|
115 |
|
else |
|
116 |
|
artwork2:SetVertexColor(1, 69 / 255, 0) |
|
117 |
|
label1:SetTextColor(248 / 255, 248 / 255, 1) |
|
118 |
|
end |
|
119 |
|
end |
|
120 |
|
|
|
121 |
|
local function applyDurationRemainingSec(self, durationRemainingSec) |
|
122 |
|
assert(self ~= nil) |
|
123 |
|
|
|
124 |
|
assert(durationRemainingSec ~= nil) |
|
125 |
|
assert('number' == type(durationRemainingSec)) |
|
126 |
|
|
48 |
127 |
local label2 = self.label2 or _G[self:GetName() .. 'Text2'] |
local label2 = self.label2 or _G[self:GetName() .. 'Text2'] |
49 |
128 |
assert(label2 ~= nil) |
assert(label2 ~= nil) |
50 |
129 |
|
|
51 |
|
local spellName, pictureFile, startInstance, endInstance, shieldedFlag |
|
52 |
|
local spellName0, _, _, pictureFile0, startInstance0, endInstance0, _, _, shieldedFlag0 = UnitCastingInfo(u) |
|
53 |
|
local spellName1, _, _, pictureFile1, startInstance1, endInstance1, _, _, shieldedFlag1 = UnitChannelInfo(u) |
|
54 |
|
if spellName0 then |
|
55 |
|
spellName = spellName0 |
|
56 |
|
pictureFile = pictureFile0 |
|
57 |
|
startInstance = startInstance0 |
|
58 |
|
endInstance = endInstance0 |
|
59 |
|
shieldedFlag = shieldedFlag0 |
|
60 |
|
elseif spellName1 then |
|
61 |
|
spellName = spellName1 |
|
62 |
|
pictureFile = pictureFile1 |
|
63 |
|
startInstance = startInstance1 |
|
64 |
|
endInstance = endInstance1 |
|
65 |
|
shieldedFlag = shieldedFlag1 |
|
|
130 |
|
local t = string.format('%.1f', durationRemainingSec) |
|
131 |
|
label2:SetText(t) |
|
132 |
|
end |
|
133 |
|
|
|
134 |
|
local function applyBounds(self, startInstance, endInstance) |
|
135 |
|
assert(self ~= nil) |
|
136 |
|
|
|
137 |
|
assert(startInstance ~= nil) |
|
138 |
|
assert('number' == type(startInstance)) |
|
139 |
|
startInstance = math.abs(startInstance) |
|
140 |
|
assert(startInstance >= 0) |
|
141 |
|
|
|
142 |
|
assert(endInstance ~= nil) |
|
143 |
|
assert('number' == type(endInstance)) |
|
144 |
|
endInstance = math.abs(endInstance) |
|
145 |
|
assert(endInstance >= 0) |
|
146 |
|
|
|
147 |
|
local x = math.min(startInstance, endInstance) |
|
148 |
|
local y = math.max(startInstance, endInstance) |
|
149 |
|
assert(x <= y) |
|
150 |
|
|
|
151 |
|
self:SetMinMaxValues(x, y) |
|
152 |
|
end |
|
153 |
|
|
|
154 |
|
local function applyCurrentInstanceMili(self, nowMili) |
|
155 |
|
assert(self ~= nil) |
|
156 |
|
|
|
157 |
|
assert(nowMili ~= nil) |
|
158 |
|
assert('number' == type(nowMili)) |
|
159 |
|
nowMili = math.abs(nowMili) |
|
160 |
|
assert(nowMili >= 0) |
|
161 |
|
|
|
162 |
|
self:SetValue(nowMili) |
|
163 |
|
end |
|
164 |
|
|
|
165 |
|
local function castFrameEventProcessor(self, eventCategory, ...) |
|
166 |
|
assert(self ~= nil) |
|
167 |
|
|
|
168 |
|
if not castFrameEventIsRelevant(self, eventCategory, ...) then |
|
169 |
|
return |
66 |
170 |
end |
end |
67 |
171 |
|
|
68 |
|
if tContains({'UNIT_SPELLCAST_START', 'UNIT_SPELLCAST_CHANNEL_START', 'UNIT_SPELLCAST_DELAYED'}, eventCategory) then |
|
69 |
|
if spellName then |
|
70 |
|
label1:SetText(spellName) |
|
71 |
|
end |
|
72 |
|
if pictureFile then |
|
73 |
|
artwork1:SetTexture(pictureFile) |
|
74 |
|
end |
|
75 |
|
if shieldedFlag then |
|
76 |
|
artwork2:SetVertexColor(248 / 255, 248 / 255, 1) |
|
77 |
|
label1:SetTextColor(1, 215 / 255, 0) |
|
78 |
|
elseif UnitIsFriend('player', u) then |
|
79 |
|
artwork2:SetVertexColor(143 / 255, 188 / 255, 143 / 255) |
|
80 |
|
label1:SetTextColor(248 / 255, 248 / 255, 1) |
|
81 |
|
else |
|
82 |
|
artwork2:SetVertexColor(1, 69 / 255, 0) |
|
83 |
|
label1:SetTextColor(248 / 255, 248 / 255, 1) |
|
84 |
|
end |
|
85 |
|
self:SetMinMaxValues(startInstance, endInstance) |
|
|
172 |
|
local u = SecureButton_GetUnit(self) |
|
173 |
|
if not u or not UnitExists(u) then |
|
174 |
|
return |
|
175 |
|
end |
|
176 |
|
|
|
177 |
|
local label2 = self.label2 or _G[self:GetName() .. 'Text2'] |
|
178 |
|
assert(label2 ~= nil) |
|
179 |
|
|
|
180 |
|
local spellName, _, _, pictureFile, startInstance, endInstance, _, _, shieldedFlag = getCastInfo(u) |
|
181 |
|
|
|
182 |
|
local castOngoingFlag = spellName ~= nil |
|
183 |
|
if castOngoingFlag then |
|
184 |
|
applyBounds(self, startInstance, endInstance) |
|
185 |
|
|
|
186 |
|
local now = GetTime() * 1000 |
|
187 |
|
applyCurrentInstanceMili(self, now) |
|
188 |
|
|
|
189 |
|
local dur = getDurationRemainingSec(now, startInstance, endInstance) |
|
190 |
|
applyDurationRemainingSec(self, dur) |
|
191 |
|
|
|
192 |
|
applyArtworkSpellIcon(self, pictureFile) |
|
193 |
|
applyArtworkCastBar(self, u, shieldedFlag) |
|
194 |
|
applySpellName(self, spellName) |
86 |
195 |
self:Show() |
self:Show() |
87 |
|
elseif tContains({'UNIT_SPELLCAST_STOP', 'UNIT_SPELLCAST_CHANNEL_STOP'}, eventCategory) then |
|
|
196 |
|
else |
88 |
197 |
self:Hide() |
self:Hide() |
89 |
198 |
end |
end |
90 |
199 |
end |
end |
|
... |
... |
local function castFrameUpdateProcessor(self) |
98 |
207 |
end |
end |
99 |
208 |
|
|
100 |
209 |
local now = GetTime() * 1000 |
local now = GetTime() * 1000 |
101 |
|
self:SetValue(now) |
|
102 |
|
local _, b = self:GetMinMaxValues() |
|
|
210 |
|
applyCurrentInstanceMili(self, now) |
103 |
211 |
|
|
104 |
|
local label2 = self.label2 or _G[self:GetName() .. 'Text2'] |
|
105 |
|
assert(label2 ~= nil) |
|
|
212 |
|
local a, b = self:GetMinMaxValues() |
|
213 |
|
local durationRemainingSec = getDurationRemainingSec(now, a, b) |
106 |
214 |
|
|
107 |
|
local durationRemainingSec = (b - now) / 1000 |
|
108 |
|
local t = string.format('%.1f', durationRemainingSec) |
|
109 |
|
label2:SetText(t) |
|
|
215 |
|
applyDurationRemainingSec(self, durationRemainingSec) |
110 |
216 |
end |
end |
111 |
217 |
|
|
112 |
218 |
local function castFrameMain(self) |
local function castFrameMain(self) |
|
... |
... |
local function castFrameMain(self) |
131 |
237 |
self:SetScript('OnUpdate', castFrameUpdateProcessor) |
self:SetScript('OnUpdate', castFrameUpdateProcessor) |
132 |
238 |
|
|
133 |
239 |
self:RegisterEvent("PLAYER_ENTERING_WORLD"); |
self:RegisterEvent("PLAYER_ENTERING_WORLD"); |
|
240 |
|
self:RegisterEvent("PLAYER_FOCUS_CHANGED"); |
|
241 |
|
self:RegisterEvent("PLAYER_TARGET_CHANGED"); |
134 |
242 |
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START"); |
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START"); |
135 |
243 |
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP"); |
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP"); |
136 |
244 |
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE"); |
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE"); |