mirror of
https://github.com/huderlem/porymap.git
synced 2026-11-18 17:17:19 -06:00
Merge branch 'master' of https://github.com/huderlem/porymap into slam
This commit is contained in:
@@ -295,7 +295,7 @@ int MainWindow::getBorderHeight() {
|
||||
}
|
||||
|
||||
void MainWindow::setBorderDimensions(int width, int height) {
|
||||
if (!this->editor || !this->editor->layout || !projectConfig.getUseCustomBorderSize())
|
||||
if (!this->editor || !this->editor->layout || !projectConfig.useCustomBorderSize)
|
||||
return;
|
||||
if (width < 1 || height < 1 || width > MAX_BORDER_WIDTH || height > MAX_BORDER_HEIGHT)
|
||||
return;
|
||||
@@ -305,7 +305,7 @@ void MainWindow::setBorderDimensions(int width, int height) {
|
||||
}
|
||||
|
||||
void MainWindow::setBorderWidth(int width) {
|
||||
if (!this->editor || !this->editor->layout || !projectConfig.getUseCustomBorderSize())
|
||||
if (!this->editor || !this->editor->layout || !projectConfig.useCustomBorderSize)
|
||||
return;
|
||||
if (width < 1 || width > MAX_BORDER_WIDTH)
|
||||
return;
|
||||
@@ -315,7 +315,7 @@ void MainWindow::setBorderWidth(int width) {
|
||||
}
|
||||
|
||||
void MainWindow::setBorderHeight(int height) {
|
||||
if (!this->editor || !this->editor->layout || !projectConfig.getUseCustomBorderSize())
|
||||
if (!this->editor || !this->editor->layout || !projectConfig.useCustomBorderSize)
|
||||
return;
|
||||
if (height < 1 || height > MAX_BORDER_HEIGHT)
|
||||
return;
|
||||
|
||||
@@ -7,6 +7,18 @@ ScriptUtility::ScriptUtility(MainWindow *mainWindow) {
|
||||
this->window = mainWindow;
|
||||
}
|
||||
|
||||
ScriptUtility::~ScriptUtility() {
|
||||
if (window && window->ui && window->ui->menuTools) {
|
||||
for (auto action : this->registeredActions) {
|
||||
window->ui->menuTools->removeAction(action);
|
||||
}
|
||||
}
|
||||
for (auto timer : this->activeTimers) {
|
||||
timer->stop();
|
||||
delete timer;
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptUtility::registerAction(QString functionName, QString actionName, QString shortcut) {
|
||||
if (!window || !window->ui || !window->ui->menuTools)
|
||||
return false;
|
||||
@@ -44,12 +56,6 @@ bool ScriptUtility::registerToggleAction(QString functionName, QString actionNam
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScriptUtility::clearActions() {
|
||||
for (auto action : this->registeredActions) {
|
||||
window->ui->menuTools->removeAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
QString ScriptUtility::getActionFunctionName(int actionIndex) {
|
||||
return this->actionMap.value(actionIndex);
|
||||
}
|
||||
@@ -58,11 +64,15 @@ void ScriptUtility::setTimeout(QJSValue callback, int milliseconds) {
|
||||
if (!callback.isCallable() || milliseconds < 0)
|
||||
return;
|
||||
|
||||
QTimer *timer = new QTimer(0);
|
||||
QTimer *timer = new QTimer();
|
||||
connect(timer, &QTimer::timeout, [=](){
|
||||
this->callTimeoutFunction(callback);
|
||||
if (this->activeTimers.remove(timer)) {
|
||||
this->callTimeoutFunction(callback);
|
||||
timer->deleteLater();
|
||||
}
|
||||
});
|
||||
connect(timer, &QTimer::timeout, timer, &QTimer::deleteLater);
|
||||
|
||||
this->activeTimers.insert(timer);
|
||||
timer->setSingleShot(true);
|
||||
timer->start(milliseconds);
|
||||
}
|
||||
@@ -157,7 +167,10 @@ int ScriptUtility::getMapViewTab() {
|
||||
}
|
||||
|
||||
void ScriptUtility::setMapViewTab(int index) {
|
||||
if (this->getMainTab() != 0 || !window->ui->mapViewTab || index < 0 || index >= window->ui->mapViewTab->count())
|
||||
if (this->getMainTab() != MainTab::Map || !window->ui->mapViewTab || index < 0 || index >= window->ui->mapViewTab->count())
|
||||
return;
|
||||
// Can't select tab if it's disabled
|
||||
if (!window->ui->mapViewTab->isTabEnabled(index))
|
||||
return;
|
||||
window->on_mapViewTab_tabBarClicked(index);
|
||||
}
|
||||
@@ -171,7 +184,7 @@ bool ScriptUtility::getGridVisibility() {
|
||||
}
|
||||
|
||||
void ScriptUtility::setBorderVisibility(bool visible) {
|
||||
window->editor->toggleBorderVisibility(visible, false);
|
||||
window->ui->checkBox_ToggleBorder->setChecked(visible);
|
||||
}
|
||||
|
||||
bool ScriptUtility::getBorderVisibility() {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "scripting.h"
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
|
||||
QMap<CallbackType, QString> callbackFunctions = {
|
||||
const QMap<CallbackType, QString> callbackFunctions = {
|
||||
{OnProjectOpened, "onProjectOpened"},
|
||||
{OnProjectClosed, "onProjectClosed"},
|
||||
{OnBlockChanged, "onBlockChanged"},
|
||||
@@ -21,20 +23,21 @@ QMap<CallbackType, QString> callbackFunctions = {
|
||||
|
||||
Scripting *instance = nullptr;
|
||||
|
||||
void Scripting::stop() {
|
||||
delete instance;
|
||||
instance = nullptr;
|
||||
}
|
||||
|
||||
void Scripting::init(MainWindow *mainWindow) {
|
||||
mainWindow->ui->graphicsView_Map->clearOverlayMap();
|
||||
if (instance) {
|
||||
instance->engine->setInterrupted(true);
|
||||
instance->scriptUtility->clearActions();
|
||||
qDeleteAll(instance->imageCache);
|
||||
delete instance;
|
||||
}
|
||||
if (mainWindow->ui->graphicsView_Map)
|
||||
mainWindow->ui->graphicsView_Map->clearOverlayMap();
|
||||
Scripting::stop();
|
||||
instance = new Scripting(mainWindow);
|
||||
}
|
||||
|
||||
Scripting::Scripting(MainWindow *mainWindow) {
|
||||
this->mainWindow = mainWindow;
|
||||
this->engine = new QJSEngine(mainWindow);
|
||||
this->engine = new QJSEngine();
|
||||
this->engine->installExtensions(QJSEngine::ConsoleExtension);
|
||||
const QStringList paths = userConfig.getCustomScriptPaths();
|
||||
const QList<bool> enabled = userConfig.getCustomScriptsEnabled();
|
||||
@@ -46,6 +49,13 @@ Scripting::Scripting(MainWindow *mainWindow) {
|
||||
this->scriptUtility = new ScriptUtility(mainWindow);
|
||||
}
|
||||
|
||||
Scripting::~Scripting() {
|
||||
this->engine->setInterrupted(true);
|
||||
qDeleteAll(this->imageCache);
|
||||
delete this->engine;
|
||||
delete this->scriptUtility;
|
||||
}
|
||||
|
||||
void Scripting::loadModules(QStringList moduleFiles) {
|
||||
for (QString filepath : moduleFiles) {
|
||||
QString validPath = Project::getExistingFilepath(filepath);
|
||||
@@ -74,6 +84,11 @@ void Scripting::populateGlobalObject(MainWindow *mainWindow) {
|
||||
instance->engine->globalObject().setProperty("overlay", instance->engine->newQObject(mainWindow->ui->graphicsView_Map));
|
||||
instance->engine->globalObject().setProperty("utility", instance->engine->newQObject(instance->scriptUtility));
|
||||
|
||||
// Note: QJSEngine also has these functions, but not in Qt 5.15.
|
||||
QQmlEngine::setObjectOwnership(mainWindow, QQmlEngine::CppOwnership);
|
||||
QQmlEngine::setObjectOwnership(mainWindow->ui->graphicsView_Map, QQmlEngine::CppOwnership);
|
||||
QQmlEngine::setObjectOwnership(instance->scriptUtility, QQmlEngine::CppOwnership);
|
||||
|
||||
QJSValue constants = instance->engine->newObject();
|
||||
|
||||
// Get version numbers
|
||||
|
||||
Reference in New Issue
Block a user