Merge pull request #1536 from Trial97/time3
Allow showing playtime in hours
This commit is contained in:
commit
e3b04d10cf
@ -594,6 +594,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
|||||||
m_settings->registerSetting("ShowGameTime", true);
|
m_settings->registerSetting("ShowGameTime", true);
|
||||||
m_settings->registerSetting("ShowGlobalGameTime", true);
|
m_settings->registerSetting("ShowGlobalGameTime", true);
|
||||||
m_settings->registerSetting("RecordGameTime", true);
|
m_settings->registerSetting("RecordGameTime", true);
|
||||||
|
m_settings->registerSetting("ShowGameTimeWithoutDays", false);
|
||||||
|
|
||||||
// Minecraft mods
|
// Minecraft mods
|
||||||
m_settings->registerSetting("ModMetadataDisabled", false);
|
m_settings->registerSetting("ModMetadataDisabled", false);
|
||||||
|
@ -16,19 +16,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <MMCTime.h>
|
#include <MMCTime.h>
|
||||||
|
#include <qobject.h>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
QString Time::prettifyDuration(int64_t duration)
|
QString Time::prettifyDuration(int64_t duration, bool noDays)
|
||||||
{
|
{
|
||||||
int seconds = (int)(duration % 60);
|
int seconds = (int)(duration % 60);
|
||||||
duration /= 60;
|
duration /= 60;
|
||||||
int minutes = (int)(duration % 60);
|
int minutes = (int)(duration % 60);
|
||||||
duration /= 60;
|
duration /= 60;
|
||||||
int hours = (int)(duration % 24);
|
int hours = (int)(noDays ? duration : (duration % 24));
|
||||||
int days = (int)(duration / 24);
|
int days = (int)(noDays ? 0 : (duration / 24));
|
||||||
if ((hours == 0) && (days == 0)) {
|
if ((hours == 0) && (days == 0)) {
|
||||||
return QObject::tr("%1min %2s").arg(minutes).arg(seconds);
|
return QObject::tr("%1min %2s").arg(minutes).arg(seconds);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
namespace Time {
|
namespace Time {
|
||||||
|
|
||||||
QString prettifyDuration(int64_t duration);
|
QString prettifyDuration(int64_t duration, bool noDays = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a string with short form time duration ie. `2days 1h3m4s56.0ms`.
|
* @brief Returns a string with short form time duration ie. `2days 1h3m4s56.0ms`.
|
||||||
|
@ -934,13 +934,16 @@ QString MinecraftInstance::getStatusbarDescription()
|
|||||||
if (m_settings->get("ShowGameTime").toBool()) {
|
if (m_settings->get("ShowGameTime").toBool()) {
|
||||||
if (lastTimePlayed() > 0) {
|
if (lastTimePlayed() > 0) {
|
||||||
QDateTime lastLaunchTime = QDateTime::fromMSecsSinceEpoch(lastLaunch());
|
QDateTime lastLaunchTime = QDateTime::fromMSecsSinceEpoch(lastLaunch());
|
||||||
description.append(tr(", last played on %1 for %2")
|
description.append(
|
||||||
.arg(QLocale().toString(lastLaunchTime, QLocale::ShortFormat))
|
tr(", last played on %1 for %2")
|
||||||
.arg(Time::prettifyDuration(lastTimePlayed())));
|
.arg(QLocale().toString(lastLaunchTime, QLocale::ShortFormat))
|
||||||
|
.arg(Time::prettifyDuration(lastTimePlayed(), APPLICATION->settings()->get("ShowGameTimeWithoutDays").toBool())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalTimePlayed() > 0) {
|
if (totalTimePlayed() > 0) {
|
||||||
description.append(tr(", total played for %1").arg(Time::prettifyDuration(totalTimePlayed())));
|
description.append(
|
||||||
|
tr(", total played for %1")
|
||||||
|
.arg(Time::prettifyDuration(totalTimePlayed(), APPLICATION->settings()->get("ShowGameTimeWithoutDays").toBool())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasCrashed()) {
|
if (hasCrashed()) {
|
||||||
|
@ -1736,7 +1736,9 @@ void MainWindow::updateStatusCenter()
|
|||||||
|
|
||||||
int timePlayed = APPLICATION->instances()->getTotalPlayTime();
|
int timePlayed = APPLICATION->instances()->getTotalPlayTime();
|
||||||
if (timePlayed > 0) {
|
if (timePlayed > 0) {
|
||||||
m_statusCenter->setText(tr("Total playtime: %1").arg(Time::prettifyDuration(timePlayed)));
|
m_statusCenter->setText(
|
||||||
|
tr("Total playtime: %1")
|
||||||
|
.arg(Time::prettifyDuration(timePlayed, APPLICATION->settings()->get("ShowGameTimeWithoutDays").toBool())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// "Instance actions" are actions that require an instance to be selected (i.e. "new instance" is not here)
|
// "Instance actions" are actions that require an instance to be selected (i.e. "new instance" is not here)
|
||||||
|
@ -114,6 +114,7 @@ void MinecraftPage::applySettings()
|
|||||||
s->set("ShowGameTime", ui->showGameTime->isChecked());
|
s->set("ShowGameTime", ui->showGameTime->isChecked());
|
||||||
s->set("ShowGlobalGameTime", ui->showGlobalGameTime->isChecked());
|
s->set("ShowGlobalGameTime", ui->showGlobalGameTime->isChecked());
|
||||||
s->set("RecordGameTime", ui->recordGameTime->isChecked());
|
s->set("RecordGameTime", ui->recordGameTime->isChecked());
|
||||||
|
s->set("ShowGameTimeWithoutDays", ui->showGameTimeWithoutDays->isChecked());
|
||||||
|
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
s->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked());
|
s->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked());
|
||||||
@ -165,6 +166,7 @@ void MinecraftPage::loadSettings()
|
|||||||
ui->showGameTime->setChecked(s->get("ShowGameTime").toBool());
|
ui->showGameTime->setChecked(s->get("ShowGameTime").toBool());
|
||||||
ui->showGlobalGameTime->setChecked(s->get("ShowGlobalGameTime").toBool());
|
ui->showGlobalGameTime->setChecked(s->get("ShowGlobalGameTime").toBool());
|
||||||
ui->recordGameTime->setChecked(s->get("RecordGameTime").toBool());
|
ui->recordGameTime->setChecked(s->get("RecordGameTime").toBool());
|
||||||
|
ui->showGameTimeWithoutDays->setChecked(s->get("ShowGameTimeWithoutDays").toBool());
|
||||||
|
|
||||||
ui->closeAfterLaunchCheck->setChecked(s->get("CloseAfterLaunch").toBool());
|
ui->closeAfterLaunchCheck->setChecked(s->get("CloseAfterLaunch").toBool());
|
||||||
ui->quitAfterGameStopCheck->setChecked(s->get("QuitAfterGameStop").toBool());
|
ui->quitAfterGameStopCheck->setChecked(s->get("QuitAfterGameStop").toBool());
|
||||||
|
@ -138,6 +138,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="showGameTimeWithoutDays">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show time spent playing in hours</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user