2011-08-09 05:43:46 -04:00
|
|
|
ChatSaver = LibStub('AceAddon-3.0'):NewAddon('ChatSaver','AceConsole-3.0','AceHook-3.0','AceEvent-3.0')
|
|
|
|
local core = ChatSaver
|
2011-05-25 05:05:57 -04:00
|
|
|
|
2011-05-27 17:54:01 -04:00
|
|
|
function core:OnInitialize()
|
2011-08-09 05:43:46 -04:00
|
|
|
if ChatSaverDB == nil then
|
|
|
|
core.firstrun = true
|
|
|
|
ChatSaverDB = {}
|
2011-05-27 17:54:01 -04:00
|
|
|
else
|
2011-08-09 05:43:46 -04:00
|
|
|
core.firstrun = false
|
2011-05-27 17:54:01 -04:00
|
|
|
end
|
2011-05-25 05:05:57 -04:00
|
|
|
end
|
|
|
|
|
2011-05-25 18:58:22 -04:00
|
|
|
function core:OnEnable()
|
2011-08-09 05:43:46 -04:00
|
|
|
self:Hook('ToggleChatChannel','ToggleChatChannel',true)
|
2011-05-29 06:36:07 -04:00
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','ProcessChannelChange')
|
|
|
|
if core.firstrun then
|
|
|
|
self:RegisterEvent('CHANNEL_UI_UPDATE','SetupChatSaver')
|
2011-05-27 17:54:01 -04:00
|
|
|
end
|
2011-05-25 18:58:22 -04:00
|
|
|
end
|
|
|
|
|
2011-06-03 07:33:09 -04:00
|
|
|
--[[
|
|
|
|
-- CHANNEL FUNCTIONS
|
|
|
|
-- Because GetChannelName() and GetChannelDisplayInfo() are less
|
|
|
|
-- than good.
|
|
|
|
]] --
|
|
|
|
|
|
|
|
function core:GetChannelInfo(id)
|
2011-08-09 05:43:46 -04:00
|
|
|
local channelNumber,channelName = GetChannelName(id)
|
|
|
|
local channelTable = core:GetChannelTable()
|
2011-06-03 08:28:09 -04:00
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
if channelName == nil then
|
|
|
|
id = channelTable[id]
|
2011-06-03 08:28:09 -04:00
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
if id ~= nil then
|
|
|
|
channelNumber,channelName = GetChannelName(id)
|
2011-06-03 08:28:09 -04:00
|
|
|
end
|
2011-06-03 07:33:09 -04:00
|
|
|
end
|
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
return channelNumber,channelName,core:GetChannelCategory(channelNumber)
|
2011-06-03 07:33:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:GetChannelTable()
|
2011-08-09 05:43:46 -04:00
|
|
|
local channelList = { GetChannelList() }
|
|
|
|
local channelTable = {}
|
2011-06-03 07:33:09 -04:00
|
|
|
for i = 1,#channelList,2 do
|
2011-08-09 05:43:46 -04:00
|
|
|
channelTable[channelList[i]] = channelList[i + 1]
|
|
|
|
channelTable[channelList[i + 1]] = channelList[i]
|
2011-08-09 05:30:28 -04:00
|
|
|
if type(channelList[i + 1]) == 'string' then
|
2011-08-09 05:43:46 -04:00
|
|
|
channelTable[channelList[i + 1]:lower()] = channelList[i]
|
2011-06-03 07:33:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
return channelTable
|
2011-06-03 07:33:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:GetChannelCategory(number)
|
|
|
|
for i = 1,GetNumDisplayChannels(),1 do
|
2011-08-09 05:43:46 -04:00
|
|
|
local _,_,_,channelNumber,_,_,category = GetChannelDisplayInfo(i)
|
2011-06-03 07:33:09 -04:00
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
if channelNumber == number then
|
|
|
|
return category
|
2011-06-03 07:33:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[ EVENT FUNCTIONS ]] --
|
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
function core:ProcessChannelChange(_,message,_,_,_,_,_,_,index,name)
|
2011-08-09 05:27:31 -04:00
|
|
|
if message == 'YOU_JOINED' then
|
|
|
|
local number,_,category = core:GetChannelInfo(name)
|
|
|
|
|
|
|
|
if category == 'CHANNEL_CATEGORY_CUSTOM' then
|
2011-08-09 05:43:46 -04:00
|
|
|
ChatSaverDB[name] = {}
|
|
|
|
ChatSaverDB[name]['frames'] = {}
|
|
|
|
ChatSaverDB[name]['index'] = number
|
|
|
|
ChatSaverDB[name]['frames'][DEFAULT_CHAT_FRAME:GetID()] = true
|
2011-08-09 05:27:31 -04:00
|
|
|
end
|
|
|
|
elseif message == 'YOU_LEFT' then
|
|
|
|
ChatSaverDB[name] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-27 18:53:50 -04:00
|
|
|
function core:RejoinChannels(...)
|
2011-08-09 05:43:46 -04:00
|
|
|
local currentChannels = {}
|
2011-05-29 06:36:07 -04:00
|
|
|
for i = 1,select('#',GetChannelList()) do
|
2011-05-27 19:30:56 -04:00
|
|
|
currentChannels[select(i,GetChannelList())] = true
|
|
|
|
end
|
2011-05-25 05:36:29 -04:00
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
local sortedChannels = {}
|
2011-05-27 21:49:47 -04:00
|
|
|
for channel,_ in pairs(ChatSaverDB) do
|
2011-08-09 05:43:46 -04:00
|
|
|
table.insert(sortedChannels,channel)
|
2011-06-02 04:53:40 -04:00
|
|
|
end
|
2011-08-09 05:43:46 -04:00
|
|
|
table.sort(sortedChannels,function(a,b) return ChatSaverDB[a].index < ChatSaverDB[b].index end)
|
2011-06-02 04:53:40 -04:00
|
|
|
|
|
|
|
for _,channel in pairs(sortedChannels) do
|
2011-08-09 05:30:28 -04:00
|
|
|
if currentChannels[channel] == nil then
|
2011-08-09 05:43:46 -04:00
|
|
|
JoinPermanentChannel(channel) -- does not place in chat frame properly
|
2011-05-27 21:49:47 -04:00
|
|
|
for index,_ in pairs(ChatSaverDB[channel].frames) do
|
2011-08-09 05:43:46 -04:00
|
|
|
ChatFrame_AddChannel(_G['ChatFrame'..index],channel)
|
2011-05-25 22:41:33 -04:00
|
|
|
end
|
2011-05-25 05:36:29 -04:00
|
|
|
end
|
|
|
|
end
|
2011-05-26 02:09:37 -04:00
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
self:UnregisterEvent('CHANNEL_UI_UPDATE')
|
2011-05-27 18:53:50 -04:00
|
|
|
end
|
|
|
|
|
2011-05-29 06:36:07 -04:00
|
|
|
function core:SetupChatSaver(...)
|
|
|
|
for frame = 1,NUM_CHAT_WINDOWS do
|
2011-08-09 05:43:46 -04:00
|
|
|
local chatWindowChannels = { GetChatWindowChannels(frame) }
|
2011-05-29 06:36:07 -04:00
|
|
|
for i = 1,#chatWindowChannels,2 do
|
2011-08-09 05:43:46 -04:00
|
|
|
local number,name,category = core:GetChannelInfo(chatWindowChannels[i])
|
2011-06-03 08:28:09 -04:00
|
|
|
|
2011-08-09 05:30:28 -04:00
|
|
|
if category == 'CHANNEL_CATEGORY_CUSTOM' then
|
|
|
|
if ChatSaverDB[name] == nil then
|
2011-08-09 05:43:46 -04:00
|
|
|
ChatSaverDB[name] = {}
|
|
|
|
ChatSaverDB[name]['frames'] = {}
|
|
|
|
ChatSaverDB[name]['index'] = number
|
2011-05-27 18:53:50 -04:00
|
|
|
end
|
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
ChatSaverDB[name]['frames'][frame] = true
|
2011-05-27 18:53:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-09 05:43:46 -04:00
|
|
|
self:UnregisterEvent('CHANNEL_UI_UPDATE')
|
2011-06-03 04:56:12 -04:00
|
|
|
end
|
|
|
|
|
2011-06-03 07:33:09 -04:00
|
|
|
--[[ HOOKED FUNCTIONS ]] --
|
2011-06-03 05:42:15 -04:00
|
|
|
|
2011-05-25 22:41:33 -04:00
|
|
|
function core:ToggleChatChannel(checked,channel)
|
2011-08-09 05:30:28 -04:00
|
|
|
if ChatSaverDB[channel] == nil then
|
2011-08-09 05:43:46 -04:00
|
|
|
return
|
2011-05-25 23:18:21 -04:00
|
|
|
end
|
|
|
|
|
2011-08-09 05:30:28 -04:00
|
|
|
if checked then
|
2011-08-09 05:43:46 -04:00
|
|
|
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = true
|
2011-05-25 22:41:33 -04:00
|
|
|
else
|
2011-08-09 05:43:46 -04:00
|
|
|
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = nil
|
2011-05-25 22:41:33 -04:00
|
|
|
end
|
2011-05-25 18:58:22 -04:00
|
|
|
end
|