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