Changes to autowalk position on different floors, move its functions to game interface

This commit is contained in:
Henrique Santiago 2012-07-05 02:40:21 -03:00
parent 2c6b83b476
commit 0b98dca50f
3 changed files with 40 additions and 25 deletions

View File

@ -304,14 +304,9 @@ function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatu
menu:display(menuPosition) menu:display(menuPosition)
end end
function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing) function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, multiUseThing)
local keyboardModifiers = g_keyboard.getModifiers() local keyboardModifiers = g_keyboard.getModifiers()
if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
-- todo auto walk
return true
end
if not Options.getOption('classicControl') then if not Options.getOption('classicControl') then
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing) GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
@ -341,7 +336,7 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l
return true return true
end end
else else
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then
if multiUseThing:asCreature() then if multiUseThing:asCreature() then
g_game.attack(multiUseThing:asCreature()) g_game.attack(multiUseThing:asCreature())
return true return true
@ -363,6 +358,9 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
g_game.look(lookThing) g_game.look(lookThing)
return true return true
elseif lookThing and ((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or (g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
g_game.look(lookThing)
return true
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing) GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true return true
@ -372,6 +370,16 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l
end end
end end
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), autoWalkPos, 255)
if #dirs == 0 then
TextMessage.displayStatus(tr('There is no way.'))
return true
end
g_game.autoWalk(dirs)
return true
end
return false return false
end end

View File

@ -47,6 +47,10 @@ function UIGameMap:onDrop(widget, mousePos)
return true return true
end end
function UIGameMap:onMousePress()
self.cancelNextRelease = false
end
function UIGameMap:onMouseRelease(mousePosition, mouseButton) function UIGameMap:onMouseRelease(mousePosition, mouseButton)
if self.cancelNextRelease then if self.cancelNextRelease then
self.cancelNextRelease = false self.cancelNextRelease = false
@ -56,23 +60,24 @@ function UIGameMap:onMouseRelease(mousePosition, mouseButton)
local tile = self:getTile(mousePosition) local tile = self:getTile(mousePosition)
if tile == nil then return false end if tile == nil then return false end
if Options.getOption('classicControl') and local localPlayerPos = g_game.getLocalPlayer():getPosition()
((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or local autoWalkPos = tile:getPosition()
(g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then if autoWalkPos.z ~= localPlayerPos.z then
local tile = self:getTile(mousePosition) local dz = autoWalkPos.z - localPlayerPos.z
g_game.look(tile:getTopLookThing()) autoWalkPos.x = autoWalkPos.x + dz
self.cancelNextRelease = true autoWalkPos.y = autoWalkPos.y + dz
return true autoWalkPos.z = localPlayerPos.z
elseif GameInterface.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then
return true
elseif mouseButton == MouseLeftButton and self:isPressed() then
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), tile:getPosition(), 255)
if #dirs == 0 then
TextMessage.displayStatus(tr('There is no way.'))
return true
end
g_game.autoWalk(dirs)
return true
end end
return false
local lookThing = tile:getTopLookThing()
local useThing = tile:getTopUseThing()
local creatureThing = tile:getTopCreature()
local multiUseThing = tile:getTopMultiUseThing()
local ret = GameInterface.processMouseAction(mousePosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, multiUseThing)
if ret then
self.cancelNextRelease = true
end
return ret
end end

View File

@ -256,6 +256,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Thing>("getParentContainer", &Thing::getParentContainer); g_lua.bindClassMemberFunction<Thing>("getParentContainer", &Thing::getParentContainer);
g_lua.registerClass<Creature, Thing>(); g_lua.registerClass<Creature, Thing>();
g_lua.bindClassStaticFunction<Creature>("create", []{ return CreaturePtr(new Creature); });
g_lua.bindClassMemberFunction<Creature>("getId", &Creature::getId); g_lua.bindClassMemberFunction<Creature>("getId", &Creature::getId);
g_lua.bindClassMemberFunction<Creature>("getName", &Creature::getName); g_lua.bindClassMemberFunction<Creature>("getName", &Creature::getName);
g_lua.bindClassMemberFunction<Creature>("getHealthPercent", &Creature::getHealthPercent); g_lua.bindClassMemberFunction<Creature>("getHealthPercent", &Creature::getHealthPercent);
@ -264,6 +265,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Creature>("getEmblem", &Creature::getEmblem); g_lua.bindClassMemberFunction<Creature>("getEmblem", &Creature::getEmblem);
g_lua.bindClassMemberFunction<Creature>("setOutfit", &Creature::setOutfit); g_lua.bindClassMemberFunction<Creature>("setOutfit", &Creature::setOutfit);
g_lua.bindClassMemberFunction<Creature>("getOutfit", &Creature::getOutfit); g_lua.bindClassMemberFunction<Creature>("getOutfit", &Creature::getOutfit);
g_lua.bindClassMemberFunction<Creature>("setDirection", &Creature::setDirection);
g_lua.bindClassMemberFunction<Creature>("setSkullTexture", &Creature::setSkullTexture); g_lua.bindClassMemberFunction<Creature>("setSkullTexture", &Creature::setSkullTexture);
g_lua.bindClassMemberFunction<Creature>("setShieldTexture", &Creature::setShieldTexture); g_lua.bindClassMemberFunction<Creature>("setShieldTexture", &Creature::setShieldTexture);
g_lua.bindClassMemberFunction<Creature>("setEmblemTexture", &Creature::setEmblemTexture); g_lua.bindClassMemberFunction<Creature>("setEmblemTexture", &Creature::setEmblemTexture);