Skip to content

Commit

Permalink
Adapt the end screen in benchmark mode (part 1)
Browse files Browse the repository at this point in the history
- Customize the race result screen to offer three options : leave to main menu, save test data, and return to video settings
- Ensure all three options do as they say
- Ensure that the benchmark mode and the profiler are always turned off when leaving through the end screen
  • Loading branch information
Alayan-stk-2 committed Apr 26, 2024
1 parent e68acaa commit 62d0281
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/modes/world_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ void WorldStatus::updateTime(int ticks)
{
// End profiling
profiler.desactivate();
profiler.writeToFile();
profiler.setDrawing(true);
}
terminateRace();
Expand Down
46 changes: 46 additions & 0 deletions src/states_screens/race_result_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@
#include "states_screens/feature_unlocked.hpp"
#include "states_screens/main_menu_screen.hpp"
#include "states_screens/online/networking_lobby.hpp"
#include "states_screens/options/options_screen_video.hpp"
#include "states_screens/race_setup_screen.hpp"
#include "tips/tips_manager.hpp"
#include "tracks/track.hpp"
#include "tracks/track_manager.hpp"
#include "utils/profiler.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"

Expand Down Expand Up @@ -258,6 +260,23 @@ void RaceResultGUI::enableAllButtons()
enableGPProgress();
}

// In benchmark mode, offer three options : saving the results to a file,
// going back to the main menu, and going back to the video options
if (RaceManager::get()->isBenchmarking())
{
right->setLabel(_("Back to video settings"));
right->setImage("gui/icons/main_options.png");
right->setVisible(true);
operations->select("right", PLAYER_ID_GAME_MASTER);
middle->setLabel(_("Save the test results"));
middle->setImage("gui/icons/blue_arrow.png");
middle->setVisible(true);
left->setLabel(_("Back to main menu"));
left->setImage("gui/icons/back.png");
left->setVisible(true);
return;
}

// If we're in a network world, change the buttons text
if (World::getWorld()->isNetworkWorld())
{
Expand Down Expand Up @@ -546,6 +565,29 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
return;
}

if (RaceManager::get()->isBenchmarking())
{
if (action == "middle") // Save benchmark results
{
profiler.writeToFile();
}
else // Leave to menu or video settings
{
// Turn off benchmark mode and leave
RaceManager::get()->setBenchmarking(false);
RaceManager::get()->exitRace();
RaceManager::get()->setAIKartOverride("");

// We first go the main menu in both situations, because the back button
// in the settings will not work as expected otherwise.
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
// If the video settings is requested, we then immediately go there
if (action == "right")
OptionsScreenVideo::getInstance()->push();
}
return;
}

StateManager::get()->popMenu();
if (action == "right") // Restart
{
Expand Down Expand Up @@ -596,6 +638,10 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
}
else if (action == "left") // Back to main
{
// If benchmarking, turn off benchmark mode
if (RaceManager::get()->isBenchmarking())
RaceManager::get()->setBenchmarking(false);

RaceManager::get()->exitRace();
RaceManager::get()->setAIKartOverride("");
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
Expand Down

0 comments on commit 62d0281

Please sign in to comment.