TeamSelect widget alpha added
authordisplacer
Sun, 15 Jan 2006 23:31:34 +0000
changeset 50 9ab4067dabec
parent 49 3afe33c1cf06
child 51 b6e3ae05857f
TeamSelect widget alpha added
QTfrontend/QTfrontend.pro
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/hwform.ui
QTfrontend/teamselect.cpp
QTfrontend/teamselect.h
QTfrontend/teamselhelper.cpp
QTfrontend/teamselhelper.h
--- a/QTfrontend/QTfrontend.pro	Sun Jan 15 14:14:12 2006 +0000
+++ b/QTfrontend/QTfrontend.pro	Sun Jan 15 23:31:34 2006 +0000
@@ -11,5 +11,7 @@
 
 # Input
 HEADERS += binds.h game.h hwform.h sdlkeys.h team.h rndstr.h sha1.h gamecmds.h netclient.h
+HEADERS += teamselect.h teamselhelper.h
 FORMS += hwform.ui
 SOURCES += game.cpp main.cpp hwform.cpp team.cpp rndstr.cpp sha1.cpp gamecmds.cpp netclient.cpp
+SOURCES += teamselect.cpp teamselhelper.cpp
--- a/QTfrontend/hwform.cpp	Sun Jan 15 14:14:12 2006 +0000
+++ b/QTfrontend/hwform.cpp	Sun Jan 15 23:31:34 2006 +0000
@@ -45,6 +45,7 @@
 #include "sdlkeys.h"
 #include "hwconsts.h"
 //#include "gamecmds.h"
+#include "teamselect.h"
 
 HWForm::HWForm(QWidget *parent)
 	: QMainWindow(parent)
@@ -125,7 +126,9 @@
 
 	for (QStringList::Iterator it = list.begin(); it != list.end(); ++it )
 	{
-		ui.CBTeamName->addItem((*it).replace(QRegExp("^(.*).cfg$"), "\\1"));
+	  QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1");
+	  m_teamNames.push_back(tmpTeamStr);
+	  ui.CBTeamName->addItem(tmpTeamStr);
 	}
 
 	QFile settings(cfgdir.absolutePath() + "/options");
@@ -192,6 +195,11 @@
 void HWForm::GoToSinglePlayer()
 {
 	ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER);
+
+	TeamSelWidget* pts=new TeamSelWidget(m_teamNames, ui.Pages->widget(ID_PAGE_SINGLEPLAYER));
+
+	pts->resize(500, 350);
+	pts->show();
 }
 
 void HWForm::GoToSetup()
--- a/QTfrontend/hwform.h	Sun Jan 15 14:14:12 2006 +0000
+++ b/QTfrontend/hwform.h	Sun Jan 15 23:31:34 2006 +0000
@@ -37,12 +37,17 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QDir>
+
+#include <vector>
+
 #include "ui_hwform.h"
 #include "binds.h"
 #include "game.h"
 #include "team.h"
 #include "netclient.h"
 
+using namespace std;
+
 class HWForm : public QMainWindow
 {
 	Q_OBJECT
@@ -89,6 +94,8 @@
 	QDir cfgdir;
 	HWTeam * tmpTeam;
 	HWNet * hwnet;
+
+	vector<QString> m_teamNames;
 };
 
 #define ID_PAGE_SINGLEPLAYER 0
--- a/QTfrontend/hwform.ui	Sun Jan 15 14:14:12 2006 +0000
+++ b/QTfrontend/hwform.ui	Sun Jan 15 23:31:34 2006 +0000
@@ -50,14 +50,14 @@
      </size>
     </property>
     <property name="currentIndex" >
-     <number>1</number>
+     <number>0</number>
     </property>
     <widget class="QWidget" name="pageLG" >
      <widget class="QPushButton" name="BtnSimpleGame" >
       <property name="geometry" >
        <rect>
-        <x>230</x>
-        <y>120</y>
+        <x>330</x>
+        <y>380</y>
         <width>161</width>
         <height>41</height>
        </rect>
@@ -86,8 +86,8 @@
      <widget class="QPushButton" name="BtnSPBack" >
       <property name="geometry" >
        <rect>
-        <x>230</x>
-        <y>170</y>
+        <x>120</x>
+        <y>380</y>
         <width>161</width>
         <height>41</height>
        </rect>
@@ -266,8 +266,8 @@
          <rect>
           <x>0</x>
           <y>0</y>
-          <width>181</width>
-          <height>289</height>
+          <width>96</width>
+          <height>26</height>
          </rect>
         </property>
         <attribute name="label" >
@@ -289,8 +289,8 @@
          <rect>
           <x>0</x>
           <y>0</y>
