mirror of
https://github.com/huderlem/porymap.git
synced 2026-10-01 04:16:37 -05:00
Allow compiling without the qml module
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QCloseEvent>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QJSValue>
|
||||
#include "project.h"
|
||||
#include "orderedjson.h"
|
||||
#include "config.h"
|
||||
@@ -36,6 +35,10 @@
|
||||
#include "message.h"
|
||||
#include "resizelayoutpopup.h"
|
||||
|
||||
#if __has_include(<QJSValue>)
|
||||
#include <QJSValue>
|
||||
#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);
|
||||
|
||||
@@ -2,12 +2,19 @@
|
||||
#ifndef SCRIPTING_H
|
||||
#define SCRIPTING_H
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "block.h"
|
||||
#include <QStringList>
|
||||
#include "scriptutility.h"
|
||||
|
||||
#include <QStringList>
|
||||
class Block;
|
||||
class Tile;
|
||||
class MainWindow;
|
||||
|
||||
#if __has_include(<QJSEngine>)
|
||||
#include <QJSEngine>
|
||||
#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
|
||||
|
||||
@@ -2,14 +2,24 @@
|
||||
#ifndef SCRIPTUTILITY_H
|
||||
#define SCRIPTUTILITY_H
|
||||
|
||||
#include "mainwindow.h"
|
||||
#if __has_include(<QJSValue>)
|
||||
#include <QJSValue>
|
||||
#endif
|
||||
|
||||
#ifdef QT_QML_LIB
|
||||
|
||||
#include <QAction>
|
||||
#include <QMessageBox>
|
||||
#include <QSet>
|
||||
#include <QTimer>
|
||||
|
||||
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<int, QString> actionMap;
|
||||
};
|
||||
|
||||
#endif // QT_QML_LIB
|
||||
|
||||
#endif // SCRIPTUTILITY_H
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#ifndef MAPVIEW_H
|
||||
#define MAPVIEW_H
|
||||
|
||||
#if __has_include(<QJSValue>)
|
||||
#include <QJSValue>
|
||||
#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;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <QStaticText>
|
||||
#include <QPainterPath>
|
||||
|
||||
#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
|
||||
|
||||
@@ -4,13 +4,18 @@
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui qml network
|
||||
QT += core gui network
|
||||
|
||||
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.")
|
||||
}
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "scripting.h"
|
||||
#include "utility.h"
|
||||
#include "editcommands.h"
|
||||
#include "project.h"
|
||||
|
||||
#include <QTime>
|
||||
#include <QPainter>
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "scripting.h"
|
||||
#include "imageproviders.h"
|
||||
#include "utility.h"
|
||||
#include "project.h"
|
||||
#include "layoutpixmapitem.h"
|
||||
|
||||
QList<int> Layout::s_globalMetatileLayerOrder;
|
||||
QList<float> Layout::s_globalMetatileLayerOpacity;
|
||||
|
||||
@@ -159,10 +159,24 @@ void MainWindow::initWindow() {
|
||||
ui->actionCheck_for_Updates->setVisible(false);
|
||||
#endif
|
||||
|
||||
QStringList missingModules;
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -2285,21 +2299,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() {
|
||||
@@ -2994,16 +3016,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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#if __has_include(<QQmlEngine>)
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "scripting.h"
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
const QMap<CallbackType, QString> 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(<QQmlEngine>)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if __has_include(<QtCharts>)
|
||||
#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(<QtCharts>)
|
||||
#endif // QT_CHARTS_LIB
|
||||
|
||||
Reference in New Issue
Block a user