author | unc0rr |
Fri, 26 Jan 2007 22:36:21 +0000 | |
changeset 369 | 2aed85310727 |
parent 362 | b28e0dd48269 |
child 372 | 4bac77f8cd38 |
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&))); |
322 | 38 |
} else { |
39 |
frameDontPlaying->addTeam(team, false); |
|
40 |
curDontPlayingTeams.push_back(team); |
|
41 |
QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
42 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
43 |
} |
|
184 | 44 |
} |
45 |
||
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
46 |
void TeamSelWidget::setNonInteractive() |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
47 |
{ |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
48 |
framePlaying->setNonInteractive(); |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
49 |
} |
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
50 |
|
352 | 51 |
void TeamSelWidget::hhNumChanged(const HWTeam& team) |
52 |
{ |
|
53 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
54 |
itPlay->numHedgehogs=team.numHedgehogs; |
|
55 |
emit hhogsNumChanged(team); |
|
56 |
} |
|
57 |
||
58 |
void TeamSelWidget::changeHHNum(const HWTeam& team) |
|
59 |
{ |
|
60 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
61 |
itPlay->numHedgehogs=team.numHedgehogs; |
|
62 |
||
63 |
framePlaying->setHHNum(team); |
|
64 |
} |
|
65 |
||
347 | 66 |
void TeamSelWidget::removeNetTeam(const HWTeam& team) |
67 |
{ |
|
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
68 |
for(;;) { |
352 | 69 |
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
|
70 |
if(itPlay==curPlayingTeams.end()) break; |
352 | 71 |
if(itPlay->isNetTeam()) { |
348
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
72 |
QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam))); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
73 |
framePlaying->removeTeam(team); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
74 |
curPlayingTeams.erase(itPlay); |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
75 |
break; |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
76 |
} |
c91b983de18f
equal team names huge bug fixed for multiple clients
displacer
parents:
347
diff
changeset
|
77 |
} |
347 | 78 |
} |
79 |
||
80 |
void TeamSelWidget::netTeamStatusChanged(const HWTeam& team) |
|
81 |
{ |
|
352 | 82 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
347 | 83 |
|
84 |
} |
|
85 |
||
184 | 86 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) |
87 |
//{ |
|
88 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); |
|
89 |
//} |
|
90 |
||
91 |
void TeamSelWidget::changeTeamStatus(HWTeam team) |
|
92 |
{ |
|
352 | 93 |
QList<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team); |
94 |
QList<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
184 | 95 |
|
96 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end(); |
|
97 |
||
98 |
if(!willBePlaying) { |
|
99 |
// playing team => dont playing |
|
100 |
curDontPlayingTeams.push_back(*itPlay); |
|
347 | 101 |
emit teamNotPlaying(*itPlay); |
184 | 102 |
curPlayingTeams.erase(itPlay); |
103 |
} else { |
|
104 |
// return if max playing teams reached |
|
105 |
if(framePlaying->isFullTeams()) return; |
|
106 |
// dont playing team => playing |
|
107 |
curPlayingTeams.push_back(*itDontPlay); |
|
322 | 108 |
emit teamWillPlay(*itDontPlay); |
184 | 109 |
curDontPlayingTeams.erase(itDontPlay); |
110 |
} |
|
111 |
||
112 |
FrameTeams* pRemoveTeams; |
|
113 |
FrameTeams* pAddTeams; |
|
114 |
if(!willBePlaying) { |
|
115 |
pRemoveTeams=framePlaying; |
|
116 |
pAddTeams=frameDontPlaying; |
|
117 |
} else { |
|
118 |
pRemoveTeams=frameDontPlaying; |
|
119 |
pAddTeams=framePlaying; |
|
120 |
} |
|
121 |
||
122 |
pAddTeams->addTeam(team, willBePlaying); |
|
123 |
pRemoveTeams->removeTeam(team); |
|
124 |
QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
125 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
352 | 126 |
if(willBePlaying) connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), |
127 |
this, SLOT(hhNumChanged(const HWTeam&))); |
|
184 | 128 |
|
129 |
QSize szh=pAddTeams->sizeHint(); |
|
130 |
QSize szh1=pRemoveTeams->sizeHint(); |
|
131 |
if(szh.isValid() && szh1.isValid()) { |
|
132 |
pAddTeams->resize(pAddTeams->size().width(), szh.height()); |
|
133 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); |
|
134 |
} |
|
135 |
} |
|
136 |
||
311 | 137 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int maxHeight) |
184 | 138 |
{ |
139 |
VertScrArea* area=new VertScrArea(color); |
|
140 |
area->setWidget(pfteams); |
|
141 |
mainLayout.addWidget(area, 30); |
|
311 | 142 |
if (maxHeight > 0) |
143 |
area->setMaximumHeight(maxHeight); |
|
184 | 144 |
} |
145 |
||
146 |
TeamSelWidget::TeamSelWidget(QWidget* parent) : |
|
240 | 147 |
QGroupBox(parent), mainLayout(this) |
184 | 148 |
{ |
240 | 149 |
setTitle(QGroupBox::tr("Playing teams")); |
184 | 150 |
framePlaying=new FrameTeams(); |
151 |
frameDontPlaying=new FrameTeams(); |
|
244 | 152 |
// addScrArea(framePlaying, QColor("DarkTurquoise")); |
153 |
// addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow")); |
|
154 |
QPalette p; |
|
311 | 155 |
addScrArea(framePlaying, p.color(QPalette::Window).light(105), 200); |
156 |
addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0); |
|
157 |
newTeam = new QPushButton(this); |
|
158 |
newTeam->setText(QPushButton::tr("New team")); |
|
159 |
connect(newTeam, SIGNAL(clicked()), this, SLOT(newTeamClicked())); |
|
160 |
mainLayout.addWidget(newTeam); |
|
184 | 161 |
} |
162 |
||
231 | 163 |
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist) |
184 | 164 |
{ |
352 | 165 |
QList<HWTeam>::iterator it; |
184 | 166 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { |
167 |
framePlaying->removeTeam(*it); |
|
168 |
} |
|
207 | 169 |
framePlaying->resetColors(); |
184 | 170 |
curPlayingTeams.clear(); |
171 |
for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { |
|
172 |
frameDontPlaying->removeTeam(*it); |
|
173 |
} |
|
174 |
curDontPlayingTeams.clear(); |
|
175 |
||
231 | 176 |
for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
184 | 177 |
addTeam(*it); |
178 |
} |
|
179 |
} |
|
180 |
||
181 |
bool TeamSelWidget::isPlaying(HWTeam team) const |
|
182 |
{ |
|
183 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); |
|
184 |
} |
|
185 |
||
352 | 186 |
QList<HWTeam> TeamSelWidget::getPlayingTeams() const |
184 | 187 |
{ |
188 |
return curPlayingTeams; |
|
189 |
} |
|
190 |
||
311 | 191 |
void TeamSelWidget::newTeamClicked() |
192 |
{ |
|
193 |
emit NewTeam(); |
|
194 |
} |