vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Constants
2 Chatr_Version=GetAddOnMetadata("Chatr","Title"); -- 1.11 savvy
3 Chatr_VerQuote="\"These bloodhounds... they move in a group, they're Bloodhound Gang!\"";
4 Chatr_Max=15;
5 BINDING_HEADER_CHATR="Chatr";
6 BINDING_NAME_CHATR_REPLY="Focus Last Clicked Chat";
7 BINDING_NAME_CHATR_QUICKTOGGLE="QuickToggle";
8 BINDING_NAME_CHATR_REPLYDOCK="Dock: Focus Current Tab";
9 BINDING_NAME_CHATR_NEXTCHAT="Dock: Next Tab";
10 BINDING_NAME_CHATR_PREVCHAT="Dock: Previous Tab";
11 BINDING_NAME_CHATR_CLOSETAB="Dock: Close Tab";
12  
13 -- Saved
14  
15 Chatr_Options={};
16  
17 -- Not Saved
18 Chatr_Ready=0;
19 Chatr_HookNames={"ContainerFrameItemButton_OnClick","PaperDollItemSlotButton_OnClick","BankFrameItemButtonGeneric_OnClick","SetItemRef"};
20 Chatr_HookedFuncs={};
21 Chatr_WhoInfo={};
22 Chatr_Statuses={};
23 Chatr_LastPositions={};
24 Chatr_DockedIds={};
25 Chatr_DockSelected=0;
26 Chatr_Debugging=0;
27 Chatr_FontSize=12;
28 Chatr_EditFocus=nil;
29 Chatr_LastFocused=nil;
30 Chatr_InboundFilters={};
31 Chatr_OutboundFilters={};
32 Chatr_Filters={};
33 Chatr_Whoed=0;
34 Chatr_QuickToggled=0;
35 Chatr_LastPluginButton=nil;
36 Chatr_CallMes={};
37 -- %a Locale's abbreviated weekday name.
38 -- %A Locale's full weekday name.
39 -- %b Locale's abbreviated month name.
40 -- %B Locale's full month name.
41 -- %c Locale's appropriate date and time representation.
42 -- %d Day of the month as a decimal number [01,31].
43 -- %H Hour (24-hour clock) as a decimal number [00,23].
44 -- %I Hour (12-hour clock) as a decimal number [01,12].
45 -- %j Day of the year as a decimal number [001,366].
46 -- %m Month as a decimal number [01,12].
47 -- %M Minute as a decimal number [00,59].
48 -- %p Locale's equivalent of either AM or PM. (1)
49 -- %S Second as a decimal number [00,61]. (2)
50 -- %U Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0. (3)
51 -- %w Weekday as a decimal number [0(Sunday),6].
52 -- %W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. (3)
53 -- %x Locale's appropriate date representation.
54 -- %X Locale's appropriate time representation.
55 -- %y Year without century as a decimal number [00,99].
56 -- %Y Year with century as a decimal number.
57 -- %Z Time zone name (no characters if no time zone exists).
58 -- %% A literal "%" character.
59 Chatr_TextFormat="%H:%M <$name> $text";
60 Chatr_NoteFormat="%H:%M $text";
61 Chatr_NormalTextColor={1,1,1};
62 Chatr_AFKTextColor={1,1,0.7};
63 Chatr_SelfTextColor={0.8,1,0.4};
64 Chatr_NoteTextColor={0.4,0.8,1};
65 Chatr_BGColor={0,0,0,1};
66 Chatr_BorderColor={1,1,1,1};
67 Chatr_AutoDock=0;
68 Chatr_AutoWho=0;
69 Chatr_AllowFade=1;
70 Chatr_DockMode=0;
71 Chatr_EntryInside=0;
72 Chatr_MinInCombat=0;
73 Chatr_PlaySound=1;
74 Chatr_DefaultSize={250,150};
75 Chatr_DefaultPos={0,0};
76  
77 Chatr_ExecSlash=0;
78  
79 Chatr_SavePerChar=0;
80  
81 -- Prints a message.
82 function Chatr_Print(msg)
83 DEFAULT_CHAT_FRAME:AddMessage(tostring(msg),0.2,0.7,0.9);
84 end
85 -- Prints a debug.
86 function Chatr_Debug(msg)
87 if Chatr_Debugging==1 then
88 DEFAULT_CHAT_FRAME:AddMessage("# "..msg,0.2,0.7,0.9);
89 end
90 end
91  
92 -- Shows a tooltip.
93 function Chatr_Tip(text,attach)
94 if text==nil then
95 GameTooltip:Hide();
96 else
97 if attach==nil then
98 GameTooltip_SetDefaultAnchor(GameTooltip, UIParent);
99 else
100 GameTooltip_SetDefaultAnchor(GameTooltip, attach);
101 end
102 GameTooltip:SetText(text,1,1,1,1,1);
103 GameTooltip:Show();
104 end
105 end
106  
107 function Chatr_Split(delimiter, text,maxcnt)
108 -- Edited from http://lua-users.org/wiki/SplitJoin
109  
110 local list = {}
111 local pos = 1
112 local cnt = 0
113 if text==nil or delimiter==nil or text=="" or delimiter=="" then
114 return 0,list
115 end
116 while 1 do
117 local first, last = strfind(text, delimiter, pos)
118 if first and ((maxcnt>0 and cnt<maxcnt) or maxcnt==0) then -- found?
119 table.insert(list, strsub(text, pos, first-1))
120 pos = last+1
121 cnt=cnt+1
122 else
123 table.insert(list, strsub(text, pos))
124 cnt=cnt+1
125 break
126 end
127 end
128 return cnt,list
129 end
130  
131 function Chatr_tremovebyval(tab, val)
132 for k,v in tab do
133 if v==val then
134 tremove(tab, k);
135 return k;
136 end
137 end
138 return false;
139 end
140  
141 function Chatr_tidx(tab, val)
142 for k,v in tab do
143 if v==val then
144 return k;
145 end
146 end
147 return nil;
148 end
149  
150 function Chatr_Hyperlink(arg1,arg2,arg3)
151 if ChatFrame_OnHyperlinkShow~=nil then -- EnhTooltip/Auctioneer hack (not like THAT'd ever be nil, but..)
152 ChatFrame_OnHyperlinkShow(arg1,arg2,arg3)
153 else
154 SetItemRef(arg1,arg2,arg3)
155 end
156 end
157  
158 function Chatr_ShowOptions()
159 if not ChatrOptions:IsShown() then
160 ChatrOptionsFmt:SetText(Chatr_TextFormat);
161 ChatrOptionsFmt2:SetText(Chatr_NoteFormat);
162 ChatrOptionsAutoDock:SetChecked(Chatr_AutoDock);
163 ChatrOptionsAllowFade:SetChecked(Chatr_AllowFade);
164 ChatrOptionsVertDock:SetChecked(Chatr_DockMode);
165 ChatrOptionsAutoWho:SetChecked(Chatr_AutoWho);
166 ChatrOptionsSavePer:SetChecked(Chatr_SavePerChar);
167 ChatrOptionsMinInCombat:SetChecked(Chatr_MinInCombat);
168 ChatrOptionsEntryInside:SetChecked(Chatr_EntryInside);
169 ChatrOptionsFontSize:SetValue(Chatr_FontSize);
170 ChatrOptions:Show();
171 Chatr_DoCallMe("ShowSettings",nil);
172 Chatr_SaveSettings("_backup");
173 end
174 end
175  
176 function Chatr_Cmd(arg1)
177 local cmd,parts,partn,st,i;
178 if arg1=="" then
179 Chatr_ShowOptions();
180 return;
181 end
182 partn,parts=Chatr_Split(" ",arg1,0);
183 cmd=parts[1];
184  
185 if cmd=="help" then
186 Chatr_Print("/chatr debug - toggle debugging mode");
187 Chatr_Print("/chatr reset - resets all options for all profiles");
188 Chatr_Print("/chatr t - opens testing boxes");
189 Chatr_Print("/chatr clear - closes all boxes");
190 Chatr_Print("/chatr size <w> <h> - sets default size to <w> x <h>");
191 Chatr_Print("/chatr pos <x> <y> - sets default position to <x>,<y> (0,0 is CENTER)");
192 return;
193 end
194  
195 if cmd=="debug" then
196 Chatr_Debugging=1-Chatr_Debugging;
197 Chatr_Print("Debug: "..Chatr_Debugging);
198 return;
199 end
200 if cmd=="reset" then
201 Chatr_Options={};
202 Chatr_Print("Options have been reset. Reload your UI with /console reloadui before setting new options.");
203 return;
204 end
205 if cmd=="clear" then
206 Chatr_Clear();
207 return;
208 end
209  
210 if cmd=="t" then
211 for i=1,5 do
212 Chatr_OpenFor("Bot"..random(10000,99999));
213 end
214 return;
215 end
216 if cmd=="size" then
217 local w=tonumber(parts[2]);
218 local h=tonumber(parts[3]);
219 if w and h then
220 Chatr_DefaultSize={w,h};
221 end
222 Chatr_Print("Default size: ("..Chatr_DefaultSize[1].." x "..Chatr_DefaultSize[2]..")");
223 return;
224 end
225 if cmd=="pos" then
226 local x=tonumber(parts[2]);
227 local y=tonumber(parts[3]);
228 if x and y then
229 Chatr_DefaultPos={x,y};
230 end
231 Chatr_Print("Default position: ("..Chatr_DefaultPos[1]..", "..Chatr_DefaultPos[2]..")");
232 return;
233 end
234  
235 end
236  
237 function Chatr_FindFree()
238 local i;
239 for i = 1,Chatr_Max do
240 if getglobal("Chatr"..i).open==0 then return i; end
241 end
242 return -1;
243 end
244  
245 function Chatr_FindByName(name)
246 local i,c;
247 for i = 1,Chatr_Max do
248 c=getglobal("Chatr"..i)
249 if c.open==1 and c.target==name then return i; end
250 end
251 return -1;
252 end
253  
254 function Chatr_OnUpdate(elapsed)
255 if Chatr_Ready==1 then
256 end
257 end
258  
259 function Chatr_Clear()
260 for i=1,Chatr_Max do
261 Chatr_Close(getglobal("Chatr"..i));
262 end
263 end
264  
265 function Chatr_Close(chatr)
266 local a,b,c,d,e,v;
267 if chatr.docked==0 then
268 a,b,c,d,e=chatr:GetPoint("TOPLEFT");
269 Chatr_LastPositions[chatr.target]={a,c,d,e,chatr:GetWidth(),chatr:GetHeight()};
270 else
271 Chatr_LastPositions[chatr.target]={"CENTER","CENTER",0,0,chatr:GetWidth(),chatr:GetHeight()};
272 end
273 Chatr_AbandonEntry(chatr);
274 if chatr:IsShown() then
275 chatr:Hide();
276 end
277 chatr.docked=0;
278 chatr.open=0;
279 Chatr_UpdateDock();
280 ChatrMenu:Hide();
281 Chatr_DoCallMe("CloseChatr",chatr);
282 end
283  
284  
285 function Chatr_Minimize(chatr)
286 if chatr.docked==1 then
287 Chatr_Undock(chatr);
288 else
289 if chatr.minimized==1 then
290 chatr.minimized=0;
291 chatr.editBox:Show();
292 chatr.chatBox:Show();
293 chatr.sizer:Show();
294 chatr.menu:Show();
295 chatr:SetWidth(chatr.preMinW);
296 chatr:SetHeight(chatr.preMinH);
297 elseif chatr.docked==0 then
298 chatr.minimized=1;
299 chatr.editBox:Hide();
300 chatr.chatBox:Hide();
301 chatr.sizer:Hide();
302 chatr.menu:Hide();
303 chatr.preMinW=chatr:GetWidth();
304 chatr.preMinH=chatr:GetHeight();
305 chatr:SetWidth(90);
306 chatr:SetHeight(30);
307 end
308 end
309 Chatr_UpdateWin(chatr);
310 if Chatr_BGColor~=nil then -- iambio
311 chatr:SetBackdropColor(Chatr_BGColor[1],Chatr_BGColor[2],Chatr_BGColor[3],Chatr_BGColor[4]);
312 else
313 chatr:SetBackdropColor(0,0,0,1);
314 end
315  
316 end
317  
318 function Chatr_CloseOrMinimize(chatr)
319 if IsAltKeyDown() then
320 if chatr.docked==1 then
321 Chatr_Undock(chatr);
322 else
323 Chatr_Dock(chatr);
324 end
325 elseif IsShiftKeyDown() or arg1~="LeftButton" or chatr.minimized==1 then
326 Chatr_Minimize(chatr);
327 else
328 Chatr_Close(chatr);
329 end
330 end
331  
332 function Chatr_Show(chatr)
333 chatr:Show();
334 chatr.editBox:SetAlpha(0.33);
335 chatr:ClearAllPoints();
336 chatr:SetBackdropColor(Chatr_BGColor[1],Chatr_BGColor[2],Chatr_BGColor[3],Chatr_BGColor[4]);
337 chatr:SetBackdropBorderColor(Chatr_BorderColor[1],Chatr_BorderColor[2],Chatr_BorderColor[3],Chatr_BorderColor[4]);
338 if Chatr_LastPositions[chatr.target]~=nil then
339 local ap1,ap2,x,y,w,h=unpack(Chatr_LastPositions[chatr.target]);
340 chatr:SetPoint(ap1,UIParent,ap2,x,y);
341 chatr:SetWidth(w);
342 chatr:SetHeight(h);
343 else
344 chatr:SetPoint("CENTER",UIParent,"CENTER",Chatr_DefaultPos[1]+random(-30,30),Chatr_DefaultPos[2]+random(-30,30));
345 chatr:SetWidth(Chatr_DefaultSize[1]);
346 chatr:SetHeight(Chatr_DefaultSize[2]);
347 end
348 end
349  
350 function Chatr_EBEnter(eb)
351 eb:SetAlpha(1);
352 end
353  
354 function Chatr_EBLeave(eb)
355 if eb.hasFocus==0 then
356 eb:SetAlpha(0.33);
357 end
358 end
359  
360 function Chatr_AbandonEntry(chatr)
361 chatr.editBox:ClearFocus();
362 chatr.editBox:SetText("");
363 Chatr_EBLeave(chatr.editBox);
364 Chatr_Leave(chatr);
365 end
366  
367 function Chatr_EntryChar()
368 local _temp;
369 if FLT_ChatEdit_OnChar~=nil then -- GFWL support
370 if FLT_Orig_ChatEdit_OnChar then
371 _temp=FLT_Orig_ChatEdit_OnChar;
372 FLT_Orig_ChatEdit_OnChar=nil;
373 end
374 FLT_ChatEdit_OnChar();
375 if _temp then
376 FLT_Orig_ChatEdit_OnChar=_temp;
377 end
378 end
379 end
380  
381 function Chatr_ProcessSlash(chatr,text)
382 -- Blatantly stolen from Blizzard. I should play a rogue.
383 local command = gsub(text, "/([^%s]+)%s(.*)", "/%1", 1);
384 local msg = "";
385 if command ~= text then
386 msg = strsub(text, strlen(command) + 2);
387 end
388 command = strupper(gsub(command, "%s+", ""));
389 for index, value in SlashCmdList do
390 local i = 1;
391 local cmdString = getglobal("SLASH_"..index..i);
392 while cmdString do
393 cmdString = strupper(cmdString);
394 if cmdString == command then
395 value(msg);
396 Chatr_AbandonEntry(chatr);
397 return 1;
398 end
399 i=i+1;
400 cmdString = getglobal("SLASH_"..index..i);
401 end
402 end
403 return nil;
404 end
405  
406 function Chatr_Send(chatr)
407 local target=chatr.target;
408 local msg=chatr.editBox:GetText();
409 local msgl=strlower(msg);
410 if msg~="" then
411 chatr.editBox:AddHistoryLine(msg);
412 if msgl=="/invite" then
413 InviteByName(target);
414 elseif msgl=="/who" then
415 Chatr_Who(target);
416 elseif strsub(msgl,1,1)=="/" and Chatr_ExecSlash==1 then
417 if Chatr_ProcessSlash(chatr,msg)~=1 then
418 Chatr_Print("Unknown slash command.");
419 end
420 else
421 Chatr_Debug("Sent <"..msg.."> to "..target);
422 SendChatMessage(msg, "WHISPER", nil, target);
423 end
424 end
425 Chatr_AbandonEntry(chatr);
426 end
427  
428 function Chatr_FocusLast()
429 local c;
430 if Chatr_LastFocused~=nil then
431 c=getglobal("Chatr"..Chatr_LastFocused);
432 if c.docked==1 then
433 Chatr_DockSelected=Chatr_LastFocused;
434 Chatr_UpdateDock(1);
435 end
436 if c.open==1 then
437 c.editBox:SetFocus();
438 c.editBox:SetText("");
439 end
440  
441 end
442 end
443 function Chatr_FocusDock()
444 local c;
445 if ChatrDock:IsShown() then
446 if Chatr_DockSelected~=0 then
447 c=getglobal("Chatr"..Chatr_DockSelected);
448 if c.open==1 then
449 c.editBox:SetFocus();
450 c.editBox:SetText("");
451 end
452 end
453 else
454 Chatr_FocusLast();
455 end
456  
457 end
458  
459  
460 function Chatr_NextTab()
461 local t;
462 Chatr_UpdateDockIds();
463 if Chatr_DockedIds[1]~=nil then
464 t=Chatr_tidx(Chatr_DockedIds,Chatr_DockSelected)+1;
465 if Chatr_DockedIds[t]==nil then
466 Chatr_DockSelected=Chatr_DockedIds[1];
467 else
468 Chatr_DockSelected=Chatr_DockedIds[t];
469 end
470 end
471 Chatr_UpdateDock();
472 end
473  
474 function Chatr_CloseTab()
475 if Chatr_DockSelected and Chatr_DockSelected>0 then Chatr_Close(getglobal("Chatr"..Chatr_DockSelected)); end
476 end
477  
478 function Chatr_PrevTab()
479 local t;
480 Chatr_UpdateDockIds();
481 if Chatr_DockedIds[1]~=nil then
482 t=Chatr_tidx(Chatr_DockedIds,Chatr_DockSelected)-1;
483 if Chatr_DockedIds[t]==nil then
484 Chatr_DockSelected=Chatr_DockedIds[getn(Chatr_DockedIds)];
485 else
486 Chatr_DockSelected=Chatr_DockedIds[t];
487 end
488 end
489 Chatr_UpdateDock();
490 end
491  
492  
493 function Chatr_Who(s)
494 FriendsFrame:UnregisterEvent("WHO_LIST_UPDATE");
495 SetWhoToUI(1);
496 SendWho(s);
497 Chatr_Whoed=1;
498 end
499  
500 function Chatr_OpenFor(name)
501 local frame,i,fn,fs,ff;
502 i=Chatr_FindFree();
503 if i<0 then
504 Chatr_Print("No free chatrbox for "..name);
505 return -1;
506 end
507 frame=getglobal("Chatr"..i);
508 frame.target=name;
509 frame.opened=time();
510 frame.editBox=getglobal("Chatr"..i.."EditBox");
511 frame.chatBox=getglobal("Chatr"..i.."ChatBox");
512 frame.title=getglobal("Chatr"..i.."Title");
513 frame.close=getglobal("Chatr"..i.."Close");
514 frame.sizer=getglobal("Chatr"..i.."Sizer");
515 frame.menu=getglobal("Chatr"..i.."MenuButton");
516 if Chatr_AutoWho==1 then
517 Chatr_Who(name);
518 end
519 frame.editBox:ClearAllPoints();
520 if Chatr_EntryInside==1 then
521 frame.editBox:SetPoint("TOPLEFT",frame,"BOTTOMLEFT",2,21);
522 frame.editBox:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-2,1);
523 frame.chatBox:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-5,24);
524 else
525 frame.editBox:SetPoint("TOPLEFT",frame,"BOTTOMLEFT",2,4);
526 frame.editBox:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-2,-16);
527 frame.chatBox:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-5,7);
528 end
529 Chatr_UpdateWin(frame);
530 frame.editBox:SetMaxLetters(250);
531 frame.editBox:SetAltArrowKeyMode(false);
532 frame.editBox.hasFocus=0;
533 frame.chatBox:Clear();
534 frame.editBox:Show();
535 frame.chatBox:Show();
536 frame.menu:SetAlpha(0.4);
537 frame:GetTitleRegion():SetAllPoints();
538 frame:SetMovable(true);
539 fn,fs,ff=frame.chatBox:GetFont();
540 frame.chatBox:SetFont(fn,Chatr_FontSize,ff);
541  
542 -- Hey, if you happen to be a WoW developer, could you puh-lease
543 -- add "EditBox:ClearHistoryLines()"? Pleeeeeease? It'd keep the kittens happy!
544 for i=1,frame.editBox:GetHistoryLines() do
545 frame.editBox:AddHistoryLine("");
546 end
547 frame.minimized=0;
548 frame.combatmind=0;
549 frame.docked=0;
550 frame.open=1;
551 Chatr_Debug("Opened for "..name..": "..i);
552 Chatr_Show(frame);
553 if Chatr_AutoDock==1 then
554 Chatr_Dock(frame);
555 end
556 Chatr_DoCallMe("OpenChatr",frame);
557 return i;
558 end
559  
560 function Chatr_ChatWheel(chatframe, value)
561 if IsShiftKeyDown() then
562 if value>0 then chatframe:ScrollToTop(); elseif value<0 then chatframe:ScrollToBottom(); end
563 else
564 if value>0 then chatframe:ScrollUp(); elseif value<0 then chatframe:ScrollDown(); end
565 end
566 end
567  
568 function Chatr_MakeTitle(name,minimized,small)
569 local s;
570 if Chatr_Statuses[name]~=nil and minimized~=1 then
571 if small==1 then
572 s="<"..strsub(Chatr_Statuses[name],1,3)..">"..name;
573 else
574 s="<"..Chatr_Statuses[name]..">"..name;
575 end
576 else
577 s=name;
578 end
579 if Chatr_WhoInfo[name]~=nil and minimized~=1 then
580  
581 if small==1 then
582 s=s..":"..Chatr_WhoInfo[name][3]..strsub(Chatr_WhoInfo[name][4],1,2)..strsub(Chatr_WhoInfo[name][5],1,4).." "..gsub(Chatr_WhoInfo[name][6]," ","");
583 else
584 s=s..": "..Chatr_WhoInfo[name][3].." "..Chatr_WhoInfo[name][4].." "..Chatr_WhoInfo[name][5].." - "..Chatr_WhoInfo[name][6];
585 if Chatr_WhoInfo[name][2]~="" then s=s.." <"..Chatr_WhoInfo[name][2]..">" end;
586 end
587 if time()-Chatr_WhoInfo[name][1]>300 then s=s.." (?)"; end
588 end
589 return s;
590 end
591  
592 function Chatr_UpdateWin(chatr)
593 if (chatr:GetWidth())<250 then
594 chatr.title:SetText(Chatr_MakeTitle(chatr.target,chatr.minimized,1));
595 else
596 chatr.title:SetText(Chatr_MakeTitle(chatr.target,chatr.minimized));
597 end
598 chatr:SetAlpha(1);
599 end
600  
601 function Chatr_Fmt(fmt,vars)
602 s=date(fmt);
603 for k,v in vars do
604 s=gsub(s,k,v);
605 end
606 return s;
607 end
608  
609 function Chatr_AddWhisper(name,msg,status)
610 local i,chatr;
611 i=Chatr_FindByName(name);
612 if i==-1 then
613 Chatr_Debug("Opening window for "..name.." on incoming whisper");
614 i=Chatr_OpenFor(name);
615 if i==-1 then return false; end
616 end
617 chatr=getglobal("Chatr"..i);
618 if status=="DND" or status=="AFK" then
619 if Chatr_Statuses[name]==nil or (Chatr_Statuses[name]~=nil and (strlen(Chatr_Statuses[name])<strlen(status) or status~=strsub(Chatr_Statuses[name],1,3))) then
620 Chatr_Statuses[name]=status;
621 end
622 else
623 Chatr_Statuses[name]=nil;
624 end
625 if strsub(msg,1,3)=="/me" then
626 vars={["$text"]=name.." "..strsub(msg,5)};
627 fmtd=Chatr_Fmt(Chatr_NoteFormat,vars);
628 else
629 vars={["$name"]=name,["$text"]=msg};
630 fmtd=Chatr_Fmt(Chatr_TextFormat,vars);
631 end
632 if Chatr_Statuses[name]~=nil then
633 chatr.chatBox:AddMessage(fmtd,Chatr_AFKTextColor[1],Chatr_AFKTextColor[2],Chatr_AFKTextColor[3]);
634 else
635 chatr.chatBox:AddMessage(fmtd,Chatr_NormalTextColor[1],Chatr_NormalTextColor[2],Chatr_NormalTextColor[3]);
636 end
637 Chatr_UpdateWin(chatr);
638 if chatr.minimized==1 then
639 chatr:SetBackdropColor(1,0.75,0,1);
640 end
641 if chatr.docked==1 then
642 getglobal("ChatrDockBtn"..(chatr.id)):SetTextColor(1,1,0);
643 end
644  
645 Chatr_UpdateWin(chatr);
646  
647 if Chatr_AutoWho==1 and (Chatr_WhoInfo[name]==nil or time()-Chatr_WhoInfo[name][1]>450) then
648 Chatr_Who(name);
649 end
650 Chatr_DoCallMe("IncomingWhisper",chatr,name,msg,fmtd);
651 return true;
652 end
653  
654 function Chatr_AddWhisperTo(name,msg)
655 local i,chatr;
656 i=Chatr_FindByName(name);
657 if i==-1 then
658 Chatr_Debug("Opening window for "..name.." on outgoing whisper");
659 i=Chatr_OpenFor(name);
660 if i==-1 then return false; end
661 end
662 chatr=getglobal("Chatr"..i);
663 uname=UnitName("player");
664 if strsub(msg,1,3)=="/me" then
665 vars={["$text"]=uname.." "..strsub(msg,5)};
666 fmtd=Chatr_Fmt(Chatr_NoteFormat,vars);
667 else
668 vars={["$name"]=uname,["$text"]=msg};
669 fmtd=Chatr_Fmt(Chatr_TextFormat,vars);
670 end
671 chatr.chatBox:AddMessage(fmtd,Chatr_SelfTextColor[1],Chatr_SelfTextColor[2],Chatr_SelfTextColor[3]);
672 Chatr_UpdateWin(chatr);
673 Chatr_DoCallMe("OutgoingWhisper",chatr,name,msg,fmtd);
674 return true;
675 end
676  
677 function Chatr_AddNote(name,msg,allowOpen)
678 local i,chatr,vars,fmtd;
679 i=Chatr_FindByName(name);
680 if i==-1 then
681 if allowOpen==1 then
682 Chatr_Debug("Opening window for "..name.." on info");
683 i=Chatr_OpenFor(name);
684 if i==-1 then return false; end
685 else
686 return false;
687 end
688 end
689 chatr=getglobal("Chatr"..i);
690 vars={["$text"]=msg};
691 fmtd=Chatr_Fmt(Chatr_NoteFormat,vars)
692 chatr.chatBox:AddMessage(fmtd,Chatr_NoteTextColor[1],Chatr_NoteTextColor[2],Chatr_NoteTextColor[1]);
693 Chatr_UpdateWin(chatr);
694 Chatr_DoCallMe("Note",chatr,name,msg,fmtd);
695 return true;
696 end
697  
698 function Chatr_Enter(chatr)
699 chatr:SetAlpha(1);
700 end
701  
702 function Chatr_Leave(chatr)
703 if Chatr_AllowFade==1 then
704 chatr:SetAlpha(0.5);
705 end
706 end
707  
708 function Chatr_UpdateDockIds()
709 Chatr_DockedIds={};
710 for i=1,Chatr_Max do
711 if getglobal("Chatr"..i).docked==1 then
712 tinsert(Chatr_DockedIds,i);
713 end
714 end
715 end
716  
717 function Chatr_UpdateDock(noClearColor)
718 local last,i,v,b,id,c,n,openTo;
719 last=nil;
720 Chatr_UpdateDockIds();
721 if Chatr_tidx(Chatr_DockedIds,Chatr_DockSelected)==nil then
722 Chatr_DockSelected=Chatr_DockedIds[1];
723 end
724 if ChatrDock:GetLeft()<=GetScreenWidth()/2.0 then openTo=0; else openTo=1; end
725 n=0;
726 for i=1,Chatr_Max do
727 id="ChatrDockBtn"..i;
728 b=getglobal(id)
729 c=getglobal("Chatr"..i)
730 if c.open==1 and c.docked==1 then
731 b:ClearAllPoints();
732 if last==nil then
733 if openTo==1 then
734 b:SetPoint("TOPRIGHT","ChatrDock","TOPLEFT",-5,4);
735 else
736 b:SetPoint("TOPLEFT","ChatrDock","TOPLEFT",5,4);
737 end
738 else
739 if Chatr_DockMode~=1 then -- normal dock
740 if openTo==1 then
741 b:SetPoint("TOPRIGHT",last,"TOPLEFT");
742 else
743 b:SetPoint("TOPLEFT",last,"TOPRIGHT");
744 end
745 else
746 b:SetPoint("TOPLEFT",last,"BOTTOMLEFT",0,4);
747 end
748 end
749 if ChatrDock.minimized==1 then
750 b:Hide();
751 else
752 b:Show();
753 end
754 b:SetText(strsub(c.target,1,8));
755 last=id;
756 c:ClearAllPoints();
757 if Chatr_DockMode~=1 then -- normal dock
758 if openTo==1 then
759 c:SetPoint("TOPRIGHT","ChatrDock","BOTTOMLEFT",5,2);
760 else
761 c:SetPoint("TOPLEFT","ChatrDock","BOTTOMLEFT",5,2);
762 end
763 else
764 if openTo==1 then
765 c:SetPoint("TOPRIGHT","ChatrDock","TOPLEFT",-65,0);
766 else
767 c:SetPoint("TOPLEFT","ChatrDock","TOPLEFT",65,0);
768 end
769 end
770 if ChatrDock.minimized==1 then
771 c:Hide();
772 else
773 if Chatr_DockSelected==i then
774 c:Show();
775 if noClearColor==nil then b:SetTextColor(1,1,1,1); end
776 else
777 c:Hide();
778 if noClearColor==nil then b:SetTextColor(1,1,1,0.66); end
779 end
780 end
781 n=n+1;
782 else
783 b:Hide();
784 end
785 end
786 if n>0 then
787 ChatrDock:Show()
788 else
789 ChatrDock:Hide()
790 end
791 end
792  
793 function Chatr_DockClick(id)
794 ChatrMenu:Hide();
795 Chatr_DockSelected=id;
796 Chatr_UpdateDock();
797 end
798  
799 function Chatr_Dock(chatr)
800 chatr.docked=1;
801 Chatr_DockSelected=chatr.id;
802 chatr:GetTitleRegion():ClearAllPoints();
803 chatr:SetMovable(false);
804 Chatr_DockClick(chatr.id);
805 end
806  
807 function Chatr_Undock(chatr)
808 chatr.docked=0;
809 chatr:ClearAllPoints();
810 chatr:SetPoint("CENTER","UIParent");
811 chatr:GetTitleRegion():SetAllPoints();
812 chatr:SetMovable(true);
813 Chatr_UpdateDock();
814 end
815  
816 function Chatr_DockClose(st)
817 if st~=nil then
818 ChatrDock.minimized=st;
819 else
820 ChatrDock.minimized=1-ChatrDock.minimized;
821 end
822 if ChatrDock.minimized==1 then
823 ChatrDockClose:SetAlpha(1);
824 else
825 ChatrDockClose:SetAlpha(0.33);
826 end
827 ChatrDockText:SetText("");
828 Chatr_UpdateDock(1);
829 end
830  
831 function Chatr_ContainerFrameItemButton_OnClick(button, igm)
832 if Chatr_EditFocus~=nil and (IsShiftKeyDown() and not igm) then
833 Chatr_EditFocus:Insert(GetContainerItemLink(this:GetParent():GetID(),this:GetID()));
834 return
835 end
836 Chatr_HookedFuncs["ContainerFrameItemButton_OnClick"](button,igm)
837 end
838 function Chatr_PaperDollItemSlotButton_OnClick(button, igm)
839 if Chatr_EditFocus~=nil and (IsShiftKeyDown() and not igm) then
840 Chatr_EditFocus:Insert(GetInventoryItemLink("player", this:GetID()));
841 return
842 end
843 Chatr_HookedFuncs["PaperDollItemSlotButton_OnClick"](button,igm)
844 end
845 function Chatr_BankFrameItemButtonGeneric_OnClick(button)
846 if Chatr_EditFocus~=nil and IsShiftKeyDown() then
847 Chatr_EditFocus:Insert(GetContainerItemLink(BANK_CONTAINER, this:GetID()));
848 return
849 end
850 Chatr_HookedFuncs["BankFrameItemButtonGeneric_OnClick"](button)
851 end
852  
853 function Chatr_SetItemRef(arg1,arg2,arg3)
854 if Chatr_EditFocus~=nil and IsShiftKeyDown() then
855 Chatr_EditFocus:Insert(arg2);
856 return
857 end
858 Chatr_HookedFuncs["SetItemRef"](arg1,arg2,arg3)
859 end
860  
861  
862 function Chatr_ColorFunc()
863 local R,G,B = ColorPickerFrame:GetColorRGB();
864 if ColorPickerFrame.hasOpacity==true then
865 setglobal(Chatr_UpdatingColor,{R,G,B,1.0-OpacitySliderFrame:GetValue()});
866 else
867 setglobal(Chatr_UpdatingColor,{R,G,B});
868 end
869 end
870  
871 function Chatr_ColorCancelFunc(prevvals)
872 setglobal(Chatr_UpdatingColor,Chatr_ColorBackup);
873 end
874  
875  
876 function Chatr_OptSetColor(name)
877 local tab=getglobal(name);
878 local R,G,B = tab[1],tab[2],tab[3];
879 if tab[4]~=nil then
880 ColorPickerFrame.opacity = 1.0-tab[4];
881 ColorPickerFrame.hasOpacity = true;
882 else
883 ColorPickerFrame.hasOpacity = false;
884 end
885  
886 Chatr_UpdatingColor=name;
887 Chatr_ColorBackup=getglobal(name);
888 ColorPickerFrame.func = Chatr_ColorFunc;
889 ColorPickerFrame.cancelFunc = Chatr_ColorCancelFunc;
890 ColorPickerFrame:Show();
891 ColorPickerFrame:SetColorRGB(R, G, B);
892 end
893  
894 function Chatr_Menu(chatr)
895 if ChatrMenu:IsShown() then
896 ChatrMenu:Hide();
897 else
898 ChatrMenu.chatr=chatr;
899 ChatrMenu:ClearAllPoints();
900 if chatr:GetLeft()<=GetScreenWidth()/2.0 then
901 ChatrMenu:SetPoint("TOPLEFT",chatr,"TOPRIGHT");
902 else
903 ChatrMenu:SetPoint("TOPRIGHT",chatr,"TOPLEFT");
904 end
905 ChatrMenu:Show();
906 end
907 end
908  
909 function Chatr_CheckFilter(tab,name,msg)
910 for _,v in tab do
911 name,msg=v(name,msg);
912 if name==0 or msg==0 then return nil; end
913 end
914 return name,msg;
915 end
916  
917 function Chatr_QuickToggle()
918 if Chatr_QuickToggled==0 then
919 for i=1,Chatr_Max do
920 chatr=getglobal("Chatr"..i);
921 chatr.combatmind=0;
922 if chatr.docked==0 and chatr.minimized==0 and chatr.open==1 then
923 Chatr_Minimize(chatr);
924 end
925 end
926 Chatr_DockClose(1);
927 else
928 for i=1,Chatr_Max do
929 chatr=getglobal("Chatr"..i);
930 if chatr.docked==0 and chatr.minimized==1 and chatr.open==1 then
931 Chatr_Minimize(chatr);
932 end
933 end
934 Chatr_DockClose(0);
935 end
936 Chatr_QuickToggled=1-Chatr_QuickToggled;
937 end
938  
939 function Chatr_Event()
940 local n,i, charname, guildname, level, race, class, zone, u,chatr;
941 if event=="CHAT_MSG_WHISPER" and strsub(arg1,1,4)~="$CH#" then
942 name,msg=Chatr_CheckFilter(Chatr_InboundFilters,arg2,arg1);
943 if name then
944 if Chatr_PlaySound==1 then PlaySound("TellMessage"); end
945 Chatr_AddWhisper(name,msg,arg6);
946 if ChatrDock.minimized==1 then
947 ChatrDockText:SetText("New message: "..name);
948 end
949 end
950 return;
951 end
952 if event=="CHAT_MSG_WHISPER_INFORM" and strsub(arg1,1,4)~="$CH#" then
953 name,msg=Chatr_CheckFilter(Chatr_OutboundFilters,arg2,arg1);
954 if name then
955 Chatr_AddWhisperTo(name,msg);
956 end
957 return;
958 end
959 if event=="CHAT_MSG_DND" or event=="CHAT_MSG_AFK" then
960 g=strsub(event,-3);
961 newStatus=g..": "..arg1;
962 if newStatus~=Chatr_Statuses[arg2] then
963 Chatr_Statuses[arg2]=newStatus;
964 Chatr_AddNote(arg2,arg2..": "..newStatus,0);
965 end
966 return;
967 end
968 if event=="WHO_LIST_UPDATE" then
969 if Chatr_Whoed==1 then
970 Chatr_Debug("Reverting who frame");
971 FriendsFrame:Hide();
972 FriendsFrame:RegisterEvent("WHO_LIST_UPDATE");
973 SetWhoToUI(0);
974 Chatr_Whoed=0;
975 end
976 n,_=GetNumWhoResults();
977 Chatr_Debug("Updating who info, "..n.." entries");
978 for i=1,n do
979 charname, guildname, level, race, class, zone = GetWhoInfo(i);
980 Chatr_WhoInfo[charname]={time(),guildname, level, race, class, zone};
981 u=Chatr_FindByName(charname);
982 if u>-1 then Chatr_UpdateWin(getglobal("Chatr"..u)); end
983 end
984 end
985 if event=="VARIABLES_LOADED" then
986 Chatr_LoadSettings();
987 Chatr_Print(Chatr_Version.." loaded - /chatr for options.");
988 Chatr_Ready=1;
989 end
990  
991 if event=="PLAYER_REGEN_DISABLED" and Chatr_MinInCombat==1 then
992 for i=1,Chatr_Max do
993 chatr=getglobal("Chatr"..i);
994 if chatr.docked==0 and chatr.minimized==0 and chatr.open==1 then
995 Chatr_Minimize(chatr);
996 chatr.combatmind=1;
997 end
998 end
999 Chatr_DockClose(1);
1000 end
1001 if event=="PLAYER_REGEN_ENABLED" and Chatr_MinInCombat==1 then
1002 for i=1,Chatr_Max do
1003 chatr=getglobal("Chatr"..i);
1004 if chatr.docked==0 and chatr.minimized==1 and chatr.open==1 and chatr.combatmind==1 then
1005 Chatr_Minimize(chatr);
1006 chatr.combatmind=0;
1007 end
1008 end
1009 Chatr_DockClose(0);
1010 end
1011  
1012 end
1013  
1014 Chatr_SettingNames={
1015 "TextFormat","NoteFormat",
1016 "NormalTextColor","AFKTextColor","SelfTextColor",
1017 "NoteTextColor","BGColor","BorderColor",
1018 "AutoDock","AllowFade","AutoWho",
1019 "FontSize","MinInCombat","DockMode","EntryInside",
1020 "PlaySound","DefaultSize"};
1021  
1022 function Chatr_LoadSettings(whom)
1023 local id,k;
1024 if whom==nil then
1025 id=UnitName("player").."@"..GetRealmName();
1026 Chatr_Debug("trying to load settings "..id);
1027 Chatr_SavePerChar=1;
1028 for k,_ in Chatr_Options do
1029 Chatr_Debug("Key: "..k);
1030 end
1031 if Chatr_Options[id]==nil then id="global"; Chatr_SavePerChar=0; end
1032 else
1033 id=whom;
1034 end
1035 if Chatr_Options[id]~=nil then
1036 for _,k in Chatr_SettingNames do
1037 if Chatr_Options[id][k]~=nil then
1038 setglobal("Chatr_"..k,Chatr_Options[id][k]);
1039 end
1040 end
1041 if getn(Chatr_BGColor)==3 then Chatr_BGColor={Chatr_BGColor[1],Chatr_BGColor[2],Chatr_BGColor[3],1}; end
1042 else
1043 Chatr_Print("Chatr loaded default settings - id "..id.." was not found.");
1044 end
1045 Chatr_DoCallMe("SettingsLoaded",nil);
1046 end
1047  
1048 function Chatr_SaveSettings(as)
1049 local v;
1050 if as==nil then
1051 Chatr_SavePerChar=ChatrOptionsSavePer:GetChecked();
1052 if Chatr_SavePerChar==nil then Chatr_SavePerChar=0; end
1053 if Chatr_SavePerChar==1 then
1054 id=UnitName("player").."@"..GetRealmName();
1055 else
1056 id="global";
1057 end
1058 else
1059 id=as;
1060 end
1061 Chatr_Options[id]={};
1062 for _,k in Chatr_SettingNames do
1063 v=getglobal("Chatr_"..k);
1064 if v==nil then v=0; end
1065 Chatr_Options[id][k]=v;
1066 end
1067 if as==nil then Chatr_Print("Settings saved ("..id..")"); end
1068 end
1069  
1070 function Chatr_AddPluginButton(button)
1071 button:ClearAllPoints();
1072 if Chatr_LastPluginButton==nil then
1073 button:SetPoint("TOPRIGHT",ChatrOptions,"TOPLEFT",-5,0);
1074 else
1075 button:SetPoint("TOPRIGHT",Chatr_LastPluginButton,"BOTTOMRIGHT",0,0);
1076 end
1077 Chatr_LastPluginButton=button;
1078 end
1079  
1080 function Chatr_SaveThis(...)
1081 local _,v;
1082 for _,v in arg do
1083 tinsert(Chatr_SettingNames,v);
1084 end
1085 end
1086  
1087 function Chatr_CallMe(when,func)
1088 if Chatr_CallMes[when]==nil then
1089 Chatr_CallMes[when]={};
1090 end
1091 tinsert(Chatr_CallMes[when],func);
1092 end
1093  
1094 function Chatr_DontCallMe(when,func)
1095 if Chatr_CallMes[when]==nil then return; end
1096 Chatr_tremovebyval(Chatr_CallMes[when],func);
1097 end
1098  
1099 function Chatr_DoCallMe(...)
1100 local _,v;
1101 if getn(arg)<1 then return; end
1102 when=arg[1];
1103 if Chatr_CallMes[when]==nil then return; end
1104 for _,v in Chatr_CallMes[when] do
1105 if v(arg)=="break" then return; end
1106 end
1107 end
1108  
1109 function Chatr_Init()
1110 local chatr,i,k;
1111 SlashCmdList["CHATRCMD"] = Chatr_Cmd;
1112 SLASH_CHATRCMD1 = "/chatr";
1113 for i=1,Chatr_Max do
1114 chatr=getglobal("Chatr"..i);
1115  
1116 if chatr~=nil then
1117 chatr:Hide();
1118 chatr.id=i;
1119 chatr.open=0;
1120 else
1121 Chatr_Print("Nil: "..i);
1122 end
1123 end
1124 for _,k in Chatr_HookNames do
1125 of=getglobal(k);
1126 nf=getglobal("Chatr_"..k);
1127  
1128 if of==nil then
1129 Chatr_Print("Hooked function "..k.." does not exist");
1130 elseif nf==nil then
1131 Chatr_Print("Hook function replacement for "..k.." does not exist");
1132 else
1133 Chatr_HookedFuncs[k]=of;
1134 setglobal(k,nf);
1135 Chatr_Debug("Hooked "..k);
1136 end
1137 end
1138 ChatrDock.minimized=0;
1139 ChatrOptionsQuote:SetText(Chatr_Version.." (C) AKX 2006\n"..Chatr_VerQuote.."\nCheck /chatr help for some more options");
1140 ChatrOptionsQuote:SetFont("Fonts/ARIALN.ttf",11,"");
1141 end