Add main tab to API
This commit is contained in:
parent
8f62268d00
commit
fee9ffcd44
5 changed files with 37 additions and 1 deletions
|
@ -167,6 +167,8 @@ public:
|
|||
Q_INVOKABLE int getNumMetatileLayers();
|
||||
Q_INVOKABLE int getBaseGameVersion();
|
||||
Q_INVOKABLE QList<QString> getCustomScripts();
|
||||
Q_INVOKABLE int getCurrentTab();
|
||||
Q_INVOKABLE void setCurrentTab(int index);
|
||||
|
||||
|
||||
private slots:
|
||||
|
@ -389,6 +391,7 @@ private:
|
|||
QString getEventGroupFromTabWidget(QWidget *tab);
|
||||
void closeSupplementaryWindows();
|
||||
void setWindowDisabled(bool);
|
||||
void setMainTab(int);
|
||||
|
||||
void initTilesetEditor();
|
||||
bool initRegionMapEditor();
|
||||
|
|
|
@ -15,6 +15,7 @@ enum CallbackType {
|
|||
OnMapOpened,
|
||||
OnMapResized,
|
||||
OnTilesetUpdated,
|
||||
OnTabChanged,
|
||||
};
|
||||
|
||||
class Scripting
|
||||
|
@ -38,6 +39,7 @@ public:
|
|||
static void cb_MapOpened(QString mapName);
|
||||
static void cb_MapResized(int oldWidth, int oldHeight, int newWidth, int newHeight);
|
||||
static void cb_TilesetUpdated(QString tilesetName);
|
||||
static void cb_TabChanged(int oldTab, int newTab);
|
||||
static bool tryErrorJS(QJSValue js);
|
||||
|
||||
private:
|
||||
|
|
|
@ -676,7 +676,7 @@ void MainWindow::redrawMapScene()
|
|||
|
||||
void MainWindow::refreshMapScene()
|
||||
{
|
||||
on_mainTabBar_tabBarClicked(ui->mainTabBar->currentIndex());
|
||||
setMainTab(ui->mainTabBar->currentIndex());
|
||||
|
||||
ui->graphicsView_Map->setScene(editor->scene);
|
||||
ui->graphicsView_Map->setSceneRect(editor->scene->sceneRect());
|
||||
|
@ -1678,6 +1678,14 @@ void MainWindow::on_action_Exit_triggered()
|
|||
}
|
||||
|
||||
void MainWindow::on_mainTabBar_tabBarClicked(int index)
|
||||
{
|
||||
int oldIndex = ui->mainTabBar->currentIndex();
|
||||
if (index != oldIndex)
|
||||
Scripting::cb_TabChanged(oldIndex, index);
|
||||
setMainTab(index);
|
||||
}
|
||||
|
||||
void MainWindow::setMainTab(int index)
|
||||
{
|
||||
ui->mainTabBar->setCurrentIndex(index);
|
||||
|
||||
|
|
|
@ -989,3 +989,15 @@ int MainWindow::getBaseGameVersion() {
|
|||
QList<QString> MainWindow::getCustomScripts() {
|
||||
return projectConfig.getCustomScripts();
|
||||
}
|
||||
|
||||
int MainWindow::getCurrentTab() {
|
||||
if (!this->ui || !this->ui->mainTabBar)
|
||||
return -1;
|
||||
return this->ui->mainTabBar->currentIndex();
|
||||
}
|
||||
|
||||
void MainWindow::setCurrentTab(int index) {
|
||||
if (!this->ui || !this->ui->mainTabBar || index < 0 || index >= this->ui->mainTabBar->count())
|
||||
return
|
||||
this->setMainTab(index);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ QMap<CallbackType, QString> callbackFunctions = {
|
|||
{OnMapOpened, "onMapOpened"},
|
||||
{OnMapResized, "onMapResized"},
|
||||
{OnTilesetUpdated, "onTilesetUpdated"},
|
||||
{OnTabChanged, "onTabChanged"},
|
||||
};
|
||||
|
||||
Scripting *instance = nullptr;
|
||||
|
@ -163,6 +164,16 @@ void Scripting::cb_TilesetUpdated(QString tilesetName) {
|
|||
instance->invokeCallback(OnTilesetUpdated, args);
|
||||
}
|
||||
|
||||
void Scripting::cb_TabChanged(int oldTab, int newTab) {
|
||||
if (!instance) return;
|
||||
|
||||
QJSValueList args {
|
||||
oldTab,
|
||||
newTab,
|
||||
};
|
||||
instance->invokeCallback(OnTabChanged, args);
|
||||
}
|
||||
|
||||
QJSValue Scripting::fromBlock(Block block) {
|
||||
QJSValue obj = instance->engine->newObject();
|
||||
obj.setProperty("metatileId", block.metatileId);
|
||||
|
|
Loading…
Reference in a new issue