vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 - System Message Control Tool
3  
4 - Redirect certain system messages to different chat windows or completely mute them.
5  
6 - Version: 1.28
7 ]]
8  
9 smctVars = {
10 name = "System Message Control Tool",
11 version = "1.28",
12 count = 0,
13 realmName = GetCVar("realmName"),
14 playerName = UnitName("player"),
15 curID = nil,
16 curGroup = nil,
17 events = nil,
18 chatWindows = nil,
19 profileOpenID = nil,
20 chatSystemUpdated = {},
21 chatGroupsAdded = false,
22 chatMenuItemsAdded = false;
23 ChatFrame_OnEvent = nil,
24 FCF_Tab_OnClick = nil,
25 FCF_SetChatTypeColor = nil,
26 FCF_CancelFontColorSettings = nil,
27 FCFMessageTypeDropDown_OnClick = nil,
28 channels = {},
29 channelsIgnore = {
30 ["CT_RA_Channel"] = "variable",
31 ["DamageMeters_syncChannel"] = "variable",
32 },
33 coreSystemGroups = {
34 [1] = "OFFICER",
35 [2] = "GUILD_MOTD",
36 },
37 predefinedColors = {
38 [1] = {event="SYSTEM", description="System"},
39 [2] = {event="LOOT", description="Loot"},
40 [3] = {event="MONEY", description="Money loot"},
41 [4] = {event="BG_SYSTEM_ALLIANCE", description="BG: Alliance"},
42 [5] = {event="BG_SYSTEM_HORDE", description="BG: Horde"},
43 [6] = {event="BG_SYSTEM_NEUTRAL", description="BG: Neutral"},
44 [7] = {event="CHANNEL_LIST", description="Channel list"},
45 [8] = {event="PARTY", description="Party"},
46 [9] = {event="RAID", description="Raid"},
47 [10] = {event="GUILD", description="Guild"},
48 [11] = {event="OFFICER", description="Officer"},
49 [12] = {event="SKILL", description="Skill-up"},
50 },
51 text = {
52 closeWindow = "Close window",
53 muted = "Muted",
54 passthrough = "Pass-through",
55 multipleWindows = "Multiple windows",
56 floating = "Floating",
57 windowSelectHeader = "Select message action",
58 colorGroupError = "ERROR: Couldn't find color group.",
59 optionOpenError = "ERROR: Frame already active.",
60 },
61 helpText = {
62 [1] = "|cff9bb6efHelp/information for SMCT|r";
63 [2] = "";
64 [3] = "|cfff7a21ePass-through:|r";
65 [4] = "The pass-through setting means that SMCT will ignore messages from that group and send them back into the original chat system, so it can do whatever it is setup to do.";
66 [5] = "If you just want to change the color of a message group then you can't leave it at pass-through. You will have to set the window it should be displayed in also.";
67 [6] = "";
68 [7] = "|cfff7a21eSelecting multiple windows:|r";
69 [8] = "You can send messages to multiple chat windows by holding down the shift key while selecting the windows in the menu. When you're done click the \"Close window\" button.";
70 [9] = "The \"Floating\" type can also be selected when using multiple windows.";
71 [10] = "";
72 [11] = "|cfff7a21eProfiles:|r";
73 [12] = "Click the \"Profiles\" button to copy settings from other existing profiles to this character.";
74 },
75 language = string.upper(string.sub(GetLocale(), 1, 2)),
76 indexes = {
77 ["floating"] = 100,
78 ["close"] = -10,
79 ["passthrough"] = 0,
80 ["muted"] = -1,
81 },
82 changedChannels = {
83 },
84 };
85  
86  
87  
88 function smctConvStr(s)
89 local s = string.gsub(s, "%-", "%%-");
90 s = string.gsub(s, "%+", "%%+");
91 s = string.gsub(s, "%?", "%%?");
92 s = string.gsub(s, "%.", "%%.");
93 s = string.gsub(s, "%*", "%%*");
94 s = string.gsub(s, "%%d", "%%d+");
95 s = string.gsub(s, "%%s", "[%%S]+[%%s*%%S+]*");
96 s = string.gsub(s, "%%%d$s", "[%%S]+[%%s*%%S+]*");
97 s = string.gsub(s, "%%%d$d", "[%%S]+");
98 return s;
99 end
100  
101  
102 function smctConvStr2(s)
103 local s = string.gsub(s, "%(", "%%(");
104 s = string.gsub(s, "%)", "%%)");
105 s = string.gsub(s, "%[", "%%[");
106 s = string.gsub(s, "%]", "%%]");
107 return smctConvStr(s);
108 end
109  
110  
111 function SystemMessageControlTool_OnLoad()
112 this:SetBackdropBorderColor(0.8, 0.8, 0.8, 0.9);
113 this:SetBackdropColor(0.1, 0.1, 0.1, 1);
114 this:RegisterEvent("VARIABLES_LOADED");
115 end
116  
117  
118 function SystemMessageControlTool_OnEvent(event)
119 if (event == "VARIABLES_LOADED") then
120 if (VipersAddonsLoaded) then
121 local tablePos = table.getn(VipersAddonsLoaded)+1;
122 VipersAddonsLoaded[tablePos] = {};
123 VipersAddonsLoaded[tablePos]["NAME"] = smctVars.name;
124 VipersAddonsLoaded[tablePos]["VERSION"] = smctVars.version;
125 VipersAddonsLoaded[tablePos]["OPTIONSFRAME"] = "SystemMessageControlToolFrame";
126 end
127  
128 if (not smctSettings) then
129 smctSettings = {};
130 end
131 if (not smctSettings[smctVars.realmName]) then
132 smctSettings[smctVars.realmName] = {};
133 end
134 if (not smctSettings[smctVars.realmName][smctVars.playerName]) then
135 smctSettings[smctVars.realmName][smctVars.playerName] = {};
136 end
137  
138 -- Remove any old settings in case they're there.
139 if (smctSettings.windowID) then
140 smctSettings.windowID = nil;
141 end
142 if (smctSettings.windowName) then
143 smctSettings.windowName = nil;
144 end
145  
146 SLASH_SMCT1 = "/smct";
147 SlashCmdList["SMCT"] = function(msg)
148 SystemMessageControlTool_SlashCommand(msg);
149 end
150  
151 smctVars.ChatFrame_OnEvent = ChatFrame_OnEvent;
152 smctVars.FCF_Tab_OnClick = FCF_Tab_OnClick;
153 smctVars.FCF_SetChatTypeColor = FCF_SetChatTypeColor;
154 smctVars.FCF_CancelFontColorSettings = FCF_CancelFontColorSettings;
155 smctVars.FCFMessageTypeDropDown_OnClick = FCFMessageTypeDropDown_OnClick;
156 ChatFrame_OnEvent = SystemMessageControlTool_OnEvent;
157 FCF_Tab_OnClick = smctFCF_Tab_OnClick;
158 FCF_SetChatTypeColor = smctFCF_SetChatTypeColor;
159 FCF_CancelFontColorSettings = smctFCF_CancelFontColorSettings;
160 FCFMessageTypeDropDown_OnClick = smctFCFMessageTypeDropDown_OnClick;
161  
162 -- Store current active channels.
163 local activeChannels = {GetChatWindowChannels(DEFAULT_CHAT_FRAME:GetID())};
164 local zoneID, str;
165 for i, v in activeChannels do
166 if (mod(i, 2) == 1) then
167 str = "";
168 zoneID = activeChannels[(i+1)];
169 if (zoneID > 0) then
170 str = smctConvStr(activeChannels[(i+1)]..". "..v.." - %s");
171 else
172 str = v;
173 end
174 table.insert(smctVars.channels, str)
175 end
176 end
177  
178 table.insert(UISpecialFrames, "SystemMessageControlToolFrame");
179  
180 if ((not VipersAddonsSettings) or ((VipersAddonsSettings) and (not VipersAddonsSettings["SURPRESSLOADMSG"])) and (DEFAULT_CHAT_FRAME)) then
181 DEFAULT_CHAT_FRAME:AddMessage("|cffffffff- |cff00f100Viper's "..smctVars.name.." is loaded (version "..smctVars.version..").");
182 end
183 return;
184 elseif (smctVars.events[event]) then
185 local strFound = false;
186 local group, func;
187 if (smctVars.events[event].doSearch) then
188 for i, v in smctVars.events[event].groups do
189 if (smctSkipGroup(v.group)) then
190 next(smctVars.events[event].groups);
191 end
192 for n, k in v.strings do
193 if (string.find(arg1, k)) then
194 local str = arg1;
195 func = smctVars.events[event].func;
196 if (func) then
197 str = func(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
198 end
199 if ((str) and (smctSetOutput(v.group, str))) then
200 return;
201 end
202 if (str == false) then
203 return;
204 end
205 strFound = true;
206 break;
207 end
208 end
209 if (strFound) then
210 break;
211 end
212 end
213 else
214 func = smctVars.events[event].func;
215 if ((func) and (func(smctVars.events[event].groups[1].group, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9))) then
216 return;
217 end
218 end
219 elseif (event == "UPDATE_CHAT_WINDOWS") then
220 smctVars.ChatFrame_OnEvent(event);
221 if (not smctVars.chatSystemUpdated[this:GetID()]) then
222 local i = 1;
223 local frame = getglobal("ChatFrame"..i);
224 local GuildFrame = false;
225 while (frame.messageTypeList[n]) do
226 if (frame.messageTypeList[n] == "GUILD") then
227 DEFAULT_CHAT_FRAME:AddMessage("- GUILD: "..i);
228 ChatFrame_RemoveMessageGroup(frame, "GUILD");
229 GuildFrame = true;
230 end
231 n = n + 1;
232 end
233  
234 if (not smctVars.chatMenuItemsAdded) then
235 CHAT_MSG_GUILD = "Guild: Normal";
236 CHAT_MSG_OFFICER = "Guild: Officer";
237 GUILD_MOTD = "Guild: MOTD";
238 ChatTypeInfo["GUILD_MOTD"] = {sticky=0};
239 ChatTypeGroup["GUILD"] = {
240 "CHAT_MSG_GUILD",
241 };
242 ChatTypeGroup["OFFICER"] = {
243 "CHAT_MSG_OFFICER",
244 };
245 ChatTypeGroup["GUILD_MOTD"] = {
246 "GUILD_MOTD",
247 };
248 table.insert(ChannelMenuChatTypeGroups, 4, "OFFICER");
249 table.insert(ChannelMenuChatTypeGroups, 5, "GUILD_MOTD");
250 FCF_LoadChatSubTypes(ChannelMenuChatTypeGroups);
251 smctVars.chatMenuItemsAdded = true;
252 end
253  
254 if (GuildFrame) then
255 ChatFrame_AddMessageGroup(this, "GUILD");
256 end
257 smctVars.chatSystemUpdated[this:GetID()] = true;
258 end
259 for i, v in smctVars.coreSystemGroups do
260 if (not ((smctSettings[smctVars.realmName][smctVars.playerName][v]) and (smctSettings[smctVars.realmName][smctVars.playerName][v].windowID))) then
261 smctSettings[smctVars.realmName][smctVars.playerName][v] = {};
262 smctSettings[smctVars.realmName][smctVars.playerName][v].windowID = {};
263 table.insert(smctSettings[smctVars.realmName][smctVars.playerName][v].windowID, 1);
264 end
265 for n, k in smctSettings[smctVars.realmName][smctVars.playerName][v].windowID do
266 if (k == this:GetID()) then
267 local c = 1;
268 local skipAdd = false;
269 while (this.messageTypeList[c]) do
270 if (this.messageTypeList[c] == v) then
271 skipAdd = true;
272 break;
273 end
274 c = c + 1;
275 end
276 if (not skipAdd) then
277 ChatFrame_AddMessageGroup(this, v);
278 end
279 end
280 end
281 smctVars.chatGroupsAdded = true;
282 end
283 return;
284 elseif (event == "GUILD_MOTD") then
285 local doMOTD = false;
286 local settings = smctSettings[smctVars.realmName][smctVars.playerName][event];
287 if ((settings) and (settings.windowID)) then
288 for i, v in settings.windowID do
289 if (v == this:GetID()) then
290 doMOTD = true;
291 break;
292 end
293 end
294 end
295 if (doMOTD) then
296 if ((settings) and (settings.r)) then
297 ChatTypeInfo[event].r = settings.r;
298 ChatTypeInfo[event].g = settings.g;
299 ChatTypeInfo[event].b = settings.b;
300 else
301 ChatTypeInfo[event].r = ChatTypeInfo["GUILD"].r;
302 ChatTypeInfo[event].g = ChatTypeInfo["GUILD"].g;
303 ChatTypeInfo[event].b = ChatTypeInfo["GUILD"].b;
304 end
305 local info = ChatTypeInfo["GUILD_MOTD"];
306 local string = format(TEXT(GUILD_MOTD_TEMPLATE), arg1);
307 this:AddMessage(string, info.r, info.g, info.b, info.id);
308 end
309 return;
310 end
311  
312 smctVars.ChatFrame_OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
313 end
314  
315  
316 function smctSkipGroup(group)
317 local doSkip = false;
318 if ((not smctSettings[smctVars.realmName][smctVars.playerName][group]) or ((smctSettings[smctVars.realmName][smctVars.playerName][group].windowID ~= nil) and (smctSettings[smctVars.realmName][smctVars.playerName][group].windowID == smctVars.indexes.passthrough))) then
319 doSkip = true;
320 end
321 if ((not doSkip) and (strupper(type(smctSettings[smctVars.realmName][smctVars.playerName][group].windowID)) == "TABLE")) then
322 for i, v in smctSettings[smctVars.realmName][smctVars.playerName][group].windowID do
323 if (v == -smctVars.indexes.muted) then
324 doSkip = true;
325 break;
326 end
327 end
328 end
329 return doSkip;
330 end
331  
332  
333 function smctVerifyFrame(ID)
334 local frame = getglobal("ChatFrame"..ID);
335 local frameActive = false;
336 if (frame) then
337 frameActive = true;
338 if (not frame:IsShown()) then
339 frameActive = false;
340 for index, value in DOCKED_CHAT_FRAMES do
341 if (value:GetName() == "ChatFrame"..ID) then
342 frameActive = true;
343 break;
344 end
345 end
346 end
347 end
348 return frameActive, frame;
349 end
350  
351  
352 function smctSetOutput(group, s)
353 local frameActive, frame, color;
354 local settings = smctSettings[smctVars.realmName][smctVars.playerName][group];
355 if ((settings) and (settings.windowID)) then
356 if (strupper(type(settings.windowID)) == "TABLE") then
357 color = smctGetColor(group);
358 local didDeliver = false;
359 for i, v in settings.windowID do
360 if (v == smctVars.indexes.muted) then
361 return true;
362 elseif (v == smctVars.indexes.floating) then
363 UIErrorsFrame:AddMessage(s, color.r, color.g, color.b, 1.0, UIERRORS_HOLD_TIME);
364 didDeliver = true;
365 else
366 frameActive, frame = smctVerifyFrame(v);
367 if (frameActive) then
368 frame:AddMessage(s, color.r, color.g, color.b);
369 didDeliver = true;
370 end
371 end
372 end
373 if (didDeliver) then
374 return true;
375 else
376 return false;
377 end
378 elseif (settings.windowID == smctVars.indexes.muted) then
379 return true;
380 elseif (settings.windowID == smctVars.indexes.floating) then
381 color = smctGetColor(group);
382 UIErrorsFrame:AddMessage(s, color.r, color.g, color.b, 1.0, UIERRORS_HOLD_TIME);
383 return true;
384 elseif (settings.windowID > smctVars.indexes.passthrough) then
385 -- Old code for compatability.
386 frameActive, frame = smctVerifyFrame(settings.windowID);
387 if (frameActive) then
388 color = smctGetColor(group);
389 frame:AddMessage(s, color.r, color.g, color.b);
390 return true;
391 end
392 end
393 end
394 return false;
395 end
396  
397  
398 function SystemMessageControlTool_SlashCommand(s)
399 if (SystemMessageControlToolFrame:IsVisible()) then
400 SystemMessageControlToolFrame:Hide();
401 else
402 if (not SystemMessageControlToolPredefinedColorsFrame:IsVisible()) then
403 SystemMessageControlToolFrame:Show();
404 else
405 smctSendChatMessage(smctVars.text.optionOpenError);
406 end
407 end
408 end
409  
410  
411 function smctSendChatMessage(s)
412 if (DEFAULT_CHAT_FRAME) then
413 DEFAULT_CHAT_FRAME:AddMessage("[SMCT] "..s, 0.75, 0.8, 1);
414 end
415 end
416  
417  
418 function SystemMessageControlTool_OnHide()
419 if (SystemMessageControlToolChatWindowsFrame:IsShown()) then
420 SystemMessageControlToolChatWindowsFrame:Hide();
421 end
422 if (SystemMessageControlToolProfileFrame:IsShown()) then
423 SystemMessageControlToolProfileFrame:Hide();
424 end
425 end
426  
427  
428 function SystemMessageControlTool_OnShow()
429 local groups = {};
430 local sortedEvents = {};
431 local fName = this:GetName();
432 local c = 1;
433 local tmp, color, winName;
434 local str = "";
435  
436 getglobal(fName.."HeaderText"):SetText(smctVars.name);
437 getglobal(fName.."Version"):SetText("Version "..smctVars.version);
438 for i, v in smctVars.helpText do
439 str = str..v.."\n";
440 end
441 getglobal(fName.."Help"):SetText(str);
442 getglobal(fName.."Help"):SetTextColor(0.8, 0.8, 0.8);
443  
444 table.insert(sortedEvents, smctVars.events["CHAT_MSG_LOOT"]);
445 table.insert(sortedEvents, smctVars.events["CHAT_MSG_SYSTEM"]);
446 table.insert(sortedEvents, smctVars.events["CHAT_MSG_BG_SYSTEM_ALLIANCE"]);
447 table.insert(sortedEvents, smctVars.events["CHAT_MSG_BG_SYSTEM_HORDE"]);
448 table.insert(sortedEvents, smctVars.events["CHAT_MSG_BG_SYSTEM_NEUTRAL"]);
449 table.insert(sortedEvents, smctVars.events["PLAYER_LEVEL_UP"]);
450 table.insert(sortedEvents, smctVars.events["CHARACTER_POINTS_CHANGED"]);
451 table.insert(sortedEvents, smctVars.events["TIME_PLAYED_MSG"]);
452 table.insert(sortedEvents, smctVars.events["CHAT_MSG_CHANNEL_NOTICE"]);
453 table.insert(sortedEvents, smctVars.events["CHAT_MSG_CHANNEL_LIST"]);
454 table.insert(sortedEvents, smctVars.events["CHAT_MSG_GUILD"]);
455 table.insert(sortedEvents, smctVars.events["CHAT_MSG_OFFICER"]);
456 for i, v in sortedEvents do
457 for n, k in v.groups do
458 if (not groups[k.group]) then
459 groups[k.group] = true;
460 color = smctGetColor(k.group);
461 getglobal(fName.."Group"..c.."ColorSwatchNormalTexture"):SetVertexColor(color.r, color.g, color.b);
462 getglobal(fName.."Group"..c.."SetWindow"):SetText(smctGetWindowInfo(k.group));
463 getglobal(fName.."Group"..c.."SetWindowText"):SetWidth(120);
464 tmp = getglobal(fName.."Group"..c);
465 tmp.group = k.group;
466 tmp.text = k.name;
467 tmp.tooltip = k.description;
468 tmp:Show();
469 c = c + 1;
470 end
471 end
472 end
473  
474 local i = 1;
475 smctVars.chatWindows = {
476 [1] = {index=smctVars.indexes.close, name=smctVars.text.closeWindow},
477 [2] = {index=smctVars.indexes.muted, name=smctVars.text.muted},
478 [3] = {index=smctVars.indexes.passthrough, name=smctVars.text.passthrough},
479 [4] = {index=smctVars.indexes.floating, name=smctVars.text.floating},
480 };
481 while (getglobal("ChatFrame"..i)) do
482 winName = getglobal("ChatFrame"..i.."TabText"):GetText();
483 if (winName ~= "Chat "..i) then
484 if (smctVerifyFrame(i)) then
485 table.insert(smctVars.chatWindows, {index=i, name=winName});
486 end
487 end
488 i = i + 1;
489 end
490  
491 this:SetHeight((16*c)+30);
492 end
493  
494  
495 function smctGetColor(group)
496 local gotColor = false;
497 local color = {};
498 local saved = smctSettings[smctVars.realmName][smctVars.playerName][group];
499 if ((saved) and (saved.r)) then
500 color.r = saved.r;
501 color.g = saved.g;
502 color.b = saved.b;
503 gotColor = true;
504 elseif (strsub(group, 1, 8) == "CHAT_MSG") then
505 local subEvent = string.gsub(strsub(group, 10), "_SMCT%d", "");
506 if ((ChatTypeInfo[subEvent]) and (ChatTypeInfo[subEvent].r)) then
507 color.r = ChatTypeInfo[subEvent].r;
508 color.g = ChatTypeInfo[subEvent].g;
509 color.b = ChatTypeInfo[subEvent].b;
510 gotColor = true;
511 end
512 end
513 if (not gotColor) then
514 color.r = ChatTypeInfo["SYSTEM"].r;
515 color.g = ChatTypeInfo["SYSTEM"].g;
516 color.b = ChatTypeInfo["SYSTEM"].b;
517 end
518 return color;
519 end
520  
521  
522 function smctGetWindowInfo(group)
523 local strGroup = group;
524 local group = smctSettings[smctVars.realmName][smctVars.playerName][strGroup];
525 local windowName;
526 local windowCount = 0;
527 local gotWindow = false;
528 if (group) then
529 if (group.windowID ~= nil) then
530 if (strupper(type(group.windowID)) == "TABLE") then
531 windowCount = table.getn(group.windowID);
532 if (windowCount > 1) then
533 windowName = smctVars.text.multipleWindows;
534 gotWindow = true;
535 elseif (windowCount == 1) then
536 local tmpID, tmpName = smctGetActiveWindow(strGroup);
537 if (tmpID > 0 and tmpID ~= smctVars.indexes.floating) then
538 windowName = "["..tmpID.."] "..tmpName;
539 else
540 windowName = tmpName;
541 end
542 gotWindow = true;
543 end
544 elseif (group.windowID == -1) then
545 windowName = smctVars.text.muted;
546 gotWindow = true;
547 elseif (group.windowID > 0) then
548 windowName = "["..group.windowID.."] "..group.windowName;
549 -- Convert old stored variables to work with new multiple windows code.
550 local tmpWindowID = group.windowID;
551 local tmpWindowName = group.windowName;
552 group.windowID = {};
553 group.windowName = {};
554 table.insert(group.windowID, tmpWindowID);
555 table.insert(group.windowName, tmpWindowName);
556 gotWindow = true;
557 end
558 end
559 end
560 if (not gotWindow) then
561 windowName = smctVars.text.passthrough;
562 end
563 return windowName, windowCount;
564 end
565  
566  
567 function smctOpenColorPicker(group, ID)
568 local btn;
569 for i, v in smctVars.predefinedColors do
570 btn = getglobal("SystemMessageControlToolPredefinedColorsFrameButton"..i);
571 btn:SetWidth(100);
572 btn:SetText(v.description);
573 btn:SetScript("OnClick", function() smctSetPredefinedColor(this:GetID()) end);
574 end
575 local color = smctGetColor(group);
576 smctVars.curID = ID;
577 smctVars.curGroup = group;
578 ColorPickerFrame.func = smctSaveColorPicker;
579 ColorPickerFrame.cancelFunc = smctCancelColorPicker;
580 ColorPickerFrame.hasOpacity = false;
581 ColorPickerFrame:SetColorRGB(color.r, color.g, color.b);
582 ColorPickerFrame.previousValues = {r = color.r, g = color.g, b = color.b};
583 SystemMessageControlToolFrame:Hide();
584 ColorPickerFrame:Show();
585 SystemMessageControlToolPredefinedColorsFrame:Show();
586 end
587  
588  
589 function smctSaveColorPicker()
590 local r, g, b = ColorPickerFrame:GetColorRGB();
591 if (not smctSettings[smctVars.realmName][smctVars.playerName][smctVars.curGroup]) then
592 smctSettings[smctVars.realmName][smctVars.playerName][smctVars.curGroup] = {};
593 end
594 smctSettings[smctVars.realmName][smctVars.playerName][smctVars.curGroup].r = r;
595 smctSettings[smctVars.realmName][smctVars.playerName][smctVars.curGroup].g = g;
596 smctSettings[smctVars.realmName][smctVars.playerName][smctVars.curGroup].b = b;
597 ChangeChatColor("TIME_PLAYED", r, g, b)
598 if (not ColorPickerFrame:IsVisible()) then
599 SystemMessageControlToolPredefinedColorsFrame:Hide();
600 SystemMessageControlToolFrame:Show();
601 end
602 end
603  
604  
605 function smctCancelColorPicker(previousValues)
606 if ((previousValues.r) and (smctSettings[smctVars.realmName][smctVars.playerName][smctVars.curGroup])) then
607 smctSettings[smctVars.realmName][smctVars.playerName][smctVars.curGroup].r = previousValues.r;
608 smctSettings[smctVars.realmName][smctVars.playerName][smctVars.curGroup].g = previousValues.g;
609 smctSettings[smctVars.realmName][smctVars.playerName][smctVars.curGroup].b = previousValues.b;
610 end
611 if (not ColorPickerFrame:IsVisible()) then
612 SystemMessageControlToolPredefinedColorsFrame:Hide();
613 SystemMessageControlToolFrame:Show();
614 end
615 end
616  
617  
618 function smctSetGroupWindow(e)
619 local group = e:GetParent().group;
620 local ID = e:GetParent():GetID();
621 local f = SystemMessageControlToolChatWindowsFrame;
622 local c = 0;
623 local str, btn, check, subF;
624 local fText = getglobal(f:GetName().."HeaderText");
625 local maxWidth = 120;
626 getglobal(f:GetName().."HeaderText"):SetText(smctVars.text.windowSelectHeader);
627 f:SetFrameLevel(e:GetFrameLevel()+1);
628 local btnFrameLevel = f:GetFrameLevel()+1;
629  
630 for i=1, 11 do
631 subF = getglobal(f:GetName().."Button"..i);
632 btn = getglobal(subF:GetName().."Button");
633 check = getglobal(subF:GetName().."Check");
634 if (smctVars.chatWindows[i]) then
635 str = smctVars.chatWindows[i].name;
636 if (smctVars.chatWindows[i].index > 0) then
637 if (smctVars.chatWindows[i].index == smctVars.indexes.floating) then
638 str = smctVars.text.floating;
639 else
640 str = "["..smctVars.chatWindows[i].index.."] "..str;
641 end
642 end
643 if (i == 1) then
644 btn:SetTextColor(0.6, 0.6, 0.6);
645 end
646 if (smctIsWindowSelected(group, smctVars.chatWindows[i].index)) then
647 check:Show();
648 else
649 check:Hide();
650 end
651 btn.ID = ID;
652 btn.name = smctVars.chatWindows[i].name;
653 btn.group = group;
654 btn:SetID(smctVars.chatWindows[i].index);
655 btn:SetText(str);
656 btn:SetScript("OnClick", function() smctSetChatWindow(this) end);
657 btn:SetFrameLevel((btnFrameLevel+1));
658 subF:SetFrameLevel(btnFrameLevel);
659 subF:Show();
660 c = c + 1;
661 else
662 subF:Hide();
663 end
664 end
665  
666 f:ClearAllPoints();
667 f:SetPoint("TOPLEFT", "SystemMessageControlToolFrameGroup"..ID.."SetWindow", "TOPRIGHT", 0, 0);
668 f:SetHeight((14*c)+32);
669 f:Show();
670 end
671  
672  
673 function smctSetChatWindow(f)
674 local action = f:GetID();
675 local tmpWindowID, tmpWindowName;
676 local multiselect = false;
677 local foundAction = false;
678  
679 if (IsShiftKeyDown()) then
680 multiselect = true;
681 end
682 if ((action == smctVars.indexes.close) or (not multiselect)) then
683 SystemMessageControlToolChatWindowsFrame:Hide();
684 if (action == smctVars.indexes.close) then
685 return;
686 end
687 end
688 -- Create new group for storing settings.
689 if (not smctSettings[smctVars.realmName][smctVars.playerName][f.group]) then
690 smctSettings[smctVars.realmName][smctVars.playerName][f.group] = {};
691 end
692 -- Code for handling compatability with old versions.
693 if (strupper(type(smctSettings[smctVars.realmName][smctVars.playerName][f.group].windowID)) ~= "TABLE") then
694 if (smctSettings[smctVars.realmName][smctVars.playerName][f.group].windowID) then
695 tmpWindowID = smctSettings[smctVars.realmName][smctVars.playerName][f.group].windowID;
696 tmpWindowName = smctSettings[smctVars.realmName][smctVars.playerName][f.group].windowName;
697 smctAddWindow(tmpWindowID, tmpWindowName, f.group);
698 else
699 smctAddWindow(0, smctVars.text.passthrough, f.group);
700 end
701 end
702  
703 if (not multiselect) then
704 smctUncheckWindows(f);
705 smctRemoveWindow(0, f.group);
706 smctAddWindow(action, f.name, f.group);
707 else
708 if (action > smctVars.indexes.passthrough) then
709 local didHide = false;
710 for i, v in smctSettings[smctVars.realmName][smctVars.playerName][f.group].windowID do
711 if (v <= smctVars.indexes.passthrough) then
712 if (not didHide) then
713 smctUncheckWindows(f);
714 didHide = true;
715 end
716 smctRemoveWindow(i, f.group);
717 end
718 if (v == action) then
719 if (table.getn(smctSettings[smctVars.realmName][smctVars.playerName][f.group].windowID) > 1) then
720 smctRemoveWindow(i, f.group);
721 foundAction = true;
722 else
723 return;
724 end
725 end
726 end
727 if (not foundAction) then
728 smctAddWindow(action, f.name, f.group);
729 getglobal(f:GetParent():GetName().."Check"):Show();
730 else
731 getglobal(f:GetParent():GetName().."Check"):Hide();
732 end
733 else
734 smctUncheckWindows(f);
735 smctRemoveWindow(0, f.group);
736 smctAddWindow(action, f.name, f.group);
737 getglobal(f:GetParent():GetName().."Check"):Show();
738 end
739 end
740 local str = f.name;
741 if (table.getn(smctSettings[smctVars.realmName][smctVars.playerName][f.group].windowID) > 1) then
742 str = smctVars.text.multipleWindows;
743 elseif (action > smctVars.indexes.passthrough) then
744 if (not foundAction) then
745 if (action == smctVars.indexes.floating) then
746 str = smctVars.text.floating;
747 else
748 str = "["..action.."] "..str;
749 end
750 else
751 local tmpID, tmpName = smctGetActiveWindow(f.group);
752 if (tmpID == smctVars.indexes.floating) then
753 str = smctVars.text.floating;
754 else
755 str = "["..tmpID.."] "..tmpName;
756 end
757 end
758 end
759 getglobal("SystemMessageControlToolFrameGroup"..f.ID.."SetWindow"):SetText(str);
760 end
761  
762  
763 function smctAddWindow(action, name, group)
764 if (strupper(type(smctSettings[smctVars.realmName][smctVars.playerName][group].windowID)) ~= "TABLE") then
765 smctSettings[smctVars.realmName][smctVars.playerName][group].windowID = {};
766 smctSettings[smctVars.realmName][smctVars.playerName][group].windowName = {};
767 end
768 table.insert(smctSettings[smctVars.realmName][smctVars.playerName][group].windowID, action);
769 table.insert(smctSettings[smctVars.realmName][smctVars.playerName][group].windowName, name);
770 end
771  
772  
773 function smctRemoveWindow(index, group)
774 if (not smctSettings[smctVars.realmName][smctVars.playerName][group].windowID) then
775 return;
776 end
777 if (index == 0) then
778 smctSettings[smctVars.realmName][smctVars.playerName][group].windowID = {};
779 smctSettings[smctVars.realmName][smctVars.playerName][group].windowName = {};
780 else
781 table.remove(smctSettings[smctVars.realmName][smctVars.playerName][group].windowID, index);
782 table.remove(smctSettings[smctVars.realmName][smctVars.playerName][group].windowName, index);
783 end
784 end
785  
786  
787 function smctUncheckWindows(f)
788 local frameName = f:GetParent():GetParent():GetName();
789 for i=1, 11 do
790 getglobal(frameName.."Button"..i.."Check"):Hide();
791 end
792 end
793  
794  
795 function smctGetActiveWindow(group)
796 local ID, name = "", "";
797 for i, v in smctSettings[smctVars.realmName][smctVars.playerName][group].windowID do
798 ID = v;
799 end
800 for i, v in smctSettings[smctVars.realmName][smctVars.playerName][group].windowName do
801 name = v;
802 end
803 return ID, name;
804 end
805  
806  
807 function smctIsWindowSelected(group, index)
808 local settings = smctSettings[smctVars.realmName][smctVars.playerName][group];
809 if ((settings) and (settings.windowID)) then
810 if (strupper(type(settings.windowID)) == "TABLE") then
811 for i, v in settings.windowID do
812 if (v == index) then
813 return true;
814 end
815 end
816 elseif (settings.windowID == index) then
817 return true;
818 end
819 else
820 if (index == smctVars.indexes.passthrough) then
821 return true;
822 end
823 end
824 return false;
825 end
826  
827  
828 function smctTimePlayed(group, arg1, arg2)
829 local d, h, m, s, didDeliver;
830 d, h, m, s = ChatFrame_TimeBreakDown(arg1);
831 local str1 = format(TEXT(TIME_PLAYED_TOTAL), format(TEXT(TIME_DAYHOURMINUTESECOND), d, h, m, s));
832 d, h, m, s = ChatFrame_TimeBreakDown(arg2);
833 local str2 = format(TEXT(TIME_PLAYED_LEVEL), format(TEXT(TIME_DAYHOURMINUTESECOND), d, h, m, s));
834 smctSetOutput(group, str1);
835 return smctSetOutput(group, str2);
836 end
837  
838  
839 function smctPlayerLevelUp(group, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
840 local str, didDeliver;
841 didDeliver = smctSetOutput(group, format(TEXT(LEVEL_UP), arg1));
842  
843 if (arg3 > 0) then
844 str = format(TEXT(LEVEL_UP_HEALTH_MANA), arg2, arg3);
845 else
846 str = format(TEXT(LEVEL_UP_HEALTH), arg2);
847 end
848 didDeliver = smctSetOutput(group, str);
849  
850 if (arg4 > 0) then
851 didDeliver = smctSetOutput(group, format(GetText("LEVEL_UP_CHAR_POINTS", nil, arg4), arg4));
852 end
853  
854 if (arg5 > 0) then
855 didDeliver = smctSetOutput(group, format(TEXT(LEVEL_UP_STAT), TEXT(SPELL_STAT0_NAME), arg5));
856 end
857 if (arg6 > 0) then
858 didDeliver = smctSetOutput(group, format(TEXT(LEVEL_UP_STAT), TEXT(SPELL_STAT1_NAME), arg6));
859 end
860 if (arg7 > 0) then
861 didDeliver = smctSetOutput(group, format(TEXT(LEVEL_UP_STAT), TEXT(SPELL_STAT2_NAME), arg7));
862 end
863 if (arg8 > 0) then
864 didDeliver = smctSetOutput(group, format(TEXT(LEVEL_UP_STAT), TEXT(SPELL_STAT3_NAME), arg8));
865 end
866 if (arg9 > 0) then
867 didDeliver = smctSetOutput(group, format(TEXT(LEVEL_UP_STAT), TEXT(SPELL_STAT4_NAME), arg9));
868 end
869 return didDeliver;
870 end
871  
872  
873 function smctCharacterPointsChanged(group, arg1, arg2)
874 local didDeliver = false;
875 if (arg2 > 0) then
876 local cp1, cp2 = UnitCharacterPoints("player");
877 if (cp2) then
878 didDeliver = smctSetOutput(group, format(GetText("LEVEL_UP_SKILL_POINTS", nil, cp2), cp2));
879 end
880 end
881 return didDeliver;
882 end
883  
884  
885 function smctIsChannelIgnored(channelName)
886 local isIgnored = false;
887 for i, v in smctVars.channelsIgnore do
888 if (v == "variable") then
889 if (getglobal(i) == channelName) then
890 isIgnored = true;
891 break;
892 end
893 elseif (v == "string") then
894 if (i == channelName) then
895 isIgnored = true;
896 break;
897 end
898 end
899 end
900 return isIgnored;
901 end
902  
903  
904 function smctChannelNotice(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
905 if ((not arg1) or (not arg4)) then
906 return false;
907 end
908 local displayMessage = false;
909 if (arg1 == "YOU_JOINED") then
910 if (not smctIsChannelIgnored(arg9)) then
911 local channelActive = false;
912 for i, v in smctVars.channels do
913 if (string.find(arg4, v)) then
914 channelActive = true;
915 end
916 end
917 if (not channelActive) then
918 table.insert(smctVars.channels, (table.getn(smctVars.channels)+1), smctConvStr(arg4));
919 displayMessage = true;
920 end
921 end
922 elseif (arg1 == "YOU_LEFT") then
923 if (not smctIsChannelIgnored(arg9)) then
924 for i, v in smctVars.channels do
925 if (string.find(arg4, v)) then
926 table.remove(smctVars.channels, i);
927 displayMessage = true;
928 break;
929 end
930 end
931 end
932 elseif (arg1 == "SUSPENDED") then
933 if (not smctIsChannelIgnored(arg9)) then
934 for i, v in smctVars.channels do
935 if (string.find(arg4, v)) then
936 table.remove(smctVars.channels, i);
937 displayMessage = true;
938 break;
939 end
940 end
941 end
942 elseif (arg1 == "YOU_CHANGED") then
943 if (not smctIsChannelIgnored(arg9)) then
944 if (not smctVars.changedChannels[arg4] or time()-smctVars.changedChannels[arg4] > 1) then
945 smctVars.changedChannels[arg4] = time();
946 displayMessage = true;
947 end
948 end
949 end
950  
951 if (displayMessage) then
952 local str = string.gsub(getglobal("CHAT_"..arg1.."_NOTICE"), "%%s", arg4);
953 return (str);
954 else
955 return false;
956 end
957 end
958  
959  
960 function smctBGMessageRerouter(group, arg1)
961 return smctSetOutput(group, arg1);
962 end
963  
964  
965 function smctSetPredefinedColor(i)
966 local color = ChatTypeInfo[smctVars.predefinedColors[i].event];
967 if ((color) and (color.r)) then
968 ColorPickerFrame:SetColorRGB(color.r, color.g, color.b);
969 else
970 smctSendChatMessage(smctVars.text.colorGroupError);
971 end
972 end
973  
974  
975 function smctToggleProfileWindow()
976 if (SystemMessageControlToolProfileFrame:IsShown()) then
977 SystemMessageControlToolProfileFrame:Hide();
978 else
979 SystemMessageControlToolProfileFrame:SetHeight(SystemMessageControlToolFrame:GetHeight());
980 SystemMessageControlToolProfileFrame:Show();
981 end
982 end
983  
984  
985 function smctOpenProfiles(f)
986 local ID = f:GetID();
987 local server = f.server;
988 local c = 1;
989 local hasChildren;
990 local btn, name;
991 if (smctVars.profileOpenID) then
992 for i=1, 10 do
993 getglobal("SystemMessageControlToolProfileFrameButton"..smctVars.profileOpenID.."Name"..i):Hide();
994 end
995 getglobal("SystemMessageControlToolProfileFrameButton"..smctVars.profileOpenID):SetHeight(14);
996 getglobal("SystemMessageControlToolProfileFrameButton"..smctVars.profileOpenID.."Server"):UnlockHighlight();
997 if (smctVars.profileOpenID == ID) then
998 smctVars.profileOpenID = nil;
999 return;
1000 end
1001 end
1002 f:LockHighlight();
1003 for i, v in smctSettings[server] do
1004 name = tostring(i);
1005 hasChildren = false;
1006 for n, k in smctSettings[server][name] do
1007 hasChildren = true;
1008 break;
1009 end
1010 if (hasChildren) then
1011 btn = getglobal(f:GetParent():GetName().."Name"..c);
1012 btn.server = server;
1013 btn.name = name;
1014 btn:SetText(name);
1015 btn:SetScript("OnClick", function() smctLoadProfile(this) end);
1016 btn:Show();
1017 c = c + 1;
1018 end
1019 if (c > 10) then
1020 break;
1021 end
1022 end
1023 for i=c, 10 do
1024 getglobal(f:GetParent():GetName().."Name"..i):Hide();
1025 end
1026 f:GetParent():SetHeight(((c-1)*14)+16);
1027 smctVars.profileOpenID = ID;
1028 end
1029  
1030  
1031 function smctLoadProfile(f)
1032 local name, server = f.name, f.server;
1033 -- SystemMessageControlToolFrame:Hide();
1034 -- smctSendChatMessage("Server: "..server.." - Name: "..name);
1035  
1036 smctSettings[smctVars.realmName][smctVars.playerName] = {};
1037  
1038 for i, v in smctSettings[server][name] do
1039 smctSettings[smctVars.realmName][smctVars.playerName][i] = {};
1040 smctSettings[smctVars.realmName][smctVars.playerName][i] = v;
1041 end
1042 smctSendChatMessage("Loaded settings from profile (Server: "..server.." - Name: "..name..").");
1043 SystemMessageControlTool_OnShow();
1044 -- SystemMessageControlToolFrame:Show();
1045 end
1046  
1047  
1048 function SystemMessageControlTool_Profiles_OnShow()
1049 local btn, server;
1050 local c = 1;
1051 local hasChildren;
1052 for i, v in smctSettings do
1053 server = tostring(i);
1054 hasChildren = false;
1055 for n, k in smctSettings[server] do
1056 hasChildren = true;
1057 break;
1058 end
1059 if (hasChildren) then
1060 btn = getglobal("SystemMessageControlToolProfileFrameButton"..c.."Server");
1061 btn:SetID(c);
1062 btn.server = server;
1063 btn:SetText(server);
1064 btn:SetScript("OnClick", function() smctOpenProfiles(this) end);
1065 getglobal("SystemMessageControlToolProfileFrameButton"..c):Show();
1066 end
1067 c = c + 1;
1068 if (c > 15) then
1069 break;
1070 end
1071 end
1072 end
1073  
1074  
1075 function smctFCF_Tab_OnClick(button)
1076 smctVars.FCF_Tab_OnClick(button);
1077 if (button == "RightButton") then
1078 local frame = getglobal("ChatFrame"..this:GetID());
1079 local settings = {};
1080 for i, v in smctVars.coreSystemGroups do
1081 local colorSettings = smctSettings[smctVars.realmName][smctVars.playerName][v];
1082 if ((colorSettings) and (colorSettings.r)) then
1083 ChatTypeInfo[v].r = colorSettings.r;
1084 ChatTypeInfo[v].g = colorSettings.g;
1085 ChatTypeInfo[v].b = colorSettings.b;
1086 else
1087 local s = string.gsub(v, "_MOTD", "");
1088 ChatTypeInfo[v].r = ChatTypeInfo[s].r;
1089 ChatTypeInfo[v].g = ChatTypeInfo[s].g;
1090 ChatTypeInfo[v].b = ChatTypeInfo[s].b;
1091 end
1092 settings[v] = smctSettings[smctVars.realmName][smctVars.playerName][v];
1093 if (not ((settings[v]) and (settings[v].windowID))) then
1094 settings[v] = {};
1095 settings[v].windowID = {};
1096 table.insert(settings[v].windowID, 1);
1097 end
1098 for n, k in settings[v].windowID do
1099 if (k == this:GetID()) then
1100 local skipAdd = false;
1101 local c = 1;
1102 while (frame.messageTypeList[c]) do
1103 if (frame.messageTypeList[c] == v) then
1104 skipAdd = true;
1105 break;
1106 end
1107 c = c + 1;
1108 end
1109 if (not skipAdd) then
1110 ChatFrame_AddMessageGroup(frame, v);
1111 end
1112 end
1113 end
1114 end
1115 end
1116 end
1117  
1118  
1119 function smctFCF_SetChatTypeColor()
1120 smctVars.FCF_SetChatTypeColor();
1121 for i, v in smctVars.coreSystemGroups do
1122 if (UIDROPDOWNMENU_MENU_VALUE == v) then
1123 if (not smctSettings[smctVars.realmName][smctVars.playerName][v]) then
1124 smctSettings[smctVars.realmName][smctVars.playerName][v] = {};
1125 end
1126 local r, g, b = ColorPickerFrame:GetColorRGB();
1127 ChatTypeInfo[v].r = r;
1128 ChatTypeInfo[v].g = g;
1129 ChatTypeInfo[v].b = b;
1130 smctSettings[smctVars.realmName][smctVars.playerName][v].r = r;
1131 smctSettings[smctVars.realmName][smctVars.playerName][v].g = g;
1132 smctSettings[smctVars.realmName][smctVars.playerName][v].b = b;
1133 end
1134 end
1135 end
1136  
1137  
1138 function smctFCF_CancelFontColorSettings(previousValues)
1139 smctVars.FCF_CancelFontColorSettings(previousValues);
1140 if (not previousValues.r) then
1141 return;
1142 end
1143 for i, v in smctVars.coreSystemGroups do
1144 if (UIDROPDOWNMENU_MENU_VALUE == v) then
1145 if (not smctSettings[smctVars.realmName][smctVars.playerName][v]) then
1146 smctSettings[smctVars.realmName][smctVars.playerName][v] = {};
1147 end
1148 local r, g, b = ColorPickerFrame:GetColorRGB();
1149 ChatTypeInfo[v].r = previousValues.r;
1150 ChatTypeInfo[v].g = previousValues.g;
1151 ChatTypeInfo[v].b = previousValues.b;
1152 smctSettings[smctVars.realmName][smctVars.playerName][v].r = previousValues.r;
1153 smctSettings[smctVars.realmName][smctVars.playerName][v].g = previousValues.g;
1154 smctSettings[smctVars.realmName][smctVars.playerName][v].b = previousValues.b;
1155 end
1156 end
1157 end
1158  
1159  
1160 function smctFCFMessageTypeDropDown_OnClick()
1161 smctVars.FCFMessageTypeDropDown_OnClick();
1162 for i, v in smctVars.coreSystemGroups do
1163 if (this.value == v) then
1164 if (not smctSettings[smctVars.realmName][smctVars.playerName][v]) then
1165 smctSettings[smctVars.realmName][smctVars.playerName][v] = {};
1166 end
1167 if (not smctSettings[smctVars.realmName][smctVars.playerName][v].windowID) then
1168 smctSettings[smctVars.realmName][smctVars.playerName][v].windowID = {};
1169 end
1170 if (UIDropDownMenuButton_GetChecked()) then
1171 for n, k in smctSettings[smctVars.realmName][smctVars.playerName][v].windowID do
1172 if (FCF_GetCurrentChatFrame():GetID() == k) then
1173 table.remove(smctSettings[smctVars.realmName][smctVars.playerName][v].windowID, n);
1174 ChatFrame_RemoveMessageGroup(FCF_GetCurrentChatFrame(), v);
1175 break;
1176 end
1177 end
1178 else
1179 table.insert(smctSettings[smctVars.realmName][smctVars.playerName][v].windowID, FCF_GetCurrentChatFrame():GetID());
1180 ChatFrame_AddMessageGroup(FCF_GetCurrentChatFrame(), v);
1181 end
1182 end
1183 end
1184 end
1185  
1186  
1187 function smctResetToDefaults()
1188 end