Compare commits

..

3 Commits

Author SHA1 Message Date
Petr Mrázek
7b0a812db7 WIP break stuff 2019-07-13 23:31:25 +02:00
Petr Mrázek
62e1bf327d Merge pull request #2740 from jturnism/patch-1
Update changelog.md
2019-07-12 08:19:20 +02:00
Joseph Turner
280e0e6e36 Update changelog.md
Just installing "qt5-qtbase" on Fedora 30 does not allow MultiMC to run. It still needs "libQt5Widgets.so.5" and by running "dnf whatprovides" it tells me "qt5-qtbase-gui" provides that file and also pulls in "qt5-qtbase" as a dependency if not already installed. I am assuming this is the same situation for CentOS/RHEL
2019-07-11 21:00:55 -05:00
3 changed files with 56 additions and 22 deletions

View File

@@ -4,7 +4,7 @@
#include <QSaveFile> #include <QSaveFile>
namespace { namespace {
bool load(const QString& path, std::vector<GameOptionItem> &contents, int & version) bool load(const QString& path, RawGameOptions & contents)
{ {
contents.clear(); contents.clear();
QFile file(path); QFile file(path);
@@ -13,7 +13,6 @@ bool load(const QString& path, std::vector<GameOptionItem> &contents, int & vers
qWarning() << "Failed to read options file."; qWarning() << "Failed to read options file.";
return false; return false;
} }
version = 0;
while(!file.atEnd()) while(!file.atEnd())
{ {
auto line = file.readLine(); auto line = file.readLine();
@@ -31,32 +30,32 @@ bool load(const QString& path, std::vector<GameOptionItem> &contents, int & vers
qDebug() << "!!" << key << "!!"; qDebug() << "!!" << key << "!!";
if(key == "version") if(key == "version")
{ {
version = value.toInt(); contents.version = value.toInt();
continue; 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; return true;
} }
bool save(const QString& path, std::vector<GameOptionItem> &mapping, int version) bool save(const QString& path, RawGameOptions& contents)
{ {
QSaveFile out(path); QSaveFile out(path);
if(!out.open(QIODevice::WriteOnly)) if(!out.open(QIODevice::WriteOnly))
{ {
return false; 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()); out.write(versionLine.toUtf8());
} }
auto iter = mapping.begin(); auto iter = contents.mapping.begin();
while (iter != mapping.end()) while (iter != contents.mapping.end())
{ {
out.write(iter->key.toUtf8()); out.write(iter->first.toUtf8());
out.write(":"); out.write(":");
out.write(iter->value.toUtf8()); out.write(iter->second.toUtf8());
out.write("\n"); out.write("\n");
iter++; iter++;
} }
@@ -95,7 +94,7 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
int row = index.row(); int row = index.row();
int column = index.column(); int column = index.column();
if (row < 0 || row >= int(contents.size())) if (row < 0 || row >= rowCount())
return QVariant(); return QVariant();
switch (role) switch (role)
@@ -103,11 +102,11 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
case Qt::DisplayRole: case Qt::DisplayRole:
if(column == 0) if(column == 0)
{ {
return contents[row].key; return cookedOptions.items[row].id;
} }
else else
{ {
return contents[row].value; return cookedOptions.items[row].default_value;
} }
default: default:
return QVariant(); return QVariant();
@@ -117,7 +116,7 @@ QVariant GameOptions::data(const QModelIndex& index, int role) const
int GameOptions::rowCount(const QModelIndex&) const int GameOptions::rowCount(const QModelIndex&) const
{ {
return contents.size(); return cookedOptions.items.size();
} }
int GameOptions::columnCount(const QModelIndex&) const int GameOptions::columnCount(const QModelIndex&) const
@@ -133,12 +132,12 @@ bool GameOptions::isLoaded() const
bool GameOptions::reload() bool GameOptions::reload()
{ {
beginResetModel(); beginResetModel();
loaded = load(path, contents, version); loaded = load(path, rawOptions);
endResetModel(); endResetModel();
return loaded; return loaded;
} }
bool GameOptions::save() bool GameOptions::save()
{ {
return ::save(path, contents, version); return ::save(path, rawOptions);
} }

View File

@@ -4,12 +4,46 @@
#include <QString> #include <QString>
#include <QAbstractListModel> #include <QAbstractListModel>
struct RawGameOptions
{
void clear()
{
version = 0;
mapping.clear();
}
std::map<QString, QString> mapping;
int version = 0;
};
struct GameOptionItem 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 key;
QString value;
}; };
struct CookedGameOptions
{
std::vector<GameOptionItem> items;
};
class GameOptions : public QAbstractListModel class GameOptions : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
@@ -27,7 +61,8 @@ public:
bool save(); bool save();
private: private:
std::vector<GameOptionItem> contents; RawGameOptions rawOptions;
CookedGameOptions cookedOptions;
bool loaded = false; bool loaded = false;
QString path; QString path;
int version = 0; int version = 0;

View File

@@ -12,7 +12,7 @@ Make sure you have the following packages before you update:
- Arch: `qt5-base` - Arch: `qt5-base`
- Debian/Ubuntu: `qt5-default` - Debian/Ubuntu: `qt5-default`
- CentOS/RHEL: `qt5-qtbase` - CentOS/RHEL/Fedora: `qt5-qtbase-gui`
- Suse: `libqt5-qtbase` - Suse: `libqt5-qtbase`
MultiMC on linux is built with Qt 5.4 and older versions of Qt will not work. MultiMC on linux is built with Qt 5.4 and older versions of Qt will not work.
@@ -1170,4 +1170,4 @@ Long time coming, this release brought a lot of incremental improvements and fix
- Added additional information to the about dialog. - Added additional information to the about dialog.
## MultiMC 0.0 ## MultiMC 0.0
- Initial release. - Initial release.