mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Implemented #714 — restart functionality, including quick restart tweak (bound to CTRL+R).
This commit is contained in:
parent
d6223dd137
commit
d9064f4f7d
@ -1484,6 +1484,14 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
|
||||
if(isActive())
|
||||
LOCPLINT->showPuzzleMap();
|
||||
return;
|
||||
case SDLK_r:
|
||||
if(isActive() && LOCPLINT->ctrlPressed())
|
||||
{
|
||||
LOCPLINT->showYesNoDialog("Are you sure you want to restart game?", std::vector<CComponent*>(),
|
||||
[]{ LOCPLINT->sendCustomEvent(RESTART_GAME); },
|
||||
[]{}, true);
|
||||
}
|
||||
return;
|
||||
case SDLK_SPACE: //space - try to revisit current object with selected hero
|
||||
{
|
||||
if(!isActive())
|
||||
|
@ -709,8 +709,7 @@ static void listenForEvents()
|
||||
}
|
||||
case RETURN_TO_MAIN_MENU:
|
||||
client->endGame();
|
||||
delete client;
|
||||
client = NULL;
|
||||
vstd::clear_pointer(client);
|
||||
|
||||
delete CGI->dobjinfo.get();
|
||||
const_cast<CGameInfo*>(CGI)->dobjinfo = new CDefObjInfoHandler;
|
||||
@ -723,6 +722,19 @@ static void listenForEvents()
|
||||
case STOP_CLIENT:
|
||||
client->endGame(false);
|
||||
break;
|
||||
case RESTART_GAME:
|
||||
{
|
||||
StartInfo si = *client->getStartInfo();
|
||||
client->endGame();
|
||||
vstd::clear_pointer(client);
|
||||
|
||||
delete CGI->dobjinfo.get();
|
||||
const_cast<CGameInfo*>(CGI)->dobjinfo = new CDefObjInfoHandler;
|
||||
const_cast<CGameInfo*>(CGI)->dobjinfo->load();
|
||||
|
||||
startGame(&si);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
tlog1 << "Error: unknown user event. Code " << ev->user.code << std::endl;
|
||||
assert(0);
|
||||
|
@ -71,7 +71,7 @@ namespace boost
|
||||
class recursive_mutex;
|
||||
};
|
||||
|
||||
enum {CHANGE_SCREEN_RESOLUTION = 1, RETURN_TO_MAIN_MENU = 2, STOP_CLIENT = 3};
|
||||
enum {CHANGE_SCREEN_RESOLUTION = 1, RETURN_TO_MAIN_MENU = 2, STOP_CLIENT = 3, RESTART_GAME};
|
||||
|
||||
/// Central class for managing user interface logic
|
||||
class CPlayerInterface : public CGameInterface, public IUpdateable
|
||||
|
@ -3684,7 +3684,10 @@ CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &Pos, CPlayerInterface
|
||||
save->swappedImages = true;
|
||||
save->update();
|
||||
|
||||
// restart = new CAdventureMapButton (CGI->generaltexth->zelp[323].first, CGI->generaltexth->zelp[323].second, boost::bind(&CSystemOptionsWindow::bmainmenuf, this), pos.x+346, pos.y+357, "SORSTRT", SDLK_r);
|
||||
restart = new CAdventureMapButton (CGI->generaltexth->zelp[323].first, CGI->generaltexth->zelp[323].second,
|
||||
boost::bind(&CSystemOptionsWindow::brestartf, this), 246, 357, "SORSTRT", SDLK_r);
|
||||
restart->swappedImages = true;
|
||||
restart->update();
|
||||
|
||||
mainMenu = new CAdventureMapButton (CGI->generaltexth->zelp[320].first, CGI->generaltexth->zelp[320].second,
|
||||
boost::bind(&CSystemOptionsWindow::bmainmenuf, this), 357, 357, "SOMAIN.DEF", SDLK_m);
|
||||
@ -3821,7 +3824,7 @@ void CSystemOptionsWindow::breturnf()
|
||||
|
||||
void CSystemOptionsWindow::bmainmenuf()
|
||||
{
|
||||
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector<CComponent*>(), boost::bind(&CSystemOptionsWindow::pushSDLEvent, this, SDL_USEREVENT, 2), 0, false);
|
||||
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector<CComponent*>(), boost::bind(&CSystemOptionsWindow::pushSDLEvent, this, SDL_USEREVENT, RETURN_TO_MAIN_MENU), 0, false);
|
||||
}
|
||||
|
||||
void CSystemOptionsWindow::bsavef()
|
||||
@ -3830,6 +3833,11 @@ void CSystemOptionsWindow::bsavef()
|
||||
GH.pushInt(new CSavingScreen(CPlayerInterface::howManyPeople > 1));
|
||||
}
|
||||
|
||||
void CSystemOptionsWindow::brestartf()
|
||||
{
|
||||
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector<CComponent*>(), boost::bind(&CSystemOptionsWindow::pushSDLEvent, this, SDL_USEREVENT, RESTART_GAME), 0, false);
|
||||
}
|
||||
|
||||
CTavernWindow::CTavernWindow(const CGObjectInstance *TavernObj)
|
||||
: tavernObj(TavernObj)
|
||||
{
|
||||
|
@ -682,6 +682,7 @@ private:
|
||||
void bsavef(); //save game
|
||||
void bquitf(); //quit game
|
||||
void breturnf(); //return to game
|
||||
void brestartf(); //return to game
|
||||
void bmainmenuf(); //return to main menu
|
||||
|
||||
//functions for checkboxes
|
||||
|
Loading…
Reference in New Issue
Block a user