Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a "Restart from Checkpoint" button #885

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/supertux/game_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ GameSession::update(float elapsed_time)
reset_button = false;
reset_level();
restart_level();
} else if(reset_checkpoint_button) {
reset_checkpoint_button = false;

PlayerStatus *player_status = currentsector->player->get_status();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe get_current_sector()->player->get_status();

player_status->coins -= std::max(player_status->coins/10, 25);

restart_level(true);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/supertux/game_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class GameSession : public Screen,
std::string get_working_directory() const;
int restart_level(bool after_death = false);
bool reset_button;
bool reset_checkpoint_button;

void toggle_pause();
void abort_level();
Expand Down
28 changes: 27 additions & 1 deletion src/supertux/menu/game_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#include "gui/menu_item.hpp"
#include "gui/menu_manager.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/game_session.hpp"
#include "supertux/game_session.hpp"
#include "supertux/level.hpp"
#include "supertux/menu/menu_storage.hpp"
#include "supertux/sector.hpp"
#include "util/gettext.hpp"

static const std::string CONFIRMATION_PROMPT = _("Are you sure?");
Expand All @@ -33,6 +34,12 @@ GameMenu::GameMenu() :
GameSession::current()->toggle_pause();
GameSession::current()->reset_button = true;
}),
reset_checkpoint_callback( [] {
MenuManager::instance().clear_menu_stack();
GameSession::current()->toggle_pause();

GameSession::current()->reset_checkpoint_button = true;
}),
abort_callback ( [] {
MenuManager::instance().clear_menu_stack();
GameSession::current()->abort_level();
Expand All @@ -44,6 +51,13 @@ GameMenu::GameMenu() :
add_hl();
add_entry(MNID_CONTINUE, _("Continue"));
add_entry(MNID_RESETLEVEL, _("Restart Level"));

if(Sector::current()->get_players()[0]->get_coins() >= 25 &&
!GameSession::current()->get_reset_point_sectorname().empty())
{
add_entry(MNID_RESETLEVELCHECKPOINT, _("Restart Level from Checkpoint"));
}

add_submenu(_("Options"), MenuStorage::INGAME_OPTIONS_MENU);
add_hl();
add_entry(MNID_ABORTLEVEL, _("Abort Level"));
Expand All @@ -70,6 +84,18 @@ GameMenu::menu_action(MenuItem& item)
}
break;

case MNID_RESETLEVELCHECKPOINT:
if (g_config->confirmation_dialog)
{
Dialog::show_confirmation(CONFIRMATION_PROMPT,
reset_checkpoint_callback);
}
else
{
reset_checkpoint_callback();
}
break;

case MNID_ABORTLEVEL:
if(g_config->confirmation_dialog)
{
Expand Down
3 changes: 3 additions & 0 deletions src/supertux/menu/game_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
enum GameMenuIDs {
MNID_CONTINUE,
MNID_RESETLEVEL,
MNID_RESETLEVELCHECKPOINT,
MNID_ABORTLEVEL
};

Expand All @@ -32,6 +33,8 @@ class GameMenu : public Menu
private:
// stores callback for level reset
std::function<void ()> reset_callback;
// stores callback for level reset from checkpoint
std::function<void ()> reset_checkpoint_callback;
// stores callback for level abort
std::function<void ()> abort_callback;
public:
Expand Down