Fix opened channels saving

This commit is contained in:
Eduardo Bart 2012-07-31 00:53:15 -03:00
parent fbb3c9933a
commit 49a8c750f9
2 changed files with 26 additions and 33 deletions

View File

@ -109,12 +109,7 @@ function terminate()
onGameStart = onGameStart, onGameStart = onGameStart,
onGameEnd = clear }) onGameEnd = clear })
for channelid, channelname in pairs(channels) do if g_game.isOnline() then clear() end
if tonumber(channelid) and tonumber(channelid) ~= 0 then
g_game.leaveChannel(channelid)
end
end
channels = {}
g_keyboard.unbindKeyDown('Ctrl+O') g_keyboard.unbindKeyDown('Ctrl+O')
g_keyboard.unbindKeyDown('Ctrl+E') g_keyboard.unbindKeyDown('Ctrl+E')
@ -145,26 +140,29 @@ function onTabChange(tabBar, tab)
end end
function clear() function clear()
local lastChannelsOpen = {} -- save last open channels
local lastChannelsOpen = g_settings.getNode('lastChannelsOpen') or {}
local player = g_game.getLocalPlayer() local char = g_game.getLocalPlayer():getName()
if(player) then local savedChannels = {}
local char = player:getName() local set = false
lastChannelsOpen[char] = {} for channelId, channelName in pairs(channels) do
if type(channelId) == 'number' then
for channelId, channelName in pairs(channels) do savedChannels[channelName] = channelId
table.insert(lastChannelsOpen[char], channelId) set = true
end end
end end
if set then
lastChannelsOpen[char] = savedChannels
else
lastChannelsOpen[char] = nil
end
g_settings.setNode('lastChannelsOpen', lastChannelsOpen)
-- save last open channels -- close channels
g_settings.setNode('LastChannelsOpen', lastChannelsOpen)
for _, channelName in pairs(channels) do for _, channelName in pairs(channels) do
local tab = consoleTabBar:getTab(channelName) local tab = consoleTabBar:getTab(channelName)
consoleTabBar:removeTab(tab) consoleTabBar:removeTab(tab)
end end
channels = {} channels = {}
consoleTabBar:getTab(tr('Default')).tabPanel:getChildById('consoleBuffer'):destroyChildren() consoleTabBar:getTab(tr('Default')).tabPanel:getChildById('consoleBuffer'):destroyChildren()
@ -563,19 +561,14 @@ end
function onGameStart() function onGameStart()
-- open last channels -- open last channels
local player = g_game.getLocalPlayer() local lastChannelsOpen = g_settings.getNode('lastChannelsOpen')
if(player) then local savedChannels = lastChannelsOpen[g_game.getLocalPlayer():getName()]
local char = player:getName() if savedChannels then
for channelName, channelId in pairs(savedChannels) do
local lastChannelsOpen = g_settings.getNode('LastChannelsOpen') channelId = tonumber(channelId)
if channelId ~= 0 then
if(not table.empty(lastChannelsOpen) and lastChannelsOpen[char]) then if not table.find(channels, channelId) then
for channelName, channelId in ipairs(lastChannelsOpen[char]) do g_game.joinChannel(channelId)
channelId = tonumber(channelId)
if channelId ~= 0 then
if not table.find(channels, channelId) then
g_game.joinChannel(channelId)
end
end end
end end
end end

View File

@ -437,7 +437,7 @@ void Game::loginWorld(const std::string& account, const std::string& password, c
resetGameStates(); resetGameStates();
m_localPlayer = LocalPlayerPtr(new LocalPlayer); m_localPlayer = LocalPlayerPtr(new LocalPlayer);
m_localPlayer->setName(m_characterName); m_localPlayer->setName(characterName);
m_protocolGame = ProtocolGamePtr(new ProtocolGame); m_protocolGame = ProtocolGamePtr(new ProtocolGame);
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName); m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);