summaryrefslogtreecommitdiffstats
path: root/logic/minecraft
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-09-22 01:06:45 +0200
committerPetr Mrázek <peterix@gmail.com>2015-09-22 01:06:45 +0200
commit9ba1cd15e7f902cae705ff22451e4f76ad0d71ab (patch)
treeaafc4d87d81489d3e8ab782c8b7922c44f1ea192 /logic/minecraft
parentb10761711234b69cf8509bacb055f7d5c3c021e8 (diff)
downloadMultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.tar
MultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.tar.gz
MultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.tar.lz
MultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.tar.xz
MultiMC-9ba1cd15e7f902cae705ff22451e4f76ad0d71ab.zip
GH-1217 add simple instance play time tracking
Not reliable in the face of crashes... but what is?
Diffstat (limited to 'logic/minecraft')
-rw-r--r--logic/minecraft/LegacyInstance.cpp12
-rw-r--r--logic/minecraft/LegacyInstance.h2
-rw-r--r--logic/minecraft/MinecraftInstance.cpp42
-rw-r--r--logic/minecraft/MinecraftInstance.h4
-rw-r--r--logic/minecraft/OneSixInstance.cpp23
-rw-r--r--logic/minecraft/OneSixInstance.h4
6 files changed, 58 insertions, 29 deletions
diff --git a/logic/minecraft/LegacyInstance.cpp b/logic/minecraft/LegacyInstance.cpp
index b9082bc6..f39f3c8b 100644
--- a/logic/minecraft/LegacyInstance.cpp
+++ b/logic/minecraft/LegacyInstance.cpp
@@ -445,16 +445,12 @@ QString LegacyInstance::defaultCustomBaseJar() const
return PathCombine(binDir(), "mcbackup.jar");
}
-QString LegacyInstance::getStatusbarDescription()
+QString LegacyInstance::lwjglFolder() const
{
- if (flags() & VersionBrokenFlag)
- {
- return tr("Legacy : %1 (broken)").arg(intendedVersionId());
- }
- return tr("Legacy : %1").arg(intendedVersionId());
+ return m_lwjglFolderSetting->get().toString();
}
-QString LegacyInstance::lwjglFolder() const
+QString LegacyInstance::typeName() const
{
- return m_lwjglFolderSetting->get().toString();
+ return tr("Legacy");
}
diff --git a/logic/minecraft/LegacyInstance.h b/logic/minecraft/LegacyInstance.h
index 724fcd33..14f13b20 100644
--- a/logic/minecraft/LegacyInstance.h
+++ b/logic/minecraft/LegacyInstance.h
@@ -120,7 +120,7 @@ public:
virtual void cleanupAfterRun() override;
- virtual QString getStatusbarDescription() override;
+ virtual QString typeName() const;
protected:
mutable std::shared_ptr<ModList> jar_mod_list;
diff --git a/logic/minecraft/MinecraftInstance.cpp b/logic/minecraft/MinecraftInstance.cpp
index e694045b..8fd65d50 100644
--- a/logic/minecraft/MinecraftInstance.cpp
+++ b/logic/minecraft/MinecraftInstance.cpp
@@ -305,4 +305,46 @@ QString MinecraftInstance::getLogFileRoot()
return minecraftRoot();
}
+QString MinecraftInstance::prettifyTimeDuration(int64_t duration)
+{
+ int seconds = (int) (duration % 60);
+ duration /= 60;
+ int minutes = (int) (duration % 60);
+ duration /= 60;
+ int hours = (int) (duration % 24);
+ int days = (int) (duration / 24);
+ if((hours == 0)&&(days == 0))
+ {
+ return tr("%1m %2s").arg(minutes).arg(seconds);
+ }
+ if (days == 0)
+ {
+ return tr("%1h %2m").arg(hours).arg(minutes);
+ }
+ return tr("%1d %2h %3m").arg(days).arg(hours).arg(minutes);
+}
+
+QString MinecraftInstance::getStatusbarDescription()
+{
+ QStringList traits;
+ if (flags() & VersionBrokenFlag)
+ {
+ traits.append(tr("broken"));
+ }
+
+ QString description;
+ description.append(tr("Minecraft %1 (%2)").arg(intendedVersionId()).arg(typeName()));
+ if(totalTimePlayed() > 0)
+ {
+ description.append(tr(", played for %1").arg(prettifyTimeDuration(totalTimePlayed())));
+ }
+ /*
+ if(traits.size())
+ {
+ description.append(QString(" (%1)").arg(traits.join(", ")));
+ }
+ */
+ return description;
+}
+
#include "MinecraftInstance.moc"
diff --git a/logic/minecraft/MinecraftInstance.h b/logic/minecraft/MinecraftInstance.h
index 8c6838e7..b5483d1b 100644
--- a/logic/minecraft/MinecraftInstance.h
+++ b/logic/minecraft/MinecraftInstance.h
@@ -55,8 +55,12 @@ public:
virtual QString getLogFileRoot() override;
+ virtual QString getStatusbarDescription() override;
+
protected:
QMap<QString, QString> createCensorFilterFromSession(AuthSessionPtr session);
+private:
+ QString prettifyTimeDuration(int64_t duration);
};
typedef std::shared_ptr<MinecraftInstance> MinecraftInstancePtr;
diff --git a/logic/minecraft/OneSixInstance.cpp b/logic/minecraft/OneSixInstance.cpp
index 87994cef..a5be8354 100644
--- a/logic/minecraft/OneSixInstance.cpp
+++ b/logic/minecraft/OneSixInstance.cpp
@@ -476,24 +476,6 @@ std::shared_ptr<MinecraftProfile> OneSixInstance::getMinecraftProfile() const
return m_version;
}
-QString OneSixInstance::getStatusbarDescription()
-{
- QStringList traits;
- if (flags() & VersionBrokenFlag)
- {
- traits.append(tr("broken"));
- }
-
- if (traits.size())
- {
- return tr("Minecraft %1 (%2)").arg(intendedVersionId()).arg(traits.join(", "));
- }
- else
- {
- return tr("Minecraft %1").arg(intendedVersionId());
- }
-}
-
QDir OneSixInstance::librariesPath() const
{
return QDir::current().absoluteFilePath("libraries");
@@ -590,3 +572,8 @@ std::shared_ptr<OneSixInstance> OneSixInstance::getSharedPtr()
{
return std::dynamic_pointer_cast<OneSixInstance>(BaseInstance::getSharedPtr());
}
+
+QString OneSixInstance::typeName() const
+{
+ return tr("OneSix");
+}
diff --git a/logic/minecraft/OneSixInstance.h b/logic/minecraft/OneSixInstance.h
index 68be1d4d..6d09b81a 100644
--- a/logic/minecraft/OneSixInstance.h
+++ b/logic/minecraft/OneSixInstance.h
@@ -79,8 +79,6 @@ public:
/// get the current full version info
std::shared_ptr<MinecraftProfile> getMinecraftProfile() const;
- virtual QString getStatusbarDescription() override;
-
virtual QDir jarmodsPath() const;
virtual QDir librariesPath() const;
virtual QDir versionsPath() const;
@@ -92,6 +90,8 @@ public:
std::shared_ptr<OneSixInstance> getSharedPtr();
+ virtual QString typeName() const;
+
signals:
void versionReloaded();