1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-23 21:07:45 +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 <QComboBox>
#include <QGridLayout>
#include <QListWidget>
#include <QLineEdit>
#include "xivlauncher.h"
@ -23,10 +22,15 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
auto mainLayout = new QGridLayout(this);
setLayout(mainLayout);
auto profileWidget = new QListWidget();
profileWidget->addItem("Default");
profileWidget = new QListWidget();
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 gameBoxLayout = new QFormLayout();
gameBox->setLayout(gameBoxLayout);
@ -207,6 +211,16 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, QWidget* parent) : window
this->window.settings.setValue("useGamemode", static_cast<bool>(state));
});
#endif
reloadControls();
}
void SettingsWindow::reloadControls() {
profileWidget->clear();
for(auto profile : window.profileList()) {
profileWidget->addItem(profile);
}
}
void SettingsWindow::openPath(const QString path) {

View file

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

View file

@ -214,6 +214,7 @@ LauncherWindow::LauncherWindow(QWidget* parent) :
QAction* settingsAction = fileMenu->addAction("Settings...");
connect(settingsAction, &QAction::triggered, [=] {
auto window = new SettingsWindow(*this);
connect(this, &LauncherWindow::settingsChanged, window, &SettingsWindow::reloadControls);
window->show();
});
@ -352,6 +353,12 @@ ProfileSettings& LauncherWindow::currentProfile() {
void LauncherWindow::setProfile(QString name) {
currentProfileIndex = getProfileIndex(name);
settingsChanged();
}
void LauncherWindow::setProfile(int index) {
currentProfileIndex = index;
settingsChanged();
}
int LauncherWindow::getProfileIndex(QString name) {
@ -370,4 +377,15 @@ QList<QString> LauncherWindow::profileList() const {
}
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();
void setProfile(QString name);
void setProfile(int index);
int getProfileIndex(QString name);
QList<QString> profileList() const;
int addProfile();
void launchGame(const LoginAuth auth);
void launchExecutable(const QStringList args);
@ -61,6 +63,9 @@ public:
QSettings settings;
signals:
void settingsChanged();
private:
SapphireLauncher* sapphireLauncher;
SquareBoot* squareBoot;