Selecting game already open in a tab brings user to that tab. (#4653)

* When trying to join a game from GameSelector that's already been joined by you, navigate to its game tab.

* return immediately, do not change button states

Co-authored-by: ebbit1q <ebbit1q@gmail.com>
This commit is contained in:
Antoine Dahan 2022-10-29 09:46:50 -04:00 committed by GitHub
parent 8e4ddf366c
commit 72743e834e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 29 additions and 11 deletions

View file

@ -21,7 +21,7 @@ UserMessagePosition::UserMessagePosition(QTextCursor &cursor)
relativePosition = cursor.position() - block.position();
}
ChatView::ChatView(const TabSupervisor *_tabSupervisor,
ChatView::ChatView(TabSupervisor *_tabSupervisor,
const UserlistProxy *_userlistProxy,
TabGame *_game,
bool _showTimestamps,

View file

@ -33,7 +33,7 @@ class ChatView : public QTextBrowser
{
Q_OBJECT
protected:
const TabSupervisor *const tabSupervisor;
TabSupervisor *const tabSupervisor;
TabGame *const game;
private:
@ -83,7 +83,7 @@ private slots:
void actMessageClicked();
public:
ChatView(const TabSupervisor *_tabSupervisor,
ChatView(TabSupervisor *_tabSupervisor,
const UserlistProxy *_userlistProxy,
TabGame *_game,
bool _showTimestamps,

View file

@ -10,6 +10,7 @@
#include "pb/serverinfo_game.pb.h"
#include "pending_command.h"
#include "tab_account.h"
#include "tab_game.h"
#include "tab_room.h"
#include "tab_supervisor.h"
@ -26,7 +27,7 @@
#include <QVBoxLayout>
GameSelector::GameSelector(AbstractClient *_client,
const TabSupervisor *_tabSupervisor,
TabSupervisor *_tabSupervisor,
TabRoom *_room,
const QMap<int, QString> &_rooms,
const QMap<int, GameTypeMap> &_gameTypes,
@ -239,6 +240,9 @@ void GameSelector::actJoin()
if (!ind.isValid())
return;
const ServerInfo_Game &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
if (tabSupervisor->switchToGameTabIfAlreadyExists(game.game_id())) {
return;
}
bool spectator = sender() == spectateButton || game.player_count() == game.max_players();
bool overrideRestrictions = !tabSupervisor->getAdminLocked();
QString password;

View file

@ -38,7 +38,7 @@ signals:
private:
AbstractClient *client;
const TabSupervisor *tabSupervisor;
TabSupervisor *tabSupervisor;
TabRoom *room;
QTreeView *gameListView;
@ -52,7 +52,7 @@ private:
public:
GameSelector(AbstractClient *_client,
const TabSupervisor *_tabSupervisor,
TabSupervisor *_tabSupervisor,
TabRoom *_room,
const QMap<int, QString> &_rooms,
const QMap<int, GameTypeMap> &_gameTypes,

View file

@ -831,7 +831,7 @@ void MessageLogWidget::connectToPlayer(Player *player)
SLOT(logAlwaysLookAtTopCard(Player *, CardZone *, bool)));
}
MessageLogWidget::MessageLogWidget(const TabSupervisor *_tabSupervisor,
MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor,
const UserlistProxy *_userlistProxy,
TabGame *_game,
QWidget *parent)

View file

@ -102,7 +102,7 @@ public slots:
public:
void connectToPlayer(Player *player);
MessageLogWidget(const TabSupervisor *_tabSupervisor,
MessageLogWidget(TabSupervisor *_tabSupervisor,
const UserlistProxy *_userlistProxy,
TabGame *_game,
QWidget *parent = nullptr);

View file

@ -735,3 +735,16 @@ const ServerInfo_User *TabSupervisor::getOnlineUser(const QString &userName) con
return nullptr;
};
bool TabSupervisor::switchToGameTabIfAlreadyExists(const int gameId)
{
bool isGameTabExists = false;
if (gameTabs.contains(gameId)) {
isGameTabExists = true;
TabGame *tabGame = gameTabs[gameId];
const int gameTabIndex = indexOf(tabGame);
setCurrentIndex(gameTabIndex);
}
return isGameTabExists;
}

View file

@ -120,6 +120,7 @@ public:
bool isUserBuddy(const QString &userName) const;
bool isUserIgnored(const QString &userName) const;
const ServerInfo_User *getOnlineUser(const QString &userName) const;
bool switchToGameTabIfAlreadyExists(const int gameId);
void actShowPopup(const QString &message);
signals:
void setMenu(const QList<QMenu *> &newMenuList = QList<QMenu *>());

View file

@ -26,7 +26,7 @@
#include <QtGui>
#include <QtWidgets>
UserContextMenu::UserContextMenu(const TabSupervisor *_tabSupervisor, QWidget *parent, TabGame *_game)
UserContextMenu::UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *parent, TabGame *_game)
: QObject(parent), client(_tabSupervisor->getClient()), tabSupervisor(_tabSupervisor), game(_game)
{
aUserName = new QAction(QString(), this);

View file

@ -21,7 +21,7 @@ class UserContextMenu : public QObject
Q_OBJECT
private:
AbstractClient *client;
const TabSupervisor *tabSupervisor;
TabSupervisor *tabSupervisor;
TabGame *game;
QAction *aUserName;
@ -49,7 +49,7 @@ private slots:
void gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer);
public:
UserContextMenu(const TabSupervisor *_tabSupervisor, QWidget *_parent, TabGame *_game = 0);
UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *_parent, TabGame *_game = 0);
void retranslateUi();
void showContextMenu(const QPoint &pos,
const QString &userName,