1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Multiplayer: add sync for RMG options in lobby

Sadly I'm not yet find proper way to block all buttons in CToggleGroup without make them invisible so it's still possible to press buttons for guest. Though CRandomMapTab::updateMapInfo is now disabled for guest so even if guest going to press multiple buttons it's not going to cause crash for him.
This commit is contained in:
ArseniyShestakov 2015-03-13 23:33:46 +03:00
parent 67aa869a33
commit eeff8f3ea4
2 changed files with 42 additions and 8 deletions

View File

@ -1008,6 +1008,9 @@ void CSelectionScreen::setSInfo(const StartInfo &si)
card->difficulty->setSelected(si.difficulty);
if(curTab == randMapTab)
randMapTab->setMapGenOptions(si.mapGenOptions);
GH.totalRedraw();
}
@ -1642,16 +1645,22 @@ CRandomMapTab::CRandomMapTab()
mapSizeBtnGroup->setSelected(1);
mapSizeBtnGroup->addCallback([&](int btnId)
{
const std::vector<int> mapSizeVal = {CMapHeader::MAP_SIZE_SMALL,CMapHeader::MAP_SIZE_MIDDLE,CMapHeader::MAP_SIZE_LARGE,CMapHeader::MAP_SIZE_XLARGE};
auto mapSizeVal = getPossibleMapSizes();
mapGenOptions.setWidth(mapSizeVal[btnId]);
mapGenOptions.setHeight(mapSizeVal[btnId]);
updateMapInfo();
if(!SEL->isGuest())
updateMapInfo();
});
// Two levels
twoLevelsBtn = new CToggleButton(Point(346, 81), "RANUNDR", CGI->generaltexth->zelp[202]);
//twoLevelsBtn->select(true); for now, deactivated
twoLevelsBtn->addCallback([&](bool on) { mapGenOptions.setHasTwoLevels(on); updateMapInfo(); });
twoLevelsBtn->addCallback([&](bool on)
{
mapGenOptions.setHasTwoLevels(on);
if(!SEL->isGuest())
updateMapInfo();
});
// Create number defs list
std::vector<std::string> numberDefs;
@ -1673,7 +1682,8 @@ CRandomMapTab::CRandomMapTab()
deactivateButtonsFrom(teamsCntGroup, btnId);
deactivateButtonsFrom(compOnlyPlayersCntGroup, 8 - btnId + 1);
validatePlayersCnt(btnId);
updateMapInfo();
if(!SEL->isGuest())
updateMapInfo();
});
// Amount of teams
@ -1684,7 +1694,8 @@ CRandomMapTab::CRandomMapTab()
teamsCntGroup->addCallback([&](int btnId)
{
mapGenOptions.setTeamCount(btnId);
updateMapInfo();
if(!SEL->isGuest())
updateMapInfo();
});
// Computer only players
@ -1698,7 +1709,8 @@ CRandomMapTab::CRandomMapTab()
mapGenOptions.setCompOnlyPlayerCount(btnId);
deactivateButtonsFrom(compOnlyTeamsCntGroup, btnId);
validateCompOnlyPlayersCnt(btnId);
updateMapInfo();
if(!SEL->isGuest())
updateMapInfo();
});
// Computer only teams
@ -1710,7 +1722,8 @@ CRandomMapTab::CRandomMapTab()
compOnlyTeamsCntGroup->addCallback([&](int btnId)
{
mapGenOptions.setCompOnlyTeamCount(btnId);
updateMapInfo();
if(!SEL->isGuest())
updateMapInfo();
});
const int WIDE_BTN_WIDTH = 85;
@ -1743,7 +1756,8 @@ CRandomMapTab::CRandomMapTab()
showRandMaps = new CButton(Point(54, 535), "RANSHOW", CGI->generaltexth->zelp[252]);
// Initialize map info object
updateMapInfo();
if(!SEL->isGuest())
updateMapInfo();
}
void CRandomMapTab::addButtonsWithRandToGroup(CToggleGroup * group, const std::vector<std::string> & defs, int nStart, int nEnd, int btnWidth, int helpStartIndex, int helpRandIndex) const
@ -1826,6 +1840,11 @@ void CRandomMapTab::validateCompOnlyPlayersCnt(int compOnlyPlayersCnt)
}
}
std::vector<int> CRandomMapTab::getPossibleMapSizes()
{
return {CMapHeader::MAP_SIZE_SMALL,CMapHeader::MAP_SIZE_MIDDLE,CMapHeader::MAP_SIZE_LARGE,CMapHeader::MAP_SIZE_XLARGE};
}
void CRandomMapTab::showAll(SDL_Surface * to)
{
CIntObject::showAll(to);
@ -1914,6 +1933,18 @@ const CMapGenOptions & CRandomMapTab::getMapGenOptions() const
return mapGenOptions;
}
void CRandomMapTab::setMapGenOptions(shared_ptr<CMapGenOptions> opts)
{
mapSizeBtnGroup->setSelected(vstd::find_pos(getPossibleMapSizes(), opts->getWidth()));
twoLevelsBtn->setSelected(opts->getHasTwoLevels());
playersCntGroup->setSelected(opts->getPlayerCount());
teamsCntGroup->setSelected(opts->getTeamCount());
compOnlyPlayersCntGroup->setSelected(opts->getCompOnlyPlayerCount());
compOnlyTeamsCntGroup->setSelected(opts->getCompOnlyTeamCount());
waterContentGroup->setSelected(opts->getWaterContent());
monsterStrengthGroup->setSelected(opts->getMonsterStrength());
}
CChatBox::CChatBox(const Rect &rect)
{
OBJ_CONSTRUCTION;
@ -3935,6 +3966,7 @@ void PlayerJoined::apply(CSelectionScreen *selScreen)
selScreen->propagateNames();
selScreen->propagateOptions();
selScreen->toggleTab(selScreen->curTab);
GH.totalRedraw();
}

View File

@ -300,6 +300,7 @@ public:
CFunctionList<void (const CMapInfo *)> & getMapInfoChanged();
const CMapInfo * getMapInfo() const;
const CMapGenOptions & getMapGenOptions() const;
void setMapGenOptions(shared_ptr<CMapGenOptions> opts);
private:
void addButtonsToGroup(CToggleGroup * group, const std::vector<std::string> & defs, int startIndex, int endIndex, int btnWidth, int helpStartIndex) const;
@ -307,6 +308,7 @@ private:
void deactivateButtonsFrom(CToggleGroup * group, int startId);
void validatePlayersCnt(int playersCnt);
void validateCompOnlyPlayersCnt(int compOnlyPlayersCnt);
std::vector<int> getPossibleMapSizes();
CPicture * bg;
CToggleButton * twoLevelsBtn;