2018-01-05 19:21:07 +02:00
|
|
|
/*
|
|
|
|
* 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 "../CMusicHandler.h"
|
|
|
|
#include "../CVideoHandler.h"
|
|
|
|
#include "../CServerHandler.h"
|
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-04-27 19:21:06 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
2023-05-16 14:10:26 +02:00
|
|
|
#include "../gui/WindowHandler.h"
|
2024-03-23 21:12:10 +02:00
|
|
|
#include "../globalLobby/GlobalLobbyClient.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../mainmenu/CMainMenu.h"
|
|
|
|
#include "../widgets/Buttons.h"
|
2023-05-30 16:31:45 +02:00
|
|
|
#include "../widgets/CComponent.h"
|
2024-01-18 16:23:12 +02:00
|
|
|
#include "../widgets/GraphicalPrimitiveCanvas.h"
|
2024-04-30 21:52:04 +02:00
|
|
|
#include "../widgets/Images.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/ObjectLists.h"
|
2023-05-30 16:31:45 +02:00
|
|
|
#include "../widgets/Slider.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
#include "../windows/GUIClasses.h"
|
|
|
|
#include "../windows/InfoWindows.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../render/CAnimation.h"
|
2023-07-31 18:50:55 +02:00
|
|
|
#include "../render/Graphics.h"
|
|
|
|
#include "../render/IFont.h"
|
2023-09-04 17:01:44 +02:00
|
|
|
#include "../render/IRenderHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/CHeroHandler.h"
|
2024-04-30 23:12:55 +02:00
|
|
|
#include "../../lib/CTownHandler.h"
|
2024-01-31 00:17:40 +02:00
|
|
|
#include "../../lib/CRandomGenerator.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../../lib/CThreadHelper.h"
|
2024-03-25 20:56:33 +02:00
|
|
|
#include "../../lib/MetaString.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../../lib/filesystem/Filesystem.h"
|
2023-05-24 01:05:59 +02:00
|
|
|
#include "../../lib/mapping/CMapHeader.h"
|
2024-03-25 20:56:33 +02:00
|
|
|
#include "../../lib/mapping/CMapInfo.h"
|
2024-04-30 01:52:49 +02:00
|
|
|
#include "../../lib/networkPacks/PacksForLobby.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
ISelectionScreenInfo::ISelectionScreenInfo(ESelectionScreen ScreenType)
|
|
|
|
: screenType(ScreenType)
|
|
|
|
{
|
|
|
|
assert(!SEL);
|
|
|
|
SEL = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ISelectionScreenInfo::~ISelectionScreenInfo()
|
|
|
|
{
|
|
|
|
assert(SEL == this);
|
|
|
|
SEL = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ISelectionScreenInfo::getCurrentDifficulty()
|
|
|
|
{
|
|
|
|
return getStartInfo()->difficulty;
|
|
|
|
}
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
PlayerInfo ISelectionScreenInfo::getPlayerInfo(PlayerColor color)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2024-01-04 23:52:57 +02:00
|
|
|
return getMapInfo()->mapHeader->players.at(color.getNum());
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CSelectionBase::CSelectionBase(ESelectionScreen type)
|
|
|
|
: CWindowObject(BORDERED | SHADOW_DISABLED), ISelectionScreenInfo(type)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
pos.w = 762;
|
|
|
|
pos.h = 584;
|
|
|
|
if(screenType == ESelectionScreen::campaignList)
|
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
setBackground(ImagePath::builtin("CamCust.bmp"));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const JsonVector & bgNames = CMainMenuConfig::get().getConfig()["game-select"].Vector();
|
2023-08-23 14:07:50 +02:00
|
|
|
setBackground(ImagePath::fromJson(*RandomGeneratorUtil::nextItem(bgNames, CRandomGenerator::getDefault())));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
pos = background->center();
|
|
|
|
card = std::make_shared<InfoCard>();
|
2023-08-23 14:07:50 +02:00
|
|
|
buttonBack = std::make_shared<CButton>(Point(581, 535), AnimationPath::builtin("SCNRBACK.DEF"), CGI->generaltexth->zelp[105], [=](){ close();}, EShortcut::GLOBAL_CANCEL);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSelectionBase::toggleTab(std::shared_ptr<CIntObject> tab)
|
|
|
|
{
|
2023-05-17 22:22:45 +02:00
|
|
|
if(curTab && curTab->isActive())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
curTab->deactivate();
|
|
|
|
curTab->recActions = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(curTab != tab)
|
|
|
|
{
|
|
|
|
tab->recActions = 255 - DISPOSE;
|
|
|
|
tab->activate();
|
|
|
|
curTab = tab;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curTab.reset();
|
|
|
|
}
|
2023-10-21 02:12:34 +02:00
|
|
|
|
2023-10-21 02:26:03 +02:00
|
|
|
if(tabSel->showRandom && tab != tabOpt)
|
2023-10-21 02:16:42 +02:00
|
|
|
{
|
2023-10-21 02:12:34 +02:00
|
|
|
tabSel->curFolder = "";
|
2023-10-21 02:16:42 +02:00
|
|
|
tabSel->showRandom = false;
|
2023-10-21 02:22:22 +02:00
|
|
|
tabSel->filter(0, true);
|
2023-10-21 02:16:42 +02:00
|
|
|
}
|
2023-10-21 02:12:34 +02:00
|
|
|
|
2023-05-16 14:10:26 +02:00
|
|
|
GH.windows().totalRedraw();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InfoCard::InfoCard()
|
2024-04-30 21:52:04 +02:00
|
|
|
: showChat(true)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
2023-07-03 18:24:12 +02:00
|
|
|
setRedrawParent(true);
|
2018-01-05 19:21:07 +02:00
|
|
|
pos.x += 393;
|
|
|
|
pos.y += 6;
|
|
|
|
|
2023-08-21 20:45:00 +02:00
|
|
|
labelSaveDate = std::make_shared<CLabel>(310, 38, FONT_SMALL, ETextAlignment::BOTTOMRIGHT, Colors::WHITE);
|
2023-10-21 18:45:45 +02:00
|
|
|
labelMapSize = std::make_shared<CLabel>(333, 56, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE);
|
2022-11-26 23:12:20 +02:00
|
|
|
mapName = std::make_shared<CLabel>(26, 39, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW);
|
2018-01-05 19:21:07 +02:00
|
|
|
Rect descriptionRect(26, 149, 320, 115);
|
|
|
|
mapDescription = std::make_shared<CTextBox>("", descriptionRect, 1);
|
2023-08-23 14:07:50 +02:00
|
|
|
playerListBg = std::make_shared<CPicture>(ImagePath::builtin("CHATPLUG.bmp"), 16, 276);
|
2023-12-23 18:12:55 +02:00
|
|
|
chat = std::make_shared<CChatBox>(Rect(18, 126, 335, 143));
|
2024-04-30 21:52:04 +02:00
|
|
|
pvpBox = std::make_shared<PvPBox>(Rect(17, 396, 338, 105));
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2024-03-26 13:01:15 +02:00
|
|
|
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(); });
|
2024-03-25 20:56:33 +02:00
|
|
|
|
|
|
|
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);
|
2024-03-23 21:12:10 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
if(SEL->screenType == ESelectionScreen::campaignList)
|
|
|
|
{
|
2022-11-26 23:12:20 +02:00
|
|
|
labelCampaignDescription = std::make_shared<CLabel>(26, 132, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[38]);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
background = std::make_shared<CPicture>(ImagePath::builtin("GSELPOP1.bmp"), 0, 0);
|
2018-01-05 19:21:07 +02:00
|
|
|
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;
|
2023-08-23 14:07:50 +02:00
|
|
|
iconsMapSizes = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRMPSZ"), 4, 0, 318, 22); //let it be custom size (frame 4) by default
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
iconDifficulty = std::make_shared<CToggleGroup>(0);
|
|
|
|
{
|
2024-02-12 13:22:54 +02:00
|
|
|
constexpr std::array difButns = {"GSPBUT3.DEF", "GSPBUT4.DEF", "GSPBUT5.DEF", "GSPBUT6.DEF", "GSPBUT7.DEF"};
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < 5; i++)
|
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
auto button = std::make_shared<CToggleButton>(Point(110 + i * 32, 450), AnimationPath::builtin(difButns[i]), CGI->generaltexth->zelp[24 + i]);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
iconDifficulty->addToggle(i, button);
|
|
|
|
if(SEL->screenType != ESelectionScreen::newGame)
|
|
|
|
button->block(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flagbox = std::make_shared<CFlagBox>(Rect(24, 400, 335, 23));
|
2022-11-26 23:12:20 +02:00
|
|
|
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]);
|
2023-08-23 14:07:50 +02:00
|
|
|
iconsVictoryCondition = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRVICT"), 0, 0, 24, 302);
|
|
|
|
iconsLossCondition = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRLOSS"), 0, 0, 24, 359);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
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);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
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);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2024-03-23 21:12:10 +02:00
|
|
|
labelGroupPlayers = std::make_shared<CLabelGroup>(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
|
2019-04-20 18:26:54 +02:00
|
|
|
disableLabelRedraws();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2024-04-30 21:52:04 +02:00
|
|
|
setChat(false);
|
2024-03-25 20:56:33 +02:00
|
|
|
if (CSH->inLobbyRoom())
|
2024-04-30 21:52:04 +02:00
|
|
|
setChat(true); // FIXME: less ugly version?
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2019-04-20 18:26:54 +02:00
|
|
|
void InfoCard::disableLabelRedraws()
|
|
|
|
{
|
|
|
|
labelSaveDate->setAutoRedraw(false);
|
2023-10-21 16:49:50 +02:00
|
|
|
labelMapSize->setAutoRedraw(false);
|
2019-04-20 18:26:54 +02:00
|
|
|
mapName->setAutoRedraw(false);
|
|
|
|
mapDescription->label->setAutoRedraw(false);
|
|
|
|
labelVictoryConditionText->setAutoRedraw(false);
|
|
|
|
labelLossConditionText->setAutoRedraw(false);
|
|
|
|
labelDifficulty->setAutoRedraw(false);
|
|
|
|
labelDifficultyPercent->setAutoRedraw(false);
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
void InfoCard::changeSelection()
|
|
|
|
{
|
2019-04-20 18:26:54 +02:00
|
|
|
auto mapInfo = SEL->getMapInfo();
|
|
|
|
if(!mapInfo)
|
2018-01-05 19:21:07 +02:00
|
|
|
return;
|
|
|
|
|
2019-04-20 18:26:54 +02:00
|
|
|
labelSaveDate->setText(mapInfo->date);
|
2023-09-27 22:53:13 +02:00
|
|
|
mapName->setText(mapInfo->getNameTranslated());
|
|
|
|
mapDescription->setText(mapInfo->getDescriptionTranslated());
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2019-04-20 18:26:54 +02:00
|
|
|
mapDescription->label->scrollTextTo(0, false);
|
2018-01-05 19:21:07 +02:00
|
|
|
if(mapDescription->slider)
|
2023-05-30 17:10:22 +02:00
|
|
|
mapDescription->slider->scrollToMin();
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
if(SEL->screenType == ESelectionScreen::campaignList)
|
|
|
|
return;
|
|
|
|
|
2019-04-20 18:26:54 +02:00
|
|
|
const CMapHeader * header = mapInfo->mapHeader.get();
|
2023-11-04 14:34:07 +02:00
|
|
|
|
|
|
|
labelMapSize->setText(std::to_string(header->width) + "x" + std::to_string(header->height));
|
|
|
|
iconsMapSizes->setFrame(mapInfo->getMapSizeIconId());
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
iconsVictoryCondition->setFrame(header->victoryIconIndex);
|
2023-06-18 12:51:11 +02:00
|
|
|
labelVictoryConditionText->setText(header->victoryMessage.toString());
|
2018-01-05 19:21:07 +02:00
|
|
|
iconsLossCondition->setFrame(header->defeatIconIndex);
|
2023-06-18 12:51:11 +02:00
|
|
|
labelLossConditionText->setText(header->defeatMessage.toString());
|
2018-01-05 19:21:07 +02:00
|
|
|
flagbox->recreate();
|
2024-02-05 21:27:55 +02:00
|
|
|
labelDifficulty->setText(CGI->generaltexth->arraytxt[142 + vstd::to_underlying(mapInfo->mapHeader->difficulty)]);
|
2018-01-05 19:21:07 +02:00
|
|
|
iconDifficulty->setSelected(SEL->getCurrentDifficulty());
|
2023-09-02 20:39:16 +02:00
|
|
|
if(SEL->screenType == ESelectionScreen::loadGame || SEL->screenType == ESelectionScreen::saveGame)
|
2023-09-02 19:37:56 +02:00
|
|
|
for(auto & button : iconDifficulty->buttons)
|
|
|
|
button.second->setEnabled(button.first == SEL->getCurrentDifficulty());
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
const std::array<std::string, 5> difficultyPercent = {"80%", "100%", "130%", "160%", "200%"};
|
|
|
|
labelDifficultyPercent->setText(difficultyPercent[SEL->getCurrentDifficulty()]);
|
|
|
|
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
// FIXME: We recreate them each time because CLabelGroup don't use smart pointers
|
2024-03-23 21:12:10 +02:00
|
|
|
labelGroupPlayers = std::make_shared<CLabelGroup>(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
|
2024-04-30 21:52:04 +02:00
|
|
|
if(!showChat)
|
2024-03-23 21:12:10 +02:00
|
|
|
labelGroupPlayers->disable();
|
|
|
|
|
2024-03-26 13:01:15 +02:00
|
|
|
for(const auto & p : CSH->playerNames)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2024-03-23 21:12:10 +02:00
|
|
|
int slotsUsed = labelGroupPlayers->currentSize();
|
|
|
|
Point labelPosition;
|
|
|
|
|
2024-03-26 13:01:15 +02:00
|
|
|
if(slotsUsed < 4)
|
2024-03-23 21:12:10 +02:00
|
|
|
labelPosition = Point(24, 285 + slotsUsed * graphics->fonts[FONT_SMALL]->getLineHeight()); // left column
|
2018-01-05 19:21:07 +02:00
|
|
|
else
|
2024-03-23 21:12:10 +02:00
|
|
|
labelPosition = Point(193, 285 + (slotsUsed - 4) * graphics->fonts[FONT_SMALL]->getLineHeight()); // right column
|
|
|
|
|
|
|
|
labelGroupPlayers->add(labelPosition.x, labelPosition.y, p.second.name);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-30 21:52:04 +02:00
|
|
|
void InfoCard::toggleChat()
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2024-04-30 21:52:04 +02:00
|
|
|
setChat(!showChat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InfoCard::setChat(bool activateChat)
|
|
|
|
{
|
|
|
|
if(showChat == activateChat)
|
2018-01-05 19:21:07 +02:00
|
|
|
return;
|
|
|
|
|
2024-04-30 21:52:04 +02:00
|
|
|
if(activateChat)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
if(SEL->screenType == ESelectionScreen::campaignList)
|
|
|
|
{
|
|
|
|
labelCampaignDescription->disable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labelScenarioDescription->disable();
|
|
|
|
labelVictoryCondition->disable();
|
|
|
|
labelLossCondition->disable();
|
|
|
|
iconsVictoryCondition->disable();
|
|
|
|
labelVictoryConditionText->disable();
|
|
|
|
iconsLossCondition->disable();
|
|
|
|
labelLossConditionText->disable();
|
2024-03-23 21:12:10 +02:00
|
|
|
labelGroupPlayers->enable();
|
|
|
|
}
|
|
|
|
if (CSH->inLobbyRoom())
|
|
|
|
{
|
|
|
|
buttonInvitePlayers->enable();
|
|
|
|
buttonOpenGlobalLobby->enable();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2024-04-30 21:52:04 +02:00
|
|
|
labelMapDiff->disable();
|
|
|
|
labelPlayerDifficulty->disable();
|
|
|
|
labelRating->disable();
|
|
|
|
labelDifficulty->disable();
|
|
|
|
labelDifficultyPercent->disable();
|
|
|
|
flagbox->disable();
|
|
|
|
iconDifficulty->disable();
|
2018-01-05 19:21:07 +02:00
|
|
|
mapDescription->disable();
|
|
|
|
chat->enable();
|
2024-04-30 21:52:04 +02:00
|
|
|
pvpBox->enable();
|
2018-01-05 19:21:07 +02:00
|
|
|
playerListBg->enable();
|
2024-04-30 21:52:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-23 21:12:10 +02:00
|
|
|
buttonInvitePlayers->disable();
|
|
|
|
buttonOpenGlobalLobby->disable();
|
2018-01-05 19:21:07 +02:00
|
|
|
mapDescription->enable();
|
|
|
|
chat->disable();
|
2024-04-29 23:55:02 +02:00
|
|
|
pvpBox->disable();
|
2018-01-05 19:21:07 +02:00
|
|
|
playerListBg->disable();
|
|
|
|
|
|
|
|
if(SEL->screenType == ESelectionScreen::campaignList)
|
|
|
|
{
|
|
|
|
labelCampaignDescription->enable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labelScenarioDescription->enable();
|
|
|
|
labelVictoryCondition->enable();
|
|
|
|
labelLossCondition->enable();
|
|
|
|
iconsVictoryCondition->enable();
|
|
|
|
iconsLossCondition->enable();
|
|
|
|
labelVictoryConditionText->enable();
|
|
|
|
labelLossConditionText->enable();
|
2024-03-23 21:12:10 +02:00
|
|
|
labelGroupPlayers->disable();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2024-04-30 21:52:04 +02:00
|
|
|
labelMapDiff->enable();
|
|
|
|
labelPlayerDifficulty->enable();
|
|
|
|
labelRating->enable();
|
|
|
|
labelDifficulty->enable();
|
|
|
|
labelDifficultyPercent->enable();
|
|
|
|
flagbox->enable();
|
|
|
|
iconDifficulty->enable();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 21:52:04 +02:00
|
|
|
showChat = activateChat;
|
2023-05-16 14:10:26 +02:00
|
|
|
GH.windows().totalRedraw();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CChatBox::CChatBox(const Rect & rect)
|
|
|
|
: CIntObject(KEYBOARD | TEXTINPUT)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION;
|
2022-12-15 23:24:03 +02:00
|
|
|
pos += rect.topLeft();
|
2023-07-03 18:24:12 +02:00
|
|
|
setRedrawParent(true);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
const int height = static_cast<int>(graphics->fonts[FONT_SMALL]->getLineHeight());
|
2023-12-23 18:12:55 +02:00
|
|
|
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));
|
2023-12-28 21:27:21 +02:00
|
|
|
inputBox = std::make_shared<CTextInput>(textInputArea, EFonts::FONT_SMALL, nullptr, ETextAlignment::TOPLEFT, true);
|
2018-01-05 19:21:07 +02:00
|
|
|
inputBox->removeUsedEvents(KEYBOARD);
|
2023-12-23 18:12:55 +02:00
|
|
|
chatHistory = std::make_shared<CTextBox>("", chatHistoryArea, 1);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
chatHistory->label->color = Colors::GREEN;
|
|
|
|
}
|
|
|
|
|
2023-10-01 16:40:26 +02:00
|
|
|
bool CChatBox::captureThisKey(EShortcut key)
|
|
|
|
{
|
|
|
|
return !inputBox->getText().empty() && key == EShortcut::GLOBAL_ACCEPT;
|
|
|
|
}
|
|
|
|
|
2023-04-27 19:21:06 +02:00
|
|
|
void CChatBox::keyPressed(EShortcut key)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-04-28 13:22:03 +02:00
|
|
|
if(key == EShortcut::GLOBAL_ACCEPT && inputBox->getText().size())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2022-12-19 22:04:50 +02:00
|
|
|
CSH->sendMessage(inputBox->getText());
|
2018-01-05 19:21:07 +02:00
|
|
|
inputBox->setText("");
|
|
|
|
}
|
|
|
|
else
|
2023-02-02 18:42:44 +02:00
|
|
|
inputBox->keyPressed(key);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CChatBox::addNewMessage(const std::string & text)
|
|
|
|
{
|
2023-09-04 12:03:15 +02:00
|
|
|
CCS->soundh->playSound(AudioPath::builtin("CHAT"));
|
2022-12-19 22:04:50 +02:00
|
|
|
chatHistory->setText(chatHistory->label->getText() + text + "\n");
|
2018-01-05 19:21:07 +02:00
|
|
|
if(chatHistory->slider)
|
2023-05-30 17:10:22 +02:00
|
|
|
chatHistory->slider->scrollToMax();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2024-04-29 23:55:02 +02:00
|
|
|
PvPBox::PvPBox(const Rect & rect)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION;
|
|
|
|
pos += rect.topLeft();
|
|
|
|
setRedrawParent(true);
|
|
|
|
|
2024-04-30 21:52:04 +02:00
|
|
|
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);
|
|
|
|
|
2024-05-01 00:49:33 +02:00
|
|
|
factionSelector = std::make_shared<FactionSelector>(Point(5, 3));
|
2024-04-30 23:12:55 +02:00
|
|
|
|
2024-05-01 00:49:33 +02:00
|
|
|
auto getBannedTowns = [this](){
|
|
|
|
std::vector<FactionID> bannedTowns;
|
|
|
|
for(auto & town : factionSelector->townsEnabled)
|
|
|
|
if(!town.second)
|
|
|
|
bannedTowns.push_back(town.first);
|
|
|
|
return bannedTowns;
|
|
|
|
};
|
|
|
|
|
2024-05-01 01:26:51 +02:00
|
|
|
auto buttonColor = CSH->isGuest() ? Colors::WHITE : Colors::ORANGE;
|
|
|
|
|
|
|
|
buttonFlipCoin = std::make_shared<CButton>(Point(190, 6), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.coin.help")), [](){
|
2024-04-30 01:52:49 +02:00
|
|
|
LobbyPvPAction lpa;
|
|
|
|
lpa.action = LobbyPvPAction::COIN;
|
|
|
|
CSH->sendLobbyPack(lpa);
|
|
|
|
}, EShortcut::NONE);
|
2024-05-01 01:26:51 +02:00
|
|
|
buttonFlipCoin->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.coin.hover"), EFonts::FONT_SMALL, buttonColor);
|
|
|
|
buttonFlipCoin->block(!CSH->isGuest());
|
2024-04-30 01:52:49 +02:00
|
|
|
|
2024-05-01 01:26:51 +02:00
|
|
|
buttonRandomTown = std::make_shared<CButton>(Point(190, 31), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.randomTown.help")), [getBannedTowns](){
|
2024-04-30 01:52:49 +02:00
|
|
|
LobbyPvPAction lpa;
|
|
|
|
lpa.action = LobbyPvPAction::RANDOM_TOWN;
|
2024-05-01 00:49:33 +02:00
|
|
|
lpa.bannedTowns = getBannedTowns();
|
2024-04-30 01:52:49 +02:00
|
|
|
CSH->sendLobbyPack(lpa);
|
|
|
|
}, EShortcut::NONE);
|
2024-05-01 01:26:51 +02:00
|
|
|
buttonRandomTown->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTown.hover"), EFonts::FONT_SMALL, buttonColor);
|
|
|
|
buttonRandomTown->block(!CSH->isGuest());
|
2024-04-30 01:52:49 +02:00
|
|
|
|
2024-05-01 01:26:51 +02:00
|
|
|
buttonRandomTownVs = std::make_shared<CButton>(Point(190, 56), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.help")), [getBannedTowns](){
|
2024-04-30 01:52:49 +02:00
|
|
|
LobbyPvPAction lpa;
|
|
|
|
lpa.action = LobbyPvPAction::RANDOM_TOWN_VS;
|
2024-05-01 00:49:33 +02:00
|
|
|
lpa.bannedTowns = getBannedTowns();
|
2024-04-30 01:52:49 +02:00
|
|
|
CSH->sendLobbyPack(lpa);
|
|
|
|
}, EShortcut::NONE);
|
2024-05-01 01:26:51 +02:00
|
|
|
buttonRandomTownVs->setTextOverlay(CGI->generaltexth->translate("vcmi.lobby.pvp.randomTownVs.hover"), EFonts::FONT_SMALL, buttonColor);
|
|
|
|
buttonRandomTownVs->block(!CSH->isGuest());
|
2024-04-29 23:55:02 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 23:12:55 +02:00
|
|
|
FactionSelector::FactionSelector(const Point & loc)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION;
|
|
|
|
pos += loc;
|
|
|
|
setRedrawParent(true);
|
|
|
|
|
2024-05-01 00:49:33 +02:00
|
|
|
int count = 0;
|
|
|
|
CGI->factions()->forEach([this, &count](const Faction *entity, bool &stop){
|
|
|
|
if(!entity->hasTown())
|
|
|
|
return;
|
|
|
|
townsEnabled[entity->getFaction()] = true;
|
|
|
|
count++;
|
|
|
|
});
|
|
|
|
|
|
|
|
auto divisionRoundUp = [](int x, int y){ return (x + (y - 1)) / y; };
|
2024-05-01 13:36:00 +02:00
|
|
|
|
|
|
|
if(count > 9)
|
|
|
|
{
|
|
|
|
slider = std::make_shared<CSlider>(Point(144, 0), 96, std::bind(&FactionSelector::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));
|
|
|
|
}
|
2024-05-01 00:49:33 +02:00
|
|
|
|
|
|
|
updateListItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FactionSelector::updateListItems()
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION;
|
2024-05-01 13:36:00 +02:00
|
|
|
int line = slider ? slider->getValue() : 0;
|
|
|
|
int x_offset = slider ? 0 : 8;
|
2024-05-01 00:49:33 +02:00
|
|
|
|
|
|
|
towns.clear();
|
|
|
|
townsArea.clear();
|
|
|
|
|
2024-04-30 23:12:55 +02:00
|
|
|
int x = 0, y = 0;
|
2024-05-01 13:36:00 +02:00
|
|
|
CGI->factions()->forEach([this, &x, &y, line, x_offset](const Faction *entity, bool &stop){
|
2024-04-30 23:12:55 +02:00
|
|
|
if(!entity->hasTown())
|
|
|
|
return;
|
|
|
|
|
2024-05-01 00:49:33 +02:00
|
|
|
if(y >= line && (y - line) < 3)
|
2024-05-01 13:19:58 +02:00
|
|
|
{
|
2024-05-01 00:49:33 +02:00
|
|
|
FactionID factionID = entity->getFaction();
|
|
|
|
auto getImageIndex = [](FactionID factionID, bool enabled){ return (*CGI->townh)[factionID]->town->clientInfo.icons[true][!enabled] + 2; };
|
2024-05-01 13:36:00 +02:00
|
|
|
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](){
|
2024-05-01 00:49:33 +02:00
|
|
|
townsEnabled[factionID] = !townsEnabled[factionID];
|
|
|
|
towns[factionID]->setFrame(getImageIndex(factionID, townsEnabled[factionID]));
|
|
|
|
redraw();
|
2024-05-01 13:19:58 +02:00
|
|
|
}, [factionID](){ CRClickPopup::createAndPush((*CGI->townh)[factionID]->town->faction->getNameTranslated()); });
|
2024-05-01 00:49:33 +02:00
|
|
|
}
|
2024-04-30 23:12:55 +02:00
|
|
|
|
|
|
|
if (x < 2)
|
|
|
|
x++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-05-01 00:49:33 +02:00
|
|
|
void FactionSelector::sliderMove(int slidPos)
|
|
|
|
{
|
|
|
|
if(!slider)
|
|
|
|
return; // ignore spurious call when slider is being created
|
|
|
|
updateListItems();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
CFlagBox::CFlagBox(const Rect & rect)
|
2023-06-13 18:33:35 +02:00
|
|
|
: CIntObject(SHOW_POPUP)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2022-12-15 23:24:03 +02:00
|
|
|
pos += rect.topLeft();
|
2018-01-05 19:21:07 +02:00
|
|
|
pos.w = rect.w;
|
|
|
|
pos.h = rect.h;
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
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] + ":");
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-09-04 17:01:44 +02:00
|
|
|
iconsTeamFlags = GH.renderHandler().loadAnimation(AnimationPath::builtin("ITGFLAGS.DEF"));
|
2018-01-05 19:21:07 +02:00
|
|
|
iconsTeamFlags->preload();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFlagBox::recreate()
|
|
|
|
{
|
|
|
|
flagsAllies.clear();
|
|
|
|
flagsEnemies.clear();
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
2020-10-01 10:38:06 +02:00
|
|
|
const int alliesX = 5 + (int)labelAllies->getWidth();
|
|
|
|
const int enemiesX = 5 + 133 + (int)labelEnemies->getWidth();
|
2018-01-05 19:21:07 +02:00
|
|
|
for(auto i = CSH->si->playerInfos.cbegin(); i != CSH->si->playerInfos.cend(); i++)
|
|
|
|
{
|
|
|
|
auto flag = std::make_shared<CAnimImage>(iconsTeamFlags, i->first.getNum(), 0);
|
|
|
|
if(i->first == CSH->myFirstColor() || CSH->getPlayerTeamId(i->first) == CSH->getPlayerTeamId(CSH->myFirstColor()))
|
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
flag->moveTo(Point(pos.x + alliesX + (int)flagsAllies.size()*flag->pos.w, pos.y));
|
2018-01-05 19:21:07 +02:00
|
|
|
flagsAllies.push_back(flag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
flag->moveTo(Point(pos.x + enemiesX + (int)flagsEnemies.size()*flag->pos.w, pos.y));
|
2018-01-05 19:21:07 +02:00
|
|
|
flagsEnemies.push_back(flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void CFlagBox::showPopupWindow(const Point & cursorPosition)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-06-11 17:20:10 +02:00
|
|
|
if(SEL->getMapInfo())
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CFlagBoxTooltipBox>(iconsTeamFlags);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CFlagBox::CFlagBoxTooltipBox::CFlagBoxTooltipBox(std::shared_ptr<CAnimation> icons)
|
2023-08-23 14:07:50 +02:00
|
|
|
: CWindowObject(BORDERED | RCLICK_POPUP | SHADOW_DISABLED, ImagePath::builtin("DIBOXBCK"))
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
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);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
std::vector<std::set<PlayerColor>> teams(PlayerColor::PLAYER_LIMIT_I);
|
|
|
|
|
|
|
|
for(PlayerColor j(0); j < PlayerColor::PLAYER_LIMIT; j++)
|
2023-09-03 07:05:02 +02:00
|
|
|
{
|
|
|
|
if(SEL->getPlayerInfo(j).canHumanPlay || SEL->getPlayerInfo(j).canComputerPlay)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-03 07:05:02 +02:00
|
|
|
teams[SEL->getPlayerInfo(j).team].insert(j);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-09-03 07:05:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto curIdx = 0;
|
|
|
|
for(const auto & team : teams)
|
|
|
|
{
|
|
|
|
if(team.empty())
|
|
|
|
continue;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-09-03 07:05:02 +02:00
|
|
|
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)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-03 07:05:02 +02:00
|
|
|
iconsFlags.push_back(std::make_shared<CAnimImage>(icons, player, 0, curx, 75 + 50 * curIdx));
|
2018-01-05 19:21:07 +02:00
|
|
|
curx += 18;
|
|
|
|
}
|
2023-09-03 07:05:02 +02:00
|
|
|
++curIdx;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-09-03 07:05:02 +02:00
|
|
|
pos.w = 256;
|
|
|
|
pos.h = 90 + 50 * curIdx;
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
background->scaleTo(Point(pos.w, pos.h));
|
|
|
|
center();
|
|
|
|
}
|