diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index d63110e7..2bc1f591 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -646,7 +646,7 @@ 3 - + true diff --git a/include/mainwindow.h b/include/mainwindow.h index bc602bd1..2830906e 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -170,8 +170,10 @@ public: Q_INVOKABLE int getNumMetatileLayers(); Q_INVOKABLE int getBaseGameVersion(); Q_INVOKABLE QList getCustomScripts(); - Q_INVOKABLE int getCurrentTab(); - Q_INVOKABLE void setCurrentTab(int index); + Q_INVOKABLE int getMainTab(); + Q_INVOKABLE void setMainTab(int index); + Q_INVOKABLE int getMapViewTab(); + Q_INVOKABLE void setMapViewTab(int index); private slots: @@ -203,7 +205,6 @@ private slots: void on_action_NewMap_triggered(); void on_actionNew_Tileset_triggered(); void on_action_Save_triggered(); - void on_tabWidget_2_currentChanged(int index); void on_action_Exit_triggered(); void on_comboBox_Song_currentTextChanged(const QString &arg1); void on_comboBox_Location_currentTextChanged(const QString &arg1); @@ -221,6 +222,7 @@ private slots: void on_actionEdit_Shortcuts_triggered(); void on_mainTabBar_tabBarClicked(int index); + void on_mapViewTab_tabBarClicked(int index); void on_actionZoom_In_triggered(); void on_actionZoom_Out_triggered(); @@ -394,7 +396,8 @@ private: QString getEventGroupFromTabWidget(QWidget *tab); void closeSupplementaryWindows(); void setWindowDisabled(bool); - void setMainTab(int); + void setMainTabInternal(int); + void setMapViewTabInternal(int); void initTilesetEditor(); bool initRegionMapEditor(); diff --git a/include/scripting.h b/include/scripting.h index 6983b4ee..08a5aa5d 100644 --- a/include/scripting.h +++ b/include/scripting.h @@ -16,7 +16,8 @@ enum CallbackType { OnMapResized, OnMapShifted, OnTilesetUpdated, - OnTabChanged, + OnMainTabChanged, + OnMapViewTabChanged, }; class Scripting @@ -41,7 +42,8 @@ public: static void cb_MapResized(int oldWidth, int oldHeight, int newWidth, int newHeight); static void cb_MapShifted(int xDelta, int yDelta); static void cb_TilesetUpdated(QString tilesetName); - static void cb_TabChanged(int oldTab, int newTab); + static void cb_MainTabChanged(int oldTab, int newTab); + static void cb_MapViewTabChanged(int oldTab, int newTab); static bool tryErrorJS(QJSValue js); private: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index deac0914..760fec54 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -676,7 +676,7 @@ void MainWindow::redrawMapScene() void MainWindow::refreshMapScene() { - setMainTab(ui->mainTabBar->currentIndex()); + setMainTabInternal(ui->mainTabBar->currentIndex()); ui->graphicsView_Map->setScene(editor->scene); ui->graphicsView_Map->setSceneRect(editor->scene->sceneRect()); @@ -1661,7 +1661,13 @@ void MainWindow::on_action_Save_triggered() { updateMapList(); } -void MainWindow::on_tabWidget_2_currentChanged(int index) +void MainWindow::on_mapViewTab_tabBarClicked(int index) +{ + Scripting::cb_MapViewTabChanged(ui->mapViewTab->currentIndex(), index); + setMapViewTabInternal(index); +} + +void MainWindow::setMapViewTabInternal(int index) { if (index == 0) { editor->setEditingMap(); @@ -1681,11 +1687,11 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index) { int oldIndex = ui->mainTabBar->currentIndex(); if (index != oldIndex) - Scripting::cb_TabChanged(oldIndex, index); - setMainTab(index); + Scripting::cb_MainTabChanged(oldIndex, index); + setMainTabInternal(index); } -void MainWindow::setMainTab(int index) +void MainWindow::setMainTabInternal(int index) { ui->mainTabBar->setCurrentIndex(index); @@ -1694,7 +1700,7 @@ void MainWindow::setMainTab(int index) if (index == 0) { ui->stackedWidget_MapEvents->setCurrentIndex(0); - on_tabWidget_2_currentChanged(ui->tabWidget_2->currentIndex()); + setMapViewTabInternal(ui->mapViewTab->currentIndex()); clickToolButtonFromEditMode(editor->map_edit_mode); } else if (index == 1) { ui->stackedWidget_MapEvents->setCurrentIndex(1); @@ -2542,7 +2548,7 @@ void MainWindow::on_toolButton_Paint_clicked() editor->settings->mapCursor = QCursor(QPixmap(":/icons/pencil_cursor.ico"), 10, 10); // do not stop single tile mode when editing collision - if (ui->tabWidget_2->currentIndex() == 0) + if (ui->mapViewTab->currentIndex() == 0) editor->cursorMapTileRect->stopSingleTileMode(); ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index 9d15a02f..0f6bd8a1 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -990,14 +990,26 @@ QList MainWindow::getCustomScripts() { return projectConfig.getCustomScripts(); } -int MainWindow::getCurrentTab() { +int MainWindow::getMainTab() { if (!this->ui || !this->ui->mainTabBar) return -1; return this->ui->mainTabBar->currentIndex(); } -void MainWindow::setCurrentTab(int index) { +void MainWindow::setMainTab(int index) { if (!this->ui || !this->ui->mainTabBar || index < 0 || index >= this->ui->mainTabBar->count()) - return - this->setMainTab(index); + return; + this->setMainTabInternal(index); +} + +int MainWindow::getMapViewTab() { + if (this->getMainTab() != 0 || !this->ui->mapViewTab) + return -1; + return this->ui->mapViewTab->currentIndex(); +} + +void MainWindow::setMapViewTab(int index) { + if (this->getMainTab() != 0 || !this->ui->mapViewTab || index < 0 || index >= this->ui->mapViewTab->count()) + return; + this->setMapViewTabInternal(index); } diff --git a/src/scripting.cpp b/src/scripting.cpp index 3dd6ce51..06f22d8f 100644 --- a/src/scripting.cpp +++ b/src/scripting.cpp @@ -9,7 +9,8 @@ QMap callbackFunctions = { {OnMapResized, "onMapResized"}, {OnMapShifted, "onMapShifted"}, {OnTilesetUpdated, "onTilesetUpdated"}, - {OnTabChanged, "onTabChanged"}, + {OnMainTabChanged, "onMainTabChanged"}, + {OnMapViewTabChanged, "onMapViewTabChanged"}, }; Scripting *instance = nullptr; @@ -175,14 +176,24 @@ void Scripting::cb_TilesetUpdated(QString tilesetName) { instance->invokeCallback(OnTilesetUpdated, args); } -void Scripting::cb_TabChanged(int oldTab, int newTab) { +void Scripting::cb_MainTabChanged(int oldTab, int newTab) { if (!instance) return; QJSValueList args { oldTab, newTab, }; - instance->invokeCallback(OnTabChanged, args); + instance->invokeCallback(OnMainTabChanged, args); +} + +void Scripting::cb_MapViewTabChanged(int oldTab, int newTab) { + if (!instance) return; + + QJSValueList args { + oldTab, + newTab, + }; + instance->invokeCallback(OnMapViewTabChanged, args); } QJSValue Scripting::fromBlock(Block block) {