QTfrontend/teamselect.cpp
author displacer
Sat, 16 Sep 2006 17:24:41 +0000
changeset 150 d9e8a336195c
parent 147 52a3c431db8a
child 151 9eb5a4cee35e
permissions -rw-r--r--
team hedgehogs number improved
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
     1
#include <QLabel>
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
     2
#include <QPixmap>
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
     3
#include <QPushButton>
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
     4
#include <QFrame>
114
2762edfc23a9 add remove command slot fixed
displacer
parents: 85
diff changeset
     5
#include <QDebug>
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
     6
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
     7
#include <vertScrollArea.h>
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
     8
#include "teamselect.h"
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
     9
#include "teamselhelper.h"
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    10
#include "frameTeam.h"
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    11
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    12
void TeamSelWidget::addTeam(HWTeam team)
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    13
{
132
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    14
  frameDontPlaying->addTeam(team, false);
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    15
  curDontPlayingTeams.push_back(team);
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    16
  QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    17
		   this, SLOT(changeTeamStatus(HWTeam)));
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    18
}
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    19
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    20
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team)
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    21
//{
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    22
  //curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    23
//}
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    24
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    25
void TeamSelWidget::changeTeamStatus(HWTeam team)
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    26
{
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    27
  list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    28
  list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    29
132
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    30
  bool willBePlaying=itDontPlay!=curDontPlayingTeams.end();
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    31
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    32
  if(!willBePlaying) {
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    33
    // playing team => dont playing
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    34
    curDontPlayingTeams.push_back(*itPlay);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    35
    curPlayingTeams.erase(itPlay);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    36
  } else {
147
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    37
    // return if max playing teams reached
150
d9e8a336195c team hedgehogs number improved
displacer
parents: 147
diff changeset
    38
    if(framePlaying->isFullTeams()) return;
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    39
    // dont playing team => playing
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    40
    curPlayingTeams.push_back(*itDontPlay);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    41
    curDontPlayingTeams.erase(itDontPlay);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    42
  }
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    43
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    44
  FrameTeams* pRemoveTeams;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    45
  FrameTeams* pAddTeams;
132
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    46
  if(!willBePlaying) {
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    47
    pRemoveTeams=framePlaying;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    48
    pAddTeams=frameDontPlaying;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    49
  } else {
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    50
    pRemoveTeams=frameDontPlaying;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    51
    pAddTeams=framePlaying;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    52
  }
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    53
132
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    54
  pAddTeams->addTeam(team, willBePlaying);
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    55
  pRemoveTeams->removeTeam(team);
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    56
  QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    57
		   this, SLOT(changeTeamStatus(HWTeam)));
131
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    58
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    59
  QSize szh=pAddTeams->sizeHint();
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    60
  QSize szh1=pRemoveTeams->sizeHint();
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    61
  if(szh.isValid() && szh1.isValid()) {
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    62
    pAddTeams->resize(pAddTeams->size().width(), szh.height());
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    63
    pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height());
122
4911cf9c1924 resize bugfix
displacer
parents: 121
diff changeset
    64
  }
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    65
}
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    66
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    67
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color)
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    68
{
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    69
  VertScrArea* area=new VertScrArea(color);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    70
  area->setWidget(pfteams);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    71
  mainLayout.addWidget(area, 30);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    72
}
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    73
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    74
TeamSelWidget::TeamSelWidget(QWidget* parent) :
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    75
  QWidget(parent), mainLayout(this)
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    76
{
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    77
  framePlaying=new FrameTeams();
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    78
  frameDontPlaying=new FrameTeams();
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    79
  addScrArea(framePlaying, QColor("DarkTurquoise"));
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    80
  addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow"));
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    81
}
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    82
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    83
void TeamSelWidget::resetPlayingTeams()
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    84
{
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    85
}
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    86
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    87
bool TeamSelWidget::isPlaying(HWTeam team)
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    88
{
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    89
  return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end();
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    90
}
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    91
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    92
unsigned char TeamSelWidget::numHedgedogs(HWTeam team)
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    93
{
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    94
  TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team));
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    95
  if(!tsw) return 0;
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    96
  return tsw->getHedgehogsNum();
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
    97
}