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-08-21 17:27:13 +00:00
|
|
|
connect( treeWidget_GameList, SIGNAL( itemClicked ( QTreeWidgetItem*, int) ), this, SLOT( gameSelected(QTreeWidgetItem*, int) ) );
|
2007-08-27 09:57:51 +00:00
|
|
|
connect( treeWidget_GameList, SIGNAL( clear () ), this, SLOT( clearGames() ) );
|
2007-08-21 17:27:13 +00:00
|
|
|
|
|
|
|
|
pushButton_JoinGame->setEnabled(false);
|
2007-08-26 12:45:37 +00:00
|
|
|
|
|
|
|
|
pushButton_Leave->hide();
|
|
|
|
|
pushButton_Kick->hide();
|
|
|
|
|
pushButton_StartGame->hide();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
treeWidget_GameList->setColumnWidth(0,250);
|
|
|
|
|
treeWidget_GameList->setColumnWidth(1,75);
|
|
|
|
|
treeWidget_GameList->setColumnWidth(2,70);
|
2007-08-29 19:27:12 +00:00
|
|
|
|
|
|
|
|
lineEdit_ChatInput->setFocus();
|
2007-08-26 12:45:37 +00:00
|
|
|
|
2007-08-20 21:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::exec()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
mySession->clientCreateGame(gameData, myConfig->readConfigString("MyName") + "'s game", "");
|
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-08-22 20:03:19 +00:00
|
|
|
void gameLobbyDialogImpl::gameSelected(QTreeWidgetItem* item, int)
|
2007-08-21 17:27:13 +00:00
|
|
|
{
|
|
|
|
|
pushButton_JoinGame->setEnabled(true);
|
2007-08-22 20:03:19 +00:00
|
|
|
|
|
|
|
|
currentGameName = item->text(0);
|
2007-08-26 12:45:37 +00:00
|
|
|
|
2007-08-27 09:57:51 +00:00
|
|
|
groupBox_GameInfo->setEnabled(true);
|
|
|
|
|
groupBox_GameInfo->setTitle(tr("Game Info") + " - " + currentGameName);
|
|
|
|
|
|
|
|
|
|
assert(mySession);
|
|
|
|
|
GameInfo info = mySession->getClientGameInfo(currentGameName.toUtf8().constData());
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::addGame(QString gameName)
|
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_GameList,0);
|
|
|
|
|
item->setData(0, 0, gameName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::removeGame(QString gameName)
|
|
|
|
|
{
|
|
|
|
|
QList<QTreeWidgetItem *> list = treeWidget_GameList->findItems(gameName, Qt::MatchExactly, 0);
|
|
|
|
|
if(!list.empty()) {
|
|
|
|
|
treeWidget_GameList->takeTopLevelItem(treeWidget_GameList->indexOfTopLevelItem(list[0]));
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-20 21:23:03 +00:00
|
|
|
|
2007-08-27 09:57:51 +00:00
|
|
|
void gameLobbyDialogImpl::clearGames()
|
|
|
|
|
{
|
|
|
|
|
pushButton_JoinGame->setEnabled(false);
|
|
|
|
|
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-08-29 22:30:18 +00:00
|
|
|
void gameLobbyDialogImpl::checkPlayerQuantity() {
|
|
|
|
|
|
|
|
|
|
// if (treeWidget->topLevelItemCount() >= 2 && isAdmin) {
|
|
|
|
|
// pushButton_startGame->setEnabled(true);
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// pushButton_startGame->setEnabled(false);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::joinedNetworkGame(QString playerName, int rights) {
|
|
|
|
|
|
|
|
|
|
isAdmin = rights == PLAYER_RIGHTS_ADMIN;
|
|
|
|
|
addConnectedPlayer(playerName, rights);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::addConnectedPlayer(QString playerName, int rights) {
|
|
|
|
|
|
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_connectedPlayers,0);
|
|
|
|
|
item->setData(0, 0, playerName);
|
|
|
|
|
|
2007-09-01 21:15:11 +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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkPlayerQuantity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::updatePlayer(QString oldPlayerName, QString newPlayerName) {
|
|
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem *> list = treeWidget_connectedPlayers->findItems(oldPlayerName, Qt::MatchExactly, 0);
|
|
|
|
|
if(!list.empty()) {
|
|
|
|
|
list[0]->setText(0, newPlayerName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::removePlayer(QString playerName) {
|
|
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem *> list = treeWidget_connectedPlayers->findItems(playerName, Qt::MatchExactly, 0);
|
|
|
|
|
if(!list.empty()) {
|
|
|
|
|
treeWidget_connectedPlayers->takeTopLevelItem(treeWidget_connectedPlayers->indexOfTopLevelItem(list[0]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|