QTfrontend/pageeditteam.cpp
changeset 6024 d38da7c19e43
parent 5907 64ccc6be0ec5
child 6042 8b5345758f62
equal deleted inserted replaced
6022:8ed6e810051a 6024:d38da7c19e43
    22 #include <QLabel>
    22 #include <QLabel>
    23 #include <QLineEdit>
    23 #include <QLineEdit>
    24 #include <QTabWidget>
    24 #include <QTabWidget>
    25 #include <QGroupBox>
    25 #include <QGroupBox>
    26 #include <QToolBox>
    26 #include <QToolBox>
       
    27 #include <QMessageBox>
    27 
    28 
    28 #include "pageeditteam.h"
    29 #include "pageeditteam.h"
    29 #include "sdlkeys.h"
    30 #include "sdlkeys.h"
    30 #include "hwconsts.h"
       
    31 #include "SquareLabel.h"
    31 #include "SquareLabel.h"
    32 #include "hats.h"
    32 #include "hats.h"
    33 #include "HWApplication.h"
    33 #include "HWApplication.h"
    34 
    34 
    35 PageEditTeam::PageEditTeam(QWidget* parent, SDLInteraction * sdli) :
    35 PageEditTeam::PageEditTeam(QWidget* parent, SDLInteraction * sdli) :
    36   AbstractPage(parent)
    36   AbstractPage(parent)
    37 {
    37 {
       
    38     m_playerHash = "0000000000000000000000000000000000000000";
    38     mySdli = sdli;
    39     mySdli = sdli;
    39     QGridLayout * pageLayout = new QGridLayout(this);
    40     QGridLayout * pageLayout = new QGridLayout(this);
    40     QTabWidget * tbw = new QTabWidget(this);
    41     QTabWidget * tbw = new QTabWidget(this);
    41     QWidget * page1 = new QWidget(this);
    42     QWidget * page1 = new QWidget(this);
    42     QWidget * page2 = new QWidget(this);
    43     QWidget * page2 = new QWidget(this);
    43     tbw->addTab(page1, tr("General"));
    44     tbw->addTab(page1, tr("General"));
    44     tbw->addTab(page2, tr("Advanced"));
    45     tbw->addTab(page2, tr("Advanced"));
    45     pageLayout->addWidget(tbw, 0, 0, 1, 3);
    46     pageLayout->addWidget(tbw, 0, 0, 1, 3);
    46     BtnTeamDiscard = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
    47 
    47     BtnTeamSave = addButton(":/res/Save.png", pageLayout, 1, 2, true);;
    48     BtnTeamSave = addButton(":/res/Save.png", pageLayout, 1, 2, true);;
    48     BtnTeamSave->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}");
    49     BtnTeamSave->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}");
       
    50     connect(BtnTeamSave, SIGNAL(clicked()), this, SLOT(saveTeam()));
       
    51 
       
    52     BtnTeamDiscard = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
    49     BtnTeamDiscard->setFixedHeight(BtnTeamSave->height());
    53     BtnTeamDiscard->setFixedHeight(BtnTeamSave->height());
    50     BtnTeamDiscard->setStyleSheet("QPushButton{margin-top: 31px;}");
    54     BtnTeamDiscard->setStyleSheet("QPushButton{margin-top: 31px;}");
       
    55     connect(BtnTeamDiscard, SIGNAL(clicked()), this, SIGNAL(goBack()));
    51 
    56 
    52     QHBoxLayout * page1Layout = new QHBoxLayout(page1);
    57     QHBoxLayout * page1Layout = new QHBoxLayout(page1);
    53     page1Layout->setAlignment(Qt::AlignTop);
    58     page1Layout->setAlignment(Qt::AlignTop);
    54     QGridLayout * page2Layout = new QGridLayout(page2);
    59     QGridLayout * page2Layout = new QGridLayout(page2);
    55 
    60 
    66 
    71 
    67     signalMapper1 = new QSignalMapper(this);
    72     signalMapper1 = new QSignalMapper(this);
    68     signalMapper2 = new QSignalMapper(this);
    73     signalMapper2 = new QSignalMapper(this);
    69 
    74 
    70     connect(signalMapper1, SIGNAL(mapped(int)), this, SLOT(fixHHname(int)));
    75     connect(signalMapper1, SIGNAL(mapped(int)), this, SLOT(fixHHname(int)));
       
    76     connect(signalMapper2, SIGNAL(mapped(int)), this, SLOT(setRandomName(int)));
    71 
    77 
    72     HatsModel * hatsModel = new HatsModel(GBoxHedgehogs);
    78     HatsModel * hatsModel = new HatsModel(GBoxHedgehogs);
    73     for(int i = 0; i < 8; i++)
    79     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
    74     {
    80     {
    75         HHHats[i] = new QComboBox(GBoxHedgehogs);
    81         HHHats[i] = new QComboBox(GBoxHedgehogs);
    76         HHHats[i]->setModel(hatsModel);
    82         HHHats[i]->setModel(hatsModel);
    77         HHHats[i]->setIconSize(QSize(32, 37));
    83         HHHats[i]->setIconSize(QSize(32, 37));
    78         //HHHats[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    84         //HHHats[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    93         connect(randButton[i], SIGNAL(clicked()), signalMapper2, SLOT(map()));
    99         connect(randButton[i], SIGNAL(clicked()), signalMapper2, SLOT(map()));
    94             signalMapper2->setMapping(randButton[i], i);
   100             signalMapper2->setMapping(randButton[i], i);
    95     }
   101     }
    96 
   102 
    97     randTeamButton = addButton(QPushButton::tr("Random Team"), GBHLayout, 9, false);
   103     randTeamButton = addButton(QPushButton::tr("Random Team"), GBHLayout, 9, false);
       
   104     connect(randTeamButton, SIGNAL(clicked()), this, SLOT(setRandomNames()));
    98 
   105 
    99     vbox1->addWidget(GBoxHedgehogs);
   106     vbox1->addWidget(GBoxHedgehogs);
   100 
   107 
   101 
   108 
   102     GBoxTeam = new QGroupBox(this);
   109     GBoxTeam = new QGroupBox(this);
   343         CBBind[i] = new QComboBox(curW);
   350         CBBind[i] = new QComboBox(curW);
   344         for(int j = 0; sdlkeys[j][1][0] != '\0'; j++)
   351         for(int j = 0; sdlkeys[j][1][0] != '\0'; j++)
   345             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]);
   352             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]);
   346         pagelayout->addWidget(CBBind[i++], num++, 1);
   353         pagelayout->addWidget(CBBind[i++], num++, 1);
   347     }
   354     }
       
   355 
   348 }
   356 }
   349 
   357 
   350 void PageEditTeam::fixHHname(int idx)
   358 void PageEditTeam::fixHHname(int idx)
   351 {
   359 {
   352     HHNameEdit[idx]->setText(HHNameEdit[idx]->text().trimmed());
   360     HHNameEdit[idx]->setText(HHNameEdit[idx]->text().trimmed());
   382     if (list.size()) {
   390     if (list.size()) {
   383         sound = Mix_LoadWAV(QString(tmpdir.absolutePath() + "/" + list[rand() % list.size()]).toLocal8Bit().constData());
   391         sound = Mix_LoadWAV(QString(tmpdir.absolutePath() + "/" + list[rand() % list.size()]).toLocal8Bit().constData());
   384         Mix_PlayChannel(-1, sound, 0);
   392         Mix_PlayChannel(-1, sound, 0);
   385     }
   393     }
   386 }
   394 }
       
   395 
       
   396 void PageEditTeam::createTeam(const QString & name, const QString & playerHash)
       
   397 {
       
   398     m_playerHash = playerHash;
       
   399     HWTeam newTeam(name);
       
   400     loadTeam(newTeam);
       
   401 }
       
   402 
       
   403 void PageEditTeam::editTeam(const QString & name, const QString & playerHash)
       
   404 {
       
   405     m_playerHash = playerHash;
       
   406     HWTeam team(name);
       
   407     team.loadFromFile();
       
   408     loadTeam(team);
       
   409 }
       
   410 
       
   411 void PageEditTeam::deleteTeam(const QString & name)
       
   412 {
       
   413     QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel, this);
       
   414 
       
   415     if (reallyDelete.exec() == QMessageBox::Ok)
       
   416         HWTeam(name).deleteFile();
       
   417 }
       
   418 
       
   419 void PageEditTeam::setRandomNames()
       
   420 {
       
   421     HWTeam team = data();
       
   422     HWNamegen::teamRandomNames(team, true);
       
   423     loadTeam(team);
       
   424 }
       
   425 
       
   426 void PageEditTeam::setRandomName(int hh_index)
       
   427 {
       
   428     HWTeam team = data();
       
   429     HWNamegen::teamRandomName(team,hh_index);
       
   430     loadTeam(team);
       
   431 }
       
   432 
       
   433 void PageEditTeam::loadTeam(const HWTeam & team)
       
   434 {
       
   435     TeamNameEdit->setText(team.name());
       
   436     CBTeamLvl->setCurrentIndex(team.difficulty());
       
   437 
       
   438     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
       
   439     {
       
   440         HWHog hh = team.hedgehog(i);
       
   441 
       
   442         HHNameEdit[i]->setText(hh.Name);
       
   443 
       
   444         if (hh.Hat.startsWith("Reserved"))
       
   445             hh.Hat = hh.Hat.remove(0,40);
       
   446 
       
   447         HHHats[i]->setCurrentIndex(HHHats[i]->findData(hh.Hat, Qt::DisplayRole));
       
   448     }
       
   449 
       
   450     CBGrave->setCurrentIndex(CBGrave->findText(team.grave()));
       
   451     CBFlag->setCurrentIndex(CBFlag->findData(team.flag()));
       
   452 
       
   453     CBFort->setCurrentIndex(CBFort->findText(team.fort()));
       
   454     CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack()));
       
   455 
       
   456     for(int i = 0; i < BINDS_NUMBER; i++)
       
   457     {
       
   458         CBBind[i]->setCurrentIndex(CBBind[i]->findData(team.keyBind(i)));
       
   459     }
       
   460 }
       
   461 
       
   462 HWTeam PageEditTeam::data()
       
   463 {
       
   464     HWTeam team(TeamNameEdit->text());
       
   465     team.setDifficulty(CBTeamLvl->currentIndex());
       
   466 
       
   467     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
       
   468     {
       
   469         HWHog hh;
       
   470         hh.Name = HHNameEdit[i]->text();
       
   471         hh.Hat = HHHats[i]->currentText();
       
   472 
       
   473         if (hh.Hat.startsWith("Reserved"))
       
   474             hh.Hat = "Reserved"+m_playerHash+hh.Hat.remove(0,9);
       
   475 
       
   476         team.setHedgehog(i,hh);
       
   477     }
       
   478 
       
   479     team.setGrave(CBGrave->currentText());
       
   480     team.setFort(CBFort->currentText());
       
   481     team.setVoicepack(CBVoicepack->currentText());
       
   482     team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString());
       
   483 
       
   484     for(int i = 0; i < BINDS_NUMBER; i++)
       
   485     {
       
   486         team.bindKey(i,CBBind[i]->itemData(CBBind[i]->currentIndex()).toString());
       
   487     }
       
   488 
       
   489     return team;
       
   490 }
       
   491 
       
   492 void PageEditTeam::saveTeam()
       
   493 {
       
   494     data().saveToFile();
       
   495     emit teamEdited();
       
   496 }
       
   497