123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595 |
- /*
- * CSelectionBase.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 "CSelectionBase.h"
- #include "CBonusSelection.h"
- #include "CLobbyScreen.h"
- #include "OptionsTab.h"
- #include "RandomMapTab.h"
- #include "SelectionTab.h"
- #include "../../CCallback.h"
- #include "../CGameInfo.h"
- #include "../CPlayerInterface.h"
- #include "../CServerHandler.h"
- #include "../gui/CGuiHandler.h"
- #include "../gui/Shortcut.h"
- #include "../gui/WindowHandler.h"
- #include "../globalLobby/GlobalLobbyClient.h"
- #include "../mainmenu/CMainMenu.h"
- #include "../media/ISoundPlayer.h"
- #include "../widgets/Buttons.h"
- #include "../widgets/CComponent.h"
- #include "../widgets/CTextInput.h"
- #include "../widgets/GraphicalPrimitiveCanvas.h"
- #include "../widgets/Images.h"
- #include "../widgets/MiscWidgets.h"
- #include "../widgets/ObjectLists.h"
- #include "../widgets/Slider.h"
- #include "../widgets/TextControls.h"
- #include "../windows/GUIClasses.h"
- #include "../windows/InfoWindows.h"
- #include "../render/CAnimation.h"
- #include "../render/Graphics.h"
- #include "../render/IFont.h"
- #include "../render/IRenderHandler.h"
- #include "../../lib/CRandomGenerator.h"
- #include "../../lib/CThreadHelper.h"
- #include "../../lib/filesystem/Filesystem.h"
- #include "../../lib/mapping/CMapHeader.h"
- #include "../../lib/mapping/CMapInfo.h"
- #include "../../lib/networkPacks/PacksForLobby.h"
- #include "../../lib/texts/CGeneralTextHandler.h"
- #include "../../lib/entities/faction/CFaction.h"
- #include "../../lib/entities/faction/CTown.h"
- #include "../../lib/entities/faction/CTownHandler.h"
- ISelectionScreenInfo::ISelectionScreenInfo(ESelectionScreen ScreenType)
- : screenType(ScreenType)
- {
- assert(!SEL);
- SEL = this;
- }
- ISelectionScreenInfo::~ISelectionScreenInfo()
- {
- assert(SEL == this);
- SEL = nullptr;
- }
- int ISelectionScreenInfo::getCurrentDifficulty()
- {
- return getStartInfo()->difficulty;
- }
- PlayerInfo ISelectionScreenInfo::getPlayerInfo(PlayerColor color)
- {
- return getMapInfo()->mapHeader->players.at(color.getNum());
- }
- CSelectionBase::CSelectionBase(ESelectionScreen type)
- : CWindowObject(BORDERED | SHADOW_DISABLED), ISelectionScreenInfo(type)
- {
- OBJECT_CONSTRUCTION;
- pos.w = 762;
- pos.h = 584;
- if(screenType == ESelectionScreen::campaignList)
- {
- setBackground(ImagePath::builtin("CamCust.bmp"));
- }
- else
- {
- const JsonVector & bgNames = CMainMenuConfig::get().getConfig()["game-select"].Vector();
- setBackground(ImagePath::fromJson(*RandomGeneratorUtil::nextItem(bgNames, CRandomGenerator::getDefault())));
- }
- pos = background->center();
- card = std::make_shared<InfoCard>();
- buttonBack = std::make_shared<CButton>(Point(581, 535), AnimationPath::builtin("SCNRBACK.DEF"), CGI->generaltexth->zelp[105], [=](){ close();}, EShortcut::GLOBAL_CANCEL);
- }
- void CSelectionBase::toggleTab(std::shared_ptr<CIntObject> tab)
- {
- if(curTab && curTab->isActive())
- {
- curTab->disable();
- }
- if(curTab != tab)
- {
- tab->enable();
- curTab = tab;
- }
- else
- {
- curTab.reset();
- }
- if(tabSel->showRandom && tab != tabOpt)
- {
- tabSel->curFolder = "";
- tabSel->showRandom = false;
- tabSel->filter(0, true);
- }
- GH.windows().totalRedraw();
- }
- InfoCard::InfoCard()
- : showChat(true)
- {
- OBJECT_CONSTRUCTION;
- setRedrawParent(true);
- pos.x += 393;
- pos.y += 6;
- labelSaveDate = std::make_shared<CLabel>(310, 38, FONT_SMALL, ETextAlignment::BOTTOMRIGHT, Colors::WHITE);
- labelMapSize = std::make_shared<CLabel>(333, 56, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE);
- mapName = std::make_shared<CLabel>(26, 39, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW, "", SEL->screenType == ESelectionScreen::campaignList ? 325 : 285);
- Rect descriptionRect(26, 149, 320, 115);
- 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(); }, EShortcut::LOBBY_INVITE_PLAYERS );
- buttonOpenGlobalLobby = std::make_shared<CButton>(Point(188, 365), AnimationPath::builtin("pregameReturnToLobby"), CGI->generaltexth->zelp[105], [](){ CSH->getGlobalLobby().activateInterface(); }, EShortcut::MAIN_MENU_LOBBY );
- buttonInvitePlayers->setTextOverlay (MetaString::createFromTextID("vcmi.lobby.invite.header").toString(), EFonts::FONT_SMALL, Colors::WHITE);
- buttonOpenGlobalLobby->setTextOverlay(MetaString::createFromTextID("vcmi.lobby.backToLobby").toString(), EFonts::FONT_SMALL, Colors::WHITE);
- if(SEL->screenType == ESelectionScreen::campaignList)
- {
- labelCampaignDescription = std::make_shared<CLabel>(26, 132, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[38]);
- }
- else
- {
- background = std::make_shared<CPicture>(ImagePath::builtin("GSELPOP1.bmp"), 0, 0);
- parent->addChild(background.get());
- auto it = vstd::find(parent->children, this); //our position among parent children
- parent->children.insert(it, background.get()); //put BG before us
- parent->children.pop_back();
- pos.w = background->pos.w;
- pos.h = background->pos.h;
- iconsMapSizes = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRMPSZ"), 4, 0, 318, 22); //let it be custom size (frame 4) by default
- iconDifficulty = std::make_shared<CToggleGroup>(0);
- {
- constexpr std::array difButns = {"GSPBUT3.DEF", "GSPBUT4.DEF", "GSPBUT5.DEF", "GSPBUT6.DEF", "GSPBUT7.DEF"};
- for(int i = 0; i < 5; i++)
- {
- auto button = std::make_shared<CToggleButton>(Point(110 + i * 32, 450), AnimationPath::builtin(difButns[i]), CGI->generaltexth->zelp[24 + i]);
- iconDifficulty->addToggle(i, button);
- if(SEL->screenType != ESelectionScreen::newGame)
- button->block(true);
- }
- }
- flagbox = std::make_shared<CFlagBox>(Rect(24, 400, 335, 23));
- labelMapDiff = std::make_shared<CLabel>(33, 430, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[494]);
- labelPlayerDifficulty = std::make_shared<CLabel>(133, 430, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[492] + ":");
- labelRating = std::make_shared<CLabel>(290, 430, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[218] + ":");
- labelScenarioName = std::make_shared<CLabel>(26, 22, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[495]);
- labelScenarioDescription = std::make_shared<CLabel>(26, 132, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[496]);
- labelVictoryCondition = std::make_shared<CLabel>(26, 283, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[497]);
- labelLossCondition = std::make_shared<CLabel>(26, 339, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[498]);
- iconsVictoryCondition = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRVICT"), 0, 0, 24, 302);
- iconsLossCondition = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRLOSS"), 0, 0, 24, 359);
- labelVictoryConditionText = std::make_shared<CLabel>(60, 307, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
- labelLossConditionText = std::make_shared<CLabel>(60, 366, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
- labelDifficulty = std::make_shared<CLabel>(62, 472, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
- labelDifficultyPercent = std::make_shared<CLabel>(311, 472, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
- labelGroupPlayers = std::make_shared<CLabelGroup>(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
- disableLabelRedraws();
- }
- setChat(false);
- if (CSH->inLobbyRoom())
- setChat(true); // FIXME: less ugly version?
- }
- void InfoCard::disableLabelRedraws()
- {
- labelSaveDate->setAutoRedraw(false);
- labelMapSize->setAutoRedraw(false);
- mapName->setAutoRedraw(false);
- mapDescription->label->setAutoRedraw(false);
- labelVictoryConditionText->setAutoRedraw(false);
- labelLossConditionText->setAutoRedraw(false);
- labelDifficulty->setAutoRedraw(false);
- labelDifficultyPercent->setAutoRedraw(false);
- }
- void InfoCard::changeSelection()
- {
- auto mapInfo = SEL->getMapInfo();
- if(!mapInfo)
- return;
- labelSaveDate->setText(mapInfo->date);
- mapName->setText(mapInfo->getNameTranslated());
- mapDescription->setText(mapInfo->getDescriptionTranslated());
- mapDescription->label->scrollTextTo(0, false);
- if(mapDescription->slider)
- mapDescription->slider->scrollToMin();
- if(SEL->screenType == ESelectionScreen::campaignList)
- return;
- const CMapHeader * header = mapInfo->mapHeader.get();
- labelMapSize->setText(std::to_string(header->width) + "x" + std::to_string(header->height));
- iconsMapSizes->setFrame(mapInfo->getMapSizeIconId());
- iconsVictoryCondition->setFrame(header->victoryIconIndex);
- labelVictoryConditionText->setText(header->victoryMessage.toString());
- iconsLossCondition->setFrame(header->defeatIconIndex);
- labelLossConditionText->setText(header->defeatMessage.toString());
- flagbox->recreate();
- labelDifficulty->setText(CGI->generaltexth->arraytxt[142 + vstd::to_underlying(mapInfo->mapHeader->difficulty)]);
- iconDifficulty->setSelected(SEL->getCurrentDifficulty());
- if(SEL->screenType == ESelectionScreen::loadGame || SEL->screenType == ESelectionScreen::saveGame)
- for(auto & button : iconDifficulty->buttons)
- button.second->setEnabled(button.first == SEL->getCurrentDifficulty());
- const std::array<std::string, 5> difficultyPercent = {"80%", "100%", "130%", "160%", "200%"};
- labelDifficultyPercent->setText(difficultyPercent[SEL->getCurrentDifficulty()]);
- OBJECT_CONSTRUCTION;
- // FIXME: We recreate them each time because CLabelGroup don't use smart pointers
- labelGroupPlayers = std::make_shared<CLabelGroup>(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
- if(!showChat)
- labelGroupPlayers->disable();
- const auto & font = GH.renderHandler().loadFont(FONT_SMALL);
- for(const auto & p : CSH->playerNames)
- {
- int slotsUsed = labelGroupPlayers->currentSize();
- Point labelPosition;
- if(slotsUsed < 4)
- labelPosition = Point(24, 285 + slotsUsed * font->getLineHeight()); // left column
- else
- labelPosition = Point(193, 285 + (slotsUsed - 4) * font->getLineHeight()); // right column
- labelGroupPlayers->add(labelPosition.x, labelPosition.y, p.second.name);
- }
- }
- void InfoCard::toggleChat()
- {
- setChat(!showChat);
- }
- void InfoCard::setChat(bool activateChat)
- {
- if(showChat == activateChat)
- return;
- if(activateChat)
- {
- if(SEL->screenType == ESelectionScreen::campaignList)
- {
- labelCampaignDescription->disable();
- }
- else
- {
- labelScenarioDescription->disable();
- labelVictoryCondition->disable();
- labelLossCondition->disable();
- iconsVictoryCondition->disable();
- labelVictoryConditionText->disable();
- iconsLossCondition->disable();
- labelLossConditionText->disable();
- labelGroupPlayers->enable();
- labelMapDiff->disable();
- labelPlayerDifficulty->disable();
- labelRating->disable();
- labelDifficulty->disable();
- labelDifficultyPercent->disable();
- flagbox->disable();
- iconDifficulty->disable();
- mapDescription->disable();
- chat->enable();
- pvpBox->enable();
- playerListBg->enable();
- }
- if (CSH->inLobbyRoom())
- {
- buttonInvitePlayers->enable();
- buttonOpenGlobalLobby->enable();
- }
- }
- else
- {
- buttonInvitePlayers->disable();
- buttonOpenGlobalLobby->disable();
- mapDescription->enable();
- chat->disable();
- pvpBox->disable();
- playerListBg->disable();
- if(SEL->screenType == ESelectionScreen::campaignList)
- {
- labelCampaignDescription->enable();
- }
- else
- {
- labelScenarioDescription->enable();
- labelVictoryCondition->enable();
- labelLossCondition->enable();
- iconsVictoryCondition->enable();
- iconsLossCondition->enable();
- labelVictoryConditionText->enable();
- labelLossConditionText->enable();
- labelGroupPlayers->disable();
- labelMapDiff->enable();
- labelPlayerDifficulty->enable();
- labelRating->enable();
- labelDifficulty->enable();
- labelDifficultyPercent->enable();
- flagbox->enable();
- iconDifficulty->enable();
- }
- }
- showChat = activateChat;
- GH.windows().totalRedraw();
- }
- CChatBox::CChatBox(const Rect & rect)
- : CIntObject(KEYBOARD | TEXTINPUT)
- {
- OBJECT_CONSTRUCTION;
- pos += rect.topLeft();
- setRedrawParent(true);
- const auto & font = GH.renderHandler().loadFont(FONT_SMALL);
- const int height = font->getLineHeight();
- Rect textInputArea(1, rect.h - height, rect.w - 1, height);
- Rect chatHistoryArea(3, 1, rect.w - 3, rect.h - height - 1);
- inputBackground = std::make_shared<TransparentFilledRectangle>(textInputArea, ColorRGBA(0,0,0,192));
- inputBox = std::make_shared<CTextInput>(textInputArea, EFonts::FONT_SMALL, ETextAlignment::CENTERLEFT, true);
- inputBox->removeUsedEvents(KEYBOARD);
- chatHistory = std::make_shared<CTextBox>("", chatHistoryArea, 1);
- chatHistory->label->color = Colors::GREEN;
- }
- bool CChatBox::captureThisKey(EShortcut key)
- {
- return !inputBox->getText().empty() && key == EShortcut::GLOBAL_ACCEPT;
- }
- void CChatBox::keyPressed(EShortcut key)
- {
- if(key == EShortcut::GLOBAL_ACCEPT && inputBox->getText().size())
- {
- CSH->sendMessage(inputBox->getText());
- inputBox->setText("");
- }
- else
- inputBox->keyPressed(key);
- }
- void CChatBox::addNewMessage(const std::string & text)
- {
- CCS->soundh->playSound(AudioPath::builtin("CHAT"));
- chatHistory->setText(chatHistory->label->getText() + text + "\n");
- if(chatHistory->slider)
- chatHistory->slider->scrollToMax();
- }
- PvPBox::PvPBox(const Rect & rect)
- {
- OBJECT_CONSTRUCTION;
- pos += rect.topLeft();
- setRedrawParent(true);
- backgroundTexture = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, rect.w, rect.h));
- backgroundTexture->setPlayerColor(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(const 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::LOBBY_FLIP_COIN);
- 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::LOBBY_RANDOM_TOWN);
- 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::LOBBY_RANDOM_TOWN_VS);
- buttonRandomTownVs->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.hover"), EFonts::FONT_SMALL, Colors::WHITE);
- buttonHandicap = std::make_shared<CButton>(Point(190, 81), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.handicap")), [](){
- if(!CSH->isHost())
- return;
- GH.windows().createAndPushWindow<OptionsTab::HandicapWindow>();
- }, EShortcut::LOBBY_HANDICAP);
- buttonHandicap->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.handicap"), EFonts::FONT_SMALL, Colors::WHITE);
- }
- TownSelector::TownSelector(const Point & loc)
- {
- OBJECT_CONSTRUCTION;
- pos += loc;
- setRedrawParent(true);
- int count = 0;
- for(auto const & factionID : CGI->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()
- {
- OBJECT_CONSTRUCTION;
- int line = slider ? slider->getValue() : 0;
- int x_offset = slider ? 0 : 8;
-
- towns.clear();
- townsArea.clear();
- int x = 0;
- int y = 0;
- for (auto const & factionID : CGI->townh->getDefaultAllowed())
- {
- if(y >= line && (y - line) < 3)
- {
- auto getImageIndex = [](FactionID targetFactionID, bool enabled){ return targetFactionID.toFaction()->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(factionID.toFaction()->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)
- {
- pos += rect.topLeft();
- pos.w = rect.w;
- pos.h = rect.h;
- OBJECT_CONSTRUCTION;
- labelAllies = std::make_shared<CLabel>(0, 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[390] + ":");
- labelEnemies = std::make_shared<CLabel>(133, 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[391] + ":");
- }
- void CFlagBox::recreate()
- {
- flagsAllies.clear();
- flagsEnemies.clear();
- OBJECT_CONSTRUCTION;
- const int alliesX = 5 + (int)labelAllies->getWidth();
- const int enemiesX = 5 + 133 + (int)labelEnemies->getWidth();
- for(auto i = CSH->si->playerInfos.cbegin(); i != CSH->si->playerInfos.cend(); i++)
- {
- auto flag = std::make_shared<CAnimImage>(AnimationPath::builtin("ITGFLAGS.DEF"), i->first.getNum(), 0);
- if(i->first == CSH->myFirstColor() || CSH->getPlayerTeamId(i->first) == CSH->getPlayerTeamId(CSH->myFirstColor()))
- {
- flag->moveTo(Point(pos.x + alliesX + (int)flagsAllies.size()*flag->pos.w, pos.y));
- flagsAllies.push_back(flag);
- }
- else
- {
- flag->moveTo(Point(pos.x + enemiesX + (int)flagsEnemies.size()*flag->pos.w, pos.y));
- flagsEnemies.push_back(flag);
- }
- }
- }
- void CFlagBox::showPopupWindow(const Point & cursorPosition)
- {
- if(SEL->getMapInfo())
- GH.windows().createAndPushWindow<CFlagBoxTooltipBox>();
- }
- CFlagBox::CFlagBoxTooltipBox::CFlagBoxTooltipBox()
- : CWindowObject(BORDERED | RCLICK_POPUP | SHADOW_DISABLED, ImagePath::builtin("DIBOXBCK"))
- {
- OBJECT_CONSTRUCTION;
- labelTeamAlignment = std::make_shared<CLabel>(128, 30, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[657]);
- labelGroupTeams = std::make_shared<CLabelGroup>(FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
- std::vector<std::set<PlayerColor>> teams(PlayerColor::PLAYER_LIMIT_I);
- for(PlayerColor j(0); j < PlayerColor::PLAYER_LIMIT; j++)
- {
- if(SEL->getPlayerInfo(j).canHumanPlay || SEL->getPlayerInfo(j).canComputerPlay)
- {
- teams[SEL->getPlayerInfo(j).team].insert(j);
- }
- }
- auto curIdx = 0;
- for(const auto & team : teams)
- {
- if(team.empty())
- continue;
- labelGroupTeams->add(128, 65 + 50 * curIdx, boost::str(boost::format(CGI->generaltexth->allTexts[656]) % (curIdx + 1)));
- int curx = 128 - 9 * team.size();
- for(const auto & player : team)
- {
- iconsFlags.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("ITGFLAGS.DEF"), player, 0, curx, 75 + 50 * curIdx));
- curx += 18;
- }
- ++curIdx;
- }
- pos.w = 256;
- pos.h = 90 + 50 * curIdx;
- background->scaleTo(Point(pos.w, pos.h));
- center();
- }
|