diff options
Diffstat (limited to 'src/net/tmwa/gamehandler.cpp')
-rw-r--r-- | src/net/tmwa/gamehandler.cpp | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index 435d5d30..6430b476 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -22,12 +22,11 @@ #include "net/tmwa/gamehandler.h" #include "client.h" +#include "event.h" #include "game.h" #include "localplayer.h" #include "log.h" -#include "gui/widgets/chattab.h" - #include "gui/okdialog.h" #include "net/messagein.h" @@ -50,7 +49,6 @@ GameHandler::GameHandler() { static const Uint16 _messages[] = { SMSG_MAP_LOGIN_SUCCESS, - SMSG_SERVER_PING, SMSG_WHO_ANSWER, SMSG_CHAR_SWITCH_RESPONSE, SMSG_MAP_QUIT_RESPONSE, @@ -58,6 +56,8 @@ GameHandler::GameHandler() }; handledMessages = _messages; gameHandler = this; + + listen(Event::GameChannel); } void GameHandler::handleMessage(Net::MessageIn &msg) @@ -75,17 +75,12 @@ void GameHandler::handleMessage(Net::MessageIn &msg) x, y, direction); // Switch now or we'll have problems Client::setState(STATE_GAME); - player_node->setTileCoords(x, y); + // Stores the position until the map is loaded. + mTileX = x; mTileY = y; } break; - case SMSG_SERVER_PING: - // We ignore this for now - // int tick = msg.readInt32() - break; - case SMSG_WHO_ANSWER: - localChatTab->chatLog(strprintf(_("Online users: %d"), - msg.readInt32()), BY_SERVER); + SERVER_NOTICE(strprintf(_("Online users: %d"), msg.readInt32())) break; case SMSG_CHAR_SWITCH_RESPONSE: @@ -105,6 +100,31 @@ void GameHandler::handleMessage(Net::MessageIn &msg) } } +void GameHandler::event(Event::Channel channel, const Event &event) +{ + if (channel == Event::GameChannel) + { + if (event.getType() == Event::EnginesInitialized) + { + Game *game = Game::instance(); + game->changeMap(mMap); + Map *map = game->getCurrentMap(); + const int tileWidth = map->getTileWidth(); + const int tileHeight = map->getTileHeight(); + if (mTileX && mTileY) + { + player_node->setPosition(Vector(mTileX * tileWidth + tileWidth / 2, + mTileY * tileHeight + tileHeight / 2)); + mTileX = mTileY = 0; + } + } + else if (event.getType() == Event::MapLoaded) + { + MessageOut outMsg(CMSG_MAP_LOADED); + } + } +} + void GameHandler::connect() { mNetwork->connect(mapServer); @@ -142,16 +162,6 @@ void GameHandler::disconnect() mNetwork->disconnect(); } -void GameHandler::inGame() -{ - Game::instance()->changeMap(mMap); -} - -void GameHandler::mapLoaded(const std::string &mapName) -{ - MessageOut outMsg(CMSG_MAP_LOADED); -} - void GameHandler::who() { } @@ -161,12 +171,6 @@ void GameHandler::quit() MessageOut outMsg(CMSG_CLIENT_QUIT); } -void GameHandler::ping(int tick) -{ - MessageOut msg(CMSG_CLIENT_PING); - msg.writeInt32(tick); -} - void GameHandler::setMap(const std::string map) { mMap = map.substr(0, map.rfind(".")); |