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