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