1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-11 11:31:52 +02:00

Better UI design for room preview dialog

This commit is contained in:
Ivan Savenko 2024-04-19 17:31:59 +03:00
parent 3e23a55c66
commit 662a508944
3 changed files with 81 additions and 19 deletions

View File

@ -99,11 +99,24 @@
"vcmi.lobby.room.description.limit" : "Up to %d players can enter your room, including you.",
"vcmi.lobby.invite.header" : "Invite Players",
"vcmi.lobby.invite.notification" : "Player has invited you to their game room. You can now join their private room.",
"vcmi.lobby.preview.title" : "Join Game Room",
"vcmi.lobby.preview.subtitle" : "Game on %s, hosted by %s", //TL Note: 1) name of map or RMG template 2) nickname of game host
"vcmi.lobby.preview.version" : "Game version:",
"vcmi.lobby.preview.players" : "Players:",
"vcmi.lobby.preview.mods" : "Used mods:",
"vcmi.lobby.preview.title" : "Join Game Room",
"vcmi.lobby.preview.allowed" : "Join the game room?",
"vcmi.lobby.preview.error.header" : "Unable to join this room.",
"vcmi.lobby.preview.error.playing" : "You need to leave your current game first.",
"vcmi.lobby.preview.error.full" : "The room is already full.",
"vcmi.lobby.preview.error.busy" : "The room no longer accepts new players.",
"vcmi.lobby.preview.error.invite" : "You were not invited to this room",
"vcmi.lobby.preview.error.mods" : "You are using different set of mods",
"vcmi.lobby.preview.error.version" : "You are using different version of VCMI",
"vcmi.lobby.room.new" : "New Game",
"vcmi.lobby.room.load" : "Load Game",
"vcmi.lobby.room.type" : "Room Type",
"vcmi.lobby.room.mode" : "Game Mode",
"vcmi.lobby.room.join" : "Join Game Room",
"vcmi.lobby.room.state.public" : "Public",
"vcmi.lobby.room.state.private" : "Private",
"vcmi.lobby.room.state.busy" : "In Game",

View File

@ -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();
}

View File

@ -65,9 +65,9 @@ class GlobalLobbyRoomWindow : public CWindowObject
std::shared_ptr<FilledTexturePlayerColored> filledBackground;
std::shared_ptr<CLabel> labelTitle;
std::shared_ptr<CLabel> labelSubtitle;
std::shared_ptr<CLabel> labelDescription;
std::shared_ptr<CLabel> labelVersion;
std::shared_ptr<CLabel> labelJoinStatus;
std::shared_ptr<CLabel> labelVersionTitle;
std::shared_ptr<CLabel> labelVersionValue;
std::shared_ptr<CTextBox> labelJoinStatus;
std::shared_ptr<CLabel> accountListTitle;
std::shared_ptr<CLabel> modListTitle;