Add map view tab to API

This commit is contained in:
GriffinR 2021-12-10 16:52:17 -05:00 committed by huderlem
parent b39906c03f
commit 39cd1d335b
6 changed files with 55 additions and 21 deletions

View file

@ -646,7 +646,7 @@
<number>3</number> <number>3</number>
</property> </property>
<item> <item>
<widget class="QTabWidget" name="tabWidget_2"> <widget class="QTabWidget" name="mapViewTab">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>

View file

@ -170,8 +170,10 @@ public:
Q_INVOKABLE int getNumMetatileLayers(); Q_INVOKABLE int getNumMetatileLayers();
Q_INVOKABLE int getBaseGameVersion(); Q_INVOKABLE int getBaseGameVersion();
Q_INVOKABLE QList<QString> getCustomScripts(); Q_INVOKABLE QList<QString> getCustomScripts();
Q_INVOKABLE int getCurrentTab(); Q_INVOKABLE int getMainTab();
Q_INVOKABLE void setCurrentTab(int index); Q_INVOKABLE void setMainTab(int index);
Q_INVOKABLE int getMapViewTab();
Q_INVOKABLE void setMapViewTab(int index);
private slots: private slots:
@ -203,7 +205,6 @@ private slots:
void on_action_NewMap_triggered(); void on_action_NewMap_triggered();
void on_actionNew_Tileset_triggered(); void on_actionNew_Tileset_triggered();
void on_action_Save_triggered(); void on_action_Save_triggered();
void on_tabWidget_2_currentChanged(int index);
void on_action_Exit_triggered(); void on_action_Exit_triggered();
void on_comboBox_Song_currentTextChanged(const QString &arg1); void on_comboBox_Song_currentTextChanged(const QString &arg1);
void on_comboBox_Location_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_actionEdit_Shortcuts_triggered();
void on_mainTabBar_tabBarClicked(int index); void on_mainTabBar_tabBarClicked(int index);
void on_mapViewTab_tabBarClicked(int index);
void on_actionZoom_In_triggered(); void on_actionZoom_In_triggered();
void on_actionZoom_Out_triggered(); void on_actionZoom_Out_triggered();
@ -394,7 +396,8 @@ private:
QString getEventGroupFromTabWidget(QWidget *tab); QString getEventGroupFromTabWidget(QWidget *tab);
void closeSupplementaryWindows(); void closeSupplementaryWindows();
void setWindowDisabled(bool); void setWindowDisabled(bool);
void setMainTab(int); void setMainTabInternal(int);
void setMapViewTabInternal(int);
void initTilesetEditor(); void initTilesetEditor();
bool initRegionMapEditor(); bool initRegionMapEditor();

View file

@ -16,7 +16,8 @@ enum CallbackType {
OnMapResized, OnMapResized,
OnMapShifted, OnMapShifted,
OnTilesetUpdated, OnTilesetUpdated,
OnTabChanged, OnMainTabChanged,
OnMapViewTabChanged,
}; };
class Scripting class Scripting
@ -41,7 +42,8 @@ public:
static void cb_MapResized(int oldWidth, int oldHeight, int newWidth, int newHeight); static void cb_MapResized(int oldWidth, int oldHeight, int newWidth, int newHeight);
static void cb_MapShifted(int xDelta, int yDelta); static void cb_MapShifted(int xDelta, int yDelta);
static void cb_TilesetUpdated(QString tilesetName); 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); static bool tryErrorJS(QJSValue js);
private: private:

View file

