diff options
| author | Chris Bessent <lost.dragonist@gmail.com> | 2021-04-29 01:57:13 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-29 01:57:13 -0700 |
| commit | 1197b562f6c044ace8c78739780cb5829df50c10 (patch) | |
| tree | 5c60a5bb694804995545f1ddce68f96a7758cc16 /src | |
| parent | 7df5329ea09569ef49cd48678e361c54be993de1 (diff) | |
| parent | dfbaed0ade533f5e203b16a5126090377cb4657b (diff) | |
Merge pull request #1496 from LostDragonist/nexus_links
Change the "Visit Nexus" button to support alternate sources
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 46 | ||||
| -rw-r--r-- | src/mainwindow.h | 1 |
2 files changed, 44 insertions, 3 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e998dd56..78efa182 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1440,12 +1440,36 @@ void MainWindow::registerModPage(IPluginModPage *modPage) ui->actionModPage->menu()->addAction(action); } +bool MainWindow::registerNexusPage(const QString& gameName) +{ + // Get the plugin + IPluginGame* plugin = m_OrganizerCore.getGame(gameName); + if (plugin == nullptr) + return false; + + // Create an action + QAction* action = new QAction( + plugin->gameIcon(), + QObject::tr("Visit %1 on Nexus").arg(plugin->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); + + return true; +} + 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,30 @@ void MainWindow::updateModPageMenu() registerModPage(modPagePlugin); } + // Add the primary game (with a separator) + registerNexusPage(m_OrganizerCore.managedGame()->gameShortName()); + ui->actionModPage->menu()->addSeparator(); + + // Add the secondary games (sorted) + bool secondaryGameAdded = false; + QStringList secondaryGames = m_OrganizerCore.managedGame()->validShortNames(); + secondaryGames.sort(Qt::CaseInsensitive); + for (auto gameName : secondaryGames) + { + if (registerNexusPage(gameName)) { + secondaryGameAdded = true; + } + } + // No mod page plugin and the menu was visible: - if (modPagePlugins.empty()) { + bool keepOriginalAction = modPagePlugins.size() == 0 && !secondaryGameAdded; + 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..6626bf51 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -187,6 +187,7 @@ private: void setToolbarButtonStyle(Qt::ToolButtonStyle s); void registerModPage(MOBase::IPluginModPage* modPage); + bool registerNexusPage(const QString& gameName); void registerPluginTool(MOBase::IPluginTool* tool, QString name = QString(), QMenu* menu = nullptr); void updateToolbarMenu(); |
