NOISSUE Use common duration format for global and instances

This commit is contained in:
Jamie Mansfield 2021-09-28 23:20:34 +01:00
parent 110c73edf2
commit 7cbca6ab20
No known key found for this signature in database
GPG Key ID: 36F61598F39F67B0
6 changed files with 42 additions and 35 deletions

View File

@ -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

21
launcher/MMCTime.cpp Normal file
View File

@ -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);
}

9
launcher/MMCTime.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <QString>
namespace Time {
QString prettifyDuration(int64_t duration);
}

View File

@ -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)));
}
}

View File

@ -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())

View File

@ -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;