1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-20 19:57:45 +00:00

Add profile switching functionality in settings

This commit is contained in:
redstrate 2021-11-09 12:06:30 -05:00
parent 26326d08a7
commit 0961679427
4 changed files with 41 additions and 8 deletions

View file

@ -9,7 +9,6 @@
#include <QGroupBox> #include <QGroupBox>
#include <QMessageBox> #include <QMessageBox>
#include <QProcess> #include <QProcess>
#include <QComboBox>
#include <QGridLayout> #include <QGridLayout>
#include <QLineEdit> #include <QLineEdit>
@ -23,6 +22,13 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
setLayout(mainLayout); setLayout(mainLayout);
profileWidget = new QListWidget(); profileWidget = new QListWidget();
profileWidget->addItem("INVALID *DEBUG*");
profileWidget->setCurrentRow(0);
connect(profileWidget, &QListWidget::currentRowChanged, [=]() {
reloadControls();
});
mainLayout->addWidget(profileWidget, 0, 0); mainLayout->addWidget(profileWidget, 0, 0);
auto addProfileButton = new QPushButton("Add Profile"); auto addProfileButton = new QPushButton("Add Profile");
@ -37,15 +43,13 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
mainLayout->addWidget(gameBox, 0, 1); mainLayout->addWidget(gameBox, 0, 1);
auto directXCombo = new QComboBox(); directXCombo = new QComboBox();
directXCombo->setCurrentIndex(window.settings.value("directx", 0).toInt());
directXCombo->addItem("DirectX 11"); directXCombo->addItem("DirectX 11");
directXCombo->addItem("DirectX 9"); directXCombo->addItem("DirectX 9");
gameBoxLayout->addRow("DirectX Version", directXCombo); gameBoxLayout->addRow("DirectX Version", directXCombo);
connect(directXCombo, &QComboBox::currentIndexChanged, [=](int index) { connect(directXCombo, &QComboBox::currentIndexChanged, [=](int index) {
this->window.settings.setValue("directx", directXCombo->currentIndex()); this->window.getProfile(profileWidget->currentRow()).useDX9 = directXCombo->currentIndex() == 1;
this->window.currentProfile().useDX9 = directXCombo->currentIndex() == 1;
}); });
auto currentGameDirectory = new QLabel(window.currentProfile().gamePath); auto currentGameDirectory = new QLabel(window.currentProfile().gamePath);
@ -216,11 +220,24 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
} }
void SettingsWindow::reloadControls() { void SettingsWindow::reloadControls() {
if(currentlyReloadingControls)
return;
currentlyReloadingControls = true;
auto oldRow = profileWidget->currentRow();
profileWidget->clear(); profileWidget->clear();
for(auto profile : window.profileList()) { for(auto profile : window.profileList()) {
profileWidget->addItem(profile); profileWidget->addItem(profile);
} }
profileWidget->setCurrentRow(oldRow);
ProfileSettings& profile = window.getProfile(profileWidget->currentRow());
directXCombo->setCurrentIndex(profile.useDX9 ? 1 : 0);
currentlyReloadingControls = false;
} }
void SettingsWindow::openPath(const QString path) { void SettingsWindow::openPath(const QString path) {

View file

@ -2,6 +2,7 @@
#include <QWidget> #include <QWidget>
#include <QListWidget> #include <QListWidget>
#include <QComboBox>
class LauncherWindow; class LauncherWindow;
@ -15,7 +16,10 @@ public slots:
private: private:
void openPath(const QString path); void openPath(const QString path);
QListWidget* profileWidget; QListWidget* profileWidget = nullptr;
QComboBox* directXCombo = nullptr;
bool currentlyReloadingControls = false;
LauncherWindow& window; LauncherWindow& window;
}; };

View file

@ -344,11 +344,19 @@ LauncherWindow::LauncherWindow(QWidget* parent) :
LauncherWindow::~LauncherWindow() = default; LauncherWindow::~LauncherWindow() = default;
ProfileSettings LauncherWindow::currentProfile() const { ProfileSettings LauncherWindow::currentProfile() const {
return profileSettings[currentProfileIndex]; return getProfile(currentProfileIndex);
} }
ProfileSettings& LauncherWindow::currentProfile() { ProfileSettings& LauncherWindow::currentProfile() {
return profileSettings[currentProfileIndex]; return getProfile(currentProfileIndex);
}
ProfileSettings LauncherWindow::getProfile(int index) const {
return profileSettings[index];
}
ProfileSettings& LauncherWindow::getProfile(int index) {
return profileSettings[index];
} }
void LauncherWindow::setProfile(QString name) { void LauncherWindow::setProfile(QString name) {

View file

@ -48,6 +48,10 @@ public:
ProfileSettings currentProfile() const; ProfileSettings currentProfile() const;
ProfileSettings& currentProfile(); ProfileSettings& currentProfile();
ProfileSettings getProfile(int index) const;
ProfileSettings& getProfile(int index);
void setProfile(QString name); void setProfile(QString name);
void setProfile(int index); void setProfile(int index);
int getProfileIndex(QString name); int getProfileIndex(QString name);