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