author | displacer |
Wed, 17 Jan 2007 21:32:52 +0000 | |
changeset 348 | c91b983de18f |
parent 347 | 6521e1b2cd40 |
child 352 | 4665bfe25470 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2006 Ulyanov Igor <iulyanov@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QLabel> |
|
20 |
#include <QPixmap> |
|
21 |
#include <QPushButton> |
|
22 |
#include <QFrame> |
|
23 |
||
24 |
#include <vertScrollArea.h> |
|
25 |
#include "teamselect.h" |
|
26 |
#include "teamselhelper.h" |
|
27 |
#include "frameTeam.h" |
|
28 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
322
diff
changeset
|
29 |
void TeamSelWidget::addTeam(HWTeam team) |
184 | 30 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
322
diff
changeset
|
31 |
if(team.netTeam) { |
322 | 32 |
framePlaying->addTeam(team, true); |
33 |
curPlayingTeams.push_back(team); |
|
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
34 |
QObject::connect(framePlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
347 | 35 |
this, SLOT(netTeamStatusChanged(const HWTeam&))); |
322 | 36 |
} else { |
37 |
frameDontPlaying->addTeam(team, false); |
|
38 |
curDontPlayingTeams.push_back(team); |
|
39 |
QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
40 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
41 |
} |
|
184 | 42 |
} |
43 |
||
347 | 44 |
void TeamSelWidget::removeNetTeam(const HWTeam& team) |
45 |
{ |
|
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
46 |
for(;;) { |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
47 |
list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
48 |
if(itPlay==curPlayingTeams.end()) break; |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
49 |
if(itPlay->netTeam) { |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
50 |
QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam))); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
51 |
framePlaying->removeTeam(team); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
52 |
curPlayingTeams.erase(itPlay); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
53 |
break; |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
54 |
} |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
55 |
} |
347 | 56 |
} |
57 |
||
58 |
void TeamSelWidget::netTeamStatusChanged(const HWTeam& team) |
|
59 |
{ |
|
60 |
list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
61 |
||
62 |
} |
|
63 |
||
184 | 64 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) |
65 |
//{ |
|
66 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); |
|
67 |
//} |
|
68 |
||
69 |
void TeamSelWidget::changeTeamStatus(HWTeam team) |
|
70 |
{ |
|
71 |
list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team); |
|
72 |
list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
73 |
||
74 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end(); |
|
75 |
||
76 |
if(!willBePlaying) { |
|
77 |
// playing team => dont playing |
|
78 |
curDontPlayingTeams.push_back(*itPlay); |
|
347 | 79 |
emit teamNotPlaying(*itPlay); |
184 | 80 |
curPlayingTeams.erase(itPlay); |
81 |
} else { |
|
82 |
// return if max playing teams reached |
|
83 |
if(framePlaying->isFullTeams()) return; |
|
84 |
// dont playing team => playing |
|
85 |
curPlayingTeams.push_back(*itDontPlay); |
|
322 | 86 |
emit teamWillPlay(*itDontPlay); |
184 | 87 |
curDontPlayingTeams.erase(itDontPlay); |
88 |
} |
|
89 |
||
90 |
FrameTeams* pRemoveTeams; |
|
91 |
FrameTeams* pAddTeams; |
|
92 |
if(!willBePlaying) { |
|
93 |
pRemoveTeams=framePlaying; |
|
94 |
pAddTeams=frameDontPlaying; |
|
95 |
} else { |
|
96 |
pRemoveTeams=frameDontPlaying; |
|
97 |
pAddTeams=framePlaying; |
|
98 |
} |
|
99 |
||
100 |
pAddTeams->addTeam(team, willBePlaying); |
|
101 |
pRemoveTeams->removeTeam(team); |
|
102 |
QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
103 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
104 |
||
105 |
QSize szh=pAddTeams->sizeHint(); |
|
106 |
QSize szh1=pRemoveTeams->sizeHint(); |
|
107 |
if(szh.isValid() && szh1.isValid()) { |
|
108 |
pAddTeams->resize(pAddTeams->size().width(), szh.height()); |
|
109 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); |
|
110 |
} |
|
111 |
} |
|
112 |
||
311 | 113 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int maxHeight) |
184 | 114 |
{ |
115 |
VertScrArea* area=new VertScrArea(color); |
|
116 |
area->setWidget(pfteams); |
|
117 |
mainLayout.addWidget(area, 30); |
|
311 | 118 |
if (maxHeight > 0) |
119 |
area->setMaximumHeight(maxHeight); |
|
184 | 120 |
} |
121 |
||
122 |
TeamSelWidget::TeamSelWidget(QWidget* parent) : |
|
240 | 123 |
QGroupBox(parent), mainLayout(this) |
184 | 124 |
{ |
240 | 125 |
setTitle(QGroupBox::tr("Playing teams")); |
184 | 126 |
framePlaying=new FrameTeams(); |
127 |
frameDontPlaying=new FrameTeams(); |
|
244 | 128 |
// addScrArea(framePlaying, QColor("DarkTurquoise")); |
129 |
// addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow")); |
|
130 |
QPalette p; |
|
311 | 131 |
addScrArea(framePlaying, p.color(QPalette::Window).light(105), 200); |
132 |
addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0); |
|
133 |
newTeam = new QPushButton(this); |
|
134 |
newTeam->setText(QPushButton::tr("New team")); |
|
135 |
connect(newTeam, SIGNAL(clicked()), this, SLOT(newTeamClicked())); |
|
136 |
mainLayout.addWidget(newTeam); |
|
184 | 137 |
} |
138 |
||
231 | 139 |
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist) |
184 | 140 |
{ |
141 |
list<HWTeam>::iterator it; |
|
142 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { |
|
143 |
framePlaying->removeTeam(*it); |
|
144 |
} |
|
207 | 145 |
framePlaying->resetColors(); |
184 | 146 |
curPlayingTeams.clear(); |
147 |
for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { |
|
148 |
frameDontPlaying->removeTeam(*it); |
|
149 |
} |
|
150 |
curDontPlayingTeams.clear(); |
|
151 |
||
231 | 152 |
for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
184 | 153 |
addTeam(*it); |
154 |
} |
|
155 |
} |
|
156 |
||
157 |
bool TeamSelWidget::isPlaying(HWTeam team) const |
|
158 |
{ |
|
159 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); |
|
160 |
} |
|
161 |
||
162 |
list<HWTeam> TeamSelWidget::getPlayingTeams() const |
|
163 |
{ |
|
164 |
return curPlayingTeams; |
|
165 |
} |
|
166 |
||
311 | 167 |
void TeamSelWidget::newTeamClicked() |
168 |
{ |
|
169 |
emit NewTeam(); |
|
170 |
} |