|
@@ -62,6 +62,48 @@ GlobalLobbyRoomModCard::GlobalLobbyRoomModCard(const GlobalLobbyRoomModInfo & mo
|
|
|
labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.mod.state." + statusToString.at(modInfo.status)));
|
|
|
}
|
|
|
|
|
|
+static const std::string getJoinRoomErrorMessage(const GlobalLobbyRoom & roomDescription, const std::vector<GlobalLobbyRoomModInfo> & modVerificationList)
|
|
|
+{
|
|
|
+ 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";
|
|
|
+
|
|
|
+ if (VCMI_VERSION_STRING != roomDescription.gameVersion)
|
|
|
+ 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:
|
|
|
+ return "vcmi.preview.join.error.mods";
|
|
|
+ break;
|
|
|
+ case ModVerificationStatus::VERSION_MISMATCH:
|
|
|
+ case ModVerificationStatus::FULL_MATCH:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ assert(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+}
|
|
|
+
|
|
|
GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const std::string & roomUUID)
|
|
|
: CWindowObject(BORDERED)
|
|
|
, roomUUID(roomUUID)
|
|
@@ -73,7 +115,7 @@ GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const s
|
|
|
pos.h = 400;
|
|
|
|
|
|
GlobalLobbyRoom roomDescription = CSH->getGlobalLobby().getActiveRoomByName(roomUUID);
|
|
|
- for (auto const & modEntry : ModVerificationInfo::verifyListAgainstLocalMods(roomDescription.modList))
|
|
|
+ for(const auto & modEntry : ModVerificationInfo::verifyListAgainstLocalMods(roomDescription.modList))
|
|
|
{
|
|
|
GlobalLobbyRoomModInfo modInfo;
|
|
|
modInfo.status = modEntry.second;
|
|
@@ -86,26 +128,33 @@ GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const s
|
|
|
modVerificationList.push_back(modInfo);
|
|
|
}
|
|
|
|
|
|
- bool gameStarted = roomDescription.statusID != "public" && roomDescription.statusID != "private";
|
|
|
- bool publicRoom = roomDescription.statusID == "public";
|
|
|
- bool hasInvite = CSH->getGlobalLobby().isInvitedToRoom(roomDescription.gameRoomID);
|
|
|
- bool canJoinRoom = (publicRoom || hasInvite) && !gameStarted && !CSH->inGame();
|
|
|
+ MetaString subtitleText;
|
|
|
+ subtitleText.appendTextID("vcmi.lobby.preview.subtitle");
|
|
|
+ subtitleText.replaceRawString(roomDescription.description);
|
|
|
+ subtitleText.replaceRawString(roomDescription.hostAccountDisplayName);
|
|
|
|
|
|
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
|
|
|
- labelTitle = std::make_shared<CLabel>( pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.room.join"));
|
|
|
- labelSubtitle = std::make_shared<CLabel>( pos.w / 2, 40, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, "Game room hosted by AccountName");
|
|
|
+ labelTitle = std::make_shared<CLabel>( pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.preview.title").toString());
|
|
|
+ labelSubtitle = std::make_shared<CLabel>( pos.w / 2, 40, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, subtitleText.toString());
|
|
|
|
|
|
- labelDescription = std::make_shared<CLabel>( 20, 60, FONT_MEDIUM, ETextAlignment::CENTERLEFT, Colors::YELLOW, roomDescription.description);
|
|
|
- labelVersion = std::make_shared<CLabel>( 20, 80, FONT_MEDIUM, ETextAlignment::CENTERLEFT, Colors::YELLOW, "Game version: " + roomDescription.gameVersion);
|
|
|
+ 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);
|
|
|
|
|
|
buttonJoin = std::make_shared<CButton>(Point(10, 360), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this](){ onJoin(); });
|
|
|
buttonClose = std::make_shared<CButton>(Point(100, 360), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this](){ onClose(); });
|
|
|
|
|
|
- if (canJoinRoom)
|
|
|
- labelJoinStatus = std::make_shared<CLabel>( 20, 300, FONT_MEDIUM, ETextAlignment::CENTERLEFT, Colors::YELLOW, "Join Room?");
|
|
|
+ MetaString joinStatusText;
|
|
|
+ std::string errorMessage = getJoinRoomErrorMessage(roomDescription, modVerificationList);
|
|
|
+ if (!errorMessage.empty())
|
|
|
+ {
|
|
|
+ joinStatusText.appendTextID("vcmi.lobby.preview.error.header");
|
|
|
+ joinStatusText.appendRawString("\n");
|
|
|
+ joinStatusText.appendTextID(errorMessage);
|
|
|
+ }
|
|
|
else
|
|
|
- labelJoinStatus = std::make_shared<CLabel>( 20, 300, FONT_MEDIUM, ETextAlignment::CENTERLEFT, Colors::YELLOW, "Unable to join room!");
|
|
|
+ joinStatusText.appendTextID("vcmi.lobby.preview.allowed");
|
|
|
|
|
|
+ labelJoinStatus = std::make_shared<CTextBox>(joinStatusText.toString(), Rect(10, 280, 150, 70), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
|
|
|
|
|
|
const auto & createAccountCardCallback = [participants = roomDescription.participants](size_t index) -> std::shared_ptr<CIntObject>
|
|
|
{
|
|
@@ -117,7 +166,7 @@ GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const s
|
|
|
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);
|
|
|
- accountListTitle = std::make_shared<CLabel>( 12, 109, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, "Players in room");
|
|
|
+ accountListTitle = std::make_shared<CLabel>( 12, 109, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.preview.players").toString());
|
|
|
|
|
|
const auto & createModCardCallback = [this](size_t index) -> std::shared_ptr<CIntObject>
|
|
|
{
|
|
@@ -129,9 +178,9 @@ GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const s
|
|
|
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);
|
|
|
- modListTitle = std::make_shared<CLabel>( 182, 59, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, "Used mods");
|
|
|
+ modListTitle = std::make_shared<CLabel>( 182, 59, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.preview.mods").toString());
|
|
|
|
|
|
- buttonJoin->block(!canJoinRoom);
|
|
|
+ buttonJoin->block(!errorMessage.empty());
|
|
|
filledBackground->playerColored(PlayerColor(1));
|
|
|
center();
|
|
|
}
|