diff --git a/docsrc/manual/scripting-capabilities.rst b/docsrc/manual/scripting-capabilities.rst index 4e016f6d..e18bd8e3 100644 --- a/docsrc/manual/scripting-capabilities.rst +++ b/docsrc/manual/scripting-capabilities.rst @@ -11,6 +11,9 @@ Porymap is extensible via scripting capabilities. This allows the user to write - Procedurally Generated Maps - Randomize Grass Patterns +.. note:: + If you are compiling Porymap yourself, these features will only be available if Qt's ``qml`` module is installed. + Custom Scripts Editor --------------------- diff --git a/include/core/network.h b/include/core/network.h index 321b3e99..23dc7eff 100644 --- a/include/core/network.h +++ b/include/core/network.h @@ -26,10 +26,14 @@ }); */ +#if __has_include() #include #include #include #include +#endif + +#ifdef QT_NETWORK_LIB class NetworkReplyData : public QObject { @@ -84,4 +88,6 @@ private: const QNetworkRequest getRequest(const QUrl &url); }; +#endif // QT_NETWORK_LIB + #endif // NETWORK_H diff --git a/include/mainwindow.h b/include/mainwindow.h index cd45fb5a..d15bde31 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -11,7 +11,6 @@ #include #include #include -#include #include "project.h" #include "orderedjson.h" #include "config.h" @@ -36,6 +35,10 @@ #include "message.h" #include "resizelayoutpopup.h" +#if __has_include() +#include +#endif + namespace Ui { @@ -56,7 +59,11 @@ public: void initialize(); + Q_INVOKABLE void setPrimaryTileset(const QString &tileset); + Q_INVOKABLE void setSecondaryTileset(const QString &tileset); + // Scripting API +#ifdef QT_QML_LIB Q_INVOKABLE QJSValue getBlock(int x, int y); void tryRedrawMapArea(bool forceRedraw); void redrawResizedMapArea(); @@ -119,8 +126,6 @@ public: Q_INVOKABLE int getNumSecondaryTilesetTiles(); Q_INVOKABLE QString getPrimaryTileset(); Q_INVOKABLE QString getSecondaryTileset(); - Q_INVOKABLE void setPrimaryTileset(const QString &tileset); - Q_INVOKABLE void setSecondaryTileset(const QString &tileset); void saveMetatilesByMetatileId(int metatileId); void saveMetatileAttributesByMetatileId(int metatileId); Metatile * getMetatile(int metatileId); @@ -172,6 +177,7 @@ public: Q_INVOKABLE void setAllowEscaping(bool allow); Q_INVOKABLE int getFloorNumber(); Q_INVOKABLE void setFloorNumber(int floorNumber); +#endif // QT_QML_LIB public slots: void on_mainTabBar_tabBarClicked(int index); @@ -325,8 +331,11 @@ private: QPointer layoutListProxyModel = nullptr; QPointer layoutTreeModel = nullptr; +#ifdef QT_NETWORK_LIB QPointer updatePromoter = nullptr; QPointer networkAccessManager = nullptr; +#endif + QPointer aboutWindow = nullptr; QPointer wildMonChart = nullptr; QPointer wildMonSearch = nullptr; diff --git a/include/scripting.h b/include/scripting.h index b2c43ed2..b700df8f 100644 --- a/include/scripting.h +++ b/include/scripting.h @@ -2,12 +2,19 @@ #ifndef SCRIPTING_H #define SCRIPTING_H -#include "mainwindow.h" -#include "block.h" +#include #include "scriptutility.h" -#include +class Block; +class Tile; +class MainWindow; + +#if __has_include() #include +#endif + + +#ifdef QT_QML_LIB // !! New callback functions or changes to existing callback function names/arguments // should be synced to resources/text/script_template.txt and docsrc/manual/scripting-capabilities.rst @@ -78,4 +85,34 @@ private: void invokeCallback(CallbackType type, QJSValueList args); }; +#else + +class Scripting +{ +public: + Scripting(MainWindow *) {} + ~Scripting() {} + static void init(MainWindow *) {} + static void stop() {} + static void populateGlobalObject(MainWindow *) {} + + static void cb_ProjectOpened(QString) {}; + static void cb_ProjectClosed(QString) {}; + static void cb_MetatileChanged(int, int, Block, Block) {}; + static void cb_BorderMetatileChanged(int, int, uint16_t, uint16_t) {}; + static void cb_BlockHoverChanged(int, int) {}; + static void cb_BlockHoverCleared() {}; + static void cb_MapOpened(QString) {}; + static void cb_LayoutOpened(QString) {}; + static void cb_MapResized(int, int, const QMargins &) {}; + static void cb_BorderResized(int, int, int, int) {}; + static void cb_MapShifted(int, int) {}; + static void cb_TilesetUpdated(const QString &) {}; + static void cb_MainTabChanged(int, int) {}; + static void cb_MapViewTabChanged(int, int) {}; + static void cb_BorderVisibilityToggled(bool) {}; +}; + +#endif // QT_QML_LIB + #endif // SCRIPTING_H diff --git a/include/scriptutility.h b/include/scriptutility.h index 09bfaae6..ae60d316 100644 --- a/include/scriptutility.h +++ b/include/scriptutility.h @@ -2,14 +2,24 @@ #ifndef SCRIPTUTILITY_H #define SCRIPTUTILITY_H -#include "mainwindow.h" +#if __has_include() +#include +#endif + +#ifdef QT_QML_LIB + +#include +#include +#include +#include + +class MainWindow; class ScriptUtility : public QObject { Q_OBJECT - public: - ScriptUtility(MainWindow *mainWindow); + ScriptUtility(MainWindow *mainWindow) : window(mainWindow) {} ~ScriptUtility(); QString getActionFunctionName(int actionIndex); @@ -69,4 +79,6 @@ private: QHash actionMap; }; +#endif // QT_QML_LIB + #endif // SCRIPTUTILITY_H diff --git a/include/ui/mapview.h b/include/ui/mapview.h index 023e1cac..34610bb1 100644 --- a/include/ui/mapview.h +++ b/include/ui/mapview.h @@ -1,7 +1,10 @@ #ifndef MAPVIEW_H #define MAPVIEW_H +#if __has_include() #include +#endif + #include "graphicsview.h" #include "overlay.h" #include "tile.h" @@ -22,6 +25,7 @@ public: void clearOverlayMap(); // Overlay scripting API +#ifdef QT_QML_LIB Q_INVOKABLE void clear(int layer); Q_INVOKABLE void clear(); Q_INVOKABLE void hide(int layer); @@ -74,6 +78,7 @@ public: Q_INVOKABLE void addTileImage(int x, int y, int tileId, bool xflip, bool yflip, int paletteId, bool setTransparency = false, int layer = 0); Q_INVOKABLE void addTileImage(int x, int y, QJSValue tileObj, bool setTransparency = false, int layer = 0); Q_INVOKABLE void addMetatileImage(int x, int y, int metatileId, bool setTransparency = false, int layer = 0); +#endif // QT_QML_LIB protected: virtual void drawForeground(QPainter *painter, const QRectF &rect) override; diff --git a/include/ui/overlay.h b/include/ui/overlay.h index 86fe0963..9be73ec8 100644 --- a/include/ui/overlay.h +++ b/include/ui/overlay.h @@ -8,6 +8,8 @@ #include #include +#ifdef QT_QML_LIB + class OverlayItem { public: OverlayItem() {} @@ -123,4 +125,17 @@ private: QRectF *clippingRect; }; +#else + +class Overlay +{ +public: + Overlay() {} + ~Overlay() {} + + void renderItems(QPainter *) {} +}; + +#endif // QT_QML_LIB + #endif // OVERLAY_H diff --git a/include/ui/updatepromoter.h b/include/ui/updatepromoter.h index de73bcdd..76157c4d 100644 --- a/include/ui/updatepromoter.h +++ b/include/ui/updatepromoter.h @@ -1,6 +1,8 @@ #ifndef UPDATEPROMOTER_H #define UPDATEPROMOTER_H +#ifdef QT_NETWORK_LIB + #include "network.h" #include @@ -47,4 +49,6 @@ signals: void changedPreferences(); }; +#endif // QT_NETWORK_LIB + #endif // UPDATEPROMOTER_H diff --git a/porymap.pro b/porymap.pro index 6b2245c1..50aa83e2 100644 --- a/porymap.pro +++ b/porymap.pro @@ -4,13 +4,23 @@ # #------------------------------------------------- -QT += core gui qml network +QT += core gui qtHaveModule(charts) { QT += charts } else { warning("Qt module 'charts' not found, disabling chart features.") } +qtHaveModule(qml) { + QT += qml +} else { + warning("Qt module 'qml' not found, disabling plug-in features.") +} +qtHaveModule(network) { + QT += network +} else { + warning("Qt module 'network' not found, disabling network features.") +} greaterThan(QT_MAJOR_VERSION, 4): QT += widgets diff --git a/src/core/map.cpp b/src/core/map.cpp index f7b75838..1f3b5916 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -4,6 +4,7 @@ #include "scripting.h" #include "utility.h" #include "editcommands.h" +#include "project.h" #include #include diff --git a/src/core/maplayout.cpp b/src/core/maplayout.cpp index b80bad0f..44616ab6 100644 --- a/src/core/maplayout.cpp +++ b/src/core/maplayout.cpp @@ -5,6 +5,8 @@ #include "scripting.h" #include "imageproviders.h" #include "utility.h" +#include "project.h" +#include "layoutpixmapitem.h" QList Layout::s_globalMetatileLayerOrder; QList Layout::s_globalMetatileLayerOpacity; diff --git a/src/core/network.cpp b/src/core/network.cpp index 4f2a1c19..ce0d5124 100644 --- a/src/core/network.cpp +++ b/src/core/network.cpp @@ -1,3 +1,4 @@ +#ifdef QT_NETWORK_LIB #include "network.h" #include "config.h" @@ -148,3 +149,5 @@ void NetworkAccessManager::processReply(QNetworkReply * reply, NetworkReplyData cacheEntry->data = data->m_body = reply->readAll(); } + +#endif // QT_NETWORK_LIB diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d1644528..3519827b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -54,6 +54,9 @@ #if defined(Q_OS_WIN) || defined(Q_OS_MACOS) #define RELEASE_PLATFORM #endif +#if defined(QT_NETWORK_LIB) && defined(RELEASE_PLATFORM) +#define USE_UPDATE_PROMOTER +#endif @@ -72,7 +75,8 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); logInit(); - logInfo(QString("Launching Porymap v%1").arg(QCoreApplication::applicationVersion())); + logInfo(QString("Launching Porymap v%1 (%2)").arg(QCoreApplication::applicationVersion()).arg(QStringLiteral(PORYMAP_LATEST_COMMIT))); + logInfo(QString("Using Qt v%2 (%3)").arg(QStringLiteral(QT_VERSION_STR)).arg(QSysInfo::buildCpuArchitecture())); } void MainWindow::initialize() { @@ -155,14 +159,33 @@ void MainWindow::initWindow() { this->initMapList(); this->initShortcuts(); -#ifndef RELEASE_PLATFORM + QStringList missingModules; + +#ifndef USE_UPDATE_PROMOTER ui->actionCheck_for_Updates->setVisible(false); +#ifdef RELEASE_PLATFORM + // Only report the network module missing if we would + // have otherwise used it (we don't on non-release platforms). + missingModules.append(" 'network'"); +#endif #endif #ifndef QT_CHARTS_LIB ui->pushButton_SummaryChart->setVisible(false); + missingModules.append(" 'charts'"); #endif +#ifndef QT_QML_LIB + ui->actionCustom_Scripts->setVisible(false); + missingModules.append(" 'qml'"); +#endif + + if (!missingModules.isEmpty()) { + logWarn(QString("Qt module%1%2 not found. Some features will be disabled.") + .arg(missingModules.length() > 1 ? "s" : "") + .arg(missingModules.join(","))); + } + setWindowDisabled(true); } @@ -332,7 +355,7 @@ void MainWindow::on_actionCheck_for_Updates_triggered() { checkForUpdates(true); } -#ifdef RELEASE_PLATFORM +#ifdef USE_UPDATE_PROMOTER void MainWindow::checkForUpdates(bool requestedByUser) { if (!this->networkAccessManager) this->networkAccessManager = new NetworkAccessManager(this); @@ -2285,21 +2308,29 @@ void MainWindow::initShortcutsEditor() { void MainWindow::connectSubEditorsToShortcutsEditor() { /* Initialize sub-editors so that their children are added to MainWindow's object tree and will * be returned by shortcutableObjects() to be passed to ShortcutsEditor. */ - if (!tilesetEditor) + if (!this->tilesetEditor) { initTilesetEditor(); - connect(shortcutsEditor, &ShortcutsEditor::shortcutsSaved, - tilesetEditor, &TilesetEditor::applyUserShortcuts); + } + if (this->tilesetEditor) { + connect(this->shortcutsEditor, &ShortcutsEditor::shortcutsSaved, + this->tilesetEditor, &TilesetEditor::applyUserShortcuts); + } - if (!regionMapEditor) + if (!this->regionMapEditor){ initRegionMapEditor(true); - if (regionMapEditor) - connect(shortcutsEditor, &ShortcutsEditor::shortcutsSaved, - regionMapEditor, &RegionMapEditor::applyUserShortcuts); + } + if (this->regionMapEditor) { + connect(this->shortcutsEditor, &ShortcutsEditor::shortcutsSaved, + this->regionMapEditor, &RegionMapEditor::applyUserShortcuts); + } - if (!customScriptsEditor) + if (!this->customScriptsEditor) { initCustomScriptsEditor(); - connect(shortcutsEditor, &ShortcutsEditor::shortcutsSaved, - customScriptsEditor, &CustomScriptsEditor::applyUserShortcuts); + } + if (this->customScriptsEditor) { + connect(this->shortcutsEditor, &ShortcutsEditor::shortcutsSaved, + this->customScriptsEditor, &CustomScriptsEditor::applyUserShortcuts); + } } void MainWindow::resetMapViewScale() { @@ -2948,8 +2979,10 @@ void MainWindow::on_actionPreferences_triggered() { void MainWindow::togglePreferenceSpecificUi() { ui->actionOpen_Project_in_Text_Editor->setEnabled(!porymapConfig.textEditorOpenFolder.isEmpty()); +#ifdef USE_UPDATE_PROMOTER if (this->updatePromoter) this->updatePromoter->updatePreferences(); +#endif } void MainWindow::openProjectSettingsEditor(int tab) { @@ -2994,16 +3027,20 @@ void MainWindow::onWarpBehaviorWarningClicked() { } void MainWindow::on_actionCustom_Scripts_triggered() { - if (!this->customScriptsEditor) + if (!this->customScriptsEditor) { initCustomScriptsEditor(); - - Util::show(this->customScriptsEditor); + } + if (this->customScriptsEditor) { + Util::show(this->customScriptsEditor); + } } void MainWindow::initCustomScriptsEditor() { +#ifdef QT_QML_LIB this->customScriptsEditor = new CustomScriptsEditor(this); connect(this->customScriptsEditor, &CustomScriptsEditor::reloadScriptEngine, this, &MainWindow::reloadScriptEngine); +#endif } void MainWindow::reloadScriptEngine() { diff --git a/src/scriptapi/apimap.cpp b/src/scriptapi/apimap.cpp index e653cafd..dcd4fc33 100644 --- a/src/scriptapi/apimap.cpp +++ b/src/scriptapi/apimap.cpp @@ -1,3 +1,4 @@ +#ifdef QT_QML_LIB #include "mainwindow.h" #include "ui_mainwindow.h" #include "scripting.h" @@ -963,3 +964,5 @@ void MainWindow::setFloorNumber(int floorNumber) { this->editor->map->header()->setFloorNumber(floorNumber); } + +#endif // QT_QML_LIB diff --git a/src/scriptapi/apioverlay.cpp b/src/scriptapi/apioverlay.cpp index ffe7743a..e2ca888f 100644 --- a/src/scriptapi/apioverlay.cpp +++ b/src/scriptapi/apioverlay.cpp @@ -1,6 +1,8 @@ +#ifdef QT_QML_LIB #include "mapview.h" #include "scripting.h" #include "imageproviders.h" +#include "editor.h" void MapView::updateScene() { if (this->scene()) { @@ -300,3 +302,5 @@ void MapView::addMetatileImage(int x, int y, int metatileId, bool setTransparenc if (this->getOverlay(layer)->addImage(x, y, image)) this->updateScene(); } + +#endif // QT_QML_LIB diff --git a/src/scriptapi/apiutility.cpp b/src/scriptapi/apiutility.cpp index 5058e2de..8f205de2 100644 --- a/src/scriptapi/apiutility.cpp +++ b/src/scriptapi/apiutility.cpp @@ -1,12 +1,10 @@ +#ifdef QT_QML_LIB +#include "scriptutility.h" #include "mainwindow.h" #include "ui_mainwindow.h" #include "scripting.h" #include "config.h" -ScriptUtility::ScriptUtility(MainWindow *mainWindow) { - this->window = mainWindow; -} - ScriptUtility::~ScriptUtility() { if (window && window->ui && window->ui->menuTools) { for (auto action : this->registeredActions) { @@ -318,3 +316,5 @@ bool ScriptUtility::isPrimaryTileset(QString tilesetName) { bool ScriptUtility::isSecondaryTileset(QString tilesetName) { return getSecondaryTilesetNames().contains(tilesetName); } + +#endif // QT_QML_LIB diff --git a/src/scriptapi/scripting.cpp b/src/scriptapi/scripting.cpp index be14a933..ff614c1a 100644 --- a/src/scriptapi/scripting.cpp +++ b/src/scriptapi/scripting.cpp @@ -1,8 +1,10 @@ +#if __has_include() #include #include "scripting.h" #include "log.h" #include "config.h" +#include "mainwindow.h" const QMap callbackFunctions = { {OnProjectOpened, "onProjectOpened"}, @@ -422,3 +424,6 @@ const QImage * Scripting::getImage(const QString &inputFilepath, bool useCache) instance->imageCache.insert(inputFilepath, image); return image; } + + +#endif // __has_include() diff --git a/src/ui/overlay.cpp b/src/ui/overlay.cpp index d1ba4ef8..4fccb530 100644 --- a/src/ui/overlay.cpp +++ b/src/ui/overlay.cpp @@ -1,3 +1,4 @@ +#ifdef QT_QML_LIB #include "overlay.h" #include "scripting.h" #include "log.h" @@ -256,3 +257,6 @@ bool Overlay::addImage(int x, int y, QImage image) { this->items.append(new OverlayPixmap(x, y, QPixmap::fromImage(image))); return true; } + + +#endif // QT_QML_LIB diff --git a/src/ui/updatepromoter.cpp b/src/ui/updatepromoter.cpp index 8afc8d9c..4b66fbff 100644 --- a/src/ui/updatepromoter.cpp +++ b/src/ui/updatepromoter.cpp @@ -1,3 +1,4 @@ +#ifdef QT_NETWORK_LIB #include "updatepromoter.h" #include "ui_updatepromoter.h" #include "log.h" @@ -188,3 +189,5 @@ void UpdatePromoter::dialogButtonClicked(QAbstractButton *button) { QDesktopServices::openUrl(this->downloadUrl); } } + +#endif // QT_NETWORK_LIB diff --git a/src/ui/wildmonchart.cpp b/src/ui/wildmonchart.cpp index 30585418..bc45415a 100644 --- a/src/ui/wildmonchart.cpp +++ b/src/ui/wildmonchart.cpp @@ -1,4 +1,4 @@ -#if __has_include() +#ifdef QT_CHARTS_LIB #include "wildmonchart.h" #include "ui_wildmonchart.h" #include "config.h" @@ -466,4 +466,4 @@ void WildMonChart::closeEvent(QCloseEvent *event) { QWidget::closeEvent(event); } -#endif // __has_include() +#endif // QT_CHARTS_LIB