vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | |||
3 | TrapsBar for WoW (World of Warcraft) |
||
4 | Desc: A row of buttons for your Hunter's Traps |
||
5 | |||
6 | LIST OF AUTHORS and FIXERS |
||
7 | Author 1: Permetheus with the TrapBar add-on |
||
8 | Author 2: CRiSPyToWN |
||
9 | |||
10 | ]]-- |
||
11 | |||
12 | TrapsBarData = { }; |
||
13 | |||
14 | --START |
||
15 | TRAP_IMMOLATION = "Immolation Trap"; |
||
16 | TRAP_FREEZE = "Freezing Trap"; |
||
17 | TRAP_FROST = "Frost Trap"; |
||
18 | TRAP_EXPLO = "Explosive Trap"; |
||
19 | |||
20 | if (GetLocale() == "frFR") then |
||
21 | TrapsBarData = { }; |
||
22 | TRAP_IMMOLATION = "Pi\195\168ge d'Immolation"; |
||
23 | TRAP_FREEZE = "Pi\195\168ge givrant"; |
||
24 | TRAP_FROST = "Pi\195\168ge de givre"; |
||
25 | TRAP_EXPLO = "Pi\195\168ge explosif"; |
||
26 | end |
||
27 | if (GetLocale() == "deDE") then |
||
28 | TrapsBarData = { }; |
||
29 | TRAP_IMMOLATION = "Feuerbrandfalle"; |
||
30 | TRAP_FREEZE = "Eisk\195\164ltefalle"; |
||
31 | TRAP_FROST = "Frostfalle"; |
||
32 | TRAP_EXPLO = "Sprengfalle"; |
||
33 | end |
||
34 | |||
35 | |||
36 | local Traps = { |
||
37 | TRAP_IMMOLATION, |
||
38 | TRAP_FREEZE, |
||
39 | TRAP_FROST, |
||
40 | TRAP_EXPLO, |
||
41 | }; |
||
42 | |||
43 | local ver = 125; |
||
44 | |||
45 | TrapsBar_ENABLED = true; |
||
46 | |||
47 | local playerName, vMounted, button; |
||
48 | |||
49 | function TrapsBar_OnLoad() |
||
50 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
51 | this:RegisterEvent("SPELLS_CHANGED"); |
||
52 | this:RegisterEvent("PLAYER_AURAS_CHANGED"); |
||
53 | this:RegisterEvent("SPELL_UPDATE_COOLDOWN"); |
||
54 | |||
55 | this:RegisterEvent("PLAYER_REGEN_ENABLED"); |
||
56 | this:RegisterEvent("PLAYER_REGEN_DISABLED"); |
||
57 | |||
58 | SLASH_TRAPSBAR1 = "/trapsbar"; |
||
59 | SlashCmdList["TRAPSBAR"] = function(msg) |
||
60 | TrapsBar_SlashHandler(string.lower(msg)); |
||
61 | end |
||
62 | end |
||
63 | |||
64 | function TrapsBar_SlashHandler(msg) |
||
65 | if (string.find(msg, "config")) then |
||
66 | TrapsBarConfig:Show(); |
||
67 | elseif (string.find(msg, "help")) then |
||
68 | DEFAULT_CHAT_FRAME:AddMessage("To configure bar type '/trapsbar config'"); |
||
69 | DEFAULT_CHAT_FRAME:AddMessage("To move the bar: Hold down the control key and right click the TrapsBar"); |
||
70 | else |
||
71 | DEFAULT_CHAT_FRAME:AddMessage("Type '/trapsbar help' for help"); |
||
72 | end |
||
73 | --tinsert(UISpecialFrames,"TrapsBarConfig"); |
||
74 | end |
||
75 | |||
76 | function StartTrapsBar() |
||
77 | if (not TrapsBarData) then |
||
78 | TrapsBarData[playerName] = { |
||
79 | ["hidebar"] = "false", |
||
80 | ["horizontal"] = "true", |
||
81 | ["order"] = "az", |
||
82 | ["scale"] = 1, |
||
83 | ["version"] = ver, |
||
84 | ["AlphaInCombat"] = 0, |
||
85 | ["AlphaOutCombat"] = 1, |
||
86 | }; |
||
87 | end |
||
88 | if (not TrapsBarData[playerName]) then |
||
89 | TrapsBarData[playerName] = { |
||
90 | ["hidebar"] = "false", |
||
91 | ["horizontal"] = "true", |
||
92 | ["order"] = "az", |
||
93 | ["scale"] = 1, |
||
94 | ["version"] = ver, |
||
95 | ["AlphaInCombat"] = 0, |
||
96 | ["AlphaOutCombat"] = 1, |
||
97 | }; |
||
98 | end |
||
99 | if (TrapsBarData[playerName]["version"] ~= ver) then |
||
100 | TrapsBarData[playerName]["version"] = ver; |
||
101 | end |
||
102 | TrapsBar_Update(); |
||
103 | TrapsBar_Scale(); |
||
104 | end |
||
105 | |||
106 | function FindPattern(text,pattern) |
||
107 | return string.sub(text, string.find(text, pattern)) |
||
108 | end |
||
109 | |||
110 | function TrapsBar_OnEvent() |
||
111 | if (event == "PLAYER_ENTERING_WORLD") then |
||
112 | if (UnitName("player") ~= UNKNOWNBEING and UnitName("player") ~= UNKNOWNOBJECT and UnitName("player") and not playerName) then |
||
113 | playerName = UnitName("player").." of "..GetCVar("realmName"); |
||
114 | end |
||
115 | StartTrapsBar(); |
||
116 | end |
||
117 | if (event == "SPELLS_CHANGED" or event == "PLAYER_AURAS_CHANGED") then |
||
118 | TrapsBar_Update(); |
||
119 | elseif (event == "SPELL_UPDATE_COOLDOWN") then |
||
120 | TrapsBar_UpdateCooldowns(); |
||
121 | elseif (event == "PLAYER_REGEN_ENABLED") then |
||
122 | TrapsBar_setAlpha(); |
||
123 | elseif (event == "PLAYER_REGEN_DISABLED") then |
||
124 | TrapsBar_setAlpha(); |
||
125 | end |
||
126 | end |
||
127 | |||
128 | function TrapsBar_Scale() |
||
129 | for i = 1, 4 do |
||
130 | button = getglobal("TrapsBarButton"..i); |
||
131 | button:SetScale(TrapsBarData[playerName]["scale"]); |
||
132 | end |
||
133 | end |
||
134 | |||
135 | function TrapsBar_O() |
||
136 | if (TrapsBarData[playerName]) then |
||
137 | if (not TrapsBarData[playerName]["horizontal"]) then |
||
138 | TrapsBarData[playerName]["horizontal"] = "true" |
||
139 | TrapsBarData[playerName]["order"] = "az" |
||
140 | end |
||
141 | if (TrapsBarData[playerName]["horizontal"] == "false" and TrapsBarData[playerName]["order"] == "az") then |
||
142 | for i = 2, 4 do |
||
143 | local button = getglobal("TrapsBarButton"..i); |
||
144 | button:ClearAllPoints(); |
||
145 | button:SetPoint("TOP", "TrapsBarButton"..i - 1, "BOTTOM", 0, 1); |
||
146 | end |
||
147 | elseif (TrapsBarData[playerName]["horizontal"] == "false" and TrapsBarData[playerName]["order"] == "za") then |
||
148 | for i = 2, 4 do |
||
149 | local button = getglobal("TrapsBarButton"..i); |
||
150 | button:ClearAllPoints(); |
||
151 | button:SetPoint("BOTTOM", "TrapsBarButton"..i - 1, "TOP", 0, 1); |
||
152 | end |
||
153 | elseif (TrapsBarData[playerName]["horizontal"] == "true" and TrapsBarData[playerName]["order"] == "az") then |
||
154 | for i = 2, 4 do |
||
155 | local button = getglobal("TrapsBarButton"..i); |
||
156 | button:ClearAllPoints(); |
||
157 | button:SetPoint("LEFT", "TrapsBarButton"..i - 1, "RIGHT", 1, 0); |
||
158 | end |
||
159 | elseif (TrapsBarData[playerName]["horizontal"] == "true" and TrapsBarData[playerName]["order"] == "za") then |
||
160 | for i = 2, 4 do |
||
161 | local button = getglobal("TrapsBarButton"..i); |
||
162 | button:ClearAllPoints(); |
||
163 | button:SetPoint("RIGHT", "TrapsBarButton"..i - 1, "LEFT", 1, 0); |
||
164 | end |
||
165 | else |
||
166 | for i = 2, 4 do |
||
167 | local button = getglobal("TrapsBarButton"..i); |
||
168 | button:ClearAllPoints(); |
||
169 | button:SetPoint("LEFT", "TrapsBarButton"..i - 1, "RIGHT", 1, 0); |
||
170 | end |
||
171 | end |
||
172 | end |
||
173 | end |
||
174 | |||
175 | function TrapsBar_Hide() |
||
176 | local frame = getglobal("TrapsBar"); |
||
177 | if (frame) then |
||
178 | if( frame:IsVisible() ) then |
||
179 | frame:Hide(); |
||
180 | else |
||
181 | frame:Show(); |
||
182 | end |
||
183 | end |
||
184 | end |
||
185 | |||
186 | function TrapsBar_Update() |
||
187 | if (TrapsBarData[playerName]) then |
||
188 | if (TrapsBarData[playerName]["hidebar"] == "false") then |
||
189 | TrapsBar_O(); |
||
190 | i = 0; |
||
191 | for key in Traps do |
||
192 | getglobal("TrapsBarButton"..key):Hide(); |
||
193 | end |
||
194 | TrapsBar:Show(); |
||
195 | for key, value in Traps do |
||
196 | local id = TrapsBar_GetSpellID(value); |
||
197 | if (id) then |
||
198 | i = i + 1; |
||
199 | button = getglobal("TrapsBarButton"..i); |
||
200 | local texture = GetSpellTexture(id, BOOKTYPE_SPELL); |
||
201 | getglobal("TrapsBarButton"..i.."Icon"):SetTexture(texture); |
||
202 | button.id = id; |
||
203 | button.texture = texture; |
||
204 | button:Show(); |
||
205 | end |
||
206 | end |
||
207 | if (i == 0) then |
||
208 | TrapsBar:Hide(); |
||
209 | end |
||
210 | end |
||
211 | end |
||
212 | end |
||
213 | |||
214 | function TrapsBar_UpdateCooldowns() |
||
215 | for i = 1, 4 do |
||
216 | button = getglobal("TrapsBarButton"..i); |
||
217 | if (button.id) then |
||
218 | local cooldown = getglobal(button:GetName().."Cooldown"); |
||
219 | local start, duration, enable = GetSpellCooldown(button.id, SpellBookFrame.bookType); |
||
220 | if (start > 0 and duration > 0) then |
||
221 | CooldownFrame_SetTimer(cooldown, start, duration, enable); |
||
222 | end |
||
223 | end |
||
224 | end |
||
225 | end |
||
226 | |||
227 | function TrapsBar_GetSpellID(spell, rank, debug) |
||
228 | local i = 1; |
||
229 | local spellID; |
||
230 | local highestRank; |
||
231 | |||
232 | while true do |
||
233 | local spellName, spellRank = GetSpellName(i, SpellBookFrame.bookType); |
||
234 | if (not spellName) then |
||
235 | break; |
||
236 | end |
||
237 | if (spellName == spell) then |
||
238 | if (rank) then |
||
239 | if (spellRank == rank) then |
||
240 | if (debug) then |
||
241 | DEFAULT_CHAT_FRAME:AddMessage("Found |cffffffff'"..spell.." ("..rank..")'|r at slot |cffffffff'"..i.."'", 0.1, 1.0, 0.0); |
||
242 | end |
||
243 | return i; |
||
244 | end |
||
245 | else |
||
246 | spellID = i; |
||
247 | highestRank = spellRank; |
||
248 | end |
||
249 | end |
||
250 | i = i + 1; |
||
251 | if (i > 400) then |
||
252 | break; |
||
253 | end |
||
254 | end |
||
255 | if (debug) then |
||
256 | DEFAULT_CHAT_FRAME:AddMessage("Could not find |cffffffff'"..spell.." ("..rank..")'", 1.0, 0.1, 0.0); |
||
257 | end |
||
258 | return spellID, highestRank; |
||
259 | end |
||
260 | |||
261 | function TrapsBar_SetTooltip() |
||
262 | if (this.id) then |
||
263 | GameTooltip_SetDefaultAnchor(GameTooltip, this); |
||
264 | GameTooltip:SetSpell(this.id, SpellBookFrame.bookType); |
||
265 | GameTooltip:Show(); |
||
266 | end |
||
267 | end |
||
268 | |||
269 | function TrapsBar_OnClick() |
||
270 | if (this.id and arg1 == "LeftButton") then |
||
271 | CastSpell(this.id, BOOKTYPE_SPELL); |
||
272 | end |
||
273 | end |
||
274 | |||
275 | function TrapsBar_OnBind(that_spell) |
||
276 | local spellID = TrapsBar_GetSpellID(that_spell); |
||
277 | CastSpell(spellID, BOOKTYPE_SPELL); |
||
278 | end |
||
279 | |||
280 | function TrapsBarGetPoint() |
||
281 | local vLeft = TrapsBar:GetLeft(); |
||
282 | local vTop = TrapsBar:GetTop(); |
||
283 | TrapsBarData[playerName]["left"] = vLeft; |
||
284 | TrapsBarData[playerName]["top"] = vTop; |
||
285 | -- DEFAULT_CHAT_FRAME:AddMessage(vLeft.." "..vTop); |
||
286 | end |
||
287 | |||
288 | function TrapsBar_setAlpha() |
||
289 | local frame = getglobal("TrapsBar"); |
||
290 | if (event == "PLAYER_REGEN_DISABLED") then |
||
291 | frame:SetAlpha(TrapsBarData[playerName]["AlphaInCombat"]); |
||
292 | else |
||
293 | frame:SetAlpha(TrapsBarData[playerName]["AlphaOutCombat"]); |
||
294 | end |
||
295 | end |
||
296 | |||
297 | -- CONFIG |
||
298 | |||
299 | -- OnShow |
||
300 | function TrapsBarConfig_OnShow() |
||
301 | if (not TrapsBarData) then |
||
302 | this:Hide(); |
||
303 | return; |
||
304 | end |
||
305 | if (not TrapsBarData[playerName]) then |
||
306 | this:Hide(); |
||
307 | return; |
||
308 | end |
||
309 | TrapsBarConfigCheckButton1:SetChecked( TrapsBarData[playerName]["horizontal"] ); |
||
310 | TrapsBarConfigCheckButton2:SetChecked( TrapsBarData[playerName]["hidebar"] ); |
||
311 | TrapsBarConfigSliderScale:SetValue( TrapsBarData[playerName]["scale"] ); |
||
312 | end |
||
313 | |||
314 | function TrapsBarConfigScale_OnClick() |
||
315 | TrapsBarData[playerName]["scale"] = this:GetValue(); |
||
316 | TrapsBar_Scale(); |
||
317 | end |
||
318 | |||
319 | function TrapsBarConfigCheckBoxHide_OnClick() |
||
320 | if (TrapsBarData[playerName]["hidebar"] == "true") then |
||
321 | TrapsBarData[playerName]["hidebar"] = "false"; |
||
322 | else |
||
323 | TrapsBarData[playerName]["hidebar"] = "true"; |
||
324 | end |
||
325 | TrapsBar_Hide(); |
||
326 | TrapsBar_Update(); |
||
327 | end |
||
328 | |||
329 | function TrapsBarConfigCheckBoxOrder_OnClick() |
||
330 | if (TrapsBarData[playerName]["order"] == "az") then |
||
331 | TrapsBarData[playerName]["order"] = "za"; |
||
332 | else |
||
333 | TrapsBarData[playerName]["order"] = "az" |
||
334 | end |
||
335 | TrapsBar_O(); |
||
336 | end |
||
337 | |||
338 | function TrapsBarConfigCheckBox_OnClick() |
||
339 | if (TrapsBarData[playerName]["horizontal"] == "true") then |
||
340 | TrapsBarData[playerName]["horizontal"] = "false"; |
||
341 | else |
||
342 | TrapsBarData[playerName]["horizontal"] = "true" |
||
343 | end |
||
344 | TrapsBar_O(); |
||
345 | end |