--- Vago/trunk/Vago/mainwindow.cpp 2013/04/06 21:08:35 791 +++ Vago/trunk/Vago/mainwindow.cpp 2016/12/09 19:04:18 1061 @@ -9,25 +9,24 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); - ui->pbConvertGeneral->setMinimumSize(ui->pbConvertGeneral->minimumSizeHint()); - ui->pbConvertGeneral->setMinimumWidth(50); - ui->pbConvertGeneral->setMinimumHeight(ui->pbConvertGeneral->minimumHeight()*1.4); + this->myLogger = new Logger(UtilVago::getAppPath(), GlobalVars::AppLogName); //start logger - qDebug() << ui->pbConvertGeneral->minimumHeight() << ui->pbConvertGeneral->minimumHeight(); + this->myLogger->writeString("Detected AppDir: "+UtilVago::getAppPath()); + this->myLogger->writeString("True app dir: "+QDir::currentPath()); - this->setWindowTitle("Vago v"+GlobalVars::AppVersion); + setVagoWindowTitle(); - if(!QFile::exists(QDir::currentPath()+"/"+GlobalVars::OniSplitString)){ - Util::showErrorPopUp("OniSplit not found. Please download it at "+GlobalVars::ModsDomain+" and put it in the same folder of Vago. \n\nProgram will now exit."); + if(!QFile::exists(UtilVago::getOniSplitExecutableAbsolutePath())){ + UtilVago::showAndLogErrorPopUp(this->myLogger, "OniSplit not found. Please download it at "+GlobalVars::ModsDomain+" and put it the Vago's tools folder. \n\nProgram will now exit."); exit(1); } - if(!QFile::exists(QDir::currentPath()+"/"+GlobalVars::XmlToolsString)){ - Util::showErrorPopUp("xmlTools not found. Please download it at "+GlobalVars::ModsDomain+" and put it in the same folder of Vago. \n\nProgram will now exit."); + if(!QFile::exists(UtilVago::getXmlToolsExecutableAbsolutePath())){ + UtilVago::showAndLogErrorPopUp(this->myLogger, "XmlTools not found. Please download it at "+GlobalVars::ModsDomain+" and put it the Vago's tools folder. \n\nProgram will now exit."); exit(1); } - this->vagoSettings = new QSettings(QDir::currentPath() + "/" + this->VagoSettingsName, QSettings::IniFormat); + this->vagoSettings = new QSettings(UtilVago::getAppPath() + "/" + this->VagoSettingsName, QSettings::IniFormat); //First Execution? Old configuration? Settings missed? bool iniChanged=false; @@ -36,7 +35,7 @@ MainWindow::MainWindow(QWidget *parent) iniChanged=true; } if(!this->vagoSettings->contains("Workspace")){ - this->vagoSettings->setValue("Workspace", QDir::currentPath()+"/VagoWorkspace"); + this->vagoSettings->setValue("Workspace", UtilVago::getAppPath()+"/VagoWorkspace"); iniChanged=true; } if(!this->vagoSettings->contains("AeFolder")){ @@ -45,7 +44,7 @@ MainWindow::MainWindow(QWidget *parent) QString aefolder=Util::normalizePath(QFileDialog::getExistingDirectory(this,"Choose Anniversary Edition (AE) folder...")); if(aefolder.isEmpty()){ - Util::showErrorPopUp("AE folder is mandatory. Application will now exit."); + UtilVago::showAndLogErrorPopUp(this->myLogger, "AE folder is mandatory. Application will now exit."); exit(1); } @@ -56,6 +55,14 @@ MainWindow::MainWindow(QWidget *parent) this->vagoSettings->setValue("AeFolder", aefolder); iniChanged=true; } + if(!this->vagoSettings->contains("WindowWidth")){ + this->vagoSettings->setValue("WindowWidth", GlobalVars::DefaultWindowWidth); + iniChanged=true; + } + if(!this->vagoSettings->contains("WindowHeight")){ + this->vagoSettings->setValue("WindowHeight", GlobalVars::DefaultWindowHeight); + iniChanged=true; + } if(!this->vagoSettings->contains("OniWindow")){ this->vagoSettings->setValue("OniWindow", true); iniChanged=true; @@ -64,10 +71,30 @@ MainWindow::MainWindow(QWidget *parent) this->vagoSettings->setValue("SeparateInWorkspace",true); iniChanged=true; } - if(!this->vagoSettings->contains("ConfirmExit")){ - this->vagoSettings->setValue("ConfirmExit", false); + if(!this->vagoSettings->contains("AskSaveProject")){ + this->vagoSettings->setValue("AskSaveProject", true); + iniChanged=true; + } + if(!this->vagoSettings->contains("AskToOpenLastProject")){ + this->vagoSettings->setValue("AskToOpenLastProject", false); + iniChanged=true; + } + if(!this->vagoSettings->contains("LastProjectPath")){ + this->vagoSettings->setValue("LastProjectPath", this->vagoSettings->value("Workspace")); iniChanged=true; } + for(int i=0; irecentProjectsMaxSize; i++){ + if(!this->vagoSettings->contains("RecentProject" + QString::number(i+1))){ + this->vagoSettings->setValue("RecentProject" + QString::number(i+1), ""); + iniChanged=true; + } + } +#ifdef Q_OS_MAC + if(!this->vagoSettings->contains("useYesAsDefaultWhenRemovingItems")){ + this->vagoSettings->setValue("useYesAsDefaultWhenRemovingItems", false); + iniChanged=true; + } +#endif if(iniChanged){ this->vagoSettings->sync(); @@ -78,6 +105,11 @@ MainWindow::MainWindow(QWidget *parent) this->workspaceWizardsLocation=this->workspaceLocation+"/Wizards"; this->AeLocation=this->vagoSettings->value("AeFolder").toString(); this->outputFolder=this->workspaceLocation; + this->startedWindowWidth=this->vagoSettings->value("WindowWidth").toInt(); + this->startedWindowHeight=this->vagoSettings->value("WindowHeight").toInt(); +#ifdef Q_OS_MAC + this->useYesAsDefaultWhenRemovingItems=this->vagoSettings->value("useYesAsDefaultWhenRemovingItems").toBool(); +#endif //Create our workspace if it doesn't exists yet if(!QDir(this->workspaceLocation).exists()){ @@ -91,16 +123,10 @@ MainWindow::MainWindow(QWidget *parent) this->myBar->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fixed); this->myBar->setMinimumWidth(150); this->myBar->hide(); //hide while not being used + ui->tbAbortConversion->hide(); //hide while not being used - ui->statusBar->addPermanentWidget(myBar); //this adds automatically in right - - this->myLogger = new Logger(); //start logger - - //Initialize list pointers - this->listToProccess = new QStringList; - - //Create a thread for do the conversion in background - this->myConverter = new Converter(this->myLogger,this->listToProccess); + ui->statusBar->addPermanentWidget(this->myBar); //this adds automatically in right + ui->statusBar->addPermanentWidget(ui->tbAbortConversion); // User interface ui->mainToolBar->addWidget(ui->tbAE); //add ae installer launch button @@ -109,11 +135,16 @@ MainWindow::MainWindow(QWidget *parent) ui->mainToolBar->addWidget(ui->emptySpacerLabel2); //same as before ui->mainToolBar->addWidget(ui->tbCommand); //add option to manual onisplit commands ui->mainToolBar->addWidget(ui->emptySpacerLabel3); //same as before + ui->mainToolBar->addWidget(ui->tbXmlToolsInterface); //add option to manual onisplit commands + ui->mainToolBar->addWidget(ui->emptySpacerLabel4); //same as before ui->mainToolBar->addWidget(ui->tbOpenFolder); //add option to open folder with files converted etc ui->mainToolBar->setLayoutDirection(Qt::RightToLeft); -#ifdef Q_WS_MAC + ui->pbConvert->setMinimumHeight(ui->pbConvert->sizeHint().height()*1.5); // This is OS indepented. It maintain size ratio over the Windows and Mac. + + +#ifdef Q_OS_MAC // setUnifiedTitleAndToolBarOnMac(true); // Qt suggests to use it on mac | http://www.slideshare.net/qtbynokia/how-to-make-your-qt-app-look-native // align on left doesn't work if active ui->tbOni->setIcon(QIcon(":/new/icons/oni_icon_mac.png")); // Oni executable on mac have a different icon than windows // Set mac platform the first one in the menu, and also make it checkable by default @@ -121,21 +152,25 @@ MainWindow::MainWindow(QWidget *parent) ui->menuTarget_Platform->addAction(ui->actionWindows); ui->actionWindows->setChecked(false); ui->actionMac_Windows_demo->setChecked(true); - // Hide file menu on mac (not needed) - ui->menuFile->hide(); - ui->menuFile->close(); - //ui->menuBar->macMenu(); + // resize(800,600); // Mac OS pcs should be able to render this resolution without any problem. It's also better + //// because the components on mac use more space #endif - connectSlots(); + resize(this->startedWindowWidth,this->startedWindowHeight); + +#ifdef Q_OS_MAC + ui->pbConvert->setToolTip(ui->pbConvert->toolTip() + " (⌘ + Enter)"); +#else + ui->pbConvert->setToolTip(ui->pbConvert->toolTip() + " (Ctrl + Enter)"); +#endif //Commands Mapping this->commandMap = QHash(); mapCommands(); - updateItemsLoaded(ui->twSourcesGeneral); + updateItemsLoaded(ui->twSourcesXML); - this->myLogger->writeString("Application started."); + loadRecentProjects(); } MainWindow::~MainWindow() @@ -144,6 +179,54 @@ MainWindow::~MainWindow() this->myLogger->writeString("Application Exited."); } + +void MainWindow::showEvent(QShowEvent *e) +{ + // If we don't have a converter yet, application wasn't started. + if(!this->applicationIsFullyLoaded) + { + // Apparently Qt doesn't contains a slot to when the application was fully load (mainwindow). So we do our own implementation instead. + connect(this, SIGNAL(signalAppIsLoaded()), this, SLOT(applicationWasLoaded()), Qt::ConnectionType::QueuedConnection); + emit signalAppIsLoaded(); + } + + e->accept(); +} + +// Called only when the MainWindow was fully loaded and painted on the screen. This slot is only called once. +void MainWindow::applicationWasLoaded(){ +#ifdef Q_OS_WIN + // QProgressBar only works after the windows was shown + // http://stackoverflow.com/questions/24840941/qwintaskbarprogress-wont-show (Kervala answer) + + this->win7TaskBarButton = new QWinTaskbarButton(); + + this->win7TaskBarButton->setWindow(this->windowHandle()); + + this->win7TaskBarProgress = this->win7TaskBarButton->progress(); + + //Create a thread for do the conversion in background + this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, &this->listToProccess, this->win7TaskBarProgress); +#else + this->myConverter = new Converter(UtilVago::getAppPath(), this->myLogger, &this->listToProccess); +#endif + + connectSlots(); + + this->myLogger->writeString("Application started."); + + this->applicationIsFullyLoaded = true; + + QString lastSavedProject = this->vagoSettings->value("RecentProject1").toString(); + + if(!lastSavedProject.isEmpty() && this->vagoSettings->value("AskToOpenLastProject").toBool()){ + if(Util::showQuestionPopUp(this,"Do you want to load latest project?\n\nLatest project was '" + Util::cutNameWithoutBackSlash(lastSavedProject) + "'.")){ + loadProjectState(lastSavedProject); + } + } +} + + void MainWindow::on_actionExit_triggered() { close(); @@ -158,14 +241,26 @@ void MainWindow::on_actionAbout_triggere void MainWindow::on_actionAE_Package_Creator_triggered() { - PackageWizard myWizard = PackageWizard(this->workspaceWizardsLocation, this->vagoSettings, this->myLogger); - myWizard.exec(); + // it deletes itself once closed + WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger); } void MainWindow::on_actionSound_Wizard_triggered() { - SoundWizard myWizard (this->workspaceWizardsLocation, this->myLogger, &this->commandMap); - myWizard.exec(); + // it deletes itself once closed + WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger, &this->commandMap); +} + +void MainWindow::on_actionBackground_Image_Wizard_triggered() +{ + // it deletes itself once closed + WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger); +} + +void MainWindow::on_actionWindow_Messages_Wizard_triggered() +{ + // it deletes itself once closed + WizardFactory::startInstance(UtilVago::getAppPath(), this->workspaceWizardsLocation, this->vagoSettings, this->myLogger); } void MainWindow::on_tbOni_clicked() @@ -175,7 +270,7 @@ void MainWindow::on_tbOni_clicked() if(this->vagoSettings->value("OniWindow").toBool()){ // Run in a window? arguments << "-noswitch"; } -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN else{ arguments << "-switch"; // only supported on windows. Was added by daodan dll. } @@ -202,6 +297,22 @@ void MainWindow::on_tbOpenFolder_clicked QDesktopServices::openUrl(QUrl("file:///"+this->outputFolder)); } + +void MainWindow::on_tbXmlToolsInterface_clicked() +{ + //We pass no parent because we want to have an independent window for XmlToolsInterface, + //so we can minimize it or maximize indepently from the MainWindow + XmlToolsInterface *xmlToolsWindow = new XmlToolsInterface(this->myLogger); + xmlToolsWindow->show(); //it destroys itself when finished. +} + +void MainWindow::on_tbAbortConversion_clicked() +{ + if(Util::showQuestionPopUp(this,"Are you sure you want to abort the current conversion?")){ + emit terminateCurrProcess(); + } +} + void MainWindow::on_cbEnvMap_toggled(bool checked) { ui->leEnvMapTexture->setEnabled(checked); @@ -217,19 +328,9 @@ void MainWindow::on_cbWithAnimation_togg ui->leAnimationName->setEnabled(checked); } -void MainWindow::on_cbCamera_toggled(bool checked) -{ - if(checked){ - ui->cbGeometry->setChecked(false); - } -} - -void MainWindow::on_cbGeometry_toggled(bool checked) +void MainWindow::on_cbSpecificFilesLevels_toggled(bool checked) { - ui->leGeometryName->setEnabled(checked); - if(checked){ - ui->cbCamera->setChecked(false); - } + ui->leSpecificFilesLevels->setEnabled(checked); } void MainWindow::on_actionCheck_For_Updates_triggered() @@ -263,19 +364,14 @@ void MainWindow::checkVagoLastVersion(QN } } else{ - Util::showErrorPopUp("An error occurred checking last version:\n\n"+result->errorString()); + UtilVago::showAndLogErrorPopUp(this->myLogger, "An error occurred checking last version:\n\n"+result->errorString()); } result->deleteLater(); } -void MainWindow::on_pbAddSourceGeneral_clicked() +void MainWindow::on_pbAddSourceXML_clicked() { - if(QString::compare(ui->cbFromGeneral->currentText(),"ONI",Qt::CaseSensitive)==0 && QString::compare(ui->cbToGeneral->currentText(),"DAT",Qt::CaseSensitive)==0){ //CaseSensitive is faster) - addFilesSource(ui->twSourcesGeneral,Util::multipleDirDialog("Choose folders with ONIs...")); - } - else{ - addFilesSource( ui->twSourcesGeneral,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); - } + addFilesSource( ui->twSourcesXML,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); } void MainWindow::on_pbAddSourceTextures_clicked() @@ -283,19 +379,24 @@ void MainWindow::on_pbAddSourceTextures_ addFilesSource( ui->twSourcesTextures, QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); } -void MainWindow::on_pbAddSourceModels_clicked() +void MainWindow::on_pbAddSourceObjects_clicked() { - addFilesSource( ui->twSourcesModels,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); + addFilesSource( ui->twSourcesObjects,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); } -void MainWindow::on_pbAddSourceAnimations_clicked() +void MainWindow::on_pbAddSourceCharacters_clicked() { - addFilesSource( ui->twSourcesAnimations,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); + addFilesSource( ui->twSourcesCharacters,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); } void MainWindow::on_pbAddSourceLevels_clicked() { - addFilesSource( ui->twSourcesLevels,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); + if(QString::compare(ui->cbFromLevels->currentText(),"ONI FILES",Qt::CaseSensitive)==0 && QString::compare(ui->cbToLevels->currentText(),"DAT",Qt::CaseSensitive)==0){ //CaseSensitive is faster) + addFilesSource(ui->twSourcesLevels,Util::multipleDirDialog("Choose folders with ONIs...")); + } + else{ + addFilesSource(ui->twSourcesLevels,QFileDialog::getOpenFileNames(this,"Choose the files...","./" , "All Files (*.*)")); + } } void MainWindow::on_pbAddSourceMisc_clicked() @@ -327,7 +428,7 @@ void MainWindow::addFilesSource(DropTabl to = QString(fromTo).remove(0,fromTo.lastIndexOf("> ")+2); //+2 to start after "> " //Pre-processing (check if the files/folders received are valid), e.g. check for ONI->DAT if are only given folders and not files - if(QString::compare(from,"ONI",Qt::CaseSensitive)==0 && QString::compare(to,"DAT",Qt::CaseSensitive)==0){ + if(from=="ONI FILES" && to=="DAT"){ //check if it's a folder foreach(QString myFile, files){ if(!QDir(myFile).exists()){ @@ -377,165 +478,147 @@ void MainWindow::addFilesSource(DropTabl addRowTable(myTable,lastFileName,fromTo,command); } updateItemsLoaded(myTable); + rowsWereChangedInDropTableWidget(); } -QString MainWindow::fileParsingGeneral(QString myOutputFolder, QString from, QString to , QString file){ +QString MainWindow::fileParsingXML(QString tabTitle, QString myOutputFolder, QString from, QString to , QString file){ QString command; - if(QString::compare(from,"ONI",Qt::CaseSensitive)==0 && QString::compare(to,"DAT",Qt::CaseSensitive)==0){ //CaseSensitive is faster - - QString datName; - - if(ui->cbDatGeneral->isChecked()){ - if(ui->leTargetDatGeneral->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbDatGeneral->text()+"' is selected. The name cannot be empty."); - return ""; - } - datName+=QString(myOutputFolder).insert(myOutputFolder.size()-1,ui->leTargetDatGeneral->text()); //set name inputted by user - if(!ui->leTargetDatGeneral->text().toUpper().endsWith(".DAT")){ - datName.insert(datName.size()-1,".dat"); //append extension if necessary (-1 to maintain final quote) - } - } - else{ - datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::cutName(file).remove("/")+".dat"); //if none iputted set the same name of input file - } - - if(ui->actionWindows->isChecked()){ //is target plataform select windows? - return command=this->commandMap.value("general->"+from+"->"+to+"(PC)")+" "+ file + " "+datName; - } - else{ - return command=this->commandMap.value("general->"+from+"->"+to+"(demoPCMAC)")+" "+ file + " "+datName; - } - } - else if(QString::compare(from,"ONI",Qt::CaseSensitive)==0 && QString::compare(to,"XML",Qt::CaseSensitive)==0 && ui->cbTRAMGeneral->isChecked()){ - if(ui->leTRAMGeneral->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbTRAMGeneral->text()+"' is selected. The source cannot be empty."); - return ""; - } - return command=this->commandMap.value("general->"+from+"->"+to)+" "+myOutputFolder+" "+this->commandMap.value("general->"+ui->cbTRAMGeneral->text())+file + " "+ Util::normalizeAndQuote(ui->leTRAMGeneral->text()); + if(from=="ONI" && to=="XML"){ + return command=this->commandMap.value(tabTitle+"->"+from+"->"+to)+" "+myOutputFolder+" "+file; } - else{ - return command=this->commandMap.value("general->"+from+"->"+to)+" "+myOutputFolder+" "+file; + else if(from=="XML" && to=="ONI"){ + return command=this->commandMap.value(tabTitle+"->"+from+"->"+to)+" "+myOutputFolder+" "+file; } + return ""; + } -QString MainWindow::fileParsingTextures(QString myOutputFolder, QString from, QString to , QString file){ +QString MainWindow::fileParsingTextures(QString tabTitle, QString myOutputFolder, QString from, QString to , QString file){ - QString command=this->commandMap.value("textures->"+from+"->"+to)+" "+myOutputFolder; + QString command=this->commandMap.value(tabTitle+"->"+from+"->"+to)+" "+myOutputFolder; if(ui->gbTextures->isEnabled()){ //faster than compare strings (if is DAT/ONI) if(ui->cbMipMapsTextures->isChecked()){ - command+=" "+this->commandMap.value("textures->"+ui->cbMipMapsTextures->text()); + command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbMipMapsTextures->text()); } if(ui->cbNoUwrap->isChecked()){ - command+=" "+this->commandMap.value("textures->"+ui->cbNoUwrap->text()); + command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbNoUwrap->text()); } if(ui->cbNoVwrap->isChecked()){ - command+=" "+this->commandMap.value("textures->"+ui->cbNoVwrap->text()); + command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbNoVwrap->text()); } if(ui->cbLarge->isChecked()){ - command+=" "+this->commandMap.value("textures->"+ui->cbLarge->text()); + command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbLarge->text()); } - if(ui->rbBGR32->isChecked()){ - command+=" "+this->commandMap.value("textures->"+ui->rbBGR32->text()); - } - else if(ui->rbBGRA32->isChecked()){ - command+=" "+this->commandMap.value("textures->"+ui->rbBGRA32->text()); - } - else if(ui->rbBGR555->isChecked()){ - command+=" "+this->commandMap.value("textures->"+ui->rbBGR555->text()); - } - else if(ui->rbBGRA5551->isChecked()){ - command+=" "+this->commandMap.value("textures->"+ui->rbBGRA5551->text()); - } - else if(ui->rbBGRA444->isChecked()){ - command+=" "+this->commandMap.value("textures->"+ui->rbBGRA444->text()); - } - else{ //dxt1 checked - command+=" "+this->commandMap.value("textures->"+ui->rbDxt1->text()); - } + command+=" "+this->commandMap.value(tabTitle+"->"+getTextureRBCheckedTypeTexture()->text()); if(ui->cbEnvMap->isChecked()){ if(ui->leEnvMapTexture->text().isEmpty()){ showErrStatusMessage("Checkbox '"+ui->cbEnvMap->text()+"' is selected. The name texture name cannot be empty."); return ""; } - command+=" "+this->commandMap.value("textures->"+ui->cbEnvMap->text()) + ui->leEnvMapTexture->text().remove(".oni",Qt::CaseInsensitive); + command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbEnvMap->text()) + ui->leEnvMapTexture->text().remove(".oni",Qt::CaseInsensitive); } } return command+=" "+file; //add source } -QString MainWindow::fileParsingModels(QString myOutputFolder, QString from, QString to , QString file){ +QString MainWindow::fileParsingCharacters(QString tabTitle, QString myOutputFolder, QString from, QString to , QString file){ - QString command=this->commandMap.value("models->"+from+"->"+to)+" "+myOutputFolder; + QString command=this->commandMap.value(tabTitle+"->"+from+"->"+to)+" "+myOutputFolder + " " + file ; - //TODO: This can be optimized. When some are not enable others are. - if(ui->cbTexture->isChecked()){ - if(ui->leTextureName->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbTexture->text()+"' is selected. The name cannot be empty."); - return ""; - } - command+=" "+this->commandMap.value("models->"+ui->cbTexture->text()) + ui->leTextureName->text().remove(".oni",Qt::CaseInsensitive); - } if(ui->cbCellShading->isChecked()){ - command+=" "+this->commandMap.value("models->"+ui->cbCellShading->text()); + command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbCellShading->text()); } if(ui->cbNormals->isChecked()){ - command+=" "+this->commandMap.value("models->"+ui->cbNormals->text()); + command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbNormals->text()); } - if(ui->cbWithAnimation->isEnabled()){ - if(ui->cbWithAnimation->isChecked()){ - command+=" "+this->commandMap.value("models->"+ui->cbWithAnimation->text())+ui->leAnimationName->text().remove(".oni",Qt::CaseInsensitive); - } - else{ - command+=" "+this->commandMap.value("models->No Animation"); + if(ui->cbWithTRBS_ONCC->isChecked()){ + if(ui->leTRBS_ONCC->text().isEmpty()){ + showErrStatusMessage("Checkbox '"+ui->cbWithTRBS_ONCC->text()+"' is selected. The name cannot be empty."); + return ""; } - } + command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbWithTRBS_ONCC->text())+Util::normalizeAndQuote(ui->leTRBS_ONCC->text()); + } - return command+=" "+file; //add source + return command; } -QString MainWindow::fileParsingAnimations(QString myOutputFolder, QString from, QString to , QString file){ - QString command=this->commandMap.value("animations->"+from+"->"+to)+" "+myOutputFolder + " " + file ; +QString MainWindow::fileParsingObjects(QString tabTitle, QString myOutputFolder, QString from, QString to , QString file){ - if(ui->cbCamera->isChecked()){ - command+=" "+this->commandMap.value("animations->"+ui->cbCamera->text()); + QString command=this->commandMap.value(tabTitle+"->"+from+"->"+to)+" "+myOutputFolder; + + if(ui->cbTexture->isChecked()){ + if(ui->leTextureName->text().isEmpty()){ + showErrStatusMessage("Checkbox '"+ui->cbTexture->text()+"' is selected. The file source cannot be empty."); + return ""; + } + command+=" "+this->commandMap.value(tabTitle+"->"+ui->cbTexture->text()) + ui->leTextureName->text(); } - else if(ui->cbGeometry->isChecked()){ - if(ui->leGeometryName->text().isEmpty()){ - showErrStatusMessage("Checkbox '"+ui->cbGeometry->text()+"' is selected. The geometry file path cannot be empty."); + else if(ui->cbWithAnimation->isChecked()){ + if(ui->leAnimationName->text().isEmpty()){ + showErrStatusMessage("Checkbox '"+ui->cbWithAnimation->text()+"' is selected. The file source cannot be empty."); return ""; } - command+=" "+this->commandMap.value("animations->"+ui->cbGeometry->text()) + (ui->leGeometryName->text().startsWith('"')?ui->leGeometryName->text():Util::insertQuotes(ui->leGeometryName->text())); + command+=" "+Util::normalizeAndQuote(ui->leAnimationName->text()) + " " + this->commandMap.value(tabTitle+"->"+ui->cbWithAnimation->text()) + file; + return command; } - return command; + if(from=="OBAN ONI (cam)"){ + command+=" -geom:camera"; + } + + return command+=" "+file; //add source } -QString MainWindow::fileParsingLevels(QString myOutputFolder, QString from, QString to , QString file){ +QString MainWindow::fileParsingLevels(QString tabTitle, QString myOutputFolder, QString from, QString to , QString file){ QString datName, command; - command=this->commandMap.value("levels->"+from+"->"+to)+" "+myOutputFolder+" "+file; + if(!(from=="ONI FILES" && to=="DAT")){ // to all except this one + + command=this->commandMap.value(tabTitle+"->"+from+"->"+to); - if(from=="MASTER XML" && to=="DAT"){ - command+=GlobalVars::OniSplitProcSeparator; //insert mark so we know this action will take 2 commands + if(ui->cbSpecificFilesLevels->isChecked()){ + if(ui->leSpecificFilesLevels->text().isEmpty()){ + showErrStatusMessage("Checkbox '"+ui->cbSpecificFilesLevels->text()+"' is selected. The files pattern cannot be empty."); + return ""; + } + + command+=":"+ui->leSpecificFilesLevels->text(); + } + + if(from=="DAT" && to=="ONI FILES"){ // extract files to a subdir with the files name ex: level0_Final + command += " " + myOutputFolder.insert(myOutputFolder.size()-2,QString(Util::cutName(file)).replace(".dat","")) + " " + file; + } + else{ + command+=" "+myOutputFolder+" "+file; + } + + } + + if((from=="ONI FILES" || from=="MASTER XML") && to=="DAT"){ // almost the same command for both QString datName; + + if(from=="MASTER XML"){ + command+=GlobalVars::OniSplitProcSeparator; //insert mark so we know this action will take 2 commands + } + if(ui->cbDatLevels->isChecked()){ if(ui->leTargetDatLevels->text().isEmpty()){ showErrStatusMessage("Checkbox '"+ui->cbDatLevels->text()+"' is selected. The name cannot be empty."); @@ -547,14 +630,28 @@ QString MainWindow::fileParsingLevels(QS } } else{ - datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::cutName(file).remove("/").replace(".xml",".dat",Qt::CaseInsensitive)); //if none iputted set the same name of input file + if(from=="ONI FILES"){ + datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::cutName(file).remove("/")+".dat"); //if none iputted set the same name of input file + } + else if(from=="MASTER XML"){ + datName=QString(myOutputFolder).insert(myOutputFolder.size()-1,Util::cutName(file).remove("/").replace(".xml",".dat",Qt::CaseInsensitive)); //if none iputted set the same name of input file + } } - - if(ui->actionWindows->isChecked()){ //is target plataform select windows? - command+=this->commandMap.value("general->ONI->"+to+"(PC)")+" "+myOutputFolder+" "+datName; //add second command + if(from=="ONI FILES"){ + if(ui->actionWindows->isChecked()){ //is target plataform select windows? + return command=this->commandMap.value(tabTitle+"->"+from+"->"+to+"(PC)")+" "+ file + " "+datName; + } + else{ + return command=this->commandMap.value(tabTitle+"->"+from+"->"+to+"(demoPCMAC)")+" "+ file + " "+datName; + } } - else{ - command+=this->commandMap.value("general->ONI->"+to+"(demoPCMAC)")+" "+myOutputFolder+" "+datName; //add second command + else if(from=="MASTER XML"){ + if(ui->actionWindows->isChecked()){ //is target plataform select windows? + command+=this->commandMap.value(tabTitle+"->ONI FILES->"+to+"(PC)")+" "+myOutputFolder+" "+datName; //add second command + } + else{ + command+=this->commandMap.value(tabTitle+"->ONI FILES->"+to+"(demoPCMAC)")+" "+myOutputFolder+" "+datName; //add second command + } } } @@ -580,7 +677,7 @@ QString MainWindow::fileParsingLevels(QS //parse all files (separated by spaces) while(true){ - nextIndex=additionalFiles.indexOf(" ",currentIndex+1); + nextIndex=additionalFiles.indexOf(";",currentIndex+1); command += " "+Util::normalizeAndQuote(additionalFiles.mid(currentIndex,(nextIndex-currentIndex))); @@ -592,7 +689,7 @@ QString MainWindow::fileParsingLevels(QS } if(ui->cbGridsLevels->isChecked()){ - command+=GlobalVars::OniSplitProcSeparator+this->commandMap.value("levels->"+ui->cbGridsLevels->text())+" "+Util::normalizeAndQuote(ui->leBnvLevels->text())+" "+file+" -out:"+myOutputFolder; + command+=GlobalVars::OniSplitProcSeparator+this->commandMap.value(tabTitle+"->"+ui->cbGridsLevels->text())+" "+Util::normalizeAndQuote(ui->leBnvLevels->text())+" "+file+" -out:"+myOutputFolder; } return command; @@ -602,7 +699,7 @@ QString MainWindow::fileParsingMisc(QStr return this->commandMap.value("misc->"+from+"->"+to)+" "+myOutputFolder+" "+file; } -void MainWindow::addRowTable(DropTableWidget *myTable, QString fileName, QString fromTo, QString command){ +void MainWindow::addRowTable(DropTableWidget *myTable, QString fileName, QString fromTo, QString command, bool isToDisabled){ //Get actual number rows int twSize=myTable->rowCount(); @@ -614,6 +711,12 @@ void MainWindow::addRowTable(DropTableWi QTableWidgetItem *newConversion = new QTableWidgetItem(fromTo); QTableWidgetItem *newCommand = new QTableWidgetItem(command); + if(isToDisabled){ + myTable->setDisableStyleWidgetItem(newFile); + myTable->setDisableStyleWidgetItem(newConversion); + myTable->setDisableStyleWidgetItem(newCommand); + } + myTable->setItem(twSize,0,newFile); myTable->setItem(twSize,1,newConversion); myTable->setItem(twSize,2,newCommand); @@ -621,41 +724,18 @@ void MainWindow::addRowTable(DropTableWi myTable->updateTableToolTips(twSize); //Update tool tips } -void MainWindow::on_pbConvertGeneral_clicked() +void MainWindow::on_pbConvert_clicked() { - startConversion(ui->twSourcesGeneral); + startConversion(); } -void MainWindow::on_pbConvertTextures_clicked() -{ - startConversion(ui->twSourcesTextures); -} - -void MainWindow::on_pbConvertModels_clicked() -{ - startConversion(ui->twSourcesModels); -} - -void MainWindow::on_pbConvertAnimations_clicked() -{ - startConversion(ui->twSourcesAnimations); -} +void MainWindow::startConversion(){ -void MainWindow::on_pbConvertLevels_clicked() -{ - startConversion(ui->twSourcesLevels); -} - -void MainWindow::on_pbConvertMisc_clicked() -{ - startConversion(ui->twSourcesMisc); -} - -void MainWindow::startConversion(DropTableWidget *myTable){ + DropTableWidget* currTable = getCurrentTableWidget(); bool ready=false; - for(int i=0; irowCount(); i++){ //There are items to process? - if(myTable->item(i,2)->background()!=myTable->disabledBackStyle){ + for(int i=0; irowCount(); i++){ //There are items to process? + if(currTable->item(i,2)->background()!=currTable->disabledBackStyle){ ready=true; break; } @@ -666,15 +746,15 @@ void MainWindow::startConversion(DropTab return; } - if(myBar->isVisible()){ + if(this->myBar->isVisible()){ Util::showErrorPopUp("Another conversion is progress. Please wait until it finishes."); return; } - for(int i=0; irowCount(); i++){ + for(int i=0; irowCount(); i++){ //Only process enabled items - if(myTable->item(i,2)->background()!=myTable->disabledBackStyle){ - this->listToProccess->append(myTable->item(i,2)->text()); + if(currTable->item(i,2)->background()!=currTable->disabledBackStyle){ + this->listToProccess.append(currTable->item(i,2)->text()); } } @@ -685,6 +765,7 @@ void MainWindow::TsetupProgressBar(int m this->myBar->setValue(0); this->myBar->show(); this->myBar->setMaximum(max); + ui->tbAbortConversion->show(); } void MainWindow::TupdateProgressBar(){ @@ -694,24 +775,31 @@ void MainWindow::TupdateProgressBar(){ void MainWindow::TresultConversion(QString result, int numErrors){ QApplication::alert(this); //Show a notification if window is not active this->myBar->hide(); + ui->tbAbortConversion->hide(); if(numErrors!=0){ QString sNumErrors=QString::number(numErrors); if(numErrors>1){ - Util::showErrorLogPopUp(result+"\n This is the last of "+sNumErrors+" Errors."); - showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" Errors)."); + UtilVago::showErrorPopUpLogButton(result+"\n This is the last of "+sNumErrors+" errors."); + showErrStatusMessage("Something gone wrong. Check log file ("+sNumErrors+" errors)."); } else{ - Util::showErrorLogPopUp(result); + UtilVago::showErrorPopUpLogButton(result); showErrStatusMessage("Something gone wrong. Check log file."); } - } else{ showSuccessStatusMessage("Everything went well!"); } } +void MainWindow::TconversionAborted(){ + this->myBar->hide(); + ui->tbAbortConversion->hide(); + + showErrStatusMessage("Conversion was aborted."); +} + void MainWindow::showErrStatusMessage(QString message){ QPalette myPalete = QPalette(); @@ -731,27 +819,21 @@ void MainWindow::showSuccessStatusMessag } void MainWindow::mapCommands(){ - ////////////////////////////////////////////////////////////////////////General Commands - this->commandMap.insert("general->DAT->ONI","-export"); - //this->commandMap.insert("general->ONI->DAT","-import"); //Not used. - this->commandMap.insert("general->ONI->DAT(PC)","-import:nosep"); - this->commandMap.insert("general->ONI->DAT(demoPCMAC)","-import:sep"); - this->commandMap.insert("general->ONI->XML","-extract:xml"); - this->commandMap.insert("general->XML->ONI","-create"); + ////////////////////////////////////////////////////////////////////////XML Commands + this->commandMap.insert("xml->ONI->XML","-extract:xml"); + this->commandMap.insert("xml->XML->ONI","-create"); //######################General Options - this->commandMap.insert("general->"+ui->cbTRAMGeneral->text(),"-anim-body:"); + //Possible Combinations - this->commandMap.insertMulti("general->DAT","ONI"); - this->commandMap.insertMulti("general->ONI","DAT"); - this->commandMap.insertMulti("general->ONI","XML"); - this->commandMap.insertMulti("general->XML","ONI"); + this->commandMap.insertMulti("xml->ONI","XML"); + this->commandMap.insertMulti("xml->XML","ONI"); ////////////////////////////////////////////////////////////////////////Textures Commands - this->commandMap.insert("textures->DAT / ONI->DDS","-extract:dds"); - this->commandMap.insert("textures->DAT / ONI->TGA","-extract:tga"); - this->commandMap.insert("textures->DAT / ONI->PNG","-extract:png"); - this->commandMap.insert("textures->DAT / ONI->JPG","-extract:jpg"); - this->commandMap.insert("textures->DDS / TGA / PNG / JPG->ONI","-create:txmp"); + this->commandMap.insert("textures->DAT / TXMP ONI->DDS","-extract:dds"); + this->commandMap.insert("textures->DAT / TXMP ONI->TGA","-extract:tga"); + this->commandMap.insert("textures->DAT / TXMP ONI->PNG","-extract:png"); + this->commandMap.insert("textures->DAT / TXMP ONI->JPG","-extract:jpg"); + this->commandMap.insert("textures->TGA / DDS / PNG / JPG->TXMP ONI","-create:txmp"); //######################Textures Options this->commandMap.insert("textures->"+ui->rbBGR32->text(),"-format:bgr32"); this->commandMap.insert("textures->"+ui->rbBGRA32->text(),"-format:bgra32"); @@ -765,135 +847,198 @@ void MainWindow::mapCommands(){ this->commandMap.insert("textures->"+ui->cbLarge->text(),"-large"); this->commandMap.insert("textures->"+ui->cbEnvMap->text(),"-envmap:"); //Possible Combinations - this->commandMap.insertMulti("textures->DAT / ONI","DDS"); - this->commandMap.insertMulti("textures->DAT / ONI","TGA"); - this->commandMap.insertMulti("textures->DAT / ONI","PNG"); - this->commandMap.insertMulti("textures->DAT / ONI","JPG"); - this->commandMap.insertMulti("textures->DDS / TGA / PNG / JPG","ONI"); - - ////////////////////////////////////////////////////////////////////////Models Commands - this->commandMap.insert("models->ONI->OBJ","-extract:obj"); - this->commandMap.insert("models->ONI->DAE","-extract:dae -search "+Util::insertQuotes(this->AeLocation+"/GameDataFolder/level0_Final")); - this->commandMap.insert("models->OBJ->ONI","-create:m3gm"); - this->commandMap.insert("models->DAE->ONI","-create:trbs"); - //######################Models Options - this->commandMap.insert("models->"+ui->cbCellShading->text(),"-cel"); - this->commandMap.insert("models->"+ui->cbNormals->text(),"-normals"); - this->commandMap.insert("models->"+ui->cbTexture->text(),"-tex:"); - this->commandMap.insert("models->"+ui->cbWithAnimation->text(),"-anim:"); - this->commandMap.insert("models->No Animation","-noanim"); //No label with this name so can't be dynamic + this->commandMap.insertMulti("textures->DAT / TXMP ONI","TGA"); + this->commandMap.insertMulti("textures->DAT / TXMP ONI","DDS"); + this->commandMap.insertMulti("textures->DAT / TXMP ONI","PNG"); + this->commandMap.insertMulti("textures->DAT / TXMP ONI","JPG"); + this->commandMap.insertMulti("textures->TGA / DDS / PNG / JPG","TXMP ONI"); + + ////////////////////////////////////////////////////////////////////////Characters Commands + this->commandMap.insert("characters->TRAM ONI->XML / XML & DAE","-extract:xml"); + this->commandMap.insert("characters->TRBS / ONCC ONI->DAE","-extract:dae"); + this->commandMap.insert("characters->TRBS XML->TRBS ONI","-create"); + this->commandMap.insert("characters->TRBS DAE->TRBS ONI","-create:trbs"); + this->commandMap.insert("characters->FILM DAT->XML","film2xml"); + + //######################Characters Options + this->commandMap.insert("characters->"+ui->cbWithTRBS_ONCC->text(),"-anim-body:"); + this->commandMap.insert("characters->"+ui->cbCellShading->text(),"-cel"); + this->commandMap.insert("characters->"+ui->cbNormals->text(),"-normals"); //Possible Combinations - this->commandMap.insertMulti("models->ONI","OBJ"); - this->commandMap.insertMulti("models->ONI","DAE"); - this->commandMap.insertMulti("models->OBJ","ONI"); - this->commandMap.insertMulti("models->DAE","ONI"); - - ////////////////////////////////////////////////////////////////////////Animations Commands - this->commandMap.insert("animations->ONI->DAE","-extract:dae"); - this->commandMap.insert("animations->FILM DAT->XML","film2xml"); - //######################Animations Options - this->commandMap.insert("animations->"+ui->cbCamera->text(),"-geom:camera"); - this->commandMap.insert("animations->"+ui->cbGeometry->text(),"-geom:"); + this->commandMap.insertMulti("characters->TRAM ONI","XML / XML & DAE"); + this->commandMap.insertMulti("characters->TRBS / ONCC ONI","DAE"); + this->commandMap.insertMulti("characters->DAE","TRBS ONI"); + this->commandMap.insertMulti("characters->TRBS DAE","TRBS ONI"); + this->commandMap.insertMulti("characters->TRBS XML","TRBS ONI"); + this->commandMap.insertMulti("characters->FILM DAT","XML"); + + ////////////////////////////////////////////////////////////////////////Objects Commands + this->commandMap.insert("objects->M3GM ONI->OBJ","-extract:obj"); + this->commandMap.insert("objects->M3GM ONI->DAE","-extract:dae"); + this->commandMap.insert("objects->ONWC ONI->OBJ","-extract:obj"); + this->commandMap.insert("objects->ONWC ONI->DAE","-extract:dae"); + this->commandMap.insert("objects->OBAN ONI (cam)->DAE","-extract:dae"); + this->commandMap.insert("objects->OBJ->M3GM ONI","-create:m3gm"); + //######################Characters Options + this->commandMap.insert("objects->"+ui->cbTexture->text(),"-tex:"); + this->commandMap.insert("objects->"+ui->cbWithAnimation->text(),"-geom:"); //Possible Combinations - this->commandMap.insertMulti("animations->ONI","DAE"); - this->commandMap.insertMulti("animations->DAE","ONI"); - this->commandMap.insertMulti("animations->FILM DAT","XML"); + this->commandMap.insertMulti("objects->M3GM ONI","OBJ"); + this->commandMap.insertMulti("objects->M3GM ONI","DAE"); + this->commandMap.insertMulti("objects->ONWC ONI","OBJ"); + this->commandMap.insertMulti("objects->ONWC ONI","DAE"); + this->commandMap.insertMulti("objects->OBAN ONI (cam)","DAE"); + this->commandMap.insertMulti("objects->OBJ","M3GM ONI"); + ////////////////////////////////////////////////////////////////////////Levels Commands - this->commandMap.insert("levels->ONI->DAE","-extract:dae -search "+Util::insertQuotes(this->AeLocation+"/GameDataFolder/level0_Final")); - this->commandMap.insert("levels->DAE->ONI","-create:akev"); + this->commandMap.insert("levels->DAT->ONI FILES","-export"); + //this->commandMap.insert("levels->ONI FILES->DAT","-import"); //Not used. + this->commandMap.insert("levels->ONI FILES->DAT(PC)","-import:nosep"); + this->commandMap.insert("levels->ONI FILES->DAT(demoPCMAC)","-import:sep"); + this->commandMap.insert("levels->AKEV ONI->DAE","-extract:dae"); + this->commandMap.insert("levels->DAE->AKEV ONI","-create:akev"); this->commandMap.insert("levels->MASTER XML->DAT","-create:level"); this->commandMap.insert("levels->MASTER XML->ONI FILES","-create:level"); //######################Levels Options this->commandMap.insert("levels->"+ui->cbGridsLevels->text(),"-grid:create"); //Possible Combinations - this->commandMap.insertMulti("levels->ONI","DAE"); - this->commandMap.insertMulti("levels->DAE","ONI"); + this->commandMap.insertMulti("levels->DAT","ONI FILES"); + this->commandMap.insertMulti("levels->ONI FILES","DAT"); + this->commandMap.insertMulti("levels->AKEV ONI","DAE"); + this->commandMap.insertMulti("levels->DAE","AKEV ONI"); this->commandMap.insertMulti("levels->MASTER XML","DAT"); this->commandMap.insertMulti("levels->MASTER XML","ONI FILES"); ////////////////////////////////////////////////////////////////////////Misc Commands - this->commandMap.insert("misc->DAT / ONI->WAV","-extract:wav"); - this->commandMap.insert("misc->DAT / ONI->AIF","-extract:aif"); - this->commandMap.insert("misc->DAT / ONI->TXT","-extract:txt"); - this->commandMap.insert("misc->WAV / AIF->ONI","-create"); - this->commandMap.insert("misc->TXT->ONI","-create:subt"); + this->commandMap.insert("misc->DAT / SNDD ONI->WAV","-extract:wav"); + this->commandMap.insert("misc->DAT / SNDD ONI->AIF","-extract:aif"); + this->commandMap.insert("misc->DAT / SUBT ONI->TXT","-extract:txt"); + this->commandMap.insert("misc->WAV / AIF->SNDD ONI","-create"); + this->commandMap.insert("misc->TXT->SUBT ONI","-create:subt"); //Possible Combinations - this->commandMap.insertMulti("misc->DAT / ONI","WAV"); - this->commandMap.insertMulti("misc->DAT / ONI","AIF"); - this->commandMap.insertMulti("misc->DAT / ONI","TXT"); - this->commandMap.insertMulti("misc->WAV / AIF","ONI"); - this->commandMap.insertMulti("misc->TXT","ONI"); + this->commandMap.insertMulti("misc->DAT / SNDD ONI","WAV"); + this->commandMap.insertMulti("misc->DAT / SNDD ONI","AIF"); + this->commandMap.insertMulti("misc->DAT / SUBT ONI","TXT"); + this->commandMap.insertMulti("misc->WAV / AIF","SNDD ONI"); + this->commandMap.insertMulti("misc->TXT","SUBT ONI"); } -void MainWindow::on_cbFromGeneral_currentIndexChanged(const QString &arg1) +void MainWindow::on_cbFromXML_currentIndexChanged(const QString &arg1) { - updateComboBox(arg1, ui->cbToGeneral, "general"); + updateComboBox(arg1, ui->cbToXML); } + void MainWindow::on_cbFromTextures_currentIndexChanged(const QString &arg1) { - //Options are only used for DAT/ONI -> Image - if(QString::compare(arg1,"DAT / ONI",Qt::CaseSensitive)==0){ //case sensitive is faster - ui->gbTextures->setEnabled(false); - } - else{ - ui->gbTextures->setEnabled(true); - } - - updateComboBox(arg1, ui->cbToTextures, "textures"); + updateComboBox(arg1, ui->cbToTextures); } -void MainWindow::on_cbFromModels_currentIndexChanged(const QString &arg1) +void MainWindow::on_cbFromObjects_currentIndexChanged(const QString &arg1) { - - ui->cbCellShading->setEnabled(false); - ui->cbCellShading->setChecked(false); - ui->cbNormals->setEnabled(false); - ui->cbNormals->setChecked(false); - ui->cbTexture->setEnabled(false); - ui->cbTexture->setChecked(false); - ui->cbWithAnimation->setEnabled(false); - ui->cbWithAnimation->setChecked(false); - - if(QString::compare(arg1,"OBJ",Qt::CaseSensitive)==0){ //case sensitive is faster - ui->cbTexture->setEnabled(true); - } - else if(QString::compare(arg1,"DAE",Qt::CaseSensitive)==0){ - ui->cbCellShading->setEnabled(true); - ui->cbNormals->setEnabled(true); - } - - updateComboBox(arg1, ui->cbToModels, "models"); + updateComboBox(arg1, ui->cbToObjects); } -void MainWindow::on_cbFromAnimations_currentIndexChanged(const QString &arg1) +void MainWindow::on_cbFromCharacters_currentIndexChanged(const QString &arg1) { - ui->cbCamera->setEnabled(false); - ui->cbCamera->setChecked(false); - ui->cbGeometry->setEnabled(false); - ui->cbGeometry->setChecked(false); - - if(QString::compare(arg1,"ONI",Qt::CaseSensitive)==0){ //case sensitive is faster - ui->cbCamera->setEnabled(true); - ui->cbGeometry->setEnabled(true); - } - - updateComboBox(arg1, ui->cbToAnimations, "animations"); + updateComboBox(arg1, ui->cbToCharacters); } void MainWindow::on_cbFromLevels_currentIndexChanged(const QString &arg1) { - updateComboBox(arg1, ui->cbToLevels, "levels"); + updateComboBox(arg1, ui->cbToLevels); } void MainWindow::on_cbFromMisc_currentIndexChanged(const QString &arg1) { - updateComboBox(arg1, ui->cbToMisc, "misc"); + updateComboBox(arg1, ui->cbToMisc); } -void MainWindow::updateComboBox(const QString &arg1, QComboBox *comboBox, const QString &identifier){ +void MainWindow::updateComboBox(const QString &arg1, QComboBox *comboBox){ + + QString identifier; + + if(comboBox == ui->cbToXML){ + identifier = ui->tabWidget->tabText(XMLTabIndex); + } + else if(comboBox == ui->cbToTextures){ + identifier = ui->tabWidget->tabText(TexturesTabIndex); + + //Options are only used for DAT/ONI -> Image + if(QString::compare(arg1,"DAT / ONI",Qt::CaseSensitive)==0){ //case sensitive is faster + ui->gbTextures->setEnabled(false); + } + else{ + ui->gbTextures->setEnabled(true); + } + } + else if(comboBox == ui->cbToCharacters){ + identifier = ui->tabWidget->tabText(CharactersTabIndex); + + ui->cbWithTRBS_ONCC->setEnabled(false); + ui->cbWithTRBS_ONCC->setChecked(false); + ui->cbCellShading->setEnabled(false); + ui->cbCellShading->setChecked(false); + ui->cbNormals->setEnabled(false); + ui->cbNormals->setChecked(false); +//#error add drag and drop to Extract TRAM with TRBS/ONCC + if(QString::compare(arg1,"TRAM ONI",Qt::CaseSensitive)==0){ //case sensitive is faster + ui->cbWithTRBS_ONCC->setEnabled(true); + } + else if(QString::compare(arg1,"TRBS DAE",Qt::CaseSensitive)==0){ + ui->cbNormals->setEnabled(true); + ui->cbCellShading->setEnabled(true); + } + + } + else if(comboBox == ui->cbToObjects){ + identifier = ui->tabWidget->tabText(ObjectsTabIndex); + + ui->cbTexture->setEnabled(false); + ui->cbTexture->setChecked(false); + ui->cbWithAnimation->setEnabled(false); + ui->cbWithAnimation->setChecked(false); + + if(QString::compare(arg1,"M3GM ONI",Qt::CaseSensitive)==0){ //case sensitive is faster + ui->cbWithAnimation->setEnabled(true); + } + else if(QString::compare(arg1,"OBJ",Qt::CaseSensitive)==0){ + ui->cbTexture->setEnabled(true); + } + } + else if(comboBox == ui->cbToLevels){ + identifier = ui->tabWidget->tabText(LevelsTabIndex); + + ui->cbSpecificFilesLevels->setEnabled(false); + ui->cbSpecificFilesLevels->setChecked(false); + ui->cbDatLevels->setEnabled(false); + ui->cbDatLevels->setChecked(false); + ui->cbBnvLevels->setEnabled(false); + ui->cbBnvLevels->setChecked(false); + ui->cbAdditionalSourcesLevels->setEnabled(false); + ui->cbAdditionalSourcesLevels->setChecked(false); + ui->cbGridsLevels->setEnabled(false); + ui->cbGridsLevels->setChecked(false); + + if(arg1=="DAT"){ //case sensitive is faster + ui->cbSpecificFilesLevels->setEnabled(true); + } + else if(arg1=="ONI FILES"){ //case sensitive is faster + ui->cbDatLevels->setEnabled(true); + } + else if(arg1=="DAE"){ + ui->cbBnvLevels->setEnabled(true); + ui->cbAdditionalSourcesLevels->setEnabled(true); + } + } + else{ // Misc + identifier = ui->tabWidget->tabText(MiscTabIndex); + } + + identifier = identifier.toLower(); // get current tab title text (lower case) + comboBox->clear(); QStringList toUpdate=QStringList(); @@ -920,9 +1065,9 @@ void MainWindow::on_actionMac_Windows_de ui->actionWindows->setChecked(false); } -void MainWindow::on_pbRemoveSourceGeneral_clicked() +void MainWindow::on_pbRemoveSourceXML_clicked() { - removeTableContents( ui->twSourcesGeneral); + removeTableContents( ui->twSourcesXML); } void MainWindow::on_pbRemoveSourceTextures_clicked() @@ -930,14 +1075,14 @@ void MainWindow::on_pbRemoveSourceTextur removeTableContents(ui->twSourcesTextures); } -void MainWindow::on_pbRemoveSourceModels_clicked() +void MainWindow::on_pbRemoveSourceObjects_clicked() { - removeTableContents(ui->twSourcesModels); + removeTableContents(ui->twSourcesObjects); } -void MainWindow::on_pbRemoveSourceAnimations_clicked() +void MainWindow::on_pbRemoveSourceCharacters_clicked() { - removeTableContents(ui->twSourcesAnimations); + removeTableContents(ui->twSourcesCharacters); } void MainWindow::on_pbRemoveSourceLevels_clicked() @@ -950,9 +1095,9 @@ void MainWindow::on_pbRemoveSourceMisc_c removeTableContents(ui->twSourcesMisc); } -void MainWindow::on_pbClearSourcesGeneral_clicked() +void MainWindow::on_pbClearSourcesXML_clicked() { - clearTableContents(ui->twSourcesGeneral); + clearTableContents(ui->twSourcesXML); } void MainWindow::on_pbClearSourcesTextures_clicked() @@ -960,14 +1105,14 @@ void MainWindow::on_pbClearSourcesTextur clearTableContents(ui->twSourcesTextures); } -void MainWindow::on_pbClearSourcesModels_clicked() +void MainWindow::on_pbClearSourcesObjects_clicked() { - clearTableContents(ui->twSourcesModels); + clearTableContents(ui->twSourcesObjects); } -void MainWindow::on_pbClearSourcesAnimations_clicked() +void MainWindow::on_pbClearSourcesCharacters_clicked() { - clearTableContents(ui->twSourcesAnimations); + clearTableContents(ui->twSourcesCharacters); } void MainWindow::on_pbClearSourcesLevels_clicked() @@ -983,33 +1128,63 @@ void MainWindow::on_pbClearSourcesMisc_c void MainWindow::removeTableContents(DropTableWidget *myTable){ int size = myTable->selectionModel()->selectedRows().size(); + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton; // default button for clear asking question, only customizable in mac os + if(size==0){ Util::showPopUp("Select a row first."); return; } - if(Util::showQuestionPopUp(this,"Are you sure you want to delete the selected rows?")){ +#ifdef Q_OS_MAC + if(this->useYesAsDefaultWhenRemovingItems){ + defaultButton = QMessageBox::Yes; + } + else{ + defaultButton = QMessageBox::No; + } +#endif + + + if(Util::showQuestionPopUp(this,"Are you sure you want to delete the selected rows?",defaultButton)){ for(int i=0; iremoveRow(myTable->selectedItems().at(size-i-1)->row()); myTable->removeRow(myTable->selectionModel()->selectedRows().at(size-i-1).row()); } updateItemsLoaded(myTable); + rowsWereChangedInDropTableWidget(); } } void MainWindow::clearTableContents(DropTableWidget *myTable){ + + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton; // default button for clear asking question, only customizable in mac os + if(myTable->rowCount()==0){ Util::showPopUp("Nothing to clear."); return; } - if(Util::showQuestionPopUp(this,"Are you sure you want to clear the content?")){ - myTable->clearContents(); - myTable->setRowCount(0); +#ifdef Q_OS_MAC + if(this->useYesAsDefaultWhenRemovingItems){ + defaultButton = QMessageBox::Yes; } - updateItemsLoaded(myTable); + else{ + defaultButton = QMessageBox::No; + } +#endif + + if(Util::showQuestionPopUp(this,"Are you sure you want to clear the content?",defaultButton)){ + clearTableNoPrompt(myTable); + updateItemsLoaded(myTable); + rowsWereChangedInDropTableWidget(); + } + } +void MainWindow::clearTableNoPrompt(DropTableWidget *myTable){ + myTable->clearContents(); + myTable->setRowCount(0); +} void MainWindow::on_actionPreferences_triggered() { @@ -1020,77 +1195,40 @@ void MainWindow::on_actionPreferences_tr void MainWindow::closeEvent(QCloseEvent *event){ - if(this->vagoSettings->value("ConfirmExit").toBool()){ - if(!Util::showQuestionPopUp(this,"Exit Vago?")){ + if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){ + QMessageBox::StandardButton result = askToSaveCurrentProject(); + if(result == QMessageBox::StandardButton::Cancel){ event->ignore(); - } - } -} - -void MainWindow::on_cbToGeneral_currentIndexChanged(const QString &arg1) -{ - - ui->cbDatGeneral->setEnabled(false); - ui->cbDatGeneral->setChecked(false); - ui->cbTRAMGeneral->setEnabled(false); - ui->cbTRAMGeneral->setChecked(false); - - if(QString::compare(ui->cbFromGeneral->currentText(),"ONI",Qt::CaseSensitive)==0){ - if(QString::compare(arg1,"DAT",Qt::CaseSensitive)==0){ - ui->cbDatGeneral->setEnabled(true); - } - else{ - ui->cbTRAMGeneral->setEnabled(true); + return; } } + // Exit application (this will also close all other windows which don't have parent, for instance ManualCommands) + QApplication::quit(); } -void MainWindow::on_cbToModels_currentIndexChanged(const QString &arg1) -{ - ui->cbWithAnimation->setEnabled(false); - ui->cbWithAnimation->setChecked(false); +QMessageBox::StandardButton MainWindow::askToSaveCurrentProject(){ + QMessageBox::StandardButton result = + Util::showQuestionPopUpWithCancel(this,"There are unsaved changes. Do you want to save the current project?", QMessageBox::StandardButton::Yes); - if(arg1=="DAE"){ - ui->cbWithAnimation->setEnabled(true); + if(result == QMessageBox::StandardButton::Yes){ + on_actionSave_triggered(); } + + return result; } void MainWindow::on_cbToLevels_currentIndexChanged(const QString &arg1) { - ui->cbDatLevels->setEnabled(false); - ui->cbDatLevels->setChecked(false); - ui->cbBnvLevels->setEnabled(false); - ui->cbBnvLevels->setChecked(false); - ui->cbAdditionalSourcesLevels->setEnabled(false); - ui->cbAdditionalSourcesLevels->setChecked(false); - ui->cbGridsLevels->setEnabled(false); - ui->cbGridsLevels->setChecked(false); - if(ui->cbFromLevels->currentText()=="MASTER XML" && arg1=="DAT"){ ui->cbDatLevels->setEnabled(true); } - else if(ui->cbFromLevels->currentText()=="DAE" && arg1=="ONI"){ - ui->cbBnvLevels->setEnabled(true); - ui->cbAdditionalSourcesLevels->setEnabled(true); + else if(ui->cbFromLevels->currentText()=="MASTER XML" && arg1=="ONI FILES"){ + ui->cbDatLevels->setEnabled(false); + ui->cbDatLevels->setChecked(false); } -} -void MainWindow::on_cbDatGeneral_toggled(bool checked) -{ - ui->leTargetDatGeneral->setEnabled(checked); -} - -void MainWindow::on_cbTRAMGeneral_toggled(bool checked) -{ - ui->leTRAMGeneral->setEnabled(checked); - if(checked){ - QString file=QFileDialog::getOpenFileName(this,"Choose the TRAM.oni file...","./" , "All Files (*.*)"); - if(!file.isEmpty()){ - ui->leTRAMGeneral->setText(file); - } - } } void MainWindow::on_cbDatLevels_toggled(bool checked) @@ -1103,7 +1241,7 @@ void MainWindow::on_cbBnvLevels_toggled( ui->leBnvLevels->setEnabled(checked); ui->cbGridsLevels->setEnabled(checked); ui->cbGridsLevels->setChecked(checked); - if(checked){ + if(checked && !projectIsLoading){ QString file=QFileDialog::getOpenFileName(this,"Choose the BNV.dae file...","./" , "All Files (*.*)"); if(!file.isEmpty()){ ui->leBnvLevels->setText(file); @@ -1115,7 +1253,7 @@ void MainWindow::on_cbAdditionalSourcesL { ui->leAdditSourcesLevels->setEnabled(checked); - if(checked){ + if(checked && !projectIsLoading){ QStringList filesSelected=QFileDialog::getOpenFileNames(this,"Choose the additional .dae files...","./" , "All Files (*.*)"); QString filesJoined; int size=filesSelected.size(); @@ -1131,46 +1269,40 @@ void MainWindow::on_cbAdditionalSourcesL } } +void MainWindow::on_cbWithTRBS_ONCC_toggled(bool checked) +{ + ui->leTRBS_ONCC->setEnabled(checked); +} + void MainWindow::on_actionCheck_OniSplit_version_triggered() { - QProcess *myProcess = new QProcess(); - myProcess->start(GlobalVars::OniSplitExeName+" -version"); - myProcess->waitForFinished(-1); - QString result=myProcess->readAllStandardOutput(); - delete myProcess; - Util::showPopUp("This Vago version was built with base in OniSplit version "+GlobalVars::BuiltOniSplitVersion+"\n\nActual version is:\n"+result); + QProcess myProcess; + myProcess.setWorkingDirectory(UtilVago::getAppPath()); + myProcess.start(UtilVago::getOniSplitExecutable()+" -version"); + myProcess.waitForFinished(); + + QString result=myProcess.readAllStandardOutput(); + + Util::showPopUp("This Vago version was built with base in OniSplit version "+GlobalVars::BuiltOniSplitVersion+"\n\nCurrent version is:\n"+result.trimmed()); } void MainWindow::on_actionCheck_xmlTools_version_triggered() { - QProcess *myProcess = new QProcess(); - myProcess->start(GlobalVars::XmlToolsExeName+" version"); - myProcess->waitForFinished(-1); - QString result=myProcess->readLine(); - delete myProcess; - Util::showPopUp("This Vago version was built with base in xmlTools version "+GlobalVars::BuiltXmlToolsVersion+"\n\nActual version is:\n"+result); + QProcess myProcess; + myProcess.setWorkingDirectory(UtilVago::getAppPath()); + myProcess.start(UtilVago::getXmlToolsExecutable()+" --version"); + myProcess.waitForFinished(); + QString result=myProcess.readLine(); + + Util::showPopUp("This Vago version was built with base in XmlTools version "+GlobalVars::BuiltXmlToolsVersion+"\n\nCurrent version is:\n"+result.trimmed()); } /** Update items loaded - **/ -void MainWindow::on_tabWidget_selected(const QString &arg1) +**/ +void MainWindow::on_tabWidget_currentChanged(int) { - if(arg1.compare("General",Qt::CaseSensitive)==0){ //case sentive is faster - updateItemsLoaded(ui->twSourcesGeneral); - } - else if(arg1.compare("Textures",Qt::CaseSensitive)==0){ - updateItemsLoaded(ui->twSourcesTextures); - } - else if(arg1.compare("Models",Qt::CaseSensitive)==0){ - updateItemsLoaded(ui->twSourcesModels); - } - else if(arg1.compare("Levels",Qt::CaseSensitive)==0){ - updateItemsLoaded(ui->twSourcesLevels); - } - else{ - updateItemsLoaded(ui->twSourcesMisc); - } + updateItemsLoaded(getCurrentTableWidget()); } void MainWindow::updateItemsLoaded(DropTableWidget *currentTable){ @@ -1180,10 +1312,19 @@ void MainWindow::updateItemsLoaded(DropT this->itemsLoaded->setText(QString().setNum(numItems)+ (numItems==1?" item ":" items ") +"loaded"); } +void MainWindow::rowsWereChangedInDropTableWidget(){ + // We have changed rows, we have now unsaved changes. + if(!this->unsavedChangesExist){ + this->unsavedChangesExist = true; + setVagoWindowTitle(); + } +} + void MainWindow::on_tbCommand_clicked() { - //Show preferences - ManualCommands *commandsWindow = new ManualCommands(this); + //We pass no parent because we want to have an independent window for ManualCommands, + //so we can minimize it or maximize indepently from the MainWindow + ManualCommands *commandsWindow = new ManualCommands(); commandsWindow->show(); //it destroys itself when finished. } @@ -1223,27 +1364,113 @@ void MainWindow::on_actionOther_triggere void MainWindow::on_actionView_log_triggered() { - Util::openLogFile(); + UtilVago::openLogFile(); +} + +void MainWindow::on_actionOpen_AE_folder_triggered() +{ + QDesktopServices::openUrl(QUrl("file:///"+this->AeLocation)); +} + +void MainWindow::on_actionSave_Project_triggered() +{ + + QString filePath = QFileDialog::getSaveFileName(this, tr("Save File"), + this->vagoSettings->value("LastProjectPath").toString(), + tr("Vago project files (*.vgp)")); + + if(!filePath.isEmpty()){ + saveProjectState(filePath); + } + +} + +// New Project +void MainWindow::on_actionNew_Project_triggered() +{ + if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){ + QMessageBox::StandardButton result = askToSaveCurrentProject(); + if(result == QMessageBox::StandardButton::Cancel){ + return; + } + } + + QList myTables = getAllTableWidgets(); + + for(DropTableWidget* const currTable : myTables){ + clearTableNoPrompt(currTable); + } + + this->lastProjectFilePath=""; // clear last project file path + this->unsavedChangesExist = false; + + setVagoWindowTitle(); // update vago title +} + +void MainWindow::on_actionSave_triggered() +{ + if(this->lastProjectFilePath.isEmpty()){ + on_actionSave_Project_triggered(); + return; + } + + saveProjectState(this->lastProjectFilePath); +} + +void MainWindow::on_actionLoad_Project_triggered() +{ + + QString filePath = QFileDialog::getOpenFileName(this, tr("Load File"), + this->vagoSettings->value("LastProjectPath").toString(), + tr("Vago project files (*.vgp)")); + if(!filePath.isEmpty()){ + loadProjectState(filePath); + } +} + +void MainWindow::on_actionProject1_triggered() +{ + loadProjectState(this->ui->actionProject1->text()); +} + +void MainWindow::on_actionProject2_triggered() +{ + loadProjectState(this->ui->actionProject2->text()); +} + +void MainWindow::on_actionProject3_triggered() +{ + loadProjectState(this->ui->actionProject3->text()); +} + +void MainWindow::on_actionProject4_triggered() +{ + loadProjectState(this->ui->actionProject4->text()); +} + +void MainWindow::on_actionProject5_triggered() +{ + loadProjectState(this->ui->actionProject5->text()); } QString MainWindow::getTypeConversion(DropTableWidget *myTable){ QString from,to; - if(myTable==ui->twSourcesGeneral){ - from=ui->cbFromGeneral->currentText(); - to=ui->cbToGeneral->currentText(); + if(myTable==ui->twSourcesXML){ + from=ui->cbFromXML->currentText(); + to=ui->cbToXML->currentText(); } else if(myTable==ui->twSourcesTextures){ from=ui->cbFromTextures->currentText(); to=ui->cbToTextures->currentText(); } - else if(myTable==ui->twSourcesModels){ - from=ui->cbFromModels->currentText(); - to=ui->cbToModels->currentText(); - } - else if(myTable==ui->twSourcesAnimations){ - from=ui->cbFromAnimations->currentText(); - to=ui->cbToAnimations->currentText(); + else if(myTable==ui->twSourcesObjects){ + from=ui->cbFromObjects->currentText(); + to=ui->cbToObjects->currentText(); + } + else if(myTable==ui->twSourcesCharacters){ + from=ui->cbFromCharacters->currentText(); + to=ui->cbToCharacters->currentText(); } else if(myTable==ui->twSourcesLevels){ from=ui->cbFromLevels->currentText(); @@ -1275,26 +1502,26 @@ void MainWindow::dtContextMenu(DropTable selectedRows << rowItem.row(); } - QMenu *menu = new QMenu(); - QAction *copy = new QAction("Copy",myTable); - QAction *moveUp = new QAction("Move Up",myTable); - QAction *moveDown = new QAction("Move Down",myTable); - QAction *changeOptions = new QAction("Change To Current Options",myTable); - QMenu *changeOutput = new QMenu("Change Output for:"); - QAction *outWorkspace = new QAction("Workspace",myTable); - QAction *outCurrOutput = new QAction("Current Output Folder",myTable); - QAction *outOther = new QAction("Other...",myTable); - QAction *edisable = new QAction("Enable/Disable",myTable); + std::unique_ptr menu = std::make_unique(); + std::unique_ptr copy = std::make_unique("Copy",myTable); + std::unique_ptr moveUp = std::make_unique("Move Up",myTable); + std::unique_ptr moveDown = std::make_unique("Move Down",myTable); + std::unique_ptr changeOptions = std::make_unique("Change To Current Options",myTable); + std::unique_ptr changeOutput = std::make_unique("Change Output for:"); + std::unique_ptr outWorkspace = std::make_unique("Workspace",myTable); + std::unique_ptr outCurrOutput = std::make_unique("Current Output Folder",myTable); + std::unique_ptr outOther = std::make_unique("Other...",myTable); + std::unique_ptr edisable = std::make_unique("Enable/Disable",myTable); - menu->addAction(copy); + menu->addAction(copy.get()); menu->addSeparator(); - menu->addAction(moveUp); - menu->addAction(moveDown); + menu->addAction(moveUp.get()); + menu->addAction(moveDown.get()); menu->addSeparator(); - menu->addAction(changeOptions); - menu->addMenu(changeOutput); - changeOutput->addActions(QList() << outWorkspace << outCurrOutput << outOther); - menu->addAction(edisable); + menu->addAction(changeOptions.get()); + menu->addMenu(changeOutput.get()); + changeOutput->addActions(QList() << outWorkspace.get() << outCurrOutput.get() << outOther.get()); + menu->addAction(edisable.get()); //if it's in the first row it can't be setted up @@ -1318,7 +1545,7 @@ void MainWindow::dtContextMenu(DropTable QAction* selectedOption = menu->exec(event->globalPos()); - if(selectedOption==copy){ + if(selectedOption==copy.get()){ //Let's copy the contents to the clipboard QString toCopy; @@ -1341,24 +1568,26 @@ void MainWindow::dtContextMenu(DropTable QApplication::clipboard()->setText(toCopy); showSuccessStatusMessage(QString::number(size) + (size==1?" item ":" items ")+ "copied to the clipboard"); } - else if(selectedOption==moveUp){ + else if(selectedOption==moveUp.get()){ qSort(selectedRows); //let's order the selections by the row number, so we know exactly how to swap it myTable->swapPositions(selectedRows,-1); + rowsWereChangedInDropTableWidget(); } - else if(selectedOption==moveDown){ + else if(selectedOption==moveDown.get()){ qSort(selectedRows); myTable->swapPositions(selectedRows,+1); + rowsWereChangedInDropTableWidget(); } - else if(selectedOption==changeOptions){ + else if(selectedOption==changeOptions.get()){ changeToCurrentSettings(selectedRows,myTable); } - else if(selectedOption==outWorkspace){ + else if(selectedOption==outWorkspace.get()){ changeItemsOutput(myTable,selectedRows,this->workspaceLocation); } - else if(selectedOption==outCurrOutput){ + else if(selectedOption==outCurrOutput.get()){ changeItemsOutput(myTable,selectedRows,this->outputFolder); } - else if(selectedOption==outOther){ + else if(selectedOption==outOther.get()){ QString newDir=QFileDialog::getExistingDirectory(this,"Choose the folder for the output of the files selected...",this->AeLocation+"/GameDataFolder"); newDir=Util::normalizePath(newDir); @@ -1370,7 +1599,7 @@ void MainWindow::dtContextMenu(DropTable changeItemsOutput(myTable,selectedRows,newDir); } - else if(selectedOption==edisable){ + else if(selectedOption==edisable.get()){ int enabledCount=0, disabledCount=0; @@ -1406,19 +1635,9 @@ void MainWindow::dtContextMenu(DropTable result+=QString::number(disabledCount) + (disabledCount==1?" item ":" items ") + "Disabled"; } + rowsWereChangedInDropTableWidget(); showSuccessStatusMessage(result); } - - delete copy; - delete moveUp; - delete moveDown; - delete changeOptions; - delete outWorkspace; - delete outCurrOutput; - delete outOther; - delete changeOutput; - delete edisable; - delete menu; } void MainWindow::changeToCurrentSettings(QList rows, DropTableWidget* myTable){ @@ -1442,6 +1661,7 @@ void MainWindow::changeToCurrentSettings myTable->updateTableToolTips(row); } + rowsWereChangedInDropTableWidget(); showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed to the current settings"); } @@ -1465,24 +1685,28 @@ void MainWindow::changeItemsOutput(DropT myTable->updateTableToolTips(row); } + rowsWereChangedInDropTableWidget(); showSuccessStatusMessage(QString::number(rows.size()) + (rows.size()==1?" item ":" items ")+ "changed the output to "+(newOutput!=this->workspaceLocation?Util::cutName(newOutput):"Vago workspace")); } QString MainWindow::getCommand(DropTableWidget* myTable, QString myOutputFolder, QString from, QString to , QString file){ - if(myTable==ui->twSourcesGeneral){ //So we only need to parse one command. - return fileParsingGeneral(myOutputFolder,from,to,file); + + QString tabTitle=ui->tabWidget->tabText(ui->tabWidget->currentIndex()).toLower(); // get current tab title + + if(myTable==ui->twSourcesXML){ //So we only need to parse one command. + return fileParsingXML(tabTitle, myOutputFolder,from,to,file); } else if(myTable==ui->twSourcesTextures){ - return fileParsingTextures(myOutputFolder,from,to,file); + return fileParsingTextures(tabTitle, myOutputFolder,from,to,file); } - else if(myTable==ui->twSourcesModels){ - return fileParsingModels(myOutputFolder,from,to,file); + else if(myTable==ui->twSourcesObjects){ + return fileParsingObjects(tabTitle, myOutputFolder,from,to,file); } - else if(myTable==ui->twSourcesAnimations){ - return fileParsingAnimations(myOutputFolder,from,to,file); + else if(myTable==ui->twSourcesCharacters){ + return fileParsingCharacters(tabTitle, myOutputFolder,from,to,file); } else if(myTable==ui->twSourcesLevels){ - return fileParsingLevels(myOutputFolder,from,to,file); + return fileParsingLevels(tabTitle, myOutputFolder,from,to,file); } else{ return fileParsingMisc(myOutputFolder,from,to,file); @@ -1501,17 +1725,23 @@ void MainWindow::connectSlots(){ //This signal is for thread that is working can show the result of a conversion connect(myConverter, SIGNAL(resultConversion(QString,int)), this, SLOT(TresultConversion(QString,int))); + //This signal is for thread that is working notify the gui thread that the conversion was aborted with sucess + connect(myConverter, SIGNAL(conversionAborted()), this, SLOT(TconversionAborted())); + + // This signal is to the user be able to terminate a conversion (OniSplit process in class myConverter will be terminated) + connect(this, SIGNAL(terminateCurrProcess()), myConverter, SLOT(terminateCurrProcess())); + //Drop signal for General table - connect(ui->twSourcesGeneral, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList))); + connect(ui->twSourcesXML, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList))); //Drop signal for Textures table connect(ui->twSourcesTextures, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList))); - //Drop signal for Models table - connect(ui->twSourcesModels, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList))); + //Drop signal for Objects table + connect(ui->twSourcesObjects, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList))); - //Drop signal for Animations table - connect(ui->twSourcesAnimations, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList))); + //Drop signal for Characters table + connect(ui->twSourcesCharacters, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList))); //Drop signal for Levels table connect(ui->twSourcesLevels, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList))); @@ -1520,16 +1750,16 @@ void MainWindow::connectSlots(){ connect(ui->twSourcesMisc, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addFilesSource(DropTableWidget*,QStringList))); //Context menu for General table - connect(ui->twSourcesGeneral, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*))); + connect(ui->twSourcesXML, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*))); //Context menu for Textures table connect(ui->twSourcesTextures, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*))); - //Context menu for Models table - connect(ui->twSourcesModels, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*))); + //Context menu for Objects table + connect(ui->twSourcesObjects, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*))); - //Context menu for Animations table - connect(ui->twSourcesAnimations, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*))); + //Context menu for Characters table + connect(ui->twSourcesCharacters, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*))); //Context menu for Levels table connect(ui->twSourcesLevels, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*))); @@ -1538,4 +1768,518 @@ void MainWindow::connectSlots(){ connect(ui->twSourcesMisc, SIGNAL(dtContextMenu(DropTableWidget*,QContextMenuEvent*)), this, SLOT(dtContextMenu(DropTableWidget*,QContextMenuEvent*))); } +void MainWindow::saveProjectState(const QString &filePath) +{ + + QList tableWidgets = getAllTableWidgets(); + + pugi::xml_document doc; + + pugi::xml_node rootNode = doc.append_child("VagoProject"); + rootNode.append_attribute("vagoVersion").set_value(GlobalVars::LastCompatibleVersion.toUtf8().constData()); + + foreach(DropTableWidget* const &myTable, tableWidgets){ + saveProjectWidget(rootNode, myTable); + } + + if(!doc.save_file(filePath.toUtf8().constData(), PUGIXML_TEXT("\t"), pugi::format_default | pugi::format_write_bom, pugi::xml_encoding::encoding_utf8)){ + UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error ocurred while trying to save the project file. Please try another path."); + return; + } + + this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path()); + + this->lastProjectFilePath = filePath; + this->unsavedChangesExist = false; + + addNewRecentProject(filePath); + + setVagoWindowTitle(); + + showSuccessStatusMessage("Project saved sucessfully."); +} + +void MainWindow::saveProjectWidget(pugi::xml_node &rootNode, DropTableWidget* table) +{ + QString from; + QString to; + QString tabName = getTabNameByTableWidget(table); + + pugi::xml_node currentNodeTable = rootNode.append_child("tempName"); + pugi::xml_node options; + + if(table==ui->twSourcesXML){ //So we only need to parse one command. + from = ui->cbFromXML->currentText().toUtf8().constData(); + to = ui->cbToXML->currentText().toUtf8().constData(); + } + else if(table==ui->twSourcesTextures){ + from = ui->cbFromTextures->currentText().toUtf8().constData(); + to = ui->cbToTextures->currentText().toUtf8().constData(); + options = currentNodeTable.append_child("Options"); + options.append_attribute("type").set_value(Util::qStrToCstr(getTextureRBCheckedTypeTexture()->text())); + options.append_attribute("genMipMaps").set_value(Util::boolToCstr(ui->cbMipMapsTextures->isChecked())); + options.append_attribute("noUwrap").set_value(Util::boolToCstr(ui->cbNoUwrap->isChecked())); + options.append_attribute("noVwrap").set_value(Util::boolToCstr(ui->cbNoVwrap->isChecked())); + options.append_attribute("large").set_value(Util::boolToCstr(ui->cbLarge->isChecked())); + options.append_attribute("envMap").set_value(Util::boolToCstr(ui->cbEnvMap->isChecked())); + options.append_attribute("envMapValue").set_value(Util::qStrToCstr(ui->leEnvMapTexture->text())); + } + else if(table==ui->twSourcesCharacters){ + from = ui->cbFromCharacters->currentText().toUtf8().constData(); + to = ui->cbToCharacters->currentText().toUtf8().constData(); + options = currentNodeTable.append_child("Options"); + options.append_attribute("cellShading").set_value(Util::boolToCstr(ui->cbCellShading->isChecked())); + options.append_attribute("normals").set_value(Util::boolToCstr(ui->cbNormals->isChecked())); + options.append_attribute("extractTRBSONCC").set_value(Util::boolToCstr(ui->cbWithTRBS_ONCC->isChecked())); + options.append_attribute("extractTRBSONCCValue").set_value(Util::qStrToCstr(ui->leTRBS_ONCC->text())); + } + else if(table==ui->twSourcesObjects){ + from = ui->cbFromObjects->currentText().toUtf8().constData(); + to = ui->cbToObjects->currentText().toUtf8().constData(); + options = currentNodeTable.append_child("Options"); + options.append_attribute("texture").set_value(Util::boolToCstr(ui->cbTexture->isChecked())); + options.append_attribute("textureValue").set_value(Util::qStrToCstr(ui->leTextureName->text())); + options.append_attribute("withAnimation").set_value(Util::boolToCstr(ui->cbWithAnimation->isChecked())); + options.append_attribute("withAnimationValue").set_value(Util::qStrToCstr(ui->leAnimationName->text())); + } + else if(table==ui->twSourcesLevels){ + from = ui->cbFromLevels->currentText().toUtf8().constData(); + to = ui->cbToLevels->currentText().toUtf8().constData(); + options = currentNodeTable.append_child("Options"); + options.append_attribute("extractWithFiles").set_value(Util::boolToCstr(ui->cbSpecificFilesLevels->isChecked())); + options.append_attribute("extractWithFilesValue").set_value(Util::qStrToCstr(ui->leSpecificFilesLevels->text())); + options.append_attribute("datFilename").set_value(Util::boolToCstr(ui->cbDatLevels->isChecked())); + options.append_attribute("datFilenameValue").set_value(Util::qStrToCstr(ui->leTargetDatLevels->text())); + options.append_attribute("bnvSource").set_value(Util::boolToCstr(ui->cbBnvLevels->isChecked())); + options.append_attribute("bnvSourceValue").set_value(Util::qStrToCstr(ui->leBnvLevels->text())); + options.append_attribute("generateGrids").set_value(Util::boolToCstr(ui->cbGridsLevels->isChecked())); + options.append_attribute("additionalSources").set_value(Util::boolToCstr(ui->cbAdditionalSourcesLevels->isChecked())); + options.append_attribute("additionalSourcesValue").set_value(Util::qStrToCstr(ui->leAdditSourcesLevels->text())); + } + else{ + from = ui->cbFromMisc->currentText().toUtf8().constData(); + to = ui->cbToMisc->currentText().toUtf8().constData(); + } + + currentNodeTable.set_name(tabName.toUtf8().constData()); + + currentNodeTable.append_attribute("from").set_value(from.toUtf8().constData()); + currentNodeTable.append_attribute("to").set_value(to.toUtf8().constData()); + + + for(int i=0; irowCount(); i++){ + + QString currFileFolder = table->item(i,0)->text(); + QString currFromTo = table->item(i,1)->text(); + QString currCommand = table->item(i,2)->text(); + + pugi::xml_node currentRow = currentNodeTable.append_child("Row"); + + + currentRow.append_attribute("fileFolder").set_value(Util::qStrToCstr(currFileFolder)); + currentRow.append_attribute("fromTo").set_value(Util::qStrToCstr(currFromTo)); + currentRow.append_attribute("command").set_value(Util::qStrToCstr(currCommand)); + + if(table->item(i,2)->background()==table->disabledBackStyle){ + currentRow.append_attribute("disabled").set_value(true); + } + + } +} + +QRadioButton* MainWindow::getTextureRBCheckedTypeTexture() +{ + if(ui->rbBGR32->isChecked()){ + return ui->rbBGR32; + } + else if(ui->rbBGRA32->isChecked()){ + return ui->rbBGRA32; + } + else if(ui->rbBGR555->isChecked()){ + return ui->rbBGR555; + } + else if(ui->rbBGRA5551->isChecked()){ + return ui->rbBGRA5551; + } + else if(ui->rbBGRA444->isChecked()){ + return ui->rbBGRA444; + } + else{ //dxt1 checked + return ui->rbDxt1; + } +} + +QRadioButton* MainWindow::getTextureRBTypeTextureByName(const QString &texType) +{ + if(QString::compare(texType,ui->rbBGR32->text(),Qt::CaseSensitive)==0){ + return ui->rbBGR32; + } + else if(QString::compare(texType,ui->rbBGRA32->text(),Qt::CaseSensitive)==0){ + return ui->rbBGRA32; + } + else if(QString::compare(texType, ui->rbBGR555->text(),Qt::CaseSensitive)==0){ + return ui->rbBGR555; + } + else if(QString::compare(texType,ui->rbBGRA5551->text(),Qt::CaseSensitive)==0){ + return ui->rbBGRA5551; + } + else if(QString::compare(texType,ui->rbBGRA444->text(),Qt::CaseSensitive)==0){ + return ui->rbBGRA444; + } + else{ //dxt1 + return ui->rbDxt1; + } + +} + +void MainWindow::setVagoWindowTitle(){ + + QString vagoTitle = "Vago v"+GlobalVars::AppVersion + " - "; + + if(this->lastProjectFilePath.isEmpty()){ + vagoTitle += "Untitled"; + } + else{ + vagoTitle += Util::cutNameWithoutBackSlash(this->lastProjectFilePath); + } + + if(this->unsavedChangesExist){ + vagoTitle += "*"; + } + + setWindowTitle(vagoTitle); +} + +DropTableWidget* MainWindow::getCurrentTableWidget(){ + + return getTableWidgetByTabName(ui->tabWidget->tabText(ui->tabWidget->currentIndex())); + +} + +DropTableWidget* MainWindow::getTableWidgetByTabName(const QString &tabName){ + + if(tabName.compare("XML",Qt::CaseSensitive)==0){ //case sentive is faster + return ui->twSourcesXML; + } + else if(tabName.compare("Textures",Qt::CaseSensitive)==0){ + return ui->twSourcesTextures; + } + else if(tabName.compare("Characters",Qt::CaseSensitive)==0){ + return ui->twSourcesCharacters; + } + else if(tabName.compare("Objects",Qt::CaseSensitive)==0){ + return ui->twSourcesObjects; + } + else if(tabName.compare("Levels",Qt::CaseSensitive)==0){ + return ui->twSourcesLevels; + } + else{ + return ui->twSourcesMisc; + } + +} + +QString MainWindow::getCurrentTabName(){ + return ui->tabWidget->tabText(ui->tabWidget->currentIndex()); +} + +QString MainWindow::getTabNameByTableWidget(DropTableWidget* table){ + + if(table == ui->twSourcesXML){ + return ui->tabWidget->tabText(XMLTabIndex); + } + else if(table == ui->twSourcesTextures){ + return ui->tabWidget->tabText(TexturesTabIndex); + } + else if(table == ui->twSourcesCharacters){ + return ui->tabWidget->tabText(CharactersTabIndex); + } + else if(table == ui->twSourcesObjects){ + return ui->tabWidget->tabText(ObjectsTabIndex); + } + else if(table == ui->twSourcesLevels){ + return ui->tabWidget->tabText(LevelsTabIndex); + } + else{ + return ui->tabWidget->tabText(MiscTabIndex); + } + +} + +QList MainWindow::getAllTableWidgets() +{ + QList tableWidgets; + + tableWidgets << ui->twSourcesXML << ui->twSourcesTextures << ui->twSourcesCharacters + << ui->twSourcesObjects << ui->twSourcesLevels << ui->twSourcesMisc; + + return tableWidgets; +} + +void MainWindow::loadProjectState(const QString &filePath) +{ + + this->projectIsLoading = true; + + if(this->vagoSettings->value("AskSaveProject").toBool() && this->unsavedChangesExist){ + QMessageBox::StandardButton result = askToSaveCurrentProject(); + if(result == QMessageBox::StandardButton::Cancel){ + this->projectIsLoading = false; + return; + } + } + + QString statusError = "Couldn't load project."; + + pugi::xml_document doc; + + pugi::xml_parse_result result = doc.load_file(Util::qStrToCstr(filePath)); + + if(result.status!=pugi::status_ok){ + UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error ocurred while loading project file.\n" + QString(result.description())); + showErrStatusMessage(statusError); + this->projectIsLoading = false; + return; + } + + + if(QString(doc.root().first_child().name()) != "VagoProject"){ + UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, QString(doc.root().name()) + "The file opened is not a valid VagoProject file. Load aborted."); + showErrStatusMessage(statusError); + this->projectIsLoading = false; + return; + } + + QString projVagoVersion; + + try{ + projVagoVersion = QString(doc.select_node("/VagoProject/@vagoVersion").attribute().value()); + } + catch (const pugi::xpath_exception& e) + { + UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't find the vagoVersion of the current project. Load aborted.\n" + QString(e.what())); + showErrStatusMessage(statusError); + this->projectIsLoading = false; + return; + } + + if(!projVagoVersion.startsWith(GlobalVars::LastCompatibleVersion)){ + UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "The project that you are trying to load seems it is not compatible with your Vago Version. Please update Vago and try again."); + showErrStatusMessage(statusError); + this->projectIsLoading = false; + return; + } + + // After the initial validations begin loading the project data + + QList tableWidgets = getAllTableWidgets(); + + try{ + foreach(DropTableWidget* const &myTable, tableWidgets){ + loadProjectWidget(doc, myTable); + } + } + catch(const std::exception& e){ + UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't load the vago project. Error: " + QString(e.what())); + showErrStatusMessage(statusError); + this->projectIsLoading = false; + return; + } + + this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path()); + + this->lastProjectFilePath = filePath; + this->unsavedChangesExist = false; + + addNewRecentProject(filePath); + + setVagoWindowTitle(); + + this->projectIsLoading = false; + + showSuccessStatusMessage("Project loaded sucessfully."); +} + + +void MainWindow::loadProjectWidget(pugi::xml_document &doc, DropTableWidget* table) +{ + QString tabName = getTabNameByTableWidget(table); + QString from (doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/@from")).attribute().value()); + QString to (doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/@to")).attribute().value()); + + if(table==ui->twSourcesXML){ + ui->cbFromXML->setCurrentText(from); + on_cbFromXML_currentIndexChanged(from); + ui->cbToXML->setCurrentText(to); + } + else if(table==ui->twSourcesTextures){ + //ui->cbFromTextures->setCurrentText(from); + on_cbFromTextures_currentIndexChanged(from); + ui->cbToTextures->setCurrentText(to); + getTextureRBTypeTextureByName((doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@type")).attribute().value()))->setChecked(true); + ui->cbMipMapsTextures->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@genMipMaps")).attribute().as_bool()); + ui->cbNoUwrap->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@noUwrap")).attribute().as_bool()); + ui->cbNoVwrap->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@noVwrap")).attribute().as_bool()); + ui->cbLarge->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@large")).attribute().as_bool()); + ui->cbEnvMap->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@envMap")).attribute().as_bool()); + ui->leEnvMapTexture->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@envMapValue")).attribute().value())); + } + else if(table==ui->twSourcesCharacters){ + ui->cbFromCharacters->setCurrentText(from); + on_cbFromCharacters_currentIndexChanged(from); + ui->cbToCharacters->setCurrentText(to); + + + ui->cbCellShading->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@cellShading")).attribute().as_bool()); + ui->cbNormals->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@normals")).attribute().as_bool()); + ui->cbWithTRBS_ONCC->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@extractTRBSONCC")).attribute().as_bool()); + ui->leTRBS_ONCC->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@extractTRBSONCCValue")).attribute().value())); + } + else if(table==ui->twSourcesObjects){ + ui->cbFromObjects->setCurrentText(from); + on_cbFromObjects_currentIndexChanged(from); + ui->cbToObjects->setCurrentText(to); + + ui->cbTexture->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@texture")).attribute().as_bool()); + ui->leTextureName->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@textureValue")).attribute().value())); + ui->cbWithAnimation->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@withAnimation")).attribute().as_bool()); + ui->leAnimationName->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@withAnimationValue")).attribute().value())); + } + else if(table==ui->twSourcesLevels){ + ui->cbFromLevels->setCurrentText(from); + on_cbFromLevels_currentIndexChanged(from); + ui->cbToLevels->setCurrentText(to); + + ui->cbSpecificFilesLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@extractWithFiles")).attribute().as_bool()); + ui->leSpecificFilesLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@extractWithFilesValue")).attribute().value())); + ui->cbDatLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@datFilename")).attribute().as_bool()); + ui->leTargetDatLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@datFilenameValue")).attribute().value())); + ui->cbBnvLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@bnvSource")).attribute().as_bool()); + ui->leBnvLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@bnvSourceValue")).attribute().value())); + ui->cbGridsLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@generateGrids")).attribute().as_bool()); + ui->cbAdditionalSourcesLevels->setChecked(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@additionalSources")).attribute().as_bool()); + ui->leAdditSourcesLevels->setText(QString(doc.select_node(Util::qStrToCstr("/VagoProject/"+tabName+"/Options/@additionalSourcesValue")).attribute().value())); + } + else{ + ui->cbFromMisc->setCurrentText(from); + on_cbFromMisc_currentIndexChanged(from); + ui->cbToMisc->setCurrentText(to); + } + + // Clean previous rows + clearTableNoPrompt(table); + + for(const pugi::xpath_node &xPathNode : doc.select_nodes(Util::qStrToCstr("/VagoProject/"+tabName+"/Row"))){ + pugi::xml_node currNode = xPathNode.node(); + + QString currFileFolder = currNode.attribute("fileFolder").value(); + QString currFromTo = currNode.attribute("fromTo").value(); + QString currCommand = currNode.attribute("command").value(); + + bool isToDisable = false; + pugi::xml_attribute disabledAttr = currNode.attribute("disabled"); + isToDisable = disabledAttr.empty() ? false : disabledAttr.as_bool(); + + addRowTable(table,currFileFolder,currFromTo,currCommand, isToDisable); + } +} + +void MainWindow::saveRecentProjects(){ + for(int i=0; irecentProjectsList.size(); i++){ + this->vagoSettings->setValue("RecentProject" + QString::number(i+1), recentProjectsList[i]); + } +} + +void MainWindow::loadRecentProjects(){ + for(int i=0; irecentProjectsMaxSize; i++){ + + QString currProj = this->vagoSettings->value("RecentProject" + QString::number(i+1)).toString(); + + if(!currProj.isEmpty()){ + recentProjectsList.append(currProj); + } + else{ + break; + } + } + + reloadRecentProjectsMenu(); + +} + +void MainWindow::addNewRecentProject(const QString &filePath){ + + // If the new project is equal to the last one simply ignore + if(filePath == this->vagoSettings->value("RecentProject1").toString()){ + return; + } + + // If the item already exists in our list remove it, so it can go to the top again + for(auto it = this->recentProjectsList.begin(); it != this->recentProjectsList.end();){ + if(*it == filePath){ + it = this->recentProjectsList.erase(it); + } + else{ + it++; + } + } + + // if we gonna overflow our list, remove the older item to reserve space to the new one + if(this->recentProjectsList.size()==this->recentProjectsMaxSize){ + this->recentProjectsList.removeLast(); + } + + this->vagoSettings->setValue("LastProjectPath",QFileInfo(filePath).absoluteDir().path()); + + // add new recent file + this->recentProjectsList.prepend(filePath); + + reloadRecentProjectsMenu(); + + saveRecentProjects(); +} + +void MainWindow::reloadRecentProjectsMenu(){ + + ui->menuRecent_Projects->setEnabled(false); + ui->actionProject1->setVisible(false); + ui->actionProject2->setVisible(false); + ui->actionProject3->setVisible(false); + ui->actionProject4->setVisible(false); + ui->actionProject5->setVisible(false); + + { + QList::const_iterator it; + int i; + for(it = recentProjectsList.cbegin(), i=0; it != recentProjectsList.cend(); it++, i++){ + + QAction* currAction = nullptr; + + switch (i){ + case 0: + currAction = ui->actionProject1; + break; + case 1: + currAction = ui->actionProject2; + break; + case 2: + currAction = ui->actionProject3; + break; + case 3: + currAction = ui->actionProject4; + break; + case 4: + currAction = ui->actionProject5; + break; + } + + if(currAction){ + ui->menuRecent_Projects->setEnabled(true); + currAction->setText(*it); + currAction->setVisible(true); + } + } + } + +}