mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2024-12-24 12:14:30 +00:00
Added total playtime
This commit is contained in:
parent
8ea500de68
commit
1762d2fc7d
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,6 +16,7 @@ CMakeLists.txt.user.*
|
||||
/.settings
|
||||
/.idea
|
||||
cmake-build-*/
|
||||
Debug
|
||||
|
||||
# Build dirs
|
||||
build
|
||||
|
@ -387,9 +387,19 @@ InstanceList::InstListError InstanceList::loadList()
|
||||
add(newList);
|
||||
}
|
||||
m_dirty = false;
|
||||
updateTotalPlayTime();
|
||||
return NoError;
|
||||
}
|
||||
|
||||
void InstanceList::updateTotalPlayTime()
|
||||
{
|
||||
totalPlayTime = 0;
|
||||
for(auto const& itr : m_instances)
|
||||
{
|
||||
totalPlayTime += itr.get()->totalTimePlayed();
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceList::saveNow()
|
||||
{
|
||||
for(auto & item: m_instances)
|
||||
@ -475,6 +485,7 @@ void InstanceList::propertiesChanged(BaseInstance *inst)
|
||||
if (i != -1)
|
||||
{
|
||||
emit dataChanged(index(i), index(i));
|
||||
updateTotalPlayTime();
|
||||
}
|
||||
}
|
||||
|
||||
@ -848,4 +859,9 @@ bool InstanceList::destroyStagingPath(const QString& keyPath)
|
||||
return FS::deletePath(keyPath);
|
||||
}
|
||||
|
||||
int InstanceList::getTotalPlayTime() {
|
||||
updateTotalPlayTime();
|
||||
return totalPlayTime;
|
||||
}
|
||||
|
||||
#include "InstanceList.moc"
|
@ -128,6 +128,8 @@ public:
|
||||
*/
|
||||
bool destroyStagingPath(const QString & keyPath);
|
||||
|
||||
int getTotalPlayTime();
|
||||
|
||||
signals:
|
||||
void dataIsInvalid();
|
||||
void instancesChanged();
|
||||
@ -145,6 +147,7 @@ private slots:
|
||||
|
||||
private:
|
||||
int getInstIndex(BaseInstance *inst) const;
|
||||
void updateTotalPlayTime();
|
||||
void suspendWatch();
|
||||
void resumeWatch();
|
||||
void add(const QList<InstancePtr> &list);
|
||||
@ -155,6 +158,7 @@ private:
|
||||
|
||||
private:
|
||||
int m_watchLevel = 0;
|
||||
int totalPlayTime = 0;
|
||||
bool m_dirty = false;
|
||||
QList<InstancePtr> m_instances;
|
||||
QSet<QString> m_groupNameCache;
|
||||
|
@ -259,6 +259,7 @@ public:
|
||||
actionAddInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Add a new instance."));
|
||||
all_actions.append(&actionAddInstance);
|
||||
mainToolBar->addAction(actionAddInstance);
|
||||
actionAddInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "A"));
|
||||
|
||||
mainToolBar->addSeparator();
|
||||
|
||||
@ -724,8 +725,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
||||
connect(MMC, &MultiMC::globalSettingsClosed, this, &MainWindow::globalSettingsClosed);
|
||||
|
||||
m_statusLeft = new QLabel(tr("No instance selected"), this);
|
||||
m_statusCenter = new QLabel(tr("Total playtime: 0s."), this);
|
||||
m_statusRight = new ServerStatus(this);
|
||||
statusBar()->addPermanentWidget(m_statusLeft, 1);
|
||||
statusBar()->addPermanentWidget(m_statusCenter, 1);
|
||||
statusBar()->addPermanentWidget(m_statusRight, 0);
|
||||
|
||||
// Add "manage accounts" button, right align
|
||||
@ -1327,7 +1330,6 @@ void MainWindow::setCatBackground(bool enabled)
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
|
||||
;
|
||||
QString cat = (non_stupid_abs(now.daysTo(xmas)) <= 4) ? "catmas" : "kitteh";
|
||||
view->setStyleSheet(QString(R"(
|
||||
GroupView
|
||||
@ -1526,6 +1528,7 @@ void MainWindow::setSelectedInstanceById(const QString &id)
|
||||
{
|
||||
QModelIndex selectionIndex = proxymodel->mapFromSource(index);
|
||||
view->selectionModel()->setCurrentIndex(selectionIndex, QItemSelectionModel::ClearAndSelect);
|
||||
updateStatusCenter();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1854,6 +1857,7 @@ void MainWindow::instanceChanged(const QModelIndex ¤t, const QModelIndex &
|
||||
ui->actionExportInstance->setEnabled(m_selectedInstance->canExport());
|
||||
ui->renameButton->setText(m_selectedInstance->name());
|
||||
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
|
||||
updateStatusCenter();
|
||||
updateInstanceToolIcon(m_selectedInstance->iconKey());
|
||||
|
||||
updateToolsMenu();
|
||||
@ -1932,3 +1936,17 @@ void MainWindow::checkInstancePathForProblems()
|
||||
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));
|
||||
}
|
||||
|
@ -194,6 +194,7 @@ private:
|
||||
void setCatBackground(bool enabled);
|
||||
void updateInstanceToolIcon(QString new_icon);
|
||||
void setSelectedInstanceById(const QString &id);
|
||||
void updateStatusCenter();
|
||||
|
||||
void runModalTask(Task *task);
|
||||
void instanceFromInstanceTask(InstanceTask *task);
|
||||
@ -207,6 +208,7 @@ private:
|
||||
InstanceProxyModel *proxymodel = nullptr;
|
||||
QToolButton *newsLabel = nullptr;
|
||||
QLabel *m_statusLeft = nullptr;
|
||||
QLabel *m_statusCenter = nullptr;
|
||||
ServerStatus *m_statusRight = nullptr;
|
||||
QMenu *accountMenu = nullptr;
|
||||
QToolButton *accountMenuButton = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user