mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-17 00:07:41 +02:00
Implemented #714 — restart functionality, including quick restart tweak (bound to CTRL+R).
This commit is contained in:
@ -1484,6 +1484,14 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
|
|||||||
if(isActive())
|
if(isActive())
|
||||||
LOCPLINT->showPuzzleMap();
|
LOCPLINT->showPuzzleMap();
|
||||||
return;
|
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
|
case SDLK_SPACE: //space - try to revisit current object with selected hero
|
||||||
{
|
{
|
||||||
if(!isActive())
|
if(!isActive())
|
||||||
|
@ -709,8 +709,7 @@ static void listenForEvents()
|
|||||||
}
|
}
|
||||||
case RETURN_TO_MAIN_MENU:
|
case RETURN_TO_MAIN_MENU:
|
||||||
client->endGame();
|
client->endGame();
|
||||||
delete client;
|
vstd::clear_pointer(client);
|
||||||
client = NULL;
|
|
||||||
|
|
||||||
delete CGI->dobjinfo.get();
|
delete CGI->dobjinfo.get();
|
||||||
const_cast<CGameInfo*>(CGI)->dobjinfo = new CDefObjInfoHandler;
|
const_cast<CGameInfo*>(CGI)->dobjinfo = new CDefObjInfoHandler;
|
||||||
@ -723,6 +722,19 @@ static void listenForEvents()
|
|||||||
case STOP_CLIENT:
|
case STOP_CLIENT:
|
||||||
client->endGame(false);
|
client->endGame(false);
|
||||||
break;
|
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:
|
default:
|
||||||
tlog1 << "Error: unknown user event. Code " << ev->user.code << std::endl;
|
tlog1 << "Error: unknown user event. Code " << ev->user.code << std::endl;
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -71,7 +71,7 @@ namespace boost
|
|||||||
class recursive_mutex;
|
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
|
/// Central class for managing user interface logic
|
||||||
class CPlayerInterface : public CGameInterface, public IUpdateable
|
class CPlayerInterface : public CGameInterface, public IUpdateable
|
||||||
|
@ -3684,7 +3684,10 @@ CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &Pos, CPlayerInterface
|
|||||||
save->swappedImages = true;
|
save->swappedImages = true;
|
||||||
save->update();
|
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,
|
mainMenu = new CAdventureMapButton (CGI->generaltexth->zelp[320].first, CGI->generaltexth->zelp[320].second,
|
||||||
boost::bind(&CSystemOptionsWindow::bmainmenuf, this), 357, 357, "SOMAIN.DEF", SDLK_m);
|
boost::bind(&CSystemOptionsWindow::bmainmenuf, this), 357, 357, "SOMAIN.DEF", SDLK_m);
|
||||||
@ -3821,7 +3824,7 @@ void CSystemOptionsWindow::breturnf()
|
|||||||
|
|
||||||
void CSystemOptionsWindow::bmainmenuf()
|
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()
|
void CSystemOptionsWindow::bsavef()
|
||||||
@ -3830,6 +3833,11 @@ void CSystemOptionsWindow::bsavef()
|
|||||||
GH.pushInt(new CSavingScreen(CPlayerInterface::howManyPeople > 1));
|
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)
|
CTavernWindow::CTavernWindow(const CGObjectInstance *TavernObj)
|
||||||
: tavernObj(TavernObj)
|
: tavernObj(TavernObj)
|
||||||
{
|
{
|
||||||
|
@ -682,6 +682,7 @@ private:
|
|||||||
void bsavef(); //save game
|
void bsavef(); //save game
|
||||||
void bquitf(); //quit game
|
void bquitf(); //quit game
|
||||||
void breturnf(); //return to game
|
void breturnf(); //return to game
|
||||||
|
void brestartf(); //return to game
|
||||||
void bmainmenuf(); //return to main menu
|
void bmainmenuf(); //return to main menu
|
||||||
|
|
||||||
//functions for checkboxes
|
//functions for checkboxes
|
||||||
|
Reference in New Issue
Block a user