mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-23 21:29:13 +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:
parent
67aa869a33
commit
eeff8f3ea4
client
@ -1008,6 +1008,9 @@ void CSelectionScreen::setSInfo(const StartInfo &si)
|
|||||||
|
|
||||||
card->difficulty->setSelected(si.difficulty);
|
card->difficulty->setSelected(si.difficulty);
|
||||||
|
|
||||||
|
if(curTab == randMapTab)
|
||||||
|
randMapTab->setMapGenOptions(si.mapGenOptions);
|
||||||
|
|
||||||
GH.totalRedraw();
|
GH.totalRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1642,16 +1645,22 @@ CRandomMapTab::CRandomMapTab()
|
|||||||
mapSizeBtnGroup->setSelected(1);
|
mapSizeBtnGroup->setSelected(1);
|
||||||
mapSizeBtnGroup->addCallback([&](int btnId)
|
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.setWidth(mapSizeVal[btnId]);
|
||||||
mapGenOptions.setHeight(mapSizeVal[btnId]);
|
mapGenOptions.setHeight(mapSizeVal[btnId]);
|
||||||
updateMapInfo();
|
if(!SEL->isGuest())
|
||||||
|
updateMapInfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Two levels
|
// Two levels
|
||||||
twoLevelsBtn = new CToggleButton(Point(346, 81), "RANUNDR", CGI->generaltexth->zelp[202]);
|
twoLevelsBtn = new CToggleButton(Point(346, 81), "RANUNDR", CGI->generaltexth->zelp[202]);
|
||||||
//twoLevelsBtn->select(true); for now, deactivated
|
//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
|
// Create number defs list
|
||||||
std::vector<std::string> numberDefs;
|
std::vector<std::string> numberDefs;
|
||||||
@ -1673,7 +1682,8 @@ CRandomMapTab::CRandomMapTab()
|
|||||||
deactivateButtonsFrom(teamsCntGroup, btnId);
|
deactivateButtonsFrom(teamsCntGroup, btnId);
|
||||||
deactivateButtonsFrom(compOnlyPlayersCntGroup, 8 - btnId + 1);
|
deactivateButtonsFrom(compOnlyPlayersCntGroup, 8 - btnId + 1);
|
||||||
validatePlayersCnt(btnId);
|
validatePlayersCnt(btnId);
|
||||||
updateMapInfo();
|
if(!SEL->isGuest())
|
||||||
|
updateMapInfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Amount of teams
|
// Amount of teams
|
||||||
@ -1684,7 +1694,8 @@ CRandomMapTab::CRandomMapTab()
|
|||||||
teamsCntGroup->addCallback([&](int btnId)
|
teamsCntGroup->addCallback([&](int btnId)
|
||||||
{
|
{
|
||||||
mapGenOptions.setTeamCount(btnId);
|
mapGenOptions.setTeamCount(btnId);
|
||||||
updateMapInfo();
|
if(!SEL->isGuest())
|
||||||
|
updateMapInfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Computer only players
|
// Computer only players
|
||||||
@ -1698,7 +1709,8 @@ CRandomMapTab::CRandomMapTab()
|
|||||||
mapGenOptions.setCompOnlyPlayerCount(btnId);
|
mapGenOptions.setCompOnlyPlayerCount(btnId);
|
||||||
deactivateButtonsFrom(compOnlyTeamsCntGroup, btnId);
|
deactivateButtonsFrom(compOnlyTeamsCntGroup, btnId);
|
||||||
validateCompOnlyPlayersCnt(btnId);
|
validateCompOnlyPlayersCnt(btnId);
|
||||||
updateMapInfo();
|
if(!SEL->isGuest())
|
||||||
|
updateMapInfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Computer only teams
|
// Computer only teams
|
||||||
@ -1710,7 +1722,8 @@ CRandomMapTab::CRandomMapTab()
|
|||||||
compOnlyTeamsCntGroup->addCallback([&](int btnId)
|
compOnlyTeamsCntGroup->addCallback([&](int btnId)
|
||||||
{
|
{
|
||||||
mapGenOptions.setCompOnlyTeamCount(btnId);
|
mapGenOptions.setCompOnlyTeamCount(btnId);
|
||||||
updateMapInfo();
|
if(!SEL->isGuest())
|
||||||
|
updateMapInfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
const int WIDE_BTN_WIDTH = 85;
|
const int WIDE_BTN_WIDTH = 85;
|
||||||
@ -1743,7 +1756,8 @@ CRandomMapTab::CRandomMapTab()
|
|||||||
showRandMaps = new CButton(Point(54, 535), "RANSHOW", CGI->generaltexth->zelp[252]);
|
showRandMaps = new CButton(Point(54, 535), "RANSHOW", CGI->generaltexth->zelp[252]);
|
||||||
|
|
||||||
// Initialize map info object
|
// 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
|
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)
|
void CRandomMapTab::showAll(SDL_Surface * to)
|
||||||
{
|
{
|
||||||
CIntObject::showAll(to);
|
CIntObject::showAll(to);
|
||||||
@ -1914,6 +1933,18 @@ const CMapGenOptions & CRandomMapTab::getMapGenOptions() const
|
|||||||
return mapGenOptions;
|
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)
|
CChatBox::CChatBox(const Rect &rect)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION;
|
OBJ_CONSTRUCTION;
|
||||||
@ -3935,6 +3966,7 @@ void PlayerJoined::apply(CSelectionScreen *selScreen)
|
|||||||
|
|
||||||
selScreen->propagateNames();
|
selScreen->propagateNames();
|
||||||
selScreen->propagateOptions();
|
selScreen->propagateOptions();
|
||||||
|
selScreen->toggleTab(selScreen->curTab);
|
||||||
|
|
||||||
GH.totalRedraw();
|
GH.totalRedraw();
|
||||||
}
|
}
|
||||||
|
@ -300,6 +300,7 @@ public:
|
|||||||
CFunctionList<void (const CMapInfo *)> & getMapInfoChanged();
|
CFunctionList<void (const CMapInfo *)> & getMapInfoChanged();
|
||||||
const CMapInfo * getMapInfo() const;
|
const CMapInfo * getMapInfo() const;
|
||||||
const CMapGenOptions & getMapGenOptions() const;
|
const CMapGenOptions & getMapGenOptions() const;
|
||||||
|
void setMapGenOptions(shared_ptr<CMapGenOptions> opts);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addButtonsToGroup(CToggleGroup * group, const std::vector<std::string> & defs, int startIndex, int endIndex, int btnWidth, int helpStartIndex) const;
|
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 deactivateButtonsFrom(CToggleGroup * group, int startId);
|
||||||
void validatePlayersCnt(int playersCnt);
|
void validatePlayersCnt(int playersCnt);
|
||||||
void validateCompOnlyPlayersCnt(int compOnlyPlayersCnt);
|
void validateCompOnlyPlayersCnt(int compOnlyPlayersCnt);
|
||||||
|
std::vector<int> getPossibleMapSizes();
|
||||||
|
|
||||||
CPicture * bg;
|
CPicture * bg;
|
||||||
CToggleButton * twoLevelsBtn;
|
CToggleButton * twoLevelsBtn;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user