[prev in list] [next in list] [prev in thread] [next in thread]
List: atlantik-devel
Subject: [atlantik-cvs] CVS: kdegames/atlantik/client event.cpp, 1.2,
From: kde () office ! kde ! org
Date: 2004-01-20 6:51:32
Message-ID: 20040120065132.9DEFF1E31 () office ! kde ! org
[Download RAW message or body]
Update of /home/kde/kdegames/atlantik/client
In directory office:/tmp/cvs-serv26057/client
Modified Files:
Makefile.am atlantik.cpp atlantik.h main.h
selectconfiguration_widget.cpp selectconfiguration_widget.h
selectgame_widget.cpp selectgame_widget.h
selectserver_widget.cpp selectserver_widget.h
Added Files:
event.cpp event.h eventlogwidget.cpp eventlogwidget.h
Log Message:
Merge atlantik_3_3_branch into HEAD.
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/Makefile.am,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- Makefile.am 19 Dec 2002 03:11:07 -0000 1.39
+++ Makefile.am 20 Jan 2004 06:51:29 -0000 1.40
@@ -3,9 +3,9 @@
atlantik_LDFLAGS = $(all_libraries) $(KDE_RPATH)
atlantik_LDADD = ../libatlantikui/libatlantikui.la \
../libatlantikclient/libatlantikclient.la $(LIB_KDEGAMES) $(LIB_KIO)
-atlantik_SOURCES = atlantik.cpp configdlg.cpp main.cpp monopigator.cpp \
- selectconfiguration_widget.cpp selectgame_widget.cpp \
- selectserver_widget.cpp tokenwidget.cpp
+atlantik_SOURCES = atlantik.cpp configdlg.cpp event.cpp eventlogwidget.cpp \
+ main.cpp monopigator.cpp selectconfiguration_widget.cpp \
+ selectgame_widget.cpp selectserver_widget.cpp tokenwidget.cpp
KDE_ICON = atlantik
Index: atlantik.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/atlantik.cpp,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -d -r1.158 -r1.159
--- atlantik.cpp 8 Dec 2003 17:10:19 -0000 1.158
+++ atlantik.cpp 20 Jan 2004 06:51:29 -0000 1.159
@@ -21,16 +21,20 @@
#include <qlineedit.h>
#include <qscrollbar.h>
+#include <kaboutapplication.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kconfig.h>
#include <klocale.h>
#include <knotifyclient.h>
#include <knotifydialog.h>
+#include <kstatusbar.h>
#include <kstdgameaction.h>
#include <kstdaction.h>
#include <ktoolbar.h>
+#include <kdebug.h>
+
#include <atlantic_core.h>
#include <auction.h>
#include <estate.h>
@@ -43,6 +47,8 @@
#include <board.h>
#include <trade_widget.h>
+#include "eventlogwidget.h"
+#include "main.h"
#include "selectserver_widget.h"
#include "selectgame_widget.h"
#include "selectconfiguration_widget.h"
@@ -54,6 +60,7 @@
// Toolbar: Game
// KStdGameAction::gameNew(this, SLOT(slotNewGame()), actionCollection(), \
"game_new"); + m_showEventLog = new KAction(i18n("Show Event &Log"), \
"atlantik_showeventlog", CTRL+Key_L, this, SLOT(showEventLog()), actionCollection(), \
"showeventlog"); KStdGameAction::quit(kapp, SLOT(closeAllWindows()), \
actionCollection(), "game_quit");
// Toolbar: Settings
@@ -63,6 +70,7 @@
// Initialize pointers to 0L
m_configDialog = 0;
m_board = 0;
+ m_eventLogWidget = 0;
m_selectServer = 0;
m_selectGame = 0;
m_selectConfiguration = 0;
@@ -70,11 +78,14 @@
// Game and network core
m_atlanticCore = new AtlanticCore(this, "atlanticCore");
- initNetworkObject();
-
+ connect(m_atlanticCore, SIGNAL(createGUI(Player *)), this, SLOT(newPlayer(Player \
*))); connect(m_atlanticCore, SIGNAL(removeGUI(Player *)), this, \
SLOT(removeGUI(Player *))); + connect(m_atlanticCore, SIGNAL(createGUI(Trade *)), \
this, SLOT(newTrade(Trade *))); connect(m_atlanticCore, SIGNAL(removeGUI(Trade *)), \
this, SLOT(removeGUI(Trade *)));
+ initEventLog();
+ initNetworkObject();
+
// Menu,toolbar: Move
m_roll = KStdGameAction::roll(this, SIGNAL(rollDice()), actionCollection());
m_roll->setEnabled(false);
@@ -93,6 +104,9 @@
// Mix code and XML into GUI
KMainWindow::createGUI();
+ KMainWindow::statusBar()->insertItem("Atlantik " ATLANTIK_VERSION_STRING, 0);
+ KMainWindow::statusBar()->insertItem(QString::null, 1);
+ connect(statusBar(), SIGNAL(released(int)), this, SLOT(statusBarClick(int)));
// Main widget, containing all others
m_mainWidget = new QWidget(this, "main");
@@ -179,9 +193,6 @@
void Atlantik::newPlayer(Player *player)
{
- if (player->isSelf())
- m_atlanticCore->setPlayerSelf(player);
-
initBoard();
m_board->addToken(player);
addPortfolioView(player);
@@ -194,7 +205,7 @@
connect(player, SIGNAL(gainedTurn()), this, SLOT(gainedTurn()));
connect(player, SIGNAL(changed(Player *)), m_board, SLOT(playerChanged(Player *)));
- KNotifyClient::event("newplayer");
+ KNotifyClient::event(this->winId(), "newplayer");
}
void Atlantik::newEstate(Estate *estate)
@@ -235,29 +246,34 @@
void Atlantik::showSelectServer()
{
+ if (m_selectServer)
+ return;
+
m_selectServer = new SelectServer(m_config.connectOnStart, \
m_config.hideDevelopmentServers, m_mainWidget, "selectServer"); \
m_mainLayout->addMultiCellWidget(m_selectServer, 0, 2, 1, 1); \
m_selectServer->show();
if (m_selectGame)
{
- disconnect(m_atlantikNetwork, SIGNAL(gameListClear()), m_selectGame, \
SLOT(slotGameListClear()));
-
delete m_selectGame;
m_selectGame = 0;
}
m_atlanticCore->reset(true);
-
initNetworkObject();
- connect(m_atlantikNetwork, SIGNAL(gameListClear()), this, SLOT(showSelectGame()));
connect(m_selectServer, SIGNAL(serverConnect(const QString, int)), \
m_atlantikNetwork, SLOT(serverConnect(const QString, int))); \
+ connect(m_selectServer, SIGNAL(msgStatus(const QString &)), this, \
SLOT(slotMsgStatus(const QString &))); }
void Atlantik::showSelectGame()
{
- m_selectGame = new SelectGame(m_mainWidget, "selectGame");
+ if (m_selectGame)
+ return;
+
+ m_selectGame = new SelectGame(m_atlanticCore, m_mainWidget, "selectGame");
+ m_atlanticCore->emitGames();
+
m_mainLayout->addMultiCellWidget(m_selectGame, 0, 2, 1, 1);
m_selectGame->show();
@@ -284,47 +300,36 @@
m_selectConfiguration = 0;
}
- // Game list clear has a different meaning now
- disconnect(m_atlantikNetwork, SIGNAL(gameListClear()), this, \
SLOT(showSelectGame()));
- connect(m_atlantikNetwork, SIGNAL(gameListClear()), m_selectGame, \
SLOT(slotGameListClear()));
-
- connect(m_atlantikNetwork, SIGNAL(gameListAdd(QString, QString, QString, QString, \
QString, bool)), m_selectGame, SLOT(slotGameListAdd(QString, QString, QString, \
QString, QString, bool)));
- connect(m_atlantikNetwork, SIGNAL(gameListEdit(QString, QString, QString, QString, \
QString, bool)), m_selectGame, SLOT(slotGameListEdit(QString, QString, QString, \
QString, QString, bool)));
- connect(m_atlantikNetwork, SIGNAL(gameListDel(QString)), m_selectGame, \
SLOT(slotGameListDel(QString)));
- connect(m_atlantikNetwork, SIGNAL(gameListEndUpdate()), m_selectGame, \
SLOT(slotGameListEndUpdate()));
-
connect(m_selectGame, SIGNAL(joinGame(int)), m_atlantikNetwork, \
SLOT(joinGame(int))); connect(m_selectGame, SIGNAL(newGame(const QString &)), \
m_atlantikNetwork, SLOT(newGame(const QString &))); connect(m_selectGame, \
SIGNAL(leaveServer()), this, SLOT(showSelectServer())); + connect(m_selectGame, \
SIGNAL(msgStatus(const QString &)), this, SLOT(slotMsgStatus(const QString &))); }
void Atlantik::showSelectConfiguration()
{
+ if (m_selectConfiguration)
+ return;
+
if (m_selectGame)
{
- disconnect(m_atlantikNetwork, SIGNAL(gameListClear()), m_selectGame, \
SLOT(slotGameListClear()));
-
delete m_selectGame;
m_selectGame = 0;
}
- if (m_selectConfiguration)
- return;
-
- Player *playerSelf = m_atlanticCore->playerSelf();
- m_selectConfiguration = new SelectConfiguration(m_mainWidget, \
"selectConfiguration");
- m_selectConfiguration->setCanStart(playerSelf ? playerSelf->master() : false);
+ m_selectConfiguration = new SelectConfiguration(m_atlanticCore, m_mainWidget, \
"selectConfiguration"); m_mainLayout->addMultiCellWidget(m_selectConfiguration, 0, \
2, 1, 1); m_selectConfiguration->show();
- connect(m_atlantikNetwork, SIGNAL(gameListClear()), this, SLOT(showSelectGame()));
+ connect(m_atlanticCore, SIGNAL(createGUI(ConfigOption *)), m_selectConfiguration, \
SLOT(addConfigOption(ConfigOption *))); connect(m_atlantikNetwork, \
SIGNAL(gameOption(QString, QString, QString, QString, QString)), \
m_selectConfiguration, SLOT(gameOption(QString, QString, QString, QString, \
QString)));
- connect(m_atlantikNetwork, SIGNAL(endConfigUpdate()), m_selectConfiguration, \
SLOT(slotEndUpdate())); connect(m_atlantikNetwork, SIGNAL(gameInit()), \
m_selectConfiguration, SLOT(initGame())); connect(m_selectConfiguration, \
SIGNAL(startGame()), m_atlantikNetwork, SLOT(startGame())); \
connect(m_selectConfiguration, SIGNAL(leaveGame()), m_atlantikNetwork, \
SLOT(leaveGame())); + connect(m_selectConfiguration, SIGNAL(changeOption(int, const \
QString &)), m_atlantikNetwork, SLOT(changeOption(int, const QString &))); \
connect(m_selectConfiguration, SIGNAL(buttonCommand(QString)), m_atlantikNetwork, \
SLOT(writeData(QString))); connect(m_selectConfiguration, SIGNAL(iconSelected(const \
QString &)), m_atlantikNetwork, SLOT(setImage(const QString &))); \
+ connect(m_selectConfiguration, SIGNAL(statusMessage(const QString &)), this, \
SLOT(slotMsgStatus(const QString &))); }
void Atlantik::initBoard()
@@ -346,8 +351,6 @@
{
if (m_selectGame)
{
- disconnect(m_atlantikNetwork, SIGNAL(gameListClear()), m_selectGame, \
SLOT(slotGameListClear()));
-
delete m_selectGame;
m_selectGame = 0;
}
@@ -369,8 +372,6 @@
for (QPtrListIterator<PortfolioView> it(m_portfolioViews); *it; ++it)
if ((portfolioView = dynamic_cast<PortfolioView*>(*it)))
portfolioView->buildPortfolio();
-
- connect(m_atlantikNetwork, SIGNAL(gameListClear()), this, SLOT(showSelectGame()));
}
void Atlantik::freezeBoard()
@@ -383,17 +384,12 @@
void Atlantik::slotNetworkConnected()
{
- // We're connected, so let's make ourselves known.
- m_atlantikNetwork->setName(m_config.playerName);
-
// Check command-line args to see if we need to auto-join
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
QCString game = args->getOption("game");
if (!game.isNull())
m_atlantikNetwork->joinGame(game.toInt());
- else
- showSelectGame();
}
void Atlantik::slotNetworkError(int errnum)
@@ -423,6 +419,20 @@
initNetworkObject();
}
+void Atlantik::networkClosed(int status)
+{
+ switch( status )
+ {
+ case KBufferedIO::involuntary:
+ slotMsgStatus( i18n("Connection with server %1:%2 \
lost.").arg(m_atlantikNetwork->host()).arg(m_atlantikNetwork->port()), \
QString("connect_no") ); + showSelectServer();
+ break;
+ default:
+ if ( !m_atlantikNetwork->host().isEmpty() )
+ slotMsgStatus( i18n("Disconnected from \
%1:%2.").arg(m_atlantikNetwork->host()).arg(m_atlantikNetwork->port()), \
QString("connect_no") ); + break;
+ }
+}
void Atlantik::slotConfigure()
{
@@ -433,6 +443,13 @@
connect(m_configDialog, SIGNAL(okClicked()), this, SLOT(slotUpdateConfig()));
}
+void Atlantik::showEventLog()
+{
+ if (!m_eventLogWidget)
+ m_eventLogWidget = new EventLogWidget(m_eventLog, 0);
+ m_eventLogWidget->show();
+}
+
void Atlantik::configureNotifications()
{
KNotifyDialog::configure(this);
@@ -549,6 +566,12 @@
serverMsgsAppend("Error: " + msg);
}
+void Atlantik::slotMsgStatus(const QString &message, const QString &icon)
+{
+ KMainWindow::statusBar()->changeItem(message, 1);
+ m_eventLog->addEvent(message, icon);
+}
+
void Atlantik::slotMsgChat(QString player, QString msg)
{
if (m_config.chatTimestamps)
@@ -558,7 +581,7 @@
}
else
serverMsgsAppend(player + ": " + msg);
- KNotifyClient::event("chat");
+ KNotifyClient::event(this->winId(), "chat");
}
void Atlantik::serverMsgsAppend(QString msg)
@@ -578,24 +601,28 @@
if (player == playerSelf)
{
// We changed ourselves..
-
PortfolioView *portfolioView = 0;
for (QPtrListIterator<PortfolioView> it(m_portfolioViews); *it; ++it)
if ((portfolioView = dynamic_cast<PortfolioView*>(*it)))
{
// Clear all portfolios if we're not in game
- if ( player->gameId() == -1 )
+ if ( !player->game() )
portfolioView->clearPortfolio();
// Show players in our game, hide the rest
- if ( portfolioView->player()->gameId() == playerSelf->gameId() )
+ Player *pTmp = portfolioView->player();
+ if (pTmp->game() == playerSelf->game())
portfolioView->show();
else
portfolioView->hide();
}
-
- if (m_selectConfiguration)
- m_selectConfiguration->setCanStart(player->master());
+ if (!player->game())
+ showSelectGame();
+ else
+ {
+ if ( !m_board || m_board->isHidden() )
+ showSelectConfiguration();
+ }
m_roll->setEnabled(player->canRoll());
m_buyEstate->setEnabled(player->canBuy());
@@ -613,19 +640,24 @@
// his/her portfolioView.
if (playerSelf)
{
- if (player->gameId() == playerSelf->gameId())
+ if (player->game() == playerSelf->game())
portfolioView->show();
else
portfolioView->hide();
}
- else if (player->gameId() == -1)
+ else if ( !player->game() )
portfolioView->hide();
}
}
void Atlantik::gainedTurn()
{
- KNotifyClient::event("gainedturn");
+ KNotifyClient::event(this->winId(), "gainedturn");
+}
+
+void Atlantik::initEventLog()
+{
+ m_eventLog = new EventLog();
}
void Atlantik::initNetworkObject()
@@ -639,23 +671,25 @@
m_atlantikNetwork = new AtlantikNetwork(m_atlanticCore);
connect(m_atlantikNetwork, SIGNAL(msgInfo(QString)), this, \
SLOT(slotMsgInfo(QString))); connect(m_atlantikNetwork, SIGNAL(msgError(QString)), \
this, SLOT(slotMsgError(QString))); + connect(m_atlantikNetwork, \
SIGNAL(msgStatus(const QString &, const QString &)), this, SLOT(slotMsgStatus(const \
QString &, const QString &))); connect(m_atlantikNetwork, SIGNAL(msgChat(QString, \
QString)), this, SLOT(slotMsgChat(QString, QString)));
connect(m_atlantikNetwork, SIGNAL(connectionSuccess()), this, \
SLOT(slotNetworkConnected())); connect(m_atlantikNetwork, \
SIGNAL(connectionFailed(int)), this, SLOT(slotNetworkError(int))); \
+ connect(m_atlantikNetwork, SIGNAL(closed(int)), this, SLOT(networkClosed(int))); +
+ connect(m_atlantikNetwork, SIGNAL(receivedHandshake()), this, \
SLOT(sendHandshake()));
- connect(m_atlantikNetwork, SIGNAL(gameListClear()), this, SLOT(showSelectGame()));
connect(m_atlantikNetwork, SIGNAL(gameConfig()), this, \
SLOT(showSelectConfiguration())); connect(m_atlantikNetwork, SIGNAL(gameInit()), \
this, SLOT(initBoard())); connect(m_atlantikNetwork, SIGNAL(gameRun()), this, \
SLOT(showBoard())); connect(m_atlantikNetwork, SIGNAL(gameEnd()), this, \
SLOT(freezeBoard()));
- connect(m_atlantikNetwork, SIGNAL(newPlayer(Player *)), this, SLOT(newPlayer(Player \
*))); connect(m_atlantikNetwork, SIGNAL(newEstate(Estate *)), this, \
SLOT(newEstate(Estate *)));
- connect(m_atlantikNetwork, SIGNAL(newTrade(Trade *)), this, SLOT(newTrade(Trade \
*))); connect(m_atlantikNetwork, SIGNAL(newAuction(Auction *)), this, \
SLOT(newAuction(Auction *)));
connect(m_atlantikNetwork, SIGNAL(clientCookie(QString)), this, \
SLOT(clientCookie(QString))); + connect(m_atlantikNetwork, SIGNAL(networkEvent(const \
QString &, const QString &)), m_eventLog, SLOT(addEvent(const QString &, const \
QString &)));
connect(this, SIGNAL(rollDice()), m_atlantikNetwork, SLOT(rollDice()));
connect(this, SIGNAL(buyEstate()), m_atlantikNetwork, SLOT(buyEstate()));
@@ -688,6 +722,22 @@
config->sync();
}
+void Atlantik::sendHandshake()
+{
+ m_atlantikNetwork->setName(m_config.playerName);
+}
+
+void Atlantik::statusBarClick(int item)
+{
+ if ( item == 0 )
+ {
+ KAboutApplication dialog(kapp->aboutData(), this);
+ dialog.exec();
+ }
+ else if ( item == 1)
+ showEventLog();
+}
+
PortfolioView *Atlantik::addPortfolioView(Player *player)
{
PortfolioView *portfolioView = new PortfolioView(m_atlanticCore, player, \
m_config.activeColor, m_config.inactiveColor, m_portfolioWidget); @@ -695,6 +745,7 @@
connect(player, SIGNAL(changed(Player *)), portfolioView, SLOT(playerChanged()));
connect(portfolioView, SIGNAL(newTrade(Player *)), m_atlantikNetwork, \
SLOT(newTrade(Player *))); + connect(portfolioView, SIGNAL(kickPlayer(Player *)), \
m_atlantikNetwork, SLOT(kickPlayer(Player *))); connect(portfolioView, \
SIGNAL(estateClicked(Estate *)), m_board, SLOT(prependEstateDetails(Estate *)));
m_portfolioLayout->addWidget(portfolioView);
Index: atlantik.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/atlantik.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- atlantik.h 5 Aug 2003 03:03:35 -0000 1.62
+++ atlantik.h 20 Jan 2004 06:51:29 -0000 1.63
@@ -56,6 +56,8 @@
QColor activeColor, inactiveColor;
};
+class EventLog;
+class EventLogWidget;
class SelectServer;
class SelectGame;
class SelectConfiguration;
@@ -105,6 +107,8 @@
void showBoard();
void freezeBoard();
void clientCookie(QString cookie);
+ void sendHandshake();
+ void statusBarClick(int);
public slots:
@@ -113,7 +117,7 @@
* list instead of the server list.
*
*/
- void slotNetworkConnected();
+ void slotNetworkConnected();
/**
* An error occurred while setting up the network connection. Inform the
@@ -121,8 +125,10 @@
*
* @param errno See http://doc.trolltech.com/3.0/qsocket.html#Error-enum
*/
- void slotNetworkError(int errnum);
+ void slotNetworkError(int errnum);
+ void networkClosed(int status);
+
/**
* Creates a new modeless configure dialog or raises it when it already exists.
*
@@ -130,6 +136,12 @@
void slotConfigure();
/**
+ * Opens the event log widget.
+ *
+ */
+ void showEventLog();
+
+ /**
* Opens the KNotify dialog for configuration events.
*
*/
@@ -159,6 +171,8 @@
*/
void slotMsgInfo(QString msg);
+ void slotMsgStatus(const QString &message, const QString &icon = QString::null);
+
/**
* Informs serverMsgs() to append an incoming message from the
* server to the text view as error message.
@@ -197,6 +211,7 @@
void jailRoll();
private:
+ void initEventLog();
void initNetworkObject();
PortfolioView *addPortfolioView(Player *player);
PortfolioView *findPortfolioView(Player *player);
@@ -210,7 +225,8 @@
QTextEdit *m_serverMsgs;
KAction *m_roll, *m_buyEstate, *m_auctionEstate, *m_endTurn,
- *m_jailCard, *m_jailPay, *m_jailRoll, *m_configure;
+ *m_jailCard, *m_jailPay, *m_jailRoll, *m_configure,
+ *m_showEventLog;
AtlanticCore *m_atlanticCore;
AtlantikNetwork *m_atlantikNetwork;
@@ -221,6 +237,8 @@
SelectServer *m_selectServer;
SelectGame *m_selectGame;
SelectConfiguration *m_selectConfiguration;
+ EventLog *m_eventLog;
+ EventLogWidget *m_eventLogWidget;
QPtrList<PortfolioView> m_portfolioViews;
QMap<Trade *, TradeDisplay *> m_tradeGUIMap;
Index: main.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/main.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- main.h 5 Nov 2003 19:36:07 -0000 1.40
+++ main.h 20 Jan 2004 06:51:29 -0000 1.41
@@ -17,10 +17,11 @@
#ifndef ATLANTIK_MAIN_H
#define ATLANTIK_MAIN_H
-#define ATLANTIK_VERSION 060
-#define ATLANTIK_VERSION_STRING "0.6.0"
+#define ATLANTIK_VERSION 070
+#define ATLANTIK_VERSION_STRING "0.7.0 (CVS >= 20040120)"
+
#define ATLANTIK_VERSION_MAJOR 0
-#define ATLANTIK_VERSION_MINOR 6
+#define ATLANTIK_VERSION_MINOR 7
#define ATLANTIK_VERSION_RELEASE 0
int main(int, char *[]);
Index: selectconfiguration_widget.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectconfiguration_widget.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- selectconfiguration_widget.cpp 11 Nov 2003 17:48:43 -0000 1.39
+++ selectconfiguration_widget.cpp 20 Jan 2004 06:51:29 -0000 1.40
@@ -26,14 +26,19 @@
#include <kmessagebox.h>
#include <kstandarddirs.h>
+#include <atlantic_core.h>
+#include <configoption.h>
+#include <game.h>
#include <player.h>
#include "tokenwidget.h"
#include "selectconfiguration_widget.moc"
-SelectConfiguration::SelectConfiguration(QWidget *parent, const char *name) : \
QWidget(parent, name) +SelectConfiguration::SelectConfiguration(AtlanticCore \
*atlanticCore, QWidget *parent, const char *name) : QWidget(parent, name) {
+ m_atlanticCore = atlanticCore;
m_tokenWidget = 0;
+ m_game = 0;
m_mainLayout = new QVBoxLayout(this, KDialog::marginHint());
Q_CHECK_PTR(m_mainLayout);
@@ -69,23 +74,20 @@
m_startButton = new KPushButton(SmallIcon("forward"), i18n("Start Game"), this);
serverButtons->addWidget(m_startButton);
+ m_startButton->setEnabled(false);
connect(m_startButton, SIGNAL(clicked()), this, SIGNAL(startGame()));
- // Status indicator.
- m_statusLabel = new QLabel(this);
- m_statusLabel->setText(i18n("Retrieving configuration list..."));
- m_mainLayout->addWidget(m_statusLabel);
-}
-
-SelectConfiguration::~SelectConfiguration()
-{
- delete m_statusLabel;
+ Player *playerSelf = m_atlanticCore->playerSelf();
+ playerChanged(playerSelf);
+ connect(playerSelf, SIGNAL(changed(Player *)), this, SLOT(playerChanged(Player \
*))); +
+ emit statusMessage(i18n("Retrieving configuration list..."));
}
void SelectConfiguration::initGame()
{
- m_statusLabel->setText(i18n("Game started. Retrieving full game data..."));
+ emit statusMessage(i18n("Game started. Retrieving full game data..."));
}
void SelectConfiguration::slotTokenButtonClicked()
@@ -110,6 +112,21 @@
m_tokenWidget = 0;
}
+void SelectConfiguration::addConfigOption(ConfigOption *configOption)
+{
+ // FIXME: only bool types supported!
+ QCheckBox *checkBox = new QCheckBox(configOption->description(), m_configBox, \
"checkbox"); + m_configMap[(QObject *)checkBox] = configOption;
+ m_configBoxMap[configOption] = checkBox;
+
+ checkBox->setChecked( configOption->value().toInt() );
+ checkBox->setEnabled( configOption->edit() && m_atlanticCore->selfIsMaster() );
+ checkBox->show();
+
+ connect(checkBox, SIGNAL(clicked()), this, SLOT(changeOption()));
+ connect(configOption, SIGNAL(changed(ConfigOption *)), this, \
SLOT(optionChanged(ConfigOption *))); +}
+
void SelectConfiguration::gameOption(QString title, QString type, QString value, \
QString edit, QString command) {
// Find if option exists in GUI yet
@@ -137,6 +154,27 @@
// TODO: Enable edit for master only
}
+void SelectConfiguration::changeOption()
+{
+ ConfigOption *configOption = m_configMap[(QObject *)QObject::sender()];
+ if (configOption)
+ {
+ kdDebug() << "checked " << ((QCheckBox *)QObject::sender())->isChecked() << endl;
+ emit changeOption( configOption->id(), QString::number( ((QCheckBox \
*)QObject::sender())->isChecked() ) ); + }
+}
+
+void SelectConfiguration::optionChanged(ConfigOption *configOption)
+{
+ QCheckBox *checkBox = m_configBoxMap[configOption];
+ if (checkBox)
+ {
+ checkBox->setText( configOption->description() );
+ checkBox->setChecked( configOption->value().toInt() );
+ checkBox->setEnabled( configOption->edit() && m_atlanticCore->selfIsMaster() );
+ }
+}
+
void SelectConfiguration::optionChanged()
{
QString command = m_optionCommandMap[(QObject *)QObject::sender()];
@@ -150,10 +188,31 @@
void SelectConfiguration::slotEndUpdate()
{
- m_statusLabel->setText(i18n("Retrieved configuration list."));
+ emit statusMessage(i18n("Retrieved configuration list."));
}
-void SelectConfiguration::setCanStart(const bool &canStart)
+void SelectConfiguration::playerChanged(Player *player)
{
- m_startButton->setEnabled(canStart);
+ kdDebug() << "playerChanged" << endl;
+
+ if (player->game() != m_game)
+ {
+ kdDebug() << "playerChanged::change" << endl;
+
+ if (m_game)
+ disconnect(m_game, SIGNAL(changed(Game *)), this, SLOT(gameChanged(Game *)));
+
+ m_game = player->game();
+
+ if (m_game)
+ connect(m_game, SIGNAL(changed(Game *)), this, SLOT(gameChanged(Game *)));
+ }
+}
+
+void SelectConfiguration::gameChanged(Game *game)
+{
+ m_startButton->setEnabled( game->master() == m_atlanticCore->playerSelf() );
+
+ for (QMapIterator<ConfigOption *, QCheckBox *> it = m_configBoxMap.begin() ; it != \
m_configBoxMap.end() ; ++it) + (*it)->setEnabled( it.key()->edit() && \
m_atlanticCore->selfIsMaster() ); }
Index: selectconfiguration_widget.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectconfiguration_widget.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- selectconfiguration_widget.h 12 Jul 2003 17:45:21 -0000 1.19
+++ selectconfiguration_widget.h 20 Jan 2004 06:51:29 -0000 1.20
@@ -20,7 +20,6 @@
#include <qwidget.h>
#include <qlayout.h>
#include <qvgroupbox.h>
-#include <qlabel.h>
#include <klistview.h>
#include <kpushbutton.h>
@@ -28,6 +27,9 @@
class QCheckBox;
class QListViewItem;
+class AtlanticCore;
+class ConfigOption;
+class Game;
class Player;
class TokenWidget;
@@ -36,8 +38,7 @@
Q_OBJECT
public:
- SelectConfiguration(QWidget *parent, const char *name=0);
- ~SelectConfiguration();
+ SelectConfiguration(AtlanticCore *atlanticCore, QWidget *parent, const char \
*name=0);
void setCanStart(const bool &canStart);
QString hostToConnect() const;
@@ -46,28 +47,37 @@
private slots:
void slotTokenButtonClicked();
void slotTokenSelected(const QString &name);
+ void addConfigOption(ConfigOption *configOption);
+ void changeOption();
void gameOption(QString title, QString type, QString value, QString edit, QString \
command); + void optionChanged(ConfigOption *configOption);
void optionChanged();
void slotEndUpdate();
void initGame();
+ void playerChanged(Player *player);
+ void gameChanged(Game *game);
signals:
void startGame();
void leaveGame();
void joinConfiguration(int configurationId);
void newConfiguration();
+ void changeOption(int configId, const QString &value);
void buttonCommand(QString);
void iconSelected(const QString &);
-// void statusChanged();
+ void statusMessage(const QString &message);
private:
QVBoxLayout *m_mainLayout;
- QLabel *m_statusLabel;
QVGroupBox *m_configBox, *m_messageBox;
KPushButton *m_backButton, *m_startButton, *m_tokenButton;
QMap <QObject *, QString> m_optionCommandMap;
+ QMap <QObject *, ConfigOption *> m_configMap;
+ QMap <ConfigOption *, QCheckBox *> m_configBoxMap;
QMap <QString, QCheckBox *> m_checkBoxMap;
QMap <Player *, QListViewItem *> m_items;
+ Game *m_game;
+ AtlanticCore *m_atlanticCore;
TokenWidget *m_tokenWidget;
};
Index: selectgame_widget.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectgame_widget.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- selectgame_widget.cpp 27 May 2003 21:03:19 -0000 1.28
+++ selectgame_widget.cpp 20 Jan 2004 06:51:29 -0000 1.29
@@ -1,4 +1,4 @@
-
+// Copyright (c) 2002-2003 Rob Kaper <cap@capsi.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@@ -23,10 +23,19 @@
#include <kiconloader.h>
#include <knotifyclient.h>
-#include "selectgame_widget.moc"
+#include <atlantic_core.h>
+#include <game.h>
+#include <player.h>
-SelectGame::SelectGame(QWidget *parent, const char *name) : QWidget(parent, name)
+#include "selectgame_widget.h"
+
+SelectGame::SelectGame(AtlanticCore *atlanticCore, QWidget *parent, const char \
*name) : QWidget(parent, name) {
+ m_atlanticCore = atlanticCore;
+
+ connect(m_atlanticCore, SIGNAL(createGUI(Game *)), this, SLOT(addGame(Game *)));
+ connect(m_atlanticCore, SIGNAL(removeGUI(Game *)), this, SLOT(delGame(Game *)));
+
m_mainLayout = new QVBoxLayout(this, KDialog::marginHint());
Q_CHECK_PTR(m_mainLayout);
@@ -63,80 +72,95 @@
connect(m_connectButton, SIGNAL(clicked()), this, SLOT(connectClicked()));
- // Status indicator
- m_statusLabel = new QLabel(this);
- m_statusLabel->setText(i18n("Retrieving game list..."));
- m_mainLayout->addWidget(m_statusLabel);
}
-void SelectGame::slotGameListClear()
+void SelectGame::addGame(Game *game)
{
- m_gameList->clear();
- validateConnectButton();
-// emit statusChanged();
+ connect(game, SIGNAL(changed(Game *)), this, SLOT(updateGame(Game *)));
+
+ if (game->id() == -1)
+ {
+ QListViewItem *item = new QListViewItem( m_gameList, i18n("Create a new %1 \
Game").arg(game->name()), game->description(), QString::null, QString::null, \
game->type() ); + item->setPixmap(0, QPixmap(SmallIcon("filenew")));
+ }
+ else
+ {
+ Player *master = game->master();
+ QListViewItem *item = new QListViewItem( m_gameList, i18n("Join %1's %2 \
Game").arg( (master ? master->name() : QString::null), game->name() ), \
game->description(), QString::number(game->id()), QString::number(game->players()), \
game->type() ); + item->setPixmap( 0, QPixmap(SmallIcon("atlantik")) );
+ item->setEnabled(game->canBeJoined());
+
+ KNotifyClient::event(this->winId(), "newgame");
+
+ connect(master, SIGNAL(changed(Player *)), this, SLOT(playerChanged(Player *)));
+ }
+
+// validateConnectButton();
}
-void SelectGame::slotGameListEndUpdate()
+void SelectGame::delGame(Game *game)
{
- m_statusLabel->setText(i18n("Retrieved game list."));
+ QListViewItem *item = findItem(game);
+ if (!item)
+ return;
+
+ delete item;
+
+ validateConnectButton();
}
-void SelectGame::slotGameListAdd(QString gameId, QString name, QString description, \
QString players, QString gameType, bool canBeJoined) +void \
SelectGame::updateGame(Game *game) {
- if (gameId == "-1")
- {
- QListViewItem *item = new QListViewItem(m_gameList, i18n("Create new %1 \
Game").arg(name), description, QString::null, QString::null, \
gameType);
- item->setPixmap(0, QPixmap(SmallIcon("filenew")));
- }
+ QListViewItem *item = findItem(game);
+ if (!item)
+ return;
+
+ item->setText( 1, game->description() );
+
+ if (game->id() == -1)
+ item->setText(0, i18n("Create a new %1 Game").arg(game->name()));
else
{
- QListViewItem *item = new QListViewItem(m_gameList, i18n("Join %1 Game \
#%2").arg(name).arg(gameId), description, gameId, players, gameType);
- item->setPixmap(0, QPixmap(SmallIcon("atlantik")));
- item->setEnabled(canBeJoined);
- KNotifyClient::event("newgame");
+ Player *master = game->master();
+ item->setText( 0, i18n("Join %1's %2 Game").arg( (master ? master->name() : \
QString::null), game->name() ) ); + item->setText( 3, QString::number( \
game->players() ) ); + item->setEnabled( game->canBeJoined() );
+
+ connect(master, SIGNAL(changed(Player *)), this, SLOT(playerChanged(Player *)));
}
+ m_gameList->triggerUpdate();
validateConnectButton();
}
-void SelectGame::slotGameListEdit(QString gameId, QString name, QString description, \
QString players, QString gameType, bool canBeJoined) +void \
SelectGame::playerChanged(Player *player) {
QListViewItem *item = m_gameList->firstChild();
+ Game *game = 0;
+
while (item)
{
- if (item->text(2) == gameId)
+ game = m_atlanticCore->findGame( item->text(2).toInt() );
+ if ( game && game->master() == player )
{
- if (!name.isEmpty())
- item->setText(0, i18n("Join %1 Game #%2").arg(name).arg(gameId));
- if (!description.isEmpty())
- item->setText(1, description);
- item->setText(3, players);
- if (!gameType.isEmpty())
- item->setText(4, gameType);
- item->setEnabled(canBeJoined);
- m_gameList->triggerUpdate();
+ item->setText( 0, i18n("Join %1's %2 Game").arg( player->name(), game->name() ) \
); return;
}
item = item->nextSibling();
}
- validateConnectButton();
-// emit statusChanged();
}
-void SelectGame::slotGameListDel(QString gameId)
+QListViewItem *SelectGame::findItem(Game *game)
{
QListViewItem *item = m_gameList->firstChild();
while (item)
{
- if (item->text(2) == gameId)
- {
- delete item;
- return;
- }
+ if ( (game->id() == -1 || item->text(2) == QString::number(game->id())) && \
item->text(4) == game->type() ) + return item;
+
item = item->nextSibling();
}
- validateConnectButton();
-// emit statusChanged();
+ return 0;
}
void SelectGame::validateConnectButton()
@@ -164,3 +188,5 @@
emit newGame(item->text(4));
}
}
+
+#include "selectgame_widget.moc"
Index: selectgame_widget.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectgame_widget.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- selectgame_widget.h 14 Dec 2002 01:04:02 -0000 1.16
+++ selectgame_widget.h 20 Jan 2004 06:51:29 -0000 1.17
@@ -1,4 +1,4 @@
-// Copyright (c) 2002 Rob Kaper <cap@capsi.com>
+// Copyright (c) 2002-2003 Rob Kaper <cap@capsi.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@@ -19,44 +19,45 @@
#include <qwidget.h>
#include <qlayout.h>
-#include <qlabel.h>
#include <klistview.h>
#include <kpushbutton.h>
+class AtlanticCore;
+class Game;
+class Player;
+
class SelectGame : public QWidget
{
Q_OBJECT
public:
- SelectGame(QWidget *parent, const char *name=0);
+ SelectGame(AtlanticCore *atlanticCore, QWidget *parent, const char *name=0);
void initPage();
- bool validateNext();
- QString hostToConnect() const;
- int portToConnect();
-
- public slots:
- void validateConnectButton();
-
- void slotGameListClear();
- void slotGameListAdd(QString gameId, QString name, QString description, QString \
players, QString gameType, bool canBeJoined);
- void slotGameListEdit(QString gameId, QString name, QString description, QString \
players, QString gameType, bool canBeJoined);
- void slotGameListDel(QString gameId);
+ bool validateNext();
+ QString hostToConnect() const;
+ int portToConnect();
private slots:
void connectClicked();
- void slotGameListEndUpdate();
+ void addGame(Game *game);
+ void delGame(Game *game);
+ void updateGame(Game *game);
+ void playerChanged(Player *player);
+ void validateConnectButton();
- signals:
- void joinGame(int gameId);
- void newGame(const QString &gameType);
- void leaveServer();
-// void statusChanged();
+signals:
+ void joinGame(int gameId);
+ void newGame(const QString &gameType);
+ void leaveServer();
+ void msgStatus(const QString &status);
private:
+ QListViewItem *findItem(Game *game);
+
+ AtlanticCore *m_atlanticCore;
QVBoxLayout *m_mainLayout;
- QLabel *m_statusLabel;
KListView *m_gameList;
KPushButton *m_connectButton;
};
Index: selectserver_widget.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectserver_widget.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- selectserver_widget.cpp 26 Oct 2003 09:57:00 -0000 1.36
+++ selectserver_widget.cpp 20 Jan 2004 06:51:29 -0000 1.37
@@ -14,6 +14,7 @@
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
+#include <qlabel.h>
#include <qlayout.h>
#include <qradiobutton.h>
#include <qsizepolicy.h>
@@ -87,10 +88,6 @@
connect(m_connectButton, SIGNAL(clicked()), this, SLOT(slotConnect()));
-// Status indicator
- status_label = new QLabel(this);
- m_mainLayout->addWidget(status_label);
-
// Monopigator
m_monopigator = new Monopigator();
@@ -114,7 +111,8 @@
void SelectServer::initMonopigator()
{
// Hardcoded, but there aren't any other Monopigator root servers at the moment
- status_label->setText(i18n("Retrieving server list..."));
+ emit msgStatus(i18n("Retrieving server list..."));
+
m_refreshButton->setGuiItem(KGuiItem(i18n("Reload Server List"), "reload"));
m_monopigator->loadData("http://gator.monopd.net/");
}
@@ -131,13 +129,13 @@
void SelectServer::monopigatorFinished()
{
- status_label->setText(i18n("Retrieved server list."));
+ emit msgStatus(i18n("Retrieved server list."));
m_refreshButton->setEnabled(true);
}
void SelectServer::monopigatorTimeout()
{
- status_label->setText(i18n("Error while retrieving the server list."));
+ emit msgStatus(i18n("Error while retrieving the server list."));
m_refreshButton->setEnabled(true);
}
Index: selectserver_widget.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectserver_widget.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- selectserver_widget.h 27 Jul 2003 17:58:33 -0000 1.18
+++ selectserver_widget.h 20 Jan 2004 06:51:29 -0000 1.19
@@ -20,7 +20,6 @@
#include <qwidget.h>
#include <qlayout.h>
#include <qradiobutton.h>
-#include <qlabel.h>
#include <klineedit.h>
#include <klistview.h>
@@ -58,12 +57,12 @@
signals:
void serverConnect(const QString host, int port);
+ void msgStatus(const QString &message);
private:
void initMonopigator();
QVBoxLayout *m_mainLayout;
- QLabel *status_label;
KListView *m_serverList;
KLineEdit *m_hostEdit, *m_portEdit;
KPushButton *m_addServerButton, *m_refreshButton, *m_customConnect, \
*m_connectButton;
_______________________________________________
atlantik-cvs mailing list
atlantik-cvs@kde.org
https://mail.kde.org/mailman/listinfo/atlantik-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic