Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,5 @@ compile_commands.json

# Custom
.build
.release
.install
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,14 @@ set(PROJECT_SOURCES
"src/JsmData.h"
"src/JsmExpression.cpp"
"src/JsmExpression.h"
"src/JsmHelpDialog.cpp"
"src/JsmHelpDialog.h"
"src/JsmHighlighter.cpp"
"src/JsmHighlighter.h"
"src/JsmOpcode.cpp"
"src/JsmOpcode.h"
"src/JsmPseudoCompiler.cpp"
"src/JsmPseudoCompiler.h"
"src/JsmScripts.cpp"
"src/JsmScripts.h"
"src/Listwidget.cpp"
Expand Down
695 changes: 695 additions & 0 deletions src/JsmHelpDialog.cpp

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions src/JsmHelpDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/****************************************************************************
** Deling Final Fantasy VIII Field Editor
** Copyright (C) 2009-2024 Arzel Jérôme <myst6re@gmail.com>
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#pragma once

#include <QtWidgets>

class JsmHelpDialog : public QDialog
{
Q_OBJECT
public:
explicit JsmHelpDialog(QWidget *parent = nullptr);
signals:
void insertSignature(const QString &signature);
private:
void buildContent();
QTreeWidget *_categoryTree;
QTextBrowser *_detailView;
QLineEdit *_searchField;
private slots:
void onCategorySelected();
void onSearch(const QString &text);
void onItemDoubleClicked(QTreeWidgetItem *item, int column);
};
61 changes: 37 additions & 24 deletions src/JsmHighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
****************************************************************************/
#include "JsmHighlighter.h"
#include "files/JsmFile.h"
#include <QApplication>

bool JsmHighlighter::isDarkMode() const
{
QColor bg = QApplication::palette().color(QPalette::Base);
// Luminance check: dark if background brightness < 128
return (bg.red() * 299 + bg.green() * 587 + bg.blue() * 114) / 1000 < 128;
}

JsmHighlighter::JsmHighlighter(QTextDocument *parent) :
QSyntaxHighlighter(parent)
Expand Down Expand Up @@ -66,22 +74,27 @@ void JsmHighlighter::highlightBlock(const QString &text)

void JsmHighlighter::highlightBlockPseudoCode(const QString &text)
{
bool dark = isDarkMode();

// Keywords
applyReg(text, _regKeywords, QColor(0x80, 0x80, 0x00)); // Yellow
applyReg(text, _regKeywords, dark ? QColor(0xD4, 0xD4, 0x6A) : QColor(0x80, 0x80, 0x00));

// Numeric literals and constants
applyReg(text, _regNumeric, dark ? QColor(0x6C, 0xBE, 0xF0) : QColor(0x00, 0x00, 0x80));
applyReg(text, _regConst, dark ? QColor(0x6C, 0xBE, 0xF0) : QColor(0x00, 0x00, 0x80));

// Types
applyReg(text, _regNumeric, QColor(0x00, 0x00, 0x80)); // blue
applyReg(text, _regConst, QColor(0x00, 0x00, 0x80)); // blue
applyReg(text, _regVar, QColor(0x80, 0x00, 0x00)); // red
// Variables
applyReg(text, _regVar, dark ? QColor(0xF0, 0x90, 0x70) : QColor(0x80, 0x00, 0x00));

// Methods
applyReg(text, _regExec, QColor(0x80, 0x00, 0x80)); // purple
// Method calls / exec
applyReg(text, _regExec, dark ? QColor(0xC5, 0x80, 0xDA) : QColor(0x80, 0x00, 0x80));
}

void JsmHighlighter::highlightBlockOpcodes(const QString &text)
{
QStringList rows = text.split(QRegularExpression("[\\t ]+"), Qt::SkipEmptyParts);
bool ok;
bool dark = isDarkMode();

if (rows.isEmpty()) {
return;
Expand All @@ -92,26 +105,30 @@ void JsmHighlighter::highlightBlockOpcodes(const QString &text)

if (opcode != -1) {
if (opcode == JsmOpcode::CAL) {
setFormat(text.indexOf(name), name.size(), QColor(0x00,0x66,0xcc));
setFormat(text.indexOf(name), name.size(), dark ? QColor(0x56,0x9C,0xD6) : QColor(0x00,0x66,0xcc));
} else if (opcode >= JsmOpcode::JMP && opcode <= JsmOpcode::GJMP) {
setFormat(text.indexOf(name), name.size(), QColor(0x66,0xcc,0x00));
setFormat(text.indexOf(name), name.size(), dark ? QColor(0xB5,0xCE,0xA8) : QColor(0x66,0xcc,0x00));
} else if (opcode == JsmOpcode::LBL) {
setFormat(text.indexOf(name), name.size(), QColor(0xcc,0x00,0x00));
setFormat(text.indexOf(name), name.size(), dark ? QColor(0xF4,0x70,0x67) : QColor(0xcc,0x00,0x00));
} else if (opcode >= JsmOpcode::RET && opcode <= JsmOpcode::PSHAC) {
setFormat(text.indexOf(name), name.size(), QColor(0x66,0x66,0x66));
setFormat(text.indexOf(name), name.size(), dark ? QColor(0xA0,0xA0,0xA0) : QColor(0x66,0x66,0x66));
} else if (opcode >= JsmOpcode::REQ && opcode <= JsmOpcode::PREQEW) {
setFormat(text.indexOf(name), name.size(), QColor(0xcc,0x66,0x00));
setFormat(text.indexOf(name), name.size(), dark ? QColor(0xE0,0xA0,0x50) : QColor(0xcc,0x66,0x00));
} else if (opcode == JsmOpcode::MES || opcode == JsmOpcode::ASK
|| opcode == JsmOpcode::AMESW || opcode == JsmOpcode::AMES
|| opcode == JsmOpcode::AASK || opcode == JsmOpcode::RAMESW) {
QTextCharFormat textFormat;
textFormat.setBackground(QColor(0xFF,0xFF,0x00));
if (dark) {
textFormat.setForeground(QColor(0xFF, 0xE0, 0x80));
} else {
textFormat.setBackground(QColor(0xFF,0xFF,0x00));
}
setFormat(text.indexOf(name), name.size(), textFormat);
}
} else if (name.startsWith("LABEL", Qt::CaseInsensitive)) {
name.mid(5).toInt(&ok);
if (ok) {
setFormat(text.indexOf(name), name.size(), QColor(0x66,0xcc,0x00));
setFormat(text.indexOf(name), name.size(), dark ? QColor(0xB5,0xCE,0xA8) : QColor(0x66,0xcc,0x00));
}
return;
}
Expand All @@ -121,37 +138,33 @@ void JsmHighlighter::highlightBlockOpcodes(const QString &text)
}

const QString &param = rows.at(1);
QColor paramColor = dark ? QColor(0xC5,0x80,0xDA) : QColor(0x66,0x00,0xcc);

if (opcode == JsmOpcode::CAL && JsmFile::opcodeNameCalc.contains(param.toUpper())) {
setFormat(text.indexOf(param), param.size(), QColor(0x00,0x66,0xcc));
setFormat(text.indexOf(param), param.size(), dark ? QColor(0x56,0x9C,0xD6) : QColor(0x00,0x66,0xcc));
} else if (opcode >= JsmOpcode::JMP && opcode <= JsmOpcode::GJMP
&& param.startsWith("LABEL", Qt::CaseInsensitive)) {
param.mid(5).toInt(&ok);
if (ok) {
setFormat(text.indexOf(param), param.size(), QColor(0x66,0xcc,0x00));
setFormat(text.indexOf(param), param.size(), dark ? QColor(0xB5,0xCE,0xA8) : QColor(0x66,0xcc,0x00));
}
} else if (opcode >= JsmOpcode::PSHI_L && opcode <= JsmOpcode::POPI_L
&& param.startsWith("TEMP", Qt::CaseInsensitive)) {
param.mid(4).toInt(&ok);
if (ok) {
setFormat(text.indexOf(param), param.size(), QColor(0x66,0x00,0xcc));
setFormat(text.indexOf(param), param.size(), paramColor);
}
} else if (opcode >= JsmOpcode::PSHM_B && opcode <= JsmOpcode::PSHSM_L
&& param.startsWith("VAR", Qt::CaseInsensitive)) {
param.mid(3).toInt(&ok);
if (ok) {
setFormat(text.indexOf(param), param.size(), QColor(0x66,0x00,0xcc));
setFormat(text.indexOf(param), param.size(), paramColor);
}
} else if (opcode == JsmOpcode::PSHAC
&& param.startsWith("MODEL", Qt::CaseInsensitive)) {
param.mid(5).toInt(&ok);
if (ok) {
setFormat(text.indexOf(param), param.size(), QColor(0x66,0x00,0xcc));
setFormat(text.indexOf(param), param.size(), paramColor);
}
} else {
// param.toInt(&ok);
// if (ok) {
// setFormat(text.indexOf(param), param.size(), QColor(0x00,0x66,0xcc));
// }
}
}
1 change: 1 addition & 0 deletions src/JsmHighlighter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class JsmHighlighter : public QSyntaxHighlighter
private:
void highlightBlockPseudoCode(const QString &text);
void highlightBlockOpcodes(const QString &text);
bool isDarkMode() const;
void applyReg(const QString &text, const QRegularExpression &regExp,
const QTextCharFormat &format);
void applyReg(const QString &text, const QRegularExpression &regExp,
Expand Down
Loading
Loading