mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
load game support
This commit is contained in:
parent
c6adcc40f5
commit
8b835c9253
@ -39,6 +39,10 @@
|
||||
#include "../../lib/TerrainHandler.h"
|
||||
#include "../../lib/filesystem/Filesystem.h"
|
||||
|
||||
#include "../../lib/serializer/BinaryDeserializer.h"
|
||||
#include "../../lib/StartInfo.h"
|
||||
#include "../../lib/rmg/CMapGenOptions.h"
|
||||
|
||||
CMapOverview::CMapOverview(std::string mapName, std::string fileName, std::string date, ResourcePath resource, ESelectionScreen tabType)
|
||||
: CWindowObject(BORDERED | RCLICK_POPUP), resource(resource), mapName(mapName), fileName(fileName), date(date), tabType(tabType)
|
||||
{
|
||||
@ -110,6 +114,13 @@ std::vector<std::shared_ptr<IImage>> CMapOverview::CMapOverviewWidget::createMin
|
||||
return ret;
|
||||
}
|
||||
|
||||
return createMinimaps(map, size);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IImage>> CMapOverview::CMapOverviewWidget::createMinimaps(std::unique_ptr<CMap> & map, Point size) const
|
||||
{
|
||||
std::vector<std::shared_ptr<IImage>> ret = std::vector<std::shared_ptr<IImage>>();
|
||||
|
||||
for(int i = 0; i < (map->twoLevel ? 2 : 1); i++)
|
||||
{
|
||||
Canvas canvas = createMinimapForLayer(map, i);
|
||||
@ -147,7 +158,28 @@ std::shared_ptr<CPicture> CMapOverview::CMapOverviewWidget::buildDrawMinimap(con
|
||||
if(!renderImage)
|
||||
return nullptr;
|
||||
|
||||
const std::vector<std::shared_ptr<IImage>> images = createMinimaps(ResourcePath(parent.resource.getName(), EResType::MAP), Point(rect.w, rect.h));
|
||||
ResourcePath res = ResourcePath(parent.resource.getName(), EResType::MAP);
|
||||
std::unique_ptr<CMap> campaignMap = nullptr;
|
||||
if(parent.tabType != ESelectionScreen::newGame)
|
||||
{
|
||||
CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(parent.resource.getName(), EResType::SAVEGAME)), MINIMAL_SERIALIZATION_VERSION);
|
||||
lf.checkMagicBytes(SAVEGAME_MAGIC);
|
||||
|
||||
std::unique_ptr<CMapHeader> mapHeader = std::make_unique<CMapHeader>();
|
||||
StartInfo * startInfo;
|
||||
lf >> *(mapHeader) >> startInfo;
|
||||
|
||||
if(startInfo->campState)
|
||||
campaignMap = startInfo->campState->getMap(*startInfo->campState->currentScenario());
|
||||
res = ResourcePath(startInfo->fileURI, EResType::MAP);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IImage>> images;
|
||||
if(!campaignMap)
|
||||
images = createMinimaps(res, Point(rect.w, rect.h));
|
||||
else
|
||||
images = createMinimaps(campaignMap, Point(rect.w, rect.h));
|
||||
|
||||
|
||||
if(id >= images.size())
|
||||
return nullptr;
|
||||
@ -195,7 +227,7 @@ CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent):
|
||||
InterfaceObjectConfigurable(), parent(parent)
|
||||
{
|
||||
drawPlayerElements = parent.tabType == ESelectionScreen::newGame;
|
||||
renderImage = parent.tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool();
|
||||
renderImage = settings["lobby"]["mapPreview"].Bool();
|
||||
|
||||
const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json"));
|
||||
|
||||
@ -204,8 +236,5 @@ CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent):
|
||||
REGISTER_BUILDER("drawPath", &CMapOverview::CMapOverviewWidget::buildDrawPath);
|
||||
REGISTER_BUILDER("drawString", &CMapOverview::CMapOverviewWidget::buildDrawString);
|
||||
|
||||
drawPlayerElements = parent.tabType == ESelectionScreen::newGame;
|
||||
renderImage = parent.tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool();
|
||||
|
||||
build(config);
|
||||
}
|
@ -36,6 +36,7 @@ class CMapOverview : public CWindowObject
|
||||
bool renderImage;
|
||||
Canvas createMinimapForLayer(std::unique_ptr<CMap> & map, int layer) const;
|
||||
std::vector<std::shared_ptr<IImage>> createMinimaps(ResourcePath resource, Point size) const;
|
||||
std::vector<std::shared_ptr<IImage>> createMinimaps(std::unique_ptr<CMap> & map, Point size) const;
|
||||
|
||||
std::shared_ptr<TransparentFilledRectangle> buildDrawTransparentRect(const JsonNode & config) const;
|
||||
std::shared_ptr<CPicture> buildDrawMinimap(const JsonNode & config) const;
|
||||
|
@ -102,6 +102,7 @@ struct DLL_LINKAGE StartInfo
|
||||
ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
|
||||
ui32 mapfileChecksum; //0 if not relevant
|
||||
std::string startTimeIso8601;
|
||||
std::string fileURI;
|
||||
SimturnsInfo simturnsInfo;
|
||||
TurnTimerInfo turnTimerInfo;
|
||||
std::string mapname; // empty for random map, otherwise name of the map or savegame
|
||||
@ -127,6 +128,7 @@ struct DLL_LINKAGE StartInfo
|
||||
h & seedPostInit;
|
||||
h & mapfileChecksum;
|
||||
h & startTimeIso8601;
|
||||
h & fileURI;
|
||||
h & simturnsInfo;
|
||||
h & turnTimerInfo;
|
||||
h & mapname;
|
||||
@ -135,7 +137,7 @@ struct DLL_LINKAGE StartInfo
|
||||
}
|
||||
|
||||
StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0),
|
||||
mapfileChecksum(0), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(0)))
|
||||
mapfileChecksum(0), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(0))), fileURI("")
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -318,6 +318,7 @@ bool CVCMIServer::prepareToStartGame()
|
||||
case StartInfo::CAMPAIGN:
|
||||
logNetwork->info("Preparing to start new campaign");
|
||||
si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(0));
|
||||
si->fileURI = mi->fileURI;
|
||||
si->campState->setCurrentMap(campaignMap);
|
||||
si->campState->setCurrentMapBonus(campaignBonus);
|
||||
gh->init(si.get(), progressTracking);
|
||||
@ -326,6 +327,7 @@ bool CVCMIServer::prepareToStartGame()
|
||||
case StartInfo::NEW_GAME:
|
||||
logNetwork->info("Preparing to start new game");
|
||||
si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(0));
|
||||
si->fileURI = mi->fileURI;
|
||||
gh->init(si.get(), progressTracking);
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user