diff --git a/src/Core/Log.cpp b/src/Core/Log.cpp index 922a32d0..5ab7249b 100644 --- a/src/Core/Log.cpp +++ b/src/Core/Log.cpp @@ -5,6 +5,7 @@ namespace Log { +TStringList ErrorLog; static const TString gskLogFilename = "primeworldeditor.log"; #pragma warning(push) @@ -12,7 +13,7 @@ static const TString gskLogFilename = "primeworldeditor.log"; FILE *gpLogFile = fopen(*gskLogFilename, "w"); #pragma warning(pop) -void Write(const TString& message) +void Write(const TString& rkMessage) { if (gpLogFile) { @@ -25,51 +26,65 @@ void Write(const TString& message) char Buffer[80]; strftime(Buffer, 80, "[%H:%M:%S]", &pTimeInfo); - fprintf(gpLogFile, "%s %s\n", Buffer, *message); + fprintf(gpLogFile, "%s %s\n", Buffer, *rkMessage); fflush(gpLogFile); } } -void Error(const TString& message) +void Error(const TString& rkMessage) { - Write("ERROR: " + message); - std::cout << "ERROR: " << message << "\n"; + TString FullMessage = "ERROR: " + rkMessage; + Write(FullMessage); + ErrorLog.push_back(FullMessage); + std::cout << FullMessage << "\n"; } -void Warning(const TString& message) +void Warning(const TString& rkMessage) { - Write("Warning: " + message); - std::cout << "Warning: " << message << "\n"; + TString FullMessage = "Warning: " + rkMessage; + Write(FullMessage); + ErrorLog.push_back(FullMessage); + std::cout << FullMessage << "\n"; } -void FileWrite(const TString& filename, const TString& message) +void FileWrite(const TString& rkFilename, const TString& rkMessage) { - Write(filename + " : " + message); + Write(rkFilename + " : " + rkMessage); } -void FileWrite(const TString& filename, unsigned long offset, const TString& message) +void FileWrite(const TString& rkFilename, u32 Offset, const TString& rkMessage) { - Write(filename + " : " + TString::HexString(offset) + " - " + message); + Write(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage); } -void FileError(const TString& filename, const TString& message) +void FileError(const TString& rkFilename, const TString& rkMessage) { - Error(filename + " : " + message); + Error(rkFilename + " : " + rkMessage); } -void FileError(const TString& filename, unsigned long offset, const TString& message) +void FileError(const TString& rkFilename, u32 Offset, const TString& rkMessage) { - Error(filename + " : " + TString::HexString(offset) + " - " + message); + Error(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage); } -void FileWarning(const TString& filename, const TString& message) +void FileWarning(const TString& rkFilename, const TString& rkMessage) { - Warning(filename + " : " + message); + Warning(rkFilename + " : " + rkMessage); } -void FileWarning(const TString& filename, unsigned long offset, const TString& message) +void FileWarning(const TString& rkFilename, u32 Offset, const TString& rkMessage) { - Warning(filename + " : " + TString::HexString(offset) + " - " + message); + Warning(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage); +} + +const TStringList& GetErrorLog() +{ + return ErrorLog; +} + +void ClearErrorLog() +{ + ErrorLog.clear(); } } diff --git a/src/Core/Log.h b/src/Core/Log.h index 94ff940c..27404dfd 100644 --- a/src/Core/Log.h +++ b/src/Core/Log.h @@ -6,15 +6,17 @@ namespace Log { -void Write(const TString& message); -void Error(const TString& message); -void Warning(const TString& message); -void FileWrite(const TString& filename, const TString& message); -void FileWrite(const TString& filename, unsigned long offset, const TString& message); -void FileError(const TString& filename, const TString& message); -void FileError(const TString& filename, unsigned long offset, const TString& message); -void FileWarning(const TString& filename, const TString& message); -void FileWarning(const TString& filename, unsigned long offset, const TString& message); +void Write(const TString& rkMessage); +void Error(const TString& rkMessage); +void Warning(const TString& rkMessage); +void FileWrite(const TString& rkFilename, const TString& rkMessage); +void FileWrite(const TString& rkFilename, unsigned long Offset, const TString& rkMessage); +void FileError(const TString& rkFilename, const TString& rkMessage); +void FileError(const TString& rkFilename, unsigned long Offset, const TString& rkMessage); +void FileWarning(const TString& rkFilename, const TString& rkMessage); +void FileWarning(const TString& rkFilename, unsigned long Offset, const TString& rkMessage); +const TStringList& GetErrorLog(); +void ClearErrorLog(); } diff --git a/src/Editor/CErrorLogDialog.cpp b/src/Editor/CErrorLogDialog.cpp new file mode 100644 index 00000000..c38ee158 --- /dev/null +++ b/src/Editor/CErrorLogDialog.cpp @@ -0,0 +1,51 @@ +#include "CErrorLogDialog.h" +#include "ui_CErrorLogDialog.h" +#include "UICommon.h" +#include + +CErrorLogDialog::CErrorLogDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CErrorLogDialog) +{ + ui->setupUi(this); + connect(ui->CloseButton, SIGNAL(clicked()), this, SLOT(close())); +} + +CErrorLogDialog::~CErrorLogDialog() +{ + delete ui; +} + +bool CErrorLogDialog::GatherErrors() +{ + const TStringList& rkErrors = Log::GetErrorLog(); + if (rkErrors.empty()) return false; + + QString DialogString; + + for (auto it = rkErrors.begin(); it != rkErrors.end(); it++) + { + QString Error = TO_QSTRING(*it); + QString LineColor; + + if (Error.startsWith("ERROR: ")) + LineColor = "#ff0000"; + else if (Error.startsWith("Warning: ")) + LineColor = "#ff8000"; + + QString FullLine = Error; + + if (!LineColor.isEmpty()) + { + FullLine.prepend(QString("").arg(LineColor)); + FullLine.append(""); + } + FullLine.append("
"); + + DialogString += FullLine; + } + + ui->ErrorLogTextEdit->setText(DialogString); + Log::ClearErrorLog(); + return true; +} diff --git a/src/Editor/CErrorLogDialog.h b/src/Editor/CErrorLogDialog.h new file mode 100644 index 00000000..b554183d --- /dev/null +++ b/src/Editor/CErrorLogDialog.h @@ -0,0 +1,23 @@ +#ifndef CERRORLOGDIALOG_H +#define CERRORLOGDIALOG_H + +#include + +namespace Ui { +class CErrorLogDialog; +} + +class CErrorLogDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CErrorLogDialog(QWidget *parent = 0); + ~CErrorLogDialog(); + bool GatherErrors(); + +private: + Ui::CErrorLogDialog *ui; +}; + +#endif // CERRORLOGDIALOG_H diff --git a/src/Editor/CErrorLogDialog.ui b/src/Editor/CErrorLogDialog.ui new file mode 100644 index 00000000..02cd71f2 --- /dev/null +++ b/src/Editor/CErrorLogDialog.ui @@ -0,0 +1,49 @@ + + + CErrorLogDialog + + + + 0 + 0 + 662 + 402 + + + + Errors + + + + + + The following errors were encountered while loading the area: + + + + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + + + Close + + + + + + + + diff --git a/src/Editor/CStartWindow.cpp b/src/Editor/CStartWindow.cpp index c4a94815..d931de05 100644 --- a/src/Editor/CStartWindow.cpp +++ b/src/Editor/CStartWindow.cpp @@ -1,5 +1,6 @@ #include "CStartWindow.h" #include "ui_CStartWindow.h" +#include "CErrorLogDialog.h" #include "UICommon.h" #include "Editor/ModelEditor/CModelEditorWindow.h" @@ -169,6 +170,13 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked() mpWorldEditor->SetArea(mpWorld, pArea); mpWorldEditor->setWindowModality(Qt::WindowModal); mpWorldEditor->showMaximized(); + + // Display errors + CErrorLogDialog ErrorDialog(mpWorldEditor); + bool HasErrors = ErrorDialog.GatherErrors(); + + if (HasErrors) + ErrorDialog.exec(); } gResCache.Clean(); diff --git a/src/Editor/Editor.pro b/src/Editor/Editor.pro index 9107ef94..cbbbc819 100644 --- a/src/Editor/Editor.pro +++ b/src/Editor/Editor.pro @@ -124,7 +124,8 @@ HEADERS += \ CStartWindow.h \ INodeEditor.h \ TestDialog.h \ - UICommon.h + UICommon.h \ + CErrorLogDialog.h # Source Files SOURCES += \ @@ -169,7 +170,8 @@ SOURCES += \ INodeEditor.cpp \ main.cpp \ TestDialog.cpp \ - UICommon.cpp + UICommon.cpp \ + CErrorLogDialog.cpp # UI Files FORMS += \ @@ -183,4 +185,5 @@ FORMS += \ WorldEditor/CWorldEditor.ui \ WorldEditor/WCreateTab.ui \ WorldEditor/WInstancesTab.ui \ - WorldEditor/WModifyTab.ui + WorldEditor/WModifyTab.ui \ + CErrorLogDialog.ui