2007-02-22 00:48:18 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* Copyright (C) 2006 by FThauer FHammer *
|
|
|
|
|
* f.thauer@web.de *
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
#include "startnetworkgamedialogimpl.h"
|
2007-06-05 21:56:33 +00:00
|
|
|
// #include "session.h"
|
|
|
|
|
#include "configfile.h"
|
2007-02-22 00:48:18 +00:00
|
|
|
|
2007-06-05 21:56:33 +00:00
|
|
|
startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFile *config)
|
|
|
|
|
: QDialog(parent), myConfig(config)
|
2007-02-22 00:48:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
|
|
connect( pushButton_cancel, SIGNAL( clicked() ), this, SLOT( cancel() ) );
|
|
|
|
|
connect( pushButton_startGame, SIGNAL( clicked() ), this, SLOT( startGame() ) );
|
2007-06-05 20:54:16 +00:00
|
|
|
connect( pushButton_Kick, SIGNAL( clicked() ), this, SLOT( kickPlayer() ) );
|
|
|
|
|
connect( treeWidget, SIGNAL( itemClicked ( QTreeWidgetItem*, int) ), this, SLOT( playerSelected(QTreeWidgetItem*, int) ) );
|
2007-06-05 21:26:40 +00:00
|
|
|
|
|
|
|
|
pushButton_Kick->setEnabled(FALSE);
|
2007-02-22 00:48:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startNetworkGameDialogImpl::startGame() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startNetworkGameDialogImpl::cancel() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-08 20:35:42 +00:00
|
|
|
void startNetworkGameDialogImpl::addConnectedPlayer(QString playerName) {
|
2007-03-22 01:24:01 +00:00
|
|
|
|
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget,0);
|
2007-04-08 20:35:42 +00:00
|
|
|
item->setData(0, 0, playerName);
|
2007-05-23 07:16:28 +00:00
|
|
|
|
|
|
|
|
checkPlayerQuantity();
|
2007-03-22 01:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-02 22:46:29 +00:00
|
|
|
void startNetworkGameDialogImpl::removePlayer(QString playerName) {
|
|
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem *> list = treeWidget->findItems(playerName, Qt::MatchExactly, 0);
|
|
|
|
|
if(!list.empty()) {
|
|
|
|
|
treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(list[0]));
|
|
|
|
|
}
|
2007-05-23 07:16:28 +00:00
|
|
|
|
|
|
|
|
checkPlayerQuantity();
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-05 20:54:16 +00:00
|
|
|
void startNetworkGameDialogImpl::playerSelected(QTreeWidgetItem*, int) {
|
|
|
|
|
|
|
|
|
|
pushButton_Kick->setEnabled(TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startNetworkGameDialogImpl::kickPlayer() {
|
|
|
|
|
|
2007-06-05 21:56:33 +00:00
|
|
|
|
2007-06-05 20:54:16 +00:00
|
|
|
QTreeWidgetItem *item = treeWidget->currentItem();
|
|
|
|
|
QString playerName = item->text(0);
|
2007-06-05 21:56:33 +00:00
|
|
|
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 {
|
|
|
|
|
// kickplayerFunktion(playerName.toStdString());
|
|
|
|
|
}
|
2007-06-05 20:54:16 +00:00
|
|
|
pushButton_Kick->setEnabled(FALSE);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-23 07:16:28 +00:00
|
|
|
void startNetworkGameDialogImpl::checkPlayerQuantity() {
|
|
|
|
|
|
|
|
|
|
if(treeWidget->topLevelItemCount() == maxPlayerNumber) pushButton_startGame->setEnabled(TRUE);
|
|
|
|
|
else pushButton_startGame->setDisabled(TRUE);
|
|
|
|
|
|
2007-05-02 22:46:29 +00:00
|
|
|
}
|
|
|
|
|
|
2007-02-22 00:48:18 +00:00
|
|
|
void startNetworkGameDialogImpl::keyPressEvent ( QKeyEvent * event ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (event->key() == 16777220) { pushButton_startGame->click(); } //ENTER
|
|
|
|
|
|
|
|
|
|
}
|