first new widgets added to net game
authordisplacer
Sat, 13 Jan 2007 15:13:23 +0000
changeset 322 e7175ae57945
parent 321 1148eeb0557e
child 323 ea947f2c3d2f
first new widgets added to net game
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/newnetclient.cpp
QTfrontend/pages.cpp
QTfrontend/pages.h
QTfrontend/teamselect.cpp
QTfrontend/teamselect.h
--- a/QTfrontend/hwform.cpp	Fri Jan 12 16:04:45 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sat Jan 13 15:13:23 2007 +0000
@@ -77,7 +77,7 @@
 	connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
 
 	connect(ui.pageNetGame->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
-	connect(ui.pageNetGame->BtnAddTeam,	SIGNAL(clicked()),	this, SLOT(NetAddTeam()));
+	connect(ui.pageNetGame->pNetTeamsWidget,	SIGNAL(teamWillPlay(HWTeam)),	this, SLOT(NetAddTeam(HWTeam)));
 	connect(ui.pageNetGame->BtnGo,	SIGNAL(clicked()),	this, SLOT(NetStartGame()));
 
 	connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect()));
@@ -156,15 +156,18 @@
 
 void HWForm::OnPageShown(quint8 id)
 {
-	if (id == ID_PAGE_MULTIPLAYER) {
+	if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETCFG) {
 		QStringList tmNames=config->GetTeamsList();
+		TeamSelWidget* curTeamSelWidget;
+		id == ID_PAGE_MULTIPLAYER ? curTeamSelWidget=ui.pageMultiplayer->teamsSelect : 
+		  curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget;
 		QList<HWTeam> teamsList;
 		for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) {
 		  HWTeam team(*it);
 		  team.LoadFromFile();
 		  teamsList.push_back(team);
 		}
-		ui.pageMultiplayer->teamsSelect->resetPlayingTeams(teamsList);
+		curTeamSelWidget->resetPlayingTeams(teamsList);
 	}
 }
 
@@ -236,7 +239,6 @@
 void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick)
 {
 	hwnet = new HWNewNet(config);
-	connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
 	connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
 	connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
 	connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
@@ -289,11 +291,9 @@
 	hwnet->JoinGame("#hw");
 }
 
-void HWForm::NetAddTeam()
+void HWForm::NetAddTeam(HWTeam team)
 {
-	HWTeam team("DefaultTeam");
-	team.LoadFromFile();
-	hwnet->AddTeam(team);
+  hwnet->AddTeam(team);
 }
 
 void HWForm::NetStartGame()
@@ -303,8 +303,16 @@
 
 void HWForm::ChangeInNetTeams(const QStringList & teams)
 {
-	ui.pageNetGame->listNetTeams->clear();
-	ui.pageNetGame->listNetTeams->addItems(teams);
+  QStringList addedTeams=teams;
+  list<HWTeam> lstPlaying=ui.pageNetGame->pNetTeamsWidget->getPlayingTeams();
+  for(list<HWTeam>::iterator it=lstPlaying.begin(); it!=lstPlaying.end(); ++it) {
+    QString nm=it->TeamName;
+    QStringList::iterator itt=std::find(addedTeams.begin(), addedTeams.end(), nm);
+    if(itt!=addedTeams.end()) addedTeams.erase(itt);
+  }
+  for(QStringList::iterator it=addedTeams.begin(); it!=addedTeams.end(); ++it) {
+    ui.pageNetGame->pNetTeamsWidget->addTeam(*it, true);
+  }
 }
 
 void HWForm::StartMPGame()
--- a/QTfrontend/hwform.h	Fri Jan 12 16:04:45 2007 +0000
+++ b/QTfrontend/hwform.h	Sat Jan 13 15:13:23 2007 +0000
@@ -64,7 +64,7 @@
 	void NetJoin();
 	void NetCreate();
 	void AddGame(const QString & chan);
-	void NetAddTeam();
+	void NetAddTeam(HWTeam team);
 	void NetGameEnter();
 	void NetStartGame();
 	void ChangeInNetTeams(const QStringList & teams);
