mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-30 18:43:55 -07:00
Support right-click on game list menu (#5522)
This commit is contained in:
parent
f6c31bf901
commit
37a0c00b3f
2 changed files with 57 additions and 5 deletions
|
|
@ -38,6 +38,9 @@ GameSelector::GameSelector(AbstractClient *_client,
|
||||||
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room), showFilters(_showfilters)
|
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room), showFilters(_showfilters)
|
||||||
{
|
{
|
||||||
gameListView = new QTreeView;
|
gameListView = new QTreeView;
|
||||||
|
gameListView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
connect(gameListView, &QTreeView::customContextMenuRequested, this, &GameSelector::customContextMenu);
|
||||||
|
|
||||||
gameListModel = new GamesModel(_rooms, _gameTypes, this);
|
gameListModel = new GamesModel(_rooms, _gameTypes, this);
|
||||||
if (showFilters) {
|
if (showFilters) {
|
||||||
gameListProxyModel = new GamesProxyModel(this, tabSupervisor->getUserListManager());
|
gameListProxyModel = new GamesProxyModel(this, tabSupervisor->getUserListManager());
|
||||||
|
|
@ -113,7 +116,7 @@ GameSelector::GameSelector(AbstractClient *_client,
|
||||||
setMinimumHeight(200);
|
setMinimumHeight(200);
|
||||||
|
|
||||||
connect(joinButton, &QPushButton::clicked, this, &GameSelector::actJoin);
|
connect(joinButton, &QPushButton::clicked, this, &GameSelector::actJoin);
|
||||||
connect(spectateButton, &QPushButton::clicked, this, &GameSelector::actJoin);
|
connect(spectateButton, &QPushButton::clicked, this, &GameSelector::actSpectate);
|
||||||
connect(gameListView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
connect(gameListView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||||
&GameSelector::actSelectedGameChanged);
|
&GameSelector::actSelectedGameChanged);
|
||||||
connect(gameListView, &QTreeView::activated, this, &GameSelector::actJoin);
|
connect(gameListView, &QTreeView::activated, this, &GameSelector::actJoin);
|
||||||
|
|
@ -241,21 +244,65 @@ void GameSelector::checkResponse(const Response &response)
|
||||||
|
|
||||||
void GameSelector::actJoin()
|
void GameSelector::actJoin()
|
||||||
{
|
{
|
||||||
QModelIndex ind = gameListView->currentIndex();
|
return joinGame(false);
|
||||||
if (!ind.isValid())
|
}
|
||||||
|
|
||||||
|
void GameSelector::actSpectate()
|
||||||
|
{
|
||||||
|
return joinGame(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameSelector::customContextMenu(const QPoint &point)
|
||||||
|
{
|
||||||
|
const auto &index = gameListView->indexAt(point);
|
||||||
|
if (!index.isValid()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction joinGame(tr("Join Game"));
|
||||||
|
connect(&joinGame, &QAction::triggered, this, &GameSelector::actJoin);
|
||||||
|
|
||||||
|
QAction spectateGame(tr("Spectate Game"));
|
||||||
|
connect(&spectateGame, &QAction::triggered, this, &GameSelector::actSpectate);
|
||||||
|
|
||||||
|
QAction getGameInfo(tr("Game Information"));
|
||||||
|
connect(&getGameInfo, &QAction::triggered, this, [=, this]() {
|
||||||
|
const ServerInfo_Game &gameInfo = gameListModel->getGame(index.data(Qt::UserRole).toInt());
|
||||||
|
const QMap<int, QString> &gameTypes = gameListModel->getGameTypes().value(gameInfo.room_id());
|
||||||
|
|
||||||
|
DlgCreateGame dlg(gameInfo, gameTypes, this);
|
||||||
|
dlg.exec();
|
||||||
|
});
|
||||||
|
|
||||||
|
QMenu menu;
|
||||||
|
menu.addAction(&joinGame);
|
||||||
|
menu.addAction(&spectateGame);
|
||||||
|
menu.addAction(&getGameInfo);
|
||||||
|
menu.exec(gameListView->mapToGlobal(point));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameSelector::joinGame(const bool isSpectator)
|
||||||
|
{
|
||||||
|
QModelIndex ind = gameListView->currentIndex();
|
||||||
|
if (!ind.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const ServerInfo_Game &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
|
const ServerInfo_Game &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
|
||||||
if (tabSupervisor->switchToGameTabIfAlreadyExists(game.game_id())) {
|
if (tabSupervisor->switchToGameTabIfAlreadyExists(game.game_id())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool spectator = sender() == spectateButton || game.player_count() == game.max_players();
|
|
||||||
|
bool spectator = isSpectator || game.player_count() == game.max_players();
|
||||||
|
|
||||||
bool overrideRestrictions = !tabSupervisor->getAdminLocked();
|
bool overrideRestrictions = !tabSupervisor->getAdminLocked();
|
||||||
QString password;
|
QString password;
|
||||||
if (game.with_password() && !(spectator && !game.spectators_need_password()) && !overrideRestrictions) {
|
if (game.with_password() && !(spectator && !game.spectators_need_password()) && !overrideRestrictions) {
|
||||||
bool ok;
|
bool ok;
|
||||||
password = getTextWithMax(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
|
password = getTextWithMax(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
|
||||||
if (!ok)
|
if (!ok) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_JoinGame cmd;
|
Command_JoinGame cmd;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,11 @@ private slots:
|
||||||
void actSetFilter();
|
void actSetFilter();
|
||||||
void actClearFilter();
|
void actClearFilter();
|
||||||
void actCreate();
|
void actCreate();
|
||||||
|
|
||||||
void actJoin();
|
void actJoin();
|
||||||
|
void actSpectate();
|
||||||
|
void customContextMenu(const QPoint &point);
|
||||||
|
|
||||||
void actSelectedGameChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
void actSelectedGameChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void checkResponse(const Response &response);
|
void checkResponse(const Response &response);
|
||||||
|
|
||||||
|
|
@ -53,6 +57,7 @@ private:
|
||||||
void disableButtons();
|
void disableButtons();
|
||||||
void enableButtons();
|
void enableButtons();
|
||||||
void enableButtonsForIndex(const QModelIndex ¤t);
|
void enableButtonsForIndex(const QModelIndex ¤t);
|
||||||
|
void joinGame(const bool isSpectator);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameSelector(AbstractClient *_client,
|
GameSelector(AbstractClient *_client,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue