mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
Indicate rooms with active invites, fix invite acceptance
This commit is contained in:
@ -285,13 +285,15 @@ void GlobalLobbyClient::receiveInviteReceived(const JsonNode & json)
|
|||||||
auto lobbyWindowPtr = lobbyWindow.lock();
|
auto lobbyWindowPtr = lobbyWindow.lock();
|
||||||
std::string gameRoomID = json["gameRoomID"].String();
|
std::string gameRoomID = json["gameRoomID"].String();
|
||||||
std::string accountID = json["accountID"].String();
|
std::string accountID = json["accountID"].String();
|
||||||
|
|
||||||
|
activeInvites.insert(gameRoomID);
|
||||||
if(lobbyWindowPtr)
|
if(lobbyWindowPtr)
|
||||||
{
|
{
|
||||||
std::string message = MetaString::createFromTextID("vcmi.lobby.invite.notification").toString();
|
std::string message = MetaString::createFromTextID("vcmi.lobby.invite.notification").toString();
|
||||||
std::string time = getCurrentTimeFormatted();
|
std::string time = getCurrentTimeFormatted();
|
||||||
|
|
||||||
lobbyWindowPtr->onGameChatMessage("System", message, time, "player", accountID);
|
lobbyWindowPtr->onGameChatMessage("System", message, time, "player", accountID);
|
||||||
lobbyWindowPtr->onInviteReceived(gameRoomID, accountID);
|
lobbyWindowPtr->onInviteReceived(gameRoomID);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCS->soundh->playSound(AudioPath::builtin("CHAT"));
|
CCS->soundh->playSound(AudioPath::builtin("CHAT"));
|
||||||
@ -299,8 +301,6 @@ void GlobalLobbyClient::receiveInviteReceived(const JsonNode & json)
|
|||||||
|
|
||||||
void GlobalLobbyClient::receiveJoinRoomSuccess(const JsonNode & json)
|
void GlobalLobbyClient::receiveJoinRoomSuccess(const JsonNode & json)
|
||||||
{
|
{
|
||||||
currentGameRoomUUID = json["gameRoomID"].String();
|
|
||||||
|
|
||||||
if (json["proxyMode"].Bool())
|
if (json["proxyMode"].Bool())
|
||||||
{
|
{
|
||||||
CSH->resetStateForLobby(EStartMode::NEW_GAME, ESelectionScreen::newGame, EServerMode::LOBBY_GUEST, {});
|
CSH->resetStateForLobby(EStartMode::NEW_GAME, ESelectionScreen::newGame, EServerMode::LOBBY_GUEST, {});
|
||||||
@ -310,6 +310,9 @@ void GlobalLobbyClient::receiveJoinRoomSuccess(const JsonNode & json)
|
|||||||
int16_t port = settings["lobby"]["port"].Integer();
|
int16_t port = settings["lobby"]["port"].Integer();
|
||||||
CSH->connectToServer(hostname, port);
|
CSH->connectToServer(hostname, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: must be set after CSH->resetStateForLobby call
|
||||||
|
currentGameRoomUUID = json["gameRoomID"].String();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalLobbyClient::onConnectionEstablished(const std::shared_ptr<INetworkConnection> & connection)
|
void GlobalLobbyClient::onConnectionEstablished(const std::shared_ptr<INetworkConnection> & connection)
|
||||||
@ -500,7 +503,7 @@ void GlobalLobbyClient::sendProxyConnectionLogin(const NetworkConnectionPtr & ne
|
|||||||
toSend["type"].String() = "clientProxyLogin";
|
toSend["type"].String() = "clientProxyLogin";
|
||||||
toSend["accountID"] = settings["lobby"]["accountID"];
|
toSend["accountID"] = settings["lobby"]["accountID"];
|
||||||
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
||||||
toSend["gameRoomID"] = settings["session"]["lobby"]["roomID"];
|
toSend["gameRoomID"].String() = currentGameRoomUUID;
|
||||||
|
|
||||||
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), toSend["type"].String() + " pack"));
|
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), toSend["type"].String() + " pack"));
|
||||||
netConnection->sendPacket(toSend.toBytes());
|
netConnection->sendPacket(toSend.toBytes());
|
||||||
@ -527,3 +530,8 @@ void GlobalLobbyClient::sendMatchChatMessage(const std::string & messageText)
|
|||||||
|
|
||||||
CSH->getGlobalLobby().sendMessage(toSend);
|
CSH->getGlobalLobby().sendMessage(toSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GlobalLobbyClient::isInvitedToRoom(const std::string & gameRoomID)
|
||||||
|
{
|
||||||
|
return activeInvites.count(gameRoomID) > 0;
|
||||||
|
}
|
||||||
|
@ -24,6 +24,7 @@ class GlobalLobbyClient final : public INetworkClientListener, boost::noncopyabl
|
|||||||
std::vector<GlobalLobbyAccount> activeAccounts;
|
std::vector<GlobalLobbyAccount> activeAccounts;
|
||||||
std::vector<GlobalLobbyRoom> activeRooms;
|
std::vector<GlobalLobbyRoom> activeRooms;
|
||||||
std::vector<std::string> activeChannels;
|
std::vector<std::string> activeChannels;
|
||||||
|
std::set<std::string> activeInvites;
|
||||||
std::vector<GlobalLobbyRoom> matchesHistory;
|
std::vector<GlobalLobbyRoom> matchesHistory;
|
||||||
|
|
||||||
/// Contains known history of each channel
|
/// Contains known history of each channel
|
||||||
@ -82,4 +83,5 @@ public:
|
|||||||
|
|
||||||
void connect();
|
void connect();
|
||||||
bool isConnected() const;
|
bool isConnected() const;
|
||||||
|
bool isInvitedToRoom(const std::string & gameRoomID);
|
||||||
};
|
};
|
||||||
|
@ -217,23 +217,35 @@ GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const Globa
|
|||||||
window->doJoinRoom(roomID);
|
window->doJoinRoom(roomID);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool publicRoom = roomDescription.statusID == "public";
|
||||||
|
bool hasInvite = CSH->getGlobalLobby().isInvitedToRoom(roomDescription.gameRoomID);
|
||||||
|
bool canJoin = publicRoom || hasInvite;
|
||||||
|
|
||||||
auto roomSizeText = MetaString::createFromRawString("%d/%d");
|
auto roomSizeText = MetaString::createFromRawString("%d/%d");
|
||||||
roomSizeText.replaceNumber(roomDescription.participants.size());
|
roomSizeText.replaceNumber(roomDescription.participants.size());
|
||||||
roomSizeText.replaceNumber(roomDescription.playerLimit);
|
roomSizeText.replaceNumber(roomDescription.playerLimit);
|
||||||
|
|
||||||
auto roomStatusText = MetaString::createFromTextID("vcmi.lobby.room.state." + roomDescription.statusID);
|
MetaString roomStatusText;
|
||||||
|
if (roomDescription.statusID == "private" && hasInvite)
|
||||||
|
roomStatusText.appendTextID("vcmi.lobby.room.state.invited");
|
||||||
|
else
|
||||||
|
roomStatusText.appendTextID("vcmi.lobby.room.state." + roomDescription.statusID);
|
||||||
|
|
||||||
pos.w = 230;
|
pos.w = 230;
|
||||||
pos.h = 40;
|
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));
|
if (window->isInviteUnread(roomDescription.gameRoomID))
|
||||||
|
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, roomDescription.hostAccountDisplayName);
|
labelName = std::make_shared<CLabel>(5, 10, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, roomDescription.hostAccountDisplayName);
|
||||||
labelDescription = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, roomDescription.description);
|
labelDescription = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, roomDescription.description);
|
||||||
labelRoomSize = std::make_shared<CLabel>(178, 10, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::YELLOW, roomSizeText.toString());
|
labelRoomSize = std::make_shared<CLabel>(178, 10, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::YELLOW, roomSizeText.toString());
|
||||||
labelRoomStatus = std::make_shared<CLabel>(190, 30, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::YELLOW, roomStatusText.toString());
|
labelRoomStatus = std::make_shared<CLabel>(190, 30, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::YELLOW, roomStatusText.toString());
|
||||||
iconRoomSize = std::make_shared<CPicture>(ImagePath::builtin("lobby/iconPlayer"), Point(180, 5));
|
iconRoomSize = std::make_shared<CPicture>(ImagePath::builtin("lobby/iconPlayer"), Point(180, 5));
|
||||||
|
|
||||||
if(!CSH->inGame() && roomDescription.statusID == "public")
|
if(!CSH->inGame() && canJoin)
|
||||||
{
|
{
|
||||||
buttonJoin = std::make_shared<CButton>(Point(194, 4), AnimationPath::builtin("lobbyJoinRoom"), CButton::tooltip(), onJoinClicked);
|
buttonJoin = std::make_shared<CButton>(Point(194, 4), AnimationPath::builtin("lobbyJoinRoom"), CButton::tooltip(), onJoinClicked);
|
||||||
buttonJoin->setOverlay(std::make_shared<CPicture>(ImagePath::builtin("lobby/iconEnter")));
|
buttonJoin->setOverlay(std::make_shared<CPicture>(ImagePath::builtin("lobby/iconEnter")));
|
||||||
|
@ -101,6 +101,8 @@ void GlobalLobbyWindow::doInviteAccount(const std::string & accountID)
|
|||||||
|
|
||||||
void GlobalLobbyWindow::doJoinRoom(const std::string & roomID)
|
void GlobalLobbyWindow::doJoinRoom(const std::string & roomID)
|
||||||
{
|
{
|
||||||
|
unreadInvites.erase(roomID);
|
||||||
|
|
||||||
JsonNode toSend;
|
JsonNode toSend;
|
||||||
toSend["type"].String() = "joinGameRoom";
|
toSend["type"].String() = "joinGameRoom";
|
||||||
toSend["gameRoomID"].String() = roomID;
|
toSend["gameRoomID"].String() = roomID;
|
||||||
@ -172,11 +174,17 @@ void GlobalLobbyWindow::onMatchesHistory(const std::vector<GlobalLobbyRoom> & hi
|
|||||||
widget->getMatchListHeader()->setText(text.toString());
|
widget->getMatchListHeader()->setText(text.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalLobbyWindow::onInviteReceived(const std::string & invitedRoomID, const std::string & invitedByAccountID)
|
void GlobalLobbyWindow::onInviteReceived(const std::string & invitedRoomID)
|
||||||
{
|
{
|
||||||
|
unreadInvites.insert(invitedRoomID);
|
||||||
widget->getRoomList()->reset();
|
widget->getRoomList()->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GlobalLobbyWindow::isInviteUnread(const std::string & gameRoomID)
|
||||||
|
{
|
||||||
|
return unreadInvites.count(gameRoomID) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
void GlobalLobbyWindow::onJoinedRoom()
|
void GlobalLobbyWindow::onJoinedRoom()
|
||||||
{
|
{
|
||||||
widget->getAccountList()->reset();
|
widget->getAccountList()->reset();
|
||||||
|
@ -23,6 +23,7 @@ class GlobalLobbyWindow : public CWindowObject
|
|||||||
|
|
||||||
std::shared_ptr<GlobalLobbyWidget> widget;
|
std::shared_ptr<GlobalLobbyWidget> widget;
|
||||||
std::set<std::string> unreadChannels;
|
std::set<std::string> unreadChannels;
|
||||||
|
std::set<std::string> unreadInvites;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GlobalLobbyWindow();
|
GlobalLobbyWindow();
|
||||||
@ -38,6 +39,7 @@ public:
|
|||||||
/// Returns true if provided chat channel is the one that is currently open in UI
|
/// 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);
|
bool isChannelOpen(const std::string & channelType, const std::string & channelName);
|
||||||
bool isChannelUnread(const std::string & channelType, const std::string & channelName);
|
bool isChannelUnread(const std::string & channelType, const std::string & channelName);
|
||||||
|
bool isInviteUnread(const std::string & gameRoomID);
|
||||||
|
|
||||||
// Callbacks for network packs
|
// Callbacks for network packs
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ public:
|
|||||||
void onActiveAccounts(const std::vector<GlobalLobbyAccount> & accounts);
|
void onActiveAccounts(const std::vector<GlobalLobbyAccount> & accounts);
|
||||||
void onActiveRooms(const std::vector<GlobalLobbyRoom> & rooms);
|
void onActiveRooms(const std::vector<GlobalLobbyRoom> & rooms);
|
||||||
void onMatchesHistory(const std::vector<GlobalLobbyRoom> & history);
|
void onMatchesHistory(const std::vector<GlobalLobbyRoom> & history);
|
||||||
void onInviteReceived(const std::string & invitedRoomID, const std::string & invitedByAccountID);
|
void onInviteReceived(const std::string & invitedRoomID);
|
||||||
void onJoinedRoom();
|
void onJoinedRoom();
|
||||||
void onLeftRoom();
|
void onLeftRoom();
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
"type" :
|
"type" :
|
||||||
{
|
{
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"const" : "clientLogin"
|
"const" : "clientProxyLogin"
|
||||||
},
|
},
|
||||||
"accountID" :
|
"accountID" :
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user