vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 WIM_VERSION = "1.2.10";
2  
3 WIM_Windows = {};
4 WIM_EditBoxInFocus = nil;
5 WIM_NewMessageFlag = false;
6 WIM_NewMessageCount = 0;
7 WIM_Icon_TheMenu = nil;
8 WIM_Icon_UpdateInterval = .5;
9 WIM_CascadeStep = 0;
10 WIM_MaxMenuCount = 20;
11 WIM_ClassIcons = {};
12 WIM_ClassColors = {};
13  
14 WIM_AlreadyCheckedGuildRoster = false;
15  
16 WIM_GuildList = {}; --[Not saved between sessions: Autopopulates from GUILD_ROSTER_UPDATE event
17 WIM_FriendList = {}; --[Not saved between sessions: Autopopulates from FRIENDLIST_SHOW & FRIENDLIST_UPDATE event
18  
19 WIM_Alias = {};
20 WIM_Filters = nil;
21  
22 WIM_ToggleWindow_Timer = 0;
23 WIM_ToggleWindow_Index = 1;
24  
25 WIM_RecentList = {}; --[Not saved between sessions: Store's list of recent conversations.
26  
27 WIM_History = {};
28  
29 WIM_Data_DEFAULTS = {
30 versionLastLoaded = "",
31 showChangeLogOnNewVersion = true,
32 enableWIM = true,
33 iconPosition=337,
34 showMiniMap=true,
35 displayColors = {
36 wispIn = {r=0.5607843137254902, g=0.03137254901960784, b=0.7607843137254902},
37 wispOut = {r=1, g=0.07843137254901961, b=0.9882352941176471},
38 sysMsg = {r=1, g=0.6627450980392157, b=0},
39 errorMsg = {r=1, g=0, b=0},
40 webAddress = {r=0, g=0, b=1},
41 },
42 fontSize = 12,
43 windowSize = 1,
44 windowAlpha = .8,
45 supressWisps = true,
46 keepFocus = false,
47 popNew = true,
48 popUpdate = true,
49 popOnSend = true,
50 popCombat = false,
51 autoFocus = false,
52 playSoundWisp = true,
53 showToolTips = true,
54 sortAlpha = true,
55 winSize = {
56 width = 384,
57 height = 256
58 },
59 winLoc = {
60 left =242 ,
61 top =775
62 },
63 winCascade = {
64 enabled = true,
65 direction = "downright"
66 },
67 miniFreeMoving = {
68 enabled = false;
69 left = 0,
70 top = 0
71 },
72 characterInfo = {
73 show = true,
74 classIcon = true,
75 details = true,
76 classColor = true
77 },
78 showTimeStamps = true,
79 showShortcutBar = true,
80 enableAlias = true,
81 enableFilter = true,
82 aliasAsComment = true,
83 enableHistory = true,
84 historySettings = {
85 recordEveryone = false,
86 recordFriends = true,
87 recordGuild = true,
88 colorIn = {
89 r=0.4705882352941176,
90 g=0.4705882352941176,
91 b=0.4705882352941176
92 },
93 colorOut = {
94 r=0.7058823529411764,
95 g=0.7058823529411764,
96 b=0.7058823529411764
97 },
98 popWin = {
99 enabled = true,
100 count = 25
101 },
102 maxMsg = {
103 enabled = true,
104 count = 200
105 },
106 autoDelete = {
107 enabled = true,
108 days = 7
109 }
110 }
111 };
112 --[initialize defualt values
113 WIM_Data = WIM_Data_DEFAULTS;
114  
115 WIM_CascadeDirection = {
116 up = {
117 left = 0,
118 top = 25
119 },
120 down = {
121 left = 0,
122 top = -25
123 },
124 left = {
125 left = -50,
126 top = 0
127 },
128 right = {
129 left = 50,
130 top = 0
131 },
132 upleft = {
133 left = -50,
134 top = 25
135 },
136 upright = {
137 left = 50,
138 top = 25
139 },
140 downleft = {
141 left = -50,
142 top = -25
143 },
144 downright = {
145 left = 50,
146 top = -25
147 }
148 };
149  
150 WIM_IconItems = { };
151  
152 function WIM_OnLoad()
153 SlashCmdList["WIM"] = WIM_SlashCommand;
154 SLASH_WIM1 = "/wim";
155 end
156  
157  
158 function WIM_Incoming(event)
159 --[Events
160 if(event == "VARIABLES_LOADED") then
161 if(WIM_Data.enableWIM == nil) then WIM_Data.enableWIM = WIM_Data_DEFAULTS.enableWIM; end;
162 if(WIM_Data.versionLastLoaded == nil) then WIM_Data.versionLastLoaded = ""; end;
163 if(WIM_Data.showChangeLogOnNewVersion == nil) then WIM_Data.showChangeLogOnNewVersion = WIM_Data_DEFAULTS.showChangeLogOnNewVersion; end;
164 if(WIM_Data.displayColors == nil) then WIM_Data.displayColors = WIM_Data_DEFAULTS.displayColors; end;
165 if(WIM_Data.displayColors.sysMsg == nil) then WIM_Data.displayColors.sysMsg = WIM_Data_DEFAULTS.displayColors.sysMsg; end;
166 if(WIM_Data.displayColors.errorMsg == nil) then WIM_Data.displayColors.errorMsg = WIM_Data_DEFAULTS.displayColors.errorMsg; end;
167 if(WIM_Data.fontSize == nil) then WIM_Data.fontSize = WIM_Data_DEFAULTS.fontSize; end;
168 if(WIM_Data.windowSize == nil) then WIM_Data.windowSize = WIM_Data_DEFAULTS.windowSize; end;
169 if(WIM_Data.windowAlpha == nil) then WIM_Data.windowAlpha = WIM_Data_DEFAULTS.windowAlpha; end;
170 if(WIM_Data.supressWisps == nil) then WIM_Data.supressWisps = WIM_Data_DEFAULTS.supressWisps; end;
171 if(WIM_Data.keepFocus == nil) then WIM_Data.keepFocus = WIM_Data_DEFAULTS.keepFocus; end;
172 if(WIM_Data.popNew == nil) then WIM_Data.popNew = WIM_Data_DEFAULTS.popNew; end;
173 if(WIM_Data.popUpdate == nil) then WIM_Data.popNew = WIM_Data_DEFAULTS.popUpdate; end;
174 if(WIM_Data.autoFocus == nil) then WIM_Data.autoFocus = WIM_Data_DEFAULTS.autoFocus; end;
175 if(WIM_Data.playSoundWisp == nil) then WIM_Data.playSoundWisp = WIM_Data_DEFAULTS.playSoundWisp; end;
176 if(WIM_Data.showToolTips == nil) then WIM_Data.showToolTips = WIM_Data_DEFAULTS.showToolTips; end;
177 if(WIM_Data.sortAlpha == nil) then WIM_Data.sortAlpha = WIM_Data_DEFAULTS.sortAlpha; end;
178 if(WIM_Data.winSize == nil) then WIM_Data.winSize = WIM_Data_DEFAULTS.winSize; end;
179 if(WIM_Data.miniFreeMoving == nil) then WIM_Data.miniFreeMoving = WIM_Data_DEFAULTS.miniFreeMoving; end;
180 if(WIM_Data.popCombat == nil) then WIM_Data.popCombat = WIM_Data_DEFAULTS.popCombat; end;
181 if(WIM_Data.characterInfo == nil) then WIM_Data.characterInfo = WIM_Data_DEFAULTS.characterInfo; end;
182 if(WIM_Data.showTimeStamps == nil) then WIM_Data.showTimeStamps = WIM_Data_DEFAULTS.showTimeStamps; end;
183 if(WIM_Data.showShortcutBar == nil) then WIM_Data.showShortcutBar = WIM_Data_DEFAULTS.showShortcutBar; end;
184 if(WIM_Data.enableAlias == nil) then WIM_Data.enableAlias = WIM_Data_DEFAULTS.enableAlias; end;
185 if(WIM_Data.enableFilter == nil) then WIM_Data.enableFilter = WIM_Data_DEFAULTS.enableFilter; end;
186 if(WIM_Data.aliasAsComment == nil) then WIM_Data.aliasAsComment = WIM_Data_DEFAULTS.aliasAsComment; end;
187 if(WIM_Data.enableHistory == nil) then WIM_Data.enableHistory = WIM_Data_DEFAULTS.enableHistory; end;
188 if(WIM_Data.historySettings == nil) then WIM_Data.historySettings = WIM_Data_DEFAULTS.historySettings; end;
189 if(WIM_Data.winLoc == nil) then WIM_Data.winLoc = WIM_Data_DEFAULTS.winLoc; end;
190 if(WIM_Data.winCascade == nil) then WIM_Data.winCascade = WIM_Data_DEFAULTS.winCascade; end;
191 if(WIM_Data.popOnSend == nil) then WIM_Data.popOnSend = WIM_Data_DEFAULTS.popOnSend; end;
192 if(WIM_Data.versionLastLoaded == nil) then WIM_Data.versionLastLoaded = WIM_Data_DEFAULTS.versionLastLoaded; end;
193  
194 if(WIM_Filters == nil) then
195 WIM_LoadDefaultFilters();
196 end
197  
198 ShowFriends(); --[update friend list
199 if(IsInGuild()) then GuildRoster(); end; --[update guild roster
200  
201 ItemRefTooltip:SetFrameStrata("TOOLTIP");
202  
203 WIM_HistoryPurge();
204  
205 WIM_InitClassProps();
206  
207 WIM_SetWIM_Enabled(WIM_Data.enableWIM);
208  
209 if(WIM_VERSION ~= WIM_Data.versionLastLoaded) then
210 WIM_Help:Show();
211 end
212 WIM_Data.versionLastLoaded = WIM_VERSION;
213  
214 if(WIM_Data.miniFreeMoving.enabled) then
215 if(WIM_Data.showMiniMap == false) then
216 WIM_IconFrame:Hide();
217 else
218 WIM_IconFrame:Show();
219 WIM_IconFrame:SetFrameStrata("HIGH");
220 WIM_IconFrame:SetPoint("TOPLEFT", "UIParent", "BOTTOMLEFT",WIM_Data.miniFreeMoving.left,WIM_Data.miniFreeMoving.top);
221 end
222 else
223 WIM_Icon_UpdatePosition();
224 end
225  
226 elseif(event == "TRADE_SKILL_SHOW" or event == "CRAFT_SHOW") then
227 --[hook tradeskill window functions
228 WIM_HookTradeSkill();
229 elseif(event == "GUILD_ROSTER_UPDATE") then
230 WIM_LoadGuildList();
231 WIM_AlreadyCheckedGuildRoster = true;
232 elseif(event == "FRIENDLIST_SHOW" or event == "FRIENDLIST_UPDATE") then
233 WIM_LoadFriendList();
234 else
235 if(WIM_AlreadyCheckedGuildRoster == false) then
236 if(IsInGuild()) then GuildRoster(); end; --[update guild roster
237 end
238 WIM_ChatFrame_OnEvent(event);
239 end
240 end
241  
242 function WIM_ChatFrame_OnEvent(event)
243 if( WIM_Data.enableWIM == false) then
244 return;
245 end
246 local msg = "";
247 if(event == "CHAT_MSG_AFK" or event == "CHAT_MSG_DND") then
248 local afkType;
249 if( event == "CHAT_MSG_AFK" ) then
250 afkType = "AFK";
251 else
252 afkType = "DND";
253 end
254 msg = "<"..afkType.."> |Hplayer:"..arg2.."|h"..arg2.."|h: "..arg1;
255 WIM_PostMessage(arg2, msg, 3);
256 ChatEdit_SetLastTellTarget(ChatFrameEditBox,arg2);
257 elseif(event == "CHAT_MSG_WHISPER") then
258 if(WIM_FilterResult(arg1) ~= 1 and WIM_FilterResult(arg1) ~= 2) then
259 msg = "[|Hplayer:"..arg2.."|h"..WIM_GetAlias(arg2, true).."|h]: "..arg1;
260 WIM_PostMessage(arg2, msg, 1, arg2, arg1);
261 end
262 ChatEdit_SetLastTellTarget(ChatFrameEditBox,arg2);
263 elseif(event == "CHAT_MSG_WHISPER_INFORM") then
264 if(WIM_FilterResult(arg1) ~= 1 and WIM_FilterResult(arg1) ~= 2) then
265 msg = "[|Hplayer:"..UnitName("player").."|h"..WIM_GetAlias(UnitName("player"), true).."|h]: "..arg1;
266 WIM_PostMessage(arg2, msg, 2, UnitName("player") ,arg1);
267 end
268 elseif(event == "CHAT_MSG_SYSTEM") then
269 local tstart,tfinish = string.find(arg1, "\'(%a+)\'");
270 if(tstart ~= nil and tfinish ~= nil) then
271 user = string.sub(arg1, tstart+1, tfinish-1);
272 user = string.gsub(user, "^%l", string.upper)
273 tstart, tfinish = string.find(arg1, "playing");
274 if(tstart ~= nil and WIM_Windows[user] ~= nil) then
275 -- player not playing, can't whisper
276 msg = "|Hplayer:"..user.."|h"..user.."|h is not currently playing!";
277 WIM_PostMessage(user, msg, 4);
278 end
279 end
280 end
281 end
282  
283 function WIM_ChatFrameSupressor_OnEvent(event)
284 if(WIM_Data.enableWIM == false) then
285 return true;
286 end
287 local msg = "";
288 if(event == "CHAT_MSG_AFK" or event == "CHAT_MSG_DND") then
289 if(WIM_Data.supressWisps) then
290 return false; --[ false to supress from chatframe
291 else
292 return true;
293 end
294 elseif(event == "CHAT_MSG_WHISPER") then
295 if(WIM_Data.supressWisps) then
296 if(WIM_FilterResult(arg1) == 1) then
297 return true;
298 else
299 return false; --[ false to supress from chatframe
300 end
301 else
302 if(WIM_FilterResult(arg1) == 2) then
303 return false;
304 else
305 return true;
306 end
307 end
308 elseif(event == "CHAT_MSG_WHISPER_INFORM") then
309 if(WIM_Data.supressWisps) then
310 if(WIM_FilterResult(arg1) == 1) then
311 return true;
312 else
313 return false; --[ false to supress from chatframe
314 end
315 else
316 if(WIM_FilterResult(arg1) == 2) then
317 return false;
318 else
319 return true;
320 end
321 end
322 elseif(event == "CHAT_MSG_SYSTEM") then
323 local tstart,tfinish = string.find(arg1, "\'(%a+)\'");
324 if(tstart ~= nil and tfinish ~= nil) then
325 user = string.sub(arg1, tstart+1, tfinish-1);
326 user = string.gsub(user, "^%l", string.upper)
327 tstart, tfinish = string.find(arg1, "playing");
328 if(tstart ~= nil and WIM_Windows[user] ~= nil) then
329 -- player not playing, can't whisper
330 if(WIM_Data.supressWisps) then
331 return false; --[ false to supress from chatframe
332 else
333 return true;
334 end
335 end
336 end
337 return true;
338 end
339 return true;
340 end
341  
342  
343 function WIM_PostMessage(user, msg, ttype, from, raw_msg)
344 --[[
345 ttype:
346 1 - Wisper from someone
347 2 - Wisper sent
348 3 - System Message
349 4 - Error Message
350 5 - Show window... Do nothing else...
351 ]]--
352  
353 local f,chatBox;
354 local isNew = false;
355 if(WIM_Windows[user] == nil) then
356 if(getglobal("WIM_msgFrame"..user)) then
357 f = getglobal("WIM_msgFrame"..user);
358 else
359 f = CreateFrame("Frame","WIM_msgFrame"..user,UIParent, "WIM_msgFrameTemplate");
360 end
361 WIM_SetWindowProps(f);
362 WIM_Windows[user] = {
363 frame = "WIM_msgFrame"..user,
364 newMSG = true,
365 is_visible = false,
366 last_msg=time(),
367 waiting_who=false,
368 class="",
369 level="",
370 race="",
371 guild=""
372 };
373 f.theUser = user;
374 getglobal("WIM_msgFrame"..user.."From"):SetText(WIM_GetAlias(user));
375 WIM_Icon_AddUser(user);
376 isNew = true;
377 WIM_SetWindowLocation(f);
378 if(WIM_Data.characterInfo.show) then WIM_SendWho(user); end;
379 WIM_UpdateCascadeStep();
380 WIM_DisplayHistory(user);
381 if(WIM_History[user]) then
382 getglobal(f:GetName().."HistoryButton"):Show();
383 end
384 end
385 f = getglobal("WIM_msgFrame"..user);
386 chatBox = getglobal("WIM_msgFrame"..user.."ScrollingMessageFrame");
387 msg = WIM_ConvertURLtoLinks(msg);
388 WIM_Windows[user].newMSG = true;
389 WIM_Windows[user].last_msg = time();
390 if(ttype == 1) then
391 WIM_PlaySoundWisp();
392 WIM_AddToHistory(user, from, raw_msg, false);
393 WIM_RecentListAdd(user);
394 chatBox:AddMessage(WIM_getTimeStamp()..msg, WIM_Data.displayColors.wispIn.r, WIM_Data.displayColors.wispIn.g, WIM_Data.displayColors.wispIn.b);
395 elseif(ttype == 2) then
396 WIM_AddToHistory(user, from, raw_msg, true);
397 WIM_RecentListAdd(user);
398 chatBox:AddMessage(WIM_getTimeStamp()..msg, WIM_Data.displayColors.wispOut.r, WIM_Data.displayColors.wispOut.g, WIM_Data.displayColors.wispOut.b);
399 elseif(ttype == 3) then
400 chatBox:AddMessage(msg, WIM_Data.displayColors.sysMsg.r, WIM_Data.displayColors.sysMsg.g, WIM_Data.displayColors.sysMsg.b);
401 elseif(ttype == 4) then
402 chatBox:AddMessage(msg, WIM_Data.displayColors.errorMsg.r, WIM_Data.displayColors.errorMsg.g, WIM_Data.displayColors.errorMsg.b);
403 end
404 if( WIM_PopOrNot(isNew) or (ttype==2) or (ttype==5) ) then
405 WIM_Windows[user].newMSG = false;
406 if(ttype == 2 and WIM_Data.popOnSend == false) then
407 --[ do nothing, user prefers not to pop on send
408 else
409 f:Show();
410 end
411 end
412 WIM_UpdateScrollBars(chatBox);
413 WIM_Icon_DropDown_Update();
414 if(WIM_HistoryFrame:IsVisible()) then
415 WIM_HistoryViewNameScrollBar_Update();
416 WIM_HistoryViewFiltersScrollBar_Update();
417 end
418 end
419  
420 function WIM_SetWindowLocation(theWin)
421 local CascadeOffset_Left = 0;
422 local CascadeOffset_Top = 0;
423  
424 if(WIM_Data.winCascade.enabled) then
425 CascadeOffset_Left = WIM_CascadeDirection[WIM_Data.winCascade.direction].left;
426 CascadeOffset_Top = WIM_CascadeDirection[WIM_Data.winCascade.direction].top;
427 end
428  
429 theWin:SetPoint(
430 "TOPLEFT",
431 "UIParent",
432 "BOTTOMLEFT",
433 (WIM_Data.winLoc.left + WIM_CascadeStep*CascadeOffset_Left),
434 (WIM_Data.winLoc.top + WIM_CascadeStep*CascadeOffset_Top)
435 );
436 end
437  
438 function WIM_PopOrNot(isNew)
439 if(isNew == true and WIM_Data.popNew == true) then
440 if(WIM_Data.popCombat and UnitAffectingCombat("player")) then
441 return false;
442 else
443 return true;
444 end
445 elseif(WIM_Data.popNew == true and WIM_Data.popUpdate == true) then
446 if(WIM_Data.popCombat and UnitAffectingCombat("player")) then
447 return false;
448 else
449 return true;
450 end
451 else
452 return false;
453 end
454 end
455  
456  
457 function WIM_UpdateScrollBars(smf)
458 local parentName = smf:GetParent():GetName();
459 if(smf:AtTop()) then
460 getglobal(parentName.."ScrollUp"):Disable();
461 else
462 getglobal(parentName.."ScrollUp"):Enable();
463 end
464 if(smf:AtBottom()) then
465 getglobal(parentName.."ScrollDown"):Disable();
466 else
467 getglobal(parentName.."ScrollDown"):Enable();
468 end
469 end
470  
471 function WIM_isLinkURL(link)
472 if (strsub(link, 1, 3) == "url") then
473 return true;
474 else
475 return false;
476 end
477 end
478  
479 function WIM_DisplayURL(link)
480 local theLink = "";
481 if (string.len(link) > 4) and (string.sub(link,1,4) == "url:") then
482 theLink = string.sub(link,5, string.len(link));
483 end
484 --show UI to show url so it can be copied
485 if(theLink) then
486 WIM_urlCopyUrlBox:SetText(theLink);
487 WIM_urlCopy:Show();
488 WIM_urlCopyUrlBox:HighlightText(0);
489 end
490 end
491  
492 function WIM_ConvertURLtoLinks(text)
493 local preLink, midLink, postLink;
494 preLink = "|Hurl:";
495 midLink = "|h|cff"..WIM_RGBtoHex(WIM_Data.displayColors.webAddress.r, WIM_Data.displayColors.webAddress.g, WIM_Data.displayColors.webAddress.b);
496 postLink = "|h|r";
497 text = string.gsub(text, "(%a+://[%w_/%.%?%%=~&-]+)", preLink.."%1"..midLink.."%1"..postLink);
498 return text;
499 end
500  
501 function WIM_SlashCommand(msg)
502 if(msg == "" or msg == nil) then
503 WIM_Options:Show();
504 elseif(msg == "reset") then
505 WIM_Data = WIM_Data_DEFAULTS;
506 elseif(msg == "clear history") then
507 WIM_History = {};
508 elseif(msg == "reset filters") then
509 WIM_LoadDefaultFilters();
510 elseif(msg == "history") then
511 WIM_HistoryFrame:Show();
512 elseif(msg == "help") then
513 WIM_Help:Show();
514 end
515 end
516  
517  
518 function WIM_Icon_Move(toDegree)
519 WIM_Data.iconPosition = toDegree;
520 WIM_Icon_UpdatePosition();
521 end
522  
523 function WIM_Icon_UpdatePosition()
524 if(WIM_Data.showMiniMap == false) then
525 WIM_IconFrame:Hide();
526 else
527 if(WIM_Data.miniFreeMoving.enabled == false) then
528 WIM_IconFrame:SetPoint(
529 "TOPLEFT",
530 "Minimap",
531 "TOPLEFT",
532 54 - (78 * cos(WIM_Data.iconPosition)),
533 (78 * sin(WIM_Data.iconPosition)) - 55
534 );
535 end
536 WIM_IconFrame:Show();
537 end
538 end
539  
540  
541 function WIM_SetWindowProps(theWin)
542 if(WIM_Data.showShortcutBar) then
543 getglobal(theWin:GetName().."ShortcutFrame"):Show();
544 local tHeight = WIM_Data.winSize.height;
545 if(tHeight < 240) then
546 tHeight = 240;
547 end
548 theWin:SetHeight(tHeight);
549 else
550 getglobal(theWin:GetName().."ShortcutFrame"):Hide();
551 theWin:SetHeight(WIM_Data.winSize.height);
552 end
553 theWin:SetWidth(WIM_Data.winSize.width);
554 theWin:SetScale(WIM_Data.windowSize);
555 theWin:SetAlpha(WIM_Data.windowAlpha);
556 getglobal(theWin:GetName().."ScrollingMessageFrame"):SetFont("Fonts\\FRIZQT__.TTF",WIM_Data.fontSize);
557 getglobal(theWin:GetName().."ScrollingMessageFrame"):SetAlpha(1);
558 getglobal(theWin:GetName().."MsgBox"):SetAlpha(1);
559 getglobal(theWin:GetName().."ShortcutFrame"):SetAlpha(1);
560 end
561  
562 function WIM_SetAllWindowProps()
563 for key in WIM_Windows do
564 WIM_SetWindowProps(getglobal(WIM_Windows[key].frame));
565 end
566 end
567  
568  
569 function WIM_Icon_DropDown_Init(level)
570 local dropdown;
571 if ( UIDROPDOWNMENU_OPEN_MENU ) then
572 dropdown = getglobal(UIDROPDOWNMENU_OPEN_MENU);
573 else
574 dropdown = this;
575 end
576 WIM_Icon_DropDown_InitButtons();
577 end
578  
579 function WIM_Icon_ToggleDropDown()
580 ToggleDropDownMenu(1, nil, WIM_Icon_DropDown);
581 --local tMenu = getglobal("DropDownList"..UIDROPDOWNMENU_MENU_LEVEL);
582 --tMenu:ClearAllPoints();
583 --tMenu:SetPoint("TOPRIGHT", "WIM_IconFrameButton", "BOTTOMLEFT", 0, 0);
584 WIM_Icon_DropDown:SetWidth(DropDownList1Button1:GetWidth()+50);
585 DropDownList1:SetScale(UIParent:GetScale());
586 end
587  
588 function WIM_Icon_DropDown_InitButtons()
589 local info = {};
590  
591 info = { };
592 info.text = "Conversations";
593 info.isTitle = 1;
594 info.justifyH = "LEFT";
595 info.notCheckable = 1;
596 UIDropDownMenu_AddButton(info);
597  
598 local tList = { };
599 local tListActivity = { };
600 local tCount = 0;
601 for key in WIM_IconItems do
602 table.insert(tListActivity, key);
603 tCount = tCount + 1;
604 end
605  
606 --[first get a sorted list of users by most frequent activity
607 table.sort(tListActivity, WIM_Icon_SortByActivity);
608 --[account for only the allowable amount of active users
609 for i=1,table.getn(tListActivity) do
610 if(i <= WIM_MaxMenuCount) then
611 table.insert(tList, tListActivity[i]);
612 end
613 end
614  
615 WIM_NewMessageCount = 0;
616  
617 if(tCount == 0) then
618 info = { };
619 info.justifyH = "LEFT"
620 info.text = " - None -";
621 info.notClickable = 1;
622 info.notCheckable = 1;
623 UIDropDownMenu_AddButton(info);
624 else
625 if(WIM_Data.sortAlpha) then
626 table.sort(tList);
627 end
628 WIM_NewMessageFlag = false;
629 for i=1, table.getn(tList) do
630 if( WIM_Windows[tList[i]].newMSG and WIM_Windows[tList[i]].is_visible == false) then
631 WIM_IconItems[tList[i]].textR = 77/255;
632 WIM_IconItems[tList[i]].textG = 135/255;
633 WIM_IconItems[tList[i]].textB = 224/255;
634 WIM_NewMessageFlag = true;
635 WIM_NewMessageCount = WIM_NewMessageCount + 1;
636 else
637 WIM_IconItems[tList[i]].textR = 255;
638 WIM_IconItems[tList[i]].textG = 255;
639 WIM_IconItems[tList[i]].textB = 255;
640 end
641 UIDropDownMenu_AddButton(WIM_IconItems[tList[i]]);
642 end
643 end
644 if(WIM_Data.enableWIM == true) then
645 if(WIM_NewMessageFlag == true) then
646 WIM_IconFrameButton:SetNormalTexture("Interface\\AddOns\\WIM\\Images\\miniEnabled");
647 else
648 WIM_IconFrameButton:SetNormalTexture("Interface\\AddOns\\WIM\\Images\\miniDisabled");
649 end
650 else
651 --show wim disabled icon
652 WIM_IconFrameButton:SetNormalTexture("Interface\\AddOns\\WIM\\Images\\miniOff");
653 end
654 end
655  
656  
657 function WIM_Icon_AddUser(theUser)
658 UIDROPDOWNMENU_INIT_MENU = "WIM_Options_DropDown";
659 UIDROPDOWNMENU_OPEN_MENU = UIDROPDOWNMENU_INIT_MENU;
660 local info = { };
661 info.text = theUser;
662 info.justifyH = "LEFT"
663 info.isTitle = nil;
664 info.notCheckable = 1;
665 info.value = WIM_Windows[theUser].frame;
666 info.func = WIM_Icon_PlayerClick;
667 WIM_IconItems[theUser] = info;
668 table.sort(WIM_IconItems);
669 WIM_Icon_DropDown_Update();
670 end
671  
672 function WIM_Icon_PlayerClick()
673 if(this.value ~= nil) then
674 getglobal(this.value):Show();
675 --[local user = getglobal(this.value.."From"):GetText();
676 local user = getglobal(this.value).theUser;
677 WIM_Windows[user].newMSG = false;
678 WIM_Windows[user].is_visible = true;
679 WIM_Icon_DropDown_Update();
680 end
681 end
682  
683 function WIM_Icon_DropDown_Update()
684 UIDropDownMenu_Initialize(WIM_Icon_DropDown, WIM_Icon_DropDown_Init, "MENU");
685 end
686  
687 function WIM_Icon_OnUpdate(elapsedTime)
688 if(WIM_NewMessageFlag == false) then
689 this.TimeSinceLastUpdate = 0;
690 if(WIM_Icon_NewMessageFlash:IsVisible()) then
691 WIM_Icon_NewMessageFlash:Hide();
692 end
693 return;
694 end
695  
696 this.TimeSinceLastUpdate = this.TimeSinceLastUpdate + elapsedTime;
697  
698 while (this.TimeSinceLastUpdate > WIM_Icon_UpdateInterval) do
699 if(WIM_Icon_NewMessageFlash:IsVisible()) then
700 WIM_Icon_NewMessageFlash:Hide();
701 else
702 WIM_Icon_NewMessageFlash:Show();
703 end
704 this.TimeSinceLastUpdate = this.TimeSinceLastUpdate - WIM_Icon_UpdateInterval;
705 end
706 end
707  
708 function WIM_UpdateCascadeStep()
709 WIM_CascadeStep = WIM_CascadeStep + 1;
710 if(WIM_CascadeStep > 10) then
711 WIM_CascadeStep = 0;
712 end
713 end
714  
715 function WIM_PlaySoundWisp()
716 if(WIM_Data.playSoundWisp == true) then
717 PlaySoundFile("Interface\\AddOns\\WIM\\Sounds\\wisp.wav");
718 end
719 end
720  
721 function WIM_Icon_SortByActivity(user1, user2)
722 if(WIM_Windows[user1].last_msg > WIM_Windows[user2].last_msg) then
723 return true;
724 else
725 return false;
726 end
727 end
728  
729 function WIM_RGBtoHex(r,g,b)
730 return string.format ("%.2x%.2x%.2x",r*255,g*255,b*255);
731 end
732  
733 function WIM_Icon_OnEnter()
734 GameTooltip:SetOwner(this, "ANCHOR_LEFT");
735 GameTooltip:SetText("WIM v"..WIM_VERSION.." ");
736 GameTooltip:AddDoubleLine("Conversation Menu", "Left-Click", 1,1,1,1,1,1);
737 GameTooltip:AddDoubleLine("Show New Messages", "Right-Click", 1,1,1,1,1,1);
738 GameTooltip:AddDoubleLine("WIM Options", "/wim", 1,1,1,1,1,1);
739 end
740  
741 function WIM_ShowNewMessages()
742 for key in WIM_Windows do
743 if(WIM_Windows[key].newMSG == true) then
744 getglobal(WIM_Windows[key].frame):Show();
745 WIM_Windows[key].newMSG = false;
746 end
747 end
748 WIM_Icon_DropDown_Update();
749 end
750  
751  
752 function WIM_SendWho(name)
753 WIM_Windows[name].waiting_who = true;
754 SetWhoToUI(1);
755 SendWho("\""..name.."\"");
756 end
757  
758  
759 function WIM_ShowAll()
760 for key in WIM_Windows do
761 getglobal(WIM_Windows[key].frame):Show();
762 end
763 end
764  
765 function WIM_CloseAllConvos()
766 for key in WIM_Windows do
767 WIM_CloseConvo(key);
768 end
769 end
770  
771 function WIM_CloseConvo(theUser)
772 if(WIM_Windows[theUser] == nil) then return; end; --[ fail silently
773  
774 getglobal(WIM_Windows[theUser].frame):Hide();
775 getglobal(WIM_Windows[theUser].frame.."ScrollingMessageFrame"):Clear();
776 getglobal(WIM_Windows[theUser].frame.."ClassIcon"):SetTexture("Interface\\AddOns\\WIM\\Images\\classBLANK");
777 getglobal(WIM_Windows[theUser].frame.."CharacterDetails"):SetText("");
778 WIM_Windows[theUser] = nil;
779 WIM_IconItems[theUser] = nil;
780  
781 WIM_Icon_DropDown_Update();
782 end
783  
784 function WIM_InitClassProps()
785 WIM_ClassIcons[WIM_LOCALIZED_DRUID] = "Interface\\AddOns\\WIM\\Images\\classDRUID";
786 WIM_ClassIcons[WIM_LOCALIZED_HUNTER] = "Interface\\AddOns\\WIM\\Images\\classHUNTER";
787 WIM_ClassIcons[WIM_LOCALIZED_MAGE] = "Interface\\AddOns\\WIM\\Images\\classMAGE";
788 WIM_ClassIcons[WIM_LOCALIZED_PALADIN] = "Interface\\AddOns\\WIM\\Images\\classPALADIN";
789 WIM_ClassIcons[WIM_LOCALIZED_PRIEST] = "Interface\\AddOns\\WIM\\Images\\classPRIEST";
790 WIM_ClassIcons[WIM_LOCALIZED_ROGUE] = "Interface\\AddOns\\WIM\\Images\\classROGUE";
791 WIM_ClassIcons[WIM_LOCALIZED_SHAMAN] = "Interface\\AddOns\\WIM\\Images\\classSHAMAN";
792 WIM_ClassIcons[WIM_LOCALIZED_WARLOCK] = "Interface\\AddOns\\WIM\\Images\\classWARLOCK";
793 WIM_ClassIcons[WIM_LOCALIZED_WARRIOR] = "Interface\\AddOns\\WIM\\Images\\classWARRIOR";
794  
795 WIM_ClassColors[WIM_LOCALIZED_DRUID] = "ff7d0a";
796 WIM_ClassColors[WIM_LOCALIZED_HUNTER] = "abd473";
797 WIM_ClassColors[WIM_LOCALIZED_MAGE] = "69ccf0";
798 WIM_ClassColors[WIM_LOCALIZED_PALADIN] = "f58cba";
799 WIM_ClassColors[WIM_LOCALIZED_PRIEST] = "ffffff";
800 WIM_ClassColors[WIM_LOCALIZED_ROGUE] = "fff569";
801 WIM_ClassColors[WIM_LOCALIZED_SHAMAN] = "f58cba";
802 WIM_ClassColors[WIM_LOCALIZED_WARLOCK] = "9482ca";
803 WIM_ClassColors[WIM_LOCALIZED_WARRIOR] = "c79c6e";
804 end
805  
806 function WIM_UserWithClassColor(theUser)
807 if(WIM_Windows[theUser].class == "") then
808 return theUser;
809 else
810 if(WIM_ClassColors[WIM_Windows[theUser].class]) then
811 return "|cff"..WIM_ClassColors[WIM_Windows[theUser].class]..WIM_GetAlias(theUser);
812 else
813 return WIM_GetAlias(theUser);
814 end
815 end
816 end
817  
818 function WIM_SetWhoInfo(theUser)
819 local classIcon = getglobal(WIM_Windows[theUser].frame.."ClassIcon");
820 if(WIM_Data.characterInfo.classIcon and WIM_ClassIcons[WIM_Windows[theUser].class]) then
821 classIcon:SetTexture(WIM_ClassIcons[WIM_Windows[theUser].class]);
822 else
823 classIcon:SetTexture("Interface\\AddOns\\WIM\\Images\\classBLANK");
824 end
825 if(WIM_Data.characterInfo.classColor) then
826 getglobal(WIM_Windows[theUser].frame.."From"):SetText(WIM_UserWithClassColor(theUser));
827 end
828 if(WIM_Data.characterInfo.details) then
829 local tGuild = "";
830 if(WIM_Windows[theUser].guild ~= "") then
831 tGuild = "<"..WIM_Windows[theUser].guild.."> ";
832 end
833 getglobal(WIM_Windows[theUser].frame.."CharacterDetails"):SetText("|cffffffff"..tGuild..WIM_Windows[theUser].level.." "..WIM_Windows[theUser].race.." "..WIM_Windows[theUser].class.."|r");
834 end
835 end
836  
837 function WIM_getTimeStamp()
838 if(WIM_Data.showTimeStamps) then
839 return "|cff"..WIM_RGBtoHex(WIM_Data.displayColors.sysMsg.r, WIM_Data.displayColors.sysMsg.g, WIM_Data.displayColors.sysMsg.b)..date("%H:%M").."|r ";
840 else
841 return "";
842 end
843 end
844  
845 function WIM_Bindings_EnableWIM()
846 WIM_SetWIM_Enabled(not WIM_Data.enableWIM);
847 end
848  
849 function WIM_SetWIM_Enabled(YesOrNo)
850 WIM_Data.enableWIM = YesOrNo
851 WIM_Icon_DropDown_Update();
852 end
853  
854 function WIM_LoadShortcutFrame()
855 local tButtons = {
856 {
857 icon = "Interface\\Icons\\Ability_Hunter_AimedShot",
858 cmd = "target",
859 tooltip = "Target"
860 },
861 {
862 icon = "Interface\\Icons\\Spell_Holy_BlessingOfStrength",
863 cmd = "invite",
864 tooltip = "Invite"
865 },
866 {
867 icon = "Interface\\Icons\\INV_Misc_Bag_10_Blue",
868 cmd = "trade",
869 tooltip = "Trade"
870 },
871 {
872 icon = "Interface\\Icons\\INV_Helmet_44",
873 cmd = "inspect",
874 tooltip = "Inspect"
875 },
876 {
877 icon = "Interface\\Icons\\Ability_Physical_Taunt",
878 cmd = "ignore",
879 tooltip = "Ignore"
880 },
881 };
882 for i=1,5 do
883 getglobal(this:GetName().."ShortcutFrameButton"..i.."Icon"):SetTexture(tButtons[i].icon);
884 getglobal(this:GetName().."ShortcutFrameButton"..i).cmd = tButtons[i].cmd;
885 getglobal(this:GetName().."ShortcutFrameButton"..i).tooltip = tButtons[i].tooltip;
886 end
887 getglobal(this:GetName().."ShortcutFrame"):SetScale(.75);
888 end
889  
890 function WIM_ShorcutButton_Clicked()
891 local cmd = this.cmd;
892 local theUser = this:GetParent():GetParent().theUser;
893 if(cmd == "target") then
894 TargetByName(theUser, true);
895 elseif(cmd == "invite") then
896 InviteByName(theUser);
897 elseif(cmd == "trade") then
898 TargetByName(theUser, true);
899 InitiateTrade("target");
900 elseif(cmd == "inspect") then
901 TargetByName(theUser, true);
902 InspectUnit("target");
903 elseif(cmd == "ignore") then
904 getglobal(this:GetParent():GetParent():GetName().."IgnoreConfirm"):Show();
905 end
906 end
907  
908 function WIM_GetAlias(theUser, nameOnly)
909 if(WIM_Data.enableAlias and WIM_Alias[theUser] ~= nil) then
910 if(WIM_Data.aliasAsComment) then
911 if(nameOnly) then
912 return theUser;
913 else
914 return theUser.." |cffffffff- "..WIM_Alias[theUser].."|r";
915 end
916 else
917 return WIM_Alias[theUser];
918 end
919 else
920 return theUser;
921 end
922 end
923  
924  
925 function WIM_FilterResult(theMSG)
926 if(WIM_Data.enableFilter) then
927 local key, a, b;
928 for key in WIM_Filters do
929 if(strfind(strlower(theMSG), strlower(key)) ~= nil) then
930 if(WIM_Filters[key] == "Ignore") then
931 return 1;
932 elseif(WIM_Filters[key] == "Block") then
933 return 2;
934 end
935 end
936 end
937 return 0;
938 else
939 return 0;
940 end
941 end
942  
943 function WIM_CanRecordUser(theUser)
944 if(WIM_Data.historySettings.recordEveryone) then
945 return true;
946 else
947 if(WIM_Data.historySettings.recordFriends and WIM_FriendList[theUser]) then
948 return true;
949 elseif(WIM_Data.historySettings.recordGuild and WIM_GuildList[theUser]) then
950 return true;
951 end
952 end
953 return false;
954 end
955  
956 function WIM_AddToHistory(theUser, userFrom, theMessage, isMsgIn)
957 local tmpEntry = {};
958 if(WIM_Data.enableHistory) then --[if history is enabled
959 if(WIM_CanRecordUser(theUser)) then --[if record user
960 getglobal(WIM_Windows[theUser].frame.."HistoryButton"):Show();
961 tmpEntry["stamp"] = time();
962 tmpEntry["date"] = date("%m/%d/%y");
963 tmpEntry["time"] = date("%H:%M");
964 tmpEntry["msg"] = WIM_ConvertURLtoLinks(theMessage);
965 tmpEntry["from"] = userFrom;
966 if(isMsgIn) then
967 tmpEntry["type"] = 2;
968 else
969 tmpEntry["type"] = 1;
970 end
971 if(WIM_History[theUser] == nil) then
972 WIM_History[theUser] = {};
973 end
974 table.insert(WIM_History[theUser], tmpEntry);
975  
976 if(WIM_Data.historySettings.maxMsg.enabled) then
977 local tOver = table.getn(WIM_History[theUser]) - WIM_Data.historySettings.maxMsg.count;
978 if(tOver > 0) then
979 for i = 1, tOver do
980 table.remove(WIM_History[theUser], 1);
981 end
982 end
983 end
984 if(WIM_Options:IsVisible()) then
985 WIM_HistoryScrollBar_Update();
986 end
987 end
988 end
989 end
990  
991 function WIM_SortHistory(a, b)
992 if(a.stamp < b.stamp) then
993 return true;
994 else
995 return false;
996 end
997 end
998  
999 function WIM_DisplayHistory(theUser)
1000 if(WIM_History[theUser] and WIM_Data.enableHistory and WIM_Data.historySettings.popWin.enabled) then
1001 table.sort(WIM_History[theUser], WIM_SortHistory);
1002 for i=table.getn(WIM_History[theUser])-WIM_Data.historySettings.popWin.count-1, table.getn(WIM_History[theUser]) do
1003 if(WIM_History[theUser][i]) then
1004 --WIM_GetAlias
1005 msg = "|Hplayer:"..WIM_History[theUser][i].from.."|h["..WIM_GetAlias(WIM_History[theUser][i].from, true).."]|h: "..WIM_History[theUser][i].msg;
1006 if(WIM_Data.showTimeStamps) then
1007 msg = WIM_History[theUser][i].time.." "..msg;
1008 end
1009 if(WIM_History[theUser][i].type == 1) then
1010 getglobal("WIM_msgFrame"..theUser.."ScrollingMessageFrame"):AddMessage(msg, WIM_Data.historySettings.colorIn.r, WIM_Data.historySettings.colorIn.g, WIM_Data.historySettings.colorIn.b);
1011 elseif(WIM_History[theUser][i].type == 2) then
1012 getglobal("WIM_msgFrame"..theUser.."ScrollingMessageFrame"):AddMessage(msg, WIM_Data.historySettings.colorOut.r, WIM_Data.historySettings.colorOut.g, WIM_Data.historySettings.colorOut.b);
1013 end
1014 end
1015 end
1016 end
1017 --getglobal("WIM_msgFrame"..theUser.."ScrollingMessageFrame"):AddMessage(" ");
1018 end
1019  
1020 function WIM_LoadDefaultFilters()
1021 WIM_Filters = {};
1022 WIM_Filters["^LVBM"] = "Ignore";
1023 WIM_Filters["^YOU ARE BEING WATCHED!"] = "Ignore";
1024 WIM_Filters["^YOU ARE MARKED!"] = "Ignore";
1025 WIM_Filters["^YOU ARE CURSED!"] = "Ignore";
1026 WIM_Filters["^YOU HAVE THE PLAGUE!"] = "Ignore";
1027 WIM_Filters["^YOU ARE BURNING!"] = "Ignore";
1028 WIM_Filters["^YOU ARE THE BOMB!"] = "Ignore";
1029 WIM_Filters["VOLATILE INFECTION"] = "Ignore";
1030 WIM_Filters["^<GA"] = "Ignore";
1031  
1032 WIM_FilteringScrollBar_Update();
1033 end
1034  
1035 function WIM_LoadGuildList()
1036 WIM_GuildList = {};
1037 if(IsInGuild()) then
1038 for i=1, GetNumGuildMembers(true) do
1039 local name, junk = GetGuildRosterInfo(i);
1040 WIM_GuildList[name] = "1"; --[set place holder for quick lookup
1041 end
1042 end
1043 end
1044  
1045 function WIM_LoadFriendList()
1046 WIM_FriendList = {};
1047 for i=1, GetNumFriends() do
1048 local name, junk = GetFriendInfo(i);
1049 if(name) then
1050 WIM_FriendList[name] = "1"; --[set place holder for quick lookup
1051 end
1052 end
1053 end
1054  
1055 function WIM_HistoryPurge()
1056 if(WIM_Data.historySettings.autoDelete.enabled) then
1057 local delCount = 0;
1058 local eldestTime = time() - (60 * 60 * 24 * WIM_Data.historySettings.autoDelete.days);
1059 for key in WIM_History do
1060 if(WIM_History[key][1]) then
1061 while(WIM_History[key][1].stamp < eldestTime) do
1062 table.remove(WIM_History[key], 1);
1063 delCount = delCount + 1;
1064 if(table.getn(WIM_History[key]) == 0) then
1065 WIM_History[key] = nil;
1066 break;
1067 end
1068 end
1069 end
1070 end
1071 if(delCount > 0) then
1072 DEFAULT_CHAT_FRAME:AddMessage("[WIM]: Purged "..delCount.." out-dated messages from history.");
1073 end
1074 end
1075 end
1076  
1077 function WIM_ToggleWindow_OnUpdate(elapsedTime)
1078  
1079 WIM_ToggleWindow_Timer = WIM_ToggleWindow_Timer + elapsedTime;
1080  
1081 while (WIM_ToggleWindow_Timer > 1) do
1082 WIM_ToggleWindow:Hide();
1083 WIM_ToggleWindow_Timer = 0;
1084 end
1085 end
1086  
1087 function WIM_RecentListAdd(theUser)
1088 local found = 0;
1089 for i=1, table.getn(WIM_RecentList) do
1090 if(WIM_RecentList[i] == theUser) then
1091 found = 1;
1092 break;
1093 end
1094 end
1095  
1096 if(found > 0) then
1097 table.remove(WIM_RecentList, found);
1098 end
1099 table.insert(WIM_RecentList, 1, theUser);
1100 end
1101  
1102 function WIM_ToggleWindow_Toggle()
1103 if(table.getn(WIM_RecentList) == 0) then
1104 return;
1105 end
1106  
1107 if(WIM_RecentList[WIM_ToggleWindow_Index] == nil) then
1108 WIM_ToggleWindow_Index = 1;
1109 end
1110  
1111 WIM_ToggleWindowUser:SetText(WIM_GetAlias(WIM_RecentList[WIM_ToggleWindow_Index], true));
1112 WIM_ToggleWindow.theUser = WIM_RecentList[WIM_ToggleWindow_Index];
1113 WIM_ToggleWindowCount:SetText("Recent Conversation "..WIM_ToggleWindow_Index.." of "..table.getn(WIM_RecentList));
1114 if(WIM_Windows[WIM_RecentList[WIM_ToggleWindow_Index]]) then
1115 if(WIM_Windows[WIM_RecentList[WIM_ToggleWindow_Index]].newMSG) then
1116 WIM_ToggleWindowStatus:SetText("New message!");
1117 WIM_ToggleWindowIconNew:Show();
1118 WIM_ToggleWindowIconRead:Hide();
1119 else
1120 WIM_ToggleWindowStatus:SetText("No new messages.");
1121 WIM_ToggleWindowIconRead:Show();
1122 WIM_ToggleWindowIconNew:Hide();
1123 end
1124 else
1125 WIM_ToggleWindowStatus:SetText("Conversation closed.");
1126 WIM_ToggleWindowIconRead:Show();
1127 WIM_ToggleWindowIconNew:Hide();
1128 end
1129 WIM_ToggleWindow_Timer = 0;
1130 WIM_ToggleWindow:Show();
1131 WIM_ToggleWindow_Index = WIM_ToggleWindow_Index + 1;
1132 end
1133