Merge pull request #4173 from jamierocks/common-time-duration-format
NOISSUE Use common duration format for global and instances
This commit is contained in:
commit
98887911c1
@ -84,6 +84,10 @@ set(CORE_SOURCES
|
|||||||
# A Recursive file system watcher
|
# A Recursive file system watcher
|
||||||
RecursiveFileSystemWatcher.h
|
RecursiveFileSystemWatcher.h
|
||||||
RecursiveFileSystemWatcher.cpp
|
RecursiveFileSystemWatcher.cpp
|
||||||
|
|
||||||
|
# Time
|
||||||
|
MMCTime.h
|
||||||
|
MMCTime.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(FileSystem
|
add_unit_test(FileSystem
|
||||||
|
21
launcher/MMCTime.cpp
Normal file
21
launcher/MMCTime.cpp
Normal 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
9
launcher/MMCTime.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace Time {
|
||||||
|
|
||||||
|
QString prettifyDuration(int64_t duration);
|
||||||
|
|
||||||
|
}
|
@ -88,6 +88,7 @@
|
|||||||
#include "UpdateController.h"
|
#include "UpdateController.h"
|
||||||
#include "KonamiCode.h"
|
#include "KonamiCode.h"
|
||||||
#include <InstanceCopyTask.h>
|
#include <InstanceCopyTask.h>
|
||||||
|
#include "MMCTime.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
QString profileInUseFilter(const QString & profile, bool used)
|
QString profileInUseFilter(const QString & profile, bool used)
|
||||||
@ -747,7 +748,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
|||||||
connect(LAUNCHER, &Launcher::globalSettingsClosed, this, &MainWindow::globalSettingsClosed);
|
connect(LAUNCHER, &Launcher::globalSettingsClosed, this, &MainWindow::globalSettingsClosed);
|
||||||
|
|
||||||
m_statusLeft = new QLabel(tr("No instance selected"), this);
|
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_statusLeft, 1);
|
||||||
statusBar()->addPermanentWidget(m_statusCenter, 0);
|
statusBar()->addPermanentWidget(m_statusCenter, 0);
|
||||||
|
|
||||||
@ -1926,15 +1927,8 @@ void MainWindow::checkInstancePathForProblems()
|
|||||||
|
|
||||||
void MainWindow::updateStatusCenter()
|
void MainWindow::updateStatusCenter()
|
||||||
{
|
{
|
||||||
int timeplayed = LAUNCHER->instances()->getTotalPlayTime();
|
int timePlayed = LAUNCHER->instances()->getTotalPlayTime();
|
||||||
int minutesTotal = timeplayed / 60;
|
if (timePlayed > 0) {
|
||||||
int seconds = timeplayed % 60;
|
m_statusCenter->setText(tr("Total playtime: %1").arg(Time::prettifyDuration(timePlayed)));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <pathmatcher/MultiMatcher.h>
|
#include <pathmatcher/MultiMatcher.h>
|
||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
#include <java/JavaVersion.h>
|
#include <java/JavaVersion.h>
|
||||||
|
#include "MMCTime.h"
|
||||||
|
|
||||||
#include "launch/LaunchTask.h"
|
#include "launch/LaunchTask.h"
|
||||||
#include "launch/steps/LookupServerAddress.h"
|
#include "launch/steps/LookupServerAddress.h"
|
||||||
@ -766,25 +767,6 @@ QString MinecraftInstance::getLogFileRoot()
|
|||||||
return gameRoot();
|
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()
|
QString MinecraftInstance::getStatusbarDescription()
|
||||||
{
|
{
|
||||||
QStringList traits;
|
QStringList traits;
|
||||||
@ -798,11 +780,11 @@ QString MinecraftInstance::getStatusbarDescription()
|
|||||||
if(m_settings->get("ShowGameTime").toBool())
|
if(m_settings->get("ShowGameTime").toBool())
|
||||||
{
|
{
|
||||||
if (lastTimePlayed() > 0) {
|
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) {
|
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())
|
if(hasCrashed())
|
||||||
|
@ -118,9 +118,6 @@ protected:
|
|||||||
QStringList validLaunchMethods();
|
QStringList validLaunchMethods();
|
||||||
QString launchMethod();
|
QString launchMethod();
|
||||||
|
|
||||||
private:
|
|
||||||
QString prettifyTimeDuration(int64_t duration);
|
|
||||||
|
|
||||||
protected: // data
|
protected: // data
|
||||||
std::shared_ptr<PackProfile> m_components;
|
std::shared_ptr<PackProfile> m_components;
|
||||||
mutable std::shared_ptr<ModFolderModel> m_loader_mod_list;
|
mutable std::shared_ptr<ModFolderModel> m_loader_mod_list;
|
||||||
|
Loading…
Reference in New Issue
Block a user