void Map::onResourceRealise() { if (m_resource == NULL) { return; } if (isUnnamed() || !m_resource->load()) { // Map is unnamed or load failed, reset map resource node to empty m_resource->setNode(NewMapRoot("")); MapFilePtr map = Node_getMapFile(m_resource->getNode()); if (map != NULL) { map->save(); } // Rename the map to "unnamed" in any case to avoid overwriting the failed map setMapName(_(MAP_UNNAMED_STRING)); } // Take the new node and insert it as map root GlobalSceneGraph().setRoot(m_resource->getNode()); // Associate the Scenegaph with the global RenderSystem // This usually takes a while since all editor textures are loaded - display a dialog to inform the user { ui::ScreenUpdateBlocker blocker(_("Processing..."), _("Loading textures..."), true); // force display GlobalSceneGraph().root()->setRenderSystem(boost::dynamic_pointer_cast<RenderSystem>( module::GlobalModuleRegistry().getModule(MODULE_RENDERSYSTEM))); } AutoSaver().clearChanges(); setValid(true); }
void MapModuleNotice::setCountryMapName(const char* name) { MC2String countryStr( countryNamePrefix ); countryStr += (name != NULL ) ? name : "null"; setMapName( countryStr.c_str() ); }
void Map::rename(const std::string& filename) { if (_mapName != filename) { setMapName(filename); SceneChangeNotify(); } else { m_resource->save(); setModified(false); } }
void Map::createNew() { setMapName(_(MAP_UNNAMED_STRING)); m_resource = GlobalMapResourceManager().capture(_mapName); m_resource->addObserver(*this); SceneChangeNotify(); setModified(false); focusViews(Vector3(0,0,0), Vector3(0,0,0)); }
void Map::load(const std::string& filename) { rMessage() << "Loading map from " << filename << "\n"; setMapName(filename); // Reset all layers before loading the file GlobalLayerSystem().reset(); GlobalSelectionSystem().setSelectedAll(false); { ScopeTimer timer("map load"); m_resource = GlobalMapResourceManager().capture(_mapName); // greebo: Add the observer, this usually triggers a onResourceRealise() call. m_resource->addObserver(*this); // Traverse the scenegraph and find the worldspawn MapWorldspawnFinder finder; GlobalSceneGraph().root()->traverse(finder); } rMessage() << "--- LoadMapFile ---\n"; rMessage() << _mapName << "\n"; rMessage() << GlobalCounters().getCounter(counterBrushes).get() << " brushes\n"; rMessage() << GlobalCounters().getCounter(counterPatches).get() << " patches\n"; rMessage() << GlobalCounters().getCounter(counterEntities).get() << " entities\n"; // Move the view to a start position gotoStartPosition(); // Load the stored map positions from the worldspawn entity GlobalMapPosition().loadPositions(); // Remove them, so that the user doesn't get bothered with them GlobalMapPosition().removePositions(); // Disable the region to make sure GlobalRegion().disable(); // Clear the shaderclipboard, the references are most probably invalid now GlobalShaderClipboard().clear(); // Let the filtersystem update the filtered status of all instances GlobalFilterSystem().update(); // Update the layer control dialog ui::LayerControlDialog::Instance().refresh(); // Clear the modified flag setModified(false); }
/** * Gets called whenever the user changes the file selection. * Note: this method must call the setPreviewActive() method on the * FileChooser class to indicate whether the widget is active or not. */ void MapFileChooserPreview::onFileSelectionChanged (const std::string& newFileName, gtkutil::FileChooser& fileChooser) { if (_mapResource) GlobalReferenceCache().release(_mapName); _mapResource = NULL; // Attempt to load file setMapName(newFileName); _preview.initialisePreview(); gtk_widget_queue_draw(_preview); // Always have the preview active fileChooser.setPreviewActive(true); }
bool GameScene::init() { if (!BaseLayer::init()) { return false; } MapUtil::getInstance()->dispose(); auto config = GameConfig::getInstance(); m_fScaleFactor = m_winSize.width/DESIGN_WIDTH; auto scaleH = m_winSize.height/DESIGN_HEIGHT; auto manager = GameManager::getInstance(); if(scaleH>m_fScaleFactor) { manager->setScaleFactor(scaleH); }else{ manager->setScaleFactor(m_fScaleFactor); } /* 加载音频资源 */ soundFiles.push_back(SOUND_SCENE_BG); effectFiles.push_back(SOUND_ITEM_GET_BIG_COIN); effectFiles.push_back(SOUND_ITEM_GET_BOMB); effectFiles.push_back(SOUND_ITEM_GET_LITTLE_COIN); effectFiles.push_back(SOUND_ITEM_GET_POWER); effectFiles.push_back(SOUND_ITEM_GET_SHOE); effectFiles.push_back(SOUND_ITEM_PUT_BOMB); effectFiles.push_back(SOUND_ITEM_USE_HP); effectFiles.push_back(SOUND_MONSTER_BOMBED_DEAD); effectFiles.push_back(SOUND_PLAYER_LOW_HP); effectFiles.push_back(SOUND_INGAME_WIN); effectFiles.push_back(SOUND_INGAME_FAILED); effectFiles.push_back(SOUND_ITEM_BOMB_EXPLODE); effectFiles.push_back(SOUND_ENTER_TONGGUANDIAN); effectFiles.push_back(SOUND_PLAYER_ATTACKED); effectFiles.push_back(SOUND_PLAYER_BIRTH); effectFiles.push_back(SOUND_PLAYER_DEATH); effectFiles.push_back(SOUND_PLAYER_RANDOM); /* 预加载资源 */ textureFiles.push_back("textures/default-hd"); textureFiles.push_back("textures/medium-hd"); textureFiles.push_back("textures/monster_1-hd"); textureFiles.push_back("textures/monster_2-hd"); textureFiles.push_back("textures/scenetex_small-hd"); textureFiles.push_back("textures/scenetex_medium-hd"); textureFiles.push_back("textures/scenetex_big-hd"); textureFiles.push_back("textures/scenetex_big1-hd"); textureFiles.push_back("textures/player_huxi-hd"); textureFiles.push_back("textures/ingame-hd"); textureFiles.push_back("textures/other_1-hd"); textureFiles.push_back("textures/other-hd"); textureFiles.push_back("textures/button-hd"); textureFiles.push_back("textures/item-hd"); textureFiles.push_back("textures/zh_cn/locale_3-hd"); textureFiles.push_back("textures/zh_cn/locale_4-hd"); setMapName(MapUtil::getInstance()->getMapName()); if(isShowTip()) { std::string mapTip = "textures/zh_cn/"+getMapName()+"-hd"; textureFiles.push_back(mapTip); } if (config->getSelectLevel()==12) { textureFiles.push_back(__String::createWithFormat("textures/monster_%s_boss-hd",config->getSelectSceneName().c_str())->getCString()); textureFiles.push_back("textures/monster_bomb-hd"); } char playerTextureName[50]; sprintf(playerTextureName, "textures/player_%s-hd",GameConfig::getInstance()->getSelectRoleName().c_str()); textureFiles.push_back(playerTextureName); manager->setBombNum(1); manager->setBombPower(1); manager->setLvDaiSpeed(Point::ZERO); return true; }
MapModuleNotice::MapModuleNotice(DataBuffer* dataBuffer, int indexdbversion, uint32 mapSet) { m_mapName = NULL; mc2dbg4 << "[MapModuleNotice] - created with DataBuffer*" << endl; int version = 0; if ( indexdbversion > 0 ) { version = dataBuffer->readNextLong(); mc2dbg4 << "[MapModuleNotice] - version = " << version << endl; } else { mc2dbg4 << "[MapModuleNotice] - not reading version" << endl; } m_mapID = dataBuffer->readNextLong(); if (mapSet != MAX_UINT32) m_mapID = MapBits::getMapIDWithMapSet(m_mapID, mapSet); m_countryCode = StringTable::countryCode(dataBuffer->readNextLong()); m_creationTime = dataBuffer->readNextLong(); mc2dbg4 << "Read creationtime for map " << m_mapID << ":" << m_creationTime << endl; uint32 nbrStrings = dataBuffer->readNextShort(); mc2dbg4 << "[MMN]: Number of strings = " << nbrStrings << endl; // Read status for compatibility. uint8 currentStatus = dataBuffer->readNextByte(); mc2dbg8 << "Current status = " << uint32(currentStatus) << endl; uint32 nbrNeighbours = dataBuffer->readNextByte(); // Read in the neighbours. m_neighbourMaps.clear(); for (uint32 i=0; i < nbrNeighbours; i++) { m_neighbourMaps.insert( dataBuffer->readNextLong() ); } // OK to make the name-vector static. No adds possible. // I have removed the name-array so we will not save // the names. // Read the strings for backwards compatibility. mc2dbg4 << "nbr Strings = " << nbrStrings << endl; for (uint32 i = 0; i < nbrStrings; i++) { const char* tmpStr = dataBuffer->readNextString(); mc2dbg4 << "String:" << tmpStr << endl; } m_gfxData = GfxDataFactory::create( *dataBuffer ); // Update the bounding box so that it can be used instead // of the slow getBounding box of the gfxdata. m_gfxData->getMC2BoundingBox(m_bbox); if ( version > 0 ) { // We save the mapname in versions > 0 setMapName( dataBuffer->readNextString() ); } else { m_mapName = StringUtility::newStrDup(""); } mc2dbg4 << "[MMN]: Loaded map name \"" << m_mapName << "\" for map " << m_mapID << endl; }
bool Map::loadMap(std::string mapDirectory) { GUI *guiPtr = Base::instance()->getGuiPtr(); std::ifstream fileStream; fileStream.open(mapDirectory); if(!fileStream.good()) return false; int linei = 0; bool error = false; while(!fileStream.eof()) { linei+=1; std::string line; std::vector<std::string> translatedLine; //line decryption std::getline(fileStream, line); if(line.size()==0) continue; std::string::iterator it; std::string temporaryCommandContainer; bool nameEnclosure = false; for(it=line.begin();it!=line.end();it++) { if(*it == '#') break; else if(*it == '\"') { nameEnclosure = !nameEnclosure; } else if(*it == ' ' && !nameEnclosure) { translatedLine.push_back(temporaryCommandContainer); temporaryCommandContainer = ""; } else { temporaryCommandContainer += *it; } } if(temporaryCommandContainer.size()>0) { translatedLine.push_back(temporaryCommandContainer); temporaryCommandContainer = ""; } if(translatedLine.size()==0) continue; //command decryption if(translatedLine[0]=="nazwa") { if(translatedLine.size()!=2) error=true; else setMapName(translatedLine[1]); } else if(translatedLine[0]=="mapa") { if(translatedLine.size()!=2) error=true; else { al_destroy_bitmap(mapaPtr); mapaPtr = al_load_bitmap(translatedLine[1].c_str()); al_clear_to_color(al_map_rgb(0, 0, 255)); mapaWidth = al_get_bitmap_width(mapaPtr); mapaHeight = al_get_bitmap_height(mapaPtr); } } else if(translatedLine[0]=="kraj") { if(translatedLine.size()!=6) error=true; else addRealm(translatedLine[1],al_map_rgb(std::stoi(translatedLine[2]), std::stoi(translatedLine[3]),std::stoi(translatedLine[4])), translatedLine[5]); } else if(translatedLine[0]=="koniec") { if(translatedLine.size()!=2) error=true; else if(translatedLine[1]=="krajow") fillDiplomaticStates(); else error=true; } else if(translatedLine[0]=="region") { if(translatedLine.size()!=7) error=true; else if(!addRegion(std::stoi(translatedLine[1]),std::stoi(translatedLine[2]), translatedLine[3],translatedLine[4],std::stoi(translatedLine[5]), std::stoi(translatedLine[6]))) error=true; } else if(translatedLine[0]=="droga") { if(translatedLine.size()!=3) error=true; else if(!addRegionsConnector(translatedLine[1], translatedLine[2])) error=true; } else if(translatedLine[0]=="wojna") { if(translatedLine.size()!=3) error=true; else if(!changeDiplomaticState(WAR, translatedLine[1], translatedLine[2])) error=true; } else if(translatedLine[0]=="handel") { if(translatedLine.size()!=3) error=true; else if(!changeDiplomaticState(TRADE_AGREEMENT, translatedLine[1], translatedLine[2])) error=true; } else if(translatedLine[0]=="sojusz") { if(translatedLine.size()!=3) error=true; else if(!changeDiplomaticState(ALLIANCE, translatedLine[1], translatedLine[2])) error=true; } if(error) { guiPtr->showNotification("Błąd w mapie w linii: " + std::to_string(linei)); return false; } } fillRealmsRegions(); return true; }