| 1 |
#include "wmfinalpage.h" |
| 2 |
#include "ui_wmfinalpage.h" |
| 3 |
|
| 4 |
WmFinalPage::WmFinalPage(QString AppDir, QString wmLocation, Logger *myLogger, QList<std::shared_ptr<WmPage> > &pages, QWidget *parent) : |
| 5 |
QWizardPage(parent), ui(new Ui::wmfinalpage), pages(pages) |
| 6 |
{ |
| 7 |
ui->setupUi(this); |
| 8 |
this->wmLocation=wmLocation; |
| 9 |
this->myLogger=myLogger; |
| 10 |
|
| 11 |
this->oniSplitCommands = new QStringList(); |
| 12 |
this->myConverter = new Converter(AppDir, this->myLogger,this->oniSplitCommands); |
| 13 |
|
| 14 |
ui->lbComplete->setText("<html>The wizard is now complete. The window messages have been converted. " |
| 15 |
"You can view all converted files clicking <a href=' '>here.</a><br />" |
| 16 |
"<br />Click restart to create more window messages from the wizard beggining, " |
| 17 |
"otherwise click finish.</html>"); // Don't use rich text in qtdesigner because it generates platform dependent code |
| 18 |
|
| 19 |
connectSlots(); |
| 20 |
} |
| 21 |
|
| 22 |
void WmFinalPage::openSoundsFolder(){ |
| 23 |
QDesktopServices::openUrl(QUrl("file:///"+this->wmLocation)); |
| 24 |
} |
| 25 |
|
| 26 |
void WmFinalPage::initializePage(){ |
| 27 |
startProcessing(); |
| 28 |
} |
| 29 |
|
| 30 |
void WmFinalPage::startProcessing(){ |
| 31 |
// Check if images folder exists and create it if necessary |
| 32 |
QDir saveDir(this->wmLocation); |
| 33 |
|
| 34 |
if(!saveDir.exists()) |
| 35 |
{ |
| 36 |
saveDir.mkpath("."); // http://stackoverflow.com/questions/2241808/checking-if-a-folder-exists-and-creating-folders-in-qt-c thanks Petrucio |
| 37 |
} |
| 38 |
|
| 39 |
QString filePath = this->wmLocation + "/" + field("leFileName").toString() + ".xml"; |
| 40 |
|
| 41 |
int globalSectionCounter = -1; |
| 42 |
int currentIGPGId = globalSectionCounter; |
| 43 |
int currentIGSAId = globalSectionCounter; |
| 44 |
int currentIGSTId = globalSectionCounter; |
| 45 |
|
| 46 |
pugi::xml_document doc; |
| 47 |
|
| 48 |
pugi::xml_node rootNode = doc.append_child("Oni"); |
| 49 |
pugi::xml_node typeNode; |
| 50 |
|
| 51 |
// Define type node |
| 52 |
switch(static_cast<WINDOW_TYPE>(field("cbWindowType").toInt())){ |
| 53 |
case WINDOW_TYPE::OBJECTIVE: |
| 54 |
{ |
| 55 |
typeNode = rootNode.append_child("OPge"); |
| 56 |
typeNode.append_attribute("id").set_value(++globalSectionCounter); |
| 57 |
typeNode.append_child("LevelNumber").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(field("leLevelId").toString())); |
| 58 |
typeNode.append_child("Pages").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(QString("#") + QString::number(++globalSectionCounter))); |
| 59 |
pugi::xml_node igpaNode = rootNode.append_child("IGPA"); |
| 60 |
igpaNode.append_attribute("id").set_value(globalSectionCounter); |
| 61 |
pugi::xml_node pagesNode = igpaNode.append_child("Pages"); |
| 62 |
currentIGPGId = globalSectionCounter; |
| 63 |
for(int i=0; i<this->pages.size(); i++){ |
| 64 |
pagesNode.append_child("Link").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 65 |
} |
| 66 |
break; |
| 67 |
} |
| 68 |
case WINDOW_TYPE::DIARY: |
| 69 |
typeNode = rootNode.append_child("DPge"); |
| 70 |
typeNode.append_attribute("id").set_value(++globalSectionCounter); |
| 71 |
typeNode.append_child("LevelNumber").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(field("leLevelId").toString())); |
| 72 |
typeNode.append_child("PageNumber").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(field("lePageNumber").toString())); |
| 73 |
typeNode.append_child("IsLearnedMove").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(QString::number(static_cast<int>(field("cbIsLearnedMove").toBool())))); |
| 74 |
currentIGPGId = globalSectionCounter; |
| 75 |
typeNode.append_child("Page").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 76 |
break; |
| 77 |
case WINDOW_TYPE::HELP: |
| 78 |
typeNode = rootNode.append_child("HPge"); |
| 79 |
typeNode.append_attribute("id").set_value(++globalSectionCounter); |
| 80 |
currentIGPGId = globalSectionCounter; |
| 81 |
typeNode.append_child("Page").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 82 |
break; |
| 83 |
case WINDOW_TYPE::TEXT_CONSOLE: |
| 84 |
{ |
| 85 |
typeNode = rootNode.append_child("TxtC"); |
| 86 |
typeNode.append_attribute("id").set_value(++globalSectionCounter); |
| 87 |
typeNode.append_child("Pages").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 88 |
pugi::xml_node igpaNode = rootNode.append_child("IGPA"); |
| 89 |
igpaNode.append_attribute("id").set_value(globalSectionCounter); |
| 90 |
currentIGPGId = globalSectionCounter; |
| 91 |
pugi::xml_node pagesNode = igpaNode.append_child("Pages"); |
| 92 |
for(int i=0; i<this->pages.size(); i++){ |
| 93 |
pagesNode.append_child("Link").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 94 |
} |
| 95 |
break; |
| 96 |
} |
| 97 |
case WINDOW_TYPE::WEAPON: |
| 98 |
typeNode = rootNode.append_child("WPge"); |
| 99 |
typeNode.append_attribute("id").set_value(++globalSectionCounter); |
| 100 |
typeNode.append_child("WeaponClass").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(field("leWeaponClassName").toString())); |
| 101 |
currentIGPGId = globalSectionCounter; |
| 102 |
typeNode.append_child("Page").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 103 |
break; |
| 104 |
case WINDOW_TYPE::ITEM: |
| 105 |
typeNode = rootNode.append_child("IPge"); |
| 106 |
typeNode.append_attribute("id").set_value(++globalSectionCounter); |
| 107 |
typeNode.append_child("PageNumber").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(field("lePageNumber").toString())); |
| 108 |
currentIGPGId = globalSectionCounter; |
| 109 |
typeNode.append_child("Page").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 110 |
break; |
| 111 |
case WINDOW_TYPE::ENUM_END: |
| 112 |
UtilVago::showAndLogErrorPopUp(this->myLogger, "An error ocurred: WmFinalPage::startProcessing invalid WINDOW_TYPE"); |
| 113 |
break; |
| 114 |
} |
| 115 |
|
| 116 |
// Write pages text |
| 117 |
for(int i=0; i<this->pages.size(); i++){ |
| 118 |
|
| 119 |
QTextEdit &mainText = this->pages[i]->getMainText(); |
| 120 |
int mainTextNumberOfRows = mainText.toPlainText().split("\n").size(); |
| 121 |
|
| 122 |
QTextEdit &footerText = this->pages[i]->getFooterText(); |
| 123 |
int footerTextNumberOfRows = footerText.toPlainText().split("\n").size(); |
| 124 |
|
| 125 |
// Create TXMP image if exists |
| 126 |
QString imageLocation = this->pages[i]->getMiddleImage().toolTip(); |
| 127 |
QString imageTXMPName; |
| 128 |
|
| 129 |
if(!imageLocation.isEmpty()){ |
| 130 |
|
| 131 |
imageTXMPName = "TXMP" + QFileInfo(imageLocation).baseName(); |
| 132 |
|
| 133 |
this->oniSplitCommands->clear(); |
| 134 |
this->oniSplitCommands->append("-create:txmp " + Util::insertQuotes(this->wmLocation) + " -format:bgr32 " + Util::insertQuotes(imageLocation)); |
| 135 |
|
| 136 |
this->myConverter->start(); // finally process the onisplit commands |
| 137 |
this->myConverter->wait(); // wait for it to complete |
| 138 |
} |
| 139 |
|
| 140 |
// IGPG |
| 141 |
pugi::xml_node igpgNode = rootNode.append_child("IGPG"); |
| 142 |
|
| 143 |
igpgNode.append_attribute("id").set_value(++currentIGPGId); |
| 144 |
|
| 145 |
pugi::xml_node igpgFontNode = igpgNode.append_child("Font"); |
| 146 |
igpgFontNode.append_child("Family").append_child(pugi::xml_node_type::node_pcdata).set_value("TSFFTahoma"); |
| 147 |
igpgFontNode.append_child("Style").append_child(pugi::xml_node_type::node_pcdata).set_value("Bold"); |
| 148 |
igpgFontNode.append_child("Color").append_child(pugi::xml_node_type::node_pcdata).set_value("255 127 0"); |
| 149 |
igpgFontNode.append_child("Size").append_child(pugi::xml_node_type::node_pcdata).set_value("12"); |
| 150 |
igpgFontNode.append_child("Flags").append_child(pugi::xml_node_type::node_pcdata).set_value("Family Style Color Size"); |
| 151 |
|
| 152 |
currentIGSAId = globalSectionCounter; |
| 153 |
|
| 154 |
igpgNode.append_child("Image").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(imageTXMPName)); |
| 155 |
igpgNode.append_child("Text1").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 156 |
igpgNode.append_child("Text2").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 157 |
|
| 158 |
// IGSA |
| 159 |
|
| 160 |
////// Main Text |
| 161 |
pugi::xml_node igsaMainTextNode = rootNode.append_child("IGSA"); |
| 162 |
igsaMainTextNode.append_attribute("id").set_value(++currentIGSAId); |
| 163 |
pugi::xml_node igsaMainTextStringsNode = igsaMainTextNode.append_child("Strings"); |
| 164 |
|
| 165 |
currentIGSTId = globalSectionCounter; |
| 166 |
|
| 167 |
for(int i=0; i<mainTextNumberOfRows; i++){ |
| 168 |
igsaMainTextStringsNode.append_child("Link").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 169 |
} |
| 170 |
|
| 171 |
////// Footer |
| 172 |
pugi::xml_node igsaFooterTextNode = rootNode.append_child("IGSA"); |
| 173 |
igsaFooterTextNode.append_attribute("id").set_value(++currentIGSAId); |
| 174 |
pugi::xml_node igsaFooterTextStringsNode = igsaFooterTextNode.append_child("Strings"); |
| 175 |
for(int i=0; i<footerTextNumberOfRows; i++){ |
| 176 |
igsaFooterTextStringsNode.append_child("Link").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("#" + QString::number(++globalSectionCounter))); |
| 177 |
} |
| 178 |
|
| 179 |
// IGSt |
| 180 |
|
| 181 |
auto setIGStXmlSection = [&rootNode, ¤tIGSTId](QTextEdit ¤tTextEdit, int numberOfRows){ |
| 182 |
|
| 183 |
for(int i=0; i<numberOfRows; i++){ |
| 184 |
|
| 185 |
QTextCursor currentCursor = currentTextEdit.textCursor(); |
| 186 |
currentCursor.setPosition(currentTextEdit.document()->findBlockByLineNumber(i).position()); |
| 187 |
currentCursor.movePosition(QTextCursor::StartOfLine); |
| 188 |
currentCursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); |
| 189 |
QTextCharFormat format = currentCursor.charFormat(); |
| 190 |
QString colorRGB = QString::number(format.foreground().color().red()) + " " + |
| 191 |
QString::number(format.foreground().color().green()) + " " + |
| 192 |
QString::number(format.foreground().color().blue()); |
| 193 |
QString style = (QString(format.fontItalic() ? "Italic " : "") + (format.fontWeight() == QFont::Bold ? "Bold " : "")).trimmed(); |
| 194 |
|
| 195 |
if(style.isEmpty()){ |
| 196 |
style = "Normal"; |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
pugi::xml_node igstMainTextNode = rootNode.append_child("IGSt"); |
| 201 |
igstMainTextNode.append_attribute("id").set_value(++currentIGSTId); |
| 202 |
|
| 203 |
pugi::xml_node igstMainTextFontNode = igstMainTextNode.append_child("Font"); |
| 204 |
igstMainTextFontNode.append_child("Family").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr("TSFF" + format.font().family())); |
| 205 |
igstMainTextFontNode.append_child("Style").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(style)); |
| 206 |
igstMainTextFontNode.append_child("Color").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(colorRGB)); |
| 207 |
igstMainTextFontNode.append_child("Size").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(QString::number(format.font().pointSize()))); |
| 208 |
igstMainTextFontNode.append_child("Flags").append_child(pugi::xml_node_type::node_pcdata).set_value("Family Style Color Size"); |
| 209 |
|
| 210 |
igstMainTextNode.append_child("Text").append_child(pugi::xml_node_type::node_pcdata).set_value(Util::qStrToCstr(currentCursor.selection().toPlainText())); |
| 211 |
} |
| 212 |
|
| 213 |
}; |
| 214 |
|
| 215 |
////// Main Text |
| 216 |
setIGStXmlSection(mainText, mainTextNumberOfRows); |
| 217 |
|
| 218 |
////// Footer |
| 219 |
setIGStXmlSection(footerText, footerTextNumberOfRows); |
| 220 |
} |
| 221 |
|
| 222 |
if(!doc.save_file(Util::qStrToCstr(filePath))){ |
| 223 |
UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "Couldn't create " + filePath + " file!"); |
| 224 |
return; |
| 225 |
} |
| 226 |
|
| 227 |
// Convert XML file to Oni |
| 228 |
this->oniSplitCommands->clear(); |
| 229 |
this->oniSplitCommands->append("-create " + Util::insertQuotes(this->wmLocation) + " " + Util::insertQuotes(filePath)); |
| 230 |
|
| 231 |
this->myConverter->start(); // finally process the onisplit commands |
| 232 |
this->myConverter->wait(); // wait for it to complete |
| 233 |
} |
| 234 |
|
| 235 |
void WmFinalPage::catchOSplitProcessingErrors(QString result, int numErrors){ |
| 236 |
|
| 237 |
if(numErrors!=0){ |
| 238 |
QString sNumErrors=QString::number(numErrors); |
| 239 |
if(numErrors>1){ |
| 240 |
UtilVago::showErrorPopUpLogButton(result+"\n This is the last of " + sNumErrors + " errors."); |
| 241 |
} |
| 242 |
else{ |
| 243 |
UtilVago::showErrorPopUpLogButton(result); |
| 244 |
} |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
void WmFinalPage::connectSlots(){ |
| 249 |
//This signal is for thread that is working setup the progress bar (make it visible and set it's min-max) |
| 250 |
connect(this->myConverter, SIGNAL(resultConversion(QString, int)), this, SLOT(catchOSplitProcessingErrors(QString, int))); |
| 251 |
connect(ui->lbComplete, SIGNAL(linkActivated(const QString & )), this, SLOT(openSoundsFolder())); |
| 252 |
} |
| 253 |
|
| 254 |
WmFinalPage::~WmFinalPage() |
| 255 |
{ |
| 256 |
delete this->oniSplitCommands; |
| 257 |
delete this->myConverter; |
| 258 |
delete ui; |
| 259 |
} |