Fix a bug with autowalking & add prompt param for tryLogout.

(We don't want to be prompted when pressing Ctrl + Q or  Ctrl + L).
This commit is contained in:
BeniS 2013-07-07 05:36:56 +12:00
parent c4adf2d817
commit 95abf2a1d2
2 changed files with 33 additions and 26 deletions

View File

@ -42,7 +42,8 @@ function init()
gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel') gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel')
connect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange }) connect(gameLeftPanel, { onVisibilityChange = onLeftPanelVisibilityChange })
logoutButton = modules.client_topmenu.addLeftButton('logoutButton', tr('Exit'), '/images/topbuttons/logout', tryLogout, true) logoutButton = modules.client_topmenu.addLeftButton('logoutButton', tr('Exit'),
'/images/topbuttons/logout', tryLogout, true)
setupViewMode(0) setupViewMode(0)
@ -104,8 +105,8 @@ function bindKeys()
g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel) g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel) g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel)
g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel) g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+Q', tryLogout, gameRootPanel) g_keyboard.bindKeyDown('Ctrl+Q', function() tryLogout(false) end, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+L', tryLogout, gameRootPanel) g_keyboard.bindKeyDown('Ctrl+L', function() tryLogout(false) end, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() modules.game_textmessage.clearMessages() end, gameRootPanel) g_keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() modules.game_textmessage.clearMessages() end, gameRootPanel)
g_keyboard.bindKeyDown('Ctrl+.', nextViewMode, gameRootPanel) g_keyboard.bindKeyDown('Ctrl+.', nextViewMode, gameRootPanel)
end end
@ -228,7 +229,10 @@ function tryExit()
return true return true
end end
function tryLogout() function tryLogout(prompt)
if type(prompt) ~= "boolean" then
prompt = true
end
if not g_game.isOnline() then if not g_game.isOnline() then
exit() exit()
return return
@ -238,38 +242,41 @@ function tryLogout()
return return
end end
local msg, yesCallback
if not g_game.isConnectionOk() then if not g_game.isConnectionOk() then
local yesCallback = function() msg = 'Your connection is failing, if you logout now your character will be still online, do you want to force logout?'
yesCallback = function()
g_game.forceLogout() g_game.forceLogout()
if logoutWindow then if logoutWindow then
logoutWindow:destroy() logoutWindow:destroy()
logoutWindow=nil logoutWindow=nil
end end
end end
local noCallback = function() else
logoutWindow:destroy() msg = 'Are you sure you want to logout?'
logoutWindow=nil
end
logoutWindow = displayGeneralBox(tr('Logout'), tr('Your connection is failing, if you logout now your character will be still online, do you want to force logout?'), { yesCallback = function()
g_game.safeLogout()
if logoutWindow then
logoutWindow:destroy()
logoutWindow=nil
end
end
end
local noCallback = function()
logoutWindow:destroy()
logoutWindow=nil
end
if prompt then
logoutWindow = displayGeneralBox(tr('Logout'), tr(msg), {
{ text=tr('Yes'), callback=yesCallback }, { text=tr('Yes'), callback=yesCallback },
{ text=tr('No'), callback=noCallback }, { text=tr('No'), callback=noCallback },
anchor=AnchorHorizontalCenter}, yesCallback, noCallback) anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
else else
local yesCallback = function() yesCallback()
g_game.safeLogout()
logoutWindow:destroy()
logoutWindow=nil
end
local noCallback = function()
logoutWindow:destroy()
logoutWindow=nil
end
logoutWindow = displayGeneralBox(tr('Logout'), tr('Are you sure you want to logout?'), {
{ text=tr('Yes'), callback=yesCallback },
{ text=tr('No'), callback=noCallback },
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
end end
end end

View File

@ -72,7 +72,7 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
return false; return false;
// last walk is not done yet // last walk is not done yet
if(m_walkTimer.ticksElapsed() < getStepDuration()) if((m_walkTimer.ticksElapsed() < getStepDuration()) && !isAutoWalking())
return false; return false;
// prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk // prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk
@ -83,7 +83,7 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
return false; return false;
// cannot walk while already walking // cannot walk while already walking
if(m_walking && (!prewalkTimeouted || m_secondPreWalk)) if((m_walking && !isAutoWalking()) && (!prewalkTimeouted || m_secondPreWalk))
return false; return false;
return true; return true;