/* EntryOperations::convertTextures * Converts multiple TEXTURE1/2 entries to a single ZDoom text-based * TEXTURES entry *******************************************************************/ bool EntryOperations::convertTextures(vector<ArchiveEntry*> entries) { // Check any entries were given if (entries.size() == 0) return false; // Get parent archive of entries Archive* parent = entries[0]->getParent(); // Can't do anything if entry isn't in an archive if (!parent) return false; // Find patch table in parent archive Archive::search_options_t opt; opt.match_type = EntryType::getType("pnames"); ArchiveEntry* pnames = parent->findLast(opt); // Check it exists if (!pnames) return false; // Load patch table PatchTable ptable; ptable.loadPNAMES(pnames); // Read all texture entries to a single list TextureXList tx; for (unsigned a = 0; a < entries.size(); a++) tx.readTEXTUREXData(entries[a], ptable, true); // Convert to extended (TEXTURES) format tx.convertToTEXTURES(); // Create new TEXTURES entry and write to it ArchiveEntry* textures = parent->addNewEntry("TEXTURES", parent->entryIndex(entries[0])); if (textures) { bool ok = tx.writeTEXTURESData(textures); EntryType::detectEntryType(textures); textures->setExtensionByType(); return ok; } else return false; }
/* GfxEntryPanel::extractAll * Extract all sub-images as individual PNGs *******************************************************************/ bool GfxEntryPanel::extractAll() { if (getImage()->getSize() < 2) return false; // Remember where we are int imgindex = getImage()->getIndex(); Archive* parent = entry->getParent(); if (parent == NULL) return false; int index = parent->entryIndex(entry, entry->getParentDir()); string name = wxFileName(entry->getName()).GetName(); // Loop through subimages and get things done int pos = 0; for (int i = 0; i < getImage()->getSize(); ++i) { string newname = S_FMT("%s_%i.png", name, i); Misc::loadImageFromEntry(getImage(), entry, i); // Only process images that actually contain some pixels if (getImage()->getWidth() && getImage()->getHeight()) { ArchiveEntry* newimg = parent->addNewEntry(newname, index+pos+1, entry->getParentDir()); if (newimg == NULL) return false; SIFormat::getFormat("png")->saveImage(*getImage(), newimg->getMCData(), gfx_canvas->getPalette()); EntryType::detectEntryType(newimg); pos++; } } // Reload image of where we were Misc::loadImageFromEntry(getImage(), entry, imgindex); return true; }
/* MapEditorConfigDialog::onBtnNewMap * Called when the 'New Map' button is clicked *******************************************************************/ void MapEditorConfigDialog::onBtnNewMap(wxCommandEvent& e) { // Get selected game/port index int sel_port = choice_port_config->GetSelection() - 1; if (sel_port >= 0) sel_port = ports_list[sel_port]; int sel_game = choice_game_config->GetSelection(); // Create new map dialog NewMapDialog dlg(this, sel_game, sel_port, maps); // Show it dlg.SetInitialSize(wxSize(250, -1)); dlg.CenterOnParent(); if (dlg.ShowModal() == wxID_OK) { string mapname = dlg.getMapName(); if (mapname.IsEmpty()) return; // Check the map name isn't already taken for (unsigned a = 0; a < maps.size(); a++) { if (S_CMPNOCASE(maps[a].name, mapname)) { wxMessageBox("Map " + mapname + " already exists", "Error"); return; } } // Get selected map format int map_format = MAP_DOOM; if (dlg.getMapFormat() == "Hexen") map_format = MAP_HEXEN; else if (dlg.getMapFormat() == "UDMF") map_format = MAP_UDMF; else if (dlg.getMapFormat() == "Doom64") map_format = MAP_DOOM64; // Check archive type if (archive->getType() == ARCHIVE_WAD) { // Create new (empty) map at the end of the wad ArchiveEntry* head = archive->addNewEntry(mapname); ArchiveEntry* end = NULL; if (map_format == MAP_UDMF) { // UDMF archive->addNewEntry("TEXTMAP"); end = archive->addNewEntry("ENDMAP"); } else { // Doom(64) / Hexen archive->addNewEntry("THINGS"); archive->addNewEntry("LINEDEFS"); archive->addNewEntry("SIDEDEFS"); archive->addNewEntry("VERTEXES"); end = archive->addNewEntry("SECTORS"); // Hexen if (map_format == MAP_HEXEN) end = archive->addNewEntry("BEHAVIOR"); } // Refresh map list populateMapList(); list_maps->selectItem(list_maps->GetItemCount()-1); } else if (archive->getType() == ARCHIVE_ZIP || archive->getType() == ARCHIVE_FOLDER) { // Create new wad archive for the map Archive* wad = new WadArchive(); // Create new (empty) map at the end of the wad ArchiveEntry* head = wad->addNewEntry(mapname); ArchiveEntry* end = NULL; if (map_format == MAP_UDMF) { // UDMF wad->addNewEntry("TEXTMAP"); end = wad->addNewEntry("ENDMAP"); } else { // Doom(64) / Hexen wad->addNewEntry("THINGS"); wad->addNewEntry("LINEDEFS"); wad->addNewEntry("SIDEDEFS"); wad->addNewEntry("VERTEXES"); end = wad->addNewEntry("SECTORS"); // Hexen if (map_format == MAP_HEXEN) end = wad->addNewEntry("BEHAVIOR"); // Doom 64 else if (map_format == MAP_DOOM64) { wad->addNewEntry("LIGHTS"); end = wad->addNewEntry("MACROS"); } } // Add new map entry to the maps dir //ArchiveEntry* mapentry = archive->addNewEntry(mapname+".wad", 0xFFFFFFFF, archive->createDir("maps")); ArchiveEntry* mapentry = archive->addNewEntry(mapname + ".wad", "maps"); MemChunk mc; wad->write(mc); mapentry->importMemChunk(mc); // Clean up delete wad; // Refresh map list populateMapList(); list_maps->selectItem(list_maps->GetItemCount()-1); } } }