Fixed up movement controls again and fixed a typo.
* You can change direction while already moving (There could be a better way for walking control, but this works fine for now)
This commit is contained in:
parent
caf86a9fc6
commit
a2ddb472f5
|
@ -1,4 +1,4 @@
|
||||||
WALK_AUTO_REPEAT_DELAY = 150
|
WALK_AUTO_REPEAT_DELAY = 180
|
||||||
WALK_STEPS_RETRY = 10
|
WALK_STEPS_RETRY = 10
|
||||||
|
|
||||||
gameRootPanel = nil
|
gameRootPanel = nil
|
||||||
|
@ -13,7 +13,8 @@ logoutWindow = nil
|
||||||
exitWindow = nil
|
exitWindow = nil
|
||||||
bottomSplitter = nil
|
bottomSplitter = nil
|
||||||
|
|
||||||
lastWalkDir = nil
|
lastDir = nil
|
||||||
|
walkEvent = nil
|
||||||
arrowKeys = {
|
arrowKeys = {
|
||||||
[North] = 'Up',
|
[North] = 'Up',
|
||||||
[South] = 'Down',
|
[South] = 'Down',
|
||||||
|
@ -64,6 +65,11 @@ function bindKeys()
|
||||||
g_keyboard.bindKeyPress('Down', function() smartWalk(South) 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.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.bindKeyPress('Numpad8', function() smartWalk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
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('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('Numpad6', function() smartWalk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||||
|
@ -199,9 +205,17 @@ function tryLogout()
|
||||||
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
|
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function changeWalkDir(dir)
|
||||||
|
local player = g_game.getLocalPlayer()
|
||||||
|
local lastWalkDir = g_game.getLastWalkDir()
|
||||||
|
if lastWalkDir ~= dir and player:isWalking() then
|
||||||
|
smartWalk(dir)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function smartWalk(defaultDir)
|
function smartWalk(defaultDir)
|
||||||
local rebindKey = false
|
local rebindKey = false
|
||||||
local lastKey = arrowKeys[lastWalkDir]
|
local lastKey = arrowKeys[lastDir]
|
||||||
|
|
||||||
-- choose the new direction
|
-- choose the new direction
|
||||||
if not g_keyboard.isKeyPressed(arrowKeys[defaultDir]) then
|
if not g_keyboard.isKeyPressed(arrowKeys[defaultDir]) then
|
||||||
|
@ -219,7 +233,7 @@ function smartWalk(defaultDir)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- key is still pressed from previous walk event
|
-- key is still pressed from previous walk event
|
||||||
if lastWalkDir and lastWalkDir ~= defaultDir and g_keyboard.isKeyPressed(lastKey) then
|
if lastDir and lastDir ~= defaultDir and g_keyboard.isKeyPressed(lastKey) then
|
||||||
if g_keyboard.isKeySetPressed(arrowKeys) then
|
if g_keyboard.isKeySetPressed(arrowKeys) then
|
||||||
g_keyboard.unbindKeyPress(lastKey, gameRootPanel)
|
g_keyboard.unbindKeyPress(lastKey, gameRootPanel)
|
||||||
rebindKey = true
|
rebindKey = true
|
||||||
|
@ -250,9 +264,9 @@ function smartWalk(defaultDir)
|
||||||
end
|
end
|
||||||
|
|
||||||
if rebindKey then
|
if rebindKey then
|
||||||
g_keyboard.bindKeyPress(lastKey, function() smartWalk(lastWalkDir) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
g_keyboard.bindKeyPress(lastKey, function() smartWalk(lastDir) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||||
end
|
end
|
||||||
lastWalkDir = dir
|
lastDir = dir
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateStretchShrink()
|
function updateStretchShrink()
|
||||||
|
|
|
@ -318,7 +318,6 @@ void Creature::walk(const Position& oldPos, const Position& newPos)
|
||||||
m_walkFinishAnimEvent = nullptr;
|
m_walkFinishAnimEvent = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// no direction need to be changed when the walk ends
|
// no direction need to be changed when the walk ends
|
||||||
m_walkTurnDirection = Otc::InvalidDirection;
|
m_walkTurnDirection = Otc::InvalidDirection;
|
||||||
|
|
||||||
|
|
|
@ -538,8 +538,7 @@ bool Game::walk(Otc::Direction direction)
|
||||||
if(m_lastWalkDir != direction) {
|
if(m_lastWalkDir != direction) {
|
||||||
// must add a new walk event
|
// must add a new walk event
|
||||||
float ticks = m_localPlayer->getStepTicksLeft();
|
float ticks = m_localPlayer->getStepTicksLeft();
|
||||||
if(ticks < 0)
|
if(ticks < 0) { ticks = 0; }
|
||||||
ticks = 0;
|
|
||||||
|
|
||||||
if(m_walkEvent) {
|
if(m_walkEvent) {
|
||||||
m_walkEvent->cancel();
|
m_walkEvent->cancel();
|
||||||
|
|
|
@ -293,6 +293,7 @@ public:
|
||||||
std::string getWorldName() { return m_worldName; }
|
std::string getWorldName() { return m_worldName; }
|
||||||
std::vector<uint8> getGMActions() { return m_gmActions; }
|
std::vector<uint8> getGMActions() { return m_gmActions; }
|
||||||
bool isGM() { return m_gmActions.size() > 0; }
|
bool isGM() { return m_gmActions.size() > 0; }
|
||||||
|
Otc::Direction getLastWalkDir() { return m_lastWalkDir; }
|
||||||
|
|
||||||
std::string formatCreatureName(const std::string &name);
|
std::string formatCreatureName(const std::string &name);
|
||||||
int findEmptyContainerId();
|
int findEmptyContainerId();
|
||||||
|
|
|
@ -95,7 +95,7 @@ void LocalPlayer::walk(const Position& oldPos, const Position& newPos)
|
||||||
// a prewalk was going on
|
// a prewalk was going on
|
||||||
if(m_preWalking) {
|
if(m_preWalking) {
|
||||||
if(m_waitingWalkPong) {
|
if(m_waitingWalkPong) {
|
||||||
if(newPos == m_lastPrewalkDestionation)
|
if(newPos == m_lastPrewalkDestination)
|
||||||
m_lastWalkPing = m_walkPingTimer.ticksElapsed();
|
m_lastWalkPing = m_walkPingTimer.ticksElapsed();
|
||||||
|
|
||||||
m_waitingWalkPong = false;
|
m_waitingWalkPong = false;
|
||||||
|
@ -105,7 +105,7 @@ void LocalPlayer::walk(const Position& oldPos, const Position& newPos)
|
||||||
m_preWalking = false;
|
m_preWalking = false;
|
||||||
m_lastPrewalkDone = true;
|
m_lastPrewalkDone = true;
|
||||||
// if is to the last prewalk destination, updates the walk preserving the animation
|
// if is to the last prewalk destination, updates the walk preserving the animation
|
||||||
if(newPos == m_lastPrewalkDestionation) {
|
if(newPos == m_lastPrewalkDestination) {
|
||||||
updateWalk();
|
updateWalk();
|
||||||
// was to another direction, replace the walk
|
// was to another direction, replace the walk
|
||||||
} else
|
} else
|
||||||
|
@ -127,7 +127,7 @@ void LocalPlayer::preWalk(Otc::Direction direction)
|
||||||
Position newPos = m_position.translatedToDirection(direction);
|
Position newPos = m_position.translatedToDirection(direction);
|
||||||
|
|
||||||
// avoid reanimating prewalks
|
// avoid reanimating prewalks
|
||||||
if(m_preWalking && m_lastPrewalkDestionation == newPos)
|
if(m_preWalking && m_lastPrewalkDestination == newPos)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_waitingWalkPong = false;
|
m_waitingWalkPong = false;
|
||||||
|
@ -143,7 +143,7 @@ void LocalPlayer::preWalk(Otc::Direction direction)
|
||||||
|
|
||||||
// start walking to direction
|
// start walking to direction
|
||||||
m_lastPrewalkDone = false;
|
m_lastPrewalkDone = false;
|
||||||
m_lastPrewalkDestionation = newPos;
|
m_lastPrewalkDestination = newPos;
|
||||||
Creature::walk(m_position, newPos);
|
Creature::walk(m_position, newPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ void LocalPlayer::stopWalk()
|
||||||
Creature::stopWalk(); // will call terminateWalk
|
Creature::stopWalk(); // will call terminateWalk
|
||||||
|
|
||||||
m_lastPrewalkDone = true;
|
m_lastPrewalkDone = true;
|
||||||
m_lastPrewalkDestionation = Position();
|
m_lastPrewalkDestination = Position();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer::updateWalkOffset(int totalPixelsWalked)
|
void LocalPlayer::updateWalkOffset(int totalPixelsWalked)
|
||||||
|
|
|
@ -119,7 +119,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
// walk related
|
// walk related
|
||||||
Timer m_walkPingTimer;
|
Timer m_walkPingTimer;
|
||||||
Position m_lastPrewalkDestionation;
|
Position m_lastPrewalkDestination;
|
||||||
Position m_autoWalkDestination;
|
Position m_autoWalkDestination;
|
||||||
Position m_lastAutoWalkPosition;
|
Position m_lastAutoWalkPosition;
|
||||||
ScheduledEventPtr m_autoWalkEndEvent;
|
ScheduledEventPtr m_autoWalkEndEvent;
|
||||||
|
|
|
@ -242,6 +242,7 @@ void Client::registerLuaFunctions()
|
||||||
g_lua.bindSingletonFunction("g_game", "disableFeature", &Game::disableFeature, &g_game);
|
g_lua.bindSingletonFunction("g_game", "disableFeature", &Game::disableFeature, &g_game);
|
||||||
g_lua.bindSingletonFunction("g_game", "isGM", &Game::isGM, &g_game);
|
g_lua.bindSingletonFunction("g_game", "isGM", &Game::isGM, &g_game);
|
||||||
g_lua.bindSingletonFunction("g_game", "answerModalDialog", &Game::answerModalDialog, &g_game);
|
g_lua.bindSingletonFunction("g_game", "answerModalDialog", &Game::answerModalDialog, &g_game);
|
||||||
|
g_lua.bindSingletonFunction("g_game", "getLastWalkDir", &Game::getLastWalkDir, &g_game);
|
||||||
|
|
||||||
g_lua.registerSingletonClass("g_shaders");
|
g_lua.registerSingletonClass("g_shaders");
|
||||||
g_lua.bindSingletonFunction("g_shaders", "createShader", &ShaderManager::createShader, &g_shaders);
|
g_lua.bindSingletonFunction("g_shaders", "createShader", &ShaderManager::createShader, &g_shaders);
|
||||||
|
|
Loading…
Reference in New Issue