# Qt sources
set (ED_SOURCES Main.cxx MainWindow.cxx ImageWindow.cxx TextWindow.cxx DatWindow.cxx
- ObjectWindow.cxx)
-set (ED_HEADERS MainWindow.hxx ImageWindow.hxx TextWindow.hxx DatWindow.hxx ObjectWindow.hxx)
+ ObjectWindow.cxx DefSyntax.cxx FxSyntax.cxx IniSyntax.cxx)
+set (ED_HEADERS MainWindow.hxx ImageWindow.hxx TextWindow.hxx DatWindow.hxx ObjectWindow.hxx
+ DefSyntax.hxx FxSyntax.hxx IniSyntax.hxx)
set (ED_UI_FILES MainWindow.ui ImageWindow.ui TextWindow.ui DatWindow.ui ObjectWindow.ui)
set (ED_RES_FILES Resources.qrc)
set (ED_TS_FILES i18n_english.ts i18n_french.ts i18n_german.ts)
--- /dev/null
+#include "DefSyntax.hxx"
+
+// --- internal constants ---
+
+const QString keywords("setentry");
+
+// --- constructors and deconstructors ---
+
+DefSyntax::DefSyntax(QObject *parent)
+: QSyntaxHighlighter(parent)
+{
+ setup();
+}
+
+DefSyntax::DefSyntax(QTextDocument *parent)
+: QSyntaxHighlighter(parent)
+{
+ setup();
+}
+
+DefSyntax::~DefSyntax()
+{
+}
+
+// --- protected methods ---
+
+void DefSyntax::highlightBlock(const QString& text)
+{
+ qint32 index = 0;
+
+ setCurrentBlockState(0);
+
+ // keywords
+ index = text.indexOf(_keywords_re);
+ while (index >= 0)
+ {
+ auto len = _keywords_re.matchedLength();
+
+ setFormat(index, len, _keywords_f);
+ index = text.indexOf(_keywords_re, index + len);
+ }
+
+ // ints
+ index = text.indexOf(_ints_re);
+ while (index >= 0)
+ {
+ auto len = _ints_re.matchedLength();
+
+ setFormat(index, len, _ints_f);
+ index = text.indexOf(_ints_re, index + len);
+ }
+
+ // floats
+ index = text.indexOf(_floats_re);
+ while (index >= 0)
+ {
+ auto len = _floats_re.matchedLength();
+
+ setFormat(index, len, _floats_f);
+ index = text.indexOf(_floats_re, index + len);
+ }
+
+ // strings
+ index = text.indexOf(_strings_re);
+ while (index >= 0)
+ {
+ auto len = _strings_re.matchedLength();
+
+ setFormat(index, len, _strings_f);
+ index = text.indexOf(_strings_re, index + len);
+ }
+
+ // single line comments
+ index = text.indexOf(_comment_re);
+ if (index >= 0)
+ setFormat(index, _comment_re.matchedLength(), _comment_f);
+}
+
+void DefSyntax::setup()
+{
+ QString pattern;
+
+ // format
+ _keywords_f.setFontWeight(QFont::Bold);
+ _keywords_f.setForeground(Qt::green);
+
+ _ints_f.setFontWeight(QFont::Bold);
+ _ints_f.setForeground(Qt::darkBlue);
+
+ _floats_f.setFontWeight(QFont::Bold);
+ _floats_f.setForeground(Qt::darkRed);
+
+ _strings_f.setFontWeight(QFont::Bold);
+ _strings_f.setFontItalic(true);
+ _strings_f.setForeground(Qt::darkYellow);
+
+ _comment_f.setFontItalic(true);
+ _comment_f.setForeground(Qt::darkGray);
+
+
+ // regexp
+ pattern.append("\\b(");
+ pattern.append(keywords.split(" ").join("|"));
+ pattern.append(")\\b");
+ _keywords_re.setPattern(pattern);
+
+ _ints_re.setPattern("\\b[0-9]+\\b");
+
+ _floats_re.setPattern("\\b[0-9]+\\.[0-9]+\\b");
+
+ _strings_re.setPattern("(\"[^\"]*)\"");
+
+ _comment_re.setPattern("//[^\n]*");
+}
--- /dev/null
+#pragma once
+
+#include <QSyntaxHighlighter>
+
+class DefSyntax : public QSyntaxHighlighter {
+ Q_OBJECT
+public:
+ explicit DefSyntax(QObject *parent = 0);
+ explicit DefSyntax(QTextDocument *parent = 0);
+ virtual ~DefSyntax();
+
+protected:
+ virtual void highlightBlock(const QString& text) override;
+ void setup();
+
+private:
+ QTextCharFormat _keywords_f;
+ QTextCharFormat _ints_f;
+ QTextCharFormat _floats_f;
+ QTextCharFormat _strings_f;
+ QTextCharFormat _comment_f;
+ QRegExp _keywords_re;
+ QRegExp _ints_re;
+ QRegExp _floats_re;
+ QRegExp _strings_re;
+ QRegExp _comment_re;
+};
--- /dev/null
+#include "FxSyntax.hxx"
+
+// --- internal constants ---
+
+const QString structs("PARTICLE POS MOVEMENT COLORRGBA SIZE LIFESPAN BITMAP GLOW");
+const QString functions("StartPosX StartPosY StartPosZ Random");
+
+// --- constructors and deconstructors ---
+
+FxSyntax::FxSyntax(QObject *parent)
+: QSyntaxHighlighter(parent)
+{
+ setup();
+}
+
+FxSyntax::FxSyntax(QTextDocument *parent)
+: QSyntaxHighlighter(parent)
+{
+ setup();
+}
+
+FxSyntax::~FxSyntax()
+{
+}
+
+// --- protected methods ---
+
+void FxSyntax::highlightBlock(const QString& text)
+{
+ qint32 index = 0;
+
+ setCurrentBlockState(0);
+
+ // structs
+ index = text.indexOf(_structs_re);
+ while (index >= 0)
+ {
+ auto len = _structs_re.matchedLength();
+
+ setFormat(index, len, _structs_f);
+ index = text.indexOf(_structs_re, index + len);
+ }
+
+ // functions
+ index = text.indexOf(_functions_re);
+ while (index >= 0)
+ {
+ auto len = _functions_re.matchedLength();
+
+ setFormat(index, len, _functions_f);
+ index = text.indexOf(_functions_re, index + len);
+ }
+
+ // ints
+ index = text.indexOf(_ints_re);
+ while (index >= 0)
+ {
+ auto len = _ints_re.matchedLength();
+
+ setFormat(index, len, _ints_f);
+ index = text.indexOf(_ints_re, index + len);
+ }
+
+ // floats
+ index = text.indexOf(_floats_re);
+ while (index >= 0)
+ {
+ auto len = _floats_re.matchedLength();
+
+ setFormat(index, len, _floats_f);
+ index = text.indexOf(_floats_re, index + len);
+ }
+
+ // strings
+ index = text.indexOf(_strings_re);
+ while (index >= 0)
+ {
+ auto len = _strings_re.matchedLength();
+
+ setFormat(index, len, _strings_f);
+ index = text.indexOf(_strings_re, index + len);
+ }
+
+ // single line comments
+ index = text.indexOf(_comment_re);
+ if (index >= 0)
+ setFormat(index, _comment_re.matchedLength(), _comment_f);
+}
+
+void FxSyntax::setup()
+{
+ QString pattern;
+
+ // format
+ _structs_f.setFontWeight(QFont::Bold);
+ _structs_f.setForeground(Qt::green);
+
+ _functions_f.setFontWeight(QFont::Bold);
+ _functions_f.setForeground(Qt::darkGreen);
+
+ _ints_f.setFontWeight(QFont::Bold);
+ _ints_f.setForeground(Qt::darkBlue);
+
+ _floats_f.setFontWeight(QFont::Bold);
+ _floats_f.setForeground(Qt::darkRed);
+
+ _strings_f.setFontWeight(QFont::Bold);
+ _strings_f.setFontItalic(true);
+ _strings_f.setForeground(Qt::darkYellow);
+
+ _comment_f.setFontItalic(true);
+ _comment_f.setForeground(Qt::darkGray);
+
+
+ // regexp
+ pattern.append("\\b(");
+ pattern.append(structs.split(" ").join("|"));
+ pattern.append(")\\b");
+ _structs_re.setPattern(pattern);
+
+ pattern.clear();
+ pattern.append("\\b(");
+ pattern.append(functions.split(" ").join("|"));
+ pattern.append(")\\b");
+ _functions_re.setPattern(pattern);
+
+ _ints_re.setPattern("\\b[0-9]+\\b");
+
+ _floats_re.setPattern("\\b[0-9]+\\.[0-9]+\\b");
+
+ _strings_re.setPattern("(\"[^\"]*)\"");
+
+ _comment_re.setPattern("//[^\n]*");
+}
--- /dev/null
+#pragma once
+
+#include <QSyntaxHighlighter>
+
+class FxSyntax : public QSyntaxHighlighter {
+ Q_OBJECT
+public:
+ explicit FxSyntax(QObject *parent = 0);
+ explicit FxSyntax(QTextDocument *parent = 0);
+ virtual ~FxSyntax();
+
+protected:
+ virtual void highlightBlock(const QString& text) override;
+ void setup();
+
+private:
+ QTextCharFormat _structs_f;
+ QTextCharFormat _functions_f;
+ QTextCharFormat _ints_f;
+ QTextCharFormat _floats_f;
+ QTextCharFormat _strings_f;
+ QTextCharFormat _comment_f;
+ QRegExp _structs_re;
+ QRegExp _functions_re;
+ QRegExp _ints_re;
+ QRegExp _floats_re;
+ QRegExp _strings_re;
+ QRegExp _comment_re;
+};
--- /dev/null
+#include "IniSyntax.hxx"
+
+// --- internal constants ---
+
+const QString keywords("set");
+
+// --- constructors and deconstructors ---
+
+IniSyntax::IniSyntax(QObject *parent)
+: QSyntaxHighlighter(parent)
+{
+ setup();
+}
+
+IniSyntax::IniSyntax(QTextDocument *parent)
+: QSyntaxHighlighter(parent)
+{
+ setup();
+}
+
+IniSyntax::~IniSyntax()
+{
+}
+
+// --- protected methods ---
+
+void IniSyntax::highlightBlock(const QString& text)
+{
+ qint32 index = 0;
+
+ setCurrentBlockState(0);
+
+ // keywords
+ index = text.indexOf(_keywords_re);
+ while (index >= 0)
+ {
+ auto len = _keywords_re.matchedLength();
+
+ setFormat(index, len, _keywords_f);
+ index = text.indexOf(_keywords_re, index + len);
+ }
+
+ // ints
+ index = text.indexOf(_ints_re);
+ while (index >= 0)
+ {
+ auto len = _ints_re.matchedLength();
+
+ setFormat(index, len, _ints_f);
+ index = text.indexOf(_ints_re, index + len);
+ }
+
+ // strings
+ index = text.indexOf(_strings_re);
+ while (index >= 0)
+ {
+ auto len = _strings_re.matchedLength();
+
+ setFormat(index, len, _strings_f);
+ index = text.indexOf(_strings_re, index + len);
+ }
+
+ // single line comments
+ index = text.indexOf(_comment_re);
+ if (index >= 0)
+ setFormat(index, _comment_re.matchedLength(), _comment_f);
+}
+
+void IniSyntax::setup()
+{
+ QString pattern;
+
+ // format
+ _keywords_f.setFontWeight(QFont::Bold);
+ _keywords_f.setForeground(Qt::green);
+
+ _ints_f.setFontWeight(QFont::Bold);
+ _ints_f.setForeground(Qt::darkBlue);
+
+ _strings_f.setFontWeight(QFont::Bold);
+ _strings_f.setFontItalic(true);
+ _strings_f.setForeground(Qt::darkYellow);
+
+ _comment_f.setFontItalic(true);
+ _comment_f.setForeground(Qt::darkGray);
+
+
+ // regexp
+ pattern.append("\\b(");
+ pattern.append(keywords.split(" ").join("|"));
+ pattern.append(")\\b");
+ _keywords_re.setPattern(pattern);
+
+ _ints_re.setPattern("\\b[0-9]+\\b");
+
+ _strings_re.setPattern("(\"[^\"]*)\"");
+
+ _comment_re.setPattern("//[^\n]*");
+}
--- /dev/null
+#pragma once
+
+#include <QSyntaxHighlighter>
+
+class IniSyntax : public QSyntaxHighlighter {
+ Q_OBJECT
+public:
+ explicit IniSyntax(QObject *parent = 0);
+ explicit IniSyntax(QTextDocument *parent = 0);
+ virtual ~IniSyntax();
+
+protected:
+ virtual void highlightBlock(const QString& text) override;
+ void setup();
+
+private:
+ QTextCharFormat _keywords_f;
+ QTextCharFormat _ints_f;
+ QTextCharFormat _strings_f;
+ QTextCharFormat _comment_f;
+ QRegExp _keywords_re;
+ QRegExp _ints_re;
+ QRegExp _strings_re;
+ QRegExp _comment_re;
+};
const QColor Grey(180, 180, 180);
const QColor Red(255, 180, 180);
const QString TableHeader("header size;position;compressed size;original size;name length;name;SHA-1");
+const QRegExp TextFiles("\\b(*.def|*.fx|*.ini|*.txt|.tsc|*.lua)\\b");
// --- constructors and deconstructors ---
if (text.contains(".def", Qt::CaseInsensitive) || text.contains(".fx", Qt::CaseInsensitive)
|| text.contains(".ini", Qt::CaseInsensitive) || text.contains(".txt", Qt::CaseInsensitive)
- || text.contains(".tsc", Qt::CaseInsensitive))
+ || text.contains(".tsc", Qt::CaseInsensitive) || text.contains(".lua", Qt::CaseInsensitive))
_ui->act_file_text->setEnabled(true);
else
_ui->act_file_image->setEnabled(false);
#include <QString>
#include "TextWindow.hxx"
#include "ui_TextWindow.h"
+#include "DefSyntax.hxx"
+#include "FxSyntax.hxx"
+#include "IniSyntax.hxx"
// --- constructors and deconstructors ---
TextWindow::TextWindow(QWidget *parent)
-: QMainWindow(parent), _ui(new Ui::TextWindow), _num(0)
+: QMainWindow(parent), _ui(new Ui::TextWindow), _def(new DefSyntax(this)), _fx(new FxSyntax(this)),
+ _ini(new IniSyntax(this)), _num(0)
{
_ui->setupUi(this);
TextWindow::~TextWindow()
{
+ delete _ini;
+ delete _fx;
+ delete _def;
delete _ui;
}
{
_entry = entry;
_num = row;
+ _def->setDocument(0);
_ui->ed_text->setPlainText(entry.oData());
_ui->ed_name->setText(entry.name());
_ui->ed_lines->setText(QString::number(_ui->ed_text->document()->lineCount()));
_ui->ed_size->setText(QString::number(_ui->ed_text->toPlainText().size()));
+
+ if (entry.name().contains(".def", Qt::CaseInsensitive))
+ _def->setDocument(_ui->ed_text->document());
+
+ if (entry.name().contains(".fx", Qt::CaseInsensitive))
+ _fx->setDocument(_ui->ed_text->document());
+
+ if (entry.name().contains(".ini", Qt::CaseInsensitive))
+ _ini->setDocument(_ui->ed_text->document());
}
// --- protected methods ---
{
class TextWindow;
}
+class DefSyntax;
+class FxSyntax;
+class IniSyntax;
class TextWindow : public QMainWindow {
Q_OBJECT
private:
Ui::TextWindow *_ui;
+ DefSyntax *_def;
+ FxSyntax *_fx;
+ IniSyntax *_ini;
NCFile _entry;
quint32 _num;
};
};
}
-struct BSPHeader {
- uint32_t magic;
- uint32_t unknown;
- uint32_t version;
- uint16_t systime[8];
-};
-
struct Chunk {
uint32_t type;
uint32_t size;
}
glEnd();
}
- /*for (Vertex& vert : vertices)
- {
- glBegin(GL_POINTS);
- glColor3f(1.0, 1.0, 1.0);
- glVertex3f(vert.x / 10.0, vert.y / 10.0, vert.z / 10.0);
- glEnd();
- }*/
- /*glBegin(GL_POINTS);
- glColor3f(1.0, 1.0, 1.0);
- glVertex3f(-496.0, -512.0, -233.0);
- glVertex3f(-496.0, -512.0, -322.0);
- glVertex3f(-496.0, -512.0, -452.0);
- glVertex3f(-304.0, -512.0, -452.0);
- glVertex3f(-304.0, -512.0, -357.0);
- glVertex3f(-304.0, -512.0, -304.0);
- glVertex3f(-304.0, -512.0, -233.0);
- glEnd();*/
glutSwapBuffers();
}
{
std::string filename = "test.bsp";
std::ifstream file;
- struct BSPHeader header;
if (argc == 2)
filename = argv[1];
if (file.is_open() && file.good())
{
Chunk chunk;
- size_t size = file.seekg(0, std::ios_base::end).tellg();
+ //size_t size = file.seekg(0, std::ios_base::end).tellg();
file.seekg(0, std::ios_base::beg);
file.close();
}
- //for (Vertex& vert : vertices)
- // std::cout << "vertex " << vert.x << " " << vert.y << " " << vert.z << std::endl;
-
- //for (uint32_t& ind : indexes)
- // std::cout << "index " << ind << std::endl;
-
- /*for (Face& face : faces)
- {
- std::cout << "Face: " << face.vertex_count << " (" << face.first << ") ->";
- for (size_t i = 0; i < face.vertex_count; ++i)
- {
- std::cout << " " << indexes[i + face.first];
- }
- std::cout << std::endl;
- std::cout << " ";
- for (size_t i = 0; i < face.vertex_count; ++i)
- {
- Vertex& vert = vertices[indexes[i + face.first]];
- std::cout << " (" << vert.x << ", " << vert.y << ", " << vert.z << ")";
- }
- std::cout << std::endl << std::endl;
- }*/
-
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(800, 600);