2007-08-20 21:23:03 +00:00
|
|
|
//
|
|
|
|
|
// C++ Implementation: gamelobbydialogimpl
|
|
|
|
|
//
|
|
|
|
|
// Description:
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Author: FThauer FHammer <webmaster@pokerth.net>, (C) 2007
|
|
|
|
|
//
|
|
|
|
|
// Copyright: See COPYING file that comes with this distribution
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
#include "gamelobbydialogimpl.h"
|
2007-08-21 12:34:33 +00:00
|
|
|
#include "session.h"
|
|
|
|
|
#include "configfile.h"
|
|
|
|
|
#include "gamedata.h"
|
2007-08-20 21:23:03 +00:00
|
|
|
|
|
|
|
|
gameLobbyDialogImpl::gameLobbyDialogImpl(QWidget *parent, ConfigFile *c)
|
2007-09-01 21:15:11 +00:00
|
|
|
: QDialog(parent), myW(NULL), mySession(NULL), myConfig(c), currentGameName(""), isAdmin(false)
|
2007-08-20 21:23:03 +00:00
|
|
|
{
|
|
|
|
|
setupUi(this);
|
|
|
|
|
|
2007-08-21 12:34:33 +00:00
|
|
|
connect( pushButton_CreateGame, SIGNAL( clicked() ), this, SLOT( createGame() ) );
|
|
|
|
|
connect( pushButton_JoinGame, SIGNAL( clicked() ), this, SLOT( joinGame() ) );
|
2007-09-02 16:36:52 +00:00
|
|
|
connect( treeWidget_GameList, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*) ), this, SLOT( gameSelected(QTreeWidgetItem*, QTreeWidgetItem*) ) );
|
2007-08-20 21:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::exec()
|
|
|
|
|
{
|
2007-09-02 16:36:52 +00:00
|
|
|
clearDialog();
|
2007-08-20 21:23:03 +00:00
|
|
|
|
|
|
|
|
QDialog::exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gameLobbyDialogImpl::~gameLobbyDialogImpl()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 12:34:33 +00:00
|
|
|
void gameLobbyDialogImpl::setSession(Session *session)
|
|
|
|
|
{
|
|
|
|
|
mySession = session;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::createGame()
|
|
|
|
|
{
|
|
|
|
|
assert(mySession);
|
|
|
|
|
|
2007-08-21 23:31:09 +00:00
|
|
|
myCreateInternetGameDialog = new createInternetGameDialogImpl(this, myConfig);
|
|
|
|
|
myCreateInternetGameDialog->exec();
|
|
|
|
|
|
|
|
|
|
if (myCreateInternetGameDialog->result() == QDialog::Accepted ) {
|
|
|
|
|
|
|
|
|
|
GameData gameData;
|
|
|
|
|
// Set Game Data
|
|
|
|
|
gameData.maxNumberOfPlayers = myCreateInternetGameDialog->spinBox_quantityPlayers->value();
|
|
|
|
|
gameData.startMoney = myCreateInternetGameDialog->spinBox_startCash->value();
|
|
|
|
|
gameData.smallBlind = myCreateInternetGameDialog->spinBox_smallBlind->value();
|
|
|
|
|
gameData.handsBeforeRaise = myCreateInternetGameDialog->spinBox_handsBeforeRaiseSmallBlind->value();
|
|
|
|
|
gameData.guiSpeed = myCreateInternetGameDialog->spinBox_gameSpeed->value();
|
|
|
|
|
gameData.playerActionTimeoutSec = myCreateInternetGameDialog->spinBox_netTimeOutPlayerAction->value();
|
|
|
|
|
|
2007-09-04 12:44:11 +00:00
|
|
|
mySession->clientCreateGame(gameData, myConfig->readConfigString("MyName") + "'s game", myCreateInternetGameDialog->lineEdit_Password->text().toUtf8().constData());
|
2007-08-21 12:34:33 +00:00
|
|
|
|
2007-08-22 20:03:19 +00:00
|
|
|
currentGameName = QString::fromUtf8(myConfig->readConfigString("MyName").c_str()) + QString("'s game");
|
|
|
|
|
|
2007-08-21 23:31:09 +00:00
|
|
|
accept();
|
|
|
|
|
}
|
2007-08-21 12:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::joinGame()
|
|
|
|
|
{
|
2007-08-21 17:27:13 +00:00
|
|
|
QTreeWidgetItem *item = treeWidget_GameList->currentItem();
|
|
|
|
|
if (item)
|
|
|
|
|
{
|
|
|
|
|
QString gameName = item->text(0);
|
2007-08-21 12:34:33 +00:00
|
|
|
|
2007-08-21 17:27:13 +00:00
|
|
|
assert(mySession);
|
|
|
|
|
mySession->clientJoinGame(gameName.toUtf8().constData(), "");
|
2007-08-21 12:34:33 +00:00
|
|
|
|
2007-08-21 17:27:13 +00:00
|
|
|
accept();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-02 16:36:52 +00:00
|
|
|
void gameLobbyDialogImpl::gameSelected(QTreeWidgetItem* item, QTreeWidgetItem*)
|
2007-08-21 17:27:13 +00:00
|
|
|
{
|
2007-09-02 16:36:52 +00:00
|
|
|
if (item)
|
|
|
|
|
{
|
|
|
|
|
pushButton_JoinGame->setEnabled(true);
|
2007-08-22 20:03:19 +00:00
|
|
|
|
2007-09-02 16:36:52 +00:00
|
|
|
currentGameName = item->text(0);
|
2007-08-26 12:45:37 +00:00
|
|
|
|
2007-09-02 16:36:52 +00:00
|
|
|
groupBox_GameInfo->setEnabled(true);
|
|
|
|
|
groupBox_GameInfo->setTitle(tr("Game Info") + " - " + currentGameName);
|
2007-08-27 09:57:51 +00:00
|
|
|
|
2007-09-02 16:36:52 +00:00
|
|
|
assert(mySession);
|
|
|
|
|
GameInfo info(mySession->getClientGameInfo(item->data(0, Qt::UserRole).toUInt()));
|
|
|
|
|
label_SmallBlind->setText(QString::number(info.data.smallBlind));
|
|
|
|
|
label_StartCash->setText(QString::number(info.data.startMoney));
|
|
|
|
|
label_MaximumNumberOfPlayers->setText(QString::number(info.data.maxNumberOfPlayers));
|
|
|
|
|
label_HandsToRaiseSmallBlind->setText(QString::number(info.data.handsBeforeRaise));
|
|
|
|
|
label_TimeoutForPlayerAction->setText(QString::number(info.data.playerActionTimeoutSec));
|
2007-08-21 12:34:33 +00:00
|
|
|
|
2007-09-02 16:36:52 +00:00
|
|
|
treeWidget_connectedPlayers->clear();
|
|
|
|
|
PlayerIdList::const_iterator i = info.players.begin();
|
|
|
|
|
PlayerIdList::const_iterator end = info.players.end();
|
|
|
|
|
while (i != end)
|
|
|
|
|
{
|
|
|
|
|
PlayerInfo info(mySession->getClientPlayerInfo(*i));
|
|
|
|
|
addConnectedPlayer(*i, QString::fromUtf8(info.playerName.c_str()), PLAYER_RIGHTS_NORMAL);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
2007-08-21 12:34:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-08-20 21:23:03 +00:00
|
|
|
|
2007-09-04 12:44:11 +00:00
|
|
|
void gameLobbyDialogImpl::updateGameItem(QTreeWidgetItem *item, unsigned gameId)
|
2007-09-02 16:36:52 +00:00
|
|
|
{
|
2007-09-04 12:44:11 +00:00
|
|
|
assert(mySession);
|
|
|
|
|
GameInfo info(mySession->getClientGameInfo(gameId));
|
2007-09-02 16:36:52 +00:00
|
|
|
|
|
|
|
|
item->setData(0, Qt::UserRole, gameId);
|
2007-09-04 12:44:11 +00:00
|
|
|
item->setData(0, Qt::DisplayRole, QString::fromUtf8(info.name.c_str()));
|
|
|
|
|
|
|
|
|
|
QString playerStr;
|
|
|
|
|
playerStr.sprintf("%u/%u", info.players.size(), info.data.maxNumberOfPlayers);
|
|
|
|
|
item->setData(1, Qt::DisplayRole, playerStr);
|
|
|
|
|
|
|
|
|
|
if (info.isPasswordProtected)
|
|
|
|
|
item->setData(2, Qt::DisplayRole, "X");
|
2007-09-02 16:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
2007-09-04 12:44:11 +00:00
|
|
|
void gameLobbyDialogImpl::addGame(unsigned gameId)
|
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_GameList, 0);
|
|
|
|
|
|
|
|
|
|
updateGameItem(item, gameId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::removeGame(unsigned gameId)
|
2007-09-02 16:36:52 +00:00
|
|
|
{
|
|
|
|
|
QTreeWidgetItemIterator it(treeWidget_GameList);
|
|
|
|
|
while (*it) {
|
|
|
|
|
if ((*it)->data(0, Qt::UserRole) == gameId)
|
|
|
|
|
{
|
|
|
|
|
treeWidget_GameList->takeTopLevelItem(treeWidget_GameList->indexOfTopLevelItem(*it));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::gameAddPlayer(unsigned gameId, unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *item = treeWidget_GameList->currentItem();
|
|
|
|
|
if (item && item->data(0, Qt::UserRole) == gameId)
|
|
|
|
|
{
|
|
|
|
|
assert(mySession);
|
|
|
|
|
PlayerInfo info(mySession->getClientPlayerInfo(playerId));
|
|
|
|
|
addConnectedPlayer(playerId, QString::fromUtf8(info.playerName.c_str()), PLAYER_RIGHTS_NORMAL);
|
|
|
|
|
}
|
2007-09-04 12:44:11 +00:00
|
|
|
|
|
|
|
|
QTreeWidgetItemIterator it(treeWidget_GameList);
|
|
|
|
|
while (*it) {
|
|
|
|
|
if ((*it)->data(0, Qt::UserRole) == gameId)
|
|
|
|
|
{
|
|
|
|
|
updateGameItem(*it, gameId);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++it;
|
|
|
|
|
}
|
2007-09-02 16:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::gameRemovePlayer(unsigned gameId, unsigned playerId)
|
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *item = treeWidget_GameList->currentItem();
|
|
|
|
|
if (item && item->data(0, Qt::UserRole) == gameId)
|
|
|
|
|
{
|
|
|
|
|
assert(mySession);
|
|
|
|
|
PlayerInfo info(mySession->getClientPlayerInfo(playerId));
|
|
|
|
|
removePlayer(playerId, QString::fromUtf8(info.playerName.c_str()));
|
|
|
|
|
}
|
2007-09-04 12:44:11 +00:00
|
|
|
|
|
|
|
|
QTreeWidgetItemIterator it(treeWidget_GameList);
|
|
|
|
|
while (*it) {
|
|
|
|
|
if ((*it)->data(0, Qt::UserRole) == gameId)
|
|
|
|
|
{
|
|
|
|
|
updateGameItem(*it, gameId);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++it;
|
|
|
|
|
}
|
2007-09-02 16:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::clearDialog()
|
2007-08-27 09:57:51 +00:00
|
|
|
{
|
|
|
|
|
groupBox_GameInfo->setTitle(tr("Game Info"));
|
|
|
|
|
groupBox_GameInfo->setEnabled(false);
|
|
|
|
|
currentGameName = "";
|
|
|
|
|
|
|
|
|
|
label_SmallBlind->setText("");
|
|
|
|
|
label_StartCash->setText("");
|
|
|
|
|
label_MaximumNumberOfPlayers->setText("");
|
|
|
|
|
label_HandsToRaiseSmallBlind->setText("");
|
|
|
|
|
label_TimeoutForPlayerAction->setText("");
|
2007-09-02 16:36:52 +00:00
|
|
|
|
|
|
|
|
treeWidget_GameList->clear();
|
|
|
|
|
treeWidget_connectedPlayers->clear();
|
|
|
|
|
|
|
|
|
|
pushButton_JoinGame->setEnabled(false);
|
|
|
|
|
pushButton_Leave->hide();
|
|
|
|
|
pushButton_Kick->hide();
|
|
|
|
|
pushButton_StartGame->hide();
|
2007-09-03 22:51:00 +00:00
|
|
|
checkBox_fillUpWithComputerOpponents->hide();
|
2007-09-02 16:36:52 +00:00
|
|
|
|
|
|
|
|
treeWidget_GameList->setColumnWidth(0,250);
|
|
|
|
|
treeWidget_GameList->setColumnWidth(1,75);
|
|
|
|
|
treeWidget_GameList->setColumnWidth(2,70);
|
|
|
|
|
|
|
|
|
|
lineEdit_ChatInput->setFocus();
|
2007-08-27 09:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-29 22:30:18 +00:00
|
|
|
void gameLobbyDialogImpl::checkPlayerQuantity() {
|
|
|
|
|
|
|
|
|
|
// if (treeWidget->topLevelItemCount() >= 2 && isAdmin) {
|
|
|
|
|
// pushButton_startGame->setEnabled(true);
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// pushButton_startGame->setEnabled(false);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-02 16:36:52 +00:00
|
|
|
void gameLobbyDialogImpl::joinedNetworkGame(unsigned playerId, QString playerName, int rights) {
|
2007-08-29 22:30:18 +00:00
|
|
|
|
|
|
|
|
isAdmin = rights == PLAYER_RIGHTS_ADMIN;
|
2007-09-02 16:36:52 +00:00
|
|
|
addConnectedPlayer(playerId, playerName, rights);
|
2007-08-29 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-02 16:36:52 +00:00
|
|
|
void gameLobbyDialogImpl::addConnectedPlayer(unsigned playerId, QString playerName, int rights) {
|
2007-08-29 22:30:18 +00:00
|
|
|
|
2007-09-02 16:36:52 +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
|
|
|
|
2007-09-02 16:36:52 +00:00
|
|
|
/* assert(mySession);
|
2007-08-29 22:30:18 +00:00
|
|
|
GameInfo info = mySession->getClientGameInfo(currentGameName.toUtf8().constData());
|
|
|
|
|
|
|
|
|
|
if(treeWidget_connectedPlayers->topLevelItemCount() != info.data.maxNumberOfPlayers) {
|
|
|
|
|
myW->getMySDLPlayer()->playSound("playerconnected", 0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
myW->getMySDLPlayer()->playSound("onlinegameready", 0);
|
2007-09-02 16:36:52 +00:00
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
checkPlayerQuantity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::updatePlayer(unsigned playerId, QString newPlayerName) {
|
|
|
|
|
|
|
|
|
|
QTreeWidgetItemIterator it(treeWidget_connectedPlayers);
|
|
|
|
|
while (*it) {
|
|
|
|
|
if ((*it)->data(0, Qt::UserRole) == playerId)
|
|
|
|
|
{
|
|
|
|
|
(*it)->setData(0, Qt::DisplayRole, newPlayerName);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::removePlayer(unsigned playerId, QString) {
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkPlayerQuantity();
|
|
|
|
|
}
|
|
|
|
|
|