summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-25 23:04:58 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-25 23:04:58 +0200
commita36909f5c3408153c9b5f9477adde9b27d8c7482 (patch)
tree0acd7721cd2bb2b27878d20027d0510458581515
parent4e18e7619e9a8c909dea3374a2a7aa39befe0c16 (diff)
downloadmana-client-a36909f5c3408153c9b5f9477adde9b27d8c7482.tar.gz
mana-client-a36909f5c3408153c9b5f9477adde9b27d8c7482.tar.bz2
mana-client-a36909f5c3408153c9b5f9477adde9b27d8c7482.tar.xz
mana-client-a36909f5c3408153c9b5f9477adde9b27d8c7482.zip
Handle map not found gracefully
Instead of shutting down, the client will now draw a gray background. This allows the player to still contact a GM in order to be helped out of the situation. It also helps me warp out of the non-existing map I accidentally warped myself onto. ;)
-rw-r--r--src/engine.cpp20
-rw-r--r--src/gui/minimap.cpp19
-rw-r--r--src/gui/viewport.cpp51
-rw-r--r--src/map.cpp13
-rw-r--r--src/map.h11
-rw-r--r--src/net/ea/maphandler.cpp1
-rw-r--r--src/net/tmwserv/maphandler.cpp1
7 files changed, 72 insertions, 44 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 1bd6c30f..d33607ec 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -31,6 +31,7 @@
#include "gui/gui.h"
#include "gui/minimap.h"
+#include "gui/okdialog.h"
#include "gui/viewport.h"
#include "net/maphandler.h"
@@ -40,6 +41,7 @@
#include "resources/monsterdb.h"
#include "resources/resourcemanager.h"
+#include "utils/gettext.h"
#include "utils/stringutils.h"
Engine::Engine():
@@ -81,7 +83,11 @@ bool Engine::changeMap(const std::string &mapPath)
Map *newMap = MapReader::readMap(map_path);
if (!newMap)
- logger->error("Could not find map file");
+ {
+ logger->log("Error while loading %s", map_path.c_str());
+ new OkDialog(_("Could not load map"),
+ strprintf(_("Error while loading %s"), map_path.c_str()));
+ }
// Notify the minimap and beingManager about the map change
minimap->setMap(newMap);
@@ -90,16 +96,12 @@ bool Engine::changeMap(const std::string &mapPath)
viewport->setMap(newMap);
// Initialize map-based particle effects
- newMap->initializeParticleEffects(particleEngine);
+ if (newMap)
+ newMap->initializeParticleEffects(particleEngine);
// Start playing new music file when necessary
- std::string oldMusic = "";
-
- if (mCurrentMap)
- oldMusic = mCurrentMap->getProperty("music");
-
- std::string newMusic = newMap->getProperty("music");
-
+ std::string oldMusic = mCurrentMap ? mCurrentMap->getMusicFile() : "";
+ std::string newMusic = newMap ? newMap->getMusicFile() : "";
if (newMusic != oldMusic)
sound.playMusic(newMusic);
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index a5bdc59d..d1c99b84 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -77,21 +77,26 @@ void Minimap::setMap(Map *map)
// Set the title for the Minimap
std::string caption;
- if (map->hasProperty("name"))
- caption = map->getProperty("name");
- else if (map->hasProperty("mapname"))
- caption = map->getProperty("mapname");
- else
+ if (map)
+ caption = map->getName();
+
+ if (caption.empty())
caption = _("Map");
minimap->setCaption(caption);
// Adapt the image
if (mMapImage)
+ {
mMapImage->decRef();
+ mMapImage = 0;
+ }
- ResourceManager *resman = ResourceManager::getInstance();
- mMapImage = resman->getImage(map->getProperty("minimap"));
+ if (map)
+ {
+ ResourceManager *resman = ResourceManager::getInstance();
+ mMapImage = resman->getImage(map->getProperty("minimap"));
+ }
if (mMapImage)
{
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 2c3f4007..d954b99f 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -19,26 +19,28 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "ministatus.h"
-#include "popupmenu.h"
-#include "viewport.h"
-
-#include "../beingmanager.h"
-#include "../configuration.h"
-#include "../flooritemmanager.h"
-#include "../game.h"
-#include "../graphics.h"
-#include "../keyboardconfig.h"
-#include "../localplayer.h"
-#include "../map.h"
-#include "../monster.h"
-#include "../npc.h"
-#include "../textmanager.h"
-
-#include "../resources/monsterinfo.h"
-#include "../resources/resourcemanager.h"
-
-#include "../utils/stringutils.h"
+#include "gui/viewport.h"
+
+#include "gui/gui.h"
+#include "gui/ministatus.h"
+#include "gui/popupmenu.h"
+
+#include "beingmanager.h"
+#include "configuration.h"
+#include "flooritemmanager.h"
+#include "game.h"
+#include "graphics.h"
+#include "keyboardconfig.h"
+#include "localplayer.h"
+#include "map.h"
+#include "monster.h"
+#include "npc.h"
+#include "textmanager.h"
+
+#include "resources/monsterinfo.h"
+#include "resources/resourcemanager.h"
+
+#include "utils/stringutils.h"
extern volatile int tick_time;
@@ -94,7 +96,12 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
static int lastTick = tick_time;
if (!mMap || !player_node)
+ {
+ gcnGraphics->setColor(gcn::Color(64, 64, 64));
+ gcnGraphics->fillRectangle(
+ gcn::Rectangle(0, 0, getWidth(), getHeight()));
return;
+ }
Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
@@ -233,11 +240,11 @@ void Viewport::logic()
{
WindowContainer::logic();
+ Uint8 button = SDL_GetMouseState(&mMouseX, &mMouseY);
+
if (!mMap || !player_node)
return;
- Uint8 button = SDL_GetMouseState(&mMouseX, &mMouseY);
-
if (mPlayerFollowMouse && button & SDL_BUTTON(1) &&
#ifdef TMWSERV_SUPPORT
get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay)
diff --git a/src/map.cpp b/src/map.cpp
index 4d867865..f0a5eae0 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -460,6 +460,19 @@ void Map::removeSprite(SpriteIterator iterator)
mSprites.erase(iterator);
}
+const std::string &Map::getMusicFile() const
+{
+ return getProperty("music");
+}
+
+const std::string &Map::getName() const
+{
+ if (hasProperty("name"))
+ return getProperty("name");
+
+ return getProperty("mapname");
+}
+
static int const basicCost = 100;
Path Map::findPath(int startX, int startY, int destX, int destY, unsigned char walkmask, int maxCost)
diff --git a/src/map.h b/src/map.h
index ba6cf24e..0432dc34 100644
--- a/src/map.h
+++ b/src/map.h
@@ -201,7 +201,7 @@ class Map : public Properties
/**
* Finds the tile set that a tile with the given global id is part of.
*/
- Tileset* getTilesetWithGid(int gid) const;
+ Tileset *getTilesetWithGid(int gid) const;
/**
* Get tile reference.
@@ -209,7 +209,7 @@ class Map : public Properties
MetaTile *getMetaTile(int x, int y) const;
/**
- * Marks a tile as occupied
+ * Marks a tile as occupied.
*/
void blockTile(int x, int y, BlockType type);
@@ -220,12 +220,12 @@ class Map : public Properties
bool getWalk(int x, int y, char walkmask = BLOCKMASK_WALL) const;
/**
- * Returns the width of this map.
+ * Returns the width of this map in tiles.
*/
int getWidth() const { return mWidth; }
/**
- * Returns the height of this map.
+ * Returns the height of this map in tiles.
*/
int getHeight() const { return mHeight; }
@@ -239,6 +239,9 @@ class Map : public Properties
*/
int getTileHeight() const { return mTileHeight; }
+ const std::string &getMusicFile() const;
+ const std::string &getName() const;
+
/**
* Find a path from one location to the next.
*/
diff --git a/src/net/ea/maphandler.cpp b/src/net/ea/maphandler.cpp
index c7ff0ec7..6f8a9827 100644
--- a/src/net/ea/maphandler.cpp
+++ b/src/net/ea/maphandler.cpp
@@ -103,7 +103,6 @@ void MapHandler::mapLoaded(const std::string &mapName)
void MapHandler::who()
{
-
}
void MapHandler::quit()
diff --git a/src/net/tmwserv/maphandler.cpp b/src/net/tmwserv/maphandler.cpp
index 400188bf..d64ea13b 100644
--- a/src/net/tmwserv/maphandler.cpp
+++ b/src/net/tmwserv/maphandler.cpp
@@ -36,7 +36,6 @@ MapHandler::MapHandler()
void MapHandler::handleMessage(MessageIn &msg)
{
-
}
void MapHandler::connect(LoginData *loginData)