From 7cbca6ab20f34bbb9522f002f2f1cfa4eca1da18 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 28 Sep 2021 23:20:34 +0100 Subject: [PATCH 1/2] NOISSUE Use common duration format for global and instances --- launcher/CMakeLists.txt | 4 ++++ launcher/MMCTime.cpp | 21 +++++++++++++++++++++ launcher/MMCTime.h | 9 +++++++++ launcher/MainWindow.cpp | 16 +++++----------- launcher/minecraft/MinecraftInstance.cpp | 24 +++--------------------- launcher/minecraft/MinecraftInstance.h | 3 --- 6 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 launcher/MMCTime.cpp create mode 100644 launcher/MMCTime.h 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 + +#include + +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 + +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 +#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 #include #include +#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 m_components; mutable std::shared_ptr m_loader_mod_list; From 5bc6dd8f970249c8279d6302f8df56910c599514 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Fri, 1 Oct 2021 23:20:25 +0100 Subject: [PATCH 2/2] NOISSUE Remove lingering full stop in playtime status --- launcher/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/MainWindow.cpp b/launcher/MainWindow.cpp index d394238a..33d9c7f4 100644 --- a/launcher/MainWindow.cpp +++ b/launcher/MainWindow.cpp @@ -748,7 +748,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow connect(LAUNCHER, &Launcher::globalSettingsClosed, this, &MainWindow::globalSettingsClosed); m_statusLeft = new QLabel(tr("No instance selected"), this); - m_statusCenter = new QLabel(tr("Total playtime: 0s."), this); + m_statusCenter = new QLabel(tr("Total playtime: 0s"), this); statusBar()->addPermanentWidget(m_statusLeft, 1); statusBar()->addPermanentWidget(m_statusCenter, 0);