2018-01-05 19:21:07 +02:00
|
|
|
/*
|
|
|
|
* CSavingScreen.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "CSavingScreen.h"
|
|
|
|
#include "SelectionTab.h"
|
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-04-27 19:21:06 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/Buttons.h"
|
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/StartInfo.h"
|
|
|
|
#include "../../lib/filesystem/Filesystem.h"
|
|
|
|
#include "../../lib/mapping/CMapInfo.h"
|
2023-05-24 01:05:59 +02:00
|
|
|
#include "../../lib/mapping/CMapHeader.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
CSavingScreen::CSavingScreen()
|
|
|
|
: CSelectionBase(ESelectionScreen::saveGame)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
center(pos);
|
2018-04-07 17:21:28 +02:00
|
|
|
localMi = std::make_shared<CMapInfo>();
|
2018-01-05 19:21:07 +02:00
|
|
|
localMi->mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader(*LOCPLINT->cb->getMapHeader()));
|
|
|
|
|
|
|
|
tabSel = std::make_shared<SelectionTab>(screenType);
|
|
|
|
tabSel->callOnSelect = std::bind(&CSavingScreen::changeSelection, this, _1);
|
2023-07-09 08:00:48 +02:00
|
|
|
tabSel->toggleMode();
|
|
|
|
curTab = tabSel;
|
|
|
|
|
2023-04-27 19:21:06 +02:00
|
|
|
buttonStart = std::make_shared<CButton>(Point(411, 535), "SCNRSAV.DEF", CGI->generaltexth->zelp[103], std::bind(&CSavingScreen::saveGame, this), EShortcut::LOBBY_SAVE_GAME);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CMapInfo * CSavingScreen::getMapInfo()
|
|
|
|
{
|
2018-04-07 17:21:28 +02:00
|
|
|
return localMi.get();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const StartInfo * CSavingScreen::getStartInfo()
|
|
|
|
{
|
2023-04-19 22:12:30 +02:00
|
|
|
if (localMi)
|
|
|
|
return localMi->scenarioOptionsOfSave;
|
|
|
|
return LOCPLINT->cb->getStartInfo();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSavingScreen::changeSelection(std::shared_ptr<CMapInfo> to)
|
|
|
|
{
|
2018-04-07 17:21:28 +02:00
|
|
|
if(localMi == to)
|
2018-01-05 19:21:07 +02:00
|
|
|
return;
|
|
|
|
|
2018-04-07 17:21:28 +02:00
|
|
|
localMi = to;
|
2018-01-05 19:21:07 +02:00
|
|
|
card->changeSelection();
|
2023-07-12 08:10:02 +02:00
|
|
|
card->redraw();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSavingScreen::saveGame()
|
|
|
|
{
|
2022-12-19 22:04:50 +02:00
|
|
|
if(!(tabSel && tabSel->inputName && tabSel->inputName->getText().size()))
|
2018-01-05 19:21:07 +02:00
|
|
|
return;
|
|
|
|
|
2023-08-08 23:46:30 +02:00
|
|
|
std::string path = "Saves/" + tabSel->curFolder + tabSel->inputName->getText();
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2018-04-07 17:21:28 +02:00
|
|
|
auto overWrite = [this, path]() -> void
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
Settings lastSave = settings.write["general"]["lastSave"];
|
|
|
|
lastSave->String() = path;
|
|
|
|
LOCPLINT->cb->save(path);
|
2018-07-25 00:36:48 +02:00
|
|
|
close();
|
2018-01-05 19:21:07 +02:00
|
|
|
};
|
|
|
|
|
2023-07-09 14:30:47 +02:00
|
|
|
if(CResourceHandler::get("local")->existsResource(ResourceID(path, EResType::SAVEGAME)))
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
std::string hlp = CGI->generaltexth->allTexts[493]; //%s exists. Overwrite?
|
2022-12-19 22:04:50 +02:00
|
|
|
boost::algorithm::replace_first(hlp, "%s", tabSel->inputName->getText());
|
2018-04-07 13:34:11 +02:00
|
|
|
LOCPLINT->showYesNoDialog(hlp, overWrite, nullptr);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
overWrite();
|
|
|
|
}
|
|
|
|
}
|