diff --git a/src/frontend_common/play_time_manager.cpp b/src/frontend_common/play_time_manager.cpp index b506cd5ae0..782433392f 100644 --- a/src/frontend_common/play_time_manager.cpp +++ b/src/frontend_common/play_time_manager.cpp @@ -13,6 +13,9 @@ #include "core/hle/service/acc/profile_manager.h" #include "play_time_manager.h" +#include +#include + namespace PlayTime { namespace { @@ -164,4 +167,37 @@ void PlayTimeManager::ResetProgramPlayTime(u64 program_id) { Save(); } +std::string PlayTimeManager::GetReadablePlayTime(u64 time_seconds) { + if (time_seconds == 0) { + return {}; + } + + const auto time_minutes = std::max(static_cast(time_seconds) / 60.0, 1.0); + const auto time_hours = static_cast(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 diff --git a/src/frontend_common/play_time_manager.h b/src/frontend_common/play_time_manager.h index 1a46d17e1f..a99ccebb1e 100644 --- a/src/frontend_common/play_time_manager.h +++ b/src/frontend_common/play_time_manager.h @@ -38,6 +38,11 @@ public: void Start(); 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: void AutoTimestamp(std::stop_token stop_token); void Save(); diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 1edc01e540..f14b48a0c7 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -201,6 +201,8 @@ add_executable(yuzu precompiled_headers.h startup_checks.cpp startup_checks.h + set_play_time_dialog.cpp + set_play_time_dialog.h util/clickable_label.cpp util/clickable_label.h util/controller_navigation.cpp diff --git a/src/yuzu/game_list_p.h b/src/yuzu/game_list_p.h index 806fffc292..e22f920e3e 100644 --- a/src/yuzu/game_list_p.h +++ b/src/yuzu/game_list_p.h @@ -21,7 +21,7 @@ #include "common/common_types.h" #include "common/logging/log.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 "yuzu/util/util.h" @@ -241,7 +241,7 @@ public: void setData(const QVariant& value, int role) override { 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); }