teams and hedgedogs num selection added to HWgame
authordisplacer
Sat, 09 Sep 2006 16:59:10 +0000
changeset 140 50ccde437ea1
parent 139 340ded7cc336
child 141 ac3680be1f4b
teams and hedgedogs num selection added to HWgame
QTfrontend/frameTeam.cpp
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/gameuiconfig.cpp
QTfrontend/hedgehogerWidget.cpp
QTfrontend/hedgehogerWidget.h
QTfrontend/hwform.cpp
QTfrontend/teamselect.cpp
QTfrontend/teamselect.h
QTfrontend/teamselhelper.cpp
QTfrontend/teamselhelper.h
--- a/QTfrontend/frameTeam.cpp	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/frameTeam.cpp	Sat Sep 09 16:59:10 2006 +0000
@@ -34,6 +34,5 @@
 {
   tmapTeamToWidget::iterator it=teamToWidget.find(team);
   QWidget* ret = it!=teamToWidget.end() ? it->second : 0;
-  if(!ret) throw; // FIXME: this is debug exception
   return ret;
 }
--- a/QTfrontend/game.cpp	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/game.cpp	Sat Sep 09 16:59:10 2006 +0000
@@ -250,11 +250,12 @@
 				.arg(error) + bindir->absolutePath() + "/hwengine)");
 }
 
-void HWGame::AddTeam(const QString & teamname)
+void HWGame::AddTeam(const QString & teamname, unsigned char numHedgedogs)
 {
 	if (TeamCount == 5) return;
 	teams[TeamCount] = teamname;
 	TeamCount++;
+	hdNum[teamname]=numHedgedogs;
 }
 
 void HWGame::SaveDemo(const QString & filename)
--- a/QTfrontend/game.h	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/game.h	Sat Sep 09 16:59:10 2006 +0000
@@ -43,6 +43,8 @@
 #include <QProcess>
 #include "team.h"
 
+#include <map>
+
 #define IPC_PORT 46631
 #define MAXMSGCHARS 255
 #define SENDIPC(a) SendIPC(a, sizeof(a) - 1)
@@ -55,7 +57,7 @@
 	Q_OBJECT
 public:
 	HWGame(GameUIConfig * config, GameCFGWidget * gamecfg);
-	void AddTeam(const QString & team);
+	void AddTeam(const QString & team, unsigned char numHedgedogs);
 	void PlayDemo(const QString & demofilename);
 	void StartLocal();
 	void StartQuick();
@@ -80,6 +82,7 @@
 	char msgbuf[MAXMSGCHARS];
 	QByteArray readbuffer;
 	QString teams[5];
+	std::map<QString, unsigned char> hdNum;
 	QString seed;
 	int TeamCount;
 	QByteArray * demo;
--- a/QTfrontend/gameuiconfig.cpp	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/gameuiconfig.cpp	Sat Sep 09 16:59:10 2006 +0000
@@ -94,7 +94,13 @@
 
 QStringList GameUIConfig::GetTeamsList()
 {
-	return cfgdir->entryList(QStringList("*.cfg"));
+	QStringList teamslist = cfgdir->entryList(QStringList("*.cfg"));
+	QStringList cleanedList;
+	for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
+	  QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1");
+	  cleanedList.push_back(tmpTeamStr);
+	}
+	return cleanedList;
 }
 
 void GameUIConfig::SaveOptions()
--- a/QTfrontend/hedgehogerWidget.cpp	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/hedgehogerWidget.cpp	Sat Sep 09 16:59:10 2006 +0000
@@ -4,7 +4,7 @@
 #include <QPainter>
 
 CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) :
-  QWidget(parent), numHedgedogs(4)
+  QWidget(parent), numHedgehogs(4)
 {
 }
 
@@ -12,10 +12,10 @@
 {
   if(event->button()==Qt::LeftButton) {
     event->accept();
-    if(numHedgedogs < 8) numHedgedogs++;
+    if(numHedgehogs < 8) numHedgehogs++;
   } else if (event->button()==Qt::RightButton) {
     event->accept();
-    if(numHedgedogs > 3) numHedgedogs--;
+    if(numHedgehogs > 3) numHedgehogs--;
   } else {
     event->ignore();
     return;
@@ -29,8 +29,13 @@
 
   QPainter painter(this);
 
-  for(int i=0; i<numHedgedogs; i++) {
+  for(int i=0; i<numHedgehogs; i++) {
     QRect target(11 * i, i % 2, 25, 25);
     painter.drawImage(target, image);
   }
 }
+
+unsigned char CHedgehogerWidget::getHedgehogsNum()
+{
+  return numHedgehogs;
+}
--- a/QTfrontend/hedgehogerWidget.h	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/hedgehogerWidget.h	Sat Sep 09 16:59:10 2006 +0000
@@ -9,13 +9,14 @@
 
  public:
   CHedgehogerWidget(QWidget * parent = 0);
+  unsigned char getHedgehogsNum();
 
  protected:
   virtual void paintEvent(QPaintEvent* event);
   virtual void mousePressEvent ( QMouseEvent * event );
   
  private:
-  unsigned char numHedgedogs;
+  unsigned char numHedgehogs;
 };
 
 #endif // _HEDGEHOGER_WIDGET
--- a/QTfrontend/hwform.cpp	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/hwform.cpp	Sat Sep 09 16:59:10 2006 +0000
@@ -67,9 +67,8 @@
 
 	for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it )
 	{
-	  QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1");
-	  ui.pageMultiplayer->teamsSelect->addTeam(tmpTeamStr);
-	  ui.pageOptions->CBTeamName->addItem(tmpTeamStr);
+	  ui.pageMultiplayer->teamsSelect->addTeam(*it);
+	  ui.pageOptions->CBTeamName->addItem(*it);
 	}
 
 	connect(ui.pageMain->BtnSinglePlayer,	SIGNAL(clicked()),	this, SLOT(GoToSinglePlayer()));
@@ -258,7 +257,11 @@
 void HWForm::StartMPGame()
 {
 	game = new HWGame(config, ui.pageMultiplayer->gameCFG);
-	game->AddTeam("DefaultTeam");
-	game->AddTeam("DefaultTeam");
+	QStringList teamslist = config->GetTeamsList();
+	for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
+	  if(ui.pageMultiplayer->teamsSelect->isPlaying(*it)) {
+	    game->AddTeam(*it, ui.pageMultiplayer->teamsSelect->numHedgedogs(*it));
+	  }
+	}
 	game->StartLocal();
 }
--- a/QTfrontend/teamselect.cpp	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/teamselect.cpp	Sat Sep 09 16:59:10 2006 +0000
@@ -77,3 +77,19 @@
   addScrArea(framePlaying, QColor("DarkTurquoise"));
   addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow"));
 }
+
+void TeamSelWidget::resetPlayingTeams()
+{
+}
+
+bool TeamSelWidget::isPlaying(HWTeam team)
+{
+  return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end();
+}
+
+unsigned char TeamSelWidget::numHedgedogs(HWTeam team)
+{
+  TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team));
+  if(!tsw) return 0;
+  return tsw->getHedgehogsNum();
+}
--- a/QTfrontend/teamselect.h	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/teamselect.h	Sat Sep 09 16:59:10 2006 +0000
@@ -23,6 +23,9 @@
   TeamSelWidget(QWidget* parent=0);
   void addTeam(HWTeam team);
   //void removeTeam(HWTeam team);
+  void resetPlayingTeams();
+  bool isPlaying(HWTeam team);
+  unsigned char numHedgedogs(HWTeam team);
 
 private slots:
   void changeTeamStatus(HWTeam team);
--- a/QTfrontend/teamselhelper.cpp	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/teamselhelper.cpp	Sat Sep 09 16:59:10 2006 +0000
@@ -5,15 +5,13 @@
 #include <QPushButton>
 #include <QPainter>
 
-#include "hedgehogerWidget.h"
-
 void TeamLabel::teamButtonClicked()
 {
   emit teamActivated(text());
 }
 
 TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) :
-  QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying)
+  QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0)
 {
   mainLayout.setSpacing(1);
   mainLayout.setMargin(2);
@@ -37,7 +35,7 @@
   mainLayout.addWidget(bText);
 
   if(m_isPlaying) {
-    CHedgehogerWidget* phhoger=new CHedgehogerWidget(this);
+    phhoger=new CHedgehogerWidget(this);
     mainLayout.addWidget(phhoger);
   }
 
@@ -49,3 +47,8 @@
 {
   emit teamStatusChanged(m_team);
 }
+
+unsigned char TeamShowWidget::getHedgehogsNum()
+{
+  return phhoger ? phhoger->getHedgehogsNum() : 0;
+}
--- a/QTfrontend/teamselhelper.h	Sun Sep 03 18:01:34 2006 +0000
+++ b/QTfrontend/teamselhelper.h	Sat Sep 09 16:59:10 2006 +0000
@@ -6,6 +6,7 @@
 #include <QString>
 
 #include "teamselect.h"
+#include "hedgehogerWidget.h"
 
 class TeamLabel : public QLabel
 {
@@ -32,11 +33,13 @@
  public:
  TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent = 0);
  void setPlaying(bool isPlaying);
+ unsigned char getHedgehogsNum();
  
  private:
  QHBoxLayout mainLayout;
  HWTeam m_team;
  bool m_isPlaying;
+ CHedgehogerWidget* phhoger;
 
  signals:
  void teamStatusChanged(HWTeam team);