Fixed controls & hotkeys interferring; smoother logouts

This commit is contained in:
Kayne Ruse
2014-12-27 19:25:49 +11:00
parent ee0b7884a8
commit f6e90d7e39
+17 -15
View File
@@ -137,10 +137,8 @@ void InWorld::Update() {
//check the connection (heartbeat)
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
if (attemptedBeats > 2) {
//two-step logout
SendLogoutRequest();
//escape to the disconnect screen
SendDisconnectRequest();
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
@@ -244,7 +242,6 @@ void InWorld::Render(SDL_Surface* const screen) {
void InWorld::QuitEvent() {
//two-step logout
SendLogoutRequest();
SendDisconnectRequest();
SetNextScene(SceneList::QUIT);
}
@@ -272,9 +269,9 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
//hotkeys
switch(key.keysym.sym) {
case SDLK_ESCAPE:
//the escape key should actually control menus and stuff
//TODO: the escape key should actually control menus and stuff
SendLogoutRequest();
break;
return;
}
//character movement
@@ -295,6 +292,9 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
case SDLK_d:
motion.x += CHARACTER_WALKING_SPEED;
break;
default:
//DOCS: prevents wrong keys screwing with character movement
return;
}
//handle diagonals
if (motion.x != 0 && motion.y != 0) {
@@ -325,6 +325,9 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
case SDLK_d:
motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED);
break;
default:
//DOCS: prevents wrong keys screwing with character movement
return;
}
//BUGFIX: reset cardinal direction speed on key release
if (motion.x > 0) {
@@ -469,30 +472,29 @@ void InWorld::SendShutdownRequest() {
}
void InWorld::HandleLogoutResponse(ClientPacket* const argPacket) {
if (localCharacter) {
characterMap.erase(characterIndex);
localCharacter = nullptr;
}
accountIndex = -1;
characterIndex = -1;
//reset the camera
camera.x = camera.y = 0;
camera.marginX = camera.marginY = 0;
//because, why not? I guess...
SendDisconnectRequest();
}
void InWorld::HandleDisconnectResponse(ClientPacket* const argPacket) {
HandleLogoutResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out";
}
void InWorld::HandleDisconnectForced(ClientPacket* const argPacket) {
//clear the local data
accountIndex = -1;
characterIndex = -1;
//reset the camera
camera.x = camera .y = 0;
camera.marginX = camera.marginY = 0;
HandleDisconnectResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
}