QTfrontend/teamselect.cpp
author displacer
Sun, 14 Jan 2007 18:45:13 +0000
changeset 332 10080f681118
parent 322 e7175ae57945
child 339 7535ab6c3820
permissions -rw-r--r--
isChiefClient is now correct :)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     1
/*
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     2
 * Hedgewars, a worms-like game
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     3
 * Copyright (c) 2006 Ulyanov Igor <iulyanov@gmail.com>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     4
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     8
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    12
 * GNU General Public License for more details.
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    13
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    15
 * along with this program; if not, write to the Free Software
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    17
 */
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    18
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    19
#include <QLabel>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    20
#include <QPixmap>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    21
#include <QPushButton>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    22
#include <QFrame>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    23
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    24
#include <vertScrollArea.h>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    25
#include "teamselect.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    26
#include "teamselhelper.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    27
#include "frameTeam.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    28
322
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    29
void TeamSelWidget::addTeam(HWTeam team, bool netTeam)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    30
{
322
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    31
  if(netTeam) {
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    32
    framePlaying->addTeam(team, true);
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    33
    curPlayingTeams.push_back(team);
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    34
  } else {
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    35
    frameDontPlaying->addTeam(team, false);
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    36
    curDontPlayingTeams.push_back(team);
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    37
    QObject::connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    38
		     this, SLOT(changeTeamStatus(HWTeam)));
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    39
  }
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    40
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    41
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    42
//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    43
//{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    44
  //curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    45
//}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    46
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    47
void TeamSelWidget::changeTeamStatus(HWTeam team)
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    48
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    49
  list<HWTeam>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    50
  list<HWTeam>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    51
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    52
  bool willBePlaying=itDontPlay!=curDontPlayingTeams.end();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    53
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    54
  if(!willBePlaying) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    55
    // playing team => dont playing
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    56
    curDontPlayingTeams.push_back(*itPlay);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    57
    curPlayingTeams.erase(itPlay);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    58
  } else {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    59
    // return if max playing teams reached
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    60
    if(framePlaying->isFullTeams()) return;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    61
    // dont playing team => playing
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    62
    curPlayingTeams.push_back(*itDontPlay);
322
e7175ae57945 first new widgets added to net game
displacer
parents: 311
diff changeset
    63
    emit teamWillPlay(*itDontPlay);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    64
    curDontPlayingTeams.erase(itDontPlay);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    65
  }
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    66
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    67
  FrameTeams* pRemoveTeams;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    68
  FrameTeams* pAddTeams;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    69
  if(!willBePlaying) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    70
    pRemoveTeams=framePlaying;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    71
    pAddTeams=frameDontPlaying;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    72
  } else {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    73
    pRemoveTeams=frameDontPlaying;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    74
    pAddTeams=framePlaying;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    75
  }
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    76
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    77
  pAddTeams->addTeam(team, willBePlaying);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    78
  pRemoveTeams->removeTeam(team);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    79
  QObject::connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)),
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    80
		   this, SLOT(changeTeamStatus(HWTeam)));
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    81
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    82
  QSize szh=pAddTeams->sizeHint();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    83
  QSize szh1=pRemoveTeams->sizeHint();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    84
  if(szh.isValid() && szh1.isValid()) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    85
    pAddTeams->resize(pAddTeams->size().width(), szh.height());
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    86
    pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height());
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    87
  }
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    88
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    89
311
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
    90
void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int maxHeight)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    91
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    92
  VertScrArea* area=new VertScrArea(color);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    93
  area->setWidget(pfteams);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    94
  mainLayout.addWidget(area, 30);
311
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
    95
  if (maxHeight > 0)
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
    96
  	area->setMaximumHeight(maxHeight);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    97
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    98
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    99
TeamSelWidget::TeamSelWidget(QWidget* parent) :
240
c7f0a4f7a54a Better-looking multiplayer page
unc0rr
parents: 231
diff changeset
   100
  QGroupBox(parent), mainLayout(this)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   101
{
240
c7f0a4f7a54a Better-looking multiplayer page
unc0rr
parents: 231
diff changeset
   102
  setTitle(QGroupBox::tr("Playing teams"));
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   103
  framePlaying=new FrameTeams();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   104
  frameDontPlaying=new FrameTeams();
244
b37ca2295b73 - Fix crosshair position
unc0rr
parents: 240
diff changeset
   105
//  addScrArea(framePlaying, QColor("DarkTurquoise"));
b37ca2295b73 - Fix crosshair position
unc0rr
parents: 240
diff changeset
   106
//  addScrArea(frameDontPlaying, QColor("LightGoldenrodYellow"));
b37ca2295b73 - Fix crosshair position
unc0rr
parents: 240
diff changeset
   107
  QPalette p;
311
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   108
  addScrArea(framePlaying, p.color(QPalette::Window).light(105), 200);
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   109
  addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0);
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   110
  newTeam = new QPushButton(this);
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   111
  newTeam->setText(QPushButton::tr("New team"));
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   112
  connect(newTeam, SIGNAL(clicked()), this, SLOT(newTeamClicked()));
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   113
  mainLayout.addWidget(newTeam);
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   114
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   115
231
c77b16e48273 bots power icons added
displacer
parents: 207
diff changeset
   116
void TeamSelWidget::resetPlayingTeams(const QList<HWTeam>& teamslist)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   117
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   118
  list<HWTeam>::iterator it;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   119
  for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   120
    framePlaying->removeTeam(*it);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   121
  }
207
287077789132 coosing colors added
displacer
parents: 184
diff changeset
   122
  framePlaying->resetColors();
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   123
  curPlayingTeams.clear();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   124
  for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   125
    frameDontPlaying->removeTeam(*it);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   126
  }
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   127
  curDontPlayingTeams.clear();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   128
231
c77b16e48273 bots power icons added
displacer
parents: 207
diff changeset
   129
  for (QList<HWTeam>::ConstIterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   130
    addTeam(*it);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   131
  }
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   132
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   133
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   134
bool TeamSelWidget::isPlaying(HWTeam team) const
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   135
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   136
  return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   137
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   138
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   139
list<HWTeam> TeamSelWidget::getPlayingTeams() const
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   140
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   141
  return curPlayingTeams;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   142
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   143
207
287077789132 coosing colors added
displacer
parents: 184
diff changeset
   144
HWTeamTempParams TeamSelWidget::getTeamParams(HWTeam team) const
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   145
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   146
  const TeamShowWidget* tsw=dynamic_cast<TeamShowWidget*>(framePlaying->getTeamWidget(team));
207
287077789132 coosing colors added
displacer
parents: 184
diff changeset
   147
  if(!tsw) throw;
287077789132 coosing colors added
displacer
parents: 184
diff changeset
   148
  return tsw->getTeamParams();
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   149
}
311
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   150
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   151
void TeamSelWidget::newTeamClicked()
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   152
{
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   153
	emit NewTeam();
b8905423f19f - Limit list of teams in game with 200 px
unc0rr
parents: 244
diff changeset
   154
}