Skip to content

Commit

Permalink
Jass editor syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnherfst committed Jan 29, 2019
1 parent 489cc61 commit deeead2
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 50 deletions.
Binary file modified HiveWE/Data/Test.w3x
Binary file not shown.
4 changes: 4 additions & 0 deletions HiveWE/HiveWE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ HiveWE::HiveWE(QWidget* parent) : QMainWindow(parent) {
// });
//});

QTimer::singleShot(5, [this]() {
window_handler.create_or_raise<TriggerEditor>();
});

connect(ui.ribbon->import_manager, &QRibbonButton::clicked, []() { window_handler.create_or_raise<ImportManager>(); });
connect(ui.ribbon->trigger_viewer, &QRibbonButton::clicked, []() { window_handler.create_or_raise<TriggerEditor>(); });

Expand Down
1 change: 1 addition & 0 deletions HiveWE/HiveWE.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
</ClCompile>
<ClCompile Include="GeneratedFiles\Release\moc_JassEditor.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseSymbols|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\Release\moc_MainRibbon.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ReleaseSymbols|x64'">true</ExcludedFromBuild>
Expand Down
86 changes: 52 additions & 34 deletions HiveWE/JassEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#include "stdafx.h"

Styling::Styling(QWidget* parent) : QsciLexerCustom(parent) {
setDefaultColor(QColor("#ff000000"));
setDefaultPaper(QColor("#ffffffff"));
setDefaultFont(QFont("Consolas", 10));
//setDefaultColor(QColor("#ff000000"));
//setDefaultPaper(QColor("#ffffffff"));

setColor(QColor("#ff000000"), 0);
setColor(QColor("#ff7f0000"), 1);
setColor(QColor("#ff0000bf"), 2);
setColor(QColor("#ff007f00"), 3);
setColor(QColor(0, 200, 0), 4);
//setColor(QColor("#ff000000"), 0);
setColor(QColor(181, 206, 168), 1); // numbers
setColor(QColor(56, 156, 214), 2); // keywords
setColor(QColor(214, 157, 133), 3); // string
setColor(QColor(87, 166, 74), 4); // comment

setPaper(QColor("#ffffffff"), 0);
setPaper(QColor("#ffffffff"), 1);
setPaper(QColor("#ffffffff"), 2);
setPaper(QColor("#ffffffff"), 3);
setPaper(QColor("#ffffffff"), 4);
//setPaper(QColor("#ffffffff"), 0);
//setPaper(QColor("#ffffffff"), 1);
//setPaper(QColor("#ffffffff"), 2);
//setPaper(QColor("#ffffffff"), 3);
//setPaper(QColor("#ffffffff"), 4);

setFont(QFont("Consolas", 10, QFont::Normal), 0);
setFont(QFont("Consolas", 10, QFont::Normal), 1);
Expand All @@ -24,15 +24,18 @@ Styling::Styling(QWidget* parent) : QsciLexerCustom(parent) {
setFont(QFont("Consolas", 10, QFont::Normal), 4);

std::vector<std::string> operators = { "+", "-", "/", "*", ",", "=", ":", "(", ")", ">=", "<=", "!=", "[", "]", "<", ">", "&" };
blocks = QStringList({ "native", "constant", "exitwhen", "takes", "returns", "private", "public", "keyword", "static",
"delegate", "initializer", "uses", "needs", "requires", "defaults", "interface", "endinterface", "globals", "endglobals",
"function", "endfunction", "scope", "endscope", "library", "library_once", "endlibrary", "struct", "endstruct", "method",
"endmethod", "loop", "endloop", "if", "then", "else", "elseif", "endif", "operator", "readonly", "stub", "module", "endmodule",
"implement", "optional" });
blocks = QStringList({ "class", "return", "if", "else", "while", "for", "in", "break", "new", "null", "package", "endpackage",
"function", "returns", "public", "private", "protected", "import", "initlater", "native", "nativetype", "extends", "interface",
"implements", "module", "use", "abstract", "static", "thistype", "override", "immutable", "it", "array", "and", "or", "not",
"this", "construct", "ondestroy", "destroy", "type", "constant", "endfunction", "nothing", "init", "castTo", "tuple", "div",
"mod", "let", "from", "to", "downto", "step", "endpackage", "skip", "true", "false", "var", "instanceof", "super", "enum",
"switch", "case", "default", "typeId", "begin", "end", "compiletime", "library", "endlibrary", "scope", "endscope", "requires",
"uses", "needs", "struct", "endstruct", "then", "endif", "loop", "exitwhen", "endloop", "method", "takes", "endmethod", "set",
"call", "globals", "endglobals", "initializer", "elseif", "vararg", "local" });
}

const char* Styling::language() const {
return "Ayylmao";
return "Vjass";
}

QString Styling::description(int style) const {
Expand All @@ -48,54 +51,69 @@ QString Styling::description(int style) const {
case 4:
return "Style4";
}
return "Idunnoman";
return "Style0";
}

void Styling::styleText(int start, int end) {
startStyling(start);

QString text = editor()->text().mid(start, end - start);



QRegExp expression(R"(([*]\/|\/[*]|\s+|\w+|\W))");
QRegExp expression(R"((\"\S*\"|\/\/[^\r\n]+|[*]\/|\/[*]|\w+|\W|[*]\/|\/[*]))");
QStringList tokens;
int pos = 0;
while ((pos = expression.indexIn(text, pos)) != -1) {
tokens << expression.cap(1);
pos += expression.matchedLength();
}

bool linecomment = false;
bool multiline = false;
if (start > 0) {
int previous_style_nr = editor()->SendScintilla(QsciScintilla::SCI_GETSTYLEAT, start - 1);
if (previous_style_nr == 4) {
multiline = true;
}
}

for (auto&& i : tokens) {
/*if (linecomment) {
linecomment = (i != "\n");
if (multiline) {
setStyling(i.length(), 4);

if (i == "*/") {
multiline = false;
}
continue;
}
if (i == "//") {
linecomment = true;
setStyling(i.length(), 4);*/
if (blocks.contains(i)) {

if (i.startsWith("//")) {
setStyling(i.length(), 4);
} else if (i == "/*") {
multiline = true;
setStyling(i.length(), 4);
} else if (blocks.contains(i)) { // Keywords
setStyling(i.length(), 2);
} else if (i.contains(QRegExp("[0-9]+(.[0-9]*)?"))) {
} else if (i.contains(QRegExp(R"(^[0-9]+$)"))) { // Numbers
setStyling(i.length(), 1);
} else if (i.contains(QRegExp(R"(^\".*\"$)"))) {
setStyling(i.length(), 3);
} else {
setStyling(i.length(), 0);
}
}

}



JassEditor::JassEditor(QWidget *parent) : QsciScintilla(parent) {
setLexer(lexer);
setCaretForegroundColor(QColor(255, 255, 255));
setMargins(1);
setMarginType(0, QsciScintilla::MarginType::NumberMargin);
setMarginWidth(0, 100);
setMarginLineNumbers(0, true);

setLexer(lexer);
setIndentationsUseTabs(true);
setTabIndents(true);
setIndentationGuides(true);
setTabWidth(4);

connect(this, &QsciScintilla::textChanged, this, &JassEditor::calculate_margin_width);
}
Expand Down
27 changes: 26 additions & 1 deletion HiveWE/SettingsEditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="themeLabel">
<property name="text">
<string>Theme</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="theme">
<item>
<property name="text">
<string>Light</string>
</property>
</item>
<item>
<property name="text">
<string>Dark</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_1">
<attribute name="title">
Expand Down Expand Up @@ -63,4 +86,6 @@
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
</ui>
<resources/>
<connections/>
</ui>
28 changes: 24 additions & 4 deletions HiveWE/Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ void Terrain::create() {
ground_texture_list.resize((width - 1) * (height - 1));
water_heights.resize(width * height);
water_exists_data.resize(width * height);


//update_ground_heights({ 0, 0, width, height });

for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
ground_corner_heights[j * width + i] = corners[i][j].final_ground_height();
Expand Down Expand Up @@ -91,8 +95,6 @@ void Terrain::create() {
continue;
}
} else if (bottom_left.ramp != top_left.ramp && bottom_right.ramp != top_right.ramp && !corners[i + (facing_left ? -1 : 1)][j + top_left.ramp].cliff) {


char bottom_char = bottom_left.ramp ? 'L' : 'A';
char top_char = top_left.ramp ? 'L' : 'A';

Expand Down Expand Up @@ -517,7 +519,7 @@ void Terrain::change_tileset(const std::vector<std::string>& new_tileset_ids, st
update_ground_textures({ 0, 0, width, height });
}

/// The texture of the tilepoint which is influenced by its surroundings. nearby cliff > blight > regular texture
/// The texture of the tilepoint which is influenced by its surroundings. nearby cliff/ramp > blight > regular texture
int Terrain::real_tile_texture(const int x, const int y) const {
for (int i = -1; i < 1; i++) {
for (int j = -1; j < 1; j++) {
Expand Down Expand Up @@ -684,7 +686,25 @@ void Terrain::update_ground_heights(const QRect& area) {
for (int j = area.y(); j < area.y() + area.height(); j++) {
for (int i = area.x(); i < area.x() + area.width(); i++) {
ground_heights[j * width + i] = corners[i][j].height; // todo 15.998???
ground_corner_heights[j * width + i] = corners[i][j].final_ground_height();



//float tt = 0.f;

//if (i < width && j < height) {
// Corner& bottom_left = corners[i][j];
// Corner& bottom_right = corners[i + 1][j];
// Corner& top_left = corners[i][j + 1];
// Corner& top_right = corners[i + 1][j + 1];

// if (bottom_left.ramp && top_left.ramp && bottom_right.ramp && top_right.ramp && !(bottom_left.layer_height == top_right.layer_height && top_left.layer_height == bottom_right.layer_height)) {
// tt = 0.5f;
// }
//}



ground_corner_heights[j * width + i] = corners[i][j].final_ground_height();// +tt;
}
}

Expand Down
2 changes: 1 addition & 1 deletion HiveWE/TriggerEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void TriggerEditor::item_clicked(QTreeWidgetItem* item) {
JassEditor* edit = new JassEditor;
layout->addWidget(edit);
edit->setText(QString::fromStdString(trigger.custom_text));
edit->setReadOnly(true);
//edit->setReadOnly(true);
} else {
QTreeWidget* edit = new QTreeWidget;
edit->setHeaderHidden(true);
Expand Down
41 changes: 31 additions & 10 deletions HiveWE/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@ extern "C" {
}
#endif

#include <stack>

class TT : public Doodad {

};

int main(int argc, char *argv[]) {
std::stack<Doodad*> triggerItems;
triggerItems.push(new TT());


QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
Expand All @@ -33,6 +23,37 @@ int main(int argc, char *argv[]) {
QApplication a(argc, argv);


qApp->setStyle(QStyleFactory::create("Fusion"));
// increase font size for better reading
QFont defaultFont = QApplication::font();
defaultFont.setPointSize(defaultFont.pointSize() + 2);
qApp->setFont(defaultFont);
// modify palette to dark
QPalette darkPalette;
darkPalette.setColor(QPalette::Window, QColor(53, 53, 53));
darkPalette.setColor(QPalette::WindowText, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(127, 127, 127));
darkPalette.setColor(QPalette::Base, QColor(42, 42, 42));
darkPalette.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
darkPalette.setColor(QPalette::Text, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
darkPalette.setColor(QPalette::Dark, QColor(35, 35, 35));
darkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20));
darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
darkPalette.setColor(QPalette::ButtonText, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127));
darkPalette.setColor(QPalette::BrightText, Qt::red);
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
darkPalette.setColor(QPalette::HighlightedText, Qt::white);
darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(127, 127, 127));

qApp->setPalette(darkPalette);


HiveWE w;
w.showMaximized();
return QApplication::exec();
Expand Down

0 comments on commit deeead2

Please sign in to comment.