void Minimap::setMap(Map *map) { // Adapt the image if (mMapImage) { mMapImage->decRef(); mMapImage = 0; } if (map) { mMap = map; std::string tempname = "graphics/minimaps/" + map->getFilename() + ".png"; ResourceManager *resman = ResourceManager::getInstance(); std::string minimapName = map->getProperty("minimap"); if (minimapName.empty() && resman->exists(tempname)) minimapName = tempname; if (!minimapName.empty()) mMapImage = resman->getImage(minimapName); } if (mMapImage) { mWidthProportion = (float) mMapImage->getWidth() / map->getWidth(); mHeightProportion = (float) mMapImage->getHeight() / map->getHeight(); setVisible(true); } else { setVisible(true); } }
void Minimap::setMap(Map *map) { // Set the title for the Minimap std::string caption = ""; std::string minimapName; if (map) caption = map->getName(); if (caption.empty()) caption = _("Map"); minimap->setCaption(caption); // Adapt the image if (mMapImage) { mMapImage->decRef(); mMapImage = 0; } if (map) { std::string tempname = "graphics/minimaps/" + map->getFilename() + ".png"; ResourceManager *resman = ResourceManager::getInstance(); minimapName = map->getProperty("minimap"); if (minimapName.empty() && resman->exists(tempname)) minimapName = tempname; mMapImage = resman->getImage(minimapName); } if (mMapImage) { const int offsetX = 2 * getPadding(); const int offsetY = getTitleBarHeight() + getPadding(); const int titleWidth = getFont()->getWidth(getCaption()) + 15; const int mapWidth = mMapImage->getWidth() < 100 ? mMapImage->getWidth() + offsetX : 100; const int mapHeight = mMapImage->getHeight() < 100 ? mMapImage->getHeight() + offsetY : 100; setMinWidth(mapWidth > titleWidth ? mapWidth : titleWidth); setMinHeight(mapHeight); mWidthProportion = (float) mMapImage->getWidth() / map->getWidth(); mHeightProportion = (float) mMapImage->getHeight() / map->getHeight(); setMaxWidth(mMapImage->getWidth() > titleWidth ? mMapImage->getWidth() + offsetX : titleWidth); setMaxHeight(mMapImage->getHeight() + offsetY); setDefaultSize(getX(), getY(), getWidth(), getHeight()); resetToDefaultSize(); if (mShow) setVisible(true); } else { if (!isSticky()) setVisible(false); } }
bool Viewport::changeMap(const std::string &path) { // Clean up floor items, beings and particles floorItemManager->clear(); beingManager->clear(); // Close the popup menu on map change so that invalid options can't be // executed. closePopupMenu(); // Unset the map of the player so that its particles are cleared before // being deleted in the next step if (player_node) player_node->setMap(NULL); particleEngine->clear(); mMapName = path.substr(0, path.rfind(".")); // Store full map path in global var std::string mapPath = "maps/" + mMapName + ".tmx"; ResourceManager *resman = ResourceManager::getInstance(); if (!resman->exists(mapPath)) mapPath += ".gz"; // Attempt to load the new map Map *newMap = MapReader::readMap(mapPath); if (!newMap) { logger->log("Error while loading %s", mapPath.c_str()); new OkDialog(_("Could not load map"), strprintf(_("Error while loading %s"), mapPath.c_str())); } // Notify the minimap and beingManager about the map change minimap->setMap(newMap); beingManager->setMap(newMap); particleEngine->setMap(newMap); keyboard.refreshActiveKeys(); // Initialize map-based particle effects if (newMap) newMap->initializeParticleEffects(particleEngine); // Start playing new music file when necessary std::string oldMusic = mCurrentMap ? mCurrentMap->getMusicFile() : ""; std::string newMusic = newMap ? newMap->getMusicFile() : ""; if (newMusic != oldMusic) sound.playMusic(newMusic); if (mCurrentMap) destroy(mCurrentMap); setMap(newMap); MessageOut outMsg(CMSG_MAP_LOADED); return true; }