Major redesign: Using game ids and player ids in gui (associated with tree view items).
Player list of all network games is now dynamically updated in lobby (no polling, server sends events).
This commit is contained in:
@@ -108,18 +108,18 @@ void ServerGuiWrapper::logPlayerWinGame(std::string playerName, int gameID) {}
|
||||
void ServerGuiWrapper::SignalNetClientConnect(int actionID) { if (myClientcb) myClientcb->SignalNetClientConnect(actionID); }
|
||||
void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) myClientcb->SignalNetClientGameInfo(actionID); }
|
||||
void ServerGuiWrapper::SignalNetClientError(int errorID, int osErrorID) { if (myClientcb) myClientcb->SignalNetClientError(errorID, osErrorID); }
|
||||
void ServerGuiWrapper::SignalNetClientSelfJoined(const string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientSelfJoined(playerName, rights); }
|
||||
void ServerGuiWrapper::SignalNetClientPlayerJoined(const string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(playerName, rights); }
|
||||
void ServerGuiWrapper::SignalNetClientPlayerChanged(const std::string &oldPlayerName, const std::string &newPlayerName) { if (myClientcb) myClientcb->SignalNetClientPlayerChanged(oldPlayerName, newPlayerName); }
|
||||
void ServerGuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerLeft(playerName); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListNew(const string &gameName) { if (myClientcb) myClientcb->SignalNetClientGameListNew(gameName); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListRemove(const string &gameName) { if (myClientcb) myClientcb->SignalNetClientGameListRemove(gameName); }
|
||||
void ServerGuiWrapper::SignalNetClientSelfJoined(unsigned playerId, const std::string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientSelfJoined(playerId, playerName, rights); }
|
||||
void ServerGuiWrapper::SignalNetClientPlayerJoined(unsigned playerId, const std::string &playerName, PlayerRights rights) { if (myClientcb) myClientcb->SignalNetClientPlayerJoined(playerId, playerName, rights); }
|
||||
void ServerGuiWrapper::SignalNetClientPlayerChanged(unsigned playerId, const std::string &newPlayerName) { if (myClientcb) myClientcb->SignalNetClientPlayerChanged(playerId, newPlayerName); }
|
||||
void ServerGuiWrapper::SignalNetClientPlayerLeft(unsigned playerId, const std::string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerLeft(playerId, playerName); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListNew(unsigned gameId, const string &gameName) { if (myClientcb) myClientcb->SignalNetClientGameListNew(gameId, gameName); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListRemove(unsigned gameId, const string &gameName) { if (myClientcb) myClientcb->SignalNetClientGameListRemove(gameId, gameName); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId) { if (myClientcb) myClientcb->SignalNetClientGameListPlayerJoined(gameId, playerId); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId) { if (myClientcb) myClientcb->SignalNetClientGameListPlayerLeft(gameId, playerId); }
|
||||
void ServerGuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); }
|
||||
void ServerGuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { if (myClientcb) myClientcb->SignalNetClientChatMsg(playerName, msg); }
|
||||
void ServerGuiWrapper::SignalNetClientWaitDialog() { if (myClientcb) myClientcb->SignalNetClientWaitDialog(); }
|
||||
|
||||
void ServerGuiWrapper::SignalNetServerSuccess(int actionID) { if (myServercb) myServercb->SignalNetServerSuccess(actionID); }
|
||||
void ServerGuiWrapper::SignalNetServerError(int errorID, int osErrorID) { if (myServercb) myServercb->SignalNetServerError(errorID, osErrorID); }
|
||||
void ServerGuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerJoined(playerName); }
|
||||
void ServerGuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { if (myServercb) myServercb->SignalNetServerPlayerLeft(playerName); }
|
||||
|
||||
|
||||
@@ -92,21 +92,21 @@ public:
|
||||
void SignalNetClientConnect(int actionID);
|
||||
void SignalNetClientGameInfo(int actionID);
|
||||
void SignalNetClientError(int errorID, int osErrorID);
|
||||
void SignalNetClientSelfJoined(const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerJoined(const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerChanged(const std::string &oldPlayerName, const std::string &newPlayerName);
|
||||
void SignalNetClientPlayerLeft(const std::string &playerName);
|
||||
void SignalNetClientSelfJoined(unsigned playerId, const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerJoined(unsigned playerId, const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerChanged(unsigned playerId, const std::string &newPlayerName);
|
||||
void SignalNetClientPlayerLeft(unsigned playerId, const std::string &playerName);
|
||||
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
|
||||
void SignalNetClientWaitDialog();
|
||||
|
||||
void SignalNetClientGameListNew(const std::string &gameName);
|
||||
void SignalNetClientGameListRemove(const std::string &gameName);
|
||||
void SignalNetClientGameListNew(unsigned gameId, const std::string &gameName);
|
||||
void SignalNetClientGameListRemove(unsigned gameId, const std::string &gameName);
|
||||
void SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId);
|
||||
void SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId);
|
||||
void SignalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||
|
||||
void SignalNetServerSuccess(int actionID);
|
||||
void SignalNetServerError(int errorID, int osErrorID);
|
||||
void SignalNetServerPlayerJoined(const std::string &playerName);
|
||||
void SignalNetServerPlayerLeft(const std::string &playerName);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -21,26 +21,12 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(QWidget *parent, ConfigFile *c)
|
||||
|
||||
connect( pushButton_CreateGame, SIGNAL( clicked() ), this, SLOT( createGame() ) );
|
||||
connect( pushButton_JoinGame, SIGNAL( clicked() ), this, SLOT( joinGame() ) );
|
||||
connect( treeWidget_GameList, SIGNAL( itemClicked ( QTreeWidgetItem*, int) ), this, SLOT( gameSelected(QTreeWidgetItem*, int) ) );
|
||||
connect( treeWidget_GameList, SIGNAL( clear () ), this, SLOT( clearGames() ) );
|
||||
|
||||
pushButton_JoinGame->setEnabled(false);
|
||||
|
||||
pushButton_Leave->hide();
|
||||
pushButton_Kick->hide();
|
||||
pushButton_StartGame->hide();
|
||||
|
||||
|
||||
treeWidget_GameList->setColumnWidth(0,250);
|
||||
treeWidget_GameList->setColumnWidth(1,75);
|
||||
treeWidget_GameList->setColumnWidth(2,70);
|
||||
|
||||
lineEdit_ChatInput->setFocus();
|
||||
|
||||
connect( treeWidget_GameList, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*) ), this, SLOT( gameSelected(QTreeWidgetItem*, QTreeWidgetItem*) ) );
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::exec()
|
||||
{
|
||||
clearDialog();
|
||||
|
||||
QDialog::exec();
|
||||
}
|
||||
@@ -95,41 +81,82 @@ void gameLobbyDialogImpl::joinGame()
|
||||
}
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::gameSelected(QTreeWidgetItem* item, int)
|
||||
void gameLobbyDialogImpl::gameSelected(QTreeWidgetItem* item, QTreeWidgetItem*)
|
||||
{
|
||||
pushButton_JoinGame->setEnabled(true);
|
||||
if (item)
|
||||
{
|
||||
pushButton_JoinGame->setEnabled(true);
|
||||
|
||||
currentGameName = item->text(0);
|
||||
currentGameName = item->text(0);
|
||||
|
||||
groupBox_GameInfo->setEnabled(true);
|
||||
groupBox_GameInfo->setTitle(tr("Game Info") + " - " + currentGameName);
|
||||
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));
|
||||
}
|
||||
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));
|
||||
|
||||
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]));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::clearGames()
|
||||
void gameLobbyDialogImpl::addGame(unsigned gameId, QString gameName)
|
||||
{
|
||||
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_GameList, 0);
|
||||
item->setData(0, Qt::UserRole, gameId);
|
||||
item->setData(0, Qt::DisplayRole, gameName);
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::removeGame(unsigned gameId, QString)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::clearDialog()
|
||||
{
|
||||
pushButton_JoinGame->setEnabled(false);
|
||||
groupBox_GameInfo->setTitle(tr("Game Info"));
|
||||
groupBox_GameInfo->setEnabled(false);
|
||||
currentGameName = "";
|
||||
@@ -139,6 +166,20 @@ void gameLobbyDialogImpl::clearGames()
|
||||
label_MaximumNumberOfPlayers->setText("");
|
||||
label_HandsToRaiseSmallBlind->setText("");
|
||||
label_TimeoutForPlayerAction->setText("");
|
||||
|
||||
treeWidget_GameList->clear();
|
||||
treeWidget_connectedPlayers->clear();
|
||||
|
||||
pushButton_JoinGame->setEnabled(false);
|
||||
pushButton_Leave->hide();
|
||||
pushButton_Kick->hide();
|
||||
pushButton_StartGame->hide();
|
||||
|
||||
treeWidget_GameList->setColumnWidth(0,250);
|
||||
treeWidget_GameList->setColumnWidth(1,75);
|
||||
treeWidget_GameList->setColumnWidth(2,70);
|
||||
|
||||
lineEdit_ChatInput->setFocus();
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::checkPlayerQuantity() {
|
||||
@@ -152,19 +193,20 @@ void gameLobbyDialogImpl::checkPlayerQuantity() {
|
||||
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::joinedNetworkGame(QString playerName, int rights) {
|
||||
void gameLobbyDialogImpl::joinedNetworkGame(unsigned playerId, QString playerName, int rights) {
|
||||
|
||||
isAdmin = rights == PLAYER_RIGHTS_ADMIN;
|
||||
addConnectedPlayer(playerName, rights);
|
||||
addConnectedPlayer(playerId, playerName, rights);
|
||||
}
|
||||
|
||||
|
||||
void gameLobbyDialogImpl::addConnectedPlayer(QString playerName, int rights) {
|
||||
void gameLobbyDialogImpl::addConnectedPlayer(unsigned playerId, QString playerName, int rights) {
|
||||
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_connectedPlayers,0);
|
||||
item->setData(0, 0, playerName);
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_connectedPlayers, 0);
|
||||
item->setData(0, Qt::UserRole, playerId);
|
||||
item->setData(0, Qt::DisplayRole, playerName);
|
||||
|
||||
assert(mySession);
|
||||
/* assert(mySession);
|
||||
GameInfo info = mySession->getClientGameInfo(currentGameName.toUtf8().constData());
|
||||
|
||||
if(treeWidget_connectedPlayers->topLevelItemCount() != info.data.maxNumberOfPlayers) {
|
||||
@@ -172,25 +214,36 @@ void gameLobbyDialogImpl::addConnectedPlayer(QString playerName, int rights) {
|
||||
}
|
||||
else {
|
||||
myW->getMySDLPlayer()->playSound("onlinegameready", 0);
|
||||
}*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,21 +45,24 @@ public slots:
|
||||
void createGame();
|
||||
void joinGame();
|
||||
|
||||
void gameSelected(QTreeWidgetItem*, int);
|
||||
void gameSelected(QTreeWidgetItem*, QTreeWidgetItem*);
|
||||
|
||||
void addGame(QString gameName);
|
||||
void removeGame(QString gameName);
|
||||
void addGame(unsigned gameId, QString gameName);
|
||||
void removeGame(unsigned gameId, QString gameName);
|
||||
void gameAddPlayer(unsigned gameId, unsigned playerId);
|
||||
void gameRemovePlayer(unsigned gameId, unsigned playerId);
|
||||
|
||||
void setCurrentGameName ( const QString& theValue ) { currentGameName = theValue; }
|
||||
QString getCurrentGameName() const { return currentGameName; }
|
||||
|
||||
void clearGames();
|
||||
void checkPlayerQuantity();
|
||||
|
||||
void joinedNetworkGame(QString, int);
|
||||
void addConnectedPlayer(QString, int);
|
||||
void updatePlayer(QString, QString);
|
||||
void removePlayer(QString);
|
||||
void joinedNetworkGame(unsigned, QString, int);
|
||||
void addConnectedPlayer(unsigned, QString, int);
|
||||
void updatePlayer(unsigned, QString);
|
||||
void removePlayer(unsigned, QString);
|
||||
|
||||
void clearDialog();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
+10
-10
@@ -111,22 +111,24 @@ void GuiWrapper::logPlayerWinGame(std::string playerName, int gameID) { myLog->s
|
||||
void GuiWrapper::SignalNetClientConnect(int actionID) { myW->signalNetClientConnect(actionID); }
|
||||
void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->signalNetClientGameInfo(actionID); }
|
||||
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->signalNetClientError(errorID, osErrorID); }
|
||||
void GuiWrapper::SignalNetClientSelfJoined(const string &playerName, PlayerRights rights) { myW->signalNetClientSelfJoined(QString::fromUtf8(playerName.c_str()), rights); }
|
||||
void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName, PlayerRights rights) { myW->signalNetClientPlayerJoined(QString::fromUtf8(playerName.c_str()), rights); }
|
||||
void GuiWrapper::SignalNetClientPlayerChanged(const string &oldPlayerName, const string &newPlayerName)
|
||||
void GuiWrapper::SignalNetClientSelfJoined(unsigned playerId, const string &playerName, PlayerRights rights) { myW->signalNetClientSelfJoined(playerId, QString::fromUtf8(playerName.c_str()), rights); }
|
||||
void GuiWrapper::SignalNetClientPlayerJoined(unsigned playerId, const string &playerName, PlayerRights rights) { myW->signalNetClientPlayerJoined(playerId, QString::fromUtf8(playerName.c_str()), rights); }
|
||||
void GuiWrapper::SignalNetClientPlayerChanged(unsigned playerId, const string &newPlayerName)
|
||||
{
|
||||
myW->signalNetClientPlayerChanged(QString::fromUtf8(oldPlayerName.c_str()), QString::fromUtf8(newPlayerName.c_str()));
|
||||
myW->signalNetClientPlayerChanged(playerId, QString::fromUtf8(newPlayerName.c_str()));
|
||||
}
|
||||
void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName)
|
||||
void GuiWrapper::SignalNetClientPlayerLeft(unsigned playerId, const string &playerName)
|
||||
{
|
||||
QString tmpName(QString::fromUtf8(playerName.c_str()));
|
||||
myW->signalNetClientPlayerLeft(tmpName);
|
||||
myW->signalNetClientPlayerLeft(playerId, tmpName);
|
||||
if (!playerName.empty() && playerName[0] != '#')
|
||||
myLog->signalLogPlayerLeftMsg(tmpName);
|
||||
}
|
||||
|
||||
void GuiWrapper::SignalNetClientGameListNew(const string &gameName) { myW->signalNetClientGameListNew(QString::fromUtf8(gameName.c_str())); }
|
||||
void GuiWrapper::SignalNetClientGameListRemove(const string &gameName) { myW->signalNetClientGameListRemove(QString::fromUtf8(gameName.c_str())); }
|
||||
void GuiWrapper::SignalNetClientGameListNew(unsigned gameId, const string &gameName) { myW->signalNetClientGameListNew(gameId, QString::fromUtf8(gameName.c_str())); }
|
||||
void GuiWrapper::SignalNetClientGameListRemove(unsigned gameId, const string &gameName) { myW->signalNetClientGameListRemove(gameId, QString::fromUtf8(gameName.c_str())); }
|
||||
void GuiWrapper::SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId) { myW->signalNetClientGameListPlayerJoined(gameId, playerId); }
|
||||
void GuiWrapper::SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId) { myW->signalNetClientGameListPlayerLeft(gameId, playerId); }
|
||||
|
||||
void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { myW->signalNetClientGameStart(game); }
|
||||
void GuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { myChat->signalChatMessage(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); }
|
||||
@@ -134,6 +136,4 @@ void GuiWrapper::SignalNetClientWaitDialog() { myW->signalShowNetworkStartDialog
|
||||
|
||||
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
||||
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { myW->signalNetServerError(errorID, osErrorID); }
|
||||
void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { }
|
||||
void GuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { }
|
||||
|
||||
|
||||
@@ -99,22 +99,22 @@ public:
|
||||
void SignalNetClientConnect(int actionID);
|
||||
void SignalNetClientGameInfo(int actionID);
|
||||
void SignalNetClientError(int errorID, int osErrorID);
|
||||
void SignalNetClientSelfJoined(const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerJoined(const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerChanged(const std::string &oldPlayerName, const std::string &newPlayerName);
|
||||
void SignalNetClientPlayerLeft(const std::string &playerName);
|
||||
void SignalNetClientSelfJoined(unsigned playerId, const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerJoined(unsigned playerId, const std::string &playerName, PlayerRights rights);
|
||||
void SignalNetClientPlayerChanged(unsigned playerId, const std::string &newPlayerName);
|
||||
void SignalNetClientPlayerLeft(unsigned playerId, const std::string &playerName);
|
||||
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
|
||||
void SignalNetClientWaitDialog();
|
||||
|
||||
void SignalNetClientGameListNew(const std::string &gameName);
|
||||
void SignalNetClientGameListRemove(const std::string &gameName);
|
||||
void SignalNetClientGameListNew(unsigned gameId, const std::string &gameName);
|
||||
void SignalNetClientGameListRemove(unsigned gameId, const std::string &gameName);
|
||||
void SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId);
|
||||
void SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId);
|
||||
|
||||
void SignalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||
|
||||
void SignalNetServerSuccess(int actionID);
|
||||
void SignalNetServerError(int errorID, int osErrorID);
|
||||
void SignalNetServerPlayerJoined(const std::string &playerName);
|
||||
void SignalNetServerPlayerLeft(const std::string &playerName);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -670,17 +670,21 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
|
||||
|
||||
connect(this, SIGNAL(signalNetClientConnect(int)), myConnectToServerDialog, SLOT(refresh(int)));
|
||||
connect(this, SIGNAL(signalNetClientGameInfo(int)), myStartNetworkGameDialog, SLOT(refresh(int)));
|
||||
connect(this, SIGNAL(signalNetClientSelfJoined(QString, int)), myStartNetworkGameDialog, SLOT(joinedNetworkGame(QString, int)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerJoined(QString, int)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString, int)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerChanged(QString, QString)), myStartNetworkGameDialog, SLOT(updatePlayer(QString, QString)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerLeft(QString)), myStartNetworkGameDialog, SLOT(removePlayer(QString)));
|
||||
|
||||
connect(this, SIGNAL(signalNetClientSelfJoined(QString, int)), myGameLobbyDialog, SLOT(joinedNetworkGame(QString, int)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerJoined(QString, int)), myGameLobbyDialog, SLOT(addConnectedPlayer(QString, int)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerChanged(QString, QString)), myGameLobbyDialog, SLOT(updatePlayer(QString, QString)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerLeft(QString)), myGameLobbyDialog, SLOT(removePlayer(QString)));
|
||||
connect(this, SIGNAL(signalNetClientGameListNew(QString)), myGameLobbyDialog, SLOT(addGame(QString)));
|
||||
connect(this, SIGNAL(signalNetClientGameListRemove(QString)), myGameLobbyDialog, SLOT(removeGame(QString)));
|
||||
connect(this, SIGNAL(signalNetClientSelfJoined(unsigned, QString, int)), myStartNetworkGameDialog, SLOT(joinedNetworkGame(unsigned, QString, int)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerJoined(unsigned, QString, int)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(unsigned, QString, int)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerChanged(unsigned, QString)), myStartNetworkGameDialog, SLOT(updatePlayer(unsigned, QString)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerLeft(unsigned, QString)), myStartNetworkGameDialog, SLOT(removePlayer(unsigned, QString)));
|
||||
|
||||
connect(this, SIGNAL(signalNetClientSelfJoined(unsigned, QString, int)), myGameLobbyDialog, SLOT(joinedNetworkGame(unsigned, QString, int)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerJoined(unsigned, QString, int)), myGameLobbyDialog, SLOT(addConnectedPlayer(unsigned, QString, int)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerChanged(unsigned, QString)), myGameLobbyDialog, SLOT(updatePlayer(unsigned, QString)));
|
||||
connect(this, SIGNAL(signalNetClientPlayerLeft(unsigned, QString)), myGameLobbyDialog, SLOT(removePlayer(unsigned, QString)));
|
||||
|
||||
connect(this, SIGNAL(signalNetClientGameListNew(unsigned, QString)), myGameLobbyDialog, SLOT(addGame(unsigned, QString)));
|
||||
connect(this, SIGNAL(signalNetClientGameListRemove(unsigned, QString)), myGameLobbyDialog, SLOT(removeGame(unsigned, QString)));
|
||||
connect(this, SIGNAL(signalNetClientGameListPlayerJoined(unsigned, unsigned)), myGameLobbyDialog, SLOT(gameAddPlayer(unsigned, unsigned)));
|
||||
connect(this, SIGNAL(signalNetClientGameListPlayerLeft(unsigned, unsigned)), myGameLobbyDialog, SLOT(gameRemovePlayer(unsigned, unsigned)));
|
||||
|
||||
// Errors are handled globally, not within one dialog.
|
||||
connect(this, SIGNAL(signalNetClientError(int, int)), this, SLOT(networkError(int, int)));
|
||||
@@ -789,9 +793,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() {
|
||||
gameData.playerActionTimeoutSec = myCreateNetworkGameDialog->spinBox_netTimeOutPlayerAction->value();
|
||||
|
||||
myGameLobbyDialog->setSession(&getSession());
|
||||
myGameLobbyDialog->treeWidget_GameList->clear();
|
||||
myStartNetworkGameDialog->setSession(&getSession());
|
||||
myStartNetworkGameDialog->treeWidget->clear();
|
||||
|
||||
myServerGuiInterface->getSession().startNetworkServer();
|
||||
mySession->startNetworkClientForLocalServer(gameData);
|
||||
@@ -816,9 +818,7 @@ void mainWindowImpl::callJoinNetworkGameDialog() {
|
||||
myServerGuiInterface->getSession().terminateNetworkServer();
|
||||
|
||||
myGameLobbyDialog->setSession(&getSession());
|
||||
myGameLobbyDialog->treeWidget_GameList->clear();
|
||||
myStartNetworkGameDialog->setSession(&getSession());
|
||||
myStartNetworkGameDialog->treeWidget->clear();
|
||||
// Maybe use QUrl::toPunycode.
|
||||
mySession->startNetworkClient(
|
||||
myJoinNetworkGameDialog->lineEdit_ipAddress->text().toUtf8().constData(),
|
||||
@@ -851,8 +851,6 @@ void mainWindowImpl::callGameLobbyDialog() {
|
||||
myServerGuiInterface->getSession().terminateNetworkServer();
|
||||
|
||||
myGameLobbyDialog->setSession(&getSession());
|
||||
myGameLobbyDialog->treeWidget_GameList->clear();
|
||||
myStartNetworkGameDialog->treeWidget->clear();
|
||||
myStartNetworkGameDialog->setSession(&getSession());
|
||||
|
||||
// Start client for dedicated server.
|
||||
|
||||
@@ -127,12 +127,14 @@ signals:
|
||||
void signalNetClientGameInfo(int actionID);
|
||||
void signalNetClientError(int errorID, int osErrorID);
|
||||
void signalNetServerError(int errorID, int osErrorID);
|
||||
void signalNetClientSelfJoined(QString playerName, int rights);
|
||||
void signalNetClientPlayerJoined(QString playerName, int rights);
|
||||
void signalNetClientPlayerChanged(QString oldPlayerName, QString newPlayerName);
|
||||
void signalNetClientPlayerLeft(QString playerName);
|
||||
void signalNetClientGameListNew(QString gameName);
|
||||
void signalNetClientGameListRemove(QString gameName);
|
||||
void signalNetClientSelfJoined(unsigned playerId, QString playerName, int rights);
|
||||
void signalNetClientPlayerJoined(unsigned playerId, QString playerName, int rights);
|
||||
void signalNetClientPlayerChanged(unsigned playerId, QString newPlayerName);
|
||||
void signalNetClientPlayerLeft(unsigned playerId, QString playerName);
|
||||
void signalNetClientGameListNew(unsigned gameId, QString gameName);
|
||||
void signalNetClientGameListRemove(unsigned gameId, QString gameName);
|
||||
void signalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId);
|
||||
void signalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId);
|
||||
void signalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -30,16 +30,14 @@ startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFi
|
||||
connect( pushButton_cancel, SIGNAL( clicked() ), this, SLOT( cancel() ) );
|
||||
connect( pushButton_startGame, SIGNAL( clicked() ), this, SLOT( startGame() ) );
|
||||
connect( pushButton_Kick, SIGNAL( clicked() ), this, SLOT( kickPlayer() ) );
|
||||
connect( treeWidget, SIGNAL( itemClicked ( QTreeWidgetItem*, int) ), this, SLOT( playerSelected(QTreeWidgetItem*, int) ) );
|
||||
connect( treeWidget, SIGNAL( clear () ), this, SLOT( clearPlayers() ) );
|
||||
|
||||
pushButton_Kick->setEnabled(false);
|
||||
pushButton_startGame->setEnabled(false);
|
||||
connect( treeWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*) ), this, SLOT( playerSelected(QTreeWidgetItem*, QTreeWidgetItem*) ) );
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::exec() {
|
||||
|
||||
GameInfo info = mySession->getClientGameInfo("default");
|
||||
|
||||
clearDialog();
|
||||
|
||||
GameInfo info = mySession->getClientGameInfo(0);
|
||||
label_maxPlayerNumber->setText(QString::number(info.data.maxNumberOfPlayers));
|
||||
|
||||
QDialog::exec();
|
||||
@@ -62,17 +60,18 @@ void startNetworkGameDialogImpl::refresh(int actionID) {
|
||||
}
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::joinedNetworkGame(QString playerName, int rights) {
|
||||
void startNetworkGameDialogImpl::joinedNetworkGame(unsigned playerId, QString playerName, int rights) {
|
||||
|
||||
isAdmin = rights == PLAYER_RIGHTS_ADMIN;
|
||||
addConnectedPlayer(playerName, rights);
|
||||
addConnectedPlayer(playerId, playerName, rights);
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::addConnectedPlayer(QString playerName, int rights) {
|
||||
void startNetworkGameDialogImpl::addConnectedPlayer(unsigned playerId, QString playerName, int rights) {
|
||||
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget, 0);
|
||||
item->setData(0, Qt::UserRole, playerId);
|
||||
item->setData(0, Qt::DisplayRole, playerName);
|
||||
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget,0);
|
||||
item->setData(0, 0, playerName);
|
||||
|
||||
if(treeWidget->topLevelItemCount() != maxPlayerNumber) {
|
||||
myW->getMySDLPlayer()->playSound("playerconnected", 0);
|
||||
}
|
||||
@@ -83,27 +82,38 @@ void startNetworkGameDialogImpl::addConnectedPlayer(QString playerName, int righ
|
||||
checkPlayerQuantity();
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::updatePlayer(QString oldPlayerName, QString newPlayerName)
|
||||
void startNetworkGameDialogImpl::updatePlayer(unsigned playerId, QString newPlayerName)
|
||||
{
|
||||
QList<QTreeWidgetItem *> list = treeWidget->findItems(oldPlayerName, Qt::MatchExactly, 0);
|
||||
if(!list.empty()) {
|
||||
list[0]->setText(0, newPlayerName);
|
||||
QTreeWidgetItemIterator it(treeWidget);
|
||||
while (*it) {
|
||||
if ((*it)->data(0, Qt::UserRole) == playerId)
|
||||
{
|
||||
(*it)->setData(0, Qt::DisplayRole, newPlayerName);
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::removePlayer(QString playerName) {
|
||||
void startNetworkGameDialogImpl::removePlayer(unsigned playerId, QString) {
|
||||
|
||||
QList<QTreeWidgetItem *> list = treeWidget->findItems(playerName, Qt::MatchExactly, 0);
|
||||
if(!list.empty()) {
|
||||
treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(list[0]));
|
||||
QTreeWidgetItemIterator it(treeWidget);
|
||||
while (*it) {
|
||||
if ((*it)->data(0, Qt::UserRole) == playerId)
|
||||
{
|
||||
treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(*it));
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
checkPlayerQuantity();
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::playerSelected(QTreeWidgetItem*, int) {
|
||||
void startNetworkGameDialogImpl::playerSelected(QTreeWidgetItem* item, QTreeWidgetItem*) {
|
||||
|
||||
pushButton_Kick->setEnabled(isAdmin);
|
||||
if (item)
|
||||
pushButton_Kick->setEnabled(isAdmin);
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::kickPlayer() {
|
||||
@@ -137,9 +147,11 @@ void startNetworkGameDialogImpl::checkPlayerQuantity() {
|
||||
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::clearPlayers()
|
||||
void startNetworkGameDialogImpl::clearDialog()
|
||||
{
|
||||
pushButton_Kick->setEnabled(false);
|
||||
pushButton_startGame->setEnabled(false);
|
||||
treeWidget->clear();
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::setSession(Session *session)
|
||||
|
||||
@@ -45,14 +45,14 @@ public slots:
|
||||
void startGame();
|
||||
void cancel();
|
||||
void refresh(int actionID);
|
||||
void joinedNetworkGame(QString playerName, int rights);
|
||||
void addConnectedPlayer(QString playerName, int rights);
|
||||
void updatePlayer(QString oldPlayerName, QString newPlayerName);
|
||||
void removePlayer(QString playerName);
|
||||
void playerSelected(QTreeWidgetItem*, int);
|
||||
void joinedNetworkGame(unsigned playerId, QString playerName, int rights);
|
||||
void addConnectedPlayer(unsigned playerId, QString playerName, int rights);
|
||||
void updatePlayer(unsigned playerId, QString newPlayerName);
|
||||
void removePlayer(unsigned playerId, QString playerName);
|
||||
void playerSelected(QTreeWidgetItem*, QTreeWidgetItem*);
|
||||
void kickPlayer();
|
||||
void checkPlayerQuantity();
|
||||
void clearPlayers();
|
||||
void clearDialog();
|
||||
|
||||
void keyPressEvent ( QKeyEvent*);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user