aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--launcher/CMakeLists.txt4
-rw-r--r--launcher/MMCTime.cpp21
-rw-r--r--launcher/MMCTime.h9
-rw-r--r--launcher/MainWindow.cpp16
-rw-r--r--launcher/minecraft/MinecraftInstance.cpp24
-rw-r--r--launcher/minecraft/MinecraftInstance.h3
6 files changed, 42 insertions, 35 deletions
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 5c45273b..d67dcdbf 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -84,6 +84,10 @@ set(CORE_SOURCES
# A Recursive file system watcher
RecursiveFileSystemWatcher.h
RecursiveFileSystemWatcher.cpp
+
+ # Time
+ MMCTime.h
+ MMCTime.cpp
)
add_unit_test(FileSystem
diff --git a/launcher/MMCTime.cpp b/launcher/MMCTime.cpp
new file mode 100644
index 00000000..fa26e0b9
--- /dev/null
+++ b/launcher/MMCTime.cpp
@@ -0,0 +1,21 @@
+#include <MMCTime.h>
+
+#include <QObject>
+
+QString Time::prettifyDuration(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 QObject::tr("%1m %2s").arg(minutes).arg(seconds);
+ }
+ if (days == 0)
+ {
+ return QObject::tr("%1h %2m").arg(hours).arg(minutes);
+ }
+ return QObject::tr("%1d %2h %3m").arg(days).arg(hours).arg(minutes);
+}
diff --git a/launcher/MMCTime.h b/launcher/MMCTime.h
new file mode 100644
index 00000000..728a5abb
--- /dev/null
+++ b/launcher/MMCTime.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <QString>
+
+namespace Time {
+
+QString prettifyDuration(int64_t duration);
+
+}
diff --git a/launcher/MainWindow.cpp b/launcher/MainWindow.cpp
index c3cc6b8d..d394238a 100644
--- a/launcher/MainWindow.cpp
+++ b/launcher/MainWindow.cpp
@@ -88,6 +88,7 @@
#include "UpdateController.h"
#include "KonamiCode.h"
#include <InstanceCopyTask.h>
+#include "MMCTime.h"
namespace {
QString profileInUseFilter(const QString & profile, bool used)
@@ -1926,15 +1927,8 @@ void MainWindow::checkInstancePathForProblems()
void MainWindow::updateStatusCenter()
{
- int timeplayed = LAUNCHER->instances()->getTotalPlayTime();
- int minutesTotal = timeplayed / 60;
- int seconds = timeplayed % 60;
- int minutes = minutesTotal % 60;
- int hours = minutesTotal / 60;
- if(hours != 0)
- m_statusCenter->setText(tr("Total playtime: %1h %2m %3s").arg(hours).arg(minutes).arg(seconds));
- else if(minutes != 0)
- m_statusCenter->setText(tr("Total playtime: %1m %2s").arg(minutes).arg(seconds));
- else if(seconds != 0)
- m_statusCenter->setText(tr("Total playtime: %1s").arg(seconds));
+ int timePlayed = LAUNCHER->instances()->getTotalPlayTime();
+ if (timePlayed > 0) {
+ m_statusCenter->setText(tr("Total playtime: %1").arg(Time::prettifyDuration(timePlayed)));
+ }
}
diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp
index 11c4dec1..2982a340 100644
--- a/launcher/minecraft/MinecraftInstance.cpp
+++ b/launcher/minecraft/MinecraftInstance.cpp
@@ -10,6 +10,7 @@
#include <pathmatcher/MultiMatcher.h>
#include <FileSystem.h>
#include <java/JavaVersion.h>
+#include "MMCTime.h"
#include "launch/LaunchTask.h"
#include "launch/steps/LookupServerAddress.h"
@@ -766,25 +767,6 @@ QString MinecraftInstance::getLogFileRoot()
return gameRoot();
}
-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;
@@ -798,11 +780,11 @@ QString MinecraftInstance::getStatusbarDescription()
if(m_settings->get("ShowGameTime").toBool())
{
if (lastTimePlayed() > 0) {
- description.append(tr(", last played for %1").arg(prettifyTimeDuration(lastTimePlayed())));
+ description.append(tr(", last played for %1").arg(Time::prettifyDuration(lastTimePlayed())));
}
if (totalTimePlayed() > 0) {
- description.append(tr(", total played for %1").arg(prettifyTimeDuration(totalTimePlayed())));
+ description.append(tr(", total played for %1").arg(Time::prettifyDuration(totalTimePlayed())));
}
}
if(hasCrashed())
diff --git a/launcher/minecraft/MinecraftInstance.h b/launcher/minecraft/MinecraftInstance.h
index cdfd350b..b11270e6 100644
--- a/launcher/minecraft/MinecraftInstance.h
+++ b/launcher/minecraft/MinecraftInstance.h
@@ -118,9 +118,6 @@ protected:
QStringList validLaunchMethods();
QString launchMethod();
-private:
- QString prettifyTimeDuration(int64_t duration);
-
protected: // data
std::shared_ptr<PackProfile> m_components;
mutable std::shared_ptr<ModFolderModel> m_loader_mod_list;