diff --git a/client/lobby/CSelectionBase.cpp b/client/lobby/CSelectionBase.cpp index ca6e02e64..a811a4c8c 100644 --- a/client/lobby/CSelectionBase.cpp +++ b/client/lobby/CSelectionBase.cpp @@ -403,25 +403,22 @@ PvPBox::PvPBox(const Rect & rect) backgroundTexture->playerColored(PlayerColor(1)); backgroundBorder = std::make_shared(Rect(0, 0, rect.w, rect.h), ColorRGBA(0, 0, 0, 64), ColorRGBA(96, 96, 96, 255), 1); - factionSelector = std::make_shared(Point(5, 3)); + townSelector = std::make_shared(Point(5, 3)); auto getBannedTowns = [this](){ std::vector bannedTowns; - for(auto & town : factionSelector->townsEnabled) + for(auto & town : townSelector->townsEnabled) if(!town.second) bannedTowns.push_back(town.first); return bannedTowns; }; - auto buttonColor = CSH->isGuest() ? Colors::WHITE : Colors::ORANGE; - buttonFlipCoin = std::make_shared(Point(190, 6), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.coin.help")), [](){ LobbyPvPAction lpa; lpa.action = LobbyPvPAction::COIN; CSH->sendLobbyPack(lpa); }, EShortcut::NONE); - buttonFlipCoin->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.coin.hover"), EFonts::FONT_SMALL, buttonColor); - buttonFlipCoin->block(!CSH->isGuest()); + buttonFlipCoin->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.coin.hover"), EFonts::FONT_SMALL, Colors::WHITE); buttonRandomTown = std::make_shared(Point(190, 31), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.randomTown.help")), [getBannedTowns](){ LobbyPvPAction lpa; @@ -429,8 +426,7 @@ PvPBox::PvPBox(const Rect & rect) lpa.bannedTowns = getBannedTowns(); CSH->sendLobbyPack(lpa); }, EShortcut::NONE); - buttonRandomTown->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTown.hover"), EFonts::FONT_SMALL, buttonColor); - buttonRandomTown->block(!CSH->isGuest()); + buttonRandomTown->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTown.hover"), EFonts::FONT_SMALL, Colors::WHITE); buttonRandomTownVs = std::make_shared(Point(190, 56), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.help")), [getBannedTowns](){ LobbyPvPAction lpa; @@ -438,11 +434,10 @@ PvPBox::PvPBox(const Rect & rect) lpa.bannedTowns = getBannedTowns(); CSH->sendLobbyPack(lpa); }, EShortcut::NONE); - buttonRandomTownVs->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.hover"), EFonts::FONT_SMALL, buttonColor); - buttonRandomTownVs->block(!CSH->isGuest()); + buttonRandomTownVs->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.hover"), EFonts::FONT_SMALL, Colors::WHITE); } -FactionSelector::FactionSelector(const Point & loc) +TownSelector::TownSelector(const Point & loc) { OBJ_CONSTRUCTION; pos += loc; @@ -460,7 +455,7 @@ FactionSelector::FactionSelector(const Point & loc) if(count > 9) { - slider = std::make_shared(Point(144, 0), 96, std::bind(&FactionSelector::sliderMove, this, _1), 3, divisionRoundUp(count, 3), 0, Orientation::VERTICAL, CSlider::BLUE); + slider = std::make_shared(Point(144, 0), 96, std::bind(&TownSelector::sliderMove, this, _1), 3, divisionRoundUp(count, 3), 0, Orientation::VERTICAL, CSlider::BLUE); slider->setPanningStep(24); slider->setScrollBounds(Rect(-144, 0, slider->pos.x - pos.x + slider->pos.w, slider->pos.h)); } @@ -468,7 +463,7 @@ FactionSelector::FactionSelector(const Point & loc) updateListItems(); } -void FactionSelector::updateListItems() +void TownSelector::updateListItems() { OBJ_CONSTRUCTION; int line = slider ? slider->getValue() : 0; @@ -488,8 +483,6 @@ void FactionSelector::updateListItems() auto getImageIndex = [](FactionID factionID, bool enabled){ return (*CGI->townh)[factionID]->town->clientInfo.icons[true][!enabled] + 2; }; towns[factionID] = std::make_shared(AnimationPath::builtin("ITPA"), getImageIndex(factionID, townsEnabled[factionID]), 0, x_offset + 48 * x, 32 * (y - line)); townsArea[factionID] = std::make_shared(Rect(x_offset + 48 * x, 32 * (y - line), 48, 32), [this, getImageIndex, factionID](){ - if(CSH->isGuest()) - return; townsEnabled[factionID] = !townsEnabled[factionID]; towns[factionID]->setFrame(getImageIndex(factionID, townsEnabled[factionID])); redraw(); @@ -506,7 +499,7 @@ void FactionSelector::updateListItems() }); } -void FactionSelector::sliderMove(int slidPos) +void TownSelector::sliderMove(int slidPos) { if(!slider) return; // ignore spurious call when slider is being created diff --git a/client/lobby/CSelectionBase.h b/client/lobby/CSelectionBase.h index 04cc8e677..3f545892f 100644 --- a/client/lobby/CSelectionBase.h +++ b/client/lobby/CSelectionBase.h @@ -32,7 +32,7 @@ class SelectionTab; class InfoCard; class CChatBox; class PvPBox; -class FactionSelector; +class TownSelector; class CLabel; class CSlider; class CFlagBox; @@ -148,7 +148,7 @@ class PvPBox : public CIntObject std::shared_ptr backgroundTexture; std::shared_ptr backgroundBorder; - std::shared_ptr factionSelector; + std::shared_ptr townSelector; std::shared_ptr buttonFlipCoin; std::shared_ptr buttonRandomTown; @@ -157,7 +157,7 @@ public: PvPBox(const Rect & rect); }; -class FactionSelector : public CIntObject +class TownSelector : public CIntObject { std::map> towns; std::map> townsArea; @@ -169,7 +169,7 @@ class FactionSelector : public CIntObject public: std::map townsEnabled; - FactionSelector(const Point & loc); + TownSelector(const Point & loc); }; class CFlagBox : public CIntObject diff --git a/lib/registerTypes/RegisterTypesLobbyPacks.h b/lib/registerTypes/RegisterTypesLobbyPacks.h index 74432829a..6859f5d9f 100644 --- a/lib/registerTypes/RegisterTypesLobbyPacks.h +++ b/lib/registerTypes/RegisterTypesLobbyPacks.h @@ -34,6 +34,7 @@ void registerTypesLobbyPacks(Serializer &s) s.template registerType(); s.template registerType(); s.template registerType(); + s.template registerType(); // Only host client send s.template registerType(); s.template registerType(); @@ -59,7 +60,6 @@ void registerTypesLobbyPacks(Serializer &s) s.template registerType(); s.template registerType(); s.template registerType(); - s.template registerType(); } VCMI_LIB_NAMESPACE_END diff --git a/server/LobbyNetPackVisitors.h b/server/LobbyNetPackVisitors.h index fe185d79a..2897a18d4 100644 --- a/server/LobbyNetPackVisitors.h +++ b/server/LobbyNetPackVisitors.h @@ -38,6 +38,7 @@ public: void visitLobbyChangePlayerOption(LobbyChangePlayerOption & pack) override; void visitLobbyChatMessage(LobbyChatMessage & pack) override; void visitLobbyGuiAction(LobbyGuiAction & pack) override; + void visitLobbyPvPAction(LobbyPvPAction & pack) override; }; class ApplyOnServerAfterAnnounceNetPackVisitor : public VCMI_LIB_WRAP_NAMESPACE(ICPackVisitor) diff --git a/server/NetPacksLobbyServer.cpp b/server/NetPacksLobbyServer.cpp index 1f30e66e9..f32d2fe63 100644 --- a/server/NetPacksLobbyServer.cpp +++ b/server/NetPacksLobbyServer.cpp @@ -370,6 +370,12 @@ void ApplyOnServerNetPackVisitor::visitLobbyForceSetPlayer(LobbyForceSetPlayer & result = true; } + +void ClientPermissionsCheckerNetPackVisitor::visitLobbyPvPAction(LobbyPvPAction & pack) +{ + result = true; +} + void ApplyOnServerNetPackVisitor::visitLobbyPvPAction(LobbyPvPAction & pack) { std::vector allowedTowns;