author | nemo |
Mon, 01 Mar 2010 00:19:23 +0000 | |
changeset 2892 | ac3b29b10bd9 |
parent 2522 | 42986b9ebc74 |
child 2948 | 3f21a9dc93d0 |
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 |
|
2522 | 27 |
#include "vertScrollArea.h" |
184 | 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 |
||
1475
bab5650fc894
- Fix ConfigAsked not sending full config (leads to team divide checkbox inconsistency)
unc0rr
parents:
1425
diff
changeset
|
58 |
void TeamSelWidget::setInteractivity(bool interactive) |
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
59 |
{ |
1475
bab5650fc894
- Fix ConfigAsked not sending full config (leads to team divide checkbox inconsistency)
unc0rr
parents:
1425
diff
changeset
|
60 |
framePlaying->setInteractivity(interactive); |
362
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 |
{ |
|
2110 | 115 |
//qDebug() << QString("removeNetTeam: removing team '%1'").arg(team.TeamName); |
884 | 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 |
||
1647 | 205 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int fixedHeight) |
184 | 206 |
{ |
1425 | 207 |
VertScrArea* area = new VertScrArea(color); |
208 |
area->setWidget(pfteams); |
|
209 |
mainLayout.addWidget(area, 30); |
|
1647 | 210 |
if (fixedHeight > 0) |
1425 | 211 |
{ |
1647 | 212 |
area->setMinimumHeight(fixedHeight); |
213 |
area->setMaximumHeight(fixedHeight); |
|
1425 | 214 |
area->setStyleSheet( |
215 |
"FrameTeams{" |
|
216 |
"border: solid;" |
|
217 |
"border-width: 1px;" |
|
218 |
"border-radius: 16px;" |
|
219 |
"border-color: #ffcc00;" |
|
220 |
"}" |
|
221 |
); |
|
222 |
} |
|
184 | 223 |
} |
224 |
||
225 |
TeamSelWidget::TeamSelWidget(QWidget* parent) : |
|
373 | 226 |
QGroupBox(parent), mainLayout(this), m_acceptOuter(false) |
184 | 227 |
{ |
1424 | 228 |
setTitle(QGroupBox::tr("Playing teams")); |
229 |
framePlaying = new FrameTeams(); |
|
230 |
frameDontPlaying = new FrameTeams(); |
|
2377 | 231 |
|
1424 | 232 |
QPalette p; |
233 |
p.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); |
|
1647 | 234 |
addScrArea(framePlaying, p.color(QPalette::Window).light(105), 250); |
1424 | 235 |
addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0); |
236 |
QPushButton * btnSetup = new QPushButton(this); |
|
237 |
btnSetup->setText(QPushButton::tr("Setup")); |
|
238 |
connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked())); |
|
239 |
mainLayout.addWidget(btnSetup); |
|
184 | 240 |
} |
241 |
||
373 | 242 |
void TeamSelWidget::setAcceptOuter(bool acceptOuter) |
243 |
{ |
|
244 |
m_acceptOuter=acceptOuter; |
|
245 |
} |
|
246 |
||
231 | 247 |
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist) |
184 | 248 |
{ |
352 | 249 |
QList<HWTeam>::iterator it; |
383 | 250 |
//for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { |
251 |
//framePlaying->removeTeam(*it); |
|
252 |
//} |
|
253 |
framePlaying->resetTeams(); |
|
207 | 254 |
framePlaying->resetColors(); |
184 | 255 |
curPlayingTeams.clear(); |
383 | 256 |
//for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { |
257 |
//frameDontPlaying->removeTeam(*it); |
|
258 |
//} |
|
259 |
frameDontPlaying->resetTeams(); |
|
184 | 260 |
curDontPlayingTeams.clear(); |
261 |
||
231 | 262 |
for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
184 | 263 |
addTeam(*it); |
264 |
} |
|
265 |
} |
|
266 |
||
267 |
bool TeamSelWidget::isPlaying(HWTeam team) const |
|
268 |
{ |
|
269 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); |
|
270 |
} |
|
271 |
||
352 | 272 |
QList<HWTeam> TeamSelWidget::getPlayingTeams() const |
184 | 273 |
{ |
274 |
return curPlayingTeams; |
|
275 |
} |
|
276 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
277 |
QList<HWTeam> TeamSelWidget::getDontPlayingTeams() const |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
278 |
{ |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
279 |
return curDontPlayingTeams; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
280 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
523
diff
changeset
|
281 |
|
373 | 282 |
void TeamSelWidget::pre_changeTeamStatus(HWTeam team) |
283 |
{ |
|
382
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
373
diff
changeset
|
284 |
team.teamColor=framePlaying->getNextColor(); |
373 | 285 |
emit acceptRequested(team); |
286 |
} |