author | unc0rr |
Wed, 26 Dec 2007 22:16:22 +0000 | |
changeset 686 | 494b5880989a |
parent 572 | 302ad5c3836d |
child 884 | 99cc72c8a812 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
486 | 3 |
* Copyright (c) 2006, 2007 Ulyanov Igor <iulyanov@gmail.com> |
184 | 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 |
||
572 | 19 |
#include <algorithm> |
20 |
||
184 | 21 |
#include <QLabel> |
22 |
#include <QPixmap> |
|
23 |
#include <QPushButton> |
|
24 |
#include <QFrame> |
|
25 |
||
26 |
#include <vertScrollArea.h> |
|
27 |
#include "teamselect.h" |
|
28 |
#include "teamselhelper.h" |
|
29 |
#include "frameTeam.h" |
|
30 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
322
diff
changeset
|
31 |
void TeamSelWidget::addTeam(HWTeam team) |
184 | 32 |
{ |
352 | 33 |
if(team.isNetTeam()) { |
322 | 34 |
framePlaying->addTeam(team, true); |
35 |
curPlayingTeams.push_back(team); |
|
352 | 36 |
connect(framePlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
347 | 37 |
this, SLOT(netTeamStatusChanged(const HWTeam&))); |
486 | 38 |
connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), |
356
ca3a5dfcae75
network teams hedgehogs nums modifications now working from chief client
displacer
parents:
352
diff
changeset
|
39 |
this, SLOT(hhNumChanged(const HWTeam&))); |
523
eddcef907b28
num hedgehogs while new team addition (dirty) fixed
displacer
parents:
492
diff
changeset
|
40 |
dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team))->hhNumChanged(); |
486 | 41 |
connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 42 |
this, SLOT(proxyTeamColorChanged(const HWTeam&))); |
322 | 43 |
} else { |
44 |
frameDontPlaying->addTeam(team, false); |
|
45 |
curDontPlayingTeams.push_back(team); |
|
373 | 46 |
if(m_acceptOuter) { |
47 |
connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
48 |
this, SLOT(pre_changeTeamStatus(HWTeam))); |
|
49 |
} else { |
|
50 |
connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
51 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
52 |
} |
|
322 | 53 |
} |
492 | 54 |
emit setEnabledGameStart(curPlayingTeams.size()>1); |
184 | 55 |
} |
56 |
||
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
57 |
void TeamSelWidget::setNonInteractive() |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
58 |
{ |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
59 |
framePlaying->setNonInteractive(); |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
60 |
} |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
61 |
|
352 | 62 |
void TeamSelWidget::hhNumChanged(const HWTeam& team) |
63 |
{ |
|
64 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
65 |
itPlay->numHedgehogs=team.numHedgehogs; |
|
66 |
emit hhogsNumChanged(team); |
|
67 |
} |
|
68 |
||
372 | 69 |
void TeamSelWidget::proxyTeamColorChanged(const HWTeam& team) |
70 |
{ |
|
71 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
72 |
itPlay->teamColor=team.teamColor; |
|
73 |
emit teamColorChanged(team); |
|
74 |
} |
|
75 |
||
352 | 76 |
void TeamSelWidget::changeHHNum(const HWTeam& team) |
77 |
{ |
|
78 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
372 | 79 |
if(itPlay==curPlayingTeams.end()) return; |
352 | 80 |
itPlay->numHedgehogs=team.numHedgehogs; |
81 |
||
82 |
framePlaying->setHHNum(team); |
|
83 |
} |
|
84 |
||
372 | 85 |
void TeamSelWidget::changeTeamColor(const HWTeam& team) |
86 |
{ |
|
87 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
88 |
if(itPlay==curPlayingTeams.end()) return; |
|
89 |
itPlay->teamColor=team.teamColor; |
|
90 |
||
91 |
framePlaying->setTeamColor(team); |
|
92 |
} |
|
93 |
||
347 | 94 |
void TeamSelWidget::removeNetTeam(const HWTeam& team) |
95 |
{ |
|
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
96 |
for(;;) { |
352 | 97 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
98 |
if(itPlay==curPlayingTeams.end()) break; |
352 | 99 |
if(itPlay->isNetTeam()) { |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
100 |
QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam))); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
101 |
framePlaying->removeTeam(team); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
102 |
curPlayingTeams.erase(itPlay); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
103 |
break; |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
104 |
} |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
105 |
} |
492 | 106 |
emit setEnabledGameStart(curPlayingTeams.size()>1); |
347 | 107 |
} |
108 |
||
109 |
void TeamSelWidget::netTeamStatusChanged(const HWTeam& team) |
|
110 |
{ |
|
352 | 111 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
486 | 112 |
|
347 | 113 |
} |
114 |
||
184 | 115 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) |
116 |
//{ |
|
117 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); |
|
118 |
//} |
|
119 |
||
120 |
void TeamSelWidget::changeTeamStatus(HWTeam team) |
|
121 |
{ |
|
352 | 122 |
QList<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team); |
123 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
184 | 124 |
|
125 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end(); |
|
126 |
||
127 |
if(!willBePlaying) { |
|
128 |
// playing team => dont playing |
|
129 |
curDontPlayingTeams.push_back(*itPlay); |
|
347 | 130 |
emit teamNotPlaying(*itPlay); |
184 | 131 |
curPlayingTeams.erase(itPlay); |
132 |
} else { |
|
133 |
// return if max playing teams reached |
|
134 |
if(framePlaying->isFullTeams()) return; |
|
135 |
// dont playing team => playing |
|
482
61c617f1bec7
correct team info in frames (displaying bots difficulty fixed)
displacer
parents:
387
diff
changeset
|
136 |
team=*itDontPlay; // for net team info saving in framePlaying (we have only name with netID from network) |
387 | 137 |
itDontPlay->teamColor=framePlaying->getNextColor(); |
184 | 138 |
curPlayingTeams.push_back(*itDontPlay); |
373 | 139 |
if(!m_acceptOuter) emit teamWillPlay(*itDontPlay); |
184 | 140 |
curDontPlayingTeams.erase(itDontPlay); |
141 |
} |
|
142 |
||
143 |
FrameTeams* pRemoveTeams; |
|
144 |
FrameTeams* pAddTeams; |
|
145 |
if(!willBePlaying) { |
|
146 |
pRemoveTeams=framePlaying; |
|
147 |
pAddTeams=frameDontPlaying; |
|
148 |
} else { |
|
149 |
pRemoveTeams=frameDontPlaying; |
|
150 |
pAddTeams=framePlaying; |
|
151 |
} |
|
152 |
||
153 |
pAddTeams->addTeam(team, willBePlaying); |
|
154 |
pRemoveTeams->removeTeam(team); |
|
384
29299ca39155
adding the same command twice bug fixed for net game
displacer
parents:
383
diff
changeset
|
155 |
if(!team.isNetTeam() && m_acceptOuter && !willBePlaying) { |
29299ca39155
adding the same command twice bug fixed for net game
displacer
parents:
383
diff
changeset
|
156 |
connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
29299ca39155
adding the same command twice bug fixed for net game
displacer
parents:
383
diff
changeset
|
157 |
this, SLOT(pre_changeTeamStatus(HWTeam))); |
29299ca39155
adding the same command twice bug fixed for net game
displacer
parents:
383
diff
changeset
|
158 |
} else { |
29299ca39155
adding the same command twice bug fixed for net game
displacer
parents:
383
diff
changeset
|
159 |
connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
29299ca39155
adding the same command twice bug fixed for net game
displacer
parents:
383
diff
changeset
|
160 |
this, SLOT(changeTeamStatus(HWTeam))); |
29299ca39155
adding the same command twice bug fixed for net game
displacer
parents:
383
diff
changeset
|
161 |
} |
372 | 162 |
if(willBePlaying) { |
486 | 163 |
connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), |
372 | 164 |
this, SLOT(hhNumChanged(const HWTeam&))); |
523
eddcef907b28
num hedgehogs while new team addition (dirty) fixed
displacer
parents:
492
diff
changeset
|
165 |
dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team))->hhNumChanged(); |
486 | 166 |
connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 167 |
this, SLOT(proxyTeamColorChanged(const HWTeam&))); |
168 |
emit teamColorChanged(((TeamShowWidget*)framePlaying->getTeamWidget(team))->getTeam()); |
|
169 |
} |
|
184 | 170 |
|
171 |
QSize szh=pAddTeams->sizeHint(); |
|
172 |
QSize szh1=pRemoveTeams->sizeHint(); |
|
173 |
if(szh.isValid() && szh1.isValid()) { |
|
174 |
pAddTeams->resize(pAddTeams->size().width(), szh.height()); |
|
175 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); |
|
176 |
} |
|
492 | 177 |
|
178 |
emit setEnabledGameStart(curPlayingTeams.size()>1); |
|
184 | 179 |
} |
180 |
||
311 | 181 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int maxHeight) |
184 | 182 |
{ |
183 |
VertScrArea* area=new VertScrArea(color); |
|
184 |
area->setWidget(pfteams); |
|
185 |
mainLayout.addWidget(area, 30); |
|
311 | 186 |
if (maxHeight > 0) |
187 |
area->setMaximumHeight(maxHeight); |
|
184 | 188 |
} |
189 |
||
190 |
TeamSelWidget::TeamSelWidget(QWidget* parent) : |
|
373 | 191 |
QGroupBox(parent), mainLayout(this), m_acceptOuter(false) |
184 | 192 |
{ |
240 | 193 |
setTitle(QGroupBox::tr("Playing teams")); |
184 | 194 |
framePlaying=new FrameTeams(); |
195 |
frameDontPlaying=new FrameTeams(); |
|
244 | 196 |
// addScrArea(framePlaying, QColor("DarkTurquoise")); |
197 |
// addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow")); |
|
198 |
QPalette p; |
|
311 | 199 |
addScrArea(framePlaying, p.color(QPalette::Window).light(105), 200); |
200 |
addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0); |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
201 |
QPushButton * btnSetup = new QPushButton(this); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
202 |
btnSetup->setText(QPushButton::tr("Setup")); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
203 |
connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked())); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
204 |
mainLayout.addWidget(btnSetup); |
184 | 205 |
} |
206 |
||
373 | 207 |
void TeamSelWidget::setAcceptOuter(bool acceptOuter) |
208 |
{ |
|
209 |
m_acceptOuter=acceptOuter; |
|
210 |
} |
|
211 |
||
231 | 212 |
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist) |
184 | 213 |
{ |
352 | 214 |
QList<HWTeam>::iterator it; |
383 | 215 |
//for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { |
216 |
//framePlaying->removeTeam(*it); |
|
217 |
//} |
|
218 |
framePlaying->resetTeams(); |
|
207 | 219 |
framePlaying->resetColors(); |
184 | 220 |
curPlayingTeams.clear(); |
383 | 221 |
//for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { |
222 |
//frameDontPlaying->removeTeam(*it); |
|
223 |
//} |
|
224 |
frameDontPlaying->resetTeams(); |
|
184 | 225 |
curDontPlayingTeams.clear(); |
226 |
||
231 | 227 |
for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
184 | 228 |
addTeam(*it); |
229 |
} |
|
230 |
} |
|
231 |
||
232 |
bool TeamSelWidget::isPlaying(HWTeam team) const |
|
233 |
{ |
|
234 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); |
|
235 |
} |
|
236 |
||
352 | 237 |
QList<HWTeam> TeamSelWidget::getPlayingTeams() const |
184 | 238 |
{ |
239 |
return curPlayingTeams; |
|
240 |
} |
|
241 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
242 |
QList<HWTeam> TeamSelWidget::getDontPlayingTeams() const |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
243 |
{ |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
244 |
return curDontPlayingTeams; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
245 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
246 |
|
373 | 247 |
void TeamSelWidget::pre_changeTeamStatus(HWTeam team) |
248 |
{ |
|
382
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
373
diff
changeset
|
249 |
team.teamColor=framePlaying->getNextColor(); |
373 | 250 |
emit acceptRequested(team); |
251 |
} |