diff options
| author | Chris Bessent <lost.dragonist@gmail.com> | 2021-04-25 04:10:08 -0700 |
|---|---|---|
| committer | Chris Bessent <lost.dragonist@gmail.com> | 2021-04-25 04:13:12 -0700 |
| commit | e475893ff45c187d89ffa6ad8f43eaee1cd61c1f (patch) | |
| tree | ff2694c6630cf73bb4cd0378acaa55d22a8972c2 /src | |
| parent | 40a4bf1e3a25d98da481c6807e327f036a9a33e6 (diff) | |
Change the "Visit Nexus" button to support alternate sources
If a game plugin supports more than one Nexus site for downloads,
the "Visit Nexus" button will be turned into a drop-down that
lets you select each site.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 39 | ||||
| -rw-r--r-- | src/mainwindow.h | 1 |
2 files changed, 37 insertions, 3 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bc9a3ce6..93f1198f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1440,12 +1440,36 @@ void MainWindow::registerModPage(IPluginModPage *modPage) ui->actionModPage->menu()->addAction(action); } +void MainWindow::registerNexusPages(const QStringList& gamePluginNames) +{ + for (QString gameName : gamePluginNames) { + // Get the plugin + IPluginGame* plugin = m_OrganizerCore.getGame(gameName); + if (plugin == nullptr) + continue; + + // Create an action + QAction* action = new QAction( + plugin ? plugin->gameIcon() : QIcon(), + QObject::tr("Visit %1 on Nexus").arg(plugin ? plugin->gameName() : gameName), + this); + + // Bind the action + connect(action, &QAction::triggered, this, [this, gameName]() { + shell::Open(QUrl(NexusInterface::instance().getGameURL(gameName))); + }, Qt::QueuedConnection); + + // Add the action + ui->actionModPage->menu()->addAction(action); + } +} + void MainWindow::updateModPageMenu() { // Clear the menu: ui->actionModPage->menu()->clear(); - ui->actionModPage->menu()->addAction(ui->actionNexus); + // Determine the loaded mod page plugins std::vector<IPluginModPage*> modPagePlugins = m_PluginContainer.plugins<IPluginModPage>(); // Sort the plugins by display name @@ -1466,14 +1490,23 @@ void MainWindow::updateModPageMenu() registerModPage(modPagePlugin); } + // Determine the applicable game plugins + QStringList gamePluginNames; + gamePluginNames.append(m_OrganizerCore.managedGame()->gameShortName()); + gamePluginNames.append(m_OrganizerCore.managedGame()->validShortNames()); + + // Register Nexus pages + registerNexusPages(gamePluginNames); + // No mod page plugin and the menu was visible: - if (modPagePlugins.empty()) { + bool keepOriginalAction = modPagePlugins.size() == 0 && gamePluginNames.count() <= 1; + if (keepOriginalAction) { ui->toolBar->insertAction(ui->actionAdd_Profile, ui->actionNexus); } else { ui->toolBar->removeAction(ui->actionNexus); } - ui->actionModPage->setVisible(!modPagePlugins.empty()); + ui->actionModPage->setVisible(!keepOriginalAction); } void MainWindow::startExeAction() diff --git a/src/mainwindow.h b/src/mainwindow.h index 7afd954a..ee2446af 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -187,6 +187,7 @@ private: void setToolbarButtonStyle(Qt::ToolButtonStyle s); void registerModPage(MOBase::IPluginModPage* modPage); + void registerNexusPages(const QStringList& gamePluginNames); void registerPluginTool(MOBase::IPluginTool* tool, QString name = QString(), QMenu* menu = nullptr); void updateToolbarMenu(); |
