# HG changeset patch # User displacer # Date 1137367894 0 # Node ID 9ab4067dabecc50d74a9248572f60fe0d98acb75 # Parent 3afe33c1cf06bbee6be92ae41eeac610141aa8a8 TeamSelect widget alpha added diff -r 3afe33c1cf06 -r 9ab4067dabec QTfrontend/QTfrontend.pro --- 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 diff -r 3afe33c1cf06 -r 9ab4067dabec QTfrontend/hwform.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() diff -r 3afe33c1cf06 -r 9ab4067dabec QTfrontend/hwform.h --- 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 #include #include + +#include + #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 m_teamNames; }; #define ID_PAGE_SINGLEPLAYER 0 diff -r 3afe33c1cf06 -r 9ab4067dabec QTfrontend/hwform.ui --- 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 @@ - 1 + 0 - 230 - 120 + 330 + 380 161 41 @@ -86,8 +86,8 @@ - 230 - 170 + 120 + 380 161 41 @@ -266,8 +266,8 @@ 0 0 - 181 - 289 + 96 + 26 @@ -289,8 +289,8 @@ 0 0 - 99 - 29 + 96 + 26 diff -r 3afe33c1cf06 -r 9ab4067dabec QTfrontend/teamselect.cpp --- /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 +#include +#include + +#include + +#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::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team); + list::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& teams, QWidget* parent) : + QWidget(parent), mainLayout(this) +{ + mainLayout.addLayout(&playingLayout); + mainLayout.addLayout(&dontPlayingLayout); + + for(vector::const_iterator it=teams.begin(); it!=teams.end(); ++it) { + addTeam(*it); + } +} diff -r 3afe33c1cf06 -r 9ab4067dabec QTfrontend/teamselect.h --- /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 +#include + +#include +#include + +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& 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 curPlayingTeams; + list curDontPlayingTeams; + map teamToWidget; +}; + +#endif // _TEAM_SELECT_INCLUDED diff -r 3afe33c1cf06 -r 9ab4067dabec QTfrontend/teamselhelper.cpp --- /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 +#include + +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); +} diff -r 3afe33c1cf06 -r 9ab4067dabec QTfrontend/teamselhelper.h --- /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 +#include +#include + +#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