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