mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Show active room invites and invited players in UI
This commit is contained in:
parent
a4ea74fbbc
commit
7188849aa4
@ -262,6 +262,7 @@ void GlobalLobbyClient::receiveMatchesHistory(const JsonNode & json)
|
||||
account.displayName = jsonParticipant["displayName"].String();
|
||||
room.participants.push_back(account);
|
||||
}
|
||||
|
||||
room.playerLimit = jsonEntry["playerLimit"].Integer();
|
||||
|
||||
matchesHistory.push_back(room);
|
||||
@ -569,6 +570,11 @@ void GlobalLobbyClient::resetMatchState()
|
||||
currentGameRoomUUID.clear();
|
||||
}
|
||||
|
||||
const std::string & GlobalLobbyClient::getCurrentGameRoomID() const
|
||||
{
|
||||
return currentGameRoomUUID;
|
||||
}
|
||||
|
||||
void GlobalLobbyClient::sendMatchChatMessage(const std::string & messageText)
|
||||
{
|
||||
if (!isLoggedIn())
|
||||
@ -590,5 +596,15 @@ void GlobalLobbyClient::sendMatchChatMessage(const std::string & messageText)
|
||||
|
||||
bool GlobalLobbyClient::isInvitedToRoom(const std::string & gameRoomID)
|
||||
{
|
||||
return activeInvites.count(gameRoomID) > 0;
|
||||
if (activeInvites.count(gameRoomID) > 0)
|
||||
return true;
|
||||
|
||||
const auto & gameRoom = CSH->getGlobalLobby().getActiveRoomByName(gameRoomID);
|
||||
for (auto const & invited : gameRoom.invited)
|
||||
{
|
||||
if (invited.accountID == getAccountID())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
/// Returns active room by ID. Throws out-of-range on failure
|
||||
const GlobalLobbyRoom & getActiveRoomByName(const std::string & roomUUID) const;
|
||||
|
||||
const std::string & getCurrentGameRoomID() const;
|
||||
const std::string & getAccountID() const;
|
||||
const std::string & getAccountCookie() const;
|
||||
const std::string & getAccountDisplayName() const;
|
||||
|
@ -31,10 +31,33 @@ GlobalLobbyInviteAccountCard::GlobalLobbyInviteAccountCard(const GlobalLobbyAcco
|
||||
pos.h = 40;
|
||||
addUsedEvents(LCLICK);
|
||||
|
||||
bool thisAccountInvited = false;
|
||||
const auto & myRoomID = CSH->getGlobalLobby().getCurrentGameRoomID();
|
||||
if (!myRoomID.empty())
|
||||
{
|
||||
const auto & myRoom = CSH->getGlobalLobby().getActiveRoomByName(myRoomID);
|
||||
for (auto const & invited : myRoom.invited)
|
||||
{
|
||||
if (invited.accountID == accountID)
|
||||
{
|
||||
thisAccountInvited = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1);
|
||||
if (thisAccountInvited)
|
||||
backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), Colors::WHITE, 1);
|
||||
else
|
||||
backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1);
|
||||
|
||||
labelName = std::make_shared<CLabel>(5, 10, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, accountDescription.displayName);
|
||||
labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, accountDescription.status);
|
||||
|
||||
if (thisAccountInvited)
|
||||
labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.room.state.invited").toString());
|
||||
else
|
||||
labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, accountDescription.status);
|
||||
}
|
||||
|
||||
void GlobalLobbyInviteAccountCard::clickPressed(const Point & cursorPosition)
|
||||
|
@ -231,7 +231,7 @@ GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const Globa
|
||||
pos.w = 230;
|
||||
pos.h = 40;
|
||||
|
||||
if (window->isInviteUnread(roomDescription.gameRoomID))
|
||||
if (hasInvite)
|
||||
backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), Colors::WHITE, 1);
|
||||
else
|
||||
backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1);
|
||||
|
@ -106,8 +106,6 @@ void GlobalLobbyWindow::doInviteAccount(const std::string & accountID)
|
||||
|
||||
void GlobalLobbyWindow::doJoinRoom(const std::string & roomID)
|
||||
{
|
||||
unreadInvites.erase(roomID);
|
||||
|
||||
JsonNode toSend;
|
||||
toSend["type"].String() = "joinGameRoom";
|
||||
toSend["gameRoomID"].String() = roomID;
|
||||
@ -185,15 +183,9 @@ void GlobalLobbyWindow::onMatchesHistory(const std::vector<GlobalLobbyRoom> & hi
|
||||
|
||||
void GlobalLobbyWindow::onInviteReceived(const std::string & invitedRoomID)
|
||||
{
|
||||
unreadInvites.insert(invitedRoomID);
|
||||
widget->getRoomList()->reset();
|
||||
}
|
||||
|
||||
bool GlobalLobbyWindow::isInviteUnread(const std::string & gameRoomID) const
|
||||
{
|
||||
return unreadInvites.count(gameRoomID) > 0;
|
||||
}
|
||||
|
||||
void GlobalLobbyWindow::onJoinedRoom()
|
||||
{
|
||||
widget->getAccountList()->reset();
|
||||
|
@ -23,7 +23,6 @@ class GlobalLobbyWindow : public CWindowObject
|
||||
|
||||
std::shared_ptr<GlobalLobbyWidget> widget;
|
||||
std::set<std::string> unreadChannels;
|
||||
std::set<std::string> unreadInvites;
|
||||
|
||||
public:
|
||||
GlobalLobbyWindow();
|
||||
@ -39,7 +38,6 @@ public:
|
||||
/// Returns true if provided chat channel is the one that is currently open in UI
|
||||
bool isChannelOpen(const std::string & channelType, const std::string & channelName) const;
|
||||
bool isChannelUnread(const std::string & channelType, const std::string & channelName) const;
|
||||
bool isInviteUnread(const std::string & gameRoomID) const;
|
||||
|
||||
// Callbacks for network packs
|
||||
|
||||
|
@ -819,6 +819,7 @@ void LobbyServer::receiveSendInvite(const NetworkConnectionPtr & connection, con
|
||||
|
||||
database->insertGameRoomInvite(accountID, gameRoomID);
|
||||
sendInviteReceived(targetAccountConnection, senderName, gameRoomID);
|
||||
broadcastActiveGameRooms();
|
||||
}
|
||||
|
||||
LobbyServer::~LobbyServer() = default;
|
||||
|
Loading…
Reference in New Issue
Block a user