1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-24 05:17:46 +00:00

Add button to create a new profile

This commit is contained in:
redstrate 2021-11-09 11:44:27 -05:00
parent 6737a363fe
commit 26326d08a7
4 changed files with 46 additions and 3 deletions

View file

@ -11,7 +11,6 @@
#include <QProcess> #include <QProcess>
#include <QComboBox> #include <QComboBox>
#include <QGridLayout> #include <QGridLayout>
#include <QListWidget>
#include <QLineEdit> #include <QLineEdit>
#include "xivlauncher.h" #include "xivlauncher.h"
@ -23,10 +22,15 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
auto mainLayout = new QGridLayout(this); auto mainLayout = new QGridLayout(this);
setLayout(mainLayout); setLayout(mainLayout);
auto profileWidget = new QListWidget(); profileWidget = new QListWidget();
profileWidget->addItem("Default");
mainLayout->addWidget(profileWidget, 0, 0); mainLayout->addWidget(profileWidget, 0, 0);
auto addProfileButton = new QPushButton("Add Profile");
connect(addProfileButton, &QPushButton::pressed, [=] {
profileWidget->setCurrentRow(this->window.addProfile());
});
mainLayout->addWidget(addProfileButton, 1, 0);
auto gameBox = new QGroupBox("Game Options"); auto gameBox = new QGroupBox("Game Options");
auto gameBoxLayout = new QFormLayout(); auto gameBoxLayout = new QFormLayout();
gameBox->setLayout(gameBoxLayout); gameBox->setLayout(gameBoxLayout);
@ -207,6 +211,16 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
this->window.settings.setValue("useGamemode", static_cast<bool>(state)); this->window.settings.setValue("useGamemode", static_cast<bool>(state));
}); });
#endif #endif
reloadControls();
}
void SettingsWindow::reloadControls() {
profileWidget->clear();
for(auto profile : window.profileList()) {
profileWidget->addItem(profile);
}
} }
void SettingsWindow::openPath(const QString path) { void SettingsWindow::openPath(const QString path) {

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include <QListWidget>
class LauncherWindow; class LauncherWindow;
@ -8,8 +9,13 @@ class SettingsWindow : public QWidget {
public: public:
SettingsWindow(LauncherWindow& window, QWidget* parent = nullptr); SettingsWindow(LauncherWindow& window, QWidget* parent = nullptr);
public slots:
void reloadControls();
private: private:
void openPath(const QString path); void openPath(const QString path);
QListWidget* profileWidget;
LauncherWindow& window; LauncherWindow& window;
}; };

View file

@ -214,6 +214,7 @@ LauncherWindow::LauncherWindow(QWidget* parent) :
QAction* settingsAction = fileMenu->addAction("Settings..."); QAction* settingsAction = fileMenu->addAction("Settings...");
connect(settingsAction, &QAction::triggered, [=] { connect(settingsAction, &QAction::triggered, [=] {
auto window = new SettingsWindow(*this); auto window = new SettingsWindow(*this);
connect(this, &LauncherWindow::settingsChanged, window, &SettingsWindow::reloadControls);
window->show(); window->show();
}); });
@ -352,6 +353,12 @@ ProfileSettings& LauncherWindow::currentProfile() {
void LauncherWindow::setProfile(QString name) { void LauncherWindow::setProfile(QString name) {
currentProfileIndex = getProfileIndex(name); currentProfileIndex = getProfileIndex(name);
settingsChanged();
}
void LauncherWindow::setProfile(int index) {
currentProfileIndex = index;
settingsChanged();
} }
int LauncherWindow::getProfileIndex(QString name) { int LauncherWindow::getProfileIndex(QString name) {
@ -371,3 +378,14 @@ QList<QString> LauncherWindow::profileList() const {
return list; return list;
} }
int LauncherWindow::addProfile() {
ProfileSettings newProfile;
newProfile.name = "New Profile";
profileSettings.append(newProfile);
settingsChanged();
return profileSettings.size() - 1;
}

View file

@ -49,8 +49,10 @@ public:
ProfileSettings currentProfile() const; ProfileSettings currentProfile() const;
ProfileSettings& currentProfile(); ProfileSettings& currentProfile();
void setProfile(QString name); void setProfile(QString name);
void setProfile(int index);
int getProfileIndex(QString name); int getProfileIndex(QString name);
QList<QString> profileList() const; QList<QString> profileList() const;
int addProfile();
void launchGame(const LoginAuth auth); void launchGame(const LoginAuth auth);
void launchExecutable(const QStringList args); void launchExecutable(const QStringList args);
@ -61,6 +63,9 @@ public:
QSettings settings; QSettings settings;
signals:
void settingsChanged();
private: private:
SapphireLauncher* sapphireLauncher; SapphireLauncher* sapphireLauncher;
SquareBoot* squareBoot; SquareBoot* squareBoot;