[core, android] Initial playtime implementation #2535
4 changed files with 45 additions and 2 deletions
|
@ -13,6 +13,9 @@
|
||||||
#include "core/hle/service/acc/profile_manager.h"
|
#include "core/hle/service/acc/profile_manager.h"
|
||||||
#include "play_time_manager.h"
|
#include "play_time_manager.h"
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace PlayTime {
|
namespace PlayTime {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -164,4 +167,37 @@ void PlayTimeManager::ResetProgramPlayTime(u64 program_id) {
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string PlayTimeManager::GetReadablePlayTime(u64 time_seconds) {
|
||||||
|
if (time_seconds == 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto time_minutes = std::max(static_cast<double>(time_seconds) / 60.0, 1.0);
|
||||||
|
const auto time_hours = static_cast<double>(time_seconds) / 3600.0;
|
||||||
|
const bool is_minutes = time_minutes < 60.0;
|
||||||
|
|
||||||
|
if (is_minutes) {
|
||||||
|
return fmt::format("{:.0f} m", time_minutes);
|
||||||
|
} else {
|
||||||
|
const bool has_remainder = time_seconds % 60 != 0;
|
||||||
|
if (has_remainder) {
|
||||||
|
return fmt::format("{:.1f} h", time_hours);
|
||||||
|
} else {
|
||||||
|
return fmt::format("{:.0f} h", time_hours);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PlayTimeManager::GetPlayTimeHours(u64 time_seconds) {
|
||||||
|
return fmt::format("{}", time_seconds / 3600);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PlayTimeManager::GetPlayTimeMinutes(u64 time_seconds) {
|
||||||
|
return fmt::format("{}", (time_seconds % 3600) / 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PlayTimeManager::GetPlayTimeSeconds(u64 time_seconds) {
|
||||||
|
return fmt::format("{}", time_seconds % 60);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace PlayTime
|
} // namespace PlayTime
|
||||||
|
|
|
@ -38,6 +38,11 @@ public:
|
||||||
void Start();
|
void Start();
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
|
static std::string GetReadablePlayTime(u64 time_seconds);
|
||||||
|
static std::string GetPlayTimeHours(u64 time_seconds);
|
||||||
|
static std::string GetPlayTimeMinutes(u64 time_seconds);
|
||||||
|
static std::string GetPlayTimeSeconds(u64 time_seconds);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AutoTimestamp(std::stop_token stop_token);
|
void AutoTimestamp(std::stop_token stop_token);
|
||||||
void Save();
|
void Save();
|
||||||
|
|
|
@ -201,6 +201,8 @@ add_executable(yuzu
|
||||||
precompiled_headers.h
|
precompiled_headers.h
|
||||||
startup_checks.cpp
|
startup_checks.cpp
|
||||||
startup_checks.h
|
startup_checks.h
|
||||||
|
set_play_time_dialog.cpp
|
||||||
|
set_play_time_dialog.h
|
||||||
util/clickable_label.cpp
|
util/clickable_label.cpp
|
||||||
util/clickable_label.h
|
util/clickable_label.h
|
||||||
util/controller_navigation.cpp
|
util/controller_navigation.cpp
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
#include "qt_common/qt_playtime_manager.h"
|
#include "frontend_common/play_time_manager.h"
|
||||||
#include "qt_common/uisettings.h"
|
#include "qt_common/uisettings.h"
|
||||||
#include "yuzu/util/util.h"
|
#include "yuzu/util/util.h"
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ public:
|
||||||
|
|
||||||
void setData(const QVariant& value, int role) override {
|
void setData(const QVariant& value, int role) override {
|
||||||
qulonglong time_seconds = value.toULongLong();
|
qulonglong time_seconds = value.toULongLong();
|
||||||
GameListItem::setData(QtCommon::PlayTimeManager::ReadablePlayTime(time_seconds), Qt::DisplayRole);
|
GameListItem::setData(QString::fromStdString(PlayTime::PlayTimeManager::GetReadablePlayTime(time_seconds)), Qt::DisplayRole);
|
||||||
GameListItem::setData(value, PlayTimeRole);
|
GameListItem::setData(value, PlayTimeRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue