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)
|
|
|
|
|
: QDialog(parent), myConfig(c)
|
|
|
|
|
{
|
|
|
|
|
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) ) );
|
|
|
|
|
|
|
|
|
|
pushButton_JoinGame->setEnabled(false);
|
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);
|
|
|
|
|
|
|
|
|
|
// TODO: don't use hardcoded values
|
|
|
|
|
GameData gameData;
|
|
|
|
|
// Set Game Data
|
|
|
|
|
gameData.maxNumberOfPlayers = myConfig->readConfigInt("NumberOfPlayers");
|
|
|
|
|
gameData.startMoney = myConfig->readConfigInt("StartCash");
|
|
|
|
|
gameData.smallBlind = myConfig->readConfigInt("SmallBlind");
|
|
|
|
|
gameData.handsBeforeRaise = myConfig->readConfigInt("HandsBeforeRaiseSmallBlind");
|
|
|
|
|
//Speeds
|
|
|
|
|
gameData.guiSpeed = myConfig->readConfigInt("GameSpeed");
|
|
|
|
|
|
2007-08-21 17:27:13 +00:00
|
|
|
mySession->clientCreateGame(gameData, myConfig->readConfigString("MyName") + "'s game", "");
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameLobbyDialogImpl::gameSelected(QTreeWidgetItem*, int)
|
|
|
|
|
{
|
|
|
|
|
pushButton_JoinGame->setEnabled(true);
|
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
|
|
|
|