Skip to content

Commit

Permalink
Merge branch 'timeplayedhours' into 'master'
Browse files Browse the repository at this point in the history
Improve Time Played formatting (#7971)

Closes #7971

See merge request OpenMW/openmw!4107
  • Loading branch information
psi29a committed May 20, 2024
2 parents a3bfd3a + 6bf0d17 commit d67bc1d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
Feature #7936: Scalable icons in Qt applications
Feature #7953: Allow to change SVG icons colors depending on color scheme
Feature #7964: Add Lua read access to MW Dialogue records
Feature #7971: Make save's Time Played value display hours instead of days
Task #5896: Do not use deprecated MyGUI properties
Task #6085: Replace boost::filesystem with std::filesystem
Task #6149: Dehardcode Lua API_REVISION
Expand Down
43 changes: 22 additions & 21 deletions apps/openmw/mwgui/savegamedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@
#include <osgDB/ReadFile>

#include <components/debug/debuglog.hpp>

#include <components/myguiplatform/myguitexture.hpp>

#include <components/misc/strings/lower.hpp>

#include <components/settings/values.hpp>

#include <components/esm3/loadclas.hpp>
#include <components/files/conversion.hpp>
#include <components/files/memorystream.hpp>
#include <components/l10n/manager.hpp>
#include <components/misc/strings/lower.hpp>
#include <components/misc/timeconvert.hpp>

#include <components/esm3/loadclas.hpp>
#include <components/myguiplatform/myguitexture.hpp>
#include <components/settings/values.hpp>

#include "../mwbase/environment.hpp"
#include "../mwbase/statemanager.hpp"
Expand Down Expand Up @@ -367,18 +363,23 @@ namespace MWGui

std::string formatTimeplayed(const double timeInSeconds)
{
int timePlayed = (int)floor(timeInSeconds);
int days = timePlayed / 60 / 60 / 24;
int hours = (timePlayed / 60 / 60) % 24;
int minutes = (timePlayed / 60) % 60;
int seconds = timePlayed % 60;

std::stringstream stream;
stream << std::setfill('0') << std::setw(2) << days << ":";
stream << std::setfill('0') << std::setw(2) << hours << ":";
stream << std::setfill('0') << std::setw(2) << minutes << ":";
stream << std::setfill('0') << std::setw(2) << seconds;
return stream.str();
auto l10n = MWBase::Environment::get().getL10nManager()->getContext("Interface");
int duration = static_cast<int>(timeInSeconds);
if (duration <= 0)
return l10n->formatMessage("DurationSecond", { "seconds" }, { 0 });

std::string result;
int hours = duration / 3600;
int minutes = (duration / 60) % 60;
int seconds = duration % 60;
if (hours)
result += l10n->formatMessage("DurationHour", { "hours" }, { hours });
if (minutes)
result += l10n->formatMessage("DurationMinute", { "minutes" }, { minutes });
if (seconds)
result += l10n->formatMessage("DurationSecond", { "seconds" }, { seconds });

return result;
}

void SaveGameDialog::onSlotSelected(MyGUI::ListBox* sender, size_t pos)
Expand Down

0 comments on commit d67bc1d

Please sign in to comment.