From 8c29b00fa46cb54d7dc55c1e0b354147459e5847 Mon Sep 17 00:00:00 2001 From: garak Date: Sun, 28 Apr 2019 09:05:37 -0400 Subject: [PATCH] modify event comboboxes, fix heal location parsing --- include/core/parseutil.h | 1 - include/project.h | 1 + include/ui/noscrollcombobox.h | 1 + src/core/parseutil.cpp | 18 ---------------- src/mainwindow.cpp | 39 +++++++++++++++++++++++++++-------- src/project.cpp | 21 ++++++++++++++----- src/ui/noscrollcombobox.cpp | 6 ++++++ 7 files changed, 54 insertions(+), 33 deletions(-) diff --git a/include/core/parseutil.h b/include/core/parseutil.h index e85469c1..1cb0c882 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -37,7 +37,6 @@ public: void strip_comment(QString*); QList* parseAsm(QString); int evaluateDefine(QString, QMap*); - QList* parseHealLocs(QString); private: QList tokenizeExpression(QString expression, QMap* knownIdentifiers); QList generatePostfix(QList tokens); diff --git a/include/project.h b/include/project.h index 004db8b6..9824eebd 100644 --- a/include/project.h +++ b/include/project.h @@ -117,6 +117,7 @@ public: void readSecretBaseIds(); void readBgEventFacingDirections(); void readMetatileBehaviors(); + void readHealLocations(); void loadEventPixmaps(QList objects); QMap getEventObjGfxConstants(); diff --git a/include/ui/noscrollcombobox.h b/include/ui/noscrollcombobox.h index 1291c7e9..87a4f55f 100644 --- a/include/ui/noscrollcombobox.h +++ b/include/ui/noscrollcombobox.h @@ -10,6 +10,7 @@ class NoScrollComboBox : public QComboBox public: explicit NoScrollComboBox(QWidget *parent = nullptr); void wheelEvent(QWheelEvent *event); + void hideArrow(); private: }; diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index ae8282a7..692c0568 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -68,24 +68,6 @@ int ParseUtil::evaluateDefine(QString define, QMap* knownDefines) return evaluatePostfix(postfixExpression); } -// arg here is the text in the file src/data/heal_locations.h -// returns a list of HealLocations (mapname, x, y) -QList* ParseUtil::parseHealLocs(QString text) { - QList *parsed = new QList; - QStringList lines = text.split('\n'); - - int i = 1; - for (auto line : lines){ - if (line.contains("MAP_GROUP")){ - QList li = line.remove(QRegExp("[{|} ]")).split(","); - HealLocation hloc = HealLocation(li[1].remove("MAP_NUM(").remove(")"), i, li[2].toUShort(), li[3].toUShort()); - parsed->append(hloc); - i++; - } - } - return parsed; -} - QList ParseUtil::tokenizeExpression(QString expression, QMap* knownIdentifiers) { QList tokens; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 87fa3f52..f8a76bf7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -80,6 +80,8 @@ void MainWindow::initCustomUI() { ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onOpenMapListContextMenu(const QPoint &))); + + // temporary } void MainWindow::initExtraSignals() { @@ -609,6 +611,7 @@ void MainWindow::loadDataStructures() { project->readBgEventFacingDirections(); project->readMetatileBehaviors(); project->readTilesetProperties(); + project->readHealLocations(); } void MainWindow::populateMapList() { @@ -1405,7 +1408,9 @@ void MainWindow::updateSelectedObjects() { combo->addItem("NONE", "0"); combo->addItem("NORMAL", "1"); combo->addItem("SEE ALL DIRECTIONS", "3"); - combo->setToolTip("The trainer type of this event object. If it is not a trainer, use NONE. SEE ALL DIRECTIONS should only be used with a sight radius of 1."); + combo->setToolTip("The trainer type of this event object.\n" + "If it is not a trainer, use NONE. SEE ALL DIRECTIONS\n" + "should only be used with a sight radius of 1."); int index = combo->findData(value); if (index != -1) { @@ -1426,6 +1431,7 @@ void MainWindow::updateSelectedObjects() { combo->addItems(*editor->project->mapNames); combo->setToolTip("The destination map name of the warp."); } else if (key == "destination_warp") { + combo->hideArrow(); combo->setToolTip("The warp id on the destination map."); } else if (key == "item") { if (!editor->project->itemNames->contains(value)) { @@ -1446,8 +1452,10 @@ void MainWindow::updateSelectedObjects() { combo->addItem(value); } combo->addItems(*editor->project->varNames); - combo->setToolTip("The variable by which the script is triggered. The script is triggered when this variable's value matches 'Var Value'."); - } else if (key == "script_var_value") { + combo->setToolTip("The variable by which the script is triggered.\n" + "The script is triggered when this variable's value matches 'Var Value'."); + } else if (key == "script_var_value") { + combo->hideArrow(); combo->setToolTip("The variable's value which triggers the script."); } else if (key == "movement_type") { if (!editor->project->movementTypes->contains(value)) { @@ -1459,7 +1467,8 @@ void MainWindow::updateSelectedObjects() { item->updatePixmap(); }); combo->addItems(*editor->project->movementTypes); - combo->setToolTip("The object's natural movement behavior when the player is not interacting with it."); + combo->setToolTip("The object's natural movement behavior when\n" + "the player is not interacting with it."); } else if (key == "weather") { if (!editor->project->coordEventWeatherNames->contains(value)) { combo->addItem(value); @@ -1471,21 +1480,33 @@ void MainWindow::updateSelectedObjects() { combo->addItem(value); } combo->addItems(*editor->project->secretBaseIds); - combo->setToolTip("The secret base id which is inside this secret base entrance. Secret base ids are meant to be unique to each and every secret base entrance."); + combo->setToolTip("The secret base id which is inside this secret\n" + "base entrance. Secret base ids are meant to be\n" + "unique to each and every secret base entrance."); } else if (key == "player_facing_direction") { if (!editor->project->bgEventFacingDirections->contains(value)) { combo->addItem(value); } combo->addItems(*editor->project->bgEventFacingDirections); - combo->setToolTip("The direction which the player must be facing to be able to interact with this event."); + combo->setToolTip("The direction which the player must be facing\n" + "to be able to interact with this event."); } else if (key == "radius_x") { - combo->setToolTip("The maximum number of metatiles this object is allowed to move left or right during its normal movement behavior actions."); + combo->hideArrow(); + combo->setToolTip("The maximum number of metatiles this object\n" + "is allowed to move left or right during its\n" + "normal movement behavior actions."); } else if (key == "radius_y") { - combo->setToolTip("The maximum number of metatiles this object is allowed to move up or down during its normal movement behavior actions."); + combo->hideArrow(); + combo->setToolTip("The maximum number of metatiles this object\n" + "is allowed to move up or down during its\n" + "normal movement behavior actions."); } else if (key == "script_label") { + combo->hideArrow(); combo->setToolTip("The script which is executed with this event."); } else if (key == "sight_radius_tree_id") { - combo->setToolTip("The maximum sight range of a trainer, OR the unique id of the berry tree."); + combo->hideArrow(); + combo->setToolTip("The maximum sight range of a trainer,\n" + "OR the unique id of the berry tree."); } else { combo->addItem(value); } diff --git a/src/project.cpp b/src/project.cpp index f1492ece..b4ca40dd 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1306,11 +1306,6 @@ void Project::readMapGroups() { groupNames = groups; groupedMapNames = groupedMaps; mapNames = maps; - - QString hltext = readTextFile(root + QString("/src/data/heal_locations.h")); - QList* hl = ParseUtil().parseHealLocs(hltext); - flyableMaps = *hl; - delete hl; } Map* Project::addNewMapToGroup(QString mapName, int groupNum) { @@ -1508,6 +1503,22 @@ void Project::readRegionMapSections() { } } +void Project::readHealLocations() { + QString text = readTextFile(root + "/src/data/heal_locations.h"); + text.replace(QRegularExpression("//.*?(\r\n?|\n)|/\\*.*?\\*/", QRegularExpression::DotMatchesEverythingOption), ""); + + QRegularExpression regex("MAP_GROUP\\((?[A-Za-z0-9_]*)\\),\\s+MAP_NUM\\((\\1)\\),\\s+(?[0-9A-Fa-fx]*),\\s+(?[0-9A-Fa-fx]*)"); + QRegularExpressionMatchIterator iter = regex.globalMatch(text); + + for (int i = 1; iter.hasNext(); i++) { + QRegularExpressionMatch match = iter.next(); + QString mapName = match.captured("map"); + unsigned x = match.captured("x").toUShort(); + unsigned y = match.captured("y").toUShort(); + flyableMaps.append(HealLocation(mapName, i, x, y)); + } +} + void Project::readItemNames() { QString filepath = root + "/include/constants/items.h"; QStringList prefixes = (QStringList() << "ITEM_"); diff --git a/src/ui/noscrollcombobox.cpp b/src/ui/noscrollcombobox.cpp index 723289d9..d5490c21 100644 --- a/src/ui/noscrollcombobox.cpp +++ b/src/ui/noscrollcombobox.cpp @@ -13,3 +13,9 @@ void NoScrollComboBox::wheelEvent(QWheelEvent *event) if (hasFocus()) QComboBox::wheelEvent(event); } + +void NoScrollComboBox::hideArrow() +{ + this->setStyleSheet("QComboBox {border: 0 black;}" + "QComboBox::drop-down {border: 0px;}"); +}