1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/client/lobby/RandomMapTab.cpp

572 lines
17 KiB
C++
Raw Normal View History

/*
* RandomMapTab.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "RandomMapTab.h"
#include "CSelectionBase.h"
2023-10-21 02:12:34 +02:00
#include "CLobbyScreen.h"
#include "SelectionTab.h"
#include "../CGameInfo.h"
#include "../CServerHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/MouseButton.h"
#include "../gui/WindowHandler.h"
#include "../widgets/CComponent.h"
2023-08-25 12:07:38 +02:00
#include "../widgets/ComboBox.h"
#include "../widgets/Buttons.h"
#include "../widgets/MiscWidgets.h"
#include "../widgets/ObjectLists.h"
2023-05-30 16:31:45 +02:00
#include "../widgets/Slider.h"
#include "../widgets/TextControls.h"
#include "../windows/GUIClasses.h"
#include "../windows/InfoWindows.h"
#include "../../lib/CGeneralTextHandler.h"
#include "../../lib/mapping/CMapInfo.h"
2023-05-24 01:05:59 +02:00
#include "../../lib/mapping/CMapHeader.h"
2023-05-24 00:14:06 +02:00
#include "../../lib/mapping/MapFormat.h"
#include "../../lib/rmg/CMapGenOptions.h"
2022-12-13 02:38:18 +02:00
#include "../../lib/rmg/CRmgTemplateStorage.h"
2023-03-15 21:34:29 +02:00
#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/RoadHandler.h"
2022-12-12 01:27:59 +02:00
RandomMapTab::RandomMapTab():
2022-12-12 09:48:39 +02:00
InterfaceObjectConfigurable()
{
recActions = 0;
mapGenOptions = std::make_shared<CMapGenOptions>();
2022-12-12 01:27:59 +02:00
addCallback("toggleMapSize", [&](int btnId)
{
auto mapSizeVal = getPossibleMapSizes();
mapGenOptions->setWidth(mapSizeVal[btnId]);
mapGenOptions->setHeight(mapSizeVal[btnId]);
2022-12-14 03:23:21 +02:00
if(mapGenOptions->getMapTemplate())
if(!mapGenOptions->getMapTemplate()->matchesSize(int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()}))
setTemplate(nullptr);
updateMapInfoByHost();
});
2022-12-12 01:27:59 +02:00
addCallback("toggleTwoLevels", [&](bool on)
{
mapGenOptions->setHasTwoLevels(on);
2022-12-14 03:23:21 +02:00
if(mapGenOptions->getMapTemplate())
if(!mapGenOptions->getMapTemplate()->matchesSize(int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()}))
setTemplate(nullptr);
updateMapInfoByHost();
});
2022-12-12 01:27:59 +02:00
addCallback("setPlayersCount", [&](int btnId)
{
2023-10-28 20:30:38 +02:00
mapGenOptions->setHumanOrCpuPlayerCount(btnId);
2022-12-14 02:37:11 +02:00
setMapGenOptions(mapGenOptions);
updateMapInfoByHost();
});
2022-12-12 01:27:59 +02:00
addCallback("setTeamsCount", [&](int btnId)
{
mapGenOptions->setTeamCount(btnId);
updateMapInfoByHost();
});
2022-12-12 01:27:59 +02:00
addCallback("setCompOnlyPlayers", [&](int btnId)
{
mapGenOptions->setCompOnlyPlayerCount(btnId);
2022-12-14 02:37:11 +02:00
setMapGenOptions(mapGenOptions);
updateMapInfoByHost();
});
2022-12-12 01:27:59 +02:00
addCallback("setCompOnlyTeams", [&](int btnId)
{
mapGenOptions->setCompOnlyTeamCount(btnId);
updateMapInfoByHost();
});
2022-12-12 01:27:59 +02:00
addCallback("setWaterContent", [&](int btnId)
{
mapGenOptions->setWaterContent(static_cast<EWaterContent::EWaterContent>(btnId));
updateMapInfoByHost();
});
2022-12-12 01:27:59 +02:00
2022-12-12 09:38:27 +02:00
addCallback("setMonsterStrength", [&](int btnId)
{
if(btnId < 0)
mapGenOptions->setMonsterStrength(EMonsterStrength::RANDOM);
else
mapGenOptions->setMonsterStrength(static_cast<EMonsterStrength::EMonsterStrength>(btnId)); //value 2 to 4
updateMapInfoByHost();
});
2022-12-12 01:27:59 +02:00
2022-12-13 01:47:29 +02:00
//new callbacks available only from mod
2022-12-15 22:46:36 +02:00
addCallback("teamAlignments", [&](int)
{
2023-10-22 15:00:04 +02:00
GH.windows().createAndPushWindow<TeamAlignments>(*this);
2022-12-15 22:46:36 +02:00
});
for(auto road : VLC->roadTypeHandler->objects)
2022-12-15 22:46:36 +02:00
{
std::string cbRoadType = "selectRoad_" + road->getJsonKey();
addCallback(cbRoadType, [&, road](bool on)
2022-12-15 22:46:36 +02:00
{
mapGenOptions->setRoadEnabled(road->getId(), on);
updateMapInfoByHost();
2022-12-15 22:46:36 +02:00
});
}
const JsonNode config(JsonPath::builtin("config/widgets/randomMapTab.json"));
2022-12-25 12:22:07 +02:00
build(config);
2022-12-12 01:27:59 +02:00
2023-10-21 02:12:34 +02:00
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);
});
}
2023-08-25 12:07:38 +02:00
//set combo box callbacks
if(auto w = widget<ComboBox>("templateList"))
{
w->onConstructItems = [](std::vector<const void *> & curItems){
auto templates = VLC->tplh->getTemplates();
boost::range::sort(templates, [](const CRmgTemplate * a, const CRmgTemplate * b){
return a->getName() < b->getName();
});
curItems.push_back(nullptr); //default template
for(auto & t : templates)
curItems.push_back(t);
};
w->onSetItem = [&](const void * item){
this->setTemplate(reinterpret_cast<const CRmgTemplate *>(item));
};
w->getItemText = [this](int idx, const void * item){
if(item)
return reinterpret_cast<const CRmgTemplate *>(item)->getName();
if(idx == 0)
return readText(variables["randomTemplate"]);
return std::string("");
};
}
updateMapInfoByHost();
}
void RandomMapTab::updateMapInfoByHost()
{
if(CSH->isGuest())
return;
// Generate header info
mapInfo = std::make_shared<CMapInfo>();
mapInfo->isRandomMap = true;
2022-12-07 23:36:20 +02:00
mapInfo->mapHeader = std::make_unique<CMapHeader>();
mapInfo->mapHeader->version = EMapFormat::VCMI;
2023-09-27 22:53:13 +02:00
mapInfo->mapHeader->name.appendLocalString(EMetaText::GENERAL_TXT, 740);
mapInfo->mapHeader->description.appendLocalString(EMetaText::GENERAL_TXT, 741);
const auto * temp = mapGenOptions->getMapTemplate();
if (temp)
{
auto randomTemplateDescription = temp->getDescription();
if (!randomTemplateDescription.empty())
{
auto description = std::string("\n\n") + randomTemplateDescription;
mapInfo->mapHeader->description.appendRawString(description);
}
}
mapInfo->mapHeader->difficulty = EMapDifficulty::NORMAL;
mapInfo->mapHeader->height = mapGenOptions->getHeight();
mapInfo->mapHeader->width = mapGenOptions->getWidth();
mapInfo->mapHeader->twoLevel = mapGenOptions->getHasTwoLevels();
// Generate player information
int playersToGen = mapGenOptions->getMaxPlayersCount();
mapInfo->mapHeader->howManyTeams = playersToGen;
2023-10-29 11:05:24 +02:00
//TODO: Assign all human-controlled colors in first place
2023-07-24 08:44:37 +02:00
for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
{
mapInfo->mapHeader->players[i].canComputerPlay = false;
mapInfo->mapHeader->players[i].canHumanPlay = false;
}
2023-10-28 20:30:38 +02:00
std::vector<PlayerColor> availableColors;
for (ui8 color = 0; color < PlayerColor::PLAYER_LIMIT_I; color++)
{
2023-10-28 20:30:38 +02:00
availableColors.push_back(PlayerColor(color));
}
2023-10-28 20:30:38 +02:00
//First restore known players
for (auto& player : mapGenOptions->getPlayersSettings())
{
PlayerInfo playerInfo;
playerInfo.isFactionRandom = (player.second.getStartingTown() == FactionID::RANDOM);
2023-10-28 20:30:38 +02:00
playerInfo.canComputerPlay = (player.second.getPlayerType() != EPlayerType::HUMAN);
playerInfo.canHumanPlay = (player.second.getPlayerType() != EPlayerType::COMP_ONLY);
auto team = player.second.getTeam();
playerInfo.team = team;
playerInfo.hasMainTown = true;
playerInfo.generateHeroAtMainTown = true;
mapInfo->mapHeader->players[player.first] = playerInfo;
vstd::erase(availableColors, player.first);
}
mapInfoChanged(mapInfo, mapGenOptions);
}
void RandomMapTab::setMapGenOptions(std::shared_ptr<CMapGenOptions> opts)
{
2022-12-14 02:37:11 +02:00
mapGenOptions = opts;
2023-10-28 20:30:38 +02:00
//Prepare allowed options - add all, then erase the ones above the limit
2022-12-14 02:37:11 +02:00
for(int i = 0; i <= PlayerColor::PLAYER_LIMIT_I; ++i)
{
playerCountAllowed.insert(i);
compCountAllowed.insert(i);
if (i >= 2)
{
playerTeamsAllowed.insert(i);
}
if (i >= 1)
{
compTeamsAllowed.insert(i);
}
2022-12-14 02:37:11 +02:00
}
std::set<int> humanCountAllowed;
2023-10-28 20:30:38 +02:00
2022-12-14 02:37:11 +02:00
auto * tmpl = mapGenOptions->getMapTemplate();
if(tmpl)
{
2023-10-29 11:05:24 +02:00
playerCountAllowed = tmpl->getPlayers().getNumbers();
humanCountAllowed = tmpl->getHumanPlayers().getNumbers(); // Unused now?
2022-12-14 02:37:11 +02:00
}
2023-10-28 20:30:38 +02:00
si8 playerLimit = opts->getMaxPlayersCount();
2023-10-28 20:30:38 +02:00
si8 humanOrCpuPlayerCount = opts->getHumanOrCpuPlayerCount();
2023-10-29 11:05:24 +02:00
si8 compOnlyPlayersCount = opts->getCompOnlyPlayerCount();
2023-10-28 20:30:38 +02:00
2023-10-29 11:05:24 +02:00
if(humanOrCpuPlayerCount != CMapGenOptions::RANDOM_SIZE)
2022-12-14 02:37:11 +02:00
{
2023-10-28 20:30:38 +02:00
vstd::erase_if(compCountAllowed, [playerLimit, humanOrCpuPlayerCount](int el)
{
return (playerLimit - humanOrCpuPlayerCount) < el;
2022-12-14 02:37:11 +02:00
});
2023-10-28 20:30:38 +02:00
vstd::erase_if(playerTeamsAllowed, [humanOrCpuPlayerCount](int el)
{
return humanOrCpuPlayerCount <= el;
2022-12-14 02:37:11 +02:00
});
}
else // Random
{
2023-10-30 22:33:49 +02:00
vstd::erase_if(compCountAllowed, [playerLimit](int el)
2023-10-28 20:30:38 +02:00
{
return (playerLimit - 1) < el; // Must leave at least 1 human player
});
vstd::erase_if(playerTeamsAllowed, [playerLimit](int el)
{
return playerLimit <= el;
});
}
if(!playerTeamsAllowed.count(opts->getTeamCount()))
{
opts->setTeamCount(CMapGenOptions::RANDOM_SIZE);
2022-12-14 02:37:11 +02:00
}
2023-10-29 11:05:24 +02:00
if(compOnlyPlayersCount != CMapGenOptions::RANDOM_SIZE)
2022-12-14 02:37:11 +02:00
{
2023-10-28 20:30:38 +02:00
// This setting doesn't impact total number of players
vstd::erase_if(compTeamsAllowed, [compOnlyPlayersCount](int el)
{
return compOnlyPlayersCount<= el;
2022-12-14 02:37:11 +02:00
});
2022-12-14 03:45:50 +02:00
if(!compTeamsAllowed.count(opts->getCompOnlyTeamCount()))
2023-10-28 20:30:38 +02:00
{
2022-12-14 03:45:50 +02:00
opts->setCompOnlyTeamCount(CMapGenOptions::RANDOM_SIZE);
2023-10-28 20:30:38 +02:00
}
2022-12-14 02:37:11 +02:00
}
2022-12-12 09:38:27 +02:00
if(auto w = widget<CToggleGroup>("groupMapSize"))
{
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], 1 + mapGenOptions->getHasTwoLevels());
bool sizeAllowed = !mapGenOptions->getMapTemplate() || mapGenOptions->getMapTemplate()->matchesSize(size);
button->block(!sizeAllowed);
}
}
2022-12-12 01:58:39 +02:00
w->setSelected(vstd::find_pos(getPossibleMapSizes(), opts->getWidth()));
}
2022-12-12 09:38:27 +02:00
if(auto w = widget<CToggleButton>("buttonTwoLevels"))
{
int3 size( opts->getWidth(), opts->getWidth(), 2);
bool undergoundAllowed = !mapGenOptions->getMapTemplate() || mapGenOptions->getMapTemplate()->matchesSize(size);
2022-12-12 01:58:39 +02:00
w->setSelected(opts->getHasTwoLevels());
w->block(!undergoundAllowed);
}
2022-12-12 09:38:27 +02:00
if(auto w = widget<CToggleGroup>("groupMaxPlayers"))
2022-12-14 02:37:11 +02:00
{
2023-10-28 20:30:38 +02:00
w->setSelected(opts->getHumanOrCpuPlayerCount());
2022-12-14 02:37:11 +02:00
deactivateButtonsFrom(*w, playerCountAllowed);
}
2022-12-12 09:38:27 +02:00
if(auto w = widget<CToggleGroup>("groupMaxTeams"))
2022-12-14 02:37:11 +02:00
{
2022-12-12 01:58:39 +02:00
w->setSelected(opts->getTeamCount());
2022-12-14 03:23:21 +02:00
deactivateButtonsFrom(*w, playerTeamsAllowed);
2022-12-14 02:37:11 +02:00
}
2022-12-12 09:38:27 +02:00
if(auto w = widget<CToggleGroup>("groupCompOnlyPlayers"))
2022-12-14 02:37:11 +02:00
{
2022-12-12 01:58:39 +02:00
w->setSelected(opts->getCompOnlyPlayerCount());
2022-12-14 03:23:21 +02:00
deactivateButtonsFrom(*w, compCountAllowed);
2022-12-14 02:37:11 +02:00
}
2022-12-12 09:38:27 +02:00
if(auto w = widget<CToggleGroup>("groupCompOnlyTeams"))
2022-12-14 02:37:11 +02:00
{
2022-12-12 01:58:39 +02:00
w->setSelected(opts->getCompOnlyTeamCount());
2022-12-14 02:37:11 +02:00
deactivateButtonsFrom(*w, compTeamsAllowed);
}
2022-12-12 09:38:27 +02:00
if(auto w = widget<CToggleGroup>("groupWaterContent"))
2022-12-14 02:37:11 +02:00
{
2022-12-12 01:58:39 +02:00
w->setSelected(opts->getWaterContent());
2022-12-14 02:37:11 +02:00
if(opts->getMapTemplate())
{
std::set<int> allowedWater(opts->getMapTemplate()->getWaterContentAllowed().begin(), opts->getMapTemplate()->getWaterContentAllowed().end());
deactivateButtonsFrom(*w, allowedWater);
}
else
deactivateButtonsFrom(*w, {-1});
}
2022-12-12 09:38:27 +02:00
if(auto w = widget<CToggleGroup>("groupMonsterStrength"))
2022-12-12 01:58:39 +02:00
w->setSelected(opts->getMonsterStrength());
2022-12-17 06:38:33 +02:00
if(auto w = widget<CButton>("templateButton"))
{
if(tmpl)
w->addTextOverlay(tmpl->getName(), EFonts::FONT_SMALL, Colors::WHITE);
2022-12-17 06:38:33 +02:00
else
w->addTextOverlay(readText(variables["randomTemplate"]), EFonts::FONT_SMALL, Colors::WHITE);
2022-12-17 06:38:33 +02:00
}
for(auto r : VLC->roadTypeHandler->objects)
2022-12-17 06:38:33 +02:00
{
2023-12-21 16:09:01 +02:00
// Workaround for vcmi-extras bug
std::string jsonKey = r->getJsonKey();
std::string identifier = jsonKey.substr(jsonKey.find(':')+1);
if(auto w = widget<CToggleButton>(identifier))
2022-12-17 06:38:33 +02:00
{
w->setSelected(opts->isRoadEnabled(r->getId()));
2022-12-17 06:38:33 +02:00
}
}
}
2022-12-13 02:38:18 +02:00
void RandomMapTab::setTemplate(const CRmgTemplate * tmpl)
{
mapGenOptions->setMapTemplate(tmpl);
2022-12-14 02:37:11 +02:00
setMapGenOptions(mapGenOptions);
2022-12-13 02:38:18 +02:00
if(auto w = widget<CButton>("templateButton"))
{
if(tmpl)
w->addTextOverlay(tmpl->getName(), EFonts::FONT_SMALL, Colors::WHITE);
2022-12-13 02:38:18 +02:00
else
w->addTextOverlay(readText(variables["randomTemplate"]), EFonts::FONT_SMALL, Colors::WHITE);
2022-12-13 02:38:18 +02:00
}
2022-12-14 02:37:11 +02:00
updateMapInfoByHost();
}
void RandomMapTab::deactivateButtonsFrom(CToggleGroup & group, const std::set<int> & allowed)
{
2022-12-14 02:37:11 +02:00
logGlobal->debug("Blocking buttons");
for(auto toggle : group.buttons)
{
if(auto button = std::dynamic_pointer_cast<CToggleButton>(toggle.second))
{
2022-12-14 02:37:11 +02:00
if(allowed.count(CMapGenOptions::RANDOM_SIZE)
|| allowed.count(toggle.first)
|| toggle.first == CMapGenOptions::RANDOM_SIZE)
{
button->block(false);
}
else
{
button->block(true);
}
}
}
}
std::vector<int> RandomMapTab::getPossibleMapSizes()
{
2022-12-12 02:46:42 +02:00
return {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_GIANT};
}
2022-12-13 01:47:29 +02:00
void TeamAlignmentsWidget::checkTeamCount()
{
//Do not allow to select one team only
std::set<TeamID> teams;
for (int plId = 0; plId < players.size(); ++plId)
{
teams.insert(TeamID(players[plId]->getSelected()));
}
if (teams.size() < 2)
{
//Do not let player close the window
buttonOk->block(true);
}
else
{
buttonOk->block(false);
}
}
2023-10-22 15:00:04 +02:00
TeamAlignments::TeamAlignments(RandomMapTab & randomMapTab)
: CWindowObject(BORDERED)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
widget = std::make_shared<TeamAlignmentsWidget>(randomMapTab);
pos = widget->pos;
updateShadow();
center();
}
TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab):
2022-12-30 01:35:16 +02:00
InterfaceObjectConfigurable()
{
const JsonNode config(JsonPath::builtin("config/widgets/randomMapTeamsWidget.json"));
variables = config["variables"];
//int totalPlayers = randomMapTab.obtainMapGenOptions().getPlayerLimit();
int totalPlayers = randomMapTab.obtainMapGenOptions().getMaxPlayersCount();
2022-12-17 06:19:16 +02:00
assert(totalPlayers <= PlayerColor::PLAYER_LIMIT_I);
auto settings = randomMapTab.obtainMapGenOptions().getPlayersSettings();
variables["totalPlayers"].Integer() = totalPlayers;
pos.w = variables["windowSize"]["x"].Integer() + totalPlayers * variables["cellMargin"]["x"].Integer();
pos.h = variables["windowSize"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer();
2023-10-24 18:51:58 +02:00
variables["backgroundRect"]["x"].Integer() = 0;
variables["backgroundRect"]["y"].Integer() = 0;
variables["backgroundRect"]["w"].Integer() = pos.w;
variables["backgroundRect"]["h"].Integer() = pos.h;
variables["okButtonPosition"]["x"].Integer() = variables["buttonsOffset"]["ok"]["x"].Integer();
variables["okButtonPosition"]["y"].Integer() = variables["buttonsOffset"]["ok"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer();
variables["cancelButtonPosition"]["x"].Integer() = variables["buttonsOffset"]["cancel"]["x"].Integer();
variables["cancelButtonPosition"]["y"].Integer() = variables["buttonsOffset"]["cancel"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer();
addCallback("ok", [&](int)
{
for(int plId = 0; plId < players.size(); ++plId)
{
randomMapTab.obtainMapGenOptions().setPlayerTeam(PlayerColor(plId), TeamID(players[plId]->getSelected()));
}
randomMapTab.updateMapInfoByHost();
2023-10-22 15:00:04 +02:00
for(auto & window : GH.windows().findWindows<TeamAlignments>())
GH.windows().popWindow(window);
});
addCallback("cancel", [&](int)
{
2023-10-22 15:00:04 +02:00
for(auto & window : GH.windows().findWindows<TeamAlignments>())
GH.windows().popWindow(window);
});
2022-12-25 12:22:07 +02:00
build(config);
2022-12-17 06:19:16 +02:00
center(pos);
OBJ_CONSTRUCTION;
// Window should have X * X columns, where X is max players allowed for current settings
2023-10-28 20:30:38 +02:00
// For random player count, X is 8
if (totalPlayers > settings.size())
{
auto savedPlayers = randomMapTab.obtainMapGenOptions().getSavedPlayersMap();
for (const auto & player : savedPlayers)
{
if (!vstd::contains(settings, player.first))
{
settings[player.first] = player.second;
}
}
}
std::vector<CMapGenOptions::CPlayerSettings> settingsVec;
for (const auto & player : settings)
{
settingsVec.push_back(player.second);
}
2022-12-17 06:19:16 +02:00
for(int plId = 0; plId < totalPlayers; ++plId)
{
players.push_back(std::make_shared<CToggleGroup>([&, totalPlayers, plId](int sel)
{
variables["player_id"].Integer() = plId;
OBJ_CONSTRUCTION_TARGETED(players[plId].get());
2022-12-17 06:19:16 +02:00
for(int teamId = 0; teamId < totalPlayers; ++teamId)
{
auto button = std::dynamic_pointer_cast<CToggleButton>(players[plId]->buttons[teamId]);
assert(button);
if(sel == teamId)
{
button->addOverlay(buildWidget(variables["flagsAnimation"]));
2022-12-17 06:19:16 +02:00
}
else
{
2022-12-17 18:50:33 +02:00
button->addOverlay(nullptr);
2022-12-17 06:19:16 +02:00
}
button->addCallback([this](bool)
{
checkTeamCount();
});
2022-12-17 06:19:16 +02:00
}
}));
OBJ_CONSTRUCTION_TARGETED(players.back().get());
2023-10-28 20:30:38 +02:00
2022-12-17 06:19:16 +02:00
for(int teamId = 0; teamId < totalPlayers; ++teamId)
{
variables["point"]["x"].Integer() = variables["cellOffset"]["x"].Integer() + plId * variables["cellMargin"]["x"].Integer();
variables["point"]["y"].Integer() = variables["cellOffset"]["y"].Integer() + teamId * variables["cellMargin"]["y"].Integer();
auto button = buildWidget(variables["button"]);
players.back()->addToggle(teamId, std::dynamic_pointer_cast<CToggleBase>(button));
2022-12-17 06:19:16 +02:00
}
2023-10-28 20:30:38 +02:00
// plId is not neccessarily player color, just an index
auto team = settingsVec.at(plId).getTeam();
2022-12-17 06:19:16 +02:00
if(team == TeamID::NO_TEAM)
2023-10-28 20:30:38 +02:00
{
logGlobal->warn("Player %d (id %d) has uninitialized team", settingsVec.at(plId).getColor(), plId);
2022-12-17 06:19:16 +02:00
players.back()->setSelected(plId);
2023-10-28 20:30:38 +02:00
}
2022-12-17 06:19:16 +02:00
else
players.back()->setSelected(team.getNum());
}
buttonOk = widget<CButton>("buttonOK");
buttonCancel = widget<CButton>("buttonCancel");
}