QTfrontend/teamselect.cpp
author unc0rr
Thu, 05 Oct 2006 16:33:18 +0000
changeset 183 57c2ef19f719
parent 153 dc10da2a73f9
child 184 f97a7a3dc8f6
permissions -rw-r--r--
Relicense to GPL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
153
dc10da2a73f9 license and copyright info added
displacer
parents: 152
diff changeset
     1
/*
dc10da2a73f9 license and copyright info added
displacer
parents: 152
diff changeset
     2
 * Hedgewars, a worms-like game
dc10da2a73f9 license and copyright info added
displacer
parents: 152
diff changeset
     3
 * Copyright (c) 2006 Ulyanov Igor <iulyanov@gmail.com>
dc10da2a73f9 license and copyright info added
displacer
parents: 152
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
153
dc10da2a73f9 license and copyright info added
displacer
parents: 152
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
    12
 * GNU General Public License for more details.
153
dc10da2a73f9 license and copyright info added
displacer
parents: 152
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
    15
 * along with this program; if not, write to the Free Software
57c2ef19f719 Relicense to GPL
unc0rr
parents: 153
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
153
dc10da2a73f9 license and copyright info added
displacer
parents: 152
diff changeset
    17
 */
dc10da2a73f9 license and copyright info added
displacer
parents: 152
diff changeset
    18
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    19
#include <QLabel>
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    20
#include <QPixmap>
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    21
#include <QPushButton>
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    22
#include <QFrame>
114
2762edfc23a9 add remove command slot fixed
displacer
parents: 85
diff changeset
    23
#include <QDebug>
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    24
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    25
#include <vertScrollArea.h>
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    26
#include "teamselect.h"
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    27
#include "teamselhelper.h"
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    28
#include "frameTeam.h"
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    29
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    30
void TeamSelWidget::addTeam(HWTeam team)
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    31
{
132
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    32
  frameDontPlaying->addTeam(team, false);
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    33
  curDontPlayingTeams.push_back(team);
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    34
  QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    35
		   this, SLOT(changeTeamStatus(HWTeam)));
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    36
}
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    37
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    38
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team)
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    39
//{
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    40
  //curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    41
//}
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    42
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    43
void TeamSelWidget::changeTeamStatus(HWTeam team)
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    44
{
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    45
  list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    46
  list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    47
132
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    48
  bool willBePlaying=itDontPlay!=curDontPlayingTeams.end();
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    49
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    50
  if(!willBePlaying) {
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    51
    // playing team => dont playing
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    52
    curDontPlayingTeams.push_back(*itPlay);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    53
    curPlayingTeams.erase(itPlay);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    54
  } else {
147
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    55
    // return if max playing teams reached
150
d9e8a336195c team hedgehogs number improved
displacer
parents: 147
diff changeset
    56
    if(framePlaying->isFullTeams()) return;
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    57
    // dont playing team => playing
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    58
    curPlayingTeams.push_back(*itDontPlay);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    59
    curDontPlayingTeams.erase(itDontPlay);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    60
  }
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    61
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    62
  FrameTeams* pRemoveTeams;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    63
  FrameTeams* pAddTeams;
132
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    64
  if(!willBePlaying) {
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    65
    pRemoveTeams=framePlaying;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    66
    pAddTeams=frameDontPlaying;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    67
  } else {
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    68
    pRemoveTeams=frameDontPlaying;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    69
    pAddTeams=framePlaying;
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    70
  }
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    71
132
2d0f404cdf05 first hedgehogs number selection added
displacer
parents: 131
diff changeset
    72
  pAddTeams->addTeam(team, willBePlaying);
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    73
  pRemoveTeams->removeTeam(team);
117
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    74
  QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
d21a48200772 HWTeam integration in team select widget
displacer
parents: 114
diff changeset
    75
		   this, SLOT(changeTeamStatus(HWTeam)));
131
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    76
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    77
  QSize szh=pAddTeams->sizeHint();
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    78
  QSize szh1=pRemoveTeams->sizeHint();
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    79
  if(szh.isValid() && szh1.isValid()) {
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    80
    pAddTeams->resize(pAddTeams->size().width(), szh.height());
482f78c595ec resize bugfix
displacer
parents: 122
diff changeset
    81
    pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height());
122
4911cf9c1924 resize bugfix
displacer
parents: 121
diff changeset
    82
  }
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    83
}
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    85
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color)
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    86
{
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    87
  VertScrArea* area=new VertScrArea(color);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    88
  area->setWidget(pfteams);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    89
  mainLayout.addWidget(area, 30);
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    90
}
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    91
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    92
TeamSelWidget::TeamSelWidget(QWidget* parent) :
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    93
  QWidget(parent), mainLayout(this)
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    94
{
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    95
  framePlaying=new FrameTeams();
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    96
  frameDontPlaying=new FrameTeams();
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    97
  addScrArea(framePlaying, QColor("DarkTurquoise"));
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    98
  addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow"));
0f6669da2fcb Start rewrite ui
unc0rr
parents: 63
diff changeset
    99
}
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   100
151
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   101
void TeamSelWidget::resetPlayingTeams(const QStringList& teamslist)
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   102
{
151
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   103
  list<HWTeam>::iterator it;
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   104
  for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) {
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   105
    framePlaying->removeTeam(*it);
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   106
  }
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   107
  curPlayingTeams.clear();
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   108
  for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) {
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   109
    frameDontPlaying->removeTeam(*it);
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   110
  }
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   111
  curDontPlayingTeams.clear();
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   112
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   113
  for (QStringList::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   114
    addTeam(*it);
9eb5a4cee35e reset playing teams
displacer
parents: 150
diff changeset
   115
  }
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   116
}
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   117
152
c558957ef644 teams moving order fixed
displacer
parents: 151
diff changeset
   118
bool TeamSelWidget::isPlaying(HWTeam team) const
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   119
{
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   120
  return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end();
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   121
}
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   122
152
c558957ef644 teams moving order fixed
displacer
parents: 151
diff changeset
   123
list<HWTeam> TeamSelWidget::getPlayingTeams() const
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   124
{
152
c558957ef644 teams moving order fixed
displacer
parents: 151
diff changeset
   125
  return curPlayingTeams;
c558957ef644 teams moving order fixed
displacer
parents: 151
diff changeset
   126
}
c558957ef644 teams moving order fixed
displacer
parents: 151
diff changeset
   127
c558957ef644 teams moving order fixed
displacer
parents: 151
diff changeset
   128
unsigned char TeamSelWidget::numHedgedogs(HWTeam team) const
c558957ef644 teams moving order fixed
displacer
parents: 151
diff changeset
   129
{
c558957ef644 teams moving order fixed
displacer
parents: 151
diff changeset
   130
  const TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team));
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   131
  if(!tsw) return 0;
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   132
  return tsw->getHedgehogsNum();
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 132
diff changeset
   133
}