void MapItemDatabase::ParseItemDefinationFile(string ideFile) { ifstream ideStream(ideFile, ios::in); if (!ideStream.is_open()) throw MyException(ideFile + " is invalid or bad"); IDEReader ide(&ideStream, false); IDEStatement* stmt; while ((stmt = ide.readStatement()) != NULL) { idetype_t type = stmt->getType(); if (type == IDEType::IDETypeStaticObject) { IDEStaticObject* sobj = (IDEStaticObject*)stmt; StaticMapItemDefination* staticItem = new StaticMapItemDefination(); staticItem->SetDFFStem(sobj->getModelName()); staticItem->SetTexDictStem(sobj->getTXDArchiveName().get()); staticItem->SetDrawDistance(sobj->getDrawDistances()[0]); string modelName = sobj->getModelName(); boost::algorithm::to_lower(modelName); if (modelName.find("lod") != string::npos) staticItem->SetLodProperty(true); this->m_items[sobj->getID()] = staticItem; delete sobj; } } }
IDEWidget::IDEWidget(QWidget* parent, const EntityOpenRequest& request) : QWidget(parent), linkBrush(QColor(Qt::blue)) { ui.setupUi(this); File file(request.getAttribute("file").toString().toLocal8Bit().constData()); QVariant lineVariant = request.getAttribute("line"); int selectedLine = lineVariant.isNull() ? -1 : lineVariant.toInt(); QString content; istream* stream = file.openInputStream(); char buffer[4096]; while (!stream->eof()) { stream->read(buffer, sizeof(buffer)-1); buffer[stream->gcount()] = '\0'; content.append(buffer); } delete stream; // Apply some basic syntax highlighting QString richContent("<pre>"); QStringList lines = content.split('\n'); QStringList::iterator it; QString keywords[] = { "end", "objs", "tobj", "anim", "peds", "weap", "cars", "hier", "txdp", "2dfx", "path" }; for (it = lines.begin() ; it != lines.end() ; it++) { QString line = *it; QString cline = line; int cmtIdx = line.indexOf('#'); if (cmtIdx != -1) { line.insert(cmtIdx, "<font color=\"#AAAAAA\">"); line.append("</font>"); cline = line.left(cmtIdx); } for (unsigned int i = 0 ; i < sizeof(keywords)/sizeof(keywords[0]) ; i++) { QString kw = keywords[i]; QRegExp regex(QString("^(\\s*)(%1)(\\s*)$").arg(kw)); cline.replace(regex, "\\1<font color=\"blue\"><b>\\2</b></font>\\3"); } cline.replace(",", "<font color=\"red\">,</font>"); if (cmtIdx != -1) { line.replace(0, cmtIdx, cline); } else { line = cline; } richContent.append(line).append('\n'); } richContent.append("</pre>"); ui.textEdit->setHtml(richContent); // Some kind of bug in QtDesigner incorrectly sets the visibility property of the headers to a rather // random value. ui.staticObjectTable->horizontalHeader()->setVisible(true); ui.timedObjectTable->horizontalHeader()->setVisible(true); ui.animationTable->horizontalHeader()->setVisible(true); ui.pedTable->horizontalHeader()->setVisible(true); ui.weaponTable->horizontalHeader()->setVisible(true); IDEReader ide(file); IDEStatement* stmt; while ((stmt = ide.readStatement()) != NULL) { idetype_t type = stmt->getType(); int line = ide.getLastReadLine(); if (type == IDETypeStaticObject) { IDEStaticObject* sobj = (IDEStaticObject*) stmt; int rc = ui.staticObjectTable->rowCount(); ui.staticObjectTable->setRowCount(rc+1); ui.staticObjectTable->setItem(rc, 0, createItem(QString("%1").arg(sobj->getID()))); ui.staticObjectTable->setItem(rc, 1, createItem(sobj->getModelName().get(), true)); ui.staticObjectTable->setItem(rc, 2, createItem(sobj->getTXDArchiveName().get(), true)); ui.staticObjectTable->setItem(rc, 3, createItem(QString("%1") .arg(sobj->getNumSubObjects()))); ui.staticObjectTable->setItem(rc, 5, createItem(QString("%1") .arg(sobj->getFlags()))); QStringList ddists; for (int32_t i = 0 ; i < sobj->getNumSubObjects() ; i++) { ddists << QString("%1").arg(sobj->getDrawDistances()[i]); } ui.staticObjectTable->setItem(rc, 4, createItem(ddists.join(", "))); if (line == selectedLine) { ui.staticObjectTable->setCurrentCell(rc, 0); ui.tabWidget->setCurrentWidget(ui.staticObjectWidget); } } else if (type == IDETypeTimedObject) { IDETimedObject* tobj = (IDETimedObject*) stmt; int rc = ui.timedObjectTable->rowCount(); ui.timedObjectTable->setRowCount(rc+1); ui.timedObjectTable->setItem(rc, 0, createItem(QString("%1").arg(tobj->getID()))); ui.timedObjectTable->setItem(rc, 1, createItem(tobj->getModelName().get(), true)); ui.timedObjectTable->setItem(rc, 2, createItem(tobj->getTXDArchiveName().get(), true)); ui.timedObjectTable->setItem(rc, 3, createItem(QString("%1") .arg(tobj->getNumSubObjects()))); ui.timedObjectTable->setItem(rc, 5, createItem(QString("%1") .arg(tobj->getFlags()))); ui.timedObjectTable->setItem(rc, 6, createItem(QString("%1") .arg(tobj->getTimeOn()))); ui.timedObjectTable->setItem(rc, 7, createItem(QString("%1") .arg(tobj->getTimeOff()))); QStringList ddists; for (int32_t i = 0 ; i < tobj->getNumSubObjects() ; i++) { ddists << QString("%1").arg(tobj->getDrawDistances()[i]); } ui.timedObjectTable->setItem(rc, 4, createItem(ddists.join(", "))); if (line == selectedLine) { ui.timedObjectTable->setCurrentCell(rc, 0); ui.tabWidget->setCurrentWidget(ui.timedObjectWidget); } } else if (type == IDETypeAnimation) { IDEAnimation* anim = (IDEAnimation*) stmt; int rc = ui.animationTable->rowCount(); ui.animationTable->setRowCount(rc+1); ui.animationTable->setItem(rc, 0, createItem(QString("%1").arg(anim->getID()))); ui.animationTable->setItem(rc, 1, createItem(anim->getModelName().get(), true)); ui.animationTable->setItem(rc, 2, createItem(anim->getTXDArchiveName().get(), true)); ui.animationTable->setItem(rc, 3, createItem(anim->getAnimationName().get())); ui.animationTable->setItem(rc, 4, createItem(QString("%1") .arg(anim->getDrawDist()))); ui.animationTable->setItem(rc, 5, createItem(QString("%1").arg(anim->getFlags()))); if (line == selectedLine) { ui.animationTable->setCurrentCell(rc, 0); ui.tabWidget->setCurrentWidget(ui.animationWidget); } } else if (type == IDETypePedestrian) { IDEPedestrian* ped = (IDEPedestrian*) stmt; int rc = ui.pedTable->rowCount(); ui.pedTable->setRowCount(rc+1); ui.pedTable->setItem(rc, 0, createItem(QString("%1").arg(ped->getID()))); ui.pedTable->setItem(rc, 1, createItem(ped->getModelName().get(), true)); ui.pedTable->setItem(rc, 2, createItem(ped->getTXDArchiveName().get(), true)); ui.pedTable->setItem(rc, 3, createItem(ped->getDefaultPedType().get())); ui.pedTable->setItem(rc, 4, createItem(ped->getBehavior().get())); ui.pedTable->setItem(rc, 5, createItem(ped->getAnimationGroup().get())); ui.pedTable->setItem(rc, 6, createItem(QString("%1") .arg(ped->getDrivableCarClasses(), 0, 16))); ui.pedTable->setItem(rc, 7, createItem(QString("%1").arg(ped->getFlags()))); ui.pedTable->setItem(rc, 8, createItem(ped->getSecondaryAnimationFile().get())); ui.pedTable->setItem(rc, 9, createItem(QString("%1") .arg(ped->getPreferredRadio1()))); ui.pedTable->setItem(rc, 10, createItem(QString("%1") .arg(ped->getPreferredRadio2()))); ui.pedTable->setItem(rc, 11, createItem(ped->getVoiceFile().get())); ui.pedTable->setItem(rc, 12, createItem(ped->getVoice1().get())); ui.pedTable->setItem(rc, 13, createItem(ped->getVoice2().get())); if (line == selectedLine) { ui.pedTable->setCurrentCell(rc, 0); ui.tabWidget->setCurrentWidget(ui.pedWidget); } } else if (type == IDETypeWeapon) { IDEWeapon* weap = (IDEWeapon*) stmt; int rc = ui.weaponTable->rowCount(); ui.weaponTable->setRowCount(rc+1); ui.weaponTable->setItem(rc, 0, createItem(QString("%1").arg(weap->getID()))); ui.weaponTable->setItem(rc, 1, createItem(weap->getModelName().get(), true)); ui.weaponTable->setItem(rc, 2, createItem(weap->getTXDArchiveName().get(), true)); ui.weaponTable->setItem(rc, 3, createItem(weap->getAnimationName().get())); ui.weaponTable->setItem(rc, 4, createItem(QString("%1") .arg(weap->getObjectCount()))); ui.weaponTable->setItem(rc, 6, createItem(QString("%1").arg(weap->getFlags()))); QStringList ddists; for (int32_t i = 0 ; i < weap->getObjectCount() ; i++) { ddists << QString("%1").arg(weap->getDrawDistances()[i]); } ui.weaponTable->setItem(rc, 5, createItem(ddists.join(", "))); if (line == selectedLine) { ui.weaponTable->setCurrentCell(rc, 0); ui.tabWidget->setCurrentWidget(ui.weaponWidget); } } delete stmt; } ErrorLog* log = ide.getErrorLog(); if (log->getMessageCount() > 0) { System* sys = System::getInstance(); char* elem; sys->log(LogEntry::error(tr("Parsing errors in IDE file %1:") .arg(file.getPath().getFileName().get()))); while ((elem = log->nextMessage()) != NULL) { sys->log(LogEntry::error(QString("\t%1").arg(elem))); delete[] elem; } } ui.staticObjectTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); ui.timedObjectTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); ui.animationTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); ui.pedTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); ui.weaponTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); connect(ui.staticObjectTable, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(staticObjectTableCellDoubleClicked(int, int))); connect(ui.timedObjectTable, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(timedObjectTableCellDoubleClicked(int, int))); connect(ui.animationTable, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(animationTableCellDoubleClicked(int, int))); connect(ui.pedTable, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(pedTableCellDoubleClicked(int, int))); connect(ui.weaponTable, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(weaponTableCellDoubleClicked(int, int))); }