author | displacer |
Mon, 15 Jan 2007 18:45:07 +0000 | |
changeset 339 | 7535ab6c3820 |
parent 322 | e7175ae57945 |
child 341 | 184230eb4151 |
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 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
322
diff
changeset
|
31 |
if(team.netTeam) { |
322 | 32 |
framePlaying->addTeam(team, true); |
33 |
curPlayingTeams.push_back(team); |
|
34 |
} else { |
|
35 |
frameDontPlaying->addTeam(team, false); |
|
36 |
curDontPlayingTeams.push_back(team); |
|
37 |
QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
38 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
39 |
} |
|
184 | 40 |
} |
41 |
||
42 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) |
|
43 |
//{ |
|
44 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); |
|
45 |
//} |
|
46 |
||
47 |
void TeamSelWidget::changeTeamStatus(HWTeam team) |
|
48 |
{ |
|
49 |
list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team); |
|
50 |
list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); |
|
51 |
||
52 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end(); |
|
53 |
||
54 |
if(!willBePlaying) { |
|
55 |
// playing team => dont playing |
|
56 |
curDontPlayingTeams.push_back(*itPlay); |
|
57 |
curPlayingTeams.erase(itPlay); |
|
58 |
} else { |
|
59 |
// return if max playing teams reached |
|
60 |
if(framePlaying->isFullTeams()) return; |
|
61 |
// dont playing team => playing |
|
62 |
curPlayingTeams.push_back(*itDontPlay); |
|
322 | 63 |
emit teamWillPlay(*itDontPlay); |
184 | 64 |
curDontPlayingTeams.erase(itDontPlay); |
65 |
} |
|
66 |
||
67 |
FrameTeams* pRemoveTeams; |
|
68 |
FrameTeams* pAddTeams; |
|
69 |
if(!willBePlaying) { |
|
70 |
pRemoveTeams=framePlaying; |
|
71 |
pAddTeams=frameDontPlaying; |
|
72 |
} else { |
|
73 |
pRemoveTeams=frameDontPlaying; |
|
74 |
pAddTeams=framePlaying; |
|
75 |
} |
|
76 |
||
77 |
pAddTeams->addTeam(team, willBePlaying); |
|
78 |
pRemoveTeams->removeTeam(team); |
|
79 |
QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), |
|
80 |
this, SLOT(changeTeamStatus(HWTeam))); |
|
81 |
||
82 |
QSize szh=pAddTeams->sizeHint(); |
|
83 |
QSize szh1=pRemoveTeams->sizeHint(); |
|
84 |
if(szh.isValid() && szh1.isValid()) { |
|
85 |
pAddTeams->resize(pAddTeams->size().width(), szh.height()); |
|
86 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); |
|
87 |
} |
|
88 |
} |
|
89 |
||
311 | 90 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int maxHeight) |
184 | 91 |
{ |
92 |
VertScrArea* area=new VertScrArea(color); |
|
93 |
area->setWidget(pfteams); |
|
94 |
mainLayout.addWidget(area, 30); |
|
311 | 95 |
if (maxHeight > 0) |
96 |
area->setMaximumHeight(maxHeight); |
|
184 | 97 |
} |
98 |
||
99 |
TeamSelWidget::TeamSelWidget(QWidget* parent) : |
|
240 | 100 |
QGroupBox(parent), mainLayout(this) |
184 | 101 |
{ |
240 | 102 |
setTitle(QGroupBox::tr("Playing teams")); |
184 | 103 |
framePlaying=new FrameTeams(); |
104 |
frameDontPlaying=new FrameTeams(); |
|
244 | 105 |
// addScrArea(framePlaying, QColor("DarkTurquoise")); |
106 |
// addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow")); |
|
107 |
QPalette p; |
|
311 | 108 |
addScrArea(framePlaying, p.color(QPalette::Window).light(105), 200); |
109 |
addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0); |
|
110 |
newTeam = new QPushButton(this); |
|
111 |
newTeam->setText(QPushButton::tr("New team")); |
|
112 |
connect(newTeam, SIGNAL(clicked()), this, SLOT(newTeamClicked())); |
|
113 |
mainLayout.addWidget(newTeam); |
|
184 | 114 |
} |
115 |
||
231 | 116 |
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist) |
184 | 117 |
{ |
118 |
list<HWTeam>::iterator it; |
|
119 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { |
|
120 |
framePlaying->removeTeam(*it); |
|
121 |
} |
|
207 | 122 |
framePlaying->resetColors(); |
184 | 123 |
curPlayingTeams.clear(); |
124 |
for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { |
|
125 |
frameDontPlaying->removeTeam(*it); |
|
126 |
} |
|
127 |
curDontPlayingTeams.clear(); |
|
128 |
||
231 | 129 |
for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
184 | 130 |
addTeam(*it); |
131 |
} |
|
132 |
} |
|
133 |
||
134 |
bool TeamSelWidget::isPlaying(HWTeam team) const |
|
135 |
{ |
|
136 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); |
|
137 |
} |
|
138 |
||
139 |
list<HWTeam> TeamSelWidget::getPlayingTeams() const |
|
140 |
{ |
|
141 |
return curPlayingTeams; |
|
142 |
} |
|
143 |
||
207 | 144 |
HWTeamTempParams TeamSelWidget::getTeamParams(HWTeam team) const |
184 | 145 |
{ |
146 |
const TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team)); |
|
207 | 147 |
if(!tsw) throw; |
148 |
return tsw->getTeamParams(); |
|
184 | 149 |
} |
311 | 150 |
|
151 |
void TeamSelWidget::newTeamClicked() |
|
152 |
{ |
|
153 |
emit NewTeam(); |
|
154 |
} |