Skip to content

Commit

Permalink
ALL: Fix the camera move
Browse files Browse the repository at this point in the history
The camera should not move when the console is open. Since text input
and pressed key are now distinct events, we receive two events when a
key is actually pressed. So we have to test if text input is active.

One feature brings by SDL2 is the ability to recognize a key by is
position and not is name, that is to say we can ask the key next to
tab whatever the layout is (like qwerty, azerty or dvorak).
  • Loading branch information
Supermanu authored and DrMcCoy committed Dec 14, 2013
1 parent 03602a6 commit 083d230
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/engines/aurora/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ void ConsoleWindow::showPrompt() {
_input->show();

GfxMan.unlockFrame();
SDL_StartTextInput();
}

void ConsoleWindow::hidePrompt() {
Expand All @@ -177,7 +176,6 @@ void ConsoleWindow::hidePrompt() {
_input->hide();

GfxMan.unlockFrame();
SDL_StopTextInput();
}

bool ConsoleWindow::isIn(float x, float y) const {
Expand Down Expand Up @@ -714,6 +712,7 @@ void Console::show() {

updateCaches();
showCallback();
SDL_StartTextInput();
}

void Console::hide() {
Expand All @@ -722,6 +721,7 @@ void Console::hide() {

_console->hide();
_visible = false;
SDL_StopTextInput();
}

bool Console::isVisible() const {
Expand Down
17 changes: 9 additions & 8 deletions src/engines/kotor/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ void Module::handleEvents() {
}

// Camera
if (handleCamera(event))
continue;
if (SDL_IsTextInputActive() == SDL_FALSE)
if (handleCamera(event))
continue;

_area->addEvent(event);
}
Expand All @@ -331,17 +332,17 @@ bool Module::handleCameraKeyboardInput(const Events::Event &e) {
CameraMan.turn( 0.0, 5.0, 0.0);
else if (e.key.keysym.sym == SDLK_LEFT)
CameraMan.turn( 0.0, -5.0, 0.0);
else if (e.key.keysym.sym == SDLK_w)
else if (e.key.keysym.sym == SDL_SCANCODE_W)
CameraMan.move( 0.5);
else if (e.key.keysym.sym == SDLK_s)
else if (e.key.keysym.sym == SDL_SCANCODE_S)
CameraMan.move(-0.5);
else if (e.key.keysym.sym == SDLK_d)
else if (e.key.keysym.sym == SDL_SCANCODE_D)
CameraMan.turn( 0.0, 5.0, 0.0);
else if (e.key.keysym.sym == SDLK_a)
else if (e.key.keysym.sym == SDL_SCANCODE_A)
CameraMan.turn( 0.0, -5.0, 0.0);
else if (e.key.keysym.sym == SDLK_e)
else if (e.key.keysym.sym == SDL_SCANCODE_E)
CameraMan.strafe( 0.5);
else if (e.key.keysym.sym == SDLK_q)
else if (e.key.keysym.sym == SDL_SCANCODE_Q)
CameraMan.strafe(-0.5);
else if (e.key.keysym.sym == SDLK_INSERT)
CameraMan.move(0.0, 0.5, 0.0);
Expand Down
17 changes: 9 additions & 8 deletions src/engines/nwn/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ void Module::handleEvents() {
}

// Camera
if (handleCamera(event))
continue;
if (SDL_IsTextInputActive() == SDL_FALSE)
if (handleCamera(event))
continue;

_ingameGUI->addEvent(event);
_currentArea->addEvent(event);
Expand All @@ -469,17 +470,17 @@ bool Module::handleCamera(const Events::Event &e) {
CameraMan.turn( 0.0, 5.0, 0.0);
else if (e.key.keysym.sym == SDLK_LEFT)
CameraMan.turn( 0.0, -5.0, 0.0);
else if (e.key.keysym.sym == SDLK_w)
else if (e.key.keysym.scancode == SDL_SCANCODE_W)
CameraMan.move( 0.5);
else if (e.key.keysym.sym == SDLK_s)
else if (e.key.keysym.scancode == SDL_SCANCODE_S)
CameraMan.move(-0.5);
else if (e.key.keysym.sym == SDLK_d)
else if (e.key.keysym.scancode == SDL_SCANCODE_D)
CameraMan.turn( 0.0, 5.0, 0.0);
else if (e.key.keysym.sym == SDLK_a)
else if (e.key.keysym.scancode == SDL_SCANCODE_A)
CameraMan.turn( 0.0, -5.0, 0.0);
else if (e.key.keysym.sym == SDLK_e)
else if (e.key.keysym.scancode == SDL_SCANCODE_E)
CameraMan.strafe( 0.5);
else if (e.key.keysym.sym == SDLK_q)
else if (e.key.keysym.scancode == SDL_SCANCODE_Q)
CameraMan.strafe(-0.5);
else if (e.key.keysym.sym == SDLK_INSERT)
CameraMan.move(0.0, 0.5, 0.0);
Expand Down
1 change: 1 addition & 0 deletions src/events/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void EventsManager::init() {
initJoysticks();

std::srand(getTimestamp());
SDL_StopTextInput();
}

void EventsManager::deinit() {
Expand Down

0 comments on commit 083d230

Please sign in to comment.