--- a/QTfrontend/newnetclient.cpp	Fri Jan 12 16:04:45 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Sat Jan 13 15:13:23 2007 +0000
@@ -70,8 +70,8 @@
 
 void HWNewNet::SendNet(const QByteArray & buf)
 {
-  qDebug() << "to net:" << buf;
   QString msg = QString(buf.toBase64());
+  qDebug() << "to net:" << buf << ":" << msg;
 
   //NetBuffer += buf;
   RawSendNet(QString(msg));
--- a/QTfrontend/pages.cpp	Fri Jan 12 16:04:45 2007 +0000
+++ b/QTfrontend/pages.cpp	Sat Jan 13 15:13:23 2007 +0000
@@ -447,27 +447,34 @@
 {
 	QFont * font14 = new QFont("MS Shell Dlg", 14);
 	QGridLayout * pageLayout = new QGridLayout(this);
-	pageLayout->setColumnStretch(0, 1);
-	pageLayout->setColumnStretch(1, 1);
-	pageLayout->setColumnStretch(2, 1);
+	//pageLayout->setColumnStretch(0, 1);
+	//pageLayout->setColumnStretch(1, 2);
+	//pageLayout->setColumnStretch(2, 1);
+
+	pGameCFG=new GameCFGWidget(this);
+	pageLayout->addWidget(pGameCFG, 0, 0);
+
+	
+	pNetTeamsWidget=new TeamSelWidget(this);
+	pageLayout->addWidget(pNetTeamsWidget, 0, 1);
 
 	BtnBack = new QPushButton(this);
 	BtnBack->setFont(*font14);
 	BtnBack->setText(QPushButton::tr("Back"));
-	pageLayout->addWidget(BtnBack, 2, 0);
+	pageLayout->addWidget(BtnBack, 1, 0);
 
 	BtnAddTeam = new QPushButton(this);
 	BtnAddTeam->setFont(*font14);
 	BtnAddTeam->setText(QPushButton::tr("Add Team"));
-	pageLayout->addWidget(BtnAddTeam, 1, 1);
+	//pageLayout->addWidget(BtnAddTeam, 1, 1);
 
 	BtnGo	= new QPushButton(this);
 	BtnGo->setFont(*font14);
 	BtnGo->setText(QPushButton::tr("Go!"));
-	pageLayout->addWidget(BtnGo, 2, 2);
+	pageLayout->addWidget(BtnGo, 1, 1);
 
 	listNetTeams = new QListWidget(this);
-	pageLayout->addWidget(listNetTeams, 0, 1);
+	//pageLayout->addWidget(listNetTeams, 0, 1);
 }
 
 PageInfo::PageInfo(QWidget* parent) : QWidget(parent)
--- a/QTfrontend/pages.h	Fri Jan 12 16:04:45 2007 +0000
+++ b/QTfrontend/pages.h	Sat Jan 13 15:13:23 2007 +0000
@@ -22,6 +22,7 @@
 #include <QWidget>
 
 #include "binds.h"
+#include "mapContainer.h"
 
 class GameCFGWidget;
 class QPushButton;
@@ -189,6 +190,11 @@
 	QPushButton *BtnAddTeam;
 	QPushButton *BtnGo;
 	QListWidget *listNetTeams;
+
+	TeamSelWidget* pNetTeamsWidget;
+
+ private:
+	GameCFGWidget* pGameCFG;
 };
 
 class PageInfo : public QWidget
--- a/QTfrontend/teamselect.cpp	Fri Jan 12 16:04:45 2007 +0000
+++ b/QTfrontend/teamselect.cpp	Sat Jan 13 15:13:23 2007 +0000
@@ -26,12 +26,17 @@
 #include "teamselhelper.h"
 #include "frameTeam.h"
 
-void TeamSelWidget::addTeam(HWTeam team)
+void TeamSelWidget::addTeam(HWTeam team, bool netTeam)
 {
-  frameDontPlaying->addTeam(team, false);
-  curDontPlayingTeams.push_back(team);
-  QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
-		   this, SLOT(changeTeamStatus(HWTeam)));
+  if(netTeam) {
+    framePlaying->addTeam(team, true);
+    curPlayingTeams.push_back(team);
+  } else {
+    frameDontPlaying->addTeam(team, false);
+    curDontPlayingTeams.push_back(team);
+    QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
+		     this, SLOT(changeTeamStatus(HWTeam)));
+  }
 }
 
 //void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team)
@@ -55,6 +60,7 @@
     if(framePlaying->isFullTeams()) return;
     // dont playing team => playing
     curPlayingTeams.push_back(*itDontPlay);
+    emit teamWillPlay(*itDontPlay);
     curDontPlayingTeams.erase(itDontPlay);
   }
 
--- a/QTfrontend/teamselect.h	Fri Jan 12 16:04:45 2007 +0000
+++ b/QTfrontend/teamselect.h	Sat Jan 13 15:13:23 2007 +0000
@@ -40,17 +40,20 @@
 
  public:
   TeamSelWidget(QWidget* parent=0);
-  void addTeam(HWTeam team);
   //void removeTeam(HWTeam team);
   void resetPlayingTeams(const QList<HWTeam>& teamslist);
   bool isPlaying(HWTeam team) const;
   HWTeamTempParams getTeamParams(HWTeam team) const;
   list<HWTeam> getPlayingTeams() const;
 
-  signals:
-    void NewTeam();
+ public slots:
+  void addTeam(HWTeam team, bool netTeam=false);
 
-private slots:
+ signals:
+  void NewTeam();
+  void teamWillPlay(HWTeam team);
+  
+ private slots:
   void changeTeamStatus(HWTeam team);
   void newTeamClicked();