diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 0ac30b561..93d139bc8 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -193,8 +193,13 @@ void CServerHandler::startLocalServerAndConnect(bool connectToLobby) serverRunner.reset(new ServerThreadRunner()); #endif + auto si = std::make_shared(); + + auto lastDifficulty = settings["general"]["lastDifficulty"]; + si->difficulty = lastDifficulty.Integer(); + logNetwork->trace("\tStarting local server"); - serverRunner->start(getLocalPort(), connectToLobby); + serverRunner->start(getLocalPort(), connectToLobby, si); logNetwork->trace("\tConnecting to local server"); connectToServer(getLocalHostname(), getLocalPort()); logNetwork->trace("\tWaiting for connection"); diff --git a/client/ServerRunner.cpp b/client/ServerRunner.cpp index 59cce1110..8ab4df84b 100644 --- a/client/ServerRunner.cpp +++ b/client/ServerRunner.cpp @@ -23,10 +23,15 @@ ServerThreadRunner::ServerThreadRunner() = default; ServerThreadRunner::~ServerThreadRunner() = default; -void ServerThreadRunner::start(uint16_t port, bool connectToLobby) +void ServerThreadRunner::start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) { server = std::make_unique(port, connectToLobby, true); + if (startingInfo) + { + server->si = startingInfo; //Else use default + } + threadRunLocalServer = boost::thread([this]{ setThreadName("runServer"); server->run(); @@ -68,7 +73,7 @@ int ServerProcessRunner::exitCode() return child->exit_code(); } -void ServerProcessRunner::start(uint16_t port, bool connectToLobby) +void ServerProcessRunner::start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) { boost::filesystem::path serverPath = VCMIDirs::get().serverPath(); boost::filesystem::path logPath = VCMIDirs::get().userLogsPath() / "server_log.txt"; diff --git a/client/ServerRunner.h b/client/ServerRunner.h index 115dcebfa..d045e0c75 100644 --- a/client/ServerRunner.h +++ b/client/ServerRunner.h @@ -9,12 +9,18 @@ */ #pragma once +VCMI_LIB_NAMESPACE_BEGIN + +struct StartInfo; + +VCMI_LIB_NAMESPACE_END + class CVCMIServer; class IServerRunner { public: - virtual void start(uint16_t port, bool connectToLobby) = 0; + virtual void start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) = 0; virtual void shutdown() = 0; virtual void wait() = 0; virtual int exitCode() = 0; @@ -28,7 +34,7 @@ class ServerThreadRunner : public IServerRunner, boost::noncopyable std::unique_ptr server; boost::thread threadRunLocalServer; public: - void start(uint16_t port, bool connectToLobby) override; + void start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) override; void shutdown() override; void wait() override; int exitCode() override; @@ -50,7 +56,7 @@ class ServerProcessRunner : public IServerRunner, boost::noncopyable std::unique_ptr child; public: - void start(uint16_t port, bool connectToLobby) override; + void start(uint16_t port, bool connectToLobby, std::shared_ptr startingInfo) override; void shutdown() override; void wait() override; int exitCode() override; diff --git a/client/lobby/CLobbyScreen.cpp b/client/lobby/CLobbyScreen.cpp index 4cd6c94f6..8279f1789 100644 --- a/client/lobby/CLobbyScreen.cpp +++ b/client/lobby/CLobbyScreen.cpp @@ -156,6 +156,16 @@ void CLobbyScreen::startCampaign() void CLobbyScreen::startScenario(bool allowOnlyAI) { + if (tabRand && CSH->si->mapGenOptions) + { + // Save RMG settings at game start + tabRand->saveOptions(*CSH->si->mapGenOptions); + } + + // Save chosen difficulty + Settings lastDifficulty = settings.write["general"]["lastDifficulty"]; + lastDifficulty->Integer() = getCurrentDifficulty(); + if (CSH->validateGameStart(allowOnlyAI)) { CSH->sendStartGame(allowOnlyAI); diff --git a/client/lobby/RandomMapTab.cpp b/client/lobby/RandomMapTab.cpp index 4ff10a5b6..310f9dae2 100644 --- a/client/lobby/RandomMapTab.cpp +++ b/client/lobby/RandomMapTab.cpp @@ -38,6 +38,10 @@ #include "../../lib/filesystem/Filesystem.h" #include "../../lib/RoadHandler.h" +#include "../../lib/CConfigHandler.h" +#include "../../lib/serializer/JsonSerializer.h" +#include "../../lib/serializer/JsonDeserializer.h" + RandomMapTab::RandomMapTab(): InterfaceObjectConfigurable() { @@ -162,7 +166,7 @@ RandomMapTab::RandomMapTab(): }; } - updateMapInfoByHost(); + loadOptions(); } void RandomMapTab::updateMapInfoByHost() @@ -461,7 +465,7 @@ TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab): //int totalPlayers = randomMapTab.obtainMapGenOptions().getPlayerLimit(); int totalPlayers = randomMapTab.obtainMapGenOptions().getMaxPlayersCount(); assert(totalPlayers <= PlayerColor::PLAYER_LIMIT_I); - auto settings = randomMapTab.obtainMapGenOptions().getPlayersSettings(); + auto playerSettings = randomMapTab.obtainMapGenOptions().getPlayersSettings(); variables["totalPlayers"].Integer() = totalPlayers; pos.w = variables["windowSize"]["x"].Integer() + totalPlayers * variables["cellMargin"]["x"].Integer(); @@ -502,20 +506,20 @@ TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab): // Window should have X * X columns, where X is max players allowed for current settings // For random player count, X is 8 - if (totalPlayers > settings.size()) + if (totalPlayers > playerSettings.size()) { auto savedPlayers = randomMapTab.obtainMapGenOptions().getSavedPlayersMap(); for (const auto & player : savedPlayers) { - if (!vstd::contains(settings, player.first)) + if (!vstd::contains(playerSettings, player.first)) { - settings[player.first] = player.second; + playerSettings[player.first] = player.second; } } } std::vector settingsVec; - for (const auto & player : settings) + for (const auto & player : playerSettings) { settingsVec.push_back(player.second); } @@ -569,3 +573,36 @@ TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab): buttonOk = widget("buttonOK"); buttonCancel = widget("buttonCancel"); } + +void RandomMapTab::saveOptions(const CMapGenOptions & options) +{ + JsonNode data; + JsonSerializer ser(nullptr, data); + + ser.serializeStruct("lastSettings", const_cast(options)); + + // FIXME: Do not nest fields + Settings rmgSettings = persistentStorage.write["rmg"]; + rmgSettings["rmg"] = data; +} + +void RandomMapTab::loadOptions() +{ + auto rmgSettings = persistentStorage["rmg"]["rmg"]; + if (!rmgSettings.Struct().empty()) + { + mapGenOptions.reset(new CMapGenOptions()); + JsonDeserializer handler(nullptr, rmgSettings); + handler.serializeStruct("lastSettings", *mapGenOptions); + + // Will check template and set other options as well + setTemplate(mapGenOptions->getMapTemplate()); + if(auto w = widget("templateList")) + { + w->setItem(mapGenOptions->getMapTemplate()); + } + } + updateMapInfoByHost(); + + // TODO: Save & load difficulty? +} \ No newline at end of file diff --git a/client/lobby/RandomMapTab.h b/client/lobby/RandomMapTab.h index 2ad559e80..fa62e151d 100644 --- a/client/lobby/RandomMapTab.h +++ b/client/lobby/RandomMapTab.h @@ -36,6 +36,9 @@ public: void updateMapInfoByHost(); void setMapGenOptions(std::shared_ptr opts); void setTemplate(const CRmgTemplate *); + + void saveOptions(const CMapGenOptions & options); + void loadOptions(); CMapGenOptions & obtainMapGenOptions() {return *mapGenOptions;} CFunctionList, std::shared_ptr)> mapInfoChanged; @@ -44,8 +47,8 @@ private: void deactivateButtonsFrom(CToggleGroup & group, const std::set & allowed); std::vector getPossibleMapSizes(); - std::shared_ptr mapGenOptions; std::shared_ptr mapInfo; + std::shared_ptr mapGenOptions; //options allowed - need to store as impact each other std::set playerCountAllowed; diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 73e7aca83..6c467f3e5 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -167,7 +167,12 @@ SelectionTab::SelectionTab(ESelectionScreen Type) inputName->filters += CTextInput::filenameFilter; labelMapSizes = std::make_shared(87, 62, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[510]); - int sizes[] = {36, 72, 108, 144, 0}; + // TODO: Global constants? + int sizes[] = {CMapHeader::MAP_SIZE_SMALL, + CMapHeader::MAP_SIZE_MIDDLE, + CMapHeader::MAP_SIZE_LARGE, + CMapHeader::MAP_SIZE_XLARGE, + 0}; const char * filterIconNmes[] = {"SCSMBUT.DEF", "SCMDBUT.DEF", "SCLGBUT.DEF", "SCXLBUT.DEF", "SCALBUT.DEF"}; for(int i = 0; i < 5; i++) buttonsSortBy.push_back(std::make_shared(Point(158 + 47 * i, 46), AnimationPath::builtin(filterIconNmes[i]), CGI->generaltexth->zelp[54 + i], std::bind(&SelectionTab::filter, this, sizes[i], true))); diff --git a/client/widgets/ComboBox.h b/client/widgets/ComboBox.h index cd3c1e883..670734c10 100644 --- a/client/widgets/ComboBox.h +++ b/client/widgets/ComboBox.h @@ -51,8 +51,6 @@ class ComboBox : public CButton }; friend class DropDown; - - void setItem(const void *); public: ComboBox(Point position, const AnimationPath & defName, const std::pair & help, const JsonNode & dropDownDescriptor, Point dropDownPosition, EShortcut key = {}, bool playerColoredButton = false); @@ -67,6 +65,7 @@ public: std::function getItemText; void setItem(int id); + void setItem(const void *); void updateListItems(); }; diff --git a/config/schemas/settings.json b/config/schemas/settings.json index 890b90dfa..f566c3cc1 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -28,6 +28,7 @@ "lastSave", "lastSettingsTab", "lastCampaign", + "lastDifficulty", "saveFrequency", "notifications", "extraDump", @@ -85,6 +86,10 @@ "type" : "string", "default" : "" }, + "lastDifficulty" : { + "type" : "number", + "default" : 1 + }, "saveFrequency" : { "type" : "number", "default" : 1 diff --git a/lib/rmg/CMapGenOptions.cpp b/lib/rmg/CMapGenOptions.cpp index fe233bf99..44b7f1cef 100644 --- a/lib/rmg/CMapGenOptions.cpp +++ b/lib/rmg/CMapGenOptions.cpp @@ -17,6 +17,7 @@ #include "CRandomGenerator.h" #include "../VCMI_Lib.h" #include "../CTownHandler.h" +#include "serializer/JsonSerializeFormat.h" VCMI_LIB_NAMESPACE_BEGIN @@ -816,4 +817,35 @@ void CMapGenOptions::CPlayerSettings::setTeam(const TeamID & value) team = value; } +void CMapGenOptions::serializeJson(JsonSerializeFormat & handler) +{ + handler.serializeInt("width", width); + handler.serializeInt("height", height); + handler.serializeBool("haswoLevels", hasTwoLevels); + handler.serializeInt("humanOrCpuPlayerCount", humanOrCpuPlayerCount); + handler.serializeInt("teamCount", teamCount); + handler.serializeInt("compOnlyPlayerCount", compOnlyPlayerCount); + handler.serializeInt("compOnlyTeamCount", compOnlyTeamCount); + handler.serializeInt("waterContent", waterContent); + handler.serializeInt("monsterStrength", monsterStrength); + + std::string templateName; + if(mapTemplate && handler.saving) + { + templateName = mapTemplate->getId(); + } + handler.serializeString("templateName", templateName); + if(!handler.saving) + { + setMapTemplate(templateName); + } + + handler.serializeIdArray("roads", enabledRoads); + if (!handler.saving) + { + // Player settings won't be saved + resetPlayersMap(); + } +} + VCMI_LIB_NAMESPACE_END diff --git a/lib/rmg/CMapGenOptions.h b/lib/rmg/CMapGenOptions.h index 47e33c797..2055d58e5 100644 --- a/lib/rmg/CMapGenOptions.h +++ b/lib/rmg/CMapGenOptions.h @@ -210,6 +210,8 @@ public: h & enabledRoads; } + + void serializeJson(JsonSerializeFormat & handler); }; VCMI_LIB_NAMESPACE_END diff --git a/lib/rmg/CRmgTemplate.cpp b/lib/rmg/CRmgTemplate.cpp index 75467694f..ac7a491e3 100644 --- a/lib/rmg/CRmgTemplate.cpp +++ b/lib/rmg/CRmgTemplate.cpp @@ -841,20 +841,20 @@ void CRmgTemplate::serializeSize(JsonSerializeFormat & handler, int3 & value, co { static const std::map sizeMapping = { - {"s", { 36, 36, 1}}, - {"s+u", { 36, 36, 2}}, - {"m", { 72, 72, 1}}, - {"m+u", { 72, 72, 2}}, - {"l", {108, 108, 1}}, - {"l+u", {108, 108, 2}}, - {"xl", {144, 144, 1}}, - {"xl+u", {144, 144, 2}}, - {"h", {180, 180, 1}}, - {"h+u", {180, 180, 2}}, - {"xh", {216, 216, 1}}, - {"xh+u", {216, 216, 2}}, - {"g", {252, 252, 1}}, - {"g+u", {252, 252, 2}} + {"s", {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_SMALL, 1}}, + {"s+u", {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_SMALL, 2}}, + {"m", {CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_MIDDLE, 1}}, + {"m+u", {CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_MIDDLE, 2}}, + {"l", {CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_LARGE, 1}}, + {"l+u", {CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_LARGE, 2}}, + {"xl", {CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_XLARGE, 1}} , + {"xl+u", {CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_XLARGE, 2}} , + {"h", {CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_HUGE, 1}}, + {"h+u", {CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_HUGE, 2}}, + {"xh", {CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_XHUGE, 1}}, + {"xh+u", {CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_XHUGE, 2}}, + {"g", {CMapHeader::MAP_SIZE_GIANT, CMapHeader::MAP_SIZE_GIANT, 1}}, + {"g+u", {CMapHeader::MAP_SIZE_GIANT, CMapHeader::MAP_SIZE_GIANT, 2}} }; static const std::map sizeReverseMapping = vstd::invertMap(sizeMapping); diff --git a/mapeditor/jsonutils.cpp b/mapeditor/jsonutils.cpp index 7c8f946ac..f7ce677bb 100644 --- a/mapeditor/jsonutils.cpp +++ b/mapeditor/jsonutils.cpp @@ -69,6 +69,7 @@ QVariant toVariant(const JsonNode & node) return QVariant(node.Bool()); break; case JsonNode::JsonType::DATA_FLOAT: + case JsonNode::JsonType::DATA_INTEGER: return QVariant(node.Float()); break; case JsonNode::JsonType::DATA_STRING: diff --git a/mapeditor/windownewmap.cpp b/mapeditor/windownewmap.cpp index cc673b4bd..e31c9d57e 100644 --- a/mapeditor/windownewmap.cpp +++ b/mapeditor/windownewmap.cpp @@ -17,7 +17,10 @@ #include "../lib/mapping/CMapEditManager.h" #include "../lib/mapping/MapFormat.h" #include "../lib/CGeneralTextHandler.h" +#include "../lib/serializer/JsonSerializer.h" +#include "../lib/serializer/JsonDeserializer.h" +#include "jsonutils.h" #include "windownewmap.h" #include "ui_windownewmap.h" #include "mainwindow.h" @@ -52,84 +55,77 @@ WindowNewMap::WindowNewMap(QWidget *parent) : ui->cpuTeamsCombo->setItemData(i, QVariant(cpuPlayers.at(i))); } - for(auto * combo : {ui->humanCombo, ui->cpuCombo, ui->humanTeamsCombo, ui->cpuTeamsCombo}) - combo->setCurrentIndex(0); - loadUserSettings(); + bool useLoaded = loadUserSettings(); + if (!useLoaded) + { + for(auto * combo : {ui->humanCombo, ui->cpuCombo, ui->humanTeamsCombo, ui->cpuTeamsCombo}) + combo->setCurrentIndex(0); + } show(); - //setup initial parameters - int width = ui->widthTxt->text().toInt(); - int height = ui->heightTxt->text().toInt(); - mapGenOptions.setWidth(width ? width : 1); - mapGenOptions.setHeight(height ? height : 1); - bool twoLevel = ui->twoLevelCheck->isChecked(); - mapGenOptions.setHasTwoLevels(twoLevel); - updateTemplateList(); + if (!useLoaded) + { + //setup initial parameters + int width = ui->widthTxt->text().toInt(); + int height = ui->heightTxt->text().toInt(); + mapGenOptions.setWidth(width ? width : 1); + mapGenOptions.setHeight(height ? height : 1); + bool twoLevel = ui->twoLevelCheck->isChecked(); + mapGenOptions.setHasTwoLevels(twoLevel); + + updateTemplateList(); + } } WindowNewMap::~WindowNewMap() { - saveUserSettings(); delete ui; } -void WindowNewMap::loadUserSettings() +bool WindowNewMap::loadUserSettings() { - //load window settings + bool ret = false; + CRmgTemplate * templ = nullptr; + QSettings s(Ui::teamName, Ui::appName); - auto width = s.value(newMapWidth); - if (width.isValid()) - { - ui->widthTxt->setText(width.toString()); - } - auto height = s.value(newMapHeight); - if (height.isValid()) - { - ui->heightTxt->setText(height.toString()); - } - for(auto & sz : mapSizes) - { - if(sz.second.first == width.toInt() && sz.second.second == height.toInt()) - ui->sizeCombo->setCurrentIndex(sz.first); - } - auto twoLevel = s.value(newMapTwoLevel); - if (twoLevel.isValid()) - { - ui->twoLevelCheck->setChecked(twoLevel.toBool()); - } auto generateRandom = s.value(newMapGenerateRandom); if (generateRandom.isValid()) { ui->randomMapCheck->setChecked(generateRandom.toBool()); } - auto players = s.value(newMapPlayers); - if (players.isValid()) + + auto settings = s.value(newMapWindow); + + if (settings.isValid()) { - ui->humanCombo->setCurrentIndex(players.toInt()); - } - auto cpuPlayers = s.value(newMapCpuPlayers); - if (cpuPlayers.isValid()) - { - ui->cpuCombo->setCurrentIndex(cpuPlayers.toInt()); - } - auto teams = s.value(newMapHumanTeams); - if(teams.isValid()) - { - ui->humanTeamsCombo->setCurrentIndex(teams.toInt()); - } - auto cputeams = s.value(newMapCpuTeams); - if(cputeams.isValid()) - { - ui->cpuTeamsCombo->setCurrentIndex(cputeams.toInt()); - } - - auto waterContent = s.value(newMapWaterContent); - if (waterContent.isValid()) - { - switch (waterContent.toInt()) + auto node = JsonUtils::toJson(settings); + JsonDeserializer handler(nullptr, node); + handler.serializeStruct("lastSettings", mapGenOptions); + templ = const_cast(mapGenOptions.getMapTemplate()); // Remember for later + + ui->widthTxt->setText(QString::number(mapGenOptions.getWidth())); + ui->heightTxt->setText(QString::number(mapGenOptions.getHeight())); + for(auto & sz : mapSizes) + { + if(sz.second.first == mapGenOptions.getWidth() && + sz.second.second == mapGenOptions.getHeight()) + { + ui->sizeCombo->setCurrentIndex(sz.first); + break; + } + } + + ui->twoLevelCheck->setChecked(mapGenOptions.getHasTwoLevels()); + + ui->humanCombo->setCurrentIndex(mapGenOptions.getHumanOrCpuPlayerCount()); + ui->cpuCombo->setCurrentIndex(mapGenOptions.getCompOnlyPlayerCount()); + ui->humanTeamsCombo->setCurrentIndex(mapGenOptions.getTeamCount()); + ui->cpuTeamsCombo->setCurrentIndex(mapGenOptions.getCompOnlyTeamCount()); + + switch (mapGenOptions.getWaterContent()) { case EWaterContent::RANDOM: ui->waterOpt1->setChecked(true); break; @@ -141,11 +137,7 @@ void WindowNewMap::loadUserSettings() ui->waterOpt4->setChecked(true); break; } - } - auto monsterStrength = s.value(newMapMonsterStrength); - if (monsterStrength.isValid()) - { - switch (monsterStrength.toInt()) + switch (mapGenOptions.getMonsterStrength()) { case EMonsterStrength::RANDOM: ui->monsterOpt1->setChecked(true); break; @@ -156,71 +148,47 @@ void WindowNewMap::loadUserSettings() case EMonsterStrength::GLOBAL_STRONG: ui->monsterOpt4->setChecked(true); break; } + + ret = true; } - auto templateName = s.value(newMapTemplate); - if (templateName.isValid()) + updateTemplateList(); + mapGenOptions.setMapTemplate(templ); // Can be null + + if (templ) { - updateTemplateList(); - - auto* templ = VLC->tplh->getTemplate(templateName.toString().toStdString()); - if (templ) + std::string name = templ->getName(); + for (size_t i = 0; i < ui->templateCombo->count(); i++) { - ui->templateCombo->setCurrentText(templateName.toString()); - //TODO: validate inside this method - mapGenOptions.setMapTemplate(templ); - } - else - { - //Display problem on status bar + if (ui->templateCombo->itemText(i).toStdString() == name) + { + ui->templateCombo->setCurrentIndex(i); + break; + } } + ret = true; } + + return ret; } void WindowNewMap::saveUserSettings() { QSettings s(Ui::teamName, Ui::appName); - s.setValue(newMapWidth, ui->widthTxt->text().toInt()); - s.setValue(newMapHeight, ui->heightTxt->text().toInt()); - s.setValue(newMapTwoLevel, ui->twoLevelCheck->isChecked()); + + JsonNode data; + JsonSerializer ser(nullptr, data); + + ser.serializeStruct("lastSettings", mapGenOptions); + + auto variant = JsonUtils::toVariant(data); + s.setValue(newMapWindow, variant); s.setValue(newMapGenerateRandom, ui->randomMapCheck->isChecked()); - - s.setValue(newMapPlayers,ui->humanCombo->currentIndex()); - s.setValue(newMapCpuPlayers,ui->cpuCombo->currentIndex()); - s.setValue(newMapHumanTeams, ui->humanTeamsCombo->currentIndex()); - s.setValue(newMapCpuTeams, ui->cpuTeamsCombo->currentIndex()); - - EWaterContent::EWaterContent water = EWaterContent::RANDOM; - if(ui->waterOpt1->isChecked()) - water = EWaterContent::RANDOM; - else if(ui->waterOpt2->isChecked()) - water = EWaterContent::NONE; - else if(ui->waterOpt3->isChecked()) - water = EWaterContent::NORMAL; - else if(ui->waterOpt4->isChecked()) - water = EWaterContent::ISLANDS; - s.setValue(newMapWaterContent, static_cast(water)); - - EMonsterStrength::EMonsterStrength monster = EMonsterStrength::RANDOM; - if(ui->monsterOpt1->isChecked()) - monster = EMonsterStrength::RANDOM; - else if(ui->monsterOpt2->isChecked()) - monster = EMonsterStrength::GLOBAL_WEAK; - else if(ui->monsterOpt3->isChecked()) - monster = EMonsterStrength::GLOBAL_NORMAL; - else if(ui->monsterOpt4->isChecked()) - monster = EMonsterStrength::GLOBAL_STRONG; - s.setValue(newMapMonsterStrength, static_cast(monster)); - - auto templateName = ui->templateCombo->currentText(); - if (templateName.size()) - { - s.setValue(newMapTemplate, templateName); - } } void WindowNewMap::on_cancelButton_clicked() { + saveUserSettings(); close(); } @@ -267,6 +235,8 @@ void WindowNewMap::on_okButton_clicked() mapGenOptions.setWaterContent(water); mapGenOptions.setMonsterStrength(monster); + saveUserSettings(); + std::unique_ptr nmap; if(ui->randomMapCheck->isChecked()) { diff --git a/mapeditor/windownewmap.h b/mapeditor/windownewmap.h index 76bd5dc22..1fadd28a2 100644 --- a/mapeditor/windownewmap.h +++ b/mapeditor/windownewmap.h @@ -22,6 +22,7 @@ class WindowNewMap : public QDialog { Q_OBJECT + const QString newMapWindow = "NewMapWindow/Settings"; const QString newMapWidth = "NewMapWindow/Width"; const QString newMapHeight = "NewMapWindow/Height"; const QString newMapTwoLevel = "NewMapWindow/TwoLevel"; @@ -64,10 +65,13 @@ class WindowNewMap : public QDialog const std::map> mapSizes { - {0, {36, 36}}, - {1, {72, 72}}, - {2, {108, 108}}, - {3, {144, 144}}, + {0, {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_SMALL}}, + {1, {CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_MIDDLE}}, + {2, {CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_LARGE}}, + {3, {CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_XLARGE}}, + {4, {CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_HUGE}}, + {5, {CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_XHUGE}}, + {6, {CMapHeader::MAP_SIZE_GIANT, CMapHeader::MAP_SIZE_GIANT}}, }; public: @@ -105,7 +109,7 @@ private: void updateTemplateList(); - void loadUserSettings(); + bool loadUserSettings(); void saveUserSettings(); private: diff --git a/mapeditor/windownewmap.ui b/mapeditor/windownewmap.ui index 4e83d644b..3b97e1a44 100644 --- a/mapeditor/windownewmap.ui +++ b/mapeditor/windownewmap.ui @@ -51,11 +51,11 @@ 0 20 - 261 + 281 68 - + @@ -65,6 +65,12 @@ + + + 64 + 16777215 + + Qt::ImhDigitsOnly @@ -85,6 +91,12 @@ + + + 64 + 16777215 + + Qt::ImhDigitsOnly @@ -143,23 +155,23 @@ - 120 + 144 16777215 - S (36x36) + S (36x36) - M (72x72) + M (72x72) - L (108x108) + L (108x108) @@ -167,6 +179,21 @@ XL (144x144) + + + H (180x180) + + + + + XH (216x216) + + + + + G (252x252) + +