Files
pokerth/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp
T

1600 lines
60 KiB
C++
Raw Normal View History

2007-08-20 21:23:03 +00:00
//
// C++ Implementation: gamelobbydialogimpl
//
// Description:
//
//
// Author: FThauer FHammer LMay <webmaster@pokerth.net>, (C) 2007
2007-08-20 21:23:03 +00:00
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "gamelobbydialogimpl.h"
2009-06-14 22:56:49 +00:00
#include "mygamelistsortfilterproxymodel.h"
#include "mynicklistsortfilterproxymodel.h"
#include "startwindowimpl.h"
2009-08-17 23:20:58 +00:00
#include "chattools.h"
#include "changecompleteblindsdialogimpl.h"
#include "session.h"
#include "configfile.h"
#include "gamedata.h"
2010-03-29 13:08:59 +00:00
#include "game_defs.h"
#include <net/socket_msg.h>
#include "mymessagedialogimpl.h"
2007-08-20 21:23:03 +00:00
using namespace std;
gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
: QDialog(parent), myW(NULL), myStartWindow(parent), myConfig(c), currentGameName(""), myPlayerId(0), isGameAdministrator(false), inGame(false), guestMode(false), blinkingButtonAnimationState(true), myChat(NULL), keyUpCounter(0), infoMsgToShowId(0), currentInvitationGameId(0), inviteDialogIsCurrentlyShown(false), autoStartTimerCounter(0)
2007-08-20 21:23:03 +00:00
{
2007-11-28 22:00:42 +00:00
2007-12-04 01:37:43 +00:00
#ifdef __APPLE__
2010-03-30 12:25:30 +00:00
setWindowModality(Qt::ApplicationModal);
setWindowFlags(Qt::WindowSystemMenuHint | Qt::CustomizeWindowHint | Qt::Dialog);
2007-12-04 01:37:43 +00:00
#endif
2010-03-30 12:25:30 +00:00
setupUi(this);
2007-09-07 20:26:13 +00:00
2010-03-30 12:25:30 +00:00
myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str());
2007-10-16 23:07:59 +00:00
2010-03-30 12:25:30 +00:00
//wait start game message
waitStartGameMsgBox = new QMessageBox(this);
waitStartGameMsgBox->setText(tr("Starting game. Please wait ..."));
waitStartGameMsgBox->setWindowModality(Qt::NonModal);
#ifdef __APPLE__
waitStartGameMsgBox->setWindowFlags(Qt::WindowSystemMenuHint | Qt::CustomizeWindowHint | Qt::Dialog);
#endif
waitStartGameMsgBox->setStandardButtons(QMessageBox::NoButton);
2010-03-30 12:25:30 +00:00
waitStartGameMsgBoxTimer = new QTimer(this);
waitStartGameMsgBoxTimer->setSingleShot(TRUE);
blinkingButtonAnimationTimer = new QTimer(this);
blinkingButtonAnimationTimer->setInterval(1000);
autoStartTimer = new QTimer(this);
autoStartTimer->setInterval(1000);
2010-03-30 12:25:30 +00:00
showInfoMsgBoxTimer = new QTimer(this);
showInfoMsgBoxTimer->setSingleShot(TRUE);
2010-03-27 21:55:34 +00:00
2010-03-30 12:25:30 +00:00
//fetch button colors for blinking
groupBox_GameInfo->setEnabled(true);
pushButton_StartGame->setEnabled(true);
defaultStartButtonColor = pushButton_StartGame->palette().button().color();
defaultStartButtonTextColor = pushButton_StartGame->palette().buttonText().color();
pushButton_StartGame->setEnabled(false);
groupBox_GameInfo->setEnabled(false);
disabledStartButtonColor = pushButton_StartGame->palette().button().color();
disabledStartButtonTextColor = pushButton_StartGame->palette().buttonText().color();
//prepare overlay
autoStartTimerOverlay = new QLabel(scrollArea_gameInfos);
autoStartTimerOverlay->hide();
autoStartTimerOverlay->setWordWrap(TRUE);
2010-09-05 12:26:36 +00:00
autoStartTimerOverlay->setMaximumWidth(190);
autoStartTimerOverlay->setMinimumWidth(190);
autoStartTimerOverlay->setTextFormat(Qt::RichText);
autoStartTimerOverlay->setAlignment(Qt::AlignCenter);
autoStartTimerOverlay->setAutoFillBackground(TRUE);
autoStartTimerOverlay->setFrameStyle(QFrame::StyledPanel);
QPalette p;
p.setColor(QPalette::Background, QColor(255, 255, 255, 210));
autoStartTimerOverlay->setPalette(p);
2010-03-30 12:25:30 +00:00
myGameListModel = new QStandardItemModel(this);
myGameListSortFilterProxyModel = new MyGameListSortFilterProxyModel(this);
myGameListSortFilterProxyModel->setSourceModel(myGameListModel);
myGameListSortFilterProxyModel->setDynamicSortFilter(TRUE);
treeView_GameList->setModel(myGameListSortFilterProxyModel);
2010-03-27 21:55:34 +00:00
2010-03-30 12:25:30 +00:00
myGameListSelectionModel = treeView_GameList->selectionModel();
2007-10-10 10:06:09 +00:00
2010-03-30 12:25:30 +00:00
QStringList headerList;
headerList << tr("Game") << tr("Players") << tr("State") << tr("R") << tr("P");
myGameListModel->setHorizontalHeaderLabels(headerList);
treeView_GameList->setColumnWidth(0,190);
2010-03-30 12:25:30 +00:00
treeView_GameList->setColumnWidth(1,65);
treeView_GameList->setColumnWidth(2,65);
treeView_GameList->setColumnWidth(3,40);
treeView_GameList->setColumnWidth(4,40);
2010-03-30 12:25:30 +00:00
treeView_GameList->setStyleSheet("QTreeView {background-color: white; background-image: url(\""+myAppDataPath +"gfx/gui/misc/background_gamelist.png\"); background-attachment: fixed; background-position: top center ; background-repeat: no-repeat;}");
treeView_GameList->setAutoFillBackground(TRUE);
myNickListModel = new QStandardItemModel(this);
myNickListSortFilterProxyModel = new MyNickListSortFilterProxyModel(this);
myNickListSortFilterProxyModel->setSourceModel(myNickListModel);
myNickListSortFilterProxyModel->setDynamicSortFilter(TRUE);
myNickListSortFilterProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
treeView_NickList->setModel(myNickListSortFilterProxyModel);
myNickListSelectionModel = treeView_NickList->selectionModel();
QStringList headerList2;
headerList2 << tr("Available Players");
myNickListModel->setHorizontalHeaderLabels(headerList2);
treeView_NickList->sortByColumn(0, Qt::AscendingOrder);
myChat = new ChatTools(lineEdit_ChatInput, myConfig, INET_LOBBY_CHAT, textBrowser_ChatDisplay, myNickListModel, this);
2010-03-30 12:25:30 +00:00
nickListContextMenu = new QMenu();
nickListInviteAction = new QAction(QIcon(":/gfx/list_add_user.png"), tr("Invite player"), nickListContextMenu);
nickListContextMenu->addAction(nickListInviteAction);
nickListIgnorePlayerAction = new QAction(QIcon(":/gfx/im-ban-user.png"), tr("Ignore player"), nickListContextMenu);
nickListContextMenu->addAction(nickListIgnorePlayerAction);
nickListPlayerInfoSubMenu = nickListContextMenu->addMenu(QIcon(":/gfx/dialog-information.png"), tr("Player infos ..."));
nickListPlayerInGameInfo = new QAction(nickListContextMenu);
nickListPlayerInfoSubMenu->addAction(nickListPlayerInGameInfo);
2010-03-30 12:25:30 +00:00
connect( pushButton_CreateGame, SIGNAL( clicked() ), this, SLOT( createGame() ) );
connect( pushButton_JoinGame, SIGNAL( clicked() ), this, SLOT( joinGame() ) );
connect( pushButton_joinAnyGame, SIGNAL( clicked() ), this, SLOT( joinAnyGame() ) );
connect( pushButton_StartGame, SIGNAL( clicked() ), this, SLOT( startGame() ) );
connect( pushButton_Kick, SIGNAL( clicked() ), this, SLOT( kickPlayer() ) );
connect( pushButton_Leave, SIGNAL( clicked() ), this, SLOT( leaveGame() ) );
connect( myGameListSelectionModel, SIGNAL( currentChanged (const QModelIndex &, const QModelIndex &) ), this, SLOT( gameSelected(const QModelIndex &) ) );
2010-03-30 12:25:30 +00:00
connect( treeView_GameList, SIGNAL( doubleClicked (const QModelIndex &) ), this, SLOT( joinGame() ) );
connect( treeView_GameList->header(), SIGNAL( sortIndicatorChanged ( int , Qt::SortOrder )), this, SLOT( changeGameListSorting() ) );
connect( treeWidget_connectedPlayers, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*) ), this, SLOT( playerSelected(QTreeWidgetItem*, QTreeWidgetItem*) ) );
connect( lineEdit_ChatInput, SIGNAL( returnPressed () ), myChat, SLOT( sendMessage() ) );
connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), myChat, SLOT( checkInputLength(QString) ) );
connect( lineEdit_ChatInput, SIGNAL( textEdited (QString) ), myChat, SLOT( setChatTextEdited() ) );
connect( waitStartGameMsgBoxTimer, SIGNAL(timeout()), this, SLOT( showWaitStartGameMsgBox() ));
connect( blinkingButtonAnimationTimer, SIGNAL(timeout()), this, SLOT( blinkingStartButtonAnimation() ));
connect( autoStartTimer, SIGNAL(timeout()), this, SLOT( updateAutoStartTimer() ));
2010-03-30 12:25:30 +00:00
connect( showInfoMsgBoxTimer, SIGNAL(timeout()), this, SLOT( showInfoMsgBox() ));
connect( comboBox_gameListFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changeGameListFilter(int)));
connect( comboBox_nickListFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changeNickListFilter(int)));
connect( treeView_NickList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT( showNickListContextMenu(QPoint) ) );
2010-03-30 12:25:30 +00:00
connect( nickListInviteAction, SIGNAL(triggered()), this, SLOT( invitePlayerToCurrentGame() ));
connect( nickListIgnorePlayerAction, SIGNAL(triggered()), this, SLOT( putPlayerOnIgnoreList() ));
connect( lineEdit_searchForPlayers, SIGNAL(textChanged(QString)),this, SLOT(searchForPlayerRegExpChanged()));
2010-03-30 12:25:30 +00:00
lineEdit_searchForPlayers->installEventFilter(this);
2010-03-30 12:25:30 +00:00
lineEdit_ChatInput->installEventFilter(this);
clearDialog();
2007-08-20 21:23:03 +00:00
}
void gameLobbyDialogImpl::exec()
{
2010-03-30 12:25:30 +00:00
if(myConfig->readConfigInt("UseLobbyChat")) {
groupBox_lobbyChat->show();
}
else {
groupBox_lobbyChat->hide();
}
readDialogSettings();
PlayerInfo playerInfo(mySession->getClientPlayerInfo(mySession->getClientUniquePlayerId()));
if(playerInfo.isGuest) {
guestUserMode();
}
else {
registeredUserMode();
}
2010-03-24 21:17:03 +00:00
2010-03-30 12:25:30 +00:00
QDialog::exec();
2010-03-30 12:25:30 +00:00
waitStartGameMsgBoxTimer->stop();
waitStartGameMsgBox->hide();
2007-08-20 21:23:03 +00:00
}
gameLobbyDialogImpl::~gameLobbyDialogImpl()
{
2010-03-30 12:25:30 +00:00
delete myChat;
myChat = NULL;
2007-09-07 20:26:13 +00:00
2007-08-20 21:23:03 +00:00
}
2009-08-18 00:46:18 +00:00
void gameLobbyDialogImpl::setSession(boost::shared_ptr<Session> session) {
2010-03-30 12:25:30 +00:00
mySession = session;
myChat->setSession(mySession);
2009-08-18 00:46:18 +00:00
}
void gameLobbyDialogImpl::createGame()
{
2010-03-30 12:25:30 +00:00
assert(mySession);
2010-03-30 12:25:30 +00:00
myCreateInternetGameDialog = new createInternetGameDialogImpl(this, myConfig);
PlayerInfo playerInfo(mySession->getClientPlayerInfo(mySession->getClientUniquePlayerId()));
myCreateInternetGameDialog->exec(guestMode, QString::fromUtf8(playerInfo.playerName.c_str()));
2010-03-30 12:25:30 +00:00
if (myCreateInternetGameDialog->result() == QDialog::Accepted ) {
2007-09-28 05:23:13 +00:00
2010-03-30 12:25:30 +00:00
GameData gameData;
// Set Game Data
gameData.maxNumberOfPlayers = myCreateInternetGameDialog->spinBox_quantityPlayers->value();
gameData.startMoney = myCreateInternetGameDialog->spinBox_startCash->value();
gameData.firstSmallBlind = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value();
2010-03-30 12:25:30 +00:00
if(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->radioButton_raiseBlindsAtHands->isChecked()) {
gameData.raiseIntervalMode = RAISE_ON_HANDNUMBER;
gameData.raiseSmallBlindEveryHandsValue = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value();
}
else {
gameData.raiseIntervalMode = RAISE_ON_MINUTES;
gameData.raiseSmallBlindEveryMinutesValue = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryMinutes->value();
}
2010-03-30 12:25:30 +00:00
if(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->radioButton_alwaysDoubleBlinds->isChecked()) {
gameData.raiseMode = DOUBLE_BLINDS;
}
else {
gameData.raiseMode = MANUAL_BLINDS_ORDER;
std::list<int> tempBlindList;
int i;
bool ok = TRUE;
for(i=0; i<myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->listWidget_blinds->count(); i++) {
tempBlindList.push_back(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->listWidget_blinds->item(i)->text().toInt(&ok,10));
}
gameData.manualBlindsList = tempBlindList;
if(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysDoubleBlinds->isChecked()) { gameData.afterManualBlindsMode = AFTERMB_DOUBLE_BLINDS; }
else {
if(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysRaiseAbout->isChecked()) {
gameData.afterManualBlindsMode = AFTERMB_RAISE_ABOUT;
gameData.afterMBAlwaysRaiseValue = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_afterThisAlwaysRaiseValue->value();
}
2010-03-30 12:25:30 +00:00
else { gameData.afterManualBlindsMode = AFTERMB_STAY_AT_LAST_BLIND; }
}
}
2010-03-30 12:25:30 +00:00
gameData.guiSpeed = myConfig->readConfigInt("GameSpeed");
gameData.delayBetweenHandsSec = myCreateInternetGameDialog->spinBox_netDelayBetweenHands->value();
gameData.playerActionTimeoutSec = myCreateInternetGameDialog->spinBox_netTimeOutPlayerAction->value();
gameData.gameType = GameType(myCreateInternetGameDialog->comboBox_gameType->itemData(myCreateInternetGameDialog->comboBox_gameType->currentIndex(), Qt::UserRole).toInt());
2007-09-30 00:42:14 +00:00
2010-03-30 12:25:30 +00:00
currentGameName = myCreateInternetGameDialog->lineEdit_gameName->text();
2010-03-27 09:52:49 +00:00
2010-03-30 12:25:30 +00:00
switch (gameData.gameType) {
case GAME_TYPE_NORMAL: {
label_typeIcon->setPixmap(QPixmap(":/gfx/player_play.png"));
label_typeText->setText(tr("Standard"));
}
break;
case GAME_TYPE_REGISTERED_ONLY: {
label_typeIcon->setPixmap(QPixmap(":/gfx/registered.png"));
label_typeText->setText(tr("Registered players only"));
}
break;
case GAME_TYPE_INVITE_ONLY: {
label_typeIcon->setPixmap(QPixmap(":/gfx/list_add_user.png"));
label_typeText->setText(tr("Invited players only"));
}
break;
case GAME_TYPE_RANKING: {
label_typeIcon->setPixmap(QPixmap(":/gfx/cup.png"));
label_typeText->setText(tr("Ranking game"));
}
break;
}
2007-10-03 00:32:17 +00:00
showGameDescription(TRUE);
2007-10-03 09:37:02 +00:00
2010-03-30 12:25:30 +00:00
label_SmallBlind->setText(QString("%L1").arg(gameData.firstSmallBlind));
label_StartCash->setText(QString("%L1").arg(gameData.startMoney));
2010-03-30 12:25:30 +00:00
QTreeWidgetItem *header = treeWidget_connectedPlayers->headerItem();
header->setText(0, tr("Connected players - max. %1").arg(gameData.maxNumberOfPlayers));
header->setData(0, Qt::UserRole, gameData.maxNumberOfPlayers);
updateDialogBlinds(gameData);
label_TimeoutForPlayerAction->setText(QString::number(gameData.playerActionTimeoutSec));
mySession->clientCreateGame(gameData, currentGameName.toUtf8().constData(), myCreateInternetGameDialog->lineEdit_Password->text().toUtf8().constData());
}
}
void gameLobbyDialogImpl::joinGame()
{
2010-03-30 12:25:30 +00:00
assert(mySession);
QItemSelectionModel *selection = treeView_GameList->selectionModel();
if (!inGame && selection->hasSelection())
{
unsigned gameId = selection->selectedRows().first().data(Qt::UserRole).toUInt();
GameInfo info(mySession->getClientGameInfo(gameId));
bool ok = true;
QString password;
//if private ask for password
if (info.isPasswordProtected) {
password = QInputDialog::getText(this, tr("Joining a private Game"),
tr("You are about to join a private game. Please enter the password!"), QLineEdit::Password, (""), &ok);
}
2010-03-30 12:25:30 +00:00
if (ok)
mySession->clientJoinGame(gameId, password.toUtf8().constData());
}
}
void gameLobbyDialogImpl::joinAnyGame() {
2010-03-30 12:25:30 +00:00
if(comboBox_gameListFilter->currentIndex() != 3 && comboBox_gameListFilter->currentIndex() != 0) comboBox_gameListFilter->setCurrentIndex(0);
2010-03-30 12:25:30 +00:00
bool found = FALSE;
2007-11-24 00:37:33 +00:00
2010-03-30 12:25:30 +00:00
int it = 0;
int gameToJoinId = 0;
int mostConnectedPlayers = 0;
2010-03-30 12:25:30 +00:00
while (myGameListModel->item(it)) {
int players = myGameListModel->item(it, 1)->data(Qt::DisplayRole).toString().section("/",0,0).toInt();
int maxPlayers = myGameListModel->item(it, 1)->data(Qt::DisplayRole).toString().section("/",1,1).toInt();
if (myGameListModel->item(it, 2)->data(16) == "open" && myGameListModel->item(it, 4)->data(16) == "nonpriv" && players < maxPlayers)
{
if(players > mostConnectedPlayers) {
mostConnectedPlayers = players;
gameToJoinId = it;
}
found = TRUE;
}
it++;
}
if(found) {
treeView_GameList->setCurrentIndex(myGameListSortFilterProxyModel->mapFromSource(myGameListModel->item(gameToJoinId)->index()));
joinGame();
}
}
void gameLobbyDialogImpl::refresh(int actionID) {
if (actionID == MSG_NET_GAME_CLIENT_START) {
2010-03-30 12:25:30 +00:00
myGameListModel->clear();
myGameListSelectionModel->clear();
myGameListSelectionModel->clearSelection();
myGameListSortFilterProxyModel->clear();
myNickListModel->clear();
myNickListSelectionModel->clear();
myNickListSelectionModel->clearSelection();;
2010-03-30 12:25:30 +00:00
QStringList headerList;
headerList << tr("Game") << tr("Players") << tr("State") << tr("T") << tr("P");
myGameListModel->setHorizontalHeaderLabels(headerList);
treeView_GameList->setColumnWidth(0,190);
2010-03-30 12:25:30 +00:00
treeView_GameList->setColumnWidth(1,65);
treeView_GameList->setColumnWidth(2,65);
treeView_GameList->setColumnWidth(3,40);
treeView_GameList->setColumnWidth(4,40);
QStringList headerList2;
headerList2 << tr("Available Players");
myNickListModel->setHorizontalHeaderLabels(headerList2);
2010-03-30 12:25:30 +00:00
2010-09-25 18:45:55 +00:00
//stop waitStartGameMsgBox
waitStartGameMsgBoxTimer->stop();
waitStartGameMsgBox->hide();
2010-03-30 12:25:30 +00:00
this->accept();
myW->show();
}
else if(actionID == MSG_NET_GAME_CLIENT_SYNCSTART) {
waitStartGameMsgBoxTimer->start(2000);
}
}
2007-11-07 14:11:57 +00:00
void gameLobbyDialogImpl::removedFromGame(int /*reason*/)
{
2010-03-30 12:25:30 +00:00
inGame = false;
isGameAdministrator = false;
leftGameDialogUpdate();
}
void gameLobbyDialogImpl::gameSelected(const QModelIndex &index)
{
2008-03-03 10:25:32 +00:00
if (!inGame && index.isValid() )
2010-03-30 12:25:30 +00:00
{
pushButton_JoinGame->setEnabled(true);
2010-03-30 12:25:30 +00:00
currentGameName = myGameListModel->item(myGameListSortFilterProxyModel->mapToSource(index).row(), 0)->text();
2007-08-26 12:45:37 +00:00
2010-03-30 12:25:30 +00:00
groupBox_GameInfo->setEnabled(true);
groupBox_GameInfo->setTitle(tr("Game Info") + " - " + currentGameName);
2010-03-30 12:25:30 +00:00
assert(mySession);
GameInfo info(mySession->getClientGameInfo(myGameListModel->item(myGameListSortFilterProxyModel->mapToSource(index).row(), 0)->data(Qt::UserRole).toUInt()));
switch (info.data.gameType) {
2010-03-30 12:25:30 +00:00
case GAME_TYPE_NORMAL: {
label_typeIcon->setPixmap(QPixmap(":/gfx/player_play.png"));
label_typeText->setText(tr("Standard"));
}
break;
2010-03-30 12:25:30 +00:00
case GAME_TYPE_REGISTERED_ONLY: {
label_typeIcon->setPixmap(QPixmap(":/gfx/registered.png"));
label_typeText->setText(tr("Registered players only"));
}
break;
2010-03-30 12:25:30 +00:00
case GAME_TYPE_INVITE_ONLY: {
label_typeIcon->setPixmap(QPixmap(":/gfx/list_add_user.png"));
label_typeText->setText(tr("Invited players only"));
}
break;
2010-03-30 12:25:30 +00:00
case GAME_TYPE_RANKING: {
label_typeIcon->setPixmap(QPixmap(":/gfx/cup.png"));
label_typeText->setText(tr("Ranking game"));
}
break;
}
showGameDescription(TRUE);
2010-03-30 12:25:30 +00:00
label_SmallBlind->setText(QString("%L1").arg(info.data.firstSmallBlind));
label_StartCash->setText(QString("%L1").arg(info.data.startMoney));
// label_MaximumNumberOfPlayers->setText(QString::number(info.data.maxNumberOfPlayers));s
updateDialogBlinds(info.data);
2007-10-17 22:27:11 +00:00
2010-03-30 12:25:30 +00:00
label_TimeoutForPlayerAction->setText(QString::number(info.data.playerActionTimeoutSec));
treeWidget_connectedPlayers->clear();
PlayerIdList::const_iterator i = info.players.begin();
PlayerIdList::const_iterator end = info.players.end();
while (i != end)
{
bool admin = info.adminPlayerId == *i;
PlayerInfo playerInfo(mySession->getClientPlayerInfo(*i));
addConnectedPlayer(*i, QString::fromUtf8(playerInfo.playerName.c_str()), admin);
++i;
}
QTreeWidgetItem *header = treeWidget_connectedPlayers->headerItem();
header->setText(0, tr("Connected players - Max. %1").arg(info.data.maxNumberOfPlayers));
header->setData(0, Qt::UserRole, info.data.maxNumberOfPlayers);
#ifdef __APPLE__
// Dirty workaround for a Qt redraw bug on Mac OS.
treeWidget_connectedPlayers->setFocus();
treeView_GameList->setFocus();
#endif
}
}
void gameLobbyDialogImpl::updateGameItem(QList <QStandardItem*> itemList, unsigned gameId)
{
assert(mySession);
GameInfo info(mySession->getClientGameInfo(gameId));
itemList.at(0)->setData(gameId, Qt::UserRole);
itemList.at(0)->setData(QString::fromUtf8(info.name.c_str()), Qt::DisplayRole);
PlayerIdList::const_iterator i = info.players.begin();
PlayerIdList::const_iterator end = info.players.end();
while (i != end)
{
if(myPlayerId == *i) {
itemList.at(0)->setData( "MeInThisGame", 16);
itemList.at(0)->setBackground(QBrush(QColor(0, 255, 0, 127)));
itemList.at(1)->setBackground(QBrush(QColor(0, 255, 0, 127)));
itemList.at(2)->setBackground(QBrush(QColor(0, 255, 0, 127)));
itemList.at(3)->setBackground(QBrush(QColor(0, 255, 0, 127)));
itemList.at(4)->setBackground(QBrush(QColor(0, 255, 0, 127)));
break;
}
else {
itemList.at(0)->setData( "", 16);
itemList.at(0)->setBackground(QBrush());
itemList.at(1)->setBackground(QBrush());
itemList.at(2)->setBackground(QBrush());
itemList.at(3)->setBackground(QBrush());
itemList.at(4)->setBackground(QBrush());
}
++i;
}
QString playerStr;
playerStr.sprintf("%u/%u", (unsigned)info.players.size(), (unsigned)info.data.maxNumberOfPlayers);
itemList.at(1)->setData(playerStr, Qt::DisplayRole);
if((unsigned)info.players.size() == (unsigned)info.data.maxNumberOfPlayers) { itemList.at(1)->setData("totalfull", 16); }
else { itemList.at(1)->setData("nonfull", 16); }\
if (info.mode == GAME_MODE_STARTED) {
itemList.at(2)->setData(tr("running"), Qt::DisplayRole);
itemList.at(2)->setData("running", 16);
}
else {
itemList.at(2)->setData(tr("open"), Qt::DisplayRole);
itemList.at(2)->setData("open", 16);
}
switch (info.data.gameType) {
case GAME_TYPE_NORMAL: {
itemList.at(3)->setIcon(QIcon(":/gfx/player_play.png"));
itemList.at(3)->setData("", Qt::DisplayRole);
itemList.at(3)->setData("standard", 16);
}
break;
case GAME_TYPE_REGISTERED_ONLY: {
itemList.at(3)->setIcon(QIcon(":/gfx/registered.png"));
itemList.at(3)->setData(" ", Qt::DisplayRole);
itemList.at(3)->setData("registered", 16);
}
break;
case GAME_TYPE_INVITE_ONLY: {
itemList.at(3)->setIcon(QIcon(":/gfx/list_add_user.png"));
itemList.at(3)->setData(" ", Qt::DisplayRole);
itemList.at(3)->setData("invited", 16);
}
break;
case GAME_TYPE_RANKING: {
itemList.at(3)->setIcon(QIcon(":/gfx/cup.png"));
itemList.at(3)->setData(" ", Qt::DisplayRole);
itemList.at(3)->setData("ranking", 16);
}
break;
}
if (info.isPasswordProtected) {
itemList.at(4)->setIcon(QIcon(":/gfx/lock.png"));
itemList.at(4)->setData(" ", Qt::DisplayRole);
itemList.at(4)->setData("private", 16);
}
else {
itemList.at(4)->setData("", Qt::DisplayRole);
itemList.at(4)->setData("nonpriv", 16);
}
// treeView_GameList->sortByColumn(myConfig->readConfigInt("DlgGameLobbyGameListSortingSection"), (Qt::SortOrder)myConfig->readConfigInt("DlgGameLobbyGameListSortingOrder") );
refreshGameStats();
}
void gameLobbyDialogImpl::addGame(unsigned gameId)
{
2010-03-30 12:25:30 +00:00
QList <QStandardItem*> itemList;
QStandardItem *item1 = new QStandardItem();
QStandardItem *item2 = new QStandardItem();
QStandardItem *item3 = new QStandardItem();
QStandardItem *item4 = new QStandardItem();
QStandardItem *item5 = new QStandardItem();
itemList << item1 << item2 << item3 << item4 << item5;
myGameListModel->appendRow(itemList);
updateGameItem(itemList, gameId);
}
void gameLobbyDialogImpl::updateGameMode(unsigned gameId, int /*newMode*/)
{
2010-03-30 12:25:30 +00:00
int it = 0;
while (myGameListModel->item(it)) {
if (myGameListModel->item(it, 0)->data(Qt::UserRole) == gameId)
{
QList <QStandardItem*> itemList;
itemList << myGameListModel->item(it, 0) << myGameListModel->item(it, 1) << myGameListModel->item(it, 2) << myGameListModel->item(it, 3) << myGameListModel->item(it, 4);
updateGameItem(itemList, gameId);
break;
}
it++;
}
}
void gameLobbyDialogImpl::updateGameAdmin(unsigned /*gameId*/, unsigned adminPlayerId)
{
2010-03-30 12:25:30 +00:00
newGameAdmin(adminPlayerId, "");
}
void gameLobbyDialogImpl::removeGame(unsigned gameId)
{
2010-03-30 12:25:30 +00:00
int it = 0;
while (myGameListModel->item(it)) {
if (myGameListModel->item(it, 0)->data(Qt::UserRole) == gameId)
{
myGameListModel->removeRow(it);
break;
}
it++;
}
refreshGameStats();
2007-10-17 22:27:11 +00:00
}
void gameLobbyDialogImpl::refreshGameStats() {
2010-03-30 12:25:30 +00:00
int runningGamesCounter = 0;
int openGamesCounter = 0;
2007-10-17 22:27:11 +00:00
2010-03-30 12:25:30 +00:00
int it = 0;
while (myGameListModel->item(it)) {
if (myGameListModel->item(it, 2)->data(16) == "running") { runningGamesCounter++; }
if (myGameListModel->item(it, 2)->data(16) == "open") { openGamesCounter++; }
++it;
}
2007-10-17 22:27:11 +00:00
2010-03-30 12:25:30 +00:00
label_openGamesCounter->setText("| "+tr("running games: %1").arg(runningGamesCounter));
label_runningGamesCounter->setText("| "+tr("open games: %1").arg(openGamesCounter));
//refresh joinAnyGameButton state
joinAnyGameButtonRefresh();
2007-10-17 22:27:11 +00:00
}
void gameLobbyDialogImpl::refreshPlayerStats() {
2010-03-30 12:25:30 +00:00
ServerStats stats = mySession->getClientStats();
label_connectedPlayersCounter->setText(tr("connected players: %1").arg(myNickListModel->rowCount()));
}
void gameLobbyDialogImpl::gameAddPlayer(unsigned gameId, unsigned playerId)
{
2010-03-30 12:25:30 +00:00
if (!inGame)
{
QItemSelectionModel *selection = treeView_GameList->selectionModel();
if (selection->hasSelection()) {
if(selection->selectedRows().at(0).data(Qt::UserRole).toUInt() == gameId) {
assert(mySession);
GameInfo info(mySession->getClientGameInfo(gameId));
bool admin = info.adminPlayerId == playerId;
PlayerInfo playerInfo(mySession->getClientPlayerInfo(playerId));
2010-03-30 12:25:30 +00:00
addConnectedPlayer(playerId, QString::fromUtf8(playerInfo.playerName.c_str()), admin);
}
}
}
int it = 0;
while (myGameListModel->item(it)) {
if (myGameListModel->item(it, 0)->data(Qt::UserRole) == gameId) {
QList <QStandardItem*> itemList;
itemList << myGameListModel->item(it, 0) << myGameListModel->item(it, 1) << myGameListModel->item(it, 2) << myGameListModel->item(it, 3) << myGameListModel->item(it, 4);
updateGameItem(itemList, gameId);
break;
}
it++;
}
//mark player as active
int it1 = 0;
while (myNickListModel->item(it1)) {
if (myNickListModel->item(it1, 0)->data(Qt::UserRole) == playerId) {
myNickListModel->item(it1, 0)->setData("active", 34);
break;
}
++it1;
}
}
void gameLobbyDialogImpl::gameRemovePlayer(unsigned gameId, unsigned playerId)
{
2010-03-30 12:25:30 +00:00
if (!inGame)
{
QItemSelectionModel *selection = treeView_GameList->selectionModel();
if (selection->hasSelection()) {
if(selection->selectedRows().at(0).data(Qt::UserRole).toUInt() == gameId) {
assert(mySession);
PlayerInfo info(mySession->getClientPlayerInfo(playerId));
removePlayer(playerId, QString::fromUtf8(info.playerName.c_str()));
}
}
}
2010-03-30 12:25:30 +00:00
int it = 0;
while (myGameListModel->item(it)) {
if (myGameListModel->item(it, 0)->data(Qt::UserRole) == gameId) {
QList <QStandardItem*> itemList;
itemList << myGameListModel->item(it, 0) << myGameListModel->item(it, 1) << myGameListModel->item(it, 2) << myGameListModel->item(it, 3) << myGameListModel->item(it, 4);
updateGameItem(itemList, gameId);
break;
}
++it;
}
//mark player as idle again
int it1 = 0;
while (myNickListModel->item(it1)) {
if (myNickListModel->item(it1, 0)->data(Qt::UserRole) == playerId) {
myNickListModel->item(it1, 0)->setData("idle", 34);
break;
}
++it1;
}
}
void gameLobbyDialogImpl::updateStats(ServerStats /*stats*/)
{
2010-03-30 12:25:30 +00:00
refreshPlayerStats();
}
void gameLobbyDialogImpl::clearDialog()
{
2010-03-30 12:25:30 +00:00
groupBox_GameInfo->setTitle(tr("Game Info"));
groupBox_GameInfo->setEnabled(false);
currentGameName = "";
2010-03-30 12:25:30 +00:00
QTreeWidgetItem *header = treeWidget_connectedPlayers->headerItem();
header->setText(0, tr("Connected players"));
header->setData(0, Qt::UserRole, 0);
2010-03-27 09:52:49 +00:00
showGameDescription(FALSE);
2010-03-30 12:25:30 +00:00
label_typeIcon->setText(" ");
label_typeText->setText(" ");
label_SmallBlind->setText("");
label_StartCash->setText("");
label_blindsRaiseIntervall->setText("");
label_blindsRaiseMode->setText("");
label_blindsList->setText("");
label_TimeoutForPlayerAction->setText("");
2010-03-30 12:25:30 +00:00
myGameListModel->clear();
myGameListSelectionModel->clear();
myGameListSelectionModel->clearSelection();
myGameListSortFilterProxyModel->clear();
treeView_GameList->show();
treeWidget_connectedPlayers->clear();
2010-03-30 12:25:30 +00:00
pushButton_Leave->hide();
pushButton_Kick->hide();
pushButton_Kick->setEnabled(false);
pushButton_StartGame->hide();
checkBox_fillUpWithComputerOpponents->hide();
pushButton_CreateGame->show();
pushButton_JoinGame->show();
pushButton_JoinGame->setEnabled(false);
pushButton_joinAnyGame->show();
pushButton_joinAnyGame->setEnabled(false);
2010-03-30 12:25:30 +00:00
QStringList headerList;
headerList << tr("Game") << tr("Players") << tr("State") << tr("T") << tr("P");
myGameListModel->setHorizontalHeaderLabels(headerList);
treeView_GameList->setColumnWidth(0,190);
2010-03-30 12:25:30 +00:00
treeView_GameList->setColumnWidth(1,65);
treeView_GameList->setColumnWidth(2,65);
treeView_GameList->setColumnWidth(3,40);
treeView_GameList->setColumnWidth(4,40);
2007-10-09 20:41:57 +00:00
2010-03-30 12:25:30 +00:00
pushButton_CreateGame->clearFocus();
lineEdit_ChatInput->setFocus();
myChat->clearChat();
myNickListModel->clear();
myNickListSelectionModel->clear();
myNickListSelectionModel->clearSelection();;
QStringList headerList2;
headerList2 << tr("Available Players");
myNickListModel->setHorizontalHeaderLabels(headerList2);
myNickListModel->sort(0, treeView_NickList->header()->sortIndicatorOrder());
2010-03-30 12:25:30 +00:00
inGame = false;
isGameAdministrator = false;
myPlayerId = 0;
2007-10-30 12:14:42 +00:00
showGameDescription(FALSE);
2007-11-29 11:58:23 +00:00
2010-03-30 12:25:30 +00:00
label_connectedPlayersCounter->setText(tr("connected players: %1").arg(0));
label_openGamesCounter->setText("| "+tr("running games: %1").arg(0));
label_runningGamesCounter->setText("| "+tr("open games: %1").arg(0));
readDialogSettings();
}
2007-08-29 22:30:18 +00:00
void gameLobbyDialogImpl::checkPlayerQuantity() {
assert(mySession);
GameInfo info(mySession->getClientGameInfo(mySession->getClientCurrentGameId()));
if(isGameAdministrator && info.data.gameType != GAME_TYPE_RANKING){
2010-03-30 12:25:30 +00:00
pushButton_Kick->show();
pushButton_StartGame->show();
checkBox_fillUpWithComputerOpponents->show();
if (treeWidget_connectedPlayers->topLevelItemCount() >= 2) {
pushButton_StartGame->setEnabled(true);
if(treeWidget_connectedPlayers->topLevelItemCount() == treeWidget_connectedPlayers->headerItem()->data(0, Qt::UserRole).toInt()) {
blinkingButtonAnimationTimer->start();
}
else {
blinkingButtonAnimationTimer->stop();
blinkingButtonAnimationState = false;
blinkingStartButtonAnimation();
}
}
else {
pushButton_StartGame->setEnabled(false);
blinkingButtonAnimationTimer->stop();
blinkingButtonAnimationState = false;
blinkingStartButtonAnimation();
}
}
//general actions
if(treeWidget_connectedPlayers->topLevelItemCount() < treeWidget_connectedPlayers->headerItem()->data(0, Qt::UserRole).toInt()) {
autoStartTimerOverlay->hide();
autoStartTimer->stop();
}
}
void gameLobbyDialogImpl::blinkingStartButtonAnimation() {
2010-03-30 12:25:30 +00:00
if(blinkingButtonAnimationState) {
QPalette p = pushButton_StartGame->palette();
p.setColor(QPalette::Button, QColor(Qt::red));
p.setColor(QPalette::ButtonText, QColor(Qt::white));
pushButton_StartGame->setPalette(p);
blinkingButtonAnimationState = false;
}
else {
if(pushButton_StartGame->isEnabled()) {
QPalette p = pushButton_StartGame->palette();
p.setColor(QPalette::Button, defaultStartButtonColor);
p.setColor(QPalette::ButtonText, defaultStartButtonTextColor);
pushButton_StartGame->setPalette(p);
blinkingButtonAnimationState = true;
}
else {
QPalette p = pushButton_StartGame->palette();
p.setColor(QPalette::Button, disabledStartButtonColor);
p.setColor(QPalette::ButtonText, disabledStartButtonTextColor);
pushButton_StartGame->setPalette(p);
blinkingButtonAnimationState = true;
}
}
2007-08-29 22:30:18 +00:00
}
void gameLobbyDialogImpl::joinedNetworkGame(unsigned playerId, QString playerName, bool isGameAdmin) {
2007-08-29 22:30:18 +00:00
// Update dialog
inGame = true;
joinedGameDialogUpdate();
myPlayerId = playerId;
isGameAdministrator = isGameAdmin;
addConnectedPlayer(playerId, playerName, isGameAdmin);
//show msgBox about invite only game
assert(mySession);
if(mySession->getClientGameInfo(mySession->getClientCurrentGameId()).data.gameType == GAME_TYPE_INVITE_ONLY) {
infoMsgToShowId = 2;
showInfoMsgBoxTimer->start(1000);
}
// if(!myGameListSelectionModel->hasSelection() && mySession->getClientGameInfo(mySession->getClientCurrentGameId()).data.gameType == GAME_TYPE_INVITE_ONLY) {
// int it = 0;
// while (myGameListModel->item(it)) {
// if (myGameListModel->item(it, 0)->data(Qt::UserRole) == mySession->getClientCurrentGameId()) {
// gameSelected(treeView_GameList->model()->index(it,0), true);
// break;
// }
// it++;
// }
// }
2007-08-29 22:30:18 +00:00
}
void gameLobbyDialogImpl::addConnectedPlayer(unsigned playerId, QString playerName, bool isGameAdmin) {
2007-08-29 22:30:18 +00:00
2010-03-30 12:25:30 +00:00
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_connectedPlayers, 0);
item->setData(0, Qt::UserRole, playerId);
item->setData(0, Qt::DisplayRole, playerName);
2007-08-29 22:30:18 +00:00
2010-03-30 12:25:30 +00:00
if(isGameAdmin) item->setBackground(0, QBrush(QColor(0, 255, 0, 127)));
2010-03-30 12:25:30 +00:00
if(this->isVisible() && inGame && myConfig->readConfigInt("PlayNetworkGameNotification")) {
if(treeWidget_connectedPlayers->topLevelItemCount() < treeWidget_connectedPlayers->headerItem()->data(0, Qt::UserRole).toInt()) {
myW->getMySDLPlayer()->playSound("playerconnected", 0);
}
else {
myW->getMySDLPlayer()->playSound("onlinegameready", 0);
showAutoStartTimer();
2010-03-30 12:25:30 +00:00
}
}
2007-11-01 19:27:02 +00:00
2010-03-30 12:25:30 +00:00
checkPlayerQuantity();
if (inGame)
refreshConnectedPlayerAvatars();
}
void gameLobbyDialogImpl::updatePlayer(unsigned playerId, QString newPlayerName) {
2010-03-30 12:25:30 +00:00
//rename player in connected players list
QTreeWidgetItemIterator it(treeWidget_connectedPlayers);
while (*it) {
if ((*it)->data(0, Qt::UserRole) == playerId)
{
(*it)->setData(0, Qt::DisplayRole, newPlayerName);
break;
}
++it;
}
2007-11-01 19:27:02 +00:00
2010-03-30 12:25:30 +00:00
if (inGame)
refreshConnectedPlayerAvatars();
2010-03-26 20:09:51 +00:00
2010-03-30 12:25:30 +00:00
//also rename player in nick-list
QString oldNick;
int it1 = 0;
while (myNickListModel->item(it1)) {
if (myNickListModel->item(it1, 0)->data(Qt::UserRole) == playerId) {
oldNick = myNickListModel->item(it1, 0)->text();
myNickListModel->item(it1, 0)->setText(newPlayerName);
2010-03-30 12:25:30 +00:00
PlayerInfo playerInfo(mySession->getClientPlayerInfo(playerId));
QString countryString = QString::fromUtf8(playerInfo.countryCode.c_str()).toLower();
myNickListModel->item(it1, 0)->setData(countryString, 33);
if(playerInfo.isGuest || countryString.isEmpty()) {
myNickListModel->item(it1, 0)->setIcon(QIcon(":/cflags/cflags/undefined.png"));
2010-03-30 12:25:30 +00:00
}
else {
myNickListModel->item(it1, 0)->setIcon(QIcon(QString(":/cflags/cflags/%1.png").arg(countryString)));
2010-03-30 12:25:30 +00:00
}
unsigned gameIdOfPlayer = mySession->getGameIdOfPlayer(playerId);
if(gameIdOfPlayer) { myNickListModel->item(it1, 0)->setData("active", 34); }
else { myNickListModel->item(it1, 0)->setData("idle", 34); }
2010-03-30 12:25:30 +00:00
break;
}
2010-03-30 12:25:30 +00:00
++it1;
}
if (myChat->getMyNick() == oldNick) {
myChat->setMyNick(newPlayerName);
}
}
void gameLobbyDialogImpl::removePlayer(unsigned playerId, QString) {
2010-03-30 12:25:30 +00:00
QTreeWidgetItemIterator it(treeWidget_connectedPlayers);
while (*it) {
if ((*it)->data(0, Qt::UserRole) == playerId)
{
treeWidget_connectedPlayers->takeTopLevelItem(treeWidget_connectedPlayers->indexOfTopLevelItem(*it));
break;
}
++it;
}
2007-08-29 22:30:18 +00:00
2010-03-30 12:25:30 +00:00
checkPlayerQuantity();
2007-08-29 22:30:18 +00:00
}
2009-08-17 23:20:58 +00:00
void gameLobbyDialogImpl::playerLeftLobby(unsigned playerId)
{
int it1 = 0;
while (myNickListModel->item(it1)) {
if (myNickListModel->item(it1, 0)->data(Qt::UserRole) == playerId) {
myNickListModel->removeRow(it1);;
2010-03-30 12:25:30 +00:00
break;
}
++it1;
2010-03-30 12:25:30 +00:00
}
refreshPlayerStats();
2009-08-17 23:20:58 +00:00
}
2010-03-26 20:09:51 +00:00
void gameLobbyDialogImpl::playerJoinedLobby(unsigned playerId, QString /*playerName TODO remove*/)
2009-08-17 23:20:58 +00:00
{
2010-03-30 12:25:30 +00:00
PlayerInfo playerInfo(mySession->getClientPlayerInfo(playerId));
QString countryString = QString::fromUtf8(playerInfo.countryCode.c_str()).toLower();
2010-03-26 20:09:51 +00:00
QStandardItem *item = new QStandardItem;
item->setText(QString::fromUtf8(playerInfo.playerName.c_str()));
item->setData(playerId, Qt::UserRole);
item->setData(countryString, 33);
if(playerInfo.isGuest || countryString.isEmpty()) {
item->setIcon(QIcon(":/cflags/cflags/undefined.png"));
}
else {
item->setIcon(QIcon(QString(":/cflags/cflags/%1.png").arg(countryString)));
}
unsigned gameIdOfPlayer = mySession->getGameIdOfPlayer(playerId);
if(gameIdOfPlayer) { item->setData("active", 34); }
else { item->setData("idle", 34); }
myNickListModel->appendRow(item);
2009-08-17 23:20:58 +00:00
2010-03-30 12:25:30 +00:00
refreshPlayerStats();
2009-08-17 23:20:58 +00:00
}
void gameLobbyDialogImpl::newGameAdmin(unsigned playerId, QString)
{
2010-03-30 12:25:30 +00:00
QTreeWidgetItemIterator it(treeWidget_connectedPlayers);
while (*it) {
if ((*it)->data(0, Qt::UserRole) == playerId) {
(*it)->setBackground(0, QBrush(QColor(0, 255, 0, 127)));
}
++it;
}
2007-10-03 23:30:41 +00:00
2010-03-30 12:25:30 +00:00
if (inGame && myPlayerId == playerId)
{
isGameAdministrator = true;
checkPlayerQuantity();
}
}
void gameLobbyDialogImpl::refreshConnectedPlayerAvatars() {
2010-03-30 12:25:30 +00:00
QTreeWidgetItemIterator it(treeWidget_connectedPlayers);
while (*it) {
2010-03-30 12:25:30 +00:00
std::string myAvatarFileName;
PlayerInfo playerInfo(mySession->getClientPlayerInfo((*it)->data(0, Qt::UserRole).toUInt()));
2007-11-01 16:51:59 +00:00
2010-03-30 12:25:30 +00:00
if(mySession->getAvatarFile(playerInfo.avatar, myAvatarFileName)) {
QString myAvatarString(QString::fromUtf8(myAvatarFileName.c_str()));
QFile myAvatarFile(myAvatarString);
if(myAvatarFile.exists()) {
2010-03-30 12:25:30 +00:00
QPixmap myAvatarPixmap(25,26);
myAvatarPixmap.fill(Qt::transparent);
QPixmap tempPixmap(myAvatarString);
QPainter p(&myAvatarPixmap);
p.drawPixmap (0,0,25,25,tempPixmap);
(*it)->setIcon(0, QIcon(myAvatarPixmap));
}
}
++it;
}
}
void gameLobbyDialogImpl::joinedGameDialogUpdate() {
2010-03-27 16:50:31 +00:00
2010-03-30 12:25:30 +00:00
groupBox_GameInfo->setEnabled(true);
groupBox_GameInfo->setTitle(currentGameName);
treeWidget_connectedPlayers->clear();
pushButton_CreateGame->hide();
pushButton_JoinGame->hide();
pushButton_joinAnyGame->hide();
pushButton_Leave->show();
//this was added to show game infos even if no game was selected (e.g. invite only game)
assert(mySession);
GameInfo info(mySession->getClientGameInfo(mySession->getClientCurrentGameId()));
groupBox_GameInfo->setTitle(tr("Game Info") + " - " + QString::fromUtf8(info.name.c_str()));
switch (info.data.gameType) {
case GAME_TYPE_NORMAL: {
label_typeIcon->setPixmap(QPixmap(":/gfx/player_play.png"));
label_typeText->setText(tr("Standard"));
}
break;
case GAME_TYPE_REGISTERED_ONLY: {
label_typeIcon->setPixmap(QPixmap(":/gfx/registered.png"));
label_typeText->setText(tr("Registered players only"));
}
break;
case GAME_TYPE_INVITE_ONLY: {
label_typeIcon->setPixmap(QPixmap(":/gfx/list_add_user.png"));
label_typeText->setText(tr("Invited players only"));
}
break;
case GAME_TYPE_RANKING: {
label_typeIcon->setPixmap(QPixmap(":/gfx/cup.png"));
label_typeText->setText(tr("Ranking game"));
}
break;
}
showGameDescription(TRUE);
label_SmallBlind->setText(QString("%L1").arg(info.data.firstSmallBlind));
label_StartCash->setText(QString("%L1").arg(info.data.startMoney));
updateDialogBlinds(info.data);
label_TimeoutForPlayerAction->setText(QString::number(info.data.playerActionTimeoutSec));
}
void gameLobbyDialogImpl::leftGameDialogUpdate() {
2010-03-30 12:25:30 +00:00
// un-select current game.
treeView_GameList->clearSelection();
2010-03-30 12:25:30 +00:00
groupBox_GameInfo->setTitle(tr("Game Info"));
groupBox_GameInfo->setEnabled(false);
currentGameName = "";
2010-03-30 12:25:30 +00:00
QTreeWidgetItem *header = treeWidget_connectedPlayers->headerItem();
header->setText(0, tr("Connected players"));
header->setData(0, Qt::UserRole, 0);
2010-03-27 09:52:49 +00:00
showGameDescription(FALSE);
2010-03-30 12:25:30 +00:00
label_typeIcon->setText(" ");
label_typeText->setText(" ");
label_SmallBlind->setText("");
label_StartCash->setText("");
label_blindsRaiseIntervall->setText("");
label_blindsRaiseMode->setText("");
label_blindsList->setText("");
label_TimeoutForPlayerAction->setText("");
2010-03-30 12:25:30 +00:00
treeWidget_connectedPlayers->clear();
pushButton_StartGame->hide();
pushButton_Leave->hide();
pushButton_Kick->hide();
pushButton_Kick->setEnabled(false);
checkBox_fillUpWithComputerOpponents->hide();
pushButton_CreateGame->show();
pushButton_JoinGame->show();
pushButton_JoinGame->setEnabled(false);
pushButton_joinAnyGame->show();
joinAnyGameButtonRefresh();
2010-03-30 12:25:30 +00:00
lineEdit_ChatInput->setFocus();
}
2007-10-03 09:37:02 +00:00
void gameLobbyDialogImpl::updateDialogBlinds(const GameData &gameData) {
2010-03-30 12:25:30 +00:00
if(gameData.raiseIntervalMode == RAISE_ON_HANDNUMBER) { label_blindsRaiseIntervall->setText(QString::number(gameData.raiseSmallBlindEveryHandsValue)+" "+tr("hands")); }
else { label_blindsRaiseIntervall->setText(QString::number(gameData.raiseSmallBlindEveryMinutesValue)+" "+tr("minutes")); }
if(gameData.raiseMode == DOUBLE_BLINDS) {
label_blindsRaiseMode->setText(tr("double blinds"));
label_blindsList->hide();
label_gameDesc6->hide();
}
else {
label_blindsRaiseMode->setText(tr("manual blinds order"));
label_blindsList->show();
label_gameDesc6->show();
QString blindsListString;
std::list<int>::const_iterator it1;
for(it1= gameData.manualBlindsList.begin(); it1 != gameData.manualBlindsList.end(); it1++) {
blindsListString.append(QString("%L1").arg(*it1)).append(", ");
}
blindsListString.remove(blindsListString.length()-2,2);
label_blindsList->setText(blindsListString);
}
2007-10-03 09:37:02 +00:00
}
void gameLobbyDialogImpl::playerSelected(QTreeWidgetItem* item, QTreeWidgetItem*) {
2010-03-30 12:25:30 +00:00
if (item)
pushButton_Kick->setEnabled(isGameAdministrator);
}
void gameLobbyDialogImpl::startGame() {
2010-03-30 12:25:30 +00:00
assert(mySession);
mySession->sendStartEvent(checkBox_fillUpWithComputerOpponents->isChecked());
}
void gameLobbyDialogImpl::leaveGame() {
2010-03-30 12:25:30 +00:00
assert(mySession);
mySession->sendLeaveCurrentGame();
//stop autoStartTimerOverlay
autoStartTimerOverlay->hide();
autoStartTimer->stop();
2010-09-25 18:34:45 +00:00
2010-09-25 18:45:55 +00:00
//stop waitStartGameMsgBox
2010-09-25 18:34:45 +00:00
waitStartGameMsgBoxTimer->stop();
waitStartGameMsgBox->hide();
}
void gameLobbyDialogImpl::kickPlayer() {
2010-03-30 12:25:30 +00:00
QTreeWidgetItem *item = treeWidget_connectedPlayers->currentItem();
if (item)
{
QString playerName = item->text(0);
if(playerName == QString::fromUtf8(myConfig->readConfigString("MyName").c_str())) {
{ QMessageBox::warning(this, tr("Server Error"),
tr("You should not kick yourself from this game!"),
QMessageBox::Close); }
}
else {
assert(mySession);
mySession->kickPlayer(item->data(0, Qt::UserRole).toUInt());
}
}
pushButton_Kick->setEnabled(false);
}
2007-09-07 20:26:13 +00:00
void gameLobbyDialogImpl::keyPressEvent ( QKeyEvent * event ) {
2010-03-30 12:25:30 +00:00
// qDebug() << event->key() << "\n";
2010-03-30 12:25:30 +00:00
if (event->key() == Qt::Key_Enter && lineEdit_ChatInput->hasFocus()) { myChat->sendMessage(); }
2010-03-30 12:25:30 +00:00
if (event->key() == Qt::Key_Up && lineEdit_ChatInput->hasFocus()) {
if((keyUpCounter + 1) <= myChat->getChatLinesHistorySize()) { keyUpCounter++; }
// std::cout << "Up keyUpCounter: " << keyUpCounter << "\n";
myChat->showChatHistoryIndex(keyUpCounter);
}
else if(event->key() == Qt::Key_Down && lineEdit_ChatInput->hasFocus()) {
if((keyUpCounter - 1) >= 0) { keyUpCounter--; }
// std::cout << "Down keyUpCounter: " << keyUpCounter << "\n";
myChat->showChatHistoryIndex(keyUpCounter);
}
else { keyUpCounter = 0; }
2010-03-30 12:25:30 +00:00
// if (event->key() == Qt::Key_Tab) event->ignore(); else { /*blah*/ }
// if (event->key() == Qt::Key_N) showInvitationDialog();
// if (event->key() == Qt::Key_M) guestUserMode();
2007-10-10 10:06:09 +00:00
}
2007-10-10 10:06:09 +00:00
bool gameLobbyDialogImpl::eventFilter(QObject *obj, QEvent *event)
{
2010-03-30 12:25:30 +00:00
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
QFocusEvent *focusEvent = static_cast<QFocusEvent*>(event);
2007-10-10 10:06:09 +00:00
if (obj == lineEdit_ChatInput && lineEdit_ChatInput->text() != "" && event->type() == QEvent::KeyPress && keyEvent->key() == Qt::Key_Tab) {
2010-03-30 12:25:30 +00:00
myChat->nickAutoCompletition();
return true;
}
else if (obj == lineEdit_searchForPlayers && focusEvent->gotFocus() && lineEdit_searchForPlayers->text() == tr("search for player ...")) {
lineEdit_searchForPlayers->clear();
return QDialog::eventFilter(obj, event);
}
else {
2010-03-30 12:25:30 +00:00
// pass the event on to the parent class
return QDialog::eventFilter(obj, event);
}
2007-10-10 10:06:09 +00:00
}
bool gameLobbyDialogImpl::event ( QEvent * event ) {
2010-03-30 12:25:30 +00:00
return QDialog::event(event);
}
2007-09-30 00:42:14 +00:00
void gameLobbyDialogImpl::showGameDescription(bool show) {
2007-09-30 00:42:14 +00:00
2010-03-30 12:25:30 +00:00
if(show) {
label_gameType->show();
label_gameDesc2->show();
label_gameDesc3->show();
label_gameDesc4->show();
label_gameDesc5->show();
label_gameDesc6->show();
label_gameDesc7->show();
}
else {
label_gameType->hide();
label_gameDesc2->hide();
label_gameDesc3->hide();
label_gameDesc4->hide();
label_gameDesc5->hide();
label_gameDesc6->hide();
label_gameDesc7->hide();
}
2007-09-30 18:50:46 +00:00
}
2007-10-16 23:07:59 +00:00
2007-10-18 20:10:01 +00:00
void gameLobbyDialogImpl::showWaitStartGameMsgBox() {
2010-09-25 18:34:45 +00:00
if(this->isVisible()) {
waitStartGameMsgBox->show();
waitStartGameMsgBox->raise();
waitStartGameMsgBox->activateWindow();
}
}
2007-10-16 23:07:59 +00:00
void gameLobbyDialogImpl::joinAnyGameButtonRefresh() {
2010-03-30 12:25:30 +00:00
int openNonPrivateNonFullGamesCounter = 0;
2010-03-30 12:25:30 +00:00
int it = 0;
while (myGameListModel->item(it)) {
2010-03-30 12:25:30 +00:00
int players = myGameListModel->item(it, 1)->data(Qt::DisplayRole).toString().section("/",0,0).toInt();
int maxPlayers = myGameListModel->item(it, 1)->data(Qt::DisplayRole).toString().section("/",1,1).toInt();
if (myGameListModel->item(it, 2)->data(16) == "open" && myGameListModel->item(it, 4)->data(16) == "nonpriv" && players < maxPlayers) {
openNonPrivateNonFullGamesCounter++;
}
++it;
}
2010-03-30 12:25:30 +00:00
if(openNonPrivateNonFullGamesCounter) pushButton_joinAnyGame->setEnabled(TRUE);
else pushButton_joinAnyGame->setEnabled(FALSE);
}
void gameLobbyDialogImpl::reject()
{
2010-03-30 12:25:30 +00:00
myStartWindow->show();
QDialog::reject();
}
void gameLobbyDialogImpl::closeEvent(QCloseEvent *event)
{
2010-03-30 12:25:30 +00:00
event->accept();
2010-09-25 18:45:55 +00:00
//stop waitStartGameMsgBox
waitStartGameMsgBoxTimer->stop();
waitStartGameMsgBox->hide();
}
2009-06-16 09:13:45 +00:00
void gameLobbyDialogImpl::writeDialogSettings(int saveMode)
{
2010-03-30 12:25:30 +00:00
switch(saveMode) {
case 0: {
QHeaderView *header = treeView_GameList->header();
myConfig->writeConfigInt("DlgGameLobbyGameListSortingSection", header->sortIndicatorSection());
myConfig->writeConfigInt("DlgGameLobbyGameListSortingOrder", header->sortIndicatorOrder());
}
break;
case 1: {
myConfig->writeConfigInt("DlgGameLobbyGameListFilterIndex", comboBox_gameListFilter->currentIndex());
}
break;
2010-08-30 10:41:56 +00:00
case 2: {
myConfig->writeConfigInt("DlgGameLobbyNickListSortFilterIndex", comboBox_nickListFilter->currentIndex());
}
break;
2010-03-30 12:25:30 +00:00
default:;
}
2010-08-30 10:41:56 +00:00
2010-03-30 12:25:30 +00:00
myConfig->writeBuffer();
}
void gameLobbyDialogImpl::readDialogSettings()
{
2010-03-30 12:25:30 +00:00
comboBox_gameListFilter->setCurrentIndex(myConfig->readConfigInt("DlgGameLobbyGameListFilterIndex"));
treeView_GameList->sortByColumn(myConfig->readConfigInt("DlgGameLobbyGameListSortingSection"), (Qt::SortOrder)myConfig->readConfigInt("DlgGameLobbyGameListSortingOrder") );
2010-08-30 10:41:56 +00:00
comboBox_nickListFilter->setCurrentIndex(myConfig->readConfigInt("DlgGameLobbyNickListSortFilterIndex"));
}
2009-06-14 22:56:49 +00:00
void gameLobbyDialogImpl::changeGameListFilter(int index) {
2010-03-30 12:25:30 +00:00
switch(index) {
case 0: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn4RegExp(QRegExp());
}
break;
case 1: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn4RegExp(QRegExp());
}
break;
case 2: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp("nonfull", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn4RegExp(QRegExp());
}
break;
case 3: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp("nonfull", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn4RegExp(QRegExp("nonpriv", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
case 4: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp("nonfull", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn4RegExp(QRegExp("private", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
default:;
}
myGameListSortFilterProxyModel->setFilterRegExp(QString());
myGameListSortFilterProxyModel->setFilterKeyColumn(0);
writeDialogSettings(1);
if(index) treeView_GameList->setStyleSheet("QTreeView { border-radius: 4px; border: 2px solid blue; background-color: white; background-image: url(\""+myAppDataPath +"gfx/gui/misc/background_gamelist.png\"); background-attachment: fixed; background-position: top center ; background-repeat: no-repeat;}");
else treeView_GameList->setStyleSheet("QTreeView { background-color: white; background-image: url(\""+myAppDataPath +"gfx/gui/misc/background_gamelist.png\"); background-attachment: fixed; background-position: top center ; background-repeat: no-repeat;}");
2009-06-16 09:13:45 +00:00
2009-06-14 22:56:49 +00:00
}
2009-06-16 09:13:45 +00:00
void gameLobbyDialogImpl::changeNickListFilter(int state)
{
myNickListSortFilterProxyModel->setFilterState(state);
myNickListModel->sort(0, Qt::DescendingOrder);
myNickListSortFilterProxyModel->setFilterRegExp(QString());
myNickListSortFilterProxyModel->setFilterKeyColumn(0);
2010-08-30 10:41:56 +00:00
writeDialogSettings(2);
}
2009-06-16 09:13:45 +00:00
void gameLobbyDialogImpl::changeGameListSorting() {
2010-03-30 12:25:30 +00:00
writeDialogSettings(0);
2009-06-16 09:13:45 +00:00
}
void gameLobbyDialogImpl::registeredUserMode()
{
lineEdit_ChatInput->clear();
lineEdit_ChatInput->setEnabled(true);
guestMode = false;
}
void gameLobbyDialogImpl::guestUserMode()
{
2010-07-14 10:07:08 +00:00
lineEdit_ChatInput->setText(tr("Chat is only available to registered players."));
lineEdit_ChatInput->setDisabled(true);
guestMode = true;
}
2010-03-27 21:55:34 +00:00
void gameLobbyDialogImpl::showNickListContextMenu(QPoint p)
{
if(myNickListModel->rowCount() && myNickListSelectionModel->currentIndex().isValid()) {
2010-03-27 21:55:34 +00:00
assert(mySession);
int playerUid = myNickListSelectionModel->currentIndex().data(Qt::UserRole).toUInt();
if(inGame && mySession->getClientGameInfo(mySession->getClientCurrentGameId()).data.gameType == GAME_TYPE_INVITE_ONLY && playerUid != mySession->getClientUniquePlayerId() && !mySession->getClientPlayerInfo(playerUid).isGuest) {
nickListInviteAction->setEnabled(true);
nickListInviteAction->setText(tr("Invite %1").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerUid).playerName.c_str())));
2010-03-27 21:55:34 +00:00
}
else {
nickListInviteAction->setText(tr("Invite player ..."));
2010-03-30 19:39:26 +00:00
nickListInviteAction->setEnabled(false);
}
if(playerUid != mySession->getClientUniquePlayerId() && !mySession->getClientPlayerInfo(playerUid).isGuest) {
2010-03-30 19:57:44 +00:00
nickListIgnorePlayerAction->setEnabled(true);
nickListIgnorePlayerAction->setText(tr("Ignore %1").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerUid).playerName.c_str())));
2010-03-30 19:57:44 +00:00
}
else {
nickListIgnorePlayerAction->setEnabled(false);
nickListIgnorePlayerAction->setText(tr("Ignore player ..."));
}
unsigned gameIdOfPlayer = mySession->getGameIdOfPlayer(playerUid);
QString playerInGameInfoString;
if(gameIdOfPlayer) {
playerInGameInfoString = tr("%1 is playing in \"%2\".").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerUid).playerName.c_str())).arg(QString::fromUtf8(mySession->getClientGameInfo(gameIdOfPlayer).name.c_str()));
}
else {
playerInGameInfoString = tr("%1 is not playing at the moment.").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerUid).playerName.c_str()));
}
nickListPlayerInGameInfo->setText(playerInGameInfoString);
nickListContextMenu->popup(treeView_NickList->mapToGlobal(p));
2010-03-27 21:55:34 +00:00
}
}
void gameLobbyDialogImpl::invitePlayerToCurrentGame()
{
if(myNickListSelectionModel->currentIndex().isValid()) {
mySession->invitePlayerToCurrentGame(myNickListSelectionModel->currentIndex().data(Qt::UserRole).toUInt());
2010-03-30 13:02:43 +00:00
}
2010-03-27 21:55:34 +00:00
}
void gameLobbyDialogImpl::showInfoMsgBox()
{
switch(infoMsgToShowId) {
2010-03-30 12:25:30 +00:00
case 2: {
myMessageDialogImpl dialog(myConfig, this);
2010-07-14 08:45:11 +00:00
dialog.exec(2, tr("You have entered a game with type \"invite-only\".\nFeel free to invite other players by right-clicking on their nick in the available players list."), tr("PokerTH - Info Message"), QPixmap(":/gfx/ktip.png"), QDialogButtonBox::Ok, true);
}
break;
2010-03-30 12:25:30 +00:00
default:;
break;
}
}
2010-03-29 13:08:59 +00:00
void gameLobbyDialogImpl::showInvitationDialog(unsigned gameId, unsigned playerIdFrom)
{
if(inviteDialogIsCurrentlyShown || playerIsOnIgnoreList(playerIdFrom)) {
mySession->rejectGameInvitation(gameId, DENY_GAME_INVITATION_BUSY);
}
else {
2010-03-29 13:08:59 +00:00
inviteDialogIsCurrentlyShown = true;
2010-03-29 13:08:59 +00:00
2010-03-30 12:25:30 +00:00
myMessageDialogImpl dialog(myConfig, this);
2010-07-14 08:45:11 +00:00
if(dialog.exec(3, tr("You have been invited to the game <b>%1</b> by <b>%2</b>.<br>Would you like to join this game?").arg(QString::fromUtf8(mySession->getClientGameInfo(gameId).name.c_str())).arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerIdFrom).playerName.c_str())), tr("PokerTH - Info Message"), QPixmap(":/gfx/list_add_user_64.png"), QDialogButtonBox::Yes|QDialogButtonBox::No, false)) {
2010-03-30 17:37:00 +00:00
mySession->acceptGameInvitation(gameId);
inviteDialogIsCurrentlyShown = false;
}
else {
2010-03-30 17:37:00 +00:00
mySession->rejectGameInvitation(gameId, DENY_GAME_INVITATION_NO);
inviteDialogIsCurrentlyShown = false;
}
2010-03-29 13:08:59 +00:00
}
}
void gameLobbyDialogImpl::chatInfoPlayerInvitation(unsigned gameId, unsigned playerIdWho, unsigned playerIdFrom)
2010-03-29 13:08:59 +00:00
{
textBrowser_ChatDisplay->append(tr("<span style='color:blue;'>%1 has been invited to %2 by %3.</span>").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerIdWho).playerName.c_str())).arg(QString::fromUtf8(mySession->getClientGameInfo(gameId).name.c_str())).arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerIdFrom).playerName.c_str())));
2010-03-29 13:08:59 +00:00
}
void gameLobbyDialogImpl::chatInfoPlayerRejectedInvitation(unsigned gameId, unsigned playerIdWho, DenyGameInvitationReason reason)
2010-03-29 13:08:59 +00:00
{
2010-03-29 13:08:59 +00:00
QString string;
if(reason == DENY_GAME_INVITATION_NO) string = tr("<span style='color:red;'>%1 has rejected the invitation to %2.</span>");
2010-03-29 13:08:59 +00:00
if(reason == DENY_GAME_INVITATION_BUSY) string = tr("<span style='color:red;'>%1 cannot join %2 because he is busy.</span>");
2010-03-29 13:08:59 +00:00
textBrowser_ChatDisplay->append(string.arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerIdWho).playerName.c_str())).arg(QString::fromUtf8(mySession->getClientGameInfo(gameId).name.c_str())));
2010-03-30 12:25:30 +00:00
2010-03-29 13:08:59 +00:00
}
bool gameLobbyDialogImpl::playerIsOnIgnoreList(unsigned playerId) {
list<std::string> playerIgnoreList = myConfig->readConfigStringList("PlayerIgnoreList");
list<std::string>::iterator it1;
for(it1= playerIgnoreList.begin(); it1 != playerIgnoreList.end(); it1++) {
if(QString::fromUtf8(mySession->getClientPlayerInfo(playerId).playerName.c_str()) == QString::fromUtf8(it1->c_str())) {
return true;
}
}
return false;
}
2010-03-30 19:38:14 +00:00
void gameLobbyDialogImpl::putPlayerOnIgnoreList() {
if(myNickListSelectionModel->currentIndex().isValid()) {
unsigned playerId = myNickListSelectionModel->currentIndex().data(Qt::UserRole).toUInt();
2010-03-30 19:38:14 +00:00
if(!playerIsOnIgnoreList(playerId)) {
myMessageDialogImpl dialog(myConfig, this);
2010-07-14 08:45:11 +00:00
if(dialog.exec(4, tr("You will no longer receive chat messages or game invitations from this user.<br>Do you really want to put player <b>%1</b> on your ignore list?").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerId).playerName.c_str())), tr("PokerTH - Question"), QPixmap(":/gfx/im-ban-user_64.png"), QDialogButtonBox::Yes|QDialogButtonBox::No, false ) == QDialog::Accepted) {
2010-03-30 19:38:14 +00:00
list<std::string> playerIgnoreList = myConfig->readConfigStringList("PlayerIgnoreList");
playerIgnoreList.push_back(QString("%1").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerId).playerName.c_str())).toUtf8().constData());
myConfig->writeConfigStringList("PlayerIgnoreList", playerIgnoreList);
myConfig->writeBuffer();
myChat->refreshIgnoreList();
}
2010-03-30 19:38:14 +00:00
}
}
}
void gameLobbyDialogImpl::searchForPlayerRegExpChanged()
{
QRegExp regExp(lineEdit_searchForPlayers->text(), Qt::CaseInsensitive);
myNickListSortFilterProxyModel->setFilterRegExp(regExp);
}
void gameLobbyDialogImpl::showAutoStartTimer()
{
autoStartTimerOverlay->show();
2010-09-05 12:26:36 +00:00
autoStartTimerOverlay->setGeometry(((scrollArea_gameInfos->geometry().width()-190)/2), ((scrollArea_gameInfos->geometry().height()-50)/2), 190, 50);
QString string(tr("The game will start in<br><b>%1</b> seconds.").arg(6));
2010-09-05 13:13:42 +00:00
autoStartTimerOverlay->setText("<span style='color:#008B00; font-size:9pt;'>"+string+"</span>");
autoStartTimerCounter = 6;
autoStartTimer->start(1000);
}
void gameLobbyDialogImpl::updateAutoStartTimer()
{
--autoStartTimerCounter;
if(autoStartTimerCounter) {
2010-09-05 12:26:36 +00:00
QString string(tr("The game will start in<br><b>%1</b> seconds.").arg(autoStartTimerCounter));
2010-09-05 13:13:42 +00:00
autoStartTimerOverlay->setText("<span style='color:#008B00; font-size:9pt;'>"+string+"</span>");
}
else {
autoStartTimer->stop();
autoStartTimerOverlay->hide();
}
}