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 |
#include <QDebug>
|
|
24 |
|
|
25 |
#include <vertScrollArea.h>
|
|
26 |
#include "teamselect.h"
|
|
27 |
#include "teamselhelper.h"
|
|
28 |
#include "frameTeam.h"
|
|
29 |
|
|
30 |
void TeamSelWidget::addTeam(HWTeam team)
|
|
31 |
{
|
|
32 |
frameDontPlaying->addTeam(team, false);
|
|
33 |
curDontPlayingTeams.push_back(team);
|
|
34 |
QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
|
|
35 |
this, SLOT(changeTeamStatus(HWTeam)));
|
|
36 |
}
|
|
37 |
|
|
38 |
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team)
|
|
39 |
//{
|
|
40 |
//curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
|
|
41 |
//}
|
|
42 |
|
|
43 |
void TeamSelWidget::changeTeamStatus(HWTeam team)
|
|
44 |
{
|
|
45 |
list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
|
|
46 |
list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
|
|
47 |
|
|
48 |
bool willBePlaying=itDontPlay!=curDontPlayingTeams.end();
|
|
49 |
|
|
50 |
if(!willBePlaying) {
|
|
51 |
// playing team => dont playing
|
|
52 |
curDontPlayingTeams.push_back(*itPlay);
|
|
53 |
curPlayingTeams.erase(itPlay);
|
|
54 |
} else {
|
|
55 |
// return if max playing teams reached
|
|
56 |
if(framePlaying->isFullTeams()) return;
|
|
57 |
// dont playing team => playing
|
|
58 |
curPlayingTeams.push_back(*itDontPlay);
|
|
59 |
curDontPlayingTeams.erase(itDontPlay);
|
|
60 |
}
|
|
61 |
|
|
62 |
FrameTeams* pRemoveTeams;
|
|
63 |
FrameTeams* pAddTeams;
|
|
64 |
if(!willBePlaying) {
|
|
65 |
pRemoveTeams=framePlaying;
|
|
66 |
pAddTeams=frameDontPlaying;
|
|
67 |
} else {
|
|
68 |
pRemoveTeams=frameDontPlaying;
|
|
69 |
pAddTeams=framePlaying;
|
|
70 |
}
|
|
71 |
|
|
72 |
pAddTeams->addTeam(team, willBePlaying);
|
|
73 |
pRemoveTeams->removeTeam(team);
|
|
74 |
QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
|
|
75 |
this, SLOT(changeTeamStatus(HWTeam)));
|
|
76 |
|
|
77 |
QSize szh=pAddTeams->sizeHint();
|
|
78 |
QSize szh1=pRemoveTeams->sizeHint();
|
|
79 |
if(szh.isValid() && szh1.isValid()) {
|
|
80 |
pAddTeams->resize(pAddTeams->size().width(), szh.height());
|
|
81 |
pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height());
|
|
82 |
}
|
|
83 |
}
|
|
84 |
|
|
85 |
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color)
|
|
86 |
{
|
|
87 |
VertScrArea* area=new VertScrArea(color);
|
|
88 |
area->setWidget(pfteams);
|
|
89 |
mainLayout.addWidget(area, 30);
|
|
90 |
}
|
|
91 |
|
|
92 |
TeamSelWidget::TeamSelWidget(QWidget* parent) :
|
|
93 |
QWidget(parent), mainLayout(this)
|
|
94 |
{
|
|
95 |
framePlaying=new FrameTeams();
|
|
96 |
frameDontPlaying=new FrameTeams();
|
|
97 |
addScrArea(framePlaying, QColor("DarkTurquoise"));
|
|
98 |
addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow"));
|
|
99 |
}
|
|
100 |
|
|
101 |
void TeamSelWidget::resetPlayingTeams(const QStringList& teamslist)
|
|
102 |
{
|
|
103 |
list<HWTeam>::iterator it;
|
|
104 |
for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) {
|
|
105 |
framePlaying->removeTeam(*it);
|
|
106 |
}
|
|
107 |
curPlayingTeams.clear();
|
|
108 |
for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) {
|
|
109 |
frameDontPlaying->removeTeam(*it);
|
|
110 |
}
|
|
111 |
curDontPlayingTeams.clear();
|
|
112 |
|
|
113 |
for (QStringList::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
|
114 |
addTeam(*it);
|
|
115 |
}
|
|
116 |
}
|
|
117 |
|
|
118 |
bool TeamSelWidget::isPlaying(HWTeam team) const
|
|
119 |
{
|
|
120 |
return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end();
|
|
121 |
}
|
|
122 |
|
|
123 |
list<HWTeam> TeamSelWidget::getPlayingTeams() const
|
|
124 |
{
|
|
125 |
return curPlayingTeams;
|
|
126 |
}
|
|
127 |
|
|
128 |
unsigned char TeamSelWidget::numHedgedogs(HWTeam team) const
|
|
129 |
{
|
|
130 |
const TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team));
|
|
131 |
if(!tsw) return 0;
|
|
132 |
return tsw->getHedgehogsNum();
|
|
133 |
}
|