Fix & Improve the remaining-time alert

- Fix a bug that prevented the alert sound from playing in timed Story Mode challenges.
- Extend the visual alert (colored time) to the last 15 seconds (previously 5). The sound alert remains limited to the last 5 seconds.
- Switch from yellow to orange for the timer when 5 seconds are left and the sound alert starts playing.
- Significant code simplification (tested for non-regression in soccer, FFA, story mode timed challenge)
This commit is contained in:
Alayan 2021-09-09 21:06:02 +02:00
parent 9a4fe66dc7
commit 79965ef462
2 changed files with 28 additions and 43 deletions

View File

@ -947,25 +947,16 @@ void World::updateTimeTargetSound()
{
if (RaceManager::get()->hasTimeTarget() && !RewindManager::get()->isRewinding())
{
float time_elapsed = getTime();
float time_left = getTime();
float time_target = RaceManager::get()->getTimeTarget();
if (RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_SOCCER ||
RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_FREE_FOR_ALL ||
RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_CAPTURE_THE_FLAG)
// In linear mode, the internal time still counts up even when displayed down.
if (RaceManager::get()->isLinearRaceMode())
time_left = time_target - time_left;
if (time_left <= 5 && getTimeTicks() % stk_config->time2Ticks(1.0f) == 0 &&
!World::getWorld()->isRaceOver() && time_left > 0)
{
if (time_elapsed <= 5 && getTimeTicks() % stk_config->time2Ticks(1.0f) == 0 &&
!World::getWorld()->isRaceOver() && time_elapsed > 0)
{
SFXManager::get()->quickSound("pre_start_race");
}
}
else
{
if (time_target - time_elapsed <= 5 && stk_config->time2Ticks(1.0f) == 0 &&
time_target - time_elapsed > 0)
{
SFXManager::get()->quickSound("pre_start_race");
}
}
}
} // updateTimeTargetSound

View File

@ -425,41 +425,35 @@ void RaceGUI::drawGlobalTimer()
bool use_digit_font = true;
float elapsed_time = World::getWorld()->getTime();
if (!RaceManager::get()->hasTimeTarget() ||
RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_SOCCER ||
RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_FREE_FOR_ALL ||
RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_CAPTURE_THE_FLAG)
{
sw = core::stringw (
StringUtils::timeToString(elapsed_time).c_str() );
}
else
// In linear mode with a time target, the internal time
// still counts up but needs to be displayed down.
if (RaceManager::get()->hasTimeTarget() &&
RaceManager::get()->isLinearRaceMode())
{
float time_target = RaceManager::get()->getTimeTarget();
if (elapsed_time < time_target)
elapsed_time = time_target - elapsed_time;
}
sw = core::stringw (StringUtils::timeToString(elapsed_time).c_str() );
if (RaceManager::get()->hasTimeTarget())
{
// This assumes only challenges have a time target
// and don't end the race when reaching the target.
if (elapsed_time < 0)
{
if(time_target-elapsed_time <= 5)
time_color = video::SColor(255,255,255,0);
sw = core::stringw (
StringUtils::timeToString(time_target - elapsed_time).c_str());
}
else
{
sw = _("Challenge Failed");
int string_width =
GUIEngine::getFont()->getDimension(sw.c_str()).Width;
sw = _("Challenge Failed"); // We just overwrite the default case
int string_width = GUIEngine::getFont()->getDimension(sw.c_str()).Width;
dist_from_right = 10 + string_width;
time_color = video::SColor(255,255,0,0);
use_digit_font = false;
}
}
if(elapsed_time <= 5 && RaceManager::get()->hasTimeTarget() && (RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_SOCCER ||
RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_FREE_FOR_ALL ||
RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_CAPTURE_THE_FLAG))
{
time_color = video::SColor(255,255,255,0);
else if (elapsed_time <= 5)
time_color = video::SColor(255,255,160,0);
else if (elapsed_time <= 15)
time_color = video::SColor(255,255,255,0);
}
core::rect<s32> pos(irr_driver->getActualScreenSize().Width - dist_from_right,
irr_driver->getActualScreenSize().Height*2/100,
irr_driver->getActualScreenSize().Width,