|
@@ -31,6 +31,7 @@
|
|
|
#include "../widgets/Buttons.h"
|
|
|
#include "../widgets/CComponent.h"
|
|
|
#include "../widgets/GraphicalPrimitiveCanvas.h"
|
|
|
+#include "../widgets/Images.h"
|
|
|
#include "../widgets/ObjectLists.h"
|
|
|
#include "../widgets/Slider.h"
|
|
|
#include "../widgets/TextControls.h"
|
|
@@ -43,12 +44,14 @@
|
|
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
#include "../../lib/CHeroHandler.h"
|
|
|
+#include "../../lib/CTownHandler.h"
|
|
|
#include "../../lib/CRandomGenerator.h"
|
|
|
#include "../../lib/CThreadHelper.h"
|
|
|
#include "../../lib/MetaString.h"
|
|
|
#include "../../lib/filesystem/Filesystem.h"
|
|
|
#include "../../lib/mapping/CMapHeader.h"
|
|
|
#include "../../lib/mapping/CMapInfo.h"
|
|
|
+#include "../../lib/networkPacks/PacksForLobby.h"
|
|
|
|
|
|
ISelectionScreenInfo::ISelectionScreenInfo(ESelectionScreen ScreenType)
|
|
|
: screenType(ScreenType)
|
|
@@ -137,6 +140,7 @@ InfoCard::InfoCard()
|
|
|
mapDescription = std::make_shared<CTextBox>("", descriptionRect, 1);
|
|
|
playerListBg = std::make_shared<CPicture>(ImagePath::builtin("CHATPLUG.bmp"), 16, 276);
|
|
|
chat = std::make_shared<CChatBox>(Rect(18, 126, 335, 143));
|
|
|
+ pvpBox = std::make_shared<PvPBox>(Rect(17, 396, 338, 105));
|
|
|
|
|
|
buttonInvitePlayers = std::make_shared<CButton>(Point(20, 365), AnimationPath::builtin("pregameInvitePlayers"), CGI->generaltexth->zelp[105], [](){ CSH->getGlobalLobby().activateRoomInviteInterface(); } );
|
|
|
buttonOpenGlobalLobby = std::make_shared<CButton>(Point(188, 365), AnimationPath::builtin("pregameReturnToLobby"), CGI->generaltexth->zelp[105], [](){ CSH->getGlobalLobby().activateInterface(); });
|
|
@@ -298,8 +302,16 @@ void InfoCard::setChat(bool activateChat)
|
|
|
buttonInvitePlayers->enable();
|
|
|
buttonOpenGlobalLobby->enable();
|
|
|
}
|
|
|
+ labelMapDiff->disable();
|
|
|
+ labelPlayerDifficulty->disable();
|
|
|
+ labelRating->disable();
|
|
|
+ labelDifficulty->disable();
|
|
|
+ labelDifficultyPercent->disable();
|
|
|
+ flagbox->disable();
|
|
|
+ iconDifficulty->disable();
|
|
|
mapDescription->disable();
|
|
|
chat->enable();
|
|
|
+ pvpBox->enable();
|
|
|
playerListBg->enable();
|
|
|
}
|
|
|
else
|
|
@@ -308,6 +320,7 @@ void InfoCard::setChat(bool activateChat)
|
|
|
buttonOpenGlobalLobby->disable();
|
|
|
mapDescription->enable();
|
|
|
chat->disable();
|
|
|
+ pvpBox->disable();
|
|
|
playerListBg->disable();
|
|
|
|
|
|
if(SEL->screenType == ESelectionScreen::campaignList)
|
|
@@ -325,6 +338,13 @@ void InfoCard::setChat(bool activateChat)
|
|
|
labelLossConditionText->enable();
|
|
|
labelGroupPlayers->disable();
|
|
|
}
|
|
|
+ labelMapDiff->enable();
|
|
|
+ labelPlayerDifficulty->enable();
|
|
|
+ labelRating->enable();
|
|
|
+ labelDifficulty->enable();
|
|
|
+ labelDifficultyPercent->enable();
|
|
|
+ flagbox->enable();
|
|
|
+ iconDifficulty->enable();
|
|
|
}
|
|
|
|
|
|
showChat = activateChat;
|
|
@@ -373,6 +393,120 @@ void CChatBox::addNewMessage(const std::string & text)
|
|
|
chatHistory->slider->scrollToMax();
|
|
|
}
|
|
|
|
|
|
+PvPBox::PvPBox(const Rect & rect)
|
|
|
+{
|
|
|
+ OBJ_CONSTRUCTION;
|
|
|
+ pos += rect.topLeft();
|
|
|
+ setRedrawParent(true);
|
|
|
+
|
|
|
+ backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, rect.w, rect.h));
|
|
|
+ backgroundTexture->playerColored(PlayerColor(1));
|
|
|
+ backgroundBorder = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, rect.w, rect.h), ColorRGBA(0, 0, 0, 64), ColorRGBA(96, 96, 96, 255), 1);
|
|
|
+
|
|
|
+ townSelector = std::make_shared<TownSelector>(Point(5, 3));
|
|
|
+
|
|
|
+ auto getBannedTowns = [this](){
|
|
|
+ std::vector<FactionID> bannedTowns;
|
|
|
+ for(auto & town : townSelector->townsEnabled)
|
|
|
+ if(!town.second)
|
|
|
+ bannedTowns.push_back(town.first);
|
|
|
+ return bannedTowns;
|
|
|
+ };
|
|
|
+
|
|
|
+ buttonFlipCoin = std::make_shared<CButton>(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, Colors::WHITE);
|
|
|
+
|
|
|
+ buttonRandomTown = std::make_shared<CButton>(Point(190, 31), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.randomTown.help")), [getBannedTowns](){
|
|
|
+ LobbyPvPAction lpa;
|
|
|
+ lpa.action = LobbyPvPAction::RANDOM_TOWN;
|
|
|
+ lpa.bannedTowns = getBannedTowns();
|
|
|
+ CSH->sendLobbyPack(lpa);
|
|
|
+ }, EShortcut::NONE);
|
|
|
+ buttonRandomTown->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTown.hover"), EFonts::FONT_SMALL, Colors::WHITE);
|
|
|
+
|
|
|
+ buttonRandomTownVs = std::make_shared<CButton>(Point(190, 56), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.help")), [getBannedTowns](){
|
|
|
+ LobbyPvPAction lpa;
|
|
|
+ lpa.action = LobbyPvPAction::RANDOM_TOWN_VS;
|
|
|
+ lpa.bannedTowns = getBannedTowns();
|
|
|
+ CSH->sendLobbyPack(lpa);
|
|
|
+ }, EShortcut::NONE);
|
|
|
+ buttonRandomTownVs->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.hover"), EFonts::FONT_SMALL, Colors::WHITE);
|
|
|
+}
|
|
|
+
|
|
|
+TownSelector::TownSelector(const Point & loc)
|
|
|
+{
|
|
|
+ OBJ_CONSTRUCTION;
|
|
|
+ pos += loc;
|
|
|
+ setRedrawParent(true);
|
|
|
+
|
|
|
+ int count = 0;
|
|
|
+ for(auto const & factionID : VLC->townh->getDefaultAllowed())
|
|
|
+ {
|
|
|
+ townsEnabled[factionID] = true;
|
|
|
+ count++;
|
|
|
+ };
|
|
|
+
|
|
|
+ auto divisionRoundUp = [](int x, int y){ return (x + (y - 1)) / y; };
|
|
|
+
|
|
|
+ if(count > 9)
|
|
|
+ {
|
|
|
+ slider = std::make_shared<CSlider>(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));
|
|
|
+ }
|
|
|
+
|
|
|
+ updateListItems();
|
|
|
+}
|
|
|
+
|
|
|
+void TownSelector::updateListItems()
|
|
|
+{
|
|
|
+ OBJ_CONSTRUCTION;
|
|
|
+ int line = slider ? slider->getValue() : 0;
|
|
|
+ int x_offset = slider ? 0 : 8;
|
|
|
+
|
|
|
+ towns.clear();
|
|
|
+ townsArea.clear();
|
|
|
+
|
|
|
+ int x = 0;
|
|
|
+ int y = 0;
|
|
|
+ CGI->factions()->forEach([this, &x, &y, line, x_offset](const Faction *entity, bool &stop){
|
|
|
+ if(!entity->hasTown())
|
|
|
+ return;
|
|
|
+
|
|
|
+ if(y >= line && (y - line) < 3)
|
|
|
+ {
|
|
|
+ FactionID factionID = entity->getFaction();
|
|
|
+ auto getImageIndex = [](FactionID factionID, bool enabled){ return (*CGI->townh)[factionID]->town->clientInfo.icons[true][!enabled] + 2; };
|
|
|
+ towns[factionID] = std::make_shared<CAnimImage>(AnimationPath::builtin("ITPA"), getImageIndex(factionID, townsEnabled[factionID]), 0, x_offset + 48 * x, 32 * (y - line));
|
|
|
+ townsArea[factionID] = std::make_shared<LRClickableArea>(Rect(x_offset + 48 * x, 32 * (y - line), 48, 32), [this, getImageIndex, factionID](){
|
|
|
+ townsEnabled[factionID] = !townsEnabled[factionID];
|
|
|
+ towns[factionID]->setFrame(getImageIndex(factionID, townsEnabled[factionID]));
|
|
|
+ redraw();
|
|
|
+ }, [factionID](){ CRClickPopup::createAndPush((*CGI->townh)[factionID]->town->faction->getNameTranslated()); });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (x < 2)
|
|
|
+ x++;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ x = 0;
|
|
|
+ y++;
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+void TownSelector::sliderMove(int slidPos)
|
|
|
+{
|
|
|
+ if(!slider)
|
|
|
+ return; // ignore spurious call when slider is being created
|
|
|
+ updateListItems();
|
|
|
+ redraw();
|
|
|
+}
|
|
|
+
|
|
|
CFlagBox::CFlagBox(const Rect & rect)
|
|
|
: CIntObject(SHOW_POPUP)
|
|
|
{
|