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