-          <width>99</width>
-          <height>29</height>
+          <width>96</width>
+          <height>26</height>
          </rect>
         </property>
         <attribute name="label" >
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/teamselect.cpp	Sun Jan 15 23:31:34 2006 +0000
@@ -0,0 +1,57 @@
+#include <QLabel>
+#include <QPixmap>
+#include <QPushButton>
+
+#include <algorithm>
+
+#include "teamselect.h"
+#include "teamselhelper.h"
+
+void TeamSelWidget::addTeam(tmprop team)
+{
+  curDontPlayingTeams.push_back(team);
+  TeamShowWidget* pTeamShowWidget =new TeamShowWidget(team);
+  dontPlayingLayout.addWidget(pTeamShowWidget);
+
+  teamToWidget.insert(make_pair(team, pTeamShowWidget));
+
+  QObject::connect(pTeamShowWidget, SIGNAL(teamStatusChanged(tmprop)), this, SLOT(changeTeamStatus(tmprop)));
+}
+
+void TeamSelWidget::removeTeam(tmprop team)
+{
+  curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
+}
+
+void TeamSelWidget::changeTeamStatus(tmprop team)
+{
+  list<tmprop>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
+  list<tmprop>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
+
+  if(itDontPlay==curDontPlayingTeams.end()) {
+    // playing team => dont playing
+    curDontPlayingTeams.push_back(*itPlay);
+    curPlayingTeams.erase(itPlay);
+  } else {
+    // dont playing team => playing
+    curPlayingTeams.push_back(*itDontPlay);
+    curDontPlayingTeams.erase(itDontPlay);
+  }
+
+  QGridLayout* pRemoveGrid = itDontPlay==curDontPlayingTeams.end() ? &playingLayout : &dontPlayingLayout;
+  QGridLayout* pAddGrid = itDontPlay==curDontPlayingTeams.end() ? &dontPlayingLayout : &playingLayout;
+
+  pRemoveGrid->removeWidget(teamToWidget[team]);
+  pAddGrid->addWidget(teamToWidget[team]);
+}
+
+TeamSelWidget::TeamSelWidget(const vector<QString>& teams, QWidget* parent) :
+  QWidget(parent), mainLayout(this)
+{
+  mainLayout.addLayout(&playingLayout);
+  mainLayout.addLayout(&dontPlayingLayout);
+
+  for(vector<QString>::const_iterator it=teams.begin(); it!=teams.end(); ++it) {
+    addTeam(*it);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/teamselect.h	Sun Jan 15 23:31:34 2006 +0000
@@ -0,0 +1,47 @@
+#ifndef _TEAM_SELECT_INCLUDED
+#define _TEAM_SELECT_INCLUDED
+
+#include <QWidget>
+#include <QVBoxLayout>
+
+#include <list>
+#include <map>
+
+using namespace std;
+
+struct tmprop
+{
+  tmprop(QString nm) : teamName(nm){};
+  QString teamName;
+  QString pixmapFileName;
+  bool operator==(const tmprop& t1) const {
+    return teamName==t1.teamName;
+  };
+  bool operator<(const tmprop& t1) const {
+    return teamName<t1.teamName;
+  };
+};
+
+class TeamSelWidget : public QWidget
+{
+  Q_OBJECT
+ 
+ public:
+  TeamSelWidget(const vector<QString>& teams, QWidget* parent=0);
+  void addTeam(tmprop team);
+  void removeTeam(tmprop team);
+
+private slots:
+  void changeTeamStatus(tmprop team);
+
+ private:
+  QVBoxLayout mainLayout;
+  QGridLayout playingLayout;
+  QGridLayout dontPlayingLayout;
+
+  list<tmprop> curPlayingTeams;
+  list<tmprop> curDontPlayingTeams;
+  map<tmprop, QWidget*> teamToWidget;
+};
+
+#endif // _TEAM_SELECT_INCLUDED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/teamselhelper.cpp	Sun Jan 15 23:31:34 2006 +0000
@@ -0,0 +1,30 @@
+#include "teamselhelper.h"
+
+#include <QPixmap>
+#include <QPushButton>
+
+void TeamLabel::teamButtonClicked()
+{
+  emit teamActivated(text());
+}
+
+TeamShowWidget::TeamShowWidget(tmprop team) :
+  mainLayout(this), m_team(team)
+{
+  QLabel* pixlbl=new QLabel();
+  pixlbl->setPixmap(QPixmap("./Data/Graphics/thinking.png"));
+  mainLayout.addWidget(pixlbl);
+  
+  TeamLabel* lbl=new TeamLabel(team.teamName);
+  mainLayout.addWidget(lbl);
+
+  QPushButton* butt=new QPushButton("o");
+  mainLayout.addWidget(butt);
+
+  QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam()));
+}
+
+void TeamShowWidget::activateTeam()
+{
+  emit teamStatusChanged(m_team);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/teamselhelper.h	Sun Jan 15 23:31:34 2006 +0000
@@ -0,0 +1,43 @@
+#ifndef _TEAMSEL_HELPER_INCLUDED
+#define _TEAMSEL_HELPER_INCLUDED
+
+#include <QLabel>
+#include <QWidget>
+#include <QString>
+
+#include "teamselect.h"
+
+class TeamLabel : public QLabel
+{
+ Q_OBJECT
+
+ public:
+ TeamLabel(const QString& inp_str) : QLabel(inp_str) {};
+
+ signals:
+ void teamActivated(QString team_name);
+
+ public slots:
+ void teamButtonClicked();
+
+};
+
+class TeamShowWidget : public QWidget
+{
+ Q_OBJECT
+
+ private slots:
+ void activateTeam();
+
+ public:
+ TeamShowWidget(tmprop team);
+ 
+ private:
+ QHBoxLayout mainLayout;
+ tmprop m_team;
+
+ signals:
+ void teamStatusChanged(tmprop team);
+};
+
+#endif // _TEAMSEL_HELPER_INCLUDED