1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Merge pull request #3086 from Laserlicht/show_random

show random maps
This commit is contained in:
Ivan Savenko 2023-10-22 12:29:31 +03:00 committed by GitHub
commit 8752551786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 5 deletions

View File

@ -111,6 +111,14 @@ void CSelectionBase::toggleTab(std::shared_ptr<CIntObject> tab)
{
curTab.reset();
}
if(tabSel->showRandom && tab != tabOpt)
{
tabSel->curFolder = "";
tabSel->showRandom = false;
tabSel->filter(0, true);
}
GH.windows().totalRedraw();
}

View File

@ -11,6 +11,8 @@
#include "RandomMapTab.h"
#include "CSelectionBase.h"
#include "CLobbyScreen.h"
#include "SelectionTab.h"
#include "../CGameInfo.h"
#include "../CServerHandler.h"
@ -121,6 +123,16 @@ RandomMapTab::RandomMapTab():
const JsonNode config(JsonPath::builtin("config/widgets/randomMapTab.json"));
build(config);
if(auto w = widget<CButton>("buttonShowRandomMaps"))
{
w->addCallback([&]()
{
(static_cast<CLobbyScreen *>(parent))->toggleTab((static_cast<CLobbyScreen *>(parent))->tabSel);
(static_cast<CLobbyScreen *>(parent))->tabSel->showRandom = true;
(static_cast<CLobbyScreen *>(parent))->tabSel->filter(0, true);
});
}
//set combo box callbacks
if(auto w = widget<ComboBox>("templateList"))
{

View File

@ -147,7 +147,7 @@ static ESortBy getSortBySelectionScreen(ESelectionScreen Type)
}
SelectionTab::SelectionTab(ESelectionScreen Type)
: CIntObject(LCLICK | SHOW_POPUP | KEYBOARD | DOUBLECLICK), callOnSelect(nullptr), tabType(Type), selectionPos(0), sortModeAscending(true), inputNameRect{32, 539, 350, 20}, curFolder(""), currentMapSizeFilter(0)
: CIntObject(LCLICK | SHOW_POPUP | KEYBOARD | DOUBLECLICK), callOnSelect(nullptr), tabType(Type), selectionPos(0), sortModeAscending(true), inputNameRect{32, 539, 350, 20}, curFolder(""), currentMapSizeFilter(0), showRandom(false)
{
OBJ_CONSTRUCTION;
@ -427,9 +427,15 @@ void SelectionTab::filter(int size, bool selectFirst)
{
if((elem->mapHeader && (!size || elem->mapHeader->width == size)) || tabType == ESelectionScreen::campaignList)
{
if(showRandom)
curFolder = "RANDOMMAPS/";
auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(elem->originalFileURI);
if(parentExists)
if((showRandom && baseFolder != "RANDOMMAPS") || (!showRandom && baseFolder == "RANDOMMAPS"))
continue;
if(parentExists && !showRandom)
{
auto folder = std::make_shared<ElementInfo>();
folder->isFolder = true;

View File

@ -78,6 +78,7 @@ public:
ESortBy generalSortingBy;
bool sortModeAscending;
int currentMapSizeFilter = 0;
bool showRandom;
std::shared_ptr<CTextInput> inputName;

View File

@ -566,17 +566,20 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan
{
try
{
auto path = VCMIDirs::get().userCachePath() / "RandomMaps";
auto path = VCMIDirs::get().userDataPath() / "Maps" / "RandomMaps";
boost::filesystem::create_directories(path);
std::shared_ptr<CMapGenOptions> options = scenarioOps->mapGenOptions;
const std::string templateName = options->getMapTemplate()->getName();
const ui32 seed = scenarioOps->seedToBeUsed;
const std::string dt = vstd::getDateTimeISO8601Basic(std::time(0));
const std::string fileName = boost::str(boost::format("%s_%d.vmap") % templateName % seed );
const std::string fileName = boost::str(boost::format("%s_%s_%d.vmap") % dt % templateName % seed );
const auto fullPath = path / fileName;
randomMap->name.appendRawString(boost::str(boost::format(" %s") % dt));
mapService->saveMap(randomMap, fullPath);
logGlobal->info("Random map has been saved to:");

View File

@ -99,7 +99,7 @@ public:
void preInit(Services * services);
void init(const IMapService * mapService, StartInfo * si, Load::ProgressAccumulator &, bool allowSavingRandomMap = false);
void init(const IMapService * mapService, StartInfo * si, Load::ProgressAccumulator &, bool allowSavingRandomMap = true);
void updateOnLoad(StartInfo * si);
ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)