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

View File

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