diff options
author | Petr Mrázek <peterix@gmail.com> | 2018-12-11 23:53:14 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2018-12-11 23:53:14 +0100 |
commit | 13b293dd6518f8e3c80afd6fe40629e3caee69dc (patch) | |
tree | 1af24d9e9e0ea426138f18d24c7bfbeab7803d9b | |
parent | de568b32b85b24fb24fdec2bc90066bf00b2f013 (diff) | |
download | MultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.tar MultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.tar.gz MultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.tar.lz MultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.tar.xz MultiMC-13b293dd6518f8e3c80afd6fe40629e3caee69dc.zip |
GH-2374 fix missing alternating backgrounds in worlds, add gametype column
-rw-r--r-- | api/logic/minecraft/World.cpp | 49 | ||||
-rw-r--r-- | api/logic/minecraft/World.h | 14 | ||||
-rw-r--r-- | api/logic/minecraft/WorldList.cpp | 9 | ||||
-rw-r--r-- | api/logic/minecraft/WorldList.h | 2 | ||||
-rw-r--r-- | application/pages/instance/WorldListPage.ui | 3 |
5 files changed, 76 insertions, 1 deletions
diff --git a/api/logic/minecraft/World.cpp b/api/logic/minecraft/World.cpp index b39f940e..5da562aa 100644 --- a/api/logic/minecraft/World.cpp +++ b/api/logic/minecraft/World.cpp @@ -30,6 +30,26 @@ #include <quazipfile.h> #include <quazipdir.h> +#include <QCoreApplication> + +QString gameTypeToString(GameType type) +{ + switch (type) + { + case GameType::Survival: + return QCoreApplication::translate("GameType", "Survival"); + case GameType::Creative: + return QCoreApplication::translate("GameType", "Creative"); + case GameType::Adventure: + return QCoreApplication::translate("GameType", "Adventure"); + case GameType::Spectator: + return QCoreApplication::translate("GameType", "Spectator"); + default: + break; + } + return QObject::tr("Unknown"); +} + std::unique_ptr <nbt::tag_compound> parseLevelDat(QByteArray data) { QByteArray output; @@ -303,6 +323,32 @@ static int64_t read_long (nbt::value& parent, const char * name, const int64_t & } } +static int read_int (nbt::value& parent, const char * name, const int & fallback = 0) +{ + try + { + auto &namedValue = parent.at(name); + if(namedValue.get_type() != nbt::tag_type::Int) + { + return fallback; + } + auto & tag_str = namedValue.as<nbt::tag_int>(); + return tag_str.get(); + } + catch (const std::out_of_range &e) + { + // fallback for old world formats + qWarning() << "Int NBT tag" << name << "could not be found. Defaulting to" << fallback; + return fallback; + } + catch (const std::bad_cast &e) + { + // type mismatch + qWarning() << "NBT tag" << name << "could not be converted to int. Defaulting to" << fallback; + return fallback; + } +} + void World::loadFromLevelDat(QByteArray data) { try @@ -332,11 +378,14 @@ void World::loadFromLevelDat(QByteArray data) m_lastPlayed = QDateTime::fromMSecsSinceEpoch(temp); } + m_gameType = (GameType) read_int(val, "GameType", 0); + m_randomSeed = read_long(val, "RandomSeed", 0); qDebug() << "World Name:" << m_actualName; qDebug() << "Last Played:" << m_lastPlayed.toString(); qDebug() << "Seed:" << m_randomSeed; + qDebug() << "GameMode:" << m_randomSeed; } catch (const nbt::io::input_error &e) { diff --git a/api/logic/minecraft/World.h b/api/logic/minecraft/World.h index 2cce85a2..7cb694a7 100644 --- a/api/logic/minecraft/World.h +++ b/api/logic/minecraft/World.h @@ -19,6 +19,15 @@ #include "multimc_logic_export.h" +enum class GameType +{ + Survival, + Creative, + Adventure, + Spectator +}; +QString MULTIMC_LOGIC_EXPORT gameTypeToString(GameType type); + class MULTIMC_LOGIC_EXPORT World { public: @@ -35,6 +44,10 @@ public: { return m_lastPlayed; } + GameType gameType() const + { + return m_gameType; + } int64_t seed() const { return m_randomSeed; @@ -79,5 +92,6 @@ protected: QDateTime levelDatTime; QDateTime m_lastPlayed; int64_t m_randomSeed = 0; + GameType m_gameType = GameType::Survival; bool is_valid = false; }; diff --git a/api/logic/minecraft/WorldList.cpp b/api/logic/minecraft/WorldList.cpp index 79a5bf38..827b2d63 100644 --- a/api/logic/minecraft/WorldList.cpp +++ b/api/logic/minecraft/WorldList.cpp @@ -138,7 +138,7 @@ bool WorldList::deleteWorlds(int first, int last) int WorldList::columnCount(const QModelIndex &parent) const { - return 2; + return 3; } QVariant WorldList::data(const QModelIndex &index, int role) const @@ -161,6 +161,9 @@ QVariant WorldList::data(const QModelIndex &index, int role) const case NameColumn: return world.name(); + case GameModeColumn: + return gameTypeToString(world.gameType()); + case LastPlayedColumn: return world.lastPlayed(); @@ -206,6 +209,8 @@ QVariant WorldList::headerData(int section, Qt::Orientation orientation, int rol { case NameColumn: return tr("Name"); + case GameModeColumn: + return tr("Game Mode"); case LastPlayedColumn: return tr("Last Played"); default: @@ -217,6 +222,8 @@ QVariant WorldList::headerData(int section, Qt::Orientation orientation, int rol { case NameColumn: return tr("The name of the world."); + case GameModeColumn: + return tr("Game mode of the world."); case LastPlayedColumn: return tr("Date and time the world was last played."); default: diff --git a/api/logic/minecraft/WorldList.h b/api/logic/minecraft/WorldList.h index a1cd8f51..433d354b 100644 --- a/api/logic/minecraft/WorldList.h +++ b/api/logic/minecraft/WorldList.h @@ -33,6 +33,7 @@ public: enum Columns { NameColumn, + GameModeColumn, LastPlayedColumn }; @@ -42,6 +43,7 @@ public: FolderRole, SeedRole, NameRole, + GameModeRole, LastPlayedRole }; diff --git a/application/pages/instance/WorldListPage.ui b/application/pages/instance/WorldListPage.ui index 0018ddf3..bc104854 100644 --- a/application/pages/instance/WorldListPage.ui +++ b/application/pages/instance/WorldListPage.ui @@ -126,6 +126,9 @@ <property name="dragDropMode"> <enum>QAbstractItemView::DragDrop</enum> </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> <property name="sortingEnabled"> <bool>true</bool> </property> |