Added total playtime

This commit is contained in:
Leland Liu 2019-07-09 22:23:24 -04:00 committed by Petr Mrázek
parent 8ea500de68
commit 1762d2fc7d
5 changed files with 43 additions and 2 deletions

1
.gitignore vendored
View File

@ -16,6 +16,7 @@ CMakeLists.txt.user.*
/.settings /.settings
/.idea /.idea
cmake-build-*/ cmake-build-*/
Debug
# Build dirs # Build dirs
build build

View File

@ -387,9 +387,19 @@ InstanceList::InstListError InstanceList::loadList()
add(newList); add(newList);
} }
m_dirty = false; m_dirty = false;
updateTotalPlayTime();
return NoError; return NoError;
} }
void InstanceList::updateTotalPlayTime()
{
totalPlayTime = 0;
for(auto const& itr : m_instances)
{
totalPlayTime += itr.get()->totalTimePlayed();
}
}
void InstanceList::saveNow() void InstanceList::saveNow()
{ {
for(auto & item: m_instances) for(auto & item: m_instances)
@ -475,6 +485,7 @@ void InstanceList::propertiesChanged(BaseInstance *inst)
if (i != -1) if (i != -1)
{ {
emit dataChanged(index(i), index(i)); emit dataChanged(index(i), index(i));
updateTotalPlayTime();
} }
} }
@ -848,4 +859,9 @@ bool InstanceList::destroyStagingPath(const QString& keyPath)
return FS::deletePath(keyPath); return FS::deletePath(keyPath);
} }
#include "InstanceList.moc" int InstanceList::getTotalPlayTime() {
updateTotalPlayTime();
return totalPlayTime;
}
#include "InstanceList.moc"

View File

@ -128,6 +128,8 @@ public:
*/ */
bool destroyStagingPath(const QString & keyPath); bool destroyStagingPath(const QString & keyPath);
int getTotalPlayTime();
signals: signals:
void dataIsInvalid(); void dataIsInvalid();
void instancesChanged(); void instancesChanged();
@ -145,6 +147,7 @@ private slots:
private: private:
int getInstIndex(BaseInstance *inst) const; int getInstIndex(BaseInstance *inst) const;
void updateTotalPlayTime();
void suspendWatch(); void suspendWatch();
void resumeWatch(); void resumeWatch();
void add(const QList<InstancePtr> &list); void add(const QList<InstancePtr> &list);
@ -155,6 +158,7 @@ private:
private: private:
int m_watchLevel = 0; int m_watchLevel = 0;
int totalPlayTime = 0;
bool m_dirty = false; bool m_dirty = false;
QList<InstancePtr> m_instances; QList<InstancePtr> m_instances;
QSet<QString> m_groupNameCache; QSet<QString> m_groupNameCache;

View File

@ -259,6 +259,7 @@ public:
actionAddInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Add a new instance.")); actionAddInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Add a new instance."));
all_actions.append(&actionAddInstance); all_actions.append(&actionAddInstance);
mainToolBar->addAction(actionAddInstance); mainToolBar->addAction(actionAddInstance);
actionAddInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "A"));
mainToolBar->addSeparator(); mainToolBar->addSeparator();
@ -724,8 +725,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
connect(MMC, &MultiMC::globalSettingsClosed, this, &MainWindow::globalSettingsClosed); connect(MMC, &MultiMC::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_statusRight = new ServerStatus(this); m_statusRight = new ServerStatus(this);
statusBar()->addPermanentWidget(m_statusLeft, 1); statusBar()->addPermanentWidget(m_statusLeft, 1);
statusBar()->addPermanentWidget(m_statusCenter, 1);
statusBar()->addPermanentWidget(m_statusRight, 0); statusBar()->addPermanentWidget(m_statusRight, 0);
// Add "manage accounts" button, right align // Add "manage accounts" button, right align
@ -1327,7 +1330,6 @@ void MainWindow::setCatBackground(bool enabled)
{ {
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0)); QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
;
QString cat = (non_stupid_abs(now.daysTo(xmas)) <= 4) ? "catmas" : "kitteh"; QString cat = (non_stupid_abs(now.daysTo(xmas)) <= 4) ? "catmas" : "kitteh";
view->setStyleSheet(QString(R"( view->setStyleSheet(QString(R"(
GroupView GroupView
@ -1526,6 +1528,7 @@ void MainWindow::setSelectedInstanceById(const QString &id)
{ {
QModelIndex selectionIndex = proxymodel->mapFromSource(index); QModelIndex selectionIndex = proxymodel->mapFromSource(index);
view->selectionModel()->setCurrentIndex(selectionIndex, QItemSelectionModel::ClearAndSelect); view->selectionModel()->setCurrentIndex(selectionIndex, QItemSelectionModel::ClearAndSelect);
updateStatusCenter();
} }
} }
@ -1854,6 +1857,7 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
ui->actionExportInstance->setEnabled(m_selectedInstance->canExport()); ui->actionExportInstance->setEnabled(m_selectedInstance->canExport());
ui->renameButton->setText(m_selectedInstance->name()); ui->renameButton->setText(m_selectedInstance->name());
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
updateStatusCenter();
updateInstanceToolIcon(m_selectedInstance->iconKey()); updateInstanceToolIcon(m_selectedInstance->iconKey());
updateToolsMenu(); updateToolsMenu();
@ -1932,3 +1936,17 @@ void MainWindow::checkInstancePathForProblems()
warning.exec(); warning.exec();
} }
} }
void MainWindow::updateStatusCenter()
{
int timeplayed = MMC->instances()->getTotalPlayTime();
int minutes = timeplayed / 60;
int hours = minutes / 60;
int seconds = timeplayed % 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));
}

View File

@ -194,6 +194,7 @@ private:
void setCatBackground(bool enabled); void setCatBackground(bool enabled);
void updateInstanceToolIcon(QString new_icon); void updateInstanceToolIcon(QString new_icon);
void setSelectedInstanceById(const QString &id); void setSelectedInstanceById(const QString &id);
void updateStatusCenter();
void runModalTask(Task *task); void runModalTask(Task *task);
void instanceFromInstanceTask(InstanceTask *task); void instanceFromInstanceTask(InstanceTask *task);
@ -207,6 +208,7 @@ private:
InstanceProxyModel *proxymodel = nullptr; InstanceProxyModel *proxymodel = nullptr;
QToolButton *newsLabel = nullptr; QToolButton *newsLabel = nullptr;
QLabel *m_statusLeft = nullptr; QLabel *m_statusLeft = nullptr;
QLabel *m_statusCenter = nullptr;
ServerStatus *m_statusRight = nullptr; ServerStatus *m_statusRight = nullptr;
QMenu *accountMenu = nullptr; QMenu *accountMenu = nullptr;
QToolButton *accountMenuButton = nullptr; QToolButton *accountMenuButton = nullptr;