QTfrontend/ui/page/pageeditteam.cpp
changeset 6060 fdfc01419815
parent 6042 8b5345758f62
child 6165 6fe3e922246e
equal deleted inserted replaced
6059:ddf020d0941a 6060:fdfc01419815
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@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 <QGridLayout>
       
    20 #include <QHBoxLayout>
       
    21 #include <QPushButton>
       
    22 #include <QComboBox>
       
    23 #include <QLabel>
       
    24 #include <QLineEdit>
       
    25 #include <QTabWidget>
       
    26 #include <QGroupBox>
       
    27 #include <QToolBox>
       
    28 #include <QMessageBox>
       
    29 
       
    30 #include "pageeditteam.h"
       
    31 #include "sdlkeys.h"
       
    32 #include "SquareLabel.h"
       
    33 #include "hats.h"
       
    34 #include "HWApplication.h"
       
    35 
       
    36 QLayout * PageEditTeam::bodyLayoutDefinition()
       
    37 {
       
    38     QGridLayout * pageLayout = new QGridLayout();
       
    39     QTabWidget * tbw = new QTabWidget();
       
    40     QWidget * page1 = new QWidget(this);
       
    41     QWidget * page2 = new QWidget(this);
       
    42     tbw->addTab(page1, tr("General"));
       
    43     tbw->addTab(page2, tr("Advanced"));
       
    44     pageLayout->addWidget(tbw, 0, 0, 1, 3);
       
    45 
       
    46     QHBoxLayout * page1Layout = new QHBoxLayout(page1);
       
    47     page1Layout->setAlignment(Qt::AlignTop);
       
    48     QGridLayout * page2Layout = new QGridLayout(page2);
       
    49 
       
    50 // ====== Page 1 ======
       
    51     QVBoxLayout * vbox1 = new QVBoxLayout();
       
    52     QVBoxLayout * vbox2 = new QVBoxLayout();
       
    53     page1Layout->addLayout(vbox1);
       
    54     page1Layout->addLayout(vbox2);
       
    55 
       
    56     GBoxHedgehogs = new QGroupBox(this);
       
    57     GBoxHedgehogs->setTitle(QGroupBox::tr("Team Members"));
       
    58     GBoxHedgehogs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       
    59     QGridLayout * GBHLayout = new QGridLayout(GBoxHedgehogs);
       
    60 
       
    61     HatsModel * hatsModel = new HatsModel(GBoxHedgehogs);
       
    62     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
       
    63     {
       
    64         HHHats[i] = new QComboBox(GBoxHedgehogs);
       
    65         HHHats[i]->setModel(hatsModel);
       
    66         HHHats[i]->setIconSize(QSize(32, 37));
       
    67         //HHHats[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
       
    68         //HHHats[i]->setModelColumn(1);
       
    69         //HHHats[i]->setMinimumWidth(132);
       
    70         GBHLayout->addWidget(HHHats[i], i, 0);
       
    71 
       
    72         HHNameEdit[i] = new QLineEdit(GBoxHedgehogs);
       
    73         HHNameEdit[i]->setMaxLength(64);
       
    74         HHNameEdit[i]->setMinimumWidth(120);
       
    75         GBHLayout->addWidget(HHNameEdit[i], i, 1);
       
    76 
       
    77         btnRandomHogName[i] = addButton(":/res/dice.png", GBHLayout, i, 3, true);
       
    78     }
       
    79 
       
    80     btnRandomTeam = addButton(QPushButton::tr("Random Team"), GBHLayout, 9, false);
       
    81 
       
    82     vbox1->addWidget(GBoxHedgehogs);
       
    83 
       
    84     GBoxTeam = new QGroupBox(this);
       
    85     GBoxTeam->setTitle(QGroupBox::tr("Team Settings"));
       
    86     GBoxTeam->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       
    87     QGridLayout * GBTLayout = new QGridLayout(GBoxTeam);
       
    88     QLabel * tmpLabel = new QLabel(GBoxTeam);
       
    89     tmpLabel->setText(QLabel::tr("Name"));
       
    90     GBTLayout->addWidget(tmpLabel, 0, 0);
       
    91     tmpLabel = new QLabel(GBoxTeam);
       
    92     tmpLabel->setText(QLabel::tr("Type"));
       
    93     GBTLayout->addWidget(tmpLabel, 1, 0);
       
    94     tmpLabel = new QLabel(GBoxTeam);
       
    95     tmpLabel->setText(QLabel::tr("Grave"));
       
    96     GBTLayout->addWidget(tmpLabel, 2, 0);
       
    97     tmpLabel = new QLabel(GBoxTeam);
       
    98     tmpLabel->setText(QLabel::tr("Flag"));
       
    99     GBTLayout->addWidget(tmpLabel, 3, 0);
       
   100     tmpLabel = new QLabel(GBoxTeam);
       
   101     tmpLabel->setText(QLabel::tr("Voice"));
       
   102     GBTLayout->addWidget(tmpLabel, 4, 0);
       
   103 
       
   104     TeamNameEdit = new QLineEdit(GBoxTeam);
       
   105     TeamNameEdit->setMaxLength(64);
       
   106     GBTLayout->addWidget(TeamNameEdit, 0, 1);
       
   107     vbox2->addWidget(GBoxTeam);
       
   108 
       
   109     CBTeamLvl = new QComboBox(GBoxTeam);
       
   110     CBTeamLvl->setIconSize(QSize(48, 48));
       
   111     CBTeamLvl->addItem(QIcon(":/res/botlevels/0.png"), QComboBox::tr("Human"));
       
   112     for(int i = 5; i > 0; i--)
       
   113         CBTeamLvl->addItem(
       
   114                 QIcon(QString(":/res/botlevels/%1.png").arg(6 - i)),
       
   115                 QString("%1 %2").arg(QComboBox::tr("Level")).arg(i)
       
   116                 );
       
   117     GBTLayout->addWidget(CBTeamLvl, 1, 1);
       
   118 
       
   119     CBGrave = new QComboBox(GBoxTeam);
       
   120     CBGrave->setMaxCount(65535);
       
   121     CBGrave->setIconSize(QSize(32, 32));
       
   122     GBTLayout->addWidget(CBGrave, 2, 1);
       
   123 
       
   124     CBFlag = new QComboBox(GBoxTeam);
       
   125     CBFlag->setMaxCount(65535);
       
   126     CBFlag->setIconSize(QSize(22, 15));
       
   127     GBTLayout->addWidget(CBFlag, 3, 1);
       
   128 
       
   129     QHBoxLayout * hbox = new QHBoxLayout();
       
   130     CBVoicepack = new QComboBox(GBoxTeam);
       
   131 
       
   132     hbox->addWidget(CBVoicepack, 100);
       
   133     btnTestSound = addButton(":/res/PlaySound.png", hbox, 1, true);
       
   134     hbox->setStretchFactor(btnTestSound, 1);
       
   135 
       
   136     GBTLayout->addLayout(hbox, 4, 1);
       
   137 
       
   138     GBoxFort = new QGroupBox(this);
       
   139     GBoxFort->setTitle(QGroupBox::tr("Fort"));
       
   140     QGridLayout * GBFLayout = new QGridLayout(GBoxFort);
       
   141     CBFort = new QComboBox(GBoxFort);
       
   142     CBFort->setMaxCount(65535);
       
   143     GBFLayout->addWidget(CBFort, 0, 0);
       
   144     FortPreview = new SquareLabel(GBoxFort);
       
   145     FortPreview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   146     FortPreview->setMinimumSize(128, 128);
       
   147     FortPreview->setPixmap(QPixmap());
       
   148     // perhaps due to handling its own paintevents, SquareLabel doesn't play nice with the stars
       
   149     //FortPreview->setAttribute(Qt::WA_PaintOnScreen, true);
       
   150     GBFLayout->addWidget(FortPreview, 1, 0);
       
   151     vbox2->addWidget(GBoxFort);
       
   152 
       
   153     vbox1->addStretch();
       
   154     vbox2->addStretch();
       
   155 
       
   156 // ====== Page 2 ======
       
   157     GBoxBinds = new QGroupBox(this);
       
   158     GBoxBinds->setTitle(QGroupBox::tr("Key binds"));
       
   159     QGridLayout * GBBLayout = new QGridLayout(GBoxBinds);
       
   160     BindsBox = new QToolBox(GBoxBinds);
       
   161     BindsBox->setLineWidth(0);
       
   162     GBBLayout->addWidget(BindsBox);
       
   163     page2Layout->addWidget(GBoxBinds, 0, 0);
       
   164 
       
   165     quint16 i = 0;
       
   166     quint16 num = 0;
       
   167     QWidget * curW = NULL;
       
   168     QGridLayout * pagelayout = NULL;
       
   169     QLabel* l = NULL;
       
   170     while (i < BINDS_NUMBER) {
       
   171         if(cbinds[i].category != NULL)
       
   172         {
       
   173             if(curW != NULL)
       
   174             {
       
   175                 l = new QLabel(curW);
       
   176                 l->setText("");
       
   177                 pagelayout->addWidget(l, num++, 0, 1, 2);
       
   178             }
       
   179             curW = new QWidget(this);
       
   180             BindsBox->addItem(curW, HWApplication::translate("binds (categories)", cbinds[i].category));
       
   181             pagelayout = new QGridLayout(curW);
       
   182             num = 0;
       
   183         }
       
   184         if(cbinds[i].description != NULL)
       
   185         {
       
   186             l = new QLabel(curW);
       
   187             l->setText((num > 0 ? QString("\n") : QString("")) + HWApplication::translate("binds (descriptions)", cbinds[i].description));
       
   188             pagelayout->addWidget(l, num++, 0, 1, 2);
       
   189         }
       
   190 
       
   191         l = new QLabel(curW);
       
   192         l->setText(HWApplication::translate("binds", cbinds[i].name));
       
   193         l->setAlignment(Qt::AlignRight);
       
   194         pagelayout->addWidget(l, num, 0);
       
   195         CBBind[i] = new QComboBox(curW);
       
   196         for(int j = 0; sdlkeys[j][1][0] != '\0'; j++)
       
   197             CBBind[i]->addItem(HWApplication::translate("binds (keys)", sdlkeys[j][1]).contains(": ") ? HWApplication::translate("binds (keys)", sdlkeys[j][1]) : HWApplication::translate("binds (keys)", "Keyboard") + QString(": ") + HWApplication::translate("binds (keys)", sdlkeys[j][1]), sdlkeys[j][0]);
       
   198         pagelayout->addWidget(CBBind[i++], num++, 1);
       
   199     }
       
   200 
       
   201     return pageLayout;
       
   202 }
       
   203 
       
   204 QLayout * PageEditTeam::footerLayoutDefinition()
       
   205 {
       
   206     QHBoxLayout * bottomLayout = new QHBoxLayout();
       
   207 
       
   208     btnSave = addButton(":/res/Save.png", bottomLayout, 0, true);;
       
   209     btnSave->setStyleSheet("QPushButton{margin: 24px 0 0 0;}");
       
   210     bottomLayout->setAlignment(btnSave, Qt::AlignRight | Qt::AlignBottom);
       
   211 
       
   212     return bottomLayout;
       
   213 }
       
   214 
       
   215 void PageEditTeam::connectSignals()
       
   216 {
       
   217     connect(btnSave, SIGNAL(clicked()), this, SLOT(saveTeam()));
       
   218 
       
   219     signalMapper1 = new QSignalMapper(this);
       
   220     signalMapper2 = new QSignalMapper(this);
       
   221 
       
   222     connect(signalMapper1, SIGNAL(mapped(int)), this, SLOT(fixHHname(int)));
       
   223     connect(signalMapper2, SIGNAL(mapped(int)), this, SLOT(setRandomName(int)));
       
   224 
       
   225     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
       
   226     {
       
   227         connect(HHNameEdit[i], SIGNAL(editingFinished()), signalMapper1, SLOT(map()));
       
   228             signalMapper1->setMapping(HHNameEdit[i], i);
       
   229 
       
   230         connect(btnRandomHogName[i], SIGNAL(clicked()), signalMapper2, SLOT(map()));
       
   231             signalMapper2->setMapping(btnRandomHogName[i], i);
       
   232     }
       
   233 
       
   234     connect(btnRandomTeam, SIGNAL(clicked()), this, SLOT(setRandomNames()));
       
   235     
       
   236     connect(btnTestSound, SIGNAL(clicked()), this, SLOT(testSound()));
       
   237 
       
   238     connect(CBFort, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(CBFort_activated(const QString &)));
       
   239 }
       
   240 
       
   241 PageEditTeam::PageEditTeam(QWidget* parent, SDLInteraction * sdli) :
       
   242   AbstractPage(parent)
       
   243 {
       
   244     initPage();
       
   245 
       
   246     m_playerHash = "0000000000000000000000000000000000000000";
       
   247     mySdli = sdli;
       
   248 
       
   249     QDir tmpdir;
       
   250     QStringList list;
       
   251     tmpdir.cd(cfgdir->absolutePath());
       
   252     if (tmpdir.cd("Data/Sounds/voices")) 
       
   253     {
       
   254         list = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name);
       
   255         CBVoicepack->addItems(list);
       
   256     }
       
   257 
       
   258     tmpdir.cd(datadir->absolutePath());
       
   259     tmpdir.cd("Sounds/voices");
       
   260     QStringList tmplist = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name);
       
   261     QStringList tmplist2;
       
   262     foreach (const QString & line, tmplist)
       
   263     {
       
   264         if (!list.contains(line,Qt::CaseInsensitive))
       
   265             tmplist2.append(line);
       
   266     }
       
   267 
       
   268     CBVoicepack->addItems(tmplist2);
       
   269 
       
   270     QStringList userforts;
       
   271     tmpdir.cd(cfgdir->absolutePath());
       
   272     if (tmpdir.cd("Data/Forts"))
       
   273     {
       
   274         tmpdir.setFilter(QDir::Files);
       
   275         userforts = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1");
       
   276         CBFort->addItems(userforts);
       
   277     }
       
   278 
       
   279     tmpdir.cd("../Graphics/Graves");
       
   280     QStringList userlist = tmpdir.entryList(QStringList("*.png"));
       
   281     for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it )
       
   282     {
       
   283         QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Graves/" + *it);
       
   284         QIcon icon(pix.copy(0, 0, 32, 32));
       
   285         CBGrave->addItem(icon, QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"));
       
   286     }
       
   287 
       
   288     tmpdir.cd(datadir->absolutePath());
       
   289     tmpdir.cd("Forts");
       
   290     tmpdir.setFilter(QDir::Files);
       
   291 
       
   292     tmplist = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1");
       
   293     QStringList dataforts;
       
   294     foreach (const QString & line, tmplist)
       
   295     {
       
   296         if (!userforts.contains(line,Qt::CaseInsensitive))
       
   297             dataforts.append(line);
       
   298     }
       
   299 
       
   300     CBFort->addItems(dataforts);
       
   301 
       
   302     tmpdir.cd("../Graphics/Graves");
       
   303     QStringList datalist = tmpdir.entryList(QStringList("*.png"));
       
   304     foreach (const QString & line, datalist)
       
   305     {
       
   306         if (userlist.contains(line,Qt::CaseInsensitive)) continue;
       
   307         QPixmap pix(datadir->absolutePath() + "/Graphics/Graves/" + line);
       
   308         QIcon icon(pix.copy(0, 0, 32, 32));
       
   309         QString grave = line;
       
   310         grave = grave.replace(QRegExp("^(.*)\\.png"), "\\1");
       
   311         CBGrave->addItem(icon, grave);
       
   312     }
       
   313 
       
   314     // add the default flag
       
   315     CBFlag->addItem(QIcon(QPixmap(datadir->absolutePath() + "/Graphics/Flags/hedgewars.png").copy(0, 0, 22, 15)), "Hedgewars", "hedgewars");
       
   316     CBFlag->insertSeparator(CBFlag->count());
       
   317 
       
   318     tmpdir.cd(cfgdir->absolutePath());
       
   319     tmpdir.cd("Data/Graphics/Flags");
       
   320     userlist = tmpdir.entryList(QStringList("*.png"));
       
   321     
       
   322     // add all country flags
       
   323     foreach (const QString & line, userlist)
       
   324     {
       
   325         QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + line);
       
   326         QIcon icon(pix.copy(0, 0, 22, 15));
       
   327         // TODO improve readablility
       
   328         if(line.compare("cpu.png") && line.compare("hedgewars.png") && (line.indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags
       
   329         {
       
   330             QString flag = line;
       
   331             flag = flag.replace(QRegExp("^(.*)\\.png"), "\\1");
       
   332             CBFlag->addItem(icon, flag.replace("_", " "), flag);
       
   333         }
       
   334     }
       
   335 
       
   336     CBFlag->insertSeparator(CBFlag->count());
       
   337 
       
   338     // add all community flags
       
   339     for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it )
       
   340     {
       
   341         QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + *it);
       
   342         QIcon icon(pix.copy(0, 0, 22, 15));
       
   343         if(it->indexOf("cm_") > -1) // skip non community flags this time
       
   344         {
       
   345             QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1");
       
   346             CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag);
       
   347         }
       
   348     }
       
   349 
       
   350     CBFlag->insertSeparator(CBFlag->count());
       
   351 
       
   352     tmpdir.cd(datadir->absolutePath());
       
   353     tmpdir.cd("Graphics/Flags");
       
   354     datalist = tmpdir.entryList(QStringList("*.png"));
       
   355     
       
   356     // add all country flags
       
   357     for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it )
       
   358     {
       
   359         if (userlist.contains(*it,Qt::CaseInsensitive)) continue;
       
   360         QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it);
       
   361         QIcon icon(pix.copy(0, 0, 22, 15));
       
   362         if(it->compare("cpu.png") && it->compare("hedgewars.png") && (it->indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags
       
   363         {
       
   364             QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1");
       
   365             CBFlag->addItem(icon, QString(flag).replace("_", " "), flag);
       
   366         }
       
   367     }
       
   368 
       
   369     CBFlag->insertSeparator(CBFlag->count());
       
   370 
       
   371     // add all community flags
       
   372     for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it )
       
   373     {
       
   374         if (userlist.contains(*it,Qt::CaseInsensitive)) continue;
       
   375         QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it);
       
   376         QIcon icon(pix.copy(0, 0, 22, 15));
       
   377         if(it->indexOf("cm_") > -1) // skip non community flags this time
       
   378         {
       
   379             QString flag = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
       
   380             CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag);
       
   381         }
       
   382     }
       
   383 }
       
   384 
       
   385 void PageEditTeam::fixHHname(int idx)
       
   386 {
       
   387     HHNameEdit[idx]->setText(HHNameEdit[idx]->text().trimmed());
       
   388 
       
   389     if (HHNameEdit[idx]->text().isEmpty())
       
   390         HHNameEdit[idx]->setText(QLineEdit::tr("hedgehog %1").arg(idx+1));
       
   391 }
       
   392 
       
   393 void PageEditTeam::CBFort_activated(const QString & fortname)
       
   394 {
       
   395     QFile tmp;
       
   396     tmp.setFileName(cfgdir->absolutePath() + "/Data/Forts/" + fortname + "L.png");
       
   397     if (!tmp.exists()) tmp.setFileName(datadir->absolutePath() + "/Forts/" + fortname + "L.png");
       
   398     QPixmap pix(QFileInfo(tmp).absoluteFilePath());
       
   399     FortPreview->setPixmap(pix);
       
   400 }
       
   401 
       
   402 void PageEditTeam::testSound()
       
   403 {
       
   404     Mix_Chunk *sound;
       
   405     QDir tmpdir;
       
   406     mySdli->SDLMusicInit();
       
   407     
       
   408     tmpdir.cd(cfgdir->absolutePath());
       
   409     if (!tmpdir.cd("Data/Sounds/voices/"+CBVoicepack->currentText()))
       
   410     {
       
   411         tmpdir.cd(datadir->absolutePath());
       
   412         tmpdir.cd("Sounds/voices");
       
   413         tmpdir.cd(CBVoicepack->currentText());
       
   414     }
       
   415 
       
   416     QStringList list = tmpdir.entryList(QStringList() << "Illgetyou.ogg" << "Incoming.ogg" << "Stupid.ogg" << "Coward.ogg" << "Firstblood.ogg", QDir::Files);
       
   417     if (list.size()) {
       
   418         sound = Mix_LoadWAV(QString(tmpdir.absolutePath() + "/" + list[rand() % list.size()]).toLocal8Bit().constData());
       
   419         Mix_PlayChannel(-1, sound, 0);
       
   420     }
       
   421 }
       
   422 
       
   423 void PageEditTeam::createTeam(const QString & name, const QString & playerHash)
       
   424 {
       
   425     m_playerHash = playerHash;
       
   426     HWTeam newTeam(name);
       
   427     loadTeam(newTeam);
       
   428 }
       
   429 
       
   430 void PageEditTeam::editTeam(const QString & name, const QString & playerHash)
       
   431 {
       
   432     m_playerHash = playerHash;
       
   433     HWTeam team(name);
       
   434     team.loadFromFile();
       
   435     loadTeam(team);
       
   436 }
       
   437 
       
   438 void PageEditTeam::deleteTeam(const QString & name)
       
   439 {
       
   440     QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel, this);
       
   441 
       
   442     if (reallyDelete.exec() == QMessageBox::Ok)
       
   443         HWTeam(name).deleteFile();
       
   444 }
       
   445 
       
   446 void PageEditTeam::setRandomNames()
       
   447 {
       
   448     HWTeam team = data();
       
   449     HWNamegen::teamRandomNames(team, true);
       
   450     loadTeam(team);
       
   451 }
       
   452 
       
   453 void PageEditTeam::setRandomName(int hh_index)
       
   454 {
       
   455     HWTeam team = data();
       
   456     HWNamegen::teamRandomName(team,hh_index);
       
   457     loadTeam(team);
       
   458 }
       
   459 
       
   460 void PageEditTeam::loadTeam(const HWTeam & team)
       
   461 {
       
   462     TeamNameEdit->setText(team.name());
       
   463     CBTeamLvl->setCurrentIndex(team.difficulty());
       
   464 
       
   465     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
       
   466     {
       
   467         HWHog hh = team.hedgehog(i);
       
   468 
       
   469         HHNameEdit[i]->setText(hh.Name);
       
   470 
       
   471         if (hh.Hat.startsWith("Reserved"))
       
   472             hh.Hat = hh.Hat.remove(0,40);
       
   473 
       
   474         HHHats[i]->setCurrentIndex(HHHats[i]->findData(hh.Hat, Qt::DisplayRole));
       
   475     }
       
   476 
       
   477     CBGrave->setCurrentIndex(CBGrave->findText(team.grave()));
       
   478     CBFlag->setCurrentIndex(CBFlag->findData(team.flag()));
       
   479 
       
   480     CBFort->setCurrentIndex(CBFort->findText(team.fort()));
       
   481     CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack()));
       
   482 
       
   483     for(int i = 0; i < BINDS_NUMBER; i++)
       
   484     {
       
   485         CBBind[i]->setCurrentIndex(CBBind[i]->findData(team.keyBind(i)));
       
   486     }
       
   487 }
       
   488 
       
   489 HWTeam PageEditTeam::data()
       
   490 {
       
   491     HWTeam team(TeamNameEdit->text());
       
   492     team.setDifficulty(CBTeamLvl->currentIndex());
       
   493 
       
   494     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
       
   495     {
       
   496         HWHog hh;
       
   497         hh.Name = HHNameEdit[i]->text();
       
   498         hh.Hat = HHHats[i]->currentText();
       
   499 
       
   500         if (hh.Hat.startsWith("Reserved"))
       
   501             hh.Hat = "Reserved"+m_playerHash+hh.Hat.remove(0,9);
       
   502 
       
   503         team.setHedgehog(i,hh);
       
   504     }
       
   505 
       
   506     team.setGrave(CBGrave->currentText());
       
   507     team.setFort(CBFort->currentText());
       
   508     team.setVoicepack(CBVoicepack->currentText());
       
   509     team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString());
       
   510 
       
   511     for(int i = 0; i < BINDS_NUMBER; i++)
       
   512     {
       
   513         team.bindKey(i,CBBind[i]->itemData(CBBind[i]->currentIndex()).toString());
       
   514     }
       
   515 
       
   516     return team;
       
   517 }
       
   518 
       
   519 void PageEditTeam::saveTeam()
       
   520 {
       
   521     data().saveToFile();
       
   522     emit teamEdited();
       
   523 }