Human-readable light source duration (feature #5091)

pull/2465/head
capostrophic 5 years ago
parent 1a2f51ef6f
commit 2affb8ed63

@ -149,6 +149,7 @@
Feature #5036: Allow scripted faction leaving
Feature #5046: Gamepad thumbstick cursor speed
Feature #5051: Provide a separate textures for scrollbars
Feature #5091: Human-readable light source duration
Feature #5094: Unix like console hotkeys
Task #4686: Upgrade media decoder to a more current FFmpeg API
Task #4695: Optimize Distant Terrain memory consumption

@ -156,13 +156,9 @@ namespace MWClass
std::string text;
if (Settings::Manager::getBool("show effect duration","Game"))
{
// -1 is infinite light source, so duration makes no sense here. Other negative values are treated as 0.
float remainingTime = ptr.getClass().getRemainingUsageTime(ptr);
if (remainingTime != -1.0f)
text += "\n#{sDuration}: " + MWGui::ToolTips::toString(std::max(0.f, remainingTime));
}
// Don't show duration for infinite light sources.
if (Settings::Manager::getBool("show effect duration","Game") && ptr.getClass().getRemainingUsageTime(ptr) != -1)
text += MWGui::ToolTips::getDurationString(ptr.getClass().getRemainingUsageTime(ptr), "\n#{sDuration}");
text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}");
text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}");

@ -137,27 +137,8 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->getGameSettingString("spoint", "") );
}
}
if (effectInfo.mRemainingTime > -1 &&
Settings::Manager::getBool("show effect duration","Game")) {
sourcesDescription += " #{sDuration}: ";
float duration = effectInfo.mRemainingTime;
if (duration > 3600)
{
int hour = duration / 3600;
duration -= hour*3600;
sourcesDescription += MWGui::ToolTips::toString(hour) + "h";
}
if (duration > 60)
{
int minute = duration / 60;
duration -= minute*60;
sourcesDescription += MWGui::ToolTips::toString(minute) + "m";
}
if (duration > 0.1)
{
sourcesDescription += MWGui::ToolTips::toString(duration) + "s";
}
}
if (effectInfo.mRemainingTime > -1 && Settings::Manager::getBool("show effect duration","Game"))
sourcesDescription += MWGui::ToolTips::getDurationString(effectInfo.mRemainingTime, " #{sDuration}");
addNewLine = true;
}

@ -667,6 +667,63 @@ namespace MWGui
return ret;
}
std::string ToolTips::getDurationString(float duration, const std::string& prefix)
{
std::string ret;
ret = prefix + ": ";
if (duration < 1.f)
{
ret += "0 s";
return ret;
}
constexpr float secondsPerMinute = 60.f; // 60 seconds
constexpr float secondsPerHour = secondsPerMinute * 60.f; // 60 minutes
constexpr float secondsPerDay = secondsPerHour * 24.f; // 24 hours
constexpr float secondsPerMonth = secondsPerDay * 30.f; // 30 days
constexpr float secondsPerYear = secondsPerDay * 365.f;
int units = 0;
if (duration >= secondsPerYear)
{
units++;
int years = duration / secondsPerYear;
duration -= years * secondsPerYear;
ret += toString(years) + " y ";
}
if (duration >= secondsPerMonth)
{
units++;
int months = duration / secondsPerMonth;
duration -= months * secondsPerMonth;
ret += toString(months) + " mo ";
}
if (units < 2 && duration >= secondsPerDay)
{
units++;
int days = duration / secondsPerDay;
duration -= days * secondsPerDay;
ret += toString(days) + " d ";
}
if (units < 2 && duration >= secondsPerHour)
{
units++;
int hours = duration / secondsPerHour;
duration -= hours * secondsPerHour;
ret += toString(hours) + " h ";
}
if (units < 2 && duration >= secondsPerMinute)
{
int minutes = duration / secondsPerMinute;
duration -= minutes * secondsPerMinute;
ret += toString(minutes) + " min ";
}
if (units < 2 && duration >= 1.f)
ret += toString(int(duration)) + " s ";
return ret;
}
bool ToolTips::toggleFullHelp()
{
mFullHelp = !mFullHelp;

@ -84,6 +84,9 @@ namespace MWGui
static std::string getCellRefString(const MWWorld::CellRef& cellref);
///< Returns a string containing debug tooltip information about the given cellref.
static std::string getDurationString (float duration, const std::string& prefix);
///< Returns duration as two largest time units, rounded down. Note: not localized; no line break.
// these do not create an actual tooltip, but they fill in the data that is required so the tooltip
// system knows what to show in case this widget is hovered
static void createSkillToolTip(MyGUI::Widget* widget, int skillId);

Loading…
Cancel
Save