Compare commits
No commits in common. "master" and "v1.0b-beta" have entirely different histories.
master
...
v1.0b-beta
3 changed files with 62 additions and 116 deletions
166
ChatSaver.lua
166
ChatSaver.lua
|
@ -1,136 +1,80 @@
|
||||||
ChatSaver = LibStub('AceAddon-3.0'):NewAddon('ChatSaver','AceConsole-3.0','AceHook-3.0','AceEvent-3.0');
|
ChatSaver = LibStub('AceAddon-3.0'):NewAddon('ChatSaver','AceConsole-3.0','AceHook-3.0','AceEvent-3.0');
|
||||||
local core = ChatSaver;
|
local core = ChatSaver;
|
||||||
|
|
||||||
|
core.verified = false;
|
||||||
|
|
||||||
function core:OnInitialize()
|
function core:OnInitialize()
|
||||||
if(ChatSaverDB == nil) then
|
self:RawHook(SlashCmdList,'JOIN','JoinChannel',true);
|
||||||
core.firstrun = true;
|
self:RawHook(SlashCmdList,'LEAVE','LeaveChannel',true);
|
||||||
ChatSaverDB = {};
|
self:Hook('ToggleChatChannel','ToggleChatChannel',true);
|
||||||
else
|
|
||||||
core.firstrun = false;
|
self:RegisterChatCommand('cs','SlashCommand');
|
||||||
end
|
|
||||||
|
if(ChatSaverDB == nil) then ChatSaverDB = {}; end
|
||||||
end
|
end
|
||||||
|
|
||||||
function core:OnEnable()
|
function core:OnEnable()
|
||||||
self:Hook('ToggleChatChannel','ToggleChatChannel',true);
|
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','RejoinChannels');
|
||||||
|
|
||||||
self:RegisterEvent('CHANNEL_UI_UPDATE','RejoinChannels');
|
|
||||||
if(core.firstrun) then
|
|
||||||
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','SetupChatSaver');
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
function core:SlashCommand()
|
||||||
-- CHANNEL FUNCTIONS
|
core.verified = false
|
||||||
-- Because GetChannelName() and GetChannelDisplayInfo() are less
|
core:RejoinChannels();
|
||||||
-- than good.
|
|
||||||
]] --
|
|
||||||
|
|
||||||
function core:GetChannelInfo(id)
|
|
||||||
local channelNumber,channelName = GetChannelName(id);
|
|
||||||
local channelTable = core:GetChannelTable();
|
|
||||||
|
|
||||||
if(channelName == nil) then
|
|
||||||
id = channelTable[id];
|
|
||||||
|
|
||||||
if(id ~= nil) then
|
|
||||||
channelNumber,channelName = GetChannelName(id);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return channelNumber,channelName,core:GetChannelCategory(channelNumber);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function core:GetChannelTable()
|
function core:RejoinChannels(event,message,...)
|
||||||
local channelList = { GetChannelList() };
|
if(message == 'YOU_LEFT' or core.verified == true) then
|
||||||
local channelTable = {};
|
return;
|
||||||
for i = 1,#channelList,2 do
|
end
|
||||||
channelTable[channelList[i]] = channelList[i + 1];
|
|
||||||
channelTable[channelList[i + 1]] = channelList[i];
|
local channelList = {};
|
||||||
if(type(channelList[i + 1]) == 'string') then
|
for i = 1, select("#",GetChannelList()), 2 do
|
||||||
channelTable[channelList[i + 1]:lower()] = channelList[i];
|
local index,channel = select(i,GetChannelList());
|
||||||
|
channelList[index] = channel;
|
||||||
|
end
|
||||||
|
|
||||||
|
for channel,information in pairs(ChatSaverDB) do
|
||||||
|
local found = false;
|
||||||
|
for jIndex,jChannel in pairs(channelList) do
|
||||||
|
if(jChannel == channel) then
|
||||||
|
found = true;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return channelTable;
|
if(found == false) then
|
||||||
|
JoinPermanentChannel(channel);
|
||||||
|
for index,shown in pairs(ChatSaverDB[channel].frames) do
|
||||||
|
if(shown) then
|
||||||
|
_G['ChatFrame'..index].channelList[table.getn(_G['ChatFrame'..index].channelList) + 1] = channel;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
core.verified = true;
|
||||||
end
|
end
|
||||||
|
|
||||||
function core:GetChannelCategory(number)
|
function core:JoinChannel(msg)
|
||||||
for i = 1,GetNumDisplayChannels(),1 do
|
self.hooks[SlashCmdList].JOIN(msg);
|
||||||
local _,_,_,channelNumber,_,_,category = GetChannelDisplayInfo(i);
|
|
||||||
|
|
||||||
if(channelNumber == number) then
|
local name = gsub(msg, "%s*([^%s]+).*", "%1");
|
||||||
return category;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[ EVENT FUNCTIONS ]] --
|
if(strlen(name) > 0 and string.match(name,"%a+")) then
|
||||||
|
|
||||||
function core:ProcessChannelChange(_,message,_,_,_,_,_,_,index,name)
|
|
||||||
if message == 'YOU_JOINED' then
|
|
||||||
local number,_,category = core:GetChannelInfo(name)
|
|
||||||
|
|
||||||
if category == 'CHANNEL_CATEGORY_CUSTOM' then
|
|
||||||
if ChatSaverDB[name] == nil then
|
|
||||||
ChatSaverDB[name] = {}
|
|
||||||
ChatSaverDB[name]['frames'] = {}
|
|
||||||
ChatSaverDB[name]['index'] = number
|
|
||||||
ChatSaverDB[name]['frames'][DEFAULT_CHAT_FRAME:GetID()] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif message == 'YOU_LEFT' then
|
|
||||||
ChatSaverDB[name] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function core:RejoinChannels(...)
|
|
||||||
local currentChannels = {};
|
|
||||||
for i = 1,select('#',GetChannelList()) do
|
|
||||||
currentChannels[select(i,GetChannelList())] = true
|
|
||||||
end
|
|
||||||
|
|
||||||
local sortedChannels = {};
|
|
||||||
for channel,_ in pairs(ChatSaverDB) do
|
|
||||||
table.insert(sortedChannels,channel);
|
|
||||||
end
|
|
||||||
table.sort(sortedChannels,function(a,b) return ChatSaverDB[a].index < ChatSaverDB[b].index end);
|
|
||||||
|
|
||||||
for _,channel in pairs(sortedChannels) do
|
|
||||||
if(currentChannels[channel] == nil) then
|
|
||||||
JoinPermanentChannel(channel); -- does not place in chat frame properly
|
|
||||||
for index,_ in pairs(ChatSaverDB[channel].frames) do
|
|
||||||
ChatFrame_AddChannel(_G['ChatFrame'..index],channel);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self:UnregisterEvent('CHANNEL_UI_UPDATE');
|
|
||||||
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','ProcessChannelChange')
|
|
||||||
end
|
|
||||||
|
|
||||||
function core:SetupChatSaver(...)
|
|
||||||
for frame = 1,NUM_CHAT_WINDOWS do
|
|
||||||
local chatWindowChannels = { GetChatWindowChannels(frame) };
|
|
||||||
for i = 1,#chatWindowChannels,2 do
|
|
||||||
local number,name,category = core:GetChannelInfo(chatWindowChannels[i]);
|
|
||||||
|
|
||||||
if(category == 'CHANNEL_CATEGORY_CUSTOM') then
|
|
||||||
if(ChatSaverDB[name] == nil) then
|
|
||||||
ChatSaverDB[name] = {};
|
ChatSaverDB[name] = {};
|
||||||
ChatSaverDB[name]['frames'] = {};
|
ChatSaverDB[name]['frames'] = {};
|
||||||
ChatSaverDB[name]['index'] = number;
|
ChatSaverDB[name]['index'] = GetChannelName(name);
|
||||||
|
ChatSaverDB[name]['frames'][DEFAULT_CHAT_FRAME:GetID()] = true;
|
||||||
end
|
end
|
||||||
|
|
||||||
ChatSaverDB[name]['frames'][frame] = true;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self:UnregisterEvent('CHAT_MSG_CHANNEL_NOTICE');
|
|
||||||
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','ProcessChannelChange')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[ HOOKED FUNCTIONS ]] --
|
function core:LeaveChannel(msg)
|
||||||
|
self.hooks[SlashCmdList].LEAVE(msg);
|
||||||
|
|
||||||
|
local number = gsub(msg, "%s*([^%s]+).*", "%1");
|
||||||
|
local _,name = GetChannelName(number);
|
||||||
|
|
||||||
|
ChatSaverDB[name] = nil;
|
||||||
|
end
|
||||||
|
|
||||||
function core:ToggleChatChannel(checked,channel)
|
function core:ToggleChatChannel(checked,channel)
|
||||||
if(ChatSaverDB[channel] == nil) then
|
if(ChatSaverDB[channel] == nil) then
|
||||||
|
@ -140,6 +84,6 @@ function core:ToggleChatChannel(checked,channel)
|
||||||
if(checked) then
|
if(checked) then
|
||||||
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = true;
|
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = true;
|
||||||
else
|
else
|
||||||
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = nil;
|
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = false;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
## Interface: 42000
|
## Interface: 40000
|
||||||
## Title: ChatSaver
|
## Title: ChatSaver
|
||||||
## Version: @project-version@
|
## Version: 1.0
|
||||||
## Author: Gaffer
|
## Author: Gaffer
|
||||||
## Notes: Saves chat channels and restores them if World of Warcraft loses them.
|
## Notes: Saves chat channels and restores them if World of Warcraft loses them.
|
||||||
|
## Dependencies:
|
||||||
|
## OptionalDeps:
|
||||||
## DefaultState: enabled
|
## DefaultState: enabled
|
||||||
## SavedVariablesPerCharacter: ChatSaverDB
|
## SavedVariablesPerCharacter: ChatSaverDB
|
||||||
|
|
||||||
Libs\LibStub\LibStub.lua
|
Libs\LibStub\LibStub.lua
|
||||||
Libs\CallbackHandler-1.0\CallbackHandler-1.0.xml
|
Libs\CallbackHandler-1.0\CallbackHandler-1.0.xml
|
||||||
Libs\AceAddon-3.0\AceAddon-3.0.xml
|
Libs\AceAddon-3.0\AceAddon-3.0.xml
|
||||||
Libs\AceConsole-3.0\AceConsole-3.0.xml
|
Libs\AceAddon-3.0\AceConsole-3.0.xml
|
||||||
Libs\AceEvent-3.0\AceEvent-3.0.xml
|
Libs\AceEvent-3.0\AceEvent-3.0.xml
|
||||||
Libs\AceHook-3.0\AceHook-3.0.xml
|
Libs\AceHook-3.0\AceHook-3.0.xml
|
||||||
|
|
||||||
|
|
0
README
0
README
Loading…
Reference in a new issue