Rework smart walk, fix #247

This commit is contained in:
Eduardo Bart 2013-01-26 18:10:30 -02:00
parent 4f8f02acad
commit 2fd3c643c4
12 changed files with 97 additions and 94 deletions

View File

@ -344,7 +344,7 @@ locale = {
["You are dazzled"] = "Du bist geblendet",
["You are dead."] = "Du bist tot.",
["You are dead"] = "Du bist tot",
["You are drowing"] = "Du ertrinkst",
["You are drowning"] = "Du ertrinkst",
["You are drunk"] = "Du bist betrunken",
["You are electrified"] = "Du bist elektrifiziert",
["You are freezing"] = "Du bist am Erfrieren",

View File

@ -345,7 +345,7 @@ locale = {
["You are dazzled"] = "Tu estas deslumbrado",
["You are dead."] = "Tu estas muerto.",
["You are dead"] = "Tu estas muerto",
["You are drowing"] = "Tu estas ahotado",
["You are drowning"] = "Tu estas ahotado",
["You are drunk"] = "Tu estas borracho",
["You are electrified"] = "Tu estas electrificado",
["You are freezing"] = "Tu estas congelado",

View File

@ -347,7 +347,7 @@ locale = {
["You are dazzled"] = "Jestes oslepiony",
["You are dead."] = "Zginales marnie.",
["You are dead"] = false,
["You are drowing"] = "Topisz sie",
["You are drowning"] = "Topisz sie",
["You are drunk"] = false,
["You are electrified"] = "Jestes porazony pradem",
["You are freezing"] = "Marzniesz",

View File

@ -341,7 +341,7 @@ locale = {
["You are dazzled"] = "Você está deslumbrado",
["You are dead."] = "Você está morto.",
["You are dead"] = "Você está morto",
["You are drowing"] = "Você está se afogando",
["You are drowning"] = "Você está se afogando",
["You are drunk"] = "Você está bêbado",
["You are electrified"] = "Você está eletrificado",
["You are freezing"] = "Você está congelando",

View File

@ -345,7 +345,7 @@ locale = {
["You are dazzled"] = "Du är chockad",
["You are dead."] = "Du är död.",
["You are dead"] = "Du är död",
["You are drowing"] = "Du drunknar",
["You are drowning"] = "Du drunknar",
["You are drunk"] = "Du är full.",
["You are electrified"] = "Du är elektrifierad",
["You are freezing"] = "Du Fryser",

View File

@ -339,7 +339,7 @@ neededTranslations = {
"You are dazzled",
"You are dead.",
"You are dead",
"You are drowing",
"You are drowning",
"You are drunk",
"You are electrified",
"You are freezing",

View File

@ -12,11 +12,6 @@ Panel
!text: tr('Enable smart walking')
!tooltip: tr('Will detect when to use diagonal step based on the\nkeys you are pressing')
//OptionCheckBox
//id: walkBooster
//!text: tr('Enable walk booster')
//!tooltip: tr('Also known as dash in community, recommended\nfor playing characters with high speed')
OptionCheckBox
id: showPing
!text: tr('Show connection ping')

View File

@ -4,7 +4,6 @@ local defaultOptions = {
showPing = false,
fullscreen = false,
classicControl = false,
walkBooster = false,
smartWalk = false,
autoChaseOverride = true,
showStatusMessagesInConsole = true,
@ -95,7 +94,6 @@ function init()
end
g_keyboard.bindKeyDown('Ctrl+Shift+F', function() toggleOption('fullscreen') end)
--g_keyboard.bindKeyDown('Ctrl+D', function() toggleOption('walkBooster') end)
optionsWindow = g_ui.displayUI('options')
optionsWindow:hide()

View File

@ -74,7 +74,7 @@ local function onWidgetKeyDown(widget, keyCode, keyboardModifiers)
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
local callback = widget.boundKeyDownCombos[keyComboDesc]
if callback then
callback()
callback(widget, keyCode)
return true
end
return false
@ -85,7 +85,7 @@ local function onWidgetKeyUp(widget, keyCode, keyboardModifiers)
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
local callback = widget.boundKeyUpCombos[keyComboDesc]
if callback then
callback()
callback(widget, keyCode)
return true
end
return false
@ -96,7 +96,7 @@ local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, autoRepeatTi
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
local comboConf = widget.boundKeyPressCombos[keyComboDesc]
if comboConf and (autoRepeatTicks >= comboConf.autoRepeatDelay or autoRepeatTicks == 0) and comboConf.callback then
comboConf.callback()
comboConf.callback(widget, keyCode)
return true
end
return false

View File

@ -81,6 +81,20 @@ function table.removevalue(t, value)
end
end
function table.popvalue(value)
local index = nil
for k,v in pairs(t) do
if v == value or not value then
index = k
end
end
if index then
table.remove(t, index)
return true
end
return false
end
function table.compare(t, other)
if #t ~= #other then return false end
for k,v in pairs(t) do

View File

@ -7,7 +7,7 @@ Icons[16] = { tooltip = tr('You are protected by a magic shield'), path = '/imag
Icons[32] = { tooltip = tr('You are paralysed'), path = '/images/game/states/slowed', id = 'condition_slowed' }
Icons[64] = { tooltip = tr('You are hasted'), path = '/images/game/states/haste', id = 'condition_haste' }
Icons[128] = { tooltip = tr('You may not logout during a fight'), path = '/images/game/states/logout_block', id = 'condition_logout_block' }
Icons[256] = { tooltip = tr('You are drowing'), path = '/images/game/states/drowning', id = 'condition_drowning' }
Icons[256] = { tooltip = tr('You are drowning'), path = '/images/game/states/drowning', id = 'condition_drowning' }
Icons[512] = { tooltip = tr('You are freezing'), path = '/images/game/states/freezing', id = 'condition_freezing' }
Icons[1024] = { tooltip = tr('You are dazzled'), path = '/images/game/states/dazzled', id = 'condition_dazzled' }
Icons[2048] = { tooltip = tr('You are cursed'), path = '/images/game/states/cursed', id = 'condition_cursed' }

View File

@ -1,4 +1,4 @@
WALK_AUTO_REPEAT_DELAY = 180
WALK_REPEAT_DELAY = 60
WALK_STEPS_RETRY = 10
gameRootPanel = nil
@ -14,19 +14,9 @@ exitWindow = nil
bottomSplitter = nil
limitZoom = false
currentViewMode = 0
lastDir = nil
walkEvent = nil
arrowKeys = {
[North] = 'Up',
[South] = 'Down',
[East] = 'Right',
[West] = 'Left',
[NorthEast] = 'Numpad9',
[SouthEast] = 'Numpad3',
[NorthWest] = 'Numpad7',
[SouthWest] = 'Numpad1'
}
smartWalkDirs = {}
smartWalkDir = nil
smartWalkEvent = nil
function init()
g_ui.importStyle('styles/countwindow')
@ -41,6 +31,7 @@ function init()
gameRootPanel:hide()
gameRootPanel:lower()
gameRootPanel.onGeometryChange = updateStretchShrink
gameRootPanel.onFocusChange = cancelSmartWalk
mouseGrabberWidget = gameRootPanel:getChildById('mouseGrabber')
mouseGrabberWidget.onMouseRelease = onMouseGrabberRelease
@ -64,24 +55,31 @@ function init()
end
function bindKeys()
g_keyboard.bindKeyPress('Up', function() smartWalk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Right', function() smartWalk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Down', function() smartWalk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Left', function() smartWalk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyDown('Up', function() changeWalkDir(North) end, gameRootPanel)
g_keyboard.bindKeyDown('Right', function() changeWalkDir(East) end, gameRootPanel)
g_keyboard.bindKeyDown('Down', function() changeWalkDir(South) end, gameRootPanel)
g_keyboard.bindKeyDown('Left', function() changeWalkDir(West) end, gameRootPanel)
g_keyboard.bindKeyDown('Numpad8', function() changeWalkDir(North) end, gameRootPanel)
g_keyboard.bindKeyDown('Numpad9', function() changeWalkDir(NorthEast) end, gameRootPanel)
g_keyboard.bindKeyDown('Numpad6', function() changeWalkDir(East) end, gameRootPanel)
g_keyboard.bindKeyDown('Numpad3', function() changeWalkDir(SouthEast) end, gameRootPanel)
g_keyboard.bindKeyDown('Numpad2', function() changeWalkDir(South) end, gameRootPanel)
g_keyboard.bindKeyDown('Numpad1', function() changeWalkDir(SouthWest) end, gameRootPanel)
g_keyboard.bindKeyDown('Numpad4', function() changeWalkDir(West) end, gameRootPanel)
g_keyboard.bindKeyDown('Numpad7', function() changeWalkDir(NorthWest) end, gameRootPanel)
g_keyboard.bindKeyUp('Up', function() changeWalkDir(North, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Right', function() changeWalkDir(East, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Down', function() changeWalkDir(South, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Left', function() changeWalkDir(West, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Numpad8', function() changeWalkDir(North, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Numpad9', function() changeWalkDir(NorthEast, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Numpad6', function() changeWalkDir(East, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Numpad3', function() changeWalkDir(SouthEast, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Numpad2', function() changeWalkDir(South, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Numpad1', function() changeWalkDir(SouthWest, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Numpad4', function() changeWalkDir(West, true) end, gameRootPanel)
g_keyboard.bindKeyUp('Numpad7', function() changeWalkDir(NorthWest, true) end, gameRootPanel)
g_keyboard.bindKeyPress('Numpad8', function() smartWalk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad9', function() smartWalk(NorthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad6', function() smartWalk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad3', function() smartWalk(SouthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad2', function() smartWalk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad1', function() smartWalk(SouthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad4', function() smartWalk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad7', function() smartWalk(NorthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
@ -103,6 +101,8 @@ end
function terminate()
hide()
cancelSmartWalk()
disconnect(g_game, {
onGameStart = onGameStart,
onGameEnd = onGameEnd,
@ -209,42 +209,51 @@ function tryLogout()
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
end
function changeWalkDir(dir)
local player = g_game.getLocalPlayer()
local lastWalkDir = g_game.getLastWalkDir()
if lastWalkDir ~= dir and player:isWalking() then
smartWalk(dir)
function cancelSmartWalk()
if smartWalkEvent then
smartWalkEvent:cancel()
smartWalkEvent = nil
end
smartWalkDirs = {}
end
function changeWalkDir(dir, pop)
if pop then
table.removevalue(smartWalkDirs, dir)
if #smartWalkDirs == 0 and smartWalkEvent then
smartWalkEvent:cancel()
smartWalkEvent = nil
return
end
else
table.insert(smartWalkDirs, 1, dir)
if not smartWalkEvent then
smartWalkEvent = cycleEvent(smartWalk, WALK_REPEAT_DELAY)
end
end
function smartWalk(defaultDir)
local rebindKey = false
local lastKey = arrowKeys[lastDir]
-- choose the new direction
if not g_keyboard.isKeyPressed(arrowKeys[defaultDir]) then
local changeDir = false
for k,v in pairs(arrowKeys) do
if g_keyboard.isKeyPressed(v) then
defaultDir = k
changeDir = true
smartWalkDir = smartWalkDirs[1]
if modules.client_options.getOption('smartWalk') and #smartWalkDirs > 1 then
for _,d in pairs(smartWalkDirs) do
if (smartWalkDir == North and d == West) or (smartWalkDir == West and d == North) then
smartWalkDir = NorthWest
break
elseif (smartWalkDir == North and d == East) or (smartWalkDir == East and d == North) then
smartWalkDir = NorthEast
break
elseif (smartWalkDir == South and d == West) or (smartWalkDir == West and d == South) then
smartWalkDir = SouthWest
break
elseif (smartWalkDir == South and d == East) or (smartWalkDir == East and d == South) then
smartWalkDir = SouthEast
break
end
end
if not changeDir then
return
end
end
-- key is still pressed from previous walk event
if lastDir and lastDir ~= defaultDir and g_keyboard.isKeyPressed(lastKey) then
if g_keyboard.isKeySetPressed(arrowKeys) then
g_keyboard.unbindKeyPress(lastKey, gameRootPanel)
rebindKey = true
end
end
local dir = defaultDir
function smartWalk()
local dir = smartWalkDir
if modules.client_options.getOption('smartWalk') then
if g_keyboard.isKeyPressed('Up') and g_keyboard.isKeyPressed('Left') then
dir = NorthWest
@ -257,20 +266,7 @@ function smartWalk(defaultDir)
end
end
if modules.client_options.getOption('walkBooster') then
if g_game.getLocalPlayer():canWalk(dir) then
g_game.walk(dir)
else
g_game.forceWalk(dir)
end
else
g_game.walk(dir)
end
if rebindKey then
g_keyboard.bindKeyPress(lastKey, function() smartWalk(lastDir) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
end
lastDir = dir
end
function updateStretchShrink()