vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | function DUF_TextBox_OnEvent(event) |
2 | if (not DUF_INITIALIZED) then return; end |
||
3 | if (event and string.find(event, "UNIT_")) then |
||
4 | if (arg1 ~= this:GetParent().unit) then return; end |
||
5 | end |
||
6 | |||
7 | if (event == "UNIT_COMBAT") then |
||
8 | this.damagetext = ""; |
||
9 | this.healtext = ""; |
||
10 | if( arg2 == "IMMUNE" ) then |
||
11 | this.damagetext= "|cFFFFFF00"..CombatFeedbackText["IMMUNE"]; |
||
12 | elseif ( arg2 == "WOUND" ) then |
||
13 | if ( arg3 == "ABSORB" )then |
||
14 | this.damagetext= "|cFFFFFFFF"..TEXT(ABSORB); |
||
15 | elseif ( arg4 ~= 0 ) then |
||
16 | if ( arg3 == "CRITICAL" ) then |
||
17 | this.damagetext= "|cFFFF00FF"..DUF_TEXT.Crit.."|cFFFF0000".."-"..arg4; |
||
18 | end |
||
19 | this.damagetext= "|cFFFF0000".."-"..arg4; |
||
20 | else |
||
21 | this.damagetext= "|cFFFFFF00"..CombatFeedbackText["MISS"]; |
||
22 | end |
||
23 | elseif ( arg2 == "BLOCK" ) then |
||
24 | this.damagetext= "|cFFFFFF00"..TEXT(BLOCK); |
||
25 | elseif ( arg2 == "HEAL" ) then |
||
26 | this.healtext= "|cFF00FF00".."+"..arg4; |
||
27 | if ( arg3 == "CRITICAL" ) then |
||
28 | this.healtext= "|cFFFF00FF"..DUF_TEXT.Crit.."|cFF00FF00".."+"..arg4; |
||
29 | end |
||
30 | else |
||
31 | this.damagetext= CombatFeedbackText[arg2]; |
||
32 | end |
||
33 | this.combattexttimer = 1.5; |
||
34 | elseif (event == "UNIT_HEALTH") then |
||
35 | local health = UnitHealth(this:GetParent().unit); |
||
36 | if (not this.lasthealth) then |
||
37 | this.lasthealth = health; |
||
38 | end |
||
39 | local gain = health - this.lasthealth; |
||
40 | if (health == UnitHealthMax(this:GetParent().unit) or (not DL_REGEN)) then |
||
41 | this.healthregen = 0; |
||
42 | this.healthregentick = 0; |
||
43 | this.healthtable = nil; |
||
44 | elseif (gain > 0) then |
||
45 | this.healthregentick = gain; |
||
46 | |||
47 | if (not this.healthtable) then |
||
48 | this.healthtable = {}; |
||
49 | local time = GetTime(); |
||
50 | for i=1,4 do |
||
51 | this.healthtable[i] = { v=0, t=time }; |
||
52 | end |
||
53 | this.healthtable[5] = { v=gain, t=time }; |
||
54 | else |
||
55 | for i=1,4 do |
||
56 | this.healthtable[i].v = this.healthtable[i + 1].v; |
||
57 | this.healthtable[i].t = this.healthtable[i + 1].t; |
||
58 | end |
||
59 | this.healthtable[5].v = gain; |
||
60 | this.healthtable[5].t = GetTime(); |
||
61 | end |
||
62 | |||
63 | local totalhealth = 0; |
||
64 | for i=1,5 do |
||
65 | totalhealth = totalhealth + this.healthtable[5].v; |
||
66 | end |
||
67 | local seconds = (GetTime() - this.healthtable[1].t); |
||
68 | if (seconds == 0) then |
||
69 | this.healthregen = 0; |
||
70 | else |
||
71 | this.healthregen = math.floor(totalhealth / seconds * 10) / 10; |
||
72 | end |
||
73 | end |
||
74 | this.lasthealth = health; |
||
75 | elseif (event == "UNIT_MANA" or event == "UNIT_RAGE" or event == "UNIT_ENERGY" or event == "UNIT_FOCUS") then |
||
76 | local mana = UnitMana(this:GetParent().unit); |
||
77 | if (not mana) then mana = 0 end |
||
78 | if (not this.lastmana) then |
||
79 | this.lastmana = mana; |
||
80 | end |
||
81 | local gain = mana - this.lastmana; |
||
82 | if (mana == UnitManaMax(this:GetParent().unit)) then |
||
83 | this.manaregen = 0; |
||
84 | this.manaregentick = 0; |
||
85 | this.manatable = nil; |
||
86 | elseif (gain > 0) then |
||
87 | this.manaregentick = gain; |
||
88 | |||
89 | if (not this.manatable) then |
||
90 | this.manatable = {}; |
||
91 | local time = GetTime(); |
||
92 | for i=1,4 do |
||
93 | this.manatable[i] = { v=0, t=time }; |
||
94 | end |
||
95 | this.manatable[5] = { v=gain, t=time }; |
||
96 | else |
||
97 | for i=1,4 do |
||
98 | this.manatable[i].v = this.manatable[i + 1].v; |
||
99 | this.manatable[i].t = this.manatable[i + 1].t; |
||
100 | end |
||
101 | this.manatable[5].v = gain; |
||
102 | this.manatable[5].t = GetTime(); |
||
103 | end |
||
104 | |||
105 | local totalmana = 0; |
||
106 | for i=1,5 do |
||
107 | totalmana = totalmana + this.manatable[5].v; |
||
108 | end |
||
109 | local seconds = (GetTime() - this.manatable[1].t); |
||
110 | if (seconds == 0) then |
||
111 | this.manaregen = 0; |
||
112 | else |
||
113 | this.manaregen = math.floor(totalmana / seconds * 10) / 10; |
||
114 | end |
||
115 | end |
||
116 | this.lastmana = mana; |
||
117 | elseif (event == DUF_UNIT_CHANGED_EVENTS[this:GetParent().unit]) then |
||
118 | DUF_Element_OnShow() |
||
119 | end |
||
120 | |||
121 | DUF_TextBox_Update(); |
||
122 | end |
||
123 | |||
124 | function DUF_TextBox_OnUpdate(elapsed) |
||
125 | if (not DUF_INITIALIZED) then return; end |
||
126 | |||
127 | if (this.combattexttimer) then |
||
128 | this.combattexttimer = this.combattexttimer - elapsed; |
||
129 | if (this.combattexttimer < 0) then |
||
130 | this.combattexttimer = nil; |
||
131 | this.damagetext = ""; |
||
132 | this.healtext = ""; |
||
133 | DUF_TextBox_Update(); |
||
134 | end |
||
135 | end |
||
136 | |||
137 | if (this.update) then |
||
138 | this.update = nil; |
||
139 | local unit = this:GetParent().unit; |
||
140 | local updateTextBox; |
||
141 | if (this.checkname) then |
||
142 | local name = DL_UnitName(unit.."target"); |
||
143 | if (UnitIsUnit(unit.."target", "player")) then |
||
144 | name = DUF_TEXT.You; |
||
145 | elseif (UnitIsUnit(unit.."target", "target")) then |
||
146 | name = DUF_TEXT.YourTarget; |
||
147 | end |
||
148 | if (name ~= this.targetname) then |
||
149 | this.targetname = name; |
||
150 | updateTextBox = true; |
||
151 | end |
||
152 | end |
||
153 | if (this.checkhealth) then |
||
154 | local health = DUF_Get_Health(unit.."target"); |
||
155 | if (health ~= this.targethealth) then |
||
156 | this.targethealth = health; |
||
157 | updateTextBox = true; |
||
158 | end |
||
159 | end |
||
160 | if (this.checkhealthmax) then |
||
161 | local health = DUF_Get_MaxHealth(unit.."target"); |
||
162 | if (health ~= this.targethealthmax) then |
||
163 | this.targethealthmax = health; |
||
164 | updateTextBox = true; |
||
165 | end |
||
166 | end |
||
167 | if (this.checkmana) then |
||
168 | local mana = UnitMana(unit.."target"); |
||
169 | if (this.targetmana ~= mana) then |
||
170 | this.targetmana = mana; |
||
171 | updateTextBox=true; |
||
172 | end |
||
173 | end |
||
174 | if (this.checkmanamax) then |
||
175 | local mana = UnitManaMax(unit.."target"); |
||
176 | if (this.targetmanamax ~= mana) then |
||
177 | this.targetmanamax = mana; |
||
178 | updateTextBox=true; |
||
179 | end |
||
180 | end |
||
181 | if (this.checklevel) then |
||
182 | local level = UnitLevel(unit.."target"); |
||
183 | if (this.targetlevel ~= level) then |
||
184 | this.targetlevel = level; |
||
185 | updateTextBox = true; |
||
186 | end |
||
187 | end |
||
188 | if (this.checktype) then |
||
189 | local ctype; |
||
190 | if (UnitIsPlayer(unit.."target")) then |
||
191 | ctype = UnitClass(unit.."target"); |
||
192 | else |
||
193 | ctype = UnitCreatureType(unit.."target"); |
||
194 | end |
||
195 | if (ctype ~= this.targettype) then |
||
196 | this.targettype = ctype; |
||
197 | updateTextBox = true; |
||
198 | end |
||
199 | end |
||
200 | if (this.checkreaction) then |
||
201 | local reaction = UnitReaction("player", unit); |
||
202 | if (reaction ~= this.ttreaction) then |
||
203 | this.ttreaction = reaction; |
||
204 | updateTextBox = true; |
||
205 | end |
||
206 | end |
||
207 | if (this.checkoffline) then |
||
208 | local connected = UnitIsConnected(unit); |
||
209 | if (connected ~= this.connected) then |
||
210 | this.connected = connected; |
||
211 | updateTextBox = true; |
||
212 | end |
||
213 | end |
||
214 | if (this.checkcombat) then |
||
215 | local ic = UnitAffectingCombat(unit); |
||
216 | if (ic ~= this.incombat) then |
||
217 | this.incombat = ic; |
||
218 | updateTextBox = true; |
||
219 | end |
||
220 | end |
||
221 | if (this.checkpetxp) then |
||
222 | local min,max = GetPetExperience(); |
||
223 | if (min ~= this.minpetxp or max ~= this.maxpetxp) then |
||
224 | this.minpetxp = min; |
||
225 | this.maxpetxp = max; |
||
226 | updateTextBox = true; |
||
227 | end |
||
228 | end |
||
229 | if (this.checkvisibility) then |
||
230 | local visibility = UnitIsVisible(unit); |
||
231 | if (this.visibility ~= visibility) then |
||
232 | this.visibility = visibility; |
||
233 | updateTextBox = true; |
||
234 | end |
||
235 | end |
||
236 | if (this.checkcolor) then |
||
237 | updateTextBox = true; |
||
238 | end |
||
239 | if (updateTextBox) then |
||
240 | DUF_TextBox_Update(); |
||
241 | end |
||
242 | end |
||
243 | end |
||
244 | |||
245 | function DUF_TextBox_Update() |
||
246 | local unit = this:GetParent().unit; |
||
247 | local id = this:GetID(); |
||
248 | local text = DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].TextBox[id].text; |
||
249 | local maxchar = DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].TextBox[id].maxcharacters; |
||
250 | local hideifnotext = DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].TextBox[id].hideifnotext; |
||
251 | local vert = DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].TextBox[id].verttext; |
||
252 | if ((not text) or text == "") then return; end |
||
253 | |||
254 | if (this.variables) then |
||
255 | for var in this.variables do |
||
256 | text = DUF_VARIABLE_FUNCTIONS[var].func(text, unit); |
||
257 | end |
||
258 | end |
||
259 | if (not text) then text = ""; end |
||
260 | if (maxchar) then |
||
261 | local numchar = string.len(text); |
||
262 | local count = 0; |
||
263 | for i in string.gfind(text, "|c") do |
||
264 | count = count + 1; |
||
265 | end |
||
266 | numchar = numchar - count * 10; |
||
267 | if (numchar > maxchar) then |
||
268 | text = string.sub(text, 1, maxchar + count * 10); |
||
269 | end |
||
270 | end |
||
271 | if (vert) then |
||
272 | text = string.gsub(text, "(.)", function(x) return x.."\n" end); |
||
273 | end |
||
274 | getglobal(this:GetName().."_Text"):SetText(text); |
||
275 | if (hideifnotext) then |
||
276 | if (text == "") then |
||
277 | getglobal(this:GetName().."_Background"):SetAlpha(0); |
||
278 | else |
||
279 | getglobal(this:GetName().."_Background"):SetAlpha(1); |
||
280 | end |
||
281 | end |
||
282 | end |