@ -676,7 +676,7 @@ void MainWindow::redrawMapScene()
void MainWindow::refreshMapScene() void MainWindow::refreshMapScene()
{ {
setMainTab(ui->mainTabBar->currentIndex()); setMainTabInternal(ui->mainTabBar->currentIndex());
ui->graphicsView_Map->setScene(editor->scene); ui->graphicsView_Map->setScene(editor->scene);
ui->graphicsView_Map->setSceneRect(editor->scene->sceneRect()); ui->graphicsView_Map->setSceneRect(editor->scene->sceneRect());
@ -1661,7 +1661,13 @@ void MainWindow::on_action_Save_triggered() {
updateMapList(); 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) { if (index == 0) {
editor->setEditingMap(); editor->setEditingMap();
@ -1681,11 +1687,11 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index)
{ {
int oldIndex = ui->mainTabBar->currentIndex(); int oldIndex = ui->mainTabBar->currentIndex();
if (index != oldIndex) if (index != oldIndex)
Scripting::cb_TabChanged(oldIndex, index); Scripting::cb_MainTabChanged(oldIndex, index);
setMainTab(index); setMainTabInternal(index);
} }
void MainWindow::setMainTab(int index) void MainWindow::setMainTabInternal(int index)
{ {
ui->mainTabBar->setCurrentIndex(index); ui->mainTabBar->setCurrentIndex(index);
@ -1694,7 +1700,7 @@ void MainWindow::setMainTab(int index)
if (index == 0) { if (index == 0) {
ui->stackedWidget_MapEvents->setCurrentIndex(0); ui->stackedWidget_MapEvents->setCurrentIndex(0);
on_tabWidget_2_currentChanged(ui->tabWidget_2->currentIndex()); setMapViewTabInternal(ui->mapViewTab->currentIndex());
clickToolButtonFromEditMode(editor->map_edit_mode); clickToolButtonFromEditMode(editor->map_edit_mode);
} else if (index == 1) { } else if (index == 1) {
ui->stackedWidget_MapEvents->setCurrentIndex(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); editor->settings->mapCursor = QCursor(QPixmap(":/icons/pencil_cursor.ico"), 10, 10);
// do not stop single tile mode when editing collision // do not stop single tile mode when editing collision
if (ui->tabWidget_2->currentIndex() == 0) if (ui->mapViewTab->currentIndex() == 0)
editor->cursorMapTileRect->stopSingleTileMode(); editor->cursorMapTileRect->stopSingleTileMode();
ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);

View file

@ -990,14 +990,26 @@ QList<QString> MainWindow::getCustomScripts() {
return projectConfig.getCustomScripts(); return projectConfig.getCustomScripts();
} }
int MainWindow::getCurrentTab() { int MainWindow::getMainTab() {
if (!this->ui || !this->ui->mainTabBar) if (!this->ui || !this->ui->mainTabBar)
return -1; return -1;
return this->ui->mainTabBar->currentIndex(); 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()) if (!this->ui || !this->ui->mainTabBar || index < 0 || index >= this->ui->mainTabBar->count())
return return;
this->setMainTab(index); 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);
} }

View file

@ -9,7 +9,8 @@ QMap<CallbackType, QString> callbackFunctions = {
{OnMapResized, "onMapResized"}, {OnMapResized, "onMapResized"},
{OnMapShifted, "onMapShifted"}, {OnMapShifted, "onMapShifted"},
{OnTilesetUpdated, "onTilesetUpdated"}, {OnTilesetUpdated, "onTilesetUpdated"},
{OnTabChanged, "onTabChanged"}, {OnMainTabChanged, "onMainTabChanged"},
{OnMapViewTabChanged, "onMapViewTabChanged"},
}; };
Scripting *instance = nullptr; Scripting *instance = nullptr;
@ -175,14 +176,24 @@ void Scripting::cb_TilesetUpdated(QString tilesetName) {
instance->invokeCallback(OnTilesetUpdated, args); instance->invokeCallback(OnTilesetUpdated, args);
} }
void Scripting::cb_TabChanged(int oldTab, int newTab) { void Scripting::cb_MainTabChanged(int oldTab, int newTab) {
if (!instance) return; if (!instance) return;
QJSValueList args { QJSValueList args {
oldTab, oldTab,
newTab, 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) { QJSValue Scripting::fromBlock(Block block) {