From 26326d08a7d746359a7038c591158f34d4ad4247 Mon Sep 17 00:00:00 2001 From: redstrate Date: Tue, 9 Nov 2021 11:44:27 -0500 Subject: [PATCH] Add button to create a new profile --- src/settingswindow.cpp | 20 +++++++++++++++++--- src/settingswindow.h | 6 ++++++ src/xivlauncher.cpp | 18 ++++++++++++++++++ src/xivlauncher.h | 5 +++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/settingswindow.cpp b/src/settingswindow.cpp index 4365094..fd11eba 100644 --- a/src/settingswindow.cpp +++ b/src/settingswindow.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #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(state)); }); #endif + + reloadControls(); +} + +void SettingsWindow::reloadControls() { + profileWidget->clear(); + + for(auto profile : window.profileList()) { + profileWidget->addItem(profile); + } } void SettingsWindow::openPath(const QString path) { diff --git a/src/settingswindow.h b/src/settingswindow.h index b60a09b..1a0f3e1 100644 --- a/src/settingswindow.h +++ b/src/settingswindow.h @@ -1,6 +1,7 @@ #pragma once #include +#include 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; }; \ No newline at end of file diff --git a/src/xivlauncher.cpp b/src/xivlauncher.cpp index f01af83..23c6d78 100755 --- a/src/xivlauncher.cpp +++ b/src/xivlauncher.cpp @@ -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 LauncherWindow::profileList() const { } return list; +} + +int LauncherWindow::addProfile() { + ProfileSettings newProfile; + newProfile.name = "New Profile"; + + profileSettings.append(newProfile); + + settingsChanged(); + + return profileSettings.size() - 1; } \ No newline at end of file diff --git a/src/xivlauncher.h b/src/xivlauncher.h index f3265fd..00b2c1c 100755 --- a/src/xivlauncher.h +++ b/src/xivlauncher.h @@ -49,8 +49,10 @@ public: ProfileSettings currentProfile() const; ProfileSettings& currentProfile(); void setProfile(QString name); + void setProfile(int index); int getProfileIndex(QString name); QList 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;