1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-21 04:07:46 +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 <QMessageBox>
#include <QProcess>
#include <QComboBox>
#include <QGridLayout>
#include <QLineEdit>
@ -23,6 +22,13 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
setLayout(mainLayout);
profileWidget = new QListWidget();
profileWidget->addItem("INVALID *DEBUG*");
profileWidget->setCurrentRow(0);
connect(profileWidget, &QListWidget::currentRowChanged, [=]() {
reloadControls();
});
mainLayout->addWidget(profileWidget, 0, 0);
auto addProfileButton = new QPushButton("Add Profile");
@ -37,15 +43,13 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
mainLayout->addWidget(gameBox, 0, 1);
auto directXCombo = new QComboBox();
directXCombo->setCurrentIndex(window.settings.value("directx", 0).toInt());
directXCombo = new QComboBox();
directXCombo->addItem("DirectX 11");
directXCombo->addItem("DirectX 9");
gameBoxLayout->addRow("DirectX Version", directXCombo);
connect(directXCombo, &QComboBox::currentIndexChanged, [=](int index) {
this->window.settings.setValue("directx", directXCombo->currentIndex());
this->window.currentProfile().useDX9 = directXCombo->currentIndex() == 1;
this->window.getProfile(profileWidget->currentRow()).useDX9 = directXCombo->currentIndex() == 1;
});
auto currentGameDirectory = new QLabel(window.currentProfile().gamePath);
@ -216,11 +220,24 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
}
void SettingsWindow::reloadControls() {
if(currentlyReloadingControls)
return;
currentlyReloadingControls = true;
auto oldRow = profileWidget->currentRow();
profileWidget->clear();
for(auto profile : window.profileList()) {
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) {

View file

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

View file

@ -344,11 +344,19 @@ LauncherWindow::LauncherWindow(QWidget* parent) :
LauncherWindow::~LauncherWindow() = default;
ProfileSettings LauncherWindow::currentProfile() const {
return profileSettings[currentProfileIndex];
return getProfile(currentProfileIndex);
}
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) {

View file

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