mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
show random maps
This commit is contained in:
parent
f3acc939b9
commit
0eba0ee686
@ -111,6 +111,12 @@ void CSelectionBase::toggleTab(std::shared_ptr<CIntObject> tab)
|
|||||||
{
|
{
|
||||||
curTab.reset();
|
curTab.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(tabSel->showRandom)
|
||||||
|
tabSel->curFolder = "";
|
||||||
|
tabSel->showRandom = false;
|
||||||
|
tabSel->filter(0, true);
|
||||||
|
|
||||||
GH.windows().totalRedraw();
|
GH.windows().totalRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#include "RandomMapTab.h"
|
#include "RandomMapTab.h"
|
||||||
#include "CSelectionBase.h"
|
#include "CSelectionBase.h"
|
||||||
|
#include "CLobbyScreen.h"
|
||||||
|
#include "SelectionTab.h"
|
||||||
|
|
||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "../CServerHandler.h"
|
#include "../CServerHandler.h"
|
||||||
@ -121,6 +123,16 @@ RandomMapTab::RandomMapTab():
|
|||||||
const JsonNode config(JsonPath::builtin("config/widgets/randomMapTab.json"));
|
const JsonNode config(JsonPath::builtin("config/widgets/randomMapTab.json"));
|
||||||
build(config);
|
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
|
//set combo box callbacks
|
||||||
if(auto w = widget<ComboBox>("templateList"))
|
if(auto w = widget<ComboBox>("templateList"))
|
||||||
{
|
{
|
||||||
|
@ -147,7 +147,7 @@ static ESortBy getSortBySelectionScreen(ESelectionScreen Type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SelectionTab::SelectionTab(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;
|
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((elem->mapHeader && (!size || elem->mapHeader->width == size)) || tabType == ESelectionScreen::campaignList)
|
||||||
{
|
{
|
||||||
|
if(showRandom)
|
||||||
|
curFolder = "RANDOMMAPS/";
|
||||||
|
|
||||||
auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(elem->originalFileURI);
|
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>();
|
auto folder = std::make_shared<ElementInfo>();
|
||||||
folder->isFolder = true;
|
folder->isFolder = true;
|
||||||
|
@ -78,6 +78,7 @@ public:
|
|||||||
ESortBy generalSortingBy;
|
ESortBy generalSortingBy;
|
||||||
bool sortModeAscending;
|
bool sortModeAscending;
|
||||||
int currentMapSizeFilter = 0;
|
int currentMapSizeFilter = 0;
|
||||||
|
bool showRandom;
|
||||||
|
|
||||||
std::shared_ptr<CTextInput> inputName;
|
std::shared_ptr<CTextInput> inputName;
|
||||||
|
|
||||||
|
@ -566,17 +566,20 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto path = VCMIDirs::get().userCachePath() / "RandomMaps";
|
auto path = VCMIDirs::get().userDataPath() / "Maps" / "RandomMaps";
|
||||||
boost::filesystem::create_directories(path);
|
boost::filesystem::create_directories(path);
|
||||||
|
|
||||||
std::shared_ptr<CMapGenOptions> options = scenarioOps->mapGenOptions;
|
std::shared_ptr<CMapGenOptions> options = scenarioOps->mapGenOptions;
|
||||||
|
|
||||||
const std::string templateName = options->getMapTemplate()->getName();
|
const std::string templateName = options->getMapTemplate()->getName();
|
||||||
const ui32 seed = scenarioOps->seedToBeUsed;
|
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;
|
const auto fullPath = path / fileName;
|
||||||
|
|
||||||
|
randomMap->name.appendRawString(boost::str(boost::format(" %s") % dt));
|
||||||
|
|
||||||
mapService->saveMap(randomMap, fullPath);
|
mapService->saveMap(randomMap, fullPath);
|
||||||
|
|
||||||
logGlobal->info("Random map has been saved to:");
|
logGlobal->info("Random map has been saved to:");
|
||||||
|
@ -99,7 +99,7 @@ public:
|
|||||||
|
|
||||||
void preInit(Services * services);
|
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);
|
void updateOnLoad(StartInfo * si);
|
||||||
|
|
||||||
ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
|
ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
|
||||||
|
Loading…
Reference in New Issue
Block a user