/* ------------------------------------------------------------------------------------------- * * ------------------------------------------------------------------------------------------- */ void DMWindow::addMap() { QString fileName = QFileDialog::getOpenFileName(this,tr("Open Game"),rpg::FileUtils::mapsDirectory(), tr("Map Files (*.tmx)")); if(fileName != "") { // Get the name of the map Tiled::MapReader reader; Tiled::Map *map = reader.readMap(fileName); QString name = map->properties()["name"] == "" ? QDir(fileName).dirName() : map->properties()["name"]; delete map; QVariantMap data; data.insert("name", name); data.insert("file",rpg::FileUtils::relativeTo(rpg::FileUtils::mapsDirectory(), fileName)); this->engine->getRepository()->put("maps",QUuid::createUuid().toString(),data); this->updateMapList(); } }
void MainWindow::updateSavegameList() { if(!datapackPathExists) { ui->savegameEmpty->setText(QString("<html><head/><body><p align=\"center\"><span style=\"font-size:12pt;color:#a0a0a0;\">%1</span></p></body></html>").arg(tr("No datapack!"))); return; } QString lastSelectedPath; if(selectedSavegame!=NULL) lastSelectedPath=savegamePathList[selectedSavegame]; selectedSavegame=NULL; int index=0; while(savegame.size()>0) { delete savegame.at(0); savegame.removeAt(0); index++; } savegamePathList.clear(); savegameWithMetaData.clear(); QFileInfoList entryList=QDir(savegamePath).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System,QDir::DirsFirst);//possible wait time here index=0; while(index<entryList.size()) { bool ok=false; QFileInfo fileInfo=entryList.at(index); if(!fileInfo.isDir()) { index++; continue; } QString savegamesPath=fileInfo.absoluteFilePath()+"/"; QSettings metaData(savegamesPath+"metadata.conf",QSettings::IniFormat); SaveGameLabel *newEntry=new SaveGameLabel(); connect(newEntry,SIGNAL(clicked()),this,SLOT(savegameLabelClicked()),Qt::QueuedConnection); connect(newEntry,SIGNAL(doubleClicked()),this,SLOT(savegameLabelDoubleClicked()),Qt::QueuedConnection); newEntry->setStyleSheet("QLabel::hover{border:1px solid #bbb;background-color:rgb(180,180,180,100);border-radius:10px;}"); QString dateString; if(!QFileInfo(savegamesPath+"metadata.conf").exists()) newEntry->setText(QString("<span style=\"font-size:12pt;font-weight:600;\">Missing metadata</span><br/><span style=\"color:#909090;\">Missing metadata<br/>Bug</span>")); else { dateString=QFileInfo(savegamesPath+"metadata.conf").lastModified().toString("dd/MM/yyyy hh:mm:ssAP"); if(!metaData.isWritable()) newEntry->setText(QString("<span style=\"font-size:12pt;font-weight:600;\">%1</span><br/><span style=\"color:#909090;\">%2<br/>Bug</span>").arg("Bug").arg(dateString)); else { if(metaData.status()==QSettings::NoError) { if(metaData.contains("title") && metaData.contains("location") && metaData.contains("time_played") && metaData.contains("pass")) { int time_played_number=metaData.value("time_played").toUInt(&ok); QString time_played; if(!ok) time_played="Time player: bug"; else if(time_played_number>=3600*24*10) time_played=QObject::tr("%n day(s) played","",time_played_number/(3600*24)); else if(time_played_number>=3600*24) time_played=QObject::tr("%n day(s) and %1 played","",time_played_number/3600*24).arg(QObject::tr("%n hour(s)","",(time_played_number%(3600*24))/3600)); else if(time_played_number>=3600) time_played=QObject::tr("%n hour(s) and %1 played","",time_played_number/3600).arg(QObject::tr("%n minute(s)","",(time_played_number%3600)/60)); else time_played=QObject::tr("%n minute(s) and %1 played","",time_played_number/60).arg(QObject::tr("%n second(s)","",time_played_number%60)); //load the map name QString mapName=metaData.value("location").toString(); Tiled::MapReader reader; Tiled::Map * tiledMap = reader.readMap(datapackPath+DATAPACK_BASE_PATH_MAP+metaData.value("location").toString()); if(tiledMap) { if(tiledMap->properties().contains("name")) mapName=tiledMap->properties().value("name"); delete tiledMap; } newEntry->setText(QString("<span style=\"font-size:12pt;font-weight:600;\">%1</span><br/><span style=\"color:#909090;\">%2<br/>%3 (%4)</span>") .arg(metaData.value("title").toString()) .arg(dateString) .arg(mapName) .arg(time_played) ); } } else newEntry->setText(QString("<span style=\"font-size:12pt;font-weight:600;\">%1</span><br/><span style=\"color:#909090;\">%2<br/>Bug</span>").arg(metaData.value("title").toString()).arg(dateString)); } } ui->scrollAreaWidgetContents->layout()->addWidget(newEntry); if(lastSelectedPath==savegamesPath) selectedSavegame=newEntry; savegame << newEntry; savegamePathList[newEntry]=savegamesPath; savegameWithMetaData[newEntry]=ok; index++; } ui->savegameEmpty->setVisible(index==0); if(index>0) { ui->scrollAreaWidgetContents->layout()->removeItem(spacer); delete spacer; spacer=new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Expanding); ui->scrollAreaWidgetContents->layout()->addItem(spacer); } savegameLabelUpdate(); }