1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

possiblity to set custom sizes with last button

This commit is contained in:
Laserlicht
2025-11-13 02:14:42 +01:00
parent d0273ae0ab
commit 9eae52574b
4 changed files with 96 additions and 10 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -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<CMapGenOptions>();
addCallback("toggleMapSize", [&](int btnId)
addCallback("toggleMapSize", [this](int btnId)
{
if(btnId == -1)
return;
auto mapSizeVal = getPossibleMapSizes();
mapGenOptions->setWidth(mapSizeVal[btnId]);
mapGenOptions->setHeight(mapSizeVal[btnId]);
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<SetSizeWindow>(int3(mapGenOptions->getWidth(), mapGenOptions->getWidth(), mapGenOptions->getLevels()), [this, setTemplateForSize](int3 ret){
if(ret.z > 2)
{
std::shared_ptr<CInfoWindow> 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]);
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<CMapGenOptions> opts)
if(auto w = widget<CToggleGroup>("groupMapSize"))
{
const auto & mapSizes = getPossibleMapSizes();
for(auto toggle : w->buttons)
{
if(auto button = std::dynamic_pointer_cast<CToggleButton>(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<CToggleButton>("buttonTwoLevels"))
{
@@ -366,7 +394,7 @@ void RandomMapTab::setMapGenOptions(std::shared_ptr<CMapGenOptions> 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<CToggleGroup>("groupMaxPlayers"))
@@ -653,3 +681,37 @@ void RandomMapTab::loadOptions()
// TODO: Save & load difficulty?
}
SetSizeWindow::SetSizeWindow(int3 initSize, std::function<void(int3)> cb)
: CWindowObject(BORDERED)
{
OBJECT_CONSTRUCTION;
pos.w = 200;
pos.h = 122;
updateShadow();
center();
background = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
background->setPlayerColor(PlayerColor(1));
buttonOk = std::make_shared<CButton>(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<CLabel>(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<TransparentFilledRectangle>(r, ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1));
titles.push_back(std::make_shared<CLabel>(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<CTextInput>(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));
}

View File

@@ -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<FilledTexturePlayerColored> background;
std::vector<std::shared_ptr<CLabel>> titles;
std::shared_ptr<CButton> buttonOk;
std::vector<std::shared_ptr<CTextInput>> numInputs;
std::vector<std::shared_ptr<TransparentFilledRectangle>> rectangles;
public:
SetSizeWindow(int3 initSize, std::function<void(int3)> cb);
};