vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --------------------------------------------------------------------------
2 -- ChatBar.lua
3 --------------------------------------------------------------------------
4 --[[
5 ChatBar
6  
7 Author: AnduinLothar KarlKFI@cosmosui.org
8 Graphics: Vynn
9  
10 -Button Bar for openning chat messages of each type.
11  
12 Change Log:
13 v1.0
14 -Initial Release
15 v1.1
16 -Addon Channels Hidden added GuildMap
17 -Text has been made Localizable
18 -Officer chat shows up if you CanEditOfficerNote()
19 -Buttons now correctly update when raid, party, and guild changes
20 -Hide Text now correctly says Show Text
21 -Fixed button for channel 8 to diplay and tooltip correctly
22 -Added Reset Position Option
23 -Added Options to hide the each button by chat type or channel name (hide from button menu, show from main sub menu)
24 -Added option to use Channel Numbers as text overlay
25 -Added VisibilityOptions, however autohide is a bit finicky atm.
26 v1.2
27 -VisibilityOptions AutoHide is now smarter and shows whenever ChatBar is sliding or being dragged or the cursor is over its menu
28 -Fixed Eclipse onload error
29 -Fixed Whisper abreviation
30 v1.3
31 -Fixed nil SetText errors
32 -Fixed channel 10 nil errors
33 -Added Channel Reorder (from ChannelManager) if you have Sky installed (uses many library functions)
34 v1.4
35 -Fixed a nil loading error
36 v1.5
37 -Fixed saved variables issue with 1.11 not saving nils
38 -Fixed a nill bug with the right-click menu
39 v1.6
40 -Channel Reorder no longer requires Sky
41 -toc to 11200
42  
43 ]]--
44  
45 --------------------------------------------------
46 -- Globals
47 --------------------------------------------------
48  
49 CHAT_BAR_MAX_BUTTONS = 20;
50 CHAT_BAR_UPDATE_DELAY = 30;
51 ChatBar_VerticalDisplay = false;
52 ChatBar_AlternateOrientation = false;
53 ChatBar_TextOnButtonDisplay = false;
54 ChatBar_ButtonFlashing = true;
55 ChatBar_BarBorder = true;
56 ChatBar_ButtonText = true;
57 ChatBar_TextChannelNumbers = false;
58 ChatBar_VerticalDisplay_Sliding = false;
59 ChatBar_AlternateDisplay_Sliding = false;
60 ChatBar_HideSpecialChannels = true;
61 ChatBar_LastTell = nil;
62 ChatBar_StoredStickies = { };
63 ChatBar_HiddenButtons = { };
64  
65 --------------------------------------------------
66 -- Retell Hook
67 --------------------------------------------------
68  
69 local SendChatMessage_orig = SendChatMessage;
70 function ChatBar_SendChatMessage(text, type, language, target)
71 SendChatMessage_orig(text, type, language, target);
72 -- saves target for 'Retell'
73 if ( type == "WHISPER" ) then
74 ChatBar_LastTell = target;
75 end
76 end
77 SendChatMessage = ChatBar_SendChatMessage;
78  
79 --------------------------------------------------
80 -- Button Functions
81 --------------------------------------------------
82  
83 function ChatBar_StandardButtonClick(button)
84 local chatFrame = SELECTED_DOCK_FRAME
85 if ( not chatFrame ) then
86 chatFrame = DEFAULT_CHAT_FRAME;
87 end
88 if (button == "RightButton") then
89 ToggleDropDownMenu(1, this.ChatID, ChatBar_DropDown, this:GetName(), 10, 0, "TOPRIGHT");
90 else
91 local chatType = ChatBar_ChatTypes[this.ChatID].type;
92 chatFrame.editBox:Show();
93 if (chatFrame.editBox.chatType == chatType) then
94 ChatFrame_OpenChat("", chatFrame);
95 else
96 chatFrame.editBox.chatType = chatType;
97 end
98 ChatEdit_UpdateHeader(chatFrame.editBox);
99 end
100 end
101  
102 function ChatBar_WhisperButtonClick(button)
103 local chatFrame = SELECTED_DOCK_FRAME
104 if ( not chatFrame ) then
105 chatFrame = DEFAULT_CHAT_FRAME;
106 end
107 if (button == "RightButton") then
108 ToggleDropDownMenu(1, this.ChatID, ChatBar_DropDown, this:GetName(), 10, 0, "TOPRIGHT");
109 else
110 local chatType = ChatBar_ChatTypes[this.ChatID].type;
111 --ChatFrame_SendTell(name, SELECTED_DOCK_FRAME)
112 if (chatFrame.editBox.chatType == chatType) then
113 ChatFrame_OpenChat("", chatFrame);
114 else
115 ChatFrame_ReplyTell(chatFrame);
116 if (not chatFrame.editBox:IsVisible()) or (chatFrame.editBox.chatType ~= chatType) then
117 ChatFrame_OpenChat("/w ", chatFrame);
118 end
119 end
120 end
121 end
122  
123 function ChatBar_ChannelShortText(index)
124 local channelNum, channelName = GetChannelName(index);
125 if (channelNum ~= 0) then
126 if (ChatBar_TextChannelNumbers) then
127 return channelNum;
128 else
129 return strsub(channelName,1,1);
130 end
131 end
132 end
133  
134 function ChatBar_ChannelText(index)
135 local channelNum, channelName = GetChannelName(index);
136 if (channelNum ~= 0) then
137 return channelNum..") "..channelName;
138 end
139 return "";
140 end
141  
142 function ChatBar_ChannelClick(button, index)
143 if (not index) then
144 index = 1;
145 end
146 local chatFrame = SELECTED_DOCK_FRAME
147 if ( not chatFrame ) then
148 chatFrame = DEFAULT_CHAT_FRAME;
149 end
150 if (button == "RightButton") then
151 ToggleDropDownMenu(1, this.ChatID, ChatBar_DropDown, this:GetName(), 10, 0, "TOPRIGHT");
152 else
153 --local chatType = ChatBar_ChatTypes[this.ChatID].type;
154 chatFrame.editBox:Show();
155 if (chatFrame.editBox.chatType == "CHANNEL") and (chatFrame.editBox.channelTarget == index) then
156 ChatFrame_OpenChat("", chatFrame);
157 else
158 chatFrame.editBox.chatType = "CHANNEL";
159 chatFrame.editBox.channelTarget = index
160 ChatEdit_UpdateHeader(chatFrame.editBox);
161 end
162 end
163  
164 end
165  
166 function ChatBar_ChannelShow(index)
167 local channelNum, channelName = GetChannelName(index);
168 if (channelNum ~= 0) then
169 if (ChatBar_HideSpecialChannels) then
170 --Special Hidden Whisper Ignores
171 if ( IsAddOnLoaded("Sky") ) then
172 if (string.len(channelName) >= 3) and (string.sub(channelName,1,3) == "Sky") then
173 --Hide Sky channels
174 return;
175 end
176 for i, bogusName in BOGUS_CHANNELS do
177 if (channelName == bogusName) then
178 --Hide reorder channels
179 return;
180 end
181 end
182 elseif ( IsAddOnLoaded("CallToArms") ) and (channelName == CTA_DEFAULT_RAID_CHANNEL) then
183 --Hide CallToArms channel
184 return;
185 elseif ( IsAddOnLoaded("CT_RaidAssist") ) and (channelName == CT_RA_Channel) then
186 --Hide CT_RaidAssist channel
187 return;
188 elseif ( IsAddOnLoaded("GuildMap") ) and (GuildMapConfig) and (channelName == GuildMapConfig.channel) then
189 --Hide GuildMap channel
190 return;
191 elseif ( channelName == "GlobalComm" ) then
192 --Hide standard GlobalComm channel (Telepathy, AceComm)
193 return;
194 end
195 end
196 return (not ChatBar_HiddenButtons[ChatBar_GetFirstWord(channelName)]);
197 end
198 end
199  
200 --------------------------------------------------
201 -- Button Info
202 --------------------------------------------------
203  
204 ChatBar_ChatTypes = {
205 {
206 type = "SAY",
207 shortText = function() return CHATBAR_SAY_ABRV; end,
208 text = function() return CHAT_MSG_SAY; end,
209 click = ChatBar_StandardButtonClick,
210 show = function()
211 return (not ChatBar_HiddenButtons[CHAT_MSG_SAY]);
212 end
213 },
214 {
215 type = "YELL",
216 shortText = function() return CHATBAR_YELL_ABRV; end,
217 text = function() return CHAT_MSG_YELL; end,
218 click = ChatBar_StandardButtonClick,
219 show = function()
220 return (not ChatBar_HiddenButtons[CHAT_MSG_YELL]);
221 end
222 },
223 {
224 type = "PARTY",
225 shortText = function() return CHATBAR_PARTY_ABRV; end,
226 text = function() return CHAT_MSG_PARTY; end,
227 click = ChatBar_StandardButtonClick,
228 show = function()
229 return UnitExists("party1") and (not ChatBar_HiddenButtons[CHAT_MSG_PARTY]);
230 end
231 },
232 {
233 type = "RAID",
234 shortText = function() return CHATBAR_RAID_ABRV; end,
235 text = function() return CHAT_MSG_RAID; end,
236 click = ChatBar_StandardButtonClick,
237 show = function()
238 return (GetNumRaidMembers() > 0) and (not ChatBar_HiddenButtons[CHAT_MSG_RAID]);
239 end
240 },
241 {
242 type = "GUILD",
243 shortText = function() return CHATBAR_GUILD_ABRV; end,
244 text = function() return CHAT_MSG_GUILD; end,
245 click = ChatBar_StandardButtonClick,
246 show = function()
247 return IsInGuild() and (not ChatBar_HiddenButtons[CHAT_MSG_GUILD]);
248 end
249 },
250 {
251 type = "OFFICER",
252 shortText = function() return CHATBAR_OFFICER_ABRV; end,
253 text = function() return CHAT_MSG_OFFICER; end,
254 click = ChatBar_StandardButtonClick,
255 show = function()
256 return CanEditOfficerNote() and (not ChatBar_HiddenButtons[CHAT_MSG_OFFICER]);
257 end
258 },
259 {
260 type = "WHISPER",
261 shortText = function() return CHATBAR_WHISPER_ABRV; end,
262 text = function() return CHAT_MSG_WHISPER_INFORM; end,
263 click = ChatBar_WhisperButtonClick,
264 show = function()
265 return (not ChatBar_HiddenButtons[CHAT_MSG_WHISPER_INFORM]);
266 end
267 },
268 {
269 type = "EMOTE",
270 shortText = function() return CHATBAR_EMOTE_ABRV; end,
271 text = function() return CHAT_MSG_EMOTE; end,
272 click = ChatBar_StandardButtonClick,
273 show = function()
274 return (not ChatBar_HiddenButtons[CHAT_MSG_EMOTE]);
275 end
276 },
277 {
278 type = "CHANNEL1",
279 shortText = function() return ChatBar_ChannelShortText(1); end,
280 text = function() return ChatBar_ChannelText(1); end,
281 click = function(button) ChatBar_ChannelClick(button, 1); end,
282 show = function() return ChatBar_ChannelShow(1); end
283 },
284 {
285 type = "CHANNEL2",
286 shortText = function() return ChatBar_ChannelShortText(2); end,
287 text = function() return ChatBar_ChannelText(2); end,
288 click = function(button) ChatBar_ChannelClick(button, 2); end,
289 show = function() return ChatBar_ChannelShow(2); end
290 },
291 {
292 type = "CHANNEL3",
293 shortText = function() return ChatBar_ChannelShortText(3); end,
294 text = function() return ChatBar_ChannelText(3); end,
295 click = function(button) ChatBar_ChannelClick(button, 3); end,
296 show = function() return ChatBar_ChannelShow(3); end
297 },
298 {
299 type = "CHANNEL4",
300 shortText = function() return ChatBar_ChannelShortText(4); end,
301 text = function() return ChatBar_ChannelText(4); end,
302 click = function(button) ChatBar_ChannelClick(button, 4); end,
303 show = function() return ChatBar_ChannelShow(4); end
304 },
305 {
306 type = "CHANNEL5",
307 shortText = function() return ChatBar_ChannelShortText(5); end,
308 text = function() return ChatBar_ChannelText(5); end,
309 click = function(button) ChatBar_ChannelClick(button, 5); end,
310 show = function() return ChatBar_ChannelShow(5); end
311 },
312 {
313 type = "CHANNEL6",
314 shortText = function() return ChatBar_ChannelShortText(6); end,
315 text = function() return ChatBar_ChannelText(6); end,
316 click = function(button) ChatBar_ChannelClick(button, 6); end,
317 show = function() return ChatBar_ChannelShow(6); end
318 },
319 {
320 type = "CHANNEL7",
321 shortText = function() return ChatBar_ChannelShortText(7); end,
322 text = function() return ChatBar_ChannelText(7); end,
323 click = function(button) ChatBar_ChannelClick(button, 7); end,
324 show = function() return ChatBar_ChannelShow(7); end
325 },
326 {
327 type = "CHANNEL8",
328 shortText = function() return ChatBar_ChannelShortText(8); end,
329 text = function() return ChatBar_ChannelText(8); end,
330 click = function(button) ChatBar_ChannelClick(button, 8); end,
331 show = function() return ChatBar_ChannelShow(8); end
332 },
333 {
334 type = "CHANNEL9",
335 shortText = function() return ChatBar_ChannelShortText(9); end,
336 text = function() return ChatBar_ChannelText(9); end,
337 click = function(button) ChatBar_ChannelClick(button, 9); end,
338 show = function() return ChatBar_ChannelShow(9); end
339 },
340 {
341 type = "CHANNEL10",
342 shortText = function() return ChatBar_ChannelShortText(10); end,
343 text = function() return ChatBar_ChannelText(10); end,
344 click = function(button) ChatBar_ChannelClick(button, 10); end,
345 show = function() return ChatBar_ChannelShow(10); end
346 }
347  
348 };
349  
350 ChatBar_BarTypes = {};
351  
352 --------------------------------------------------
353 -- Frame Scripts
354 --------------------------------------------------
355  
356 function ChatBar_OnLoad()
357 this:RegisterEvent("UPDATE_CHAT_COLOR");
358 this:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE");
359 this:RegisterEvent("PARTY_MEMBERS_CHANGED");
360 this:RegisterEvent("RAID_ROSTER_UPDATE");
361 this:RegisterEvent("PLAYER_GUILD_UPDATE");
362 this:RegisterEvent("VARIABLES_LOADED");
363 this:RegisterForDrag("LeftButton");
364 this.velocity = 0;
365 if (Eclipse) then
366 --Register with VisibilityOptions
367 Eclipse.registerForVisibility( {
368 name = "ChatBarFrame"; --The name of the config, in this case also the name of the frame
369 uiname = "ChatBar"; --This is the base name of this reg to display in the description and ui
370 slashcom = { "chatbar", "cb" }; --These are the slash commands
371 reqs = { var=ChatBar_ShowIf, val=true, show=true };
372 } );
373 end
374 end
375  
376 function ChatBar_ShowIf()
377 return ChatBarFrame.isSliding or ChatBarFrame.isMoving or (type(ChatBarFrame.count)=="number") or ((UIDROPDOWNMENU_OPEN_MENU=="ChatBar_DropDown" and (MouseIsOver(DropDownList1) or (UIDROPDOWNMENU_MENU_LEVEL==2 and MouseIsOver(DropDownList2))))==1);
378 end
379  
380 function ChatBar_OnEvent(event)
381 if ( event == "UPDATE_CHAT_COLOR" ) then
382 ChatBarFrame.count = 0;
383 elseif ( event == "CHAT_MSG_CHANNEL_NOTICE" ) then
384 ChatBarFrame.count = 0;
385 elseif ( event == "PARTY_MEMBERS_CHANGED" ) then
386 ChatBarFrame.count = 0;
387 elseif ( event == "RAID_ROSTER_UPDATE" ) then
388 ChatBarFrame.count = 0;
389 elseif ( event == "PLAYER_GUILD_UPDATE" ) then
390 ChatBarFrame.count = 0;
391 elseif ( event == "CHAT_MSG_CHANNEL" ) and (type(arg8) == "number") then
392 if (ChatBar_BarTypes["CHANNEL"..arg8]) then
393 UIFrameFlash(getglobal("ChatBarFrameButton"..ChatBar_BarTypes["CHANNEL"..arg8].."Flash"), .5, .5, 1.1);
394 end
395 elseif (event == "CHAT_MSG_SAY") or (event == "CHAT_MSG_YELL") or (event == "CHAT_MSG_PARTY") or (event == "CHAT_MSG_RAID") or
396 (event == "CHAT_MSG_GUILD") or (event == "CHAT_MSG_OFFICER") or (event == "CHAT_MSG_WHISPER") or (event == "CHAT_MSG_EMOTE") then
397 --Sea.io.printComma(arg1,arg2,arg3);
398 if (ChatBar_BarTypes[strsub(event,10)]) then
399 UIFrameFlash(getglobal("ChatBarFrameButton"..ChatBar_BarTypes[strsub(event,10)].."Flash"), .5, .5, 1.1);
400 end
401 elseif ( event == "VARIABLES_LOADED" ) then
402 ChatBar_UpdateButtonOrientation();
403 ChatBar_UpdateButtonFlashing();
404 ChatBar_UpdateBarBorder();
405 ChatBar_UpdateButtonText();
406  
407 --Update live Stickies
408 for chatType, enabled in ChatBar_StoredStickies do
409 if (enabled) then
410 ChatTypeInfo[chatType].sticky = enabled;
411 end
412 end
413 end
414 end
415  
416 --ConstantInitialVelocity = 10;
417 ConstantVelocityModifier = 1.25;
418 ConstantJerk = 3*ConstantVelocityModifier;
419 ConstantSnapLimit = 2;
420  
421 function ChatBar_OnUpdate(elapsed)
422  
423 if (this.slidingEnabled) and (this.isSliding) and (this.velocity) and (this.endsize) then
424 local currSize = ChatBar_GetSize();
425 if (math.abs(currSize - this.endsize) < ConstantSnapLimit) then
426 ChatBar_SetSize(this.endsize);
427 ChatBarFrame.isSliding = nil;
428 this.velocity = 0;
429 if (ChatBar_VerticalDisplay_Sliding or ChatBar_AlternateDisplay_Sliding) and (this:GetWidth() <= 17) and (this:GetHeight() <= 17) then
430 if (ChatBar_VerticalDisplay_Sliding) then
431 ChatBar_VerticalDisplay_Sliding = nil;
432 ChatBar_Toggle_VerticalButtonOrientation();
433 elseif (ChatBar_AlternateDisplay_Sliding) then
434 ChatBar_AlternateDisplay_Sliding = nil;
435 ChatBar_Toggle_AlternateButtonOrientation();
436 end
437 ChatBar_UpdateOrientationPoint();
438 else
439 ChatBar_UpdateOrientationPoint(true);
440 end
441 else
442 --[[
443 local desiredVelocity = ConstantVelocityModifier * (this.endsize - currSize);
444 this.velocity = (1 - ConstantJerk) * this.velocity + ConstantJerk * desiredVelocity;
445 ChatBar_SetSize(currSize + this.velocity * elapsed);
446 ]]--
447 --[[
448 local w = 1 - math.exp(-ConstantJerk* elapsed);
449 this.velocity = (1-w)*this.velocity + w*ConstantVelocityModifier*(this.endsize - currSize);
450 ChatBar_SetSize(currSize + this.velocity * elapsed);
451 ]]--
452 --[[ incomplete
453 local totalDistance = this.endsize - this.startsize;
454 local distanceFromStart = this.startsize - currSize;
455 local accel = math.cos(distanceFromStart/totalDistance*math.pi) * ConstantJerk;
456 ChatBar_SetSize(currSize + accel * elapsed * elapsed);
457 ]]--
458 local desiredVelocity = ConstantVelocityModifier * (this.endsize - currSize);
459 local acceleration = ConstantJerk * (desiredVelocity - this.velocity);
460 this.velocity = this.velocity + acceleration * elapsed;
461 ChatBar_SetSize(currSize + this.velocity * elapsed);
462 end
463 local frame, init, final, step;
464 for i=1, CHAT_BAR_MAX_BUTTONS do
465 frame = getglobal("ChatBarFrameButton".. i);
466 if (currSize >= i*16+18) then
467 frame:Show();
468 else
469 frame:Hide();
470 end
471 end
472 elseif (this.count) then
473 if (this.count > CHAT_BAR_UPDATE_DELAY) then
474 this.count = nil;
475 ChatBarFrame.slidingEnabled = true;
476 ChatBar_UpdateButtons();
477 else
478 this.count = this.count+1;
479 end
480 end
481  
482 end
483  
484 function ChatBar_GetSize()
485 if (ChatBar_VerticalDisplay) then
486 return ChatBarFrame:GetHeight();
487 else
488 return ChatBarFrame:GetWidth();
489 end
490 end
491  
492 function ChatBar_SetSize(size)
493 if (ChatBar_VerticalDisplay) then
494 ChatBarFrame:SetHeight(size);
495 else
496 ChatBarFrame:SetWidth(size);
497 end
498 end
499  
500 function ChatBar_Button_OnLoad()
501 this.Text = getglobal("ChatBarFrameButton"..this:GetID().."Text");
502 this.ChatID = this:GetID();
503  
504 getglobal(this:GetName().."Highlight"):SetAlpha(.75);
505 getglobal(this:GetName().."UpTex_Spec"):SetAlpha(.75);
506 getglobal(this:GetName().."UpTex_Shad"):SetAlpha(.75);
507 --getglobal(this:GetName().."DownTex_Spec"):SetAlpha(1);
508 getglobal(this:GetName().."DownTex_Shad"):SetAlpha(1);
509  
510 this:SetFrameLevel(this:GetFrameLevel()+1);
511 this:RegisterForClicks("LeftButtonDown", "RightButtonDown");
512 end
513  
514 function ChatBar_Button_OnClick()
515 ChatBar_ChatTypes[this.ChatID].click(arg1);
516 end
517  
518 function ChatBar_Button_OnEnter()
519 --local id = this:GetID();
520 if (this.ChatID) then
521 ChatBarFrameTooltip:SetOwner(this, "ANCHOR_TOPLEFT");
522 ChatBarFrameTooltip:SetText(ChatBar_ChatTypes[this.ChatID].text());
523 end
524 end
525  
526 function ChatBar_Button_OnLeave()
527 if (ChatBarFrameTooltip:IsOwned(this)) then
528 ChatBarFrameTooltip:Hide();
529 end
530 end
531  
532 function ChatBar_OnMouseDown(button)
533 if (button == "RightButton") then
534 ToggleDropDownMenu(1, "ChatBarMenu", ChatBar_DropDown, "cursor");
535 else
536 local x, y = GetCursorPosition();
537 this.xOffset = x - this:GetLeft();
538 this.yOffset = y - this:GetBottom();
539 end
540 end
541  
542 function ChatBar_OnDragStart()
543 if (not this.isSliding) then
544 local x, y = GetCursorPosition();
545 this:ClearAllPoints();
546 this:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", x-this.xOffset, y-this.yOffset);
547 this:StartMoving();
548 this.isMoving = true;
549 end
550 end
551  
552 function ChatBar_OnDragStop()
553 this:StopMovingOrSizing();
554 this.isMoving = false;
555 ChatBar_UpdateOrientationPoint(true);
556 end
557  
558 --------------------------------------------------
559 -- DropDown Menu
560 --------------------------------------------------
561  
562 function ChatBar_DropDownOnLoad()
563 UIDropDownMenu_Initialize(this, ChatBar_LoadDropDownMenu, "MENU");
564 end
565  
566 function ChatBar_LoadDropDownMenu()
567 if (not UIDROPDOWNMENU_MENU_VALUE) then
568 return;
569 end
570  
571 if (UIDROPDOWNMENU_MENU_VALUE == "ChatBarMenu") then
572 ChatBar_CreateFrameMenu();
573 elseif (UIDROPDOWNMENU_MENU_VALUE == "HiddenButtonsMenu") then
574 ChatBar_CreateHiddenButtonsMenu();
575 else
576 ChatBar_CreateButtonMenu();
577 end
578  
579 end
580  
581 function ChatBar_CreateFrameMenu()
582 --Title
583 local info = {};
584 info.text = CHATBAR_MENU_MAIN_TITLE;
585 info.notClickable = 1;
586 info.isTitle = 1;
587 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
588  
589 --Vertical
590 local info = {};
591 info.text = CHATBAR_MENU_MAIN_VERTICAL;
592 info.func = ChatBar_Toggle_VerticalButtonOrientationSlide;
593 if (ChatBar_VerticalDisplay) then
594 info.checked = 1;
595 end
596 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
597  
598 --Alt Button
599 local info = {};
600 info.text = CHATBAR_MENU_MAIN_REVERSE;
601 info.func = ChatBar_Toggle_AlternateButtonOrientationSlide;
602 if (ChatBar_AlternateOrientation) then
603 info.checked = 1;
604 end
605 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
606  
607 --Text On Buttons
608 local info = {};
609 info.text = CHATBAR_MENU_MAIN_TEXTONBUTTONS;
610 info.func = ChatBar_Toggle_TextOrientation;
611 info.keepShownOnClick = 1;
612 if (ChatBar_TextOnButtonDisplay) then
613 info.checked = 1;
614 end
615 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
616  
617 --Show Button Text
618 local info = {};
619 info.text = CHATBAR_MENU_MAIN_SHOWTEXT;
620 info.func = ChatBar_Toggle_ButtonText;
621 info.keepShownOnClick = 1;
622 if (ChatBar_ButtonText) then
623 info.checked = 1;
624 end
625 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
626  
627 --Use Channel ID on Buttons
628 local info = {};
629 info.text = CHATBAR_MENU_MAIN_CHANNELID;
630 info.func = ChatBar_Toggle_TextChannelNumbers;
631 info.keepShownOnClick = 1;
632 if (ChatBar_TextChannelNumbers) then
633 info.checked = 1;
634 end
635 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
636  
637 --Button Flashing
638 local info = {};
639 info.text = CHATBAR_MENU_MAIN_BUTTONFLASHING;
640 info.func = ChatBar_Toggle_ButtonFlashing;
641 info.keepShownOnClick = 1;
642 if (ChatBar_ButtonFlashing) then
643 info.checked = 1;
644 end
645 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
646  
647 --Bar Border
648 local info = {};
649 info.text = CHATBAR_MENU_MAIN_BARBORDER;
650 info.func = ChatBar_Toggle_BarBorder;
651 info.keepShownOnClick = 1;
652 if (ChatBar_BarBorder) then
653 info.checked = 1;
654 end
655 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
656  
657 --Hide Special
658 local info = {};
659 info.text = CHATBAR_MENU_MAIN_ADDONCHANNELS;
660 info.func = ChatBar_Toggle_HideSpecialChannels;
661 if (ChatBar_HideSpecialChannels) then
662 info.checked = 1;
663 end
664 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
665  
666 if (ChatBar_GetTableSize(ChatBar_HiddenButtons) > 0) then
667 --Show Hidden Buttons
668 local info = {};
669 info.text = CHATBAR_MENU_MAIN_HIDDENBUTTONS;
670 info.hasArrow = 1;
671 info.func = nil;
672 info.value = "HiddenButtonsMenu";
673 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
674 end
675  
676 --Reset Position
677 local info = {};
678 info.text = CHATBAR_MENU_MAIN_RESET;
679 info.func = ChatBar_Reset;
680 if (not ChatBarFrame:IsUserPlaced()) then
681 info.checked = 1;
682 end
683 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
684  
685 if (ChatBar_ReorderChannels) then
686 --Reorder Channels
687 local info = {};
688 info.text = CHATBAR_MENU_MAIN_REORDER;
689 info.func = ChatBar_ReorderChannels;
690 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
691 end
692 end
693  
694 function ChatBar_CreateHiddenButtonsMenu()
695 for k,v in ChatBar_HiddenButtons do
696 --Show Button
697 local info = {};
698 info.text = format(CHATBAR_MENU_SHOW_BUTTON, k);
699 local ctype = k;
700 info.func = function() ChatBar_HiddenButtons[ctype]=nil ChatBarFrame.count = 0; end;
701 info.notCheckable = 1;
702 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
703 end
704 end
705  
706 function ChatBar_CreateButtonMenu()
707 local buttonHeader = ChatBar_ChatTypes[UIDROPDOWNMENU_MENU_VALUE].type;
708  
709 --Title
710 local info = {};
711 info.text = ChatBar_ChatTypes[UIDROPDOWNMENU_MENU_VALUE].text();
712 info.notClickable = 1;
713 info.isTitle = 1;
714 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
715  
716 local chatType, channelIndex = string.gfind(buttonHeader, "([^%d]*)([%d]+)$")();
717 if (channelIndex) then
718 local channelNum, channelName = GetChannelName(tonumber(channelIndex));
719 --Leave
720 local info = {};
721 info.text = CHATBAR_MENU_CHANNEL_LEAVE;
722 info.func = function() LeaveChannelByName(channelNum) end;
723 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
724  
725 --Channel User List
726 local info = {};
727 info.text = CHATBAR_MENU_CHANNEL_LIST;
728 info.func = function() ListChannelByName(channelNum) end;
729 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
730  
731 --Hide Button
732 local channelShortName = ChatBar_GetFirstWord(channelName);
733 local info = {};
734 info.text = format(CHATBAR_MENU_HIDE_BUTTON, channelShortName);
735 info.func = function() ChatBar_HiddenButtons[channelShortName]=true; ChatBarFrame.count = 0; end;
736 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
737 else
738 --Hide Button
739 local info = {};
740 local localizedChatType = ChatBar_ChatTypes[UIDROPDOWNMENU_MENU_VALUE].text()
741 info.text = format(CHATBAR_MENU_HIDE_BUTTON, localizedChatType);
742 info.func = function() ChatBar_HiddenButtons[localizedChatType]=true; ChatBarFrame.count = 0; end;
743 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
744 end
745  
746 if (buttonHeader == "WHISPER") then
747 local chatFrame = SELECTED_DOCK_FRAME
748 if ( not chatFrame ) then
749 chatFrame = DEFAULT_CHAT_FRAME;
750 end
751  
752 --Reply
753 local info = {};
754 info.text = CHATBAR_MENU_WHISPER_REPLY;
755 info.func = function()
756 ChatFrame_ReplyTell(chatFrame)
757 end;
758 if (ChatEdit_GetLastTellTarget(ChatFrameEditBox) == "") then
759 info.disabled = 1;
760 end
761 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
762  
763 --Retell
764 local info = {};
765 info.text = CHATBAR_MENU_WHISPER_RETELL;
766 info.func = function()
767 ChatFrame_SendTell(ChatBar_LastTell, chatFrame)
768 end;
769 if (not ChatBar_LastTell) then
770 info.disabled = 1;
771 end
772 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
773 end
774  
775 --Sticky
776 local info = {};
777 if (chatType) then
778 info.text = CHATBAR_MENU_CHANNEL_STICKY;
779 else
780 info.text = CHATBAR_MENU_STICKY;
781 chatType = buttonHeader;
782 end
783 info.func = function()
784 if (ChatTypeInfo[chatType].sticky == 1) then
785 ChatTypeInfo[chatType].sticky = 0;
786 ChatBar_StoredStickies[chatType] = 0;
787 else
788 ChatTypeInfo[chatType].sticky = 1;
789 ChatBar_StoredStickies[chatType] = 1;
790 end
791 end;
792 if (ChatTypeInfo[chatType].sticky == 1) then
793 info.checked = 1;
794 end
795 if (not ChatTypeInfo[chatType]) then
796 info.disabled = 1;
797 end
798 UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
799  
800 end
801  
802 --------------------------------------------------
803 -- Update Functions
804 --------------------------------------------------
805  
806 function ChatBar_UpdateButtons()
807  
808 ChatBar_BarTypes = {};
809 local i = 1;
810 local buttonIndex = 1;
811 while (ChatBar_ChatTypes[i]) and (buttonIndex <= CHAT_BAR_MAX_BUTTONS) do
812 if (ChatBar_ChatTypes[i].show()) then
813 local info=ChatTypeInfo[ChatBar_ChatTypes[i].type];
814 ChatBar_BarTypes[ChatBar_ChatTypes[i].type] = buttonIndex;
815 getglobal("ChatBarFrameButton".. buttonIndex.."Highlight"):SetVertexColor(info.r, info.g, info.b);
816 getglobal("ChatBarFrameButton".. buttonIndex.."Flash"):SetVertexColor(info.r, info.g, info.b);
817 getglobal("ChatBarFrameButton".. buttonIndex.."Center"):SetVertexColor(info.r, info.g, info.b);
818 getglobal("ChatBarFrameButton".. buttonIndex.."Text"):SetText(ChatBar_ChatTypes[i].shortText());
819 getglobal("ChatBarFrameButton".. buttonIndex).ChatID = i;
820 --getglobal("ChatBarFrameButton".. buttonIndex):Show();
821 buttonIndex = buttonIndex+1;
822 end
823 i = i+1;
824 end
825 local size = (buttonIndex-1)*16+20;
826 if (ChatBar_VerticalDisplay) then
827 ChatBarFrame:SetWidth(16);
828 if (ChatBarFrame:GetTop()) then
829 ChatBar_StartSlidingTo(size);
830 else
831 ChatBarFrame:SetHeight(size);
832 end
833 else
834 ChatBarFrame:SetHeight(16);
835 if (ChatBarFrame:GetRight()) then
836 ChatBar_StartSlidingTo(size);
837 else
838 ChatBarFrame:SetWidth(size);
839 end
840 --/z ChatBarFrame.startpoint = ChatBarFrame:GetRight();ChatBarFrame.endsize = ChatBarFrame:GetLeft() + 260;
841 --/z ChatBarFrame.centerpoint = ChatBarFrame.startpoint + (ChatBarFrame.endsize - ChatBarFrame.startpoint)/2;ChatBarFrame.velocity = 0;ChatBarFrame.isSliding = true;
842 --/z ChatBarFrame.isSliding = nil; ChatBarFrame:SetWidth(180)
843 --/z ChatBar_StartSlidingTo(300)
844 end
845 while (buttonIndex <= CHAT_BAR_MAX_BUTTONS) do
846 --getglobal("ChatBarFrameButton".. buttonIndex):Hide();
847 getglobal("ChatBarFrameButton".. buttonIndex).ChatID = nil;
848 buttonIndex = buttonIndex+1;
849 end
850  
851 end
852  
853 function ChatBar_StartSlidingTo(size)
854 ChatBarFrame.endsize = size;
855 ChatBarFrame.isSliding = true;
856 end
857  
858 function ChatBar_PrintSlideInfo()
859 Sea.io.printComma(ChatBarFrame.isSliding, ChatBarFrame.endsize, ChatBarFrame.velocity);
860 end
861  
862 function ChatBar_UpdateButtonOrientation()
863 local button = ChatBarFrameButton1;
864 button:ClearAllPoints();
865 button.Text:ClearAllPoints();
866 if (ChatBar_VerticalDisplay) then
867 if (ChatBar_AlternateOrientation) then
868 button:SetPoint("TOP", "ChatBarFrame", "TOP", 0, -10);
869 else
870 button:SetPoint("BOTTOM", "ChatBarFrame", "BOTTOM", 0, 10);
871 end
872 if (ChatBar_TextOnButtonDisplay) then
873 button.Text:SetPoint("CENTER", button);
874 else
875 button.Text:SetPoint("RIGHT", button, "LEFT", 0, 0);
876 end
877 else
878 if (ChatBar_AlternateOrientation) then
879 button:SetPoint("RIGHT", "ChatBarFrame", "RIGHT", -10, 0);
880 else
881 button:SetPoint("LEFT", "ChatBarFrame", "LEFT", 10, 0);
882 end
883 if (ChatBar_TextOnButtonDisplay) then
884 button.Text:SetPoint("CENTER", button);
885 else
886 button.Text:SetPoint("BOTTOM", button, "TOP");
887 end
888 end
889 for i=2, CHAT_BAR_MAX_BUTTONS do
890 button = getglobal("ChatBarFrameButton"..i);
891 button:ClearAllPoints();
892 button.Text:ClearAllPoints();
893 if (ChatBar_VerticalDisplay) then
894 if (ChatBar_AlternateOrientation) then
895 button:SetPoint("TOP", "ChatBarFrameButton"..(i-1), "BOTTOM");
896 else
897 button:SetPoint("BOTTOM", "ChatBarFrameButton"..(i-1), "TOP");
898 end
899 if (ChatBar_TextOnButtonDisplay) then
900 button.Text:SetPoint("CENTER", button);
901 else
902 button.Text:SetPoint("RIGHT", button, "LEFT");
903 end
904 else
905 if (ChatBar_AlternateOrientation) then
906 button:SetPoint("RIGHT", "ChatBarFrameButton"..(i-1), "LEFT");
907 else
908 button:SetPoint("LEFT", "ChatBarFrameButton"..(i-1), "RIGHT");
909 end
910 if (ChatBar_TextOnButtonDisplay) then
911 button.Text:SetPoint("CENTER", button);
912 else
913 button.Text:SetPoint("BOTTOM", button, "TOP");
914 end
915 end
916 end
917 end
918  
919 function ChatBar_UpdateButtonFlashing()
920 local frame = ChatBarFrame;
921 if (ChatBar_ButtonFlashing) then
922 frame:RegisterEvent("CHAT_MSG_SAY");
923 frame:RegisterEvent("CHAT_MSG_YELL");
924 frame:RegisterEvent("CHAT_MSG_PARTY");
925 frame:RegisterEvent("CHAT_MSG_RAID");
926 frame:RegisterEvent("CHAT_MSG_GUILD");
927 frame:RegisterEvent("CHAT_MSG_OFFICER");
928 frame:RegisterEvent("CHAT_MSG_WHISPER");
929 frame:RegisterEvent("CHAT_MSG_EMOTE");
930 frame:RegisterEvent("CHAT_MSG_CHANNEL");
931 else
932 frame:UnregisterEvent("CHAT_MSG_SAY");
933 frame:UnregisterEvent("CHAT_MSG_YELL");
934 frame:UnregisterEvent("CHAT_MSG_PARTY");
935 frame:UnregisterEvent("CHAT_MSG_RAID");
936 frame:UnregisterEvent("CHAT_MSG_GUILD");
937 frame:UnregisterEvent("CHAT_MSG_OFFICER");
938 frame:UnregisterEvent("CHAT_MSG_WHISPER");
939 frame:UnregisterEvent("CHAT_MSG_EMOTE");
940 frame:UnregisterEvent("CHAT_MSG_CHANNEL");
941  
942 end
943 end
944  
945 function ChatBar_UpdateBarBorder()
946 if (ChatBar_BarBorder) then
947 ChatBarFrameBackground:Show();
948 else
949 ChatBarFrameBackground:Hide();
950 end
951 end
952  
953 function ChatBar_Reset()
954 ChatBarFrame:ClearAllPoints();
955 ChatBarFrame:SetPoint("BOTTOMLEFT", "ChatFrame1", "TOPLEFT", 0, 30);
956 ChatBarFrame:SetUserPlaced(0);
957 end
958  
959 --------------------------------------------------
960 -- Configuration Functions
961 --------------------------------------------------
962  
963 function ChatBar_Toggle_VerticalButtonOrientationSlide()
964 if (not ChatBarFrame.isMoving) then
965 ChatBar_VerticalDisplay_Sliding = true;
966 ChatBar_StartSlidingTo(16);
967 end
968 end
969  
970 function ChatBar_Toggle_AlternateButtonOrientationSlide()
971 if (not ChatBarFrame.isMoving) then
972 ChatBar_AlternateDisplay_Sliding = true;
973 ChatBar_StartSlidingTo(16);
974 end
975 end
976  
977 function ChatBar_Toggle_VerticalButtonOrientation()
978 if (ChatBar_VerticalDisplay) then
979 ChatBar_VerticalDisplay = false;
980 else
981 ChatBar_VerticalDisplay = true;
982 end
983 --ChatBar_UpdateOrientationPoint();
984 ChatBar_UpdateButtonOrientation();
985 ChatBar_UpdateButtons();
986 end
987  
988 function ChatBar_UpdateOrientationPoint(expanded)
989 local x, y;
990 if (ChatBarFrame:IsUserPlaced()) then
991 if (expanded) then
992 if (ChatBar_AlternateOrientation) then
993 x = ChatBarFrame:GetRight();
994 y = ChatBarFrame:GetTop();
995 ChatBarFrame:ClearAllPoints();
996 ChatBarFrame:SetPoint("TOPRIGHT", "UIParent", "BOTTOMLEFT", x, y);
997 else
998 x = ChatBarFrame:GetLeft();
999 y = ChatBarFrame:GetBottom();
1000 ChatBarFrame:ClearAllPoints();
1001 ChatBarFrame:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", x, y);
1002 end
1003 else
1004 if (ChatBar_AlternateOrientation) then
1005 x = ChatBarFrame:GetLeft()+16;
1006 y = ChatBarFrame:GetBottom()+16;
1007 ChatBarFrame:ClearAllPoints();
1008 ChatBarFrame:SetPoint("TOPRIGHT", "UIParent", "BOTTOMLEFT", x, y);
1009 else
1010 x = ChatBarFrame:GetRight()-16;
1011 y = ChatBarFrame:GetTop()-16;
1012 ChatBarFrame:ClearAllPoints();
1013 ChatBarFrame:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", x, y);
1014 end
1015 end
1016 else
1017 if (ChatBar_AlternateOrientation) then
1018 ChatBarFrame:ClearAllPoints();
1019 ChatBarFrame:SetPoint("TOPRIGHT", "ChatFrame1", "TOPLEFT", 16, 46);
1020 else
1021 ChatBarFrame:ClearAllPoints();
1022 ChatBarFrame:SetPoint("BOTTOMLEFT", "ChatFrame1", "TOPLEFT", 0, 30);
1023 end
1024 end
1025 end
1026  
1027 function ChatBar_Toggle_AlternateButtonOrientation()
1028 if (ChatBar_AlternateOrientation) then
1029 ChatBar_AlternateOrientation = false;
1030 else
1031 ChatBar_AlternateOrientation = true;
1032 end
1033 --ChatBar_UpdateOrientationPoint();
1034 ChatBar_UpdateButtonOrientation();
1035 ChatBar_UpdateButtons();
1036 end
1037  
1038 function ChatBar_Toggle_TextOrientation()
1039 if (ChatBar_TextOnButtonDisplay) then
1040 ChatBar_TextOnButtonDisplay = false;
1041 else
1042 ChatBar_TextOnButtonDisplay = true;
1043 end
1044 ChatBar_UpdateButtonOrientation();
1045 end
1046  
1047 function ChatBar_Toggle_ButtonFlashing()
1048 if (ChatBar_ButtonFlashing) then
1049 ChatBar_ButtonFlashing = false;
1050 else
1051 ChatBar_ButtonFlashing = true;
1052 end
1053 ChatBar_UpdateButtonFlashing();
1054 end
1055  
1056 function ChatBar_Toggle_BarBorder()
1057 if (ChatBar_BarBorder) then
1058 ChatBar_BarBorder = false;
1059 else
1060 ChatBar_BarBorder = true;
1061 end
1062 ChatBar_UpdateBarBorder();
1063 end
1064  
1065 function ChatBar_Toggle_HideSpecialChannels()
1066 if (ChatBar_HideSpecialChannels) then
1067 ChatBar_HideSpecialChannels = false;
1068 else
1069 ChatBar_HideSpecialChannels = true;
1070 end
1071 ChatBar_UpdateButtons();
1072 end
1073  
1074 function ChatBar_UpdateButtonText()
1075 if (ChatBar_ButtonText) then
1076 for i=1, CHAT_BAR_MAX_BUTTONS do
1077 local button = getglobal("ChatBarFrameButton"..i);
1078 button.Text:Show();
1079 end
1080 else
1081 for i=1, CHAT_BAR_MAX_BUTTONS do
1082 local button = getglobal("ChatBarFrameButton"..i);
1083 button.Text:Hide();
1084 end
1085 end
1086 end
1087  
1088 function ChatBar_Toggle_ButtonText()
1089 if (ChatBar_ButtonText) then
1090 ChatBar_ButtonText = false;
1091 else
1092 ChatBar_ButtonText = true;
1093 end
1094 ChatBar_UpdateButtonText();
1095 end
1096  
1097 function ChatBar_Toggle_TextChannelNumbers()
1098 if (ChatBar_TextChannelNumbers) then
1099 ChatBar_TextChannelNumbers = false;
1100 else
1101 ChatBar_TextChannelNumbers = true;
1102 end
1103 ChatBar_UpdateButtons();
1104 end
1105  
1106 --------------------------------------------------
1107 -- Helper Functions
1108 --------------------------------------------------
1109  
1110 function ChatBar_GetTableSize(t)
1111 local i=0;
1112 for k,v in t do
1113 if (k and v) then i=i+1 end;
1114 end
1115 return i;
1116 end
1117  
1118 function ChatBar_GetFirstWord(s)
1119 local firstWord, count = gsub(s, "%s.*", "")
1120 return firstWord;
1121 end
1122  
1123  
1124 --------------------------------------------------
1125 -- Reorder Channels
1126 --------------------------------------------------
1127  
1128 -- Standard Channel Order
1129 STANDARD_CHANNEL_ORDER = {
1130 [CHATBAR_GENERAL] = 1,
1131 [CHATBAR_TRADE] = 2,
1132 [CHATBAR_LOCALDEFENSE] = 3,
1133 [CHATBAR_LFG] = 4,
1134 [CHATBAR_WORLDDEFENSE] = 5,
1135 [CHATBAR_GUILDRECRUITMENT] = 6,
1136 };
1137  
1138 BOGUS_CHANNELS = {
1139 "morneusgbyfyh",
1140 "akufbhfeuinjke",
1141 "lkushawdewui",
1142 "auwdbadwwho",
1143 "uawhbliuernb",
1144 "nvcuoiisnejfk",
1145 "cmewhumimr",
1146 "cliuchbwubine",
1147 "omepwucbawy",
1148 "yuiwbefmopou"
1149 };
1150  
1151 CHATBAR_CAPITAL_CITIES = {
1152 [CHATBAR_ORGRIMMAR] = 1,
1153 [CHATBAR_STORMWIND] = 1,
1154 [CHATBAR_IRONFORGE] = 1,
1155 [CHATBAR_DARNASSUS] = 1,
1156 [CHATBAR_UNDERCITY] = 1,
1157 [CHATBAR_THUNDERBLUFF] = 1,
1158 };
1159  
1160 --
1161 -- reorderChannels()
1162 -- Stores current channels, Leaves all channels and then rejoins them in a standard ordering.
1163 --
1164 --
1165 function ChatBar_ReorderChannels()
1166 if UnitOnTaxi("player") then
1167 Sea.io.printfc(SELECTED_CHAT_FRAME, ChatTypeInfo["SYSTEM"], CHATBAR_REORDER_FLIGHT_FAIL);
1168 -- For some reason channels do not register join/leave in a reasonable amount of time while in transit.
1169 return;
1170 end
1171  
1172 local newChannelOrder = {};
1173 local openChannelIndex = 1;
1174 local currIdentifier, simpleName, inGlobalComm, _;
1175  
1176 --Get Channel List
1177 local list = {GetChannelList()};
1178 local currChannelList = {};
1179 for i=1, getn(list), 2 do
1180 table.insert(currChannelList, tonumber(list[i]), list[i+1]);
1181 end
1182  
1183 -- Find current standard channels: store and leave
1184 for index, chanName in currChannelList do
1185 if (type(chanName) == "string") then
1186 _, _, simpleName = strfind(chanName, "(%w+).*");
1187 if (STANDARD_CHANNEL_ORDER[simpleName]) then
1188 if ( simpleName == "GlobalComm" ) then
1189 inGlobalComm = true;
1190 else
1191 newChannelOrder[STANDARD_CHANNEL_ORDER[simpleName]] = simpleName;
1192 end
1193 LeaveChannelByName(chanName);
1194 currChannelList[index] = nil;
1195 end
1196 end
1197 end
1198 --Sea.io.printTable(currChannelList);
1199 -- Find current non-standard channels: store and leave
1200 for index, chanName in currChannelList do
1201 if (type(chanName) == "string") then
1202 while (newChannelOrder[openChannelIndex]) do
1203 openChannelIndex = openChannelIndex + 1;
1204 end
1205 newChannelOrder[openChannelIndex] = chanName;
1206 LeaveChannelByName(chanName);
1207 openChannelIndex = openChannelIndex + 1;
1208 end
1209 end
1210  
1211 if (inGlobalComm) then
1212 while (newChannelOrder[openChannelIndex]) do
1213 openChannelIndex = openChannelIndex + 1;
1214 end
1215 newChannelOrder[openChannelIndex] = "GlobalComm";
1216 end
1217  
1218 --Sea.io.printTable(newChannelOrder);
1219 Sea.io.print(CHATBAR_REORDER_START);
1220 Chronos.schedule(.6, ChatBar_joinChannelsInOrder, newChannelOrder);
1221 Chronos.schedule(1.2, function() Sea.io.print(CHATBAR_REORDER_END); end );
1222 Chronos.schedule(2, ListChannels );
1223 end
1224  
1225 function ChatBar_joinChannelsInOrder(newChannelOrder)
1226  
1227 local inACity = CHATBAR_CAPITAL_CITIES[GetRealZoneText()];
1228  
1229 -- Join channels in new order
1230 for i=1, 10 do
1231 if (newChannelOrder[i]) then
1232 if (ChannelManager_CustomChannelPasswords) and (ChannelManager_CustomChannelPasswords[newChannelOrder[i]]) then
1233 JoinChannelByName(newChannelOrder[i], ChannelManager_CustomChannelPasswords[newChannelOrder[i]]);
1234 else
1235 JoinChannelByName(newChannelOrder[i]);
1236 end
1237 else
1238 -- Allow for hidden trade channel (Unfortunetly if you're not in a city and aren't in trade then numbers will be slightly off)
1239 if (inACity) or (STANDARD_CHANNEL_ORDER[CHATBAR_TRADE] ~= i) then
1240 JoinChannelByName(BOGUS_CHANNELS[i]);
1241 end
1242 end
1243 end
1244 Chronos.schedule(.6, ChatBar_leaveExtraChannels, newChannelOrder );
1245 end
1246  
1247 function ChatBar_leaveExtraChannels(newChannelOrder)
1248  
1249 for i, bogusName in BOGUS_CHANNELS do
1250 local channelNum, channelName = GetChannelName(bogusName);
1251 if (channelName) then
1252 LeaveChannelByName(channelNum);
1253 end
1254 end
1255  
1256 end
1257