GH-3450 Add checkboxes to display and record game time

This commit is contained in:
Joël Troch 2020-12-09 23:16:01 +01:00
parent 3d11f9a7e9
commit de089195cd
7 changed files with 119 additions and 1 deletions

View File

@ -134,6 +134,12 @@ void BaseInstance::setRunning(bool running)
m_isRunning = running; m_isRunning = running;
if(!m_settings->get("RecordGameTime").toBool())
{
emit runningStatusChanged(running);
return;
}
if(running) if(running)
{ {
m_timeStarted = QDateTime::currentDateTime(); m_timeStarted = QDateTime::currentDateTime();

View File

@ -106,6 +106,11 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO
m_settings->registerOverride(globalSettings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride); m_settings->registerOverride(globalSettings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride);
m_settings->registerOverride(globalSettings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride); m_settings->registerOverride(globalSettings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride);
// Game time
auto gameTimeOverride = m_settings->registerSetting("OverrideGameTime", false);
m_settings->registerOverride(globalSettings->getSetting("ShowGameTime"), gameTimeOverride);
m_settings->registerOverride(globalSettings->getSetting("RecordGameTime"), gameTimeOverride);
// DEPRECATED: Read what versions the user configuration thinks should be used // DEPRECATED: Read what versions the user configuration thinks should be used
m_settings->registerSetting({"IntendedVersion", "MinecraftVersion"}, ""); m_settings->registerSetting({"IntendedVersion", "MinecraftVersion"}, "");
m_settings->registerSetting("LWJGLVersion", ""); m_settings->registerSetting("LWJGLVersion", "");
@ -769,7 +774,7 @@ QString MinecraftInstance::getStatusbarDescription()
QString description; QString description;
description.append(tr("Minecraft %1 (%2)").arg(m_components->getComponentVersion("net.minecraft")).arg(typeName())); description.append(tr("Minecraft %1 (%2)").arg(m_components->getComponentVersion("net.minecraft")).arg(typeName()));
if(totalTimePlayed() > 0) if(m_settings->get("ShowGameTime").toBool() && totalTimePlayed() > 0)
{ {
description.append(tr(", played for %1").arg(prettifyTimeDuration(totalTimePlayed()))); description.append(tr(", played for %1").arg(prettifyTimeDuration(totalTimePlayed())));
} }

View File

@ -514,6 +514,10 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
m_settings->registerSetting("UseNativeOpenAL", false); m_settings->registerSetting("UseNativeOpenAL", false);
m_settings->registerSetting("UseNativeGLFW", false); m_settings->registerSetting("UseNativeGLFW", false);
// Game time
m_settings->registerSetting("ShowGameTime", true);
m_settings->registerSetting("RecordGameTime", true);
// Minecraft launch method // Minecraft launch method
m_settings->registerSetting("MCLaunchMethod", "LauncherPart"); m_settings->registerSetting("MCLaunchMethod", "LauncherPart");

View File

@ -67,6 +67,10 @@ void MinecraftPage::applySettings()
// Native library workarounds // Native library workarounds
s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked()); s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
s->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked()); s->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked());
// Game time
s->set("ShowGameTime", ui->showGameTime->isChecked());
s->set("RecordGameTime", ui->recordGameTime->isChecked());
} }
void MinecraftPage::loadSettings() void MinecraftPage::loadSettings()
@ -80,4 +84,7 @@ void MinecraftPage::loadSettings()
ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool()); ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool());
ui->useNativeGLFWCheck->setChecked(s->get("UseNativeGLFW").toBool()); ui->useNativeGLFWCheck->setChecked(s->get("UseNativeGLFW").toBool());
ui->showGameTime->setChecked(s->get("ShowGameTime").toBool());
ui->recordGameTime->setChecked(s->get("RecordGameTime").toBool());
} }

View File

@ -134,6 +134,29 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="gameTimeGroupBox">
<property name="title">
<string>Game time</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QCheckBox" name="showGameTime">
<property name="text">
<string>Show time spent playing instances</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="recordGameTime">
<property name="text">
<string>Record time spent playing instances</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacerMinecraft"> <spacer name="verticalSpacerMinecraft">
<property name="orientation"> <property name="orientation">

View File

@ -177,6 +177,20 @@ void InstanceSettingsPage::applySettings()
m_settings->reset("UseNativeOpenAL"); m_settings->reset("UseNativeOpenAL");
m_settings->reset("UseNativeGLFW"); m_settings->reset("UseNativeGLFW");
} }
// Game time
bool gameTime = ui->gameTimeGroupBox->isChecked();
m_settings->set("OverrideGameTime", gameTime);
if (gameTime)
{
m_settings->set("ShowGameTime", ui->showGameTime->isChecked());
m_settings->set("RecordGameTime", ui->recordGameTime->isChecked());
}
else
{
m_settings->reset("ShowGameTime");
m_settings->reset("RecordGameTime");
}
} }
void InstanceSettingsPage::loadSettings() void InstanceSettingsPage::loadSettings()
@ -238,6 +252,11 @@ void InstanceSettingsPage::loadSettings()
ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool()); ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool());
ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool()); ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool());
ui->useNativeOpenALCheck->setChecked(m_settings->get("UseNativeOpenAL").toBool()); ui->useNativeOpenALCheck->setChecked(m_settings->get("UseNativeOpenAL").toBool());
// Miscellanous
ui->gameTimeGroupBox->setChecked(m_settings->get("OverrideGameTime").toBool());
ui->showGameTime->setChecked(m_settings->get("ShowGameTime").toBool());
ui->recordGameTime->setChecked(m_settings->get("RecordGameTime").toBool());
} }
void InstanceSettingsPage::on_javaDetectBtn_clicked() void InstanceSettingsPage::on_javaDetectBtn_clicked()

View File

@ -416,6 +416,58 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="miscellanousPage">
<attribute name="title">
<string>Miscellanous</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QGroupBox" name="gameTimeGroupBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Override global game time settings</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QCheckBox" name="showGameTime">
<property name="text">
<string>Show time spent playing this instance</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="recordGameTime">
<property name="text">
<string>Record time spent playing this instance</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacerMiscellanous">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -453,6 +505,8 @@
<tabstop>nativeWorkaroundsGroupBox</tabstop> <tabstop>nativeWorkaroundsGroupBox</tabstop>
<tabstop>useNativeGLFWCheck</tabstop> <tabstop>useNativeGLFWCheck</tabstop>
<tabstop>useNativeOpenALCheck</tabstop> <tabstop>useNativeOpenALCheck</tabstop>
<tabstop>showGameTime</tabstop>
<tabstop>recordGameTime</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>