network colors (alpha)
authordisplacer
Sat, 27 Jan 2007 17:41:08 +0000
changeset 372 4bac77f8cd38
parent 371 731ad6d27bd1
child 373 df912aab6b7e
network colors (alpha)
QTfrontend/frameTeam.cpp
QTfrontend/frameTeam.h
QTfrontend/hwform.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
QTfrontend/teamselect.cpp
QTfrontend/teamselect.h
QTfrontend/teamselhelper.cpp
QTfrontend/teamselhelper.h
--- a/QTfrontend/frameTeam.cpp	Sat Jan 27 14:18:33 2007 +0000
+++ b/QTfrontend/frameTeam.cpp	Sat Jan 27 17:41:08 2007 +0000
@@ -76,10 +76,17 @@
 void FrameTeams::setHHNum(const HWTeam& team)
 {
   TeamShowWidget* pTeamShowWidget = dynamic_cast<TeamShowWidget*>(getTeamWidget(team));
-  if(!pTeamShowWidget) throw;
+  if(!pTeamShowWidget) return;
   pTeamShowWidget->setHHNum(team.numHedgehogs);
 }
 
+void FrameTeams::setTeamColor(const HWTeam& team)
+{
+  TeamShowWidget* pTeamShowWidget = dynamic_cast<TeamShowWidget*>(getTeamWidget(team));
+  if(!pTeamShowWidget) return;
+  pTeamShowWidget->changeTeamColor(team.teamColor);
+}
+
 QWidget* FrameTeams::getTeamWidget(HWTeam team)
 {
   tmapTeamToWidget::iterator it=teamToWidget.find(team);
@@ -91,3 +98,8 @@
 {
   return overallHedgehogs==maxHedgehogsPerGame;
 }
+
+void FrameTeams::emitTeamColorChanged(const HWTeam& team)
+{
+  emit teamColorChanged(team);
+}
--- a/QTfrontend/frameTeam.h	Sat Jan 27 14:18:33 2007 +0000
+++ b/QTfrontend/frameTeam.h	Sat Jan 27 17:41:08 2007 +0000
@@ -39,8 +39,12 @@
   bool isFullTeams() const;
   void resetColors();
   void setHHNum(const HWTeam& team);
+  void setTeamColor(const HWTeam& team);
   void setNonInteractive();
 
+ signals:
+  void teamColorChanged(const HWTeam&);
+
  public slots:
   void addTeam(HWTeam team, bool willPlay);
   void removeTeam(HWTeam team);
@@ -51,6 +55,8 @@
   QList<QColor> availableColors;
   QList<QColor>::Iterator currentColor;
 
+  void emitTeamColorChanged(const HWTeam& team);
+
   QVBoxLayout mainLayout;
   typedef QMultiMap<HWTeam, QWidget*> tmapTeamToWidget;
   tmapTeamToWidget teamToWidget;
--- a/QTfrontend/hwform.cpp	Sat Jan 27 14:18:33 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sat Jan 27 17:41:08 2007 +0000
@@ -248,6 +248,8 @@
 
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)),
 		hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&)));
+	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)),
+		hwnet, SLOT(onTeamColorChanged(const HWTeam&)));
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamNotPlaying(const HWTeam&)), hwnet, SLOT(RemoveTeam(const HWTeam&)));
 
@@ -266,7 +268,8 @@
 	connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool)));
 	connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), 
 		ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&)));
-
+	connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), 
+		ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&)));
 
 	hwnet->Connect(hostName, port, nick);
 	config->SaveOptions();
--- a/QTfrontend/newnetclient.cpp	Sat Jan 27 14:18:33 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Sat Jan 27 17:41:08 2007 +0000
@@ -245,6 +245,15 @@
 	  emit hhnumChanged(tmptm);
 	  return;
   	}
+  	if (lst[1] == "TEAM_COLOR") {
+	  HWTeam tmptm(lst[2], lst[3].toUInt());
+	  if(m_networkToLocalteams.find(lst[3].toUInt())!=m_networkToLocalteams.end()) {
+	    tmptm=HWTeam(lst[2]); // local team should be changed
+	  }
+	  tmptm.teamColor=QColor(lst[4]);
+	  emit teamColorChanged(tmptm);
+	  return;
+  	}
   	qDebug() << "unknow config param: " << lst[1];
     return;
   }
@@ -289,6 +298,14 @@
 	     .arg(team.numHedgehogs));
 }
 
+void HWNewNet::onTeamColorChanged(const HWTeam& team)
+{
+  qDebug() << team.getNetID() << ":" << team.teamColor.name();
+  RawSendNet(QString("CONFIG_PARAM%1TEAM_COLOR%1%2%1%3%1%4").arg(delimeter).arg(team.TeamName)\
+	     .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
+	     .arg(team.teamColor.name()));
+}
+
 void HWNewNet::onSeedChanged(const QString & seed)
 {
   RawSendNet(QString("CONFIG_PARAM%1SEED%1%2").arg(delimeter).arg(seed));
--- a/QTfrontend/newnetclient.h	Sat Jan 27 14:18:33 2007 +0000
+++ b/QTfrontend/newnetclient.h	Sat Jan 27 17:41:08 2007 +0000
@@ -98,6 +98,7 @@
   void turnTimeChanged(quint32 time);
   void fortsModeChanged(bool value);
   void hhnumChanged(const HWTeam&);
+  void teamColorChanged(const HWTeam&);
 
  public slots:
   void SendNet(const QByteArray & buf);
@@ -110,6 +111,7 @@
   void onTurnTimeChanged(quint32 time);
   void onFortsModeChanged(bool value);
   void onHedgehogsNumChanged(const HWTeam& team);
+  void onTeamColorChanged(const HWTeam& team);
 
  private slots:
   void ClientRead();
--- a/QTfrontend/teamselect.cpp	Sat Jan 27 14:18:33 2007 +0000
+++ b/QTfrontend/teamselect.cpp	Sat Jan 27 17:41:08 2007 +0000
@@ -35,6 +35,8 @@
 		     this, SLOT(netTeamStatusChanged(const HWTeam&)));
     connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), 
 			    this, SLOT(hhNumChanged(const HWTeam&)));
+    connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), 
+			    this, SLOT(proxyTeamColorChanged(const HWTeam&)));
   } else {
     frameDontPlaying->addTeam(team, false);
     curDontPlayingTeams.push_back(team);
@@ -55,14 +57,31 @@
   emit hhogsNumChanged(team);
 }
 
+void TeamSelWidget::proxyTeamColorChanged(const HWTeam& team)
+{
+  QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+  itPlay->teamColor=team.teamColor;
+  emit teamColorChanged(team);
+}
+
 void TeamSelWidget::changeHHNum(const HWTeam& team)
 {
   QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+  if(itPlay==curPlayingTeams.end()) return;
   itPlay->numHedgehogs=team.numHedgehogs;
 
   framePlaying->setHHNum(team);
 }
 
+void TeamSelWidget::changeTeamColor(const HWTeam& team)
+{
+  QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+  if(itPlay==curPlayingTeams.end()) return;
+  itPlay->teamColor=team.teamColor;
+
+  framePlaying->setTeamColor(team);
+}
+
 void TeamSelWidget::removeNetTeam(const HWTeam& team)
 {
   for(;;) {
@@ -123,8 +142,13 @@
   pRemoveTeams->removeTeam(team);
   QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
 		   this, SLOT(changeTeamStatus(HWTeam)));
-  if(willBePlaying) connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), 
-			    this, SLOT(hhNumChanged(const HWTeam&)));
+  if(willBePlaying) {
+    connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), 
+	    this, SLOT(hhNumChanged(const HWTeam&)));
+    connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), 
+	    this, SLOT(proxyTeamColorChanged(const HWTeam&)));
+    emit teamColorChanged(((TeamShowWidget*)framePlaying->getTeamWidget(team))->getTeam());
+  }
 
   QSize szh=pAddTeams->sizeHint();
   QSize szh1=pRemoveTeams->sizeHint();
--- a/QTfrontend/teamselect.h	Sat Jan 27 14:18:33 2007 +0000
+++ b/QTfrontend/teamselect.h	Sat Jan 27 17:41:08 2007 +0000
@@ -50,17 +50,20 @@
   void addTeam(HWTeam team);
   void netTeamStatusChanged(const HWTeam& team);
   void changeHHNum(const HWTeam&);
+  void changeTeamColor(const HWTeam&);
   
  signals:
   void NewTeam();
   void teamWillPlay(HWTeam team);
   void teamNotPlaying(const HWTeam& team);
   void hhogsNumChanged(const HWTeam&);
+  void teamColorChanged(const HWTeam&);
   
  private slots:
   void changeTeamStatus(HWTeam team);
   void newTeamClicked();
   void hhNumChanged(const HWTeam& team);
+  void proxyTeamColorChanged(const HWTeam& team);
 
  private:
   void addScrArea(FrameTeams* pfteams, QColor color, int maxHeight);
--- a/QTfrontend/teamselhelper.cpp	Sat Jan 27 14:18:33 2007 +0000
+++ b/QTfrontend/teamselhelper.cpp	Sat Jan 27 17:41:08 2007 +0000
@@ -111,17 +111,27 @@
   return params;
 }*/
 
-void TeamShowWidget::changeTeamColor()
+void TeamShowWidget::changeTeamColor(QColor color)
 {
   FrameTeams* pOurFrameTeams=dynamic_cast<FrameTeams*>(parentWidget());
-  if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) {
-    pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
+  if(!color.isValid()) {
+    if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) {
+      pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
+    }
+    color=QColor(*pOurFrameTeams->currentColor);
   }
 
   QPalette newPalette = palette();
-  newPalette.setColor(QPalette::Button, QColor(*pOurFrameTeams->currentColor));
-  newPalette.setColor(QPalette::Highlight, QColor(*pOurFrameTeams->currentColor));
+  newPalette.setColor(QPalette::Button, color);
+  newPalette.setColor(QPalette::Highlight, color);
   //colorButt->setStyleSheet(QString("background-color : ")+pOurFrameTeams->currentColor->name());
   colorButt->setStyle(QStyleFactory::create("plastique"));
   colorButt->setPalette(newPalette);
+  m_team.teamColor=color;
+  emit teamColorChanged(m_team);
 }
+
+HWTeam TeamShowWidget::getTeam() const
+{
+  return m_team;
+}
--- a/QTfrontend/teamselhelper.h	Sat Jan 27 14:18:33 2007 +0000
+++ b/QTfrontend/teamselhelper.h	Sat Jan 27 17:41:08 2007 +0000
@@ -46,15 +46,19 @@
 {
  Q_OBJECT
 
+ public slots:
+ void changeTeamColor(QColor color=QColor());
+
  private slots:
  void activateTeam();
- void changeTeamColor();
+ void hhNumChanged();
 
  public:
  TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent);
  void setPlaying(bool isPlaying);
  void setHHNum(unsigned int num);
  void setNonInteractive();
+ HWTeam getTeam() const;
 
  private:
  TeamShowWidget();
@@ -66,12 +70,10 @@
  QPushButton* butt;
  QPushButton* bText;
 
- private slots:
-  void hhNumChanged();
-
  signals:
  void teamStatusChanged(HWTeam team);
  void hhNmChanged(const HWTeam&);
+ void teamColorChanged(const HWTeam&);
 };
 
 #endif // _TEAMSEL_HELPER_INCLUDED