diff --git a/Mods/vcmi/Content/config/english.json b/Mods/vcmi/Content/config/english.json index 2aa81d5a6..d6542c7a7 100644 --- a/Mods/vcmi/Content/config/english.json +++ b/Mods/vcmi/Content/config/english.json @@ -147,6 +147,11 @@ "vcmi.lobby.battleOnlyModeReset" : "Reset", "vcmi.lobby.templatesSelect.hover" : "Templates", "vcmi.lobby.templatesSelect.help" : "Search and select template", + "vcmi.lobby.customRmgSize.title" : "Select custom size", + "vcmi.lobby.customRmgSize.experimental" : "Multilevel support is highly experimental yet. Expect issues.", + "vcmi.lobby.customRmgSize.0" : "Width", + "vcmi.lobby.customRmgSize.1" : "Height", + "vcmi.lobby.customRmgSize.2" : "Layers", "vcmi.broadcast.failedLoadGame" : "Failed to load game", "vcmi.broadcast.command" : "Use '!help' to list available commands", diff --git a/Mods/vcmi/Content/config/german.json b/Mods/vcmi/Content/config/german.json index c05a712f8..1af9c619c 100644 --- a/Mods/vcmi/Content/config/german.json +++ b/Mods/vcmi/Content/config/german.json @@ -147,6 +147,11 @@ "vcmi.lobby.battleOnlyModeReset" : "Zurücksetzen", "vcmi.lobby.templatesSelect.hover" : "Templates", "vcmi.lobby.templatesSelect.help" : "Suche und wähle Template aus", + "vcmi.lobby.customRmgSize.title" : "Wähle Größe", + "vcmi.lobby.customRmgSize.experimental" : "Die Multi-Ebenen-Unterstützung befindet sich noch in einem sehr experimentellen Stadium. Es ist mit Problemen zu rechnen.", + "vcmi.lobby.customRmgSize.0" : "Breite", + "vcmi.lobby.customRmgSize.1" : "Höhe", + "vcmi.lobby.customRmgSize.2" : "Ebenen", "vcmi.broadcast.failedLoadGame" : "Spiel konnte nicht geladen werden", "vcmi.broadcast.command" : "Benutze '!help' um alle verfügbaren Befehle aufzulisten", diff --git a/client/lobby/RandomMapTab.cpp b/client/lobby/RandomMapTab.cpp index 6ed53ab08..984739cb2 100644 --- a/client/lobby/RandomMapTab.cpp +++ b/client/lobby/RandomMapTab.cpp @@ -19,6 +19,7 @@ #include "../GameInstance.h" #include "../gui/MouseButton.h" #include "../gui/WindowHandler.h" +#include "../gui/Shortcut.h" #include "../widgets/CComponent.h" #include "../widgets/ComboBox.h" #include "../widgets/Buttons.h" @@ -26,6 +27,8 @@ #include "../widgets/ObjectLists.h" #include "../widgets/Slider.h" #include "../widgets/TextControls.h" +#include "../widgets/GraphicalPrimitiveCanvas.h" +#include "../widgets/CTextInput.h" #include "../windows/GUIClasses.h" #include "../windows/InfoWindows.h" @@ -49,19 +52,43 @@ RandomMapTab::RandomMapTab(): recActions = 0; mapGenOptions = std::make_shared(); - addCallback("toggleMapSize", [&](int btnId) + addCallback("toggleMapSize", [this](int btnId) { + if(btnId == -1) + return; + auto mapSizeVal = getPossibleMapSizes(); + + auto setTemplateForSize = [this](){ + if(mapGenOptions->getMapTemplate()) + if(!mapGenOptions->getMapTemplate()->matchesSize(int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), mapGenOptions->getLevels()})) + setTemplate(nullptr); + updateMapInfoByHost(); + }; + + if(btnId == mapSizeVal.size() - 1) + { + ENGINE->windows().createAndPushWindow(int3(mapGenOptions->getWidth(), mapGenOptions->getWidth(), mapGenOptions->getLevels()), [this, setTemplateForSize](int3 ret){ + if(ret.z > 2) + { + std::shared_ptr temp = CInfoWindow::create(LIBRARY->generaltexth->translate("vcmi.lobby.customRmgSize.experimental"), PlayerColor(0), {}); //TODO: multilevel support + ENGINE->windows().pushWindow(temp); + } + mapGenOptions->setWidth(ret.x); + mapGenOptions->setHeight(ret.y); + mapGenOptions->setLevels(ret.z); + setTemplateForSize(); + }); + return; + } + mapGenOptions->setWidth(mapSizeVal[btnId]); mapGenOptions->setHeight(mapSizeVal[btnId]); - if(mapGenOptions->getMapTemplate()) - if(!mapGenOptions->getMapTemplate()->matchesSize(int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), mapGenOptions->getLevels()})) - setTemplate(nullptr); - updateMapInfoByHost(); + setTemplateForSize(); }); addCallback("toggleTwoLevels", [&](bool on) { - mapGenOptions->setLevels(on ? 2 : 1); // TODO: multilevel support + mapGenOptions->setLevels(on ? 2 : 1); if(mapGenOptions->getMapTemplate()) if(!mapGenOptions->getMapTemplate()->matchesSize(int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), mapGenOptions->getLevels()})) setTemplate(nullptr); @@ -345,18 +372,19 @@ void RandomMapTab::setMapGenOptions(std::shared_ptr opts) if(auto w = widget("groupMapSize")) { + const auto & mapSizes = getPossibleMapSizes(); for(auto toggle : w->buttons) { if(auto button = std::dynamic_pointer_cast(toggle.second)) { - const auto & mapSizes = getPossibleMapSizes(); int3 size( mapSizes[toggle.first], mapSizes[toggle.first], mapGenOptions->getLevels()); bool sizeAllowed = !mapGenOptions->getMapTemplate() || mapGenOptions->getMapTemplate()->matchesSize(size); - button->block(!sizeAllowed); + button->block(!sizeAllowed && !(toggle.first == mapSizes.size() - 1)); } } - w->setSelected(vstd::find_pos(getPossibleMapSizes(), opts->getWidth())); + auto position = vstd::find_pos(getPossibleMapSizes(), opts->getWidth()); + w->setSelected(position == mapSizes.size() - 1 ? -1 : position); } if(auto w = widget("buttonTwoLevels")) { @@ -366,7 +394,7 @@ void RandomMapTab::setMapGenOptions(std::shared_ptr opts) auto sizes = mapGenOptions->getMapTemplate()->getMapSizes(); possibleLevelCount = sizes.second.z - sizes.first.z + 1; } - w->setSelected(opts->getLevels() == 2); // TODO: multilevel support + w->setSelectedSilent(opts->getLevels() == 2); w->block(possibleLevelCount < 2); } if(auto w = widget("groupMaxPlayers")) @@ -653,3 +681,37 @@ void RandomMapTab::loadOptions() // TODO: Save & load difficulty? } + +SetSizeWindow::SetSizeWindow(int3 initSize, std::function cb) + : CWindowObject(BORDERED) +{ + OBJECT_CONSTRUCTION; + + pos.w = 200; + pos.h = 122; + + updateShadow(); + center(); + + background = std::make_shared(Rect(0, 0, pos.w, pos.h)); + background->setPlayerColor(PlayerColor(1)); + buttonOk = std::make_shared(Point(68, 80), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this, cb](){ + close(); + if(cb) + cb(int3(std::max(1, std::stoi(numInputs[0]->getText())), std::max(1, std::stoi(numInputs[1]->getText())), std::max(1, std::stoi(numInputs[2]->getText())))); + }, EShortcut::GLOBAL_ACCEPT); + + titles.push_back(std::make_shared(100, 15, FONT_BIG, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->translate("vcmi.lobby.customRmgSize.title"))); + + for(int i = 0; i < 3; i++) + { + Rect r(30 + i * 50, 50, 40, 20); + rectangles.push_back(std::make_shared(r, ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1)); + titles.push_back(std::make_shared(50 + i * 50, 40, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->translate("vcmi.lobby.customRmgSize." + std::to_string(i)))); + numInputs.push_back(std::make_shared(r, EFonts::FONT_SMALL, ETextAlignment::CENTER, false)); + numInputs.back()->setFilterNumber(0, i < 2 ? 999 : 9); + } + numInputs[0]->setText(std::to_string(initSize.x)); + numInputs[1]->setText(std::to_string(initSize.y)); + numInputs[2]->setText(std::to_string(initSize.z)); +} diff --git a/client/lobby/RandomMapTab.h b/client/lobby/RandomMapTab.h index 4e199e410..dae74eea6 100644 --- a/client/lobby/RandomMapTab.h +++ b/client/lobby/RandomMapTab.h @@ -27,6 +27,8 @@ class CLabel; class CLabelGroup; class CSlider; class CPicture; +class CTextInput; +class TransparentFilledRectangle; class RandomMapTab : public InterfaceObjectConfigurable { @@ -81,3 +83,15 @@ class TeamAlignments: public CWindowObject public: TeamAlignments(RandomMapTab & randomMapTab); }; + +class SetSizeWindow: public CWindowObject +{ + std::shared_ptr background; + std::vector> titles; + std::shared_ptr buttonOk; + + std::vector> numInputs; + std::vector> rectangles; +public: + SetSizeWindow(int3 initSize, std::function cb); +};