vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 NURFED_GENERAL_VERS = "07.01.2006";
3  
4 NURFED_GENERAL_DEFAULT = {
5 repair = 1;
6 repairinv = 1;
7 repairlimit = 20;
8 ping = 1;
9 traineravailable = 1;
10 timestamps = 1;
11 timeoffset = 0;
12 ampm = 1;
13 raidgroup = 1;
14 raidclass = 1;
15 hidechat = 1;
16 chatfade = 1;
17 chatfadetime = 120;
18 autoinvite = 1;
19 chatprefix = 1;
20 keyword = "invite";
21 };
22  
23 ChatTypeInfo["CHANNEL"].sticky = 1;
24 ChatTypeInfo["OFFICER"].sticky = 1;
25 UnitPopupButtons["INSPECT"] = { text = TEXT(INSPECT), dist = 0 };
26 ManaBarColor[0] = { r = 0.00, g = 1.00, b = 1.00, prefix = TEXT(MANA) };
27  
28 local utility = Nurfed_Utility:New();
29 local unitlib = Nurfed_Units:New();
30 local framelib = Nurfed_Frames:New();
31 local lib = Nurfed_General:New();
32 local options = Nurfed_Options:New();
33 local currtime = 0;
34 local pingflood = {};
35 local raidtarget = {
36 [RAID_TARGET_1] = 1,
37 [RAID_TARGET_2] = 2,
38 [RAID_TARGET_3] = 3,
39 [RAID_TARGET_4] = 4,
40 [RAID_TARGET_5] = 5,
41 [RAID_TARGET_6] = 6,
42 [RAID_TARGET_7] = 7,
43 [RAID_TARGET_8] = 8,
44 };
45  
46 --------------------------------------------------------------------------------------------------
47 -- Slash Commands
48 --------------------------------------------------------------------------------------------------
49  
50 SLASH_NURFEDEQUIP1 = "/nequip";
51 SlashCmdList["NURFEDEQUIP"] = function(msg)
52 lib:itemswitch(msg);
53 end
54  
55 SLASH_NURFEDWHISPER1 = "/wtar";
56 SlashCmdList["NURFEDWHISPER"] = function(msg)
57 if (UnitExists("target")) then
58 SendChatMessage(msg, "WHISPER", this.language, UnitName("target"));
59 end
60 end
61  
62 SLASH_NURFEDRAIDTARGET1 = "/rtar";
63 SlashCmdList["NURFEDRAIDTARGET"] = function(msg)
64 Nurfed_RaidTarget(msg);
65 end
66  
67 --------------------------------------------------------------------------------------------------
68 -- Put a -- in front of DAMAGE_TEXT_FONT to change back the damage font (cannot be in game).
69 --------------------------------------------------------------------------------------------------
70  
71 DAMAGE_TEXT_FONT = "Fonts\\skurri.ttf";
72  
73 --------------------------------------------------------------------------------------------------
74 -- Chat Frame Functions
75 --------------------------------------------------------------------------------------------------
76  
77  
78 local function Nurfed_AddMessage(this, msg, r, g, b, id)
79 if (msg) then
80 local prefix = options:GetOption("general", "chatprefix");
81 local text = {};
82 if(options:GetOption("general", "timestamps") == 1) then
83 local hour, minute = GetGameTime();
84 local second = GetTime() - currtime;
85 if (second > 59) then
86 second = 0;
87 end
88 hour = hour + options:GetOption("general", "timeoffset");
89 if( hour > 23 ) then
90 hour = hour - 24;
91 elseif( hour < 0 ) then
92 hour = 24 + hour;
93 end
94 if (options:GetOption("general", "ampm") == 1) then
95 if (hour >= 12) then
96 hour = hour - 12;
97 end
98 if (hour == 0) then
99 hour = 12;
100 end
101 end
102 local timestamp = format("[%d:%02d:%02d]", hour, minute, second);
103 table.insert(text, timestamp);
104 end
105  
106 if (string.find(msg, "["..RAID.."]", 1, true)) then
107 local info = unitlib:GetUnit(arg2);
108 if (info) then
109 msg = string.gsub(msg, "%["..RAID.."%] ", "");
110 if (prefix == 1) then
111 table.insert(text, "["..RAID.."]");
112 end
113 if (options:GetOption("general", "raidgroup") == 1) then
114 table.insert(text, "["..info.g.."]");
115 end
116 if (options:GetOption("general", "raidclass") == 1) then
117 table.insert(text, "["..info.c.."]");
118 end
119 end
120 end
121 if (prefix ~= 1) then
122 msg = string.gsub(msg, "%["..CHAT_MSG_OFFICER.."%] ", "");
123 msg = string.gsub(msg, "%["..CHAT_MSG_GUILD.."%] ", "");
124 msg = string.gsub(msg, "%["..CHAT_MSG_PARTY.."%] ", "");
125 msg = string.gsub(msg, "%["..CHAT_MSG_RAID.."%] ", "");
126 msg = string.gsub(msg, "%["..CHAT_MSG_RAID_LEADER.."%] ", "");
127 msg = string.gsub(msg, "%["..CHAT_MSG_RAID_WARNING.."%] ", "");
128 end
129 table.insert(text, msg);
130 this:Original_AddMessage(table.concat(text, " "), r, g, b, id);
131 end
132 end
133  
134 local Original_ChatFrame_OnEvent = ChatFrame_OnEvent;
135  
136 local function Nurfed_ChatFrame_OnEvent(event)
137 if (event == "CHAT_MSG_SYSTEM" and arg1 ~= nil) then
138 local _, _, name, id, days, hours, minutes, seconds = string.find(arg1, "(.+) %(ID=(%x+)%): (%d+)d (%d+)h (%d+)m (%d+)s")
139 if (name ~= nil) then
140 local timeTable = date("*t");
141 timeTable["sec"] = timeTable["sec"] + (days * 86400) + (hours * 3600) + (minutes * 60) + seconds;
142 arg1 = name.." (ID="..id.."): "..date("%A %B %d at %I:%M %p", time(timeTable)).."";
143 end
144 if (options:GetOption("general", "autoinvite") == 1) then
145 if (string.find(arg1, ERR_GROUP_FULL, 1, true)) then
146 local lastTell = ChatEdit_GetLastTellTarget(DEFAULT_CHAT_FRAME.editBox);
147 SendChatMessage("Party Full", "WHISPER", this.language, lastTell);
148 else
149 local ingroup = utility:FormatGS(ERR_ALREADY_IN_GROUP_S, true);
150 local result = { string.find(arg1, ingroup) };
151 if (result[1]) then
152 SendChatMessage("Drop group and resend '"..options:GetOption("general", "keyword").."'", "WHISPER", this.language, result[3]);
153 end
154 end
155 end
156 elseif (event == "CHAT_MSG_WHISPER" and arg1 ~= nil) then
157 if (options:GetOption("general", "autoinvite") == 1) then
158 if (IsPartyLeader() or IsRaidLeader() or IsRaidOfficer()) then
159 local text = string.lower(arg1);
160 local keyword = string.lower(options:GetOption("general", "keyword"));
161 if (string.find(text, "^"..keyword)) then
162 InviteByName(arg2);
163 end
164 end
165 end
166 elseif (event == "CHAT_MSG_WHISPER_INFORM") then
167 if (string.find(arg1, "^%!ndkp")) then
168 return;
169 end
170 end
171 Original_ChatFrame_OnEvent(event);
172 if(not this.Original_AddMessage) then
173 this.Original_AddMessage = this.AddMessage;
174 this.AddMessage = Nurfed_AddMessage;
175 end
176 end
177  
178 utility:Hook("replace", "ChatFrame_OnEvent", Nurfed_ChatFrame_OnEvent);
179  
180 --------------------------------------------------------------------------------------------------
181 -- Buff Duration Add Seconds
182 --------------------------------------------------------------------------------------------------
183  
184 local function Nurfed_SecondsToTimeAbbrev(seconds)
185 local time = "";
186 local tempTime;
187 local tempTime2;
188 if ( seconds > 86400 ) then
189 tempTime = ceil(seconds / 86400);
190 time = tempTime.." "..DAY_ONELETTER_ABBR;
191 return time;
192 end
193 if ( seconds > 3600 ) then
194 tempTime = ceil(seconds / 3600);
195 time = tempTime.." "..HOUR_ONELETTER_ABBR;
196 return time;
197 end
198 if ( seconds > 60 ) then
199 tempTime = floor(seconds / 60);
200 tempTime2 = floor(seconds-(tempTime)*60);
201 time = format("%02d:%02d", tempTime, tempTime2);
202 return time;
203 end
204 time = format("00:%02d", seconds);
205 return time;
206 end
207  
208 SecondsToTimeAbbrev = Nurfed_SecondsToTimeAbbrev;
209  
210 --------------------------------------------------------------------------------------------------
211 -- Create Frame
212 --------------------------------------------------------------------------------------------------
213  
214 -- adds guild info to a line in the inspect frame
215 local function Nurfed_InspectOnShow()
216 InspectPaperDollFrame_OnShow();
217 local guildname, guildtitle = GetGuildInfo("target");
218 if(guildname and guildtitle) then
219 InspectTitleText:SetText(format(TEXT(GUILD_TITLE_TEMPLATE), guildtitle, guildname));
220 InspectTitleText:Show();
221 else
222 InspectTitleText:Hide();
223 end
224 end
225  
226 local orig_chatframeOnShow = ChatFrame1:GetScript("OnShow");
227  
228 local function togglechat()
229 local hidden = options:GetOption("general", "hidechat");
230 local fade = options:GetOption("general", "chatfade");
231 local fadetime = options:GetOption("general", "chatfadetime");
232 for i = 1, 7 do
233 local chatframe = getglobal("ChatFrame"..i);
234 local up = getglobal("ChatFrame"..i.."UpButton");
235 local down = getglobal("ChatFrame"..i.."DownButton");
236 local bottom = getglobal("ChatFrame"..i.."BottomButton");
237 if (hidden == 1) then
238 chatframe:SetScript("OnShow", function() SetChatWindowShown(this:GetID(), 1) end);
239 up:Hide();
240 down:Hide();
241 bottom:Hide();
242 if (i == 1) then
243 ChatFrameMenuButton:Hide();
244 end
245 else
246 chatframe:SetScript("OnShow", orig_chatframeOnShow);
247 up:Show();
248 down:Show();
249 bottom:Show();
250 if (i == 1) then
251 ChatFrameMenuButton:Show();
252 end
253 end
254 chatframe:SetFading(fade);
255 chatframe:SetTimeVisible(fadetime);
256 end
257 end
258  
259 local function Nurfed_General_OnEvent()
260 if (event == "PLAYER_ENTERING_WORLD") then
261 this:UnregisterEvent(event);
262 togglechat();
263 elseif (event == "TRAINER_SHOW") then
264 if(options:GetOption("general", "traineravailable") == 1) then
265 SetTrainerServiceTypeFilter("unavailable",0);
266 end
267 elseif (event == "MERCHANT_SHOW") then
268 if (options:GetOption("general", "repair") == 1) then
269 lib:repair(options:GetOption("general", "repairlimit"), options:GetOption("general", "repairinv"));
270 end
271 elseif (event == "MINIMAP_PING") then
272 if(options:GetOption("general", "ping") == 1) then
273 local name = UnitName(arg1);
274 if (name ~= UnitName("player") and not pingflood[name]) then
275 utility:Print(name.." Ping.", 1, 1, 1, 0);
276 pingflood[name] = GetTime();
277 end
278 end
279 elseif (event == "ADDON_LOADED" and arg1 == "Blizzard_InspectUI") then
280 InspectPaperDollFrame:SetScript("OnShow", Nurfed_InspectOnShow);
281 end
282 end
283  
284 function Nurfed_General_OnUpdate(arg1)
285 this.update = this.update + arg1;
286 if (this.update > 0.5) then
287 local hour, minute = GetGameTime();
288 if (minute ~= this.lastmin) then
289 currtime = GetTime();
290 this.lastmin = minute;
291 end
292  
293 local svol = GetCVar("MasterVolume")+0;
294 if (svol > 0.5) then
295 SetCVar("MasterVolume", svol-0.05);
296 else
297 SetCVar("MasterVolume", svol+0.05);
298 end
299 SetCVar("MasterVolume", svol);
300  
301 for n, t in pingflood do
302 if (GetTime() - t > 1) then
303 pingflood[n] = nil;
304 end
305 end
306 end
307 end
308  
309 local tbl = {
310 type = "Frame",
311 events = {
312 "PLAYER_ENTERING_WORLD",
313 "MINIMAP_PING",
314 "ADDON_LOADED",
315 "TRAINER_SHOW",
316 "MERCHANT_SHOW"
317 },
318 OnEvent = function() Nurfed_General_OnEvent() end,
319 OnUpdate = function() Nurfed_General_OnUpdate(arg1) end,
320 vars = { update = 0, lastmin = 0 },
321 };
322  
323 local config = {
324 type = "Frame",
325 Anchor = { "TOP", "$parenttitlebg", "BOTTOM", 0, -1 },
326 children = {
327 check1 = {
328 template = "Nurfed_OptionCheck",
329 properties = {
330 Anchor = { "TOPLEFT", "$parent", "TOPLEFT", 0, 0 },
331 vars = {
332 text = NRF_AUTOREPAIR,
333 option = "repair",
334 },
335 },
336 },
337 check2 = {
338 template = "Nurfed_OptionCheck",
339 properties = {
340 Anchor = { "TOPLEFT", "$parentcheck1", "BOTTOMLEFT", 0, -3 },
341 vars = {
342 text = NRF_INVREPAIR,
343 option = "repairinv",
344 },
345 },
346 },
347 check3 = {
348 template = "Nurfed_OptionCheck",
349 properties = {
350 Anchor = { "TOPLEFT", "$parentcheck2", "BOTTOMLEFT", 0, -3 },
351 vars = {
352 text = NRF_PINGWARNING,
353 option = "ping",
354 },
355 },
356 },
357 check4 = {
358 template = "Nurfed_OptionCheck",
359 properties = {
360 Anchor = { "TOPLEFT", "$parentcheck3", "BOTTOMLEFT", 0, -3 },
361 vars = {
362 text = NRF_UNTRAINABLE,
363 option = "traineravailable",
364 },
365 },
366 },
367 check5 = {
368 template = "Nurfed_OptionCheck",
369 properties = {
370 Anchor = { "TOPLEFT", "$parentcheck4", "BOTTOMLEFT", 0, -3 },
371 vars = {
372 text = NRF_CHATTIMESTAMPS,
373 option = "timestamps",
374 },
375 },
376 },
377 check6 = {
378 template = "Nurfed_OptionCheck",
379 properties = {
380 Anchor = { "TOPLEFT", "$parentcheck5", "BOTTOMLEFT", 0, -3 },
381 vars = {
382 text = NRF_TWELVEHOUR,
383 option = "ampm",
384 },
385 },
386 },
387 check7 = {
388 template = "Nurfed_OptionCheck",
389 properties = {
390 Anchor = { "TOPLEFT", "$parentcheck6", "BOTTOMLEFT", 0, -3 },
391 vars = {
392 text = NRF_RAIDGROUP,
393 option = "raidgroup",
394 },
395 },
396 },
397 check8 = {
398 template = "Nurfed_OptionCheck",
399 properties = {
400 Anchor = { "TOPLEFT", "$parentcheck7", "BOTTOMLEFT", 0, -3 },
401 vars = {
402 text = NRF_RAIDCLASS,
403 option = "raidclass",
404 },
405 },
406 },
407 check9 = {
408 template = "Nurfed_OptionCheck",
409 properties = {
410 Anchor = { "TOPLEFT", "$parentcheck8", "BOTTOMLEFT", 0, -3 },
411 vars = {
412 text = NRF_CHATBUTTONS,
413 option = "hidechat",
414 func = function() togglechat() end,
415 },
416 },
417 },
418 check10 = {
419 template = "Nurfed_OptionCheck",
420 properties = {
421 Anchor = { "TOPLEFT", "$parentcheck9", "BOTTOMLEFT", 0, -3 },
422 vars = {
423 text = NRF_CHATPREFIX,
424 option = "chatprefix",
425 },
426 },
427 },
428  
429 slider1 = {
430 template = "Nurfed_OptionSlider",
431 properties = {
432 Anchor = { "TOPRIGHT", "$parent", "TOPRIGHT", -2, -12 },
433 vars = {
434 text = NRF_REPAIRLIMIT,
435 option = "repairlimit",
436 max = 100,
437 min = 0,
438 step = 1,
439 format = "%.0f",
440 },
441 },
442 },
443 slider2 = {
444 template = "Nurfed_OptionSlider",
445 properties = {
446 Anchor = { "TOPRIGHT", "$parentslider1", "BOTTOMRIGHT", 0, -15 },
447 vars = {
448 text = NRF_TIMEOFFSET,
449 option = "timeoffset",
450 max = 12,
451 min = -12,
452 step = 0.5,
453 format = "%.1f",
454 },
455 },
456 },
457 check11 = {
458 template = "Nurfed_OptionCheck",
459 properties = {
460 Anchor = { "TOPRIGHT", "$parentslider2", "BOTTOMRIGHT", 0, -14 },
461 vars = {
462 right = true,
463 text = NRF_AUTOINVITE,
464 option = "autoinvite",
465 },
466 },
467 },
468 input1 = {
469 template = "Nurfed_OptionInput",
470 properties = {
471 Anchor = { "TOPRIGHT", "$parentcheck11", "BOTTOMRIGHT", 0, 3 },
472 vars = {
473 text = NRF_KEYWORD,
474 option = "keyword",
475 },
476 },
477 },
478 check12 = {
479 template = "Nurfed_OptionCheck",
480 properties = {
481 Anchor = { "TOPRIGHT", "$parentinput1", "BOTTOMRIGHT", 0, -10 },
482 vars = {
483 right = true,
484 text = NRF_CHATFADE,
485 option = "chatfade",
486 func = function() togglechat() end,
487 },
488 },
489 },
490 slider3 = {
491 template = "Nurfed_OptionSlider",
492 properties = {
493 Anchor = { "TOPRIGHT", "$parentcheck12", "BOTTOMRIGHT", 0, -15 },
494 vars = {
495 text = NRF_CHATFADETIME,
496 option = "chatfadetime",
497 max = 250,
498 min = 0,
499 step = 1,
500 format = "%.0f",
501 func = function() togglechat() end,
502 },
503 },
504 },
505 },
506 vars = { width = 350, height = 240 },
507 };
508  
509 local function chatOnMouseWheel()
510 if (IsShiftKeyDown()) then
511 if (arg1 > 0) then
512 this:PageUp()
513 elseif (arg1 < 0) then
514 this:PageDown();
515 end
516 elseif (IsControlKeyDown()) then
517 if (arg1 > 0) then
518 this:ScrollToTop()
519 elseif (arg1 < 0) then
520 this:ScrollToBottom();
521 end
522 else
523 if (arg1 > 0) then
524 this:ScrollUp();
525 elseif (arg1 < 0) then
526 this:ScrollDown();
527 end
528 end
529 end
530  
531 function Nurfed_General_Init()
532 framelib:ObjectInit("Nurfed_GeneralFrame", tbl, UIParent);
533 framelib:ObjectInit("Nurfed_General_Menu", config, Nurfed_OptionsFrame);
534 tbl = nil;
535 config = nil;
536 lib:updatemount();
537 lib:updateaqmount();
538  
539 for i = 1, 7 do
540 local chatframe = getglobal("ChatFrame"..i);
541 chatframe:EnableMouseWheel(1);
542 chatframe:SetScript("OnMouseWheel", function() chatOnMouseWheel(); end);
543 end
544 end
545  
546 --------------------------------------------------------------------------------------------------
547 -- Misc Functions
548 --------------------------------------------------------------------------------------------------
549  
550 function Nurfed_Mount()
551 local bag, slot = lib:getmount();
552 if (bag and slot) then
553 UseContainerItem(bag, slot);
554 end
555 end
556  
557 function Nurfed_RaidTarget(tar)
558 if (not string.find(tar, "[1-9]")) then
559 tar = string.lower(tar);
560 tar = string.gsub(tar, "^%l", string.upper);
561 if (raidtarget[tar]) then
562 tar = raidtarget[tar];
563 end
564 end
565 tar = tonumber(tar);
566 for i = 1, GetNumRaidMembers() do
567 local unit = "raid"..i;
568 local target = "raid"..i.."target";
569 if (UnitExists(unit) and UnitExists(target)) then
570 if (GetRaidTargetIndex(target) == tar) then
571 TargetUnit(target);
572 return;
573 end
574 end
575 end
576 end