mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-12-13 20:22:13 +00:00
Compare commits
1 Commits
feature/of
...
feature/op
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b0a812db7 |
@@ -4,7 +4,7 @@
|
||||
#include <QSaveFile>
|
||||
|
||||
namespace {
|
||||
bool load(const QString& path, std::vector<GameOptionItem> &contents, int & version)
|
||||
bool load(const QString& path, RawGameOptions & contents)
|
||||
{
|
||||
contents.clear();
|
||||
QFile file(path);
|
||||
@@ -13,7 +13,6 @@ bool load(const QString& path, std::vector<GameOptionItem> &contents, int & vers
|
||||
qWarning() << "Failed to read options file.";
|
||||
return false;
|
||||
}
|
||||
version = 0;
|
||||
while(!file.atEnd())
|
||||
{
|
||||
auto line = file.readLine();
|
||||
@@ -31,32 +30,32 @@ bool load(const QString& path, std::vector<GameOptionItem> &contents, int & vers
|
||||
qDebug() << "!!" << key << "!!";
|
||||
if(key == "version")
|
||||
{
|
||||
version = value.toInt();
|
||||
contents.version = value.toInt();
|
||||
continue;
|
||||
}
|
||||
contents.emplace_back(GameOptionItem{key, value});
|
||||
contents.mapping[key] = value;
|
||||
}
|
||||
qDebug() << "Loaded" << path << "with version:" << version;
|
||||
qDebug() << "Loaded" << path << "with version:" << contents.version;
|
||||
return true;
|
||||
}
|
||||
bool save(const QString& path, std::vector<GameOptionItem> &mapping, int version)
|
||||
bool save(const QString& path, RawGameOptions& contents)
|
||||
{
|
||||
QSaveFile out(path);
|
||||
if(!out.open(QIODevice::WriteOnly))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(version != 0)
|
||||
if(contents.version != 0)
|
||||
{
|
||||
QString versionLine = QString("version:%1\n").arg(version);
|
||||
QString versionLine = QString("version:%1\n").arg(contents.version);
|
||||
out.write(versionLine.toUtf8());
|
||||
}
|
||||
auto iter = mapping.begin();
|
||||
while (iter != mapping.end())
|
||||
auto iter = contents.mapping.begin();
|
||||
while (iter != contents.mapping.end())
|
||||
{
|
||||
out.write(iter->key.toUtf8());
|
||||
out.write(iter->first.toUtf8());
|
||||
out.write(":");
|
||||
out.write(iter->value.toUtf8());
|
||||
out.write(iter->second.toUtf8());
|
||||
out.write("\n");
|
||||
iter++;
|
||||
}
|
||||
@@ -95,7 +94,7 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
|
||||
int row = index.row();
|
||||
int column = index.column();
|
||||
|
||||
if (row < 0 || row >= int(contents.size()))
|
||||
if (row < 0 || row >= rowCount())
|
||||
return QVariant();
|
||||
|
||||
switch (role)
|
||||
@@ -103,11 +102,11 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
|
||||
case Qt::DisplayRole:
|
||||
if(column == 0)
|
||||
{
|
||||
return contents[row].key;
|
||||
return cookedOptions.items[row].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return contents[row].value;
|
||||
return cookedOptions.items[row].default_value;
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
@@ -117,7 +116,7 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
|
||||
|
||||
int GameOptions::rowCount(const QModelIndex&) const
|
||||
{
|
||||
return contents.size();
|
||||
return cookedOptions.items.size();
|
||||
}
|
||||
|
||||
int GameOptions::columnCount(const QModelIndex&) const
|
||||
@@ -133,12 +132,12 @@ bool GameOptions::isLoaded() const
|
||||
bool GameOptions::reload()
|
||||
{
|
||||
beginResetModel();
|
||||
loaded = load(path, contents, version);
|
||||
loaded = load(path, rawOptions);
|
||||
endResetModel();
|
||||
return loaded;
|
||||
}
|
||||
|
||||
bool GameOptions::save()
|
||||
{
|
||||
return ::save(path, contents, version);
|
||||
return ::save(path, rawOptions);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,46 @@
|
||||
#include <QString>
|
||||
#include <QAbstractListModel>
|
||||
|
||||
struct RawGameOptions
|
||||
{
|
||||
void clear()
|
||||
{
|
||||
version = 0;
|
||||
mapping.clear();
|
||||
}
|
||||
std::map<QString, QString> mapping;
|
||||
int version = 0;
|
||||
};
|
||||
|
||||
struct GameOptionItem
|
||||
{
|
||||
QString id;
|
||||
enum ValueType
|
||||
{
|
||||
INT,
|
||||
FLOAT,
|
||||
BOOL,
|
||||
FOV_MADNESS,
|
||||
FPS_MADNESS
|
||||
} value_type;
|
||||
enum VisualType
|
||||
{
|
||||
|
||||
} visual_type;
|
||||
QVariant null_value;
|
||||
QVariant default_value;
|
||||
QVariant min_value;
|
||||
QVariant max_value;
|
||||
QString key;
|
||||
QString value;
|
||||
};
|
||||
|
||||
struct CookedGameOptions
|
||||
{
|
||||
std::vector<GameOptionItem> items;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class GameOptions : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -27,7 +61,8 @@ public:
|
||||
bool save();
|
||||
|
||||
private:
|
||||
std::vector<GameOptionItem> contents;
|
||||
RawGameOptions rawOptions;
|
||||
CookedGameOptions cookedOptions;
|
||||
bool loaded = false;
|
||||
QString path;
|
||||
int version = 0;
|
||||
|
||||
@@ -488,10 +488,6 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
||||
m_settings->registerSetting("InstSortMode", "Name");
|
||||
m_settings->registerSetting("SelectedInstance", QString());
|
||||
|
||||
// Offline mode stuff
|
||||
m_settings->registerSetting("OfflineModeNameMode", "UseAccountName");
|
||||
m_settings->registerSetting("OfflineModeName", "Player");
|
||||
|
||||
// Window state and geometry
|
||||
m_settings->registerSetting("MainWindowState", "");
|
||||
m_settings->registerSetting("MainWindowGeometry", "");
|
||||
|
||||
@@ -33,18 +33,11 @@
|
||||
|
||||
#include "MultiMC.h"
|
||||
|
||||
enum class OfflineModeNameMode
|
||||
{
|
||||
UseAccountName = 1,
|
||||
RememberPerAccount = 2,
|
||||
RememberPerInstance = 3,
|
||||
UseFixedName = 4
|
||||
};
|
||||
|
||||
AccountListPage::AccountListPage(QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::AccountListPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->tabWidget->tabBar()->hide();
|
||||
|
||||
m_accounts = MMC->accounts();
|
||||
|
||||
@@ -63,15 +56,7 @@ AccountListPage::AccountListPage(QWidget *parent)
|
||||
connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
|
||||
connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
|
||||
|
||||
ui->offlineButtonGroup->setId(ui->useSelectedNameBtn, int(OfflineModeNameMode::UseAccountName));
|
||||
ui->offlineButtonGroup->setId(ui->rememberNamesForAccountsBtn, int(OfflineModeNameMode::RememberPerAccount));
|
||||
ui->offlineButtonGroup->setId(ui->rememberNamesForInstancesBtn, int(OfflineModeNameMode::RememberPerInstance));
|
||||
ui->offlineButtonGroup->setId(ui->useFixedNameBtn, int(OfflineModeNameMode::UseFixedName));
|
||||
|
||||
connect(ui->offlineButtonGroup, SIGNAL(buttonToggled(int,bool)), this, SLOT(groupSelectionChanged(int,bool)));
|
||||
|
||||
updateButtonStates();
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
AccountListPage::~AccountListPage()
|
||||
@@ -166,68 +151,3 @@ void AccountListPage::on_uploadSkinBtn_clicked()
|
||||
dialog.exec();
|
||||
}
|
||||
}
|
||||
|
||||
bool AccountListPage::apply()
|
||||
{
|
||||
applySettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
void AccountListPage::applySettings()
|
||||
{
|
||||
auto s = MMC->settings();
|
||||
auto sortMode = (OfflineModeNameMode)ui->offlineButtonGroup->checkedId();
|
||||
switch (sortMode)
|
||||
{
|
||||
default:
|
||||
case OfflineModeNameMode::UseAccountName:
|
||||
s->set("OfflineModeNameMode", "UseAccountName");
|
||||
break;
|
||||
case OfflineModeNameMode::RememberPerAccount:
|
||||
s->set("OfflineModeNameMode", "RememberPerAccount");
|
||||
break;
|
||||
case OfflineModeNameMode::RememberPerInstance:
|
||||
s->set("OfflineModeNameMode", "RememberPerInstance");
|
||||
break;
|
||||
case OfflineModeNameMode::UseFixedName:
|
||||
s->set("OfflineModeNameMode", "UseFixedName");
|
||||
break;
|
||||
}
|
||||
s->set("OfflineModeName", ui->mainOfflineNameEdit->text());
|
||||
}
|
||||
|
||||
void AccountListPage::loadSettings()
|
||||
{
|
||||
auto s = MMC->settings();
|
||||
auto value = s->get("OfflineModeNameMode").toString();
|
||||
if(value == "UseAccountName")
|
||||
{
|
||||
ui->useSelectedNameBtn->setChecked(true);
|
||||
}
|
||||
else if(value == "RememberPerAccount")
|
||||
{
|
||||
ui->rememberNamesForAccountsBtn->setChecked(true);
|
||||
}
|
||||
else if(value == "RememberPerInstance")
|
||||
{
|
||||
ui->rememberNamesForInstancesBtn->setChecked(true);
|
||||
}
|
||||
else if(value == "UseFixedName")
|
||||
{
|
||||
ui->useFixedNameBtn->setChecked(true);
|
||||
}
|
||||
ui->mainOfflineNameEdit->setText(s->get("OfflineModeName").toString());
|
||||
}
|
||||
|
||||
void AccountListPage::groupSelectionChanged(int, bool)
|
||||
{
|
||||
auto sortMode = (OfflineModeNameMode)ui->offlineButtonGroup->checkedId();
|
||||
if(sortMode == OfflineModeNameMode::UseFixedName)
|
||||
{
|
||||
ui->mainOfflineNameEdit->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->mainOfflineNameEdit->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ public:
|
||||
{
|
||||
return "Getting-Started#adding-an-account";
|
||||
}
|
||||
bool apply() override;
|
||||
|
||||
public
|
||||
slots:
|
||||
@@ -74,8 +73,6 @@ slots:
|
||||
|
||||
void listChanged();
|
||||
|
||||
void groupSelectionChanged(int, bool);
|
||||
|
||||
//! Updates the states of the dialog's buttons.
|
||||
void updateButtonStates();
|
||||
|
||||
@@ -86,10 +83,6 @@ protected
|
||||
slots:
|
||||
void addAccount(const QString& errMsg="");
|
||||
|
||||
private:
|
||||
void applySettings();
|
||||
void loadSettings();
|
||||
|
||||
private:
|
||||
Ui::AccountListPage *ui;
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>333</width>
|
||||
<height>302</height>
|
||||
<width>694</width>
|
||||
<height>609</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
@@ -28,9 +28,9 @@
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="onlineTab">
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Online</string>
|
||||
<string notr="true">Tab 1</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
@@ -113,89 +113,10 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="offlineTab">
|
||||
<attribute name="title">
|
||||
<string>Offline</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout22">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="offlineBox">
|
||||
<property name="title">
|
||||
<string>Offline mode name</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="foldersBoxLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QRadioButton" name="useSelectedNameBtn">
|
||||
<property name="text">
|
||||
<string>&Use selected account name</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">offlineButtonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QRadioButton" name="useFixedNameBtn">
|
||||
<property name="text">
|
||||
<string>Always use &this offline name:</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">offlineButtonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLineEdit" name="mainOfflineNameEdit">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QRadioButton" name="rememberNamesForAccountsBtn">
|
||||
<property name="text">
|
||||
<string>Remember offline &names per account</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">offlineButtonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QRadioButton" name="rememberNamesForInstancesBtn">
|
||||
<property name="text">
|
||||
<string>Remember offline &names per instance</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">offlineButtonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<buttongroups>
|
||||
<buttongroup name="offlineButtonGroup"/>
|
||||
</buttongroups>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user