From e475893ff45c187d89ffa6ad8f43eaee1cd61c1f Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sun, 25 Apr 2021 04:10:08 -0700 Subject: 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. --- src/mainwindow.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/mainwindow.cpp') 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 modPagePlugins = m_PluginContainer.plugins(); // 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() -- cgit v1.3.1 From dfbaed0ade533f5e203b16a5126090377cb4657b Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sun, 25 Apr 2021 04:45:35 -0700 Subject: Add a separator after the primary game and sort the secondary games --- src/mainwindow.cpp | 57 ++++++++++++++++++++++++++++++------------------------ src/mainwindow.h | 2 +- 2 files changed, 33 insertions(+), 26 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 93f1198f..1f0788f9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1440,28 +1440,28 @@ void MainWindow::registerModPage(IPluginModPage *modPage) ui->actionModPage->menu()->addAction(action); } -void MainWindow::registerNexusPages(const QStringList& gamePluginNames) +bool MainWindow::registerNexusPage(const QString& gameName) { - for (QString gameName : gamePluginNames) { - // Get the plugin - IPluginGame* plugin = m_OrganizerCore.getGame(gameName); - if (plugin == nullptr) - continue; + // Get the plugin + IPluginGame* plugin = m_OrganizerCore.getGame(gameName); + if (plugin == nullptr) + return false; - // Create an action - QAction* action = new QAction( - plugin ? plugin->gameIcon() : QIcon(), - QObject::tr("Visit %1 on Nexus").arg(plugin ? plugin->gameName() : gameName), - this); + // 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); + // 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); - } + // Add the action + ui->actionModPage->menu()->addAction(action); + + return true; } void MainWindow::updateModPageMenu() @@ -1490,16 +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()); + // Add the primary game (with a separator) + registerNexusPage(m_OrganizerCore.managedGame()->gameShortName()); + ui->actionModPage->menu()->addSeparator(); - // Register Nexus pages - registerNexusPages(gamePluginNames); + // 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: - bool keepOriginalAction = modPagePlugins.size() == 0 && gamePluginNames.count() <= 1; + bool keepOriginalAction = modPagePlugins.size() == 0 && !secondaryGameAdded; if (keepOriginalAction) { ui->toolBar->insertAction(ui->actionAdd_Profile, ui->actionNexus); } diff --git a/src/mainwindow.h b/src/mainwindow.h index ee2446af..6626bf51 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -187,7 +187,7 @@ private: void setToolbarButtonStyle(Qt::ToolButtonStyle s); void registerModPage(MOBase::IPluginModPage* modPage); - void registerNexusPages(const QStringList& gamePluginNames); + bool registerNexusPage(const QString& gameName); void registerPluginTool(MOBase::IPluginTool* tool, QString name = QString(), QMenu* menu = nullptr); void updateToolbarMenu(); -- cgit v1.3.1