vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | |||
3 | TipBuddy: --------- |
||
4 | copyright 2005 by Chester |
||
5 | |||
6 | ]] |
||
7 | |||
8 | function TB_AddMessage( text ) |
||
9 | if (not text) then |
||
10 | return; |
||
11 | end |
||
12 | if (TipBuddy_SavedVars.debug) then |
||
13 | ChatFrame3:AddMessage(GREEN_FONT_COLOR_CODE..""..text..""); |
||
14 | end |
||
15 | end |
||
16 | |||
17 | --/script TipBuddy_SavedVars["textcolors"].nam_fri = TipBuddy_RGBToHexColor( 1, 0, 1 ); TipBuddy_InitializeTextColors(); |
||
18 | function TipBuddy_RGBToHexColor( r, g, b, text ) |
||
19 | --local num = 220; |
||
20 | if (not text) then |
||
21 | text = ""; |
||
22 | end |
||
23 | --TB_AddMessage(r..g..b..text); |
||
24 | r = string.format("%x", (format("%.1f", r))*255); |
||
25 | g = string.format("%x", (format("%.1f", g))*255); |
||
26 | b = string.format("%x", (format("%.1f", b))*255); |
||
27 | if (not r or r == "0" or r == 0) then |
||
28 | r = "00"; |
||
29 | end |
||
30 | if (not g or g == "0" or g == 0) then |
||
31 | g = "00"; |
||
32 | end |
||
33 | if (not b or b == "0" or b == 0) then |
||
34 | b = "00"; |
||
35 | end |
||
36 | --TB_AddMessage("cff"..r..g..b..text); |
||
37 | local hex = ("|cff"..r..g..b..text); |
||
38 | ----TB_AddMessage(hex); |
||
39 | return hex; |
||
40 | end |
||
41 | |||
42 | -------------------------------------------------------------------------------------------------------------------------------------- |
||
43 | -- GET TARGET TYPE |
||
44 | -------------------------------------------------------------------------------------------------------------------------------------- |
||
45 | function TipBuddy_TargetInfo_GetTargetType( unit ) |
||
46 | if (not unit) then |
||
47 | return; |
||
48 | end |
||
49 | if ( ( UnitHealth(unit) <= 0 ) ) then |
||
50 | return ( "corpse" ); |
||
51 | elseif ( ( UnitHealthMax(unit) > 0 ) ) then |
||
52 | if (string.find(unit, "party.+")) then |
||
53 | return ( "pc_party" ); |
||
54 | end |
||
55 | if (UnitPlayerControlled(unit)) then |
||
56 | if (UnitIsFriend(unit, "player")) then |
||
57 | if ( TipBuddy_TargetInfo_CheckPet() ) then |
||
58 | return ( "pet_friend" ); |
||
59 | end |
||
60 | |||
61 | if (UnitInParty(unit)) then |
||
62 | return ( "pc_party" ); |
||
63 | else |
||
64 | return ( "pc_friend" ); |
||
65 | end |
||
66 | elseif (UnitIsEnemy(unit, "player")) then |
||
67 | if ( TipBuddy_TargetInfo_CheckPet() ) then |
||
68 | return ( "pet_enemy" ); |
||
69 | else |
||
70 | return ( "pc_enemy" ); |
||
71 | end |
||
72 | else |
||
73 | return ( "pet_friend" ); |
||
74 | end |
||
75 | else |
||
76 | if (UnitIsFriend(unit, "player")) then |
||
77 | if ( TipBuddy_TargetInfo_CheckPet() ) then |
||
78 | return ( "pet_friend" ); |
||
79 | else |
||
80 | return ( "npc_friend" ); |
||
81 | end |
||
82 | elseif (UnitIsEnemy(unit, "player")) then |
||
83 | if ( TipBuddy_TargetInfo_CheckPet() ) then |
||
84 | return ( "pet_enemy" ); |
||
85 | else |
||
86 | return ( "npc_enemy" ); |
||
87 | end |
||
88 | else --neutral |
||
89 | return ( "npc_neutral" ); |
||
90 | end |
||
91 | end |
||
92 | else |
||
93 | TipBuddy_Hide( TipBuddy_Main_Frame ); |
||
94 | return; |
||
95 | end |
||
96 | end |
||
97 | |||
98 | function TB_GetHealth_Text( unit, type ) |
||
99 | --TipBuddy_HealthTextGTT, TipBuddy_UpdateHealthTextGTT( TipBuddy_HealthTextGTT, unit ) |
||
100 | --TipBuddy_HealthText |
||
101 | local health, healthmax; |
||
102 | if (type == "percent") then |
||
103 | health = UnitHealth(unit); |
||
104 | --local percent = tonumber(format("%.0f", ( (health / UnitHealthMax(unit)) * 100 ) )); |
||
105 | if ( unit == "player" or UnitInParty(unit) or UnitInRaid(unit)) then |
||
106 | --return health.."/"..UnitHealthMax(unit); |
||
107 | return tonumber(format("%.0f", ( (health / UnitHealthMax(unit)) * 100 ) )); |
||
108 | else |
||
109 | return health; |
||
110 | end |
||
111 | elseif (type == "current") then |
||
112 | health = UnitHealth(unit); |
||
113 | if ( unit == "player" or UnitInParty(unit) or UnitInRaid(unit)) then |
||
114 | return health; |
||
115 | else |
||
116 | if (MobHealthDB) then |
||
117 | local ppp = MobHealth_PPP(UnitName(unit)..":"..UnitLevel(unit)); |
||
118 | local curHP = math.floor(health * ppp + 0.5); |
||
119 | local maxHP = math.floor(100 * ppp + 0.5); |
||
120 | |||
121 | if (curHP and maxHP and maxHP ~= 0) then |
||
122 | return curHP; |
||
123 | else |
||
124 | return health; |
||
125 | end |
||
126 | else |
||
127 | return health; |
||
128 | end |
||
129 | end |
||
130 | else |
||
131 | healthmax = UnitHealthMax(unit); |
||
132 | if ( unit == "player" or UnitInParty(unit) or UnitInRaid(unit)) then |
||
133 | return healthmax; |
||
134 | else |
||
135 | if (MobHealthDB) then |
||
136 | local ppp = MobHealth_PPP(UnitName(unit)..":"..UnitLevel(unit)); |
||
137 | local maxHP = math.floor(100 * ppp + 0.5); |
||
138 | |||
139 | if (maxHP and maxHP ~= 0) then |
||
140 | return maxHP; |
||
141 | else |
||
142 | return healthmax; |
||
143 | end |
||
144 | else |
||
145 | return healthmax; |
||
146 | end |
||
147 | end |
||
148 | end |
||
149 | end |
||
150 | |||
151 | function TipBuddy_ReportVarStats() |
||
152 | if (TipBuddy_Main_Frame:IsVisible()) then |
||
153 | --TB_AddMessage("MainFrame Visible, alpha: "..TipBuddy_Main_Frame:GetAlpha()); |
||
154 | else |
||
155 | --TB_AddMessage("MainFrame NOT Visible"); |
||
156 | end |
||
157 | if (GameTooltip:IsVisible()) then |
||
158 | --TB_AddMessage("GTT Visible"); |
||
159 | --TB_AddMessage("GTT Bottom = "..GameTooltip:GetBottom()); |
||
160 | else |
||
161 | --TB_AddMessage("GTT NOT Visible"); |
||
162 | end |
||
163 | if (TipBuddy.hasTarget == 1) then |
||
164 | --TB_AddMessage("TB has target"); |
||
165 | else |
||
166 | --TB_AddMessage("TB does NOT have target"); |
||
167 | end |
||
168 | end |
||
169 | |||
170 | function TipBuddy_GetUIScale() |
||
171 | local uiScale; |
||
172 | if ( GetCVar("useUiScale") == "1" ) then |
||
173 | uiScale = tonumber(GetCVar("uiscale")); |
||
174 | if ( uiScale > 0.9 ) then |
||
175 | uiScale = 0.9; |
||
176 | end |
||
177 | else |
||
178 | uiScale = 0.9; |
||
179 | end |
||
180 | return uiScale; |
||
181 | end |
||
182 | |||
183 | function TipBuddy_GetEffectiveScale(frame) |
||
184 | return frame:GetEffectiveScale() |
||
185 | end |
||
186 | |||
187 | function TipBuddy_SetEffectiveScale(frame, scale, parentframe) |
||
188 | frame.scale = scale; -- Saved in case it needs to be re-calculated when the parent's scale changes. |
||
189 | local parent = getglobal(parentframe); |
||
190 | if ( parent ) then |
||
191 | scale = scale / GetEffectiveScale(parent); |
||
192 | end |
||
193 | frame:SetScale(scale); |
||
194 | end |
||
195 | |||
196 | |||
197 | function TipBuddy_GetDifficultyColor(level) |
||
198 | local levelDiff = level - UnitLevel("player"); |
||
199 | local color, text; |
||
200 | if ( levelDiff >= 5 ) then |
||
201 | color = tbcolor_lvl_impossible; |
||
202 | text = "Impossible"; |
||
203 | elseif ( levelDiff >= 3 ) then |
||
204 | color = tbcolor_lvl_verydifficult; |
||
205 | text = "Very Difficult"; |
||
206 | elseif ( levelDiff >= -2 ) then |
||
207 | color = tbcolor_lvl_difficult; |
||
208 | text = "Difficult"; |
||
209 | elseif ( -levelDiff <= GetQuestGreenRange() ) then |
||
210 | color = tbcolor_lvl_standard; |
||
211 | text = "Standard"; |
||
212 | else |
||
213 | color = tbcolor_lvl_trivial; |
||
214 | text = "Trivial"; |
||
215 | end |
||
216 | return color, text; |
||
217 | end |
||
218 | |||
219 | function TipBuddy_ForceHide(frame) |
||
220 | ------TB_AddMessage("TipBuddy_ForceHide"); |
||
221 | UIFrameFadeRemoveFrame(frame); |
||
222 | frame.fadingout = nil; |
||
223 | frame.fadingin = nil; |
||
224 | frame:SetAlpha(0); |
||
225 | frame:Hide(); |
||
226 | end |
||
227 | |||
228 | function TipBuddy_ClearFade(frame, alpha) |
||
229 | ------TB_AddMessage("TipBuddy_ForceHide"); |
||
230 | UIFrameFadeRemoveFrame(frame); |
||
231 | frame.fadingout = nil; |
||
232 | frame.fadingin = nil; |
||
233 | frame:SetAlpha(alpha); |
||
234 | end |
||
235 | |||
236 | function TipBuddy_FixMagicChars(text) |
||
237 | text = string.gsub(text, "%%", "%%%%"); |
||
238 | text = string.gsub(text, "%^", "%%%^"); |
||
239 | text = string.gsub(text, "%$", "%%%$"); |
||
240 | text = string.gsub(text, "%.", "%%%."); |
||
241 | text = string.gsub(text, "%*", "%%%*"); |
||
242 | text = string.gsub(text, "%+", "%%%+"); |
||
243 | text = string.gsub(text, "%-", "%%%-"); |
||
244 | text = string.gsub(text, "%?", "%%%?"); |
||
245 | return text; |
||
246 | end |
||
247 | |||
248 | |||
249 | function TB_NoNegative(num) |
||
250 | if (num < 0) then |
||
251 | num = 0; |
||
252 | return num; |
||
253 | else |
||
254 | return num; |
||
255 | end |
||
256 | end |
||
257 | |||
258 | -- Start the countdown on a frame |
||
259 | function TipBuddyPopup_StartCounting(frame) |
||
260 | if ( frame.parent ) then |
||
261 | TipBuddyPopup_StartCounting(frame.parent); |
||
262 | else |
||
263 | frame.showTimer = TB_POPUP_TIMER; |
||
264 | frame.isCounting = 1; |
||
265 | end |
||
266 | end |
||
267 | |||
268 | -- Stop the countdown on a frame |
||
269 | function TipBuddyPopup_StopCounting(frame) |
||
270 | if ( frame.parent ) then |
||
271 | TipBuddyPopup_StopCounting(frame.parent); |
||
272 | else |
||
273 | frame.isCounting = nil; |
||
274 | end |
||
275 | end |
||
276 | |||
277 | function TipBuddy_GetUnitReaction( unit ) |
||
278 | if ( UnitPlayerControlled(unit) ) then |
||
279 | if ( UnitCanAttack(unit, "player") ) then |
||
280 | -- Hostile players are red |
||
281 | if ( not UnitCanAttack("player", unit) ) then |
||
282 | return "caution"; |
||
283 | else |
||
284 | return "hostile"; |
||
285 | end |
||
286 | elseif ( UnitCanAttack("player", unit) ) then |
||
287 | -- Players we can attack but which are not hostile are yellow |
||
288 | return "neutral"; |
||
289 | elseif ( UnitIsPVP(unit) ) then |
||
290 | -- Players we can assist but are PvP flagged are green |
||
291 | return "pvp"; |
||
292 | else |
||
293 | -- All other players are blue (the usual state on the "blue" server) |
||
294 | return "friendly"; |
||
295 | end |
||
296 | elseif ( UnitIsFriend(unit, "player") and UnitIsPVP(unit) ) then |
||
297 | return "pvp"; |
||
298 | elseif ( UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) ) then |
||
299 | return "tappedother"; |
||
300 | elseif ( UnitIsTappedByPlayer(unit) ) then |
||
301 | return "tappedplayer"; |
||
302 | else |
||
303 | local reaction = UnitReaction(unit, "player"); |
||
304 | --/script DEFAULT_CHAT_FRAME:AddMessage(UnitReaction("target", "player")); |
||
305 | --/script DEFAULT_CHAT_FRAME:AddMessage(TipBuddyUnitReaction[4].r); |
||
306 | if ( reaction ) then |
||
307 | return TipBuddyUnitReaction[reaction].r; |
||
308 | else |
||
309 | return "friendly"; |
||
310 | end |
||
311 | end |
||
312 | end |
||
313 | |||
314 | function TipBuddy_ToggleExtras(type, quiet) |
||
315 | if (type == "on") then |
||
316 | TipBuddy_SavedVars["pc_friend"].xtr = 1; |
||
317 | TipBuddy_SavedVars["pc_enemy"].xtr = 1; |
||
318 | TipBuddy_SavedVars["pc_party"].xtr = 1; |
||
319 | TipBuddy_SavedVars["pet_friend"].xtr = 1; |
||
320 | TipBuddy_SavedVars["pet_enemy"].xtr = 1; |
||
321 | TipBuddy_SavedVars["npc_friend"].xtr = 1; |
||
322 | TipBuddy_SavedVars["npc_enemy"].xtr = 1; |
||
323 | TipBuddy_SavedVars["npc_neutral"].xtr = 1; |
||
324 | if (not quiet) then |
||
325 | DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Extras for all target types are now ON"); |
||
326 | end |
||
327 | return type; |
||
328 | elseif (type == "off") then |
||
329 | TipBuddy_SavedVars["pc_friend"].xtr = 0; |
||
330 | TipBuddy_SavedVars["pc_enemy"].xtr = 0; |
||
331 | TipBuddy_SavedVars["pc_party"].xtr = 0; |
||
332 | TipBuddy_SavedVars["pet_friend"].xtr = 0; |
||
333 | TipBuddy_SavedVars["pet_enemy"].xtr = 0; |
||
334 | TipBuddy_SavedVars["npc_friend"].xtr = 0; |
||
335 | TipBuddy_SavedVars["npc_enemy"].xtr = 0; |
||
336 | TipBuddy_SavedVars["npc_neutral"].xtr = 0; |
||
337 | if (not quiet) then |
||
338 | DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Extras for all target types are now OFF"); |
||
339 | end |
||
340 | return type; |
||
341 | elseif (type ~= nil) then |
||
342 | if (not TipBuddy_SavedVars[type]) then |
||
343 | DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Could not recognize target type: "..type); |
||
344 | return nil; |
||
345 | else |
||
346 | if (TipBuddy_SavedVars[type].xtr == 1) then |
||
347 | TipBuddy_SavedVars[type].xtr = 0; |
||
348 | DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: No longer showing extras for target type: "..type); |
||
349 | return type; |
||
350 | else |
||
351 | TipBuddy_SavedVars[type].xtr = 1; |
||
352 | DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Now showing extras for target type: "..type); |
||
353 | return type; |
||
354 | end |
||
355 | end |
||
356 | end |
||
357 | end |