2024-04-16 15:30:22 +02:00
|
|
|
/*
|
|
|
|
* GlobalLobbyRoomWindow.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 "GlobalLobbyRoomWindow.h"
|
|
|
|
|
|
|
|
#include "GlobalLobbyClient.h"
|
|
|
|
#include "GlobalLobbyDefines.h"
|
|
|
|
#include "GlobalLobbyWindow.h"
|
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CServerHandler.h"
|
|
|
|
#include "../gui/CGuiHandler.h"
|
2024-05-18 21:59:28 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
2024-04-16 15:30:22 +02:00
|
|
|
#include "../mainmenu/CMainMenu.h"
|
|
|
|
#include "../widgets/Buttons.h"
|
|
|
|
#include "../widgets/Images.h"
|
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
#include "../widgets/GraphicalPrimitiveCanvas.h"
|
|
|
|
#include "../widgets/ObjectLists.h"
|
|
|
|
|
|
|
|
#include "../../lib/modding/CModHandler.h"
|
2024-11-09 22:29:07 +02:00
|
|
|
#include "../../lib/modding/ModDescription.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../../lib/texts/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/texts/MetaString.h"
|
2024-04-16 15:30:22 +02:00
|
|
|
|
|
|
|
GlobalLobbyRoomAccountCard::GlobalLobbyRoomAccountCard(const GlobalLobbyAccount & accountDescription)
|
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2024-04-16 15:30:22 +02:00
|
|
|
pos.w = 130;
|
|
|
|
pos.h = 40;
|
|
|
|
backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1);
|
2024-07-31 21:40:49 +02:00
|
|
|
labelName = std::make_shared<CLabel>(5, 10, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, accountDescription.displayName, 120);
|
2024-04-16 15:30:22 +02:00
|
|
|
labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, accountDescription.status);
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalLobbyRoomModCard::GlobalLobbyRoomModCard(const GlobalLobbyRoomModInfo & modInfo)
|
|
|
|
{
|
|
|
|
const std::map<ModVerificationStatus, std::string> statusToString = {
|
|
|
|
{ ModVerificationStatus::NOT_INSTALLED, "missing" },
|
|
|
|
{ ModVerificationStatus::DISABLED, "disabled" },
|
|
|
|
{ ModVerificationStatus::EXCESSIVE, "excessive" },
|
|
|
|
{ ModVerificationStatus::VERSION_MISMATCH, "version" },
|
|
|
|
{ ModVerificationStatus::FULL_MATCH, "compatible" }
|
|
|
|
};
|
|
|
|
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2024-04-16 15:30:22 +02:00
|
|
|
pos.w = 200;
|
|
|
|
pos.h = 40;
|
|
|
|
backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1);
|
|
|
|
|
2024-07-31 21:40:49 +02:00
|
|
|
labelName = std::make_shared<CLabel>(5, 10, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, modInfo.modName, 190);
|
2024-04-16 15:30:22 +02:00
|
|
|
labelVersion = std::make_shared<CLabel>(195, 30, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::YELLOW, modInfo.version);
|
2024-07-31 22:25:05 +02:00
|
|
|
auto statusColor = Colors::RED;
|
|
|
|
if(modInfo.status == ModVerificationStatus::FULL_MATCH)
|
|
|
|
statusColor = ColorRGBA(128, 128, 128);
|
|
|
|
else if(modInfo.status == ModVerificationStatus::VERSION_MISMATCH)
|
|
|
|
statusColor = Colors::YELLOW;
|
|
|
|
labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, statusColor, CGI->generaltexth->translate("vcmi.lobby.mod.state." + statusToString.at(modInfo.status)));
|
2024-04-16 15:30:22 +02:00
|
|
|
}
|
|
|
|
|
2024-05-06 17:33:30 +02:00
|
|
|
static std::string getJoinRoomErrorMessage(const GlobalLobbyRoom & roomDescription, const std::vector<GlobalLobbyRoomModInfo> & modVerificationList)
|
2024-04-19 16:31:59 +02:00
|
|
|
{
|
|
|
|
bool publicRoom = roomDescription.statusID == "public";
|
|
|
|
bool privateRoom = roomDescription.statusID == "private";
|
|
|
|
bool gameStarted = !publicRoom && !privateRoom;
|
|
|
|
bool hasInvite = CSH->getGlobalLobby().isInvitedToRoom(roomDescription.gameRoomID);
|
|
|
|
bool alreadyInRoom = CSH->inGame();
|
|
|
|
|
|
|
|
if (alreadyInRoom)
|
|
|
|
return "vcmi.lobby.preview.error.playing";
|
|
|
|
|
|
|
|
if (gameStarted)
|
|
|
|
return "vcmi.lobby.preview.error.busy";
|
|
|
|
|
2024-05-14 16:12:01 +02:00
|
|
|
CModVersion localVersion = CModVersion::fromString(VCMI_VERSION_STRING);
|
|
|
|
CModVersion hostVersion = CModVersion::fromString(roomDescription.gameVersion);
|
|
|
|
|
|
|
|
// 1.5.X can play with each other, but not with 1.X.Y
|
|
|
|
if (localVersion.major != hostVersion.major || localVersion.minor != hostVersion.minor)
|
2024-04-19 16:31:59 +02:00
|
|
|
return "vcmi.lobby.preview.error.version";
|
|
|
|
|
|
|
|
if (roomDescription.playerLimit == roomDescription.participants.size())
|
|
|
|
return "vcmi.lobby.preview.error.full";
|
|
|
|
|
|
|
|
if (privateRoom && !hasInvite)
|
|
|
|
return "vcmi.lobby.preview.error.invite";
|
|
|
|
|
|
|
|
for(const auto & mod : modVerificationList)
|
|
|
|
{
|
|
|
|
switch (mod.status)
|
|
|
|
{
|
|
|
|
case ModVerificationStatus::NOT_INSTALLED:
|
|
|
|
case ModVerificationStatus::DISABLED:
|
|
|
|
case ModVerificationStatus::EXCESSIVE:
|
2024-04-23 18:21:57 +02:00
|
|
|
return "vcmi.lobby.preview.error.mods";
|
2024-04-19 16:31:59 +02:00
|
|
|
break;
|
|
|
|
case ModVerificationStatus::VERSION_MISMATCH:
|
|
|
|
case ModVerificationStatus::FULL_MATCH:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2024-04-16 15:30:22 +02:00
|
|
|
GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const std::string & roomUUID)
|
|
|
|
: CWindowObject(BORDERED)
|
|
|
|
, window(window)
|
2024-05-06 17:33:30 +02:00
|
|
|
, roomUUID(roomUUID)
|
2024-04-16 15:30:22 +02:00
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2024-04-16 15:30:22 +02:00
|
|
|
|
|
|
|
pos.w = 400;
|
|
|
|
pos.h = 400;
|
|
|
|
|
|
|
|
GlobalLobbyRoom roomDescription = CSH->getGlobalLobby().getActiveRoomByName(roomUUID);
|
2024-04-19 16:31:59 +02:00
|
|
|
for(const auto & modEntry : ModVerificationInfo::verifyListAgainstLocalMods(roomDescription.modList))
|
2024-04-16 15:30:22 +02:00
|
|
|
{
|
|
|
|
GlobalLobbyRoomModInfo modInfo;
|
|
|
|
modInfo.status = modEntry.second;
|
2024-04-23 18:21:57 +02:00
|
|
|
if (modEntry.second == ModVerificationStatus::EXCESSIVE)
|
2024-11-09 22:29:07 +02:00
|
|
|
modInfo.version = CGI->modh->getModInfo(modEntry.first).getVersion().toString();
|
2024-04-23 18:21:57 +02:00
|
|
|
else
|
|
|
|
modInfo.version = roomDescription.modList.at(modEntry.first).version.toString();
|
|
|
|
|
2024-04-16 15:30:22 +02:00
|
|
|
if (modEntry.second == ModVerificationStatus::NOT_INSTALLED)
|
|
|
|
modInfo.modName = roomDescription.modList.at(modEntry.first).name;
|
|
|
|
else
|
2024-11-09 22:29:07 +02:00
|
|
|
modInfo.modName = CGI->modh->getModInfo(modEntry.first).getName();
|
2024-04-16 15:30:22 +02:00
|
|
|
|
|
|
|
modVerificationList.push_back(modInfo);
|
|
|
|
}
|
2024-07-31 22:10:37 +02:00
|
|
|
std::sort(modVerificationList.begin(), modVerificationList.end(), [](const GlobalLobbyRoomModInfo &a, const GlobalLobbyRoomModInfo &b)
|
|
|
|
{
|
|
|
|
if(a.status == b.status)
|
|
|
|
return a.modName < b.modName;
|
|
|
|
|
|
|
|
return a.status < b.status;
|
|
|
|
});
|
2024-04-16 15:30:22 +02:00
|
|
|
|
2024-04-19 16:31:59 +02:00
|
|
|
MetaString subtitleText;
|
|
|
|
subtitleText.appendTextID("vcmi.lobby.preview.subtitle");
|
|
|
|
subtitleText.replaceRawString(roomDescription.description);
|
|
|
|
subtitleText.replaceRawString(roomDescription.hostAccountDisplayName);
|
2024-04-16 15:30:22 +02:00
|
|
|
|
2024-09-12 18:11:03 +02:00
|
|
|
filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
|
2024-04-19 16:31:59 +02:00
|
|
|
labelTitle = std::make_shared<CLabel>( pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.preview.title").toString());
|
2024-07-31 21:40:49 +02:00
|
|
|
labelSubtitle = std::make_shared<CLabel>( pos.w / 2, 40, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, subtitleText.toString(), 400);
|
2024-04-16 15:30:22 +02:00
|
|
|
|
2024-04-19 16:31:59 +02:00
|
|
|
labelVersionTitle = std::make_shared<CLabel>( 10, 60, FONT_MEDIUM, ETextAlignment::CENTERLEFT, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.preview.version").toString());
|
|
|
|
labelVersionValue = std::make_shared<CLabel>( 10, 80, FONT_MEDIUM, ETextAlignment::CENTERLEFT, Colors::WHITE, roomDescription.gameVersion);
|
2024-04-16 15:30:22 +02:00
|
|
|
|
2024-05-18 21:59:28 +02:00
|
|
|
buttonJoin = std::make_shared<CButton>(Point(10, 360), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this](){ onJoin(); }, EShortcut::GLOBAL_ACCEPT);
|
|
|
|
buttonClose = std::make_shared<CButton>(Point(100, 360), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this](){ onClose(); }, EShortcut::GLOBAL_CANCEL);
|
2024-04-16 15:30:22 +02:00
|
|
|
|
2024-04-19 16:31:59 +02:00
|
|
|
MetaString joinStatusText;
|
|
|
|
std::string errorMessage = getJoinRoomErrorMessage(roomDescription, modVerificationList);
|
|
|
|
if (!errorMessage.empty())
|
|
|
|
{
|
|
|
|
joinStatusText.appendTextID("vcmi.lobby.preview.error.header");
|
|
|
|
joinStatusText.appendRawString("\n");
|
|
|
|
joinStatusText.appendTextID(errorMessage);
|
|
|
|
}
|
2024-04-16 15:30:22 +02:00
|
|
|
else
|
2024-04-19 16:31:59 +02:00
|
|
|
joinStatusText.appendTextID("vcmi.lobby.preview.allowed");
|
2024-04-16 15:30:22 +02:00
|
|
|
|
2024-04-19 16:31:59 +02:00
|
|
|
labelJoinStatus = std::make_shared<CTextBox>(joinStatusText.toString(), Rect(10, 280, 150, 70), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
|
2024-04-16 15:30:22 +02:00
|
|
|
|
|
|
|
const auto & createAccountCardCallback = [participants = roomDescription.participants](size_t index) -> std::shared_ptr<CIntObject>
|
|
|
|
{
|
|
|
|
if(index < participants.size())
|
|
|
|
return std::make_shared<GlobalLobbyRoomAccountCard>(participants[index]);
|
|
|
|
return std::make_shared<CIntObject>();
|
|
|
|
};
|
|
|
|
|
|
|
|
accountListBackground = std::make_shared<TransparentFilledRectangle>(Rect(8, 98, 150, 180), ColorRGBA(0, 0, 0, 64), ColorRGBA(64, 80, 128, 255), 1);
|
|
|
|
accountList = std::make_shared<CListBox>(createAccountCardCallback, Point(10, 116), Point(0, 40), 4, roomDescription.participants.size(), 0, 1 | 4, Rect(130, 0, 160, 160));
|
|
|
|
accountList->setRedrawParent(true);
|
2024-04-19 16:31:59 +02:00
|
|
|
accountListTitle = std::make_shared<CLabel>( 12, 109, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.preview.players").toString());
|
2024-04-16 15:30:22 +02:00
|
|
|
|
|
|
|
const auto & createModCardCallback = [this](size_t index) -> std::shared_ptr<CIntObject>
|
|
|
|
{
|
|
|
|
if(index < modVerificationList.size())
|
|
|
|
return std::make_shared<GlobalLobbyRoomModCard>(modVerificationList[index]);
|
|
|
|
return std::make_shared<CIntObject>();
|
|
|
|
};
|
|
|
|
|
|
|
|
modListBackground = std::make_shared<TransparentFilledRectangle>(Rect(178, 48, 220, 340), ColorRGBA(0, 0, 0, 64), ColorRGBA(64, 80, 128, 255), 1);
|
|
|
|
modList = std::make_shared<CListBox>(createModCardCallback, Point(180, 66), Point(0, 40), 8, modVerificationList.size(), 0, 1 | 4, Rect(200, 0, 320, 320));
|
|
|
|
modList->setRedrawParent(true);
|
2024-04-19 16:31:59 +02:00
|
|
|
modListTitle = std::make_shared<CLabel>( 182, 59, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.preview.mods").toString());
|
2024-04-16 15:30:22 +02:00
|
|
|
|
2024-04-19 16:31:59 +02:00
|
|
|
buttonJoin->block(!errorMessage.empty());
|
2024-06-05 17:50:50 +02:00
|
|
|
filledBackground->setPlayerColor(PlayerColor(1));
|
2024-04-16 15:30:22 +02:00
|
|
|
center();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalLobbyRoomWindow::onJoin()
|
|
|
|
{
|
|
|
|
window->doJoinRoom(roomUUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalLobbyRoomWindow::onClose()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|