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