some more cleanups and refactoring.
authorsheepluva
Sun, 25 Sep 2011 19:30:10 +0200
changeset 6024 d38da7c19e43
parent 6022 8ed6e810051a
child 6026 2833862a7e00
some more cleanups and refactoring. functional changes: when generating random hog names avoid duplicate names (if possible)
QTfrontend/game.cpp
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/namegen.cpp
QTfrontend/namegen.h
QTfrontend/newnetclient.cpp
QTfrontend/pageeditteam.cpp
QTfrontend/pageeditteam.h
QTfrontend/pageoptions.cpp
QTfrontend/pageoptions.h
QTfrontend/team.cpp
QTfrontend/team.h
--- a/QTfrontend/game.cpp	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/game.cpp	Sun Sep 25 19:30:10 2011 +0200
@@ -120,13 +120,11 @@
             .arg((themesModel->rowCount() > 0) ? themesModel->index(rand() % themesModel->rowCount()).data().toString() : "steel"));
     HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString());
 
-    HWNamegen namegen;
-
     HWTeam team1;
     team1.setDifficulty(0);
     team1.setColor(QColor(colors[0]));
     team1.setNumHedgehogs(4);
-    namegen.teamRandomNames(team1,TRUE);
+    HWNamegen::teamRandomNames(team1,true);
     HWProto::addStringListToBuffer(teamscfg,
             team1.teamGameConfig(100));
 
@@ -135,7 +133,7 @@
     team2.setColor(QColor(colors[1]));
     team2.setNumHedgehogs(4);
     do
-        namegen.teamRandomNames(team2,TRUE);
+        HWNamegen::teamRandomNames(team2,true);
     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
     HWProto::addStringListToBuffer(teamscfg,
             team2.teamGameConfig(100));
--- a/QTfrontend/hwform.cpp	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/hwform.cpp	Sun Sep 25 19:30:10 2011 +0200
@@ -44,7 +44,6 @@
 #include "hwform.h"
 #include "game.h"
 #include "team.h"
-#include "namegen.h"
 #include "teamselect.h"
 #include "selectWeapon.h"
 #include "gameuiconfig.h"
@@ -115,7 +114,6 @@
 
     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
 
-    namegen = new HWNamegen();
 
 #ifdef __APPLE__
     panel = new M3Panel;
@@ -170,11 +168,7 @@
     connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
     connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
 
-    connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
-    connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard()));
-
-    connect(ui.pageEditTeam->signalMapper2, SIGNAL(mapped(const int &)), this, SLOT(RandomName(const int &)));
-    connect(ui.pageEditTeam->randTeamButton, SIGNAL(clicked()), this, SLOT(RandomNames()));
+    connect(ui.pageEditTeam, SIGNAL(teamEdited()), this, SLOT(AfterTeamEdit()));
 
     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
     connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)),
@@ -189,9 +183,9 @@
     connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo()));
     connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo()));
 
-    connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam()));
-    connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam()));
-    connect(ui.pageOptions->BtnDeleteTeam, SIGNAL(clicked()), this, SLOT(DeleteTeam()));
+    connect(ui.pageOptions, SIGNAL(newTeamRequested()), this, SLOT(NewTeam()));
+    connect(ui.pageOptions, SIGNAL(editTeamRequested(const QString&)), this, SLOT(EditTeam(const QString&)));
+    connect(ui.pageOptions, SIGNAL(deleteTeamRequested(const QString&)), this, SLOT(DeleteTeam(const QString&)));
     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions()));
     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack()));
     connect(ui.pageOptions->BtnAssociateFiles, SIGNAL(clicked()), this, SLOT(AssociateFiles()));
@@ -476,11 +470,7 @@
     if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) {
         QStringList tmNames = config->GetTeamsList();
         TeamSelWidget* curTeamSelWidget;
-        ui.pageOptions->BtnNewTeam->setVisible(false);
-        ui.pageOptions->BtnEditTeam->setVisible(false);
-        ui.pageOptions->BtnDeleteTeam->setVisible(false);
-        ui.pageOptions->CBTeamName->setVisible(false);
-        ui.pageOptions->LblNoEditTeam->setVisible(true);
+        ui.pageOptions->setTeamOptionsEnabled(false);
 
         if (id == ID_PAGE_MULTIPLAYER) {
             curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
@@ -511,11 +501,7 @@
         }
 
     if (id == ID_PAGE_MAIN) {
-        ui.pageOptions->BtnNewTeam->setVisible(true);
-        ui.pageOptions->BtnEditTeam->setVisible(true);
-        ui.pageOptions->BtnDeleteTeam->setVisible(true);
-        ui.pageOptions->CBTeamName->setVisible(true);
-        ui.pageOptions->LblNoEditTeam->setVisible(false);
+        ui.pageOptions->setTeamOptionsEnabled(true);
     }
 
     // load and save ignore/friends lists
@@ -624,61 +610,30 @@
 
 void HWForm::NewTeam()
 {
-    editedTeam = new HWTeam(QLineEdit::tr("unnamed"));
-    editedTeam->SetToPage(this);
-    GoToPage(ID_PAGE_SETUP_TEAM);
-}
-
-void HWForm::EditTeam()
-{
-    editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
-    editedTeam->loadFromFile();
-    editedTeam->SetToPage(this);
+    ui.pageEditTeam->createTeam(QLineEdit::tr("unnamed"), playerHash);
+    UpdateTeamsLists();
     GoToPage(ID_PAGE_SETUP_TEAM);
 }
 
-void HWForm::DeleteTeam()
+void HWForm::EditTeam(const QString & teamName)
 {
-    QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel);
-
-    if (reallyDelete.exec() == QMessageBox::Ok) {
-        editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
-        editedTeam->deleteFile();
-
-        // Remove from lists
-        ui.pageOptions->CBTeamName->removeItem(ui.pageOptions->CBTeamName->currentIndex());
-    }
+    ui.pageEditTeam->editTeam(teamName, playerHash);
+    GoToPage(ID_PAGE_SETUP_TEAM);
 }
 
-void HWForm::RandomNames()
-{
-    editedTeam->GetFromPage(this);
-    namegen->teamRandomNames(*editedTeam, true);
-    editedTeam->SetToPage(this);
-}
-
-void HWForm::RandomName(const int &i)
+void HWForm::AfterTeamEdit()
 {
-    editedTeam->GetFromPage(this);
-    namegen->teamRandomName(*editedTeam,i);
-    editedTeam->SetToPage(this);
-}
-
-void HWForm::TeamSave()
-{
-    editedTeam->GetFromPage(this);
-    editedTeam->saveToFile();
-    delete editedTeam;
-    editedTeam=0;
     UpdateTeamsLists();
     GoBack();
 }
 
-void HWForm::TeamDiscard()
+
+void HWForm::DeleteTeam(const QString & teamName)
 {
-    delete editedTeam;
-    editedTeam=0;
-    GoBack();
+    ui.pageEditTeam->deleteTeam(teamName);
+    QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel);
+
+    UpdateTeamsLists();
 }
 
 void HWForm::DeleteScheme()
--- a/QTfrontend/hwform.h	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/hwform.h	Sun Sep 25 19:30:10 2011 +0200
@@ -79,12 +79,9 @@
     void btnExitClicked();
     void IntermediateSetup();
     void NewTeam();
-    void EditTeam();
-    void DeleteTeam();
-    void RandomNames();
-    void RandomName(const int &i);
-    void TeamSave();
-    void TeamDiscard();
+    void EditTeam(const QString & teamName);
+    void AfterTeamEdit();
+    void DeleteTeam(const QString & teamName);
     void DeleteScheme();
     void DeleteWeaponSet();
     void SimpleGame();
--- a/QTfrontend/namegen.cpp	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/namegen.cpp	Sun Sep 25 19:30:10 2011 +0200
@@ -26,151 +26,211 @@
 #include "hwconsts.h"
 
 
-HWNamegen::HWNamegen() :
-    typesAvailable(false)
-{
-
-    loadTypes();
-}
+HWNamegen::HWNamegen() {}
 
-HWNamegen::~HWNamegen()
-{
-}
-
+QList<QStringList> HWNamegen::TypesTeamnames;
+QList<QStringList> HWNamegen::TypesHatnames;
+bool HWNamegen::typesAvailable = false;
 
 
-void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber)
-{
-    randomNameByHat(team, HedgehogNumber);
-}
-
 void HWNamegen::teamRandomNames(HWTeam & team, const bool changeteamname)
 {
-    if ((TypesHatnames.size() > 0) && typesAvailable){
+    // load types if not already loaded
+    if (!typesAvailable)
+        if (!loadTypes())
+            return; // abort if loading failed
+
+    // abort if there are no hat types
+    if (TypesHatnames.size() <= 0)
+        return;
 
-        int kind = (rand()%(TypesHatnames.size()));
+    // the hat will influence which names the hogs get
+    int kind = (rand()%(TypesHatnames.size()));
+
+    // pick team name based on hat
+    if (changeteamname)
+    {
+        if (TypesTeamnames[kind].size() > 0)
+            team.setName(TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())]);
 
-        if (changeteamname){
-            if (TypesTeamnames[kind].size() > 0){
-                team.setName(TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())]);
-            }
-            team.setGrave(getRandomGrave());
-            team.setFort(getRandomFort());
-            team.setVoicepack("Default");
+        team.setGrave(getRandomGrave());
+        team.setFort(getRandomFort());
+        team.setVoicepack("Default");
+    }
+
+    QStringList dicts;
+    QStringList dict;
+
+    if ((TypesHatnames[kind].size()) <= 0)
+    {
+        dicts = dictsForHat(team.hedgehog(0).Hat);
+        dict  = dictContents(dicts[rand()%(dicts.size())]);
+    }
+
+    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
+    {
+        if ((TypesHatnames[kind].size()) > 0)
+        {
+            HWHog hh = team.hedgehog(i);
+            hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
+            team.setHedgehog(i,hh);
         }
 
-        //give each hedgehog a random name:
-        //TODO: load the dictionary only once! (right now it's loaded once for each hedgehog)
-        for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
+        // there is a chance that this hog has the same hat as the previous one
+        // let's reuse the hat-specific dict in this case
+        if ((i == 0) or (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat))
         {
-            if ((TypesHatnames[kind].size()) > 0){
-                HWHog hh = team.hedgehog(i);
-                hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
-                team.setHedgehog(i,hh);
-            }
-            randomNameByHat(team,i);
+            dicts = dictsForHat(team.hedgehog(i).Hat);
+            dict  = dictContents(dicts[rand()%(dicts.size())]);
         }
 
+        // give each hedgehog a random name
+        HWNamegen::teamRandomName(team,i,dict);
     }
 
 }
 
+void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber)
+{
+    QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat);
 
-void HWNamegen::randomNameByHat(HWTeam & team, const int HedgehogNumber)
+    QStringList dict = dictContents(dicts[rand()%(dicts.size())]);
+
+    teamRandomName(team, HedgehogNumber, dict);
+}
+
+void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber, const QStringList & dict)
 {
-    QStringList Dictionaries;
-    hatCfgLoad(team.hedgehog(HedgehogNumber).Hat,Dictionaries);
+    QStringList namesDict = dict;
 
-    QStringList Dictionary;
-    dictLoad(Dictionaries[rand()%(Dictionaries.size())],Dictionary);
+    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
+    {
+        namesDict.removeOne(team.hedgehog(i).Name);
+    }
+
+    // if our dict doesn't have any new names we'll have to use duplicates
+    if (namesDict.size() < 1)
+        namesDict = dict;
 
     HWHog hh = team.hedgehog(HedgehogNumber);
-    hh.Name = Dictionary[rand()%(Dictionary.size())];
+
+    hh.Name = namesDict[rand()%(namesDict.size())];
+
     team.setHedgehog(HedgehogNumber, hh);
 }
 
-void HWNamegen::dictLoad(const QString filename, QStringList &list)
+QStringList HWNamegen::dictContents(const QString filename)
 {
-    list.clear();
+    QStringList list;
 
     QFile file;
+
+    // find .cfg to load the names from
     file.setFileName(QString("%1/Data/Names/%2.txt").arg(cfgdir->absolutePath()).arg(filename));
-    if (!file.exists()) file.setFileName(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename));
+    if (!file.exists())
+        file.setFileName(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename));
+
     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
     {
 
         QTextStream in(&file);
-        while (!in.atEnd()) {
+        while (!in.atEnd())
+        {
             QString line = in.readLine();
-            if(line != QString(""))
-                {list.append(line);}
+            if(!line.isEmpty())
+                list.append(line);
         }
     }
 
-    if (list.size()==0)
+    if (list.size() == 0)
          list.append(filename);
 
+    return list;
 }
 
 
-void HWNamegen::hatCfgLoad(const QString hatname, QStringList &list)
+QStringList HWNamegen::dictsForHat(const QString hatname)
 {
-    list.clear();
+    QStringList list;
 
     QFile file;
+
+    // find .cfg to load the names from
     file.setFileName(QString("%1/Data/Names/%2.cfg").arg(cfgdir->absolutePath()).arg(hatname));
-    if (!file.exists()) file.setFileName(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname));
+    if (!file.exists())
+        file.setFileName(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname));
+
+
     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
     {
-
         QTextStream in(&file);
-        while (!in.atEnd()) {
+        while (!in.atEnd())
+        {
             QString line = in.readLine();
-            if(line != QString(""))
-                {list.append(line);}
+            if(!line.isEmpty())
+                list.append(line);
         }
     }
 
-    if (list.size()==0)
+    if (list.size() == 0)
          list.append(QString("generic"));
 
+    return list;
 }
 
+// loades types from ini files. returns true on success.
+bool HWNamegen::loadTypes()
+{
+    QFile file;
+
+    // find .cfg to load the names from
+    file.setFileName(QString("%1/Data/Names/types.ini").arg(cfgdir->absolutePath()));
+    if (!file.exists())
+        file.setFileName(QString("%1/Names/types.ini").arg(datadir->absolutePath()));
+
 
-void HWNamegen::loadTypes()
-{
-    QFile file;
-    file.setFileName(QString("%1/Data/Names/types.ini").arg(cfgdir->absolutePath()));
-    if (!file.exists()) file.setFileName(QString("%1/Names/types.ini").arg(datadir->absolutePath()));
     if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
-        {typesAvailable = false; return;}
+        return false;
 
     int counter = 0; //counter starts with 0 (teamnames mode)
     TypesTeamnames.append(QStringList());
     TypesHatnames.append(QStringList());
 
     QTextStream in(&file);
-    while (!in.atEnd()) {
+    while (!in.atEnd())
+    {
         QString line = in.readLine();
-        if (line == QString("#####")){
+        if (line == QString("#####"))
+        {
             counter++; //toggle mode (teamnames || hats)
-            if ((counter%2) == 0){
+            if ((counter%2) == 0)
+            {
                 TypesTeamnames.append(QStringList());
                 TypesHatnames.append(QStringList());
             }
-        } else if ((line == QString("*****")) || (line == QString("*END*"))){
-            typesAvailable = true; return; // bye bye
-        } else {
-            if ((counter%2) == 0){ // even => teamnames mode
+        }
+        else if ((line == QString("*****")) || (line == QString("*END*")))
+        {
+            typesAvailable = true;
+            return true; // bye bye
+        }
+        else
+        {
+            if ((counter%2) == 0)
+            {
+                // even => teamnames mode
                 TypesTeamnames[(counter/2)].append(line);
-            } else { // odd => hats mode
+            }
+            else
+            {
+                // odd => hats mode
                 TypesHatnames[((counter-1)/2)].append(line);
             }
         }
-//        Types.append(line);
     }
-        typesAvailable = true;
-    return;
+
+    typesAvailable = true;
+    return true;
 }
 
 
--- a/QTfrontend/namegen.h	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/namegen.h	Sun Sep 25 19:30:10 2011 +0200
@@ -28,24 +28,24 @@
 class HWNamegen
 {
 public:
-    HWNamegen();
-    ~HWNamegen();
 
-    void teamRandomName(HWTeam & team, const int HedgehogNumber);
-    void teamRandomNames(HWTeam & team, const bool changeteamname);
-    void randomNameByHat(HWTeam & team, const int HedgehogNumber);
+    static void teamRandomName(HWTeam & team, const int HedgehogNumber);
+    static void teamRandomNames(HWTeam & team, const bool changeteamname);
 
 private:
+        HWNamegen();
 
-        QList<QStringList> TypesTeamnames;
-        QList<QStringList> TypesHatnames;
-        bool typesAvailable;
-        void loadTypes();
-        void dictLoad(const QString filename, QStringList &list);
-        void hatCfgLoad(const QString hatname, QStringList &list);
+        static QList<QStringList> TypesTeamnames;
+        static QList<QStringList> TypesHatnames;
+        static bool typesAvailable;
 
-        QString getRandomGrave();
-        QString getRandomFort();
+        static bool loadTypes();
+        static QStringList dictContents(const QString filename);
+        static QStringList dictsForHat(const QString hatname);
+
+        static QString getRandomGrave();
+        static QString getRandomFort();
+        static void teamRandomName(HWTeam & team, const int HedgehogNumber, const QStringList & dict);
 };
 
 
--- a/QTfrontend/newnetclient.cpp	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/newnetclient.cpp	Sun Sep 25 19:30:10 2011 +0200
@@ -112,7 +112,7 @@
          team.flag() + delimeter +
          QString::number(team.difficulty());
 
-    for(unsigned int i = 0; i < HEDGEHOGS_PER_TEAM; ++i)
+    for(int i = 0; i < HEDGEHOGS_PER_TEAM; ++i)
     {
         cmd.append(delimeter);
         cmd.append(team.hedgehog(i).Name);
--- a/QTfrontend/pageeditteam.cpp	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/pageeditteam.cpp	Sun Sep 25 19:30:10 2011 +0200
@@ -24,10 +24,10 @@
 #include <QTabWidget>
 #include <QGroupBox>
 #include <QToolBox>
+#include <QMessageBox>
 
 #include "pageeditteam.h"
 #include "sdlkeys.h"
-#include "hwconsts.h"
 #include "SquareLabel.h"
 #include "hats.h"
 #include "HWApplication.h"
@@ -35,6 +35,7 @@
 PageEditTeam::PageEditTeam(QWidget* parent, SDLInteraction * sdli) :
   AbstractPage(parent)
 {
+    m_playerHash = "0000000000000000000000000000000000000000";
     mySdli = sdli;
     QGridLayout * pageLayout = new QGridLayout(this);
     QTabWidget * tbw = new QTabWidget(this);
@@ -43,11 +44,15 @@
     tbw->addTab(page1, tr("General"));
     tbw->addTab(page2, tr("Advanced"));
     pageLayout->addWidget(tbw, 0, 0, 1, 3);
-    BtnTeamDiscard = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
+
     BtnTeamSave = addButton(":/res/Save.png", pageLayout, 1, 2, true);;
     BtnTeamSave->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}");
+    connect(BtnTeamSave, SIGNAL(clicked()), this, SLOT(saveTeam()));
+
+    BtnTeamDiscard = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
     BtnTeamDiscard->setFixedHeight(BtnTeamSave->height());
     BtnTeamDiscard->setStyleSheet("QPushButton{margin-top: 31px;}");
+    connect(BtnTeamDiscard, SIGNAL(clicked()), this, SIGNAL(goBack()));
 
     QHBoxLayout * page1Layout = new QHBoxLayout(page1);
     page1Layout->setAlignment(Qt::AlignTop);
@@ -68,9 +73,10 @@
     signalMapper2 = new QSignalMapper(this);
 
     connect(signalMapper1, SIGNAL(mapped(int)), this, SLOT(fixHHname(int)));
+    connect(signalMapper2, SIGNAL(mapped(int)), this, SLOT(setRandomName(int)));
 
     HatsModel * hatsModel = new HatsModel(GBoxHedgehogs);
-    for(int i = 0; i < 8; i++)
+    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
     {
         HHHats[i] = new QComboBox(GBoxHedgehogs);
         HHHats[i]->setModel(hatsModel);
@@ -95,6 +101,7 @@
     }
 
     randTeamButton = addButton(QPushButton::tr("Random Team"), GBHLayout, 9, false);
+    connect(randTeamButton, SIGNAL(clicked()), this, SLOT(setRandomNames()));
 
     vbox1->addWidget(GBoxHedgehogs);
 
@@ -345,6 +352,7 @@
             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]);
         pagelayout->addWidget(CBBind[i++], num++, 1);
     }
+
 }
 
 void PageEditTeam::fixHHname(int idx)
@@ -384,3 +392,106 @@
         Mix_PlayChannel(-1, sound, 0);
     }
 }
+
+void PageEditTeam::createTeam(const QString & name, const QString & playerHash)
+{
+    m_playerHash = playerHash;
+    HWTeam newTeam(name);
+    loadTeam(newTeam);
+}
+
+void PageEditTeam::editTeam(const QString & name, const QString & playerHash)
+{
+    m_playerHash = playerHash;
+    HWTeam team(name);
+    team.loadFromFile();
+    loadTeam(team);
+}
+
+void PageEditTeam::deleteTeam(const QString & name)
+{
+    QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel, this);
+
+    if (reallyDelete.exec() == QMessageBox::Ok)
+        HWTeam(name).deleteFile();
+}
+
+void PageEditTeam::setRandomNames()
+{
+    HWTeam team = data();
+    HWNamegen::teamRandomNames(team, true);
+    loadTeam(team);
+}
+
+void PageEditTeam::setRandomName(int hh_index)
+{
+    HWTeam team = data();
+    HWNamegen::teamRandomName(team,hh_index);
+    loadTeam(team);
+}
+
+void PageEditTeam::loadTeam(const HWTeam & team)
+{
+    TeamNameEdit->setText(team.name());
+    CBTeamLvl->setCurrentIndex(team.difficulty());
+
+    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
+    {
+        HWHog hh = team.hedgehog(i);
+
+        HHNameEdit[i]->setText(hh.Name);
+
+        if (hh.Hat.startsWith("Reserved"))
+            hh.Hat = hh.Hat.remove(0,40);
+
+        HHHats[i]->setCurrentIndex(HHHats[i]->findData(hh.Hat, Qt::DisplayRole));
+    }
+
+    CBGrave->setCurrentIndex(CBGrave->findText(team.grave()));
+    CBFlag->setCurrentIndex(CBFlag->findData(team.flag()));
+
+    CBFort->setCurrentIndex(CBFort->findText(team.fort()));
+    CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack()));
+
+    for(int i = 0; i < BINDS_NUMBER; i++)
+    {
+        CBBind[i]->setCurrentIndex(CBBind[i]->findData(team.keyBind(i)));
+    }
+}
+
+HWTeam PageEditTeam::data()
+{
+    HWTeam team(TeamNameEdit->text());
+    team.setDifficulty(CBTeamLvl->currentIndex());
+
+    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
+    {
+        HWHog hh;
+        hh.Name = HHNameEdit[i]->text();
+        hh.Hat = HHHats[i]->currentText();
+
+        if (hh.Hat.startsWith("Reserved"))
+            hh.Hat = "Reserved"+m_playerHash+hh.Hat.remove(0,9);
+
+        team.setHedgehog(i,hh);
+    }
+
+    team.setGrave(CBGrave->currentText());
+    team.setFort(CBFort->currentText());
+    team.setVoicepack(CBVoicepack->currentText());
+    team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString());
+
+    for(int i = 0; i < BINDS_NUMBER; i++)
+    {
+        team.bindKey(i,CBBind[i]->itemData(CBBind[i]->currentIndex()).toString());
+    }
+
+    return team;
+}
+
+void PageEditTeam::saveTeam()
+{
+    data().saveToFile();
+    emit teamEdited();
+}
+
--- a/QTfrontend/pageeditteam.h	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/pageeditteam.h	Sun Sep 25 19:30:10 2011 +0200
@@ -21,8 +21,12 @@
 
 #include "AbstractPage.h"
 #include "binds.h"
+#include "hwconsts.h"
+#include "namegen.h"
 #include "SDLs.h"
 
+#include "team.h"
+
 class SquareLabel;
 
 class PageEditTeam : public AbstractPage
@@ -31,6 +35,19 @@
 
 public:
     PageEditTeam(QWidget* parent, SDLInteraction * sdli);
+
+    void createTeam(const QString & name, const QString & playerHash);
+    void editTeam(const QString & name, const QString & playerHash);
+    void deleteTeam(const QString & name);
+
+signals:
+    void teamEdited();
+
+public slots:
+    void CBFort_activated(const QString & gravename);
+
+private:
+    QPushButton * randTeamButton;
     QSignalMapper* signalMapper1;
     QSignalMapper* signalMapper2;
     QGroupBox *GBoxHedgehogs;
@@ -48,19 +65,20 @@
     QPushButton *BtnTeamSave;
     QPushButton * BtnTestSound;
     QLineEdit * TeamNameEdit;
-    QLineEdit * HHNameEdit[8];
-    QComboBox * HHHats[8];
-    QPushButton * randButton[8];
+    QLineEdit * HHNameEdit[HEDGEHOGS_PER_TEAM];
+    QComboBox * HHHats[HEDGEHOGS_PER_TEAM];
+    QPushButton * randButton[HEDGEHOGS_PER_TEAM];
     QComboBox * CBBind[BINDS_NUMBER];
-    QPushButton * randTeamButton;
+    SDLInteraction * mySdli;
+    HWTeam data();
+    QString m_playerHash;
 
-private:
-    SDLInteraction * mySdli;
-
-public slots:
-    void CBFort_activated(const QString & gravename);
+    void loadTeam(const HWTeam & team);
 
 private slots:
+    void saveTeam();
+    void setRandomNames();
+    void setRandomName(int hh_index);
     void testSound();
     void fixHHname(int idx);
 };
--- a/QTfrontend/pageoptions.cpp	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/pageoptions.cpp	Sun Sep 25 19:30:10 2011 +0200
@@ -76,6 +76,7 @@
             BtnNewTeam->setIconSize(pmNew.size());
             BtnNewTeam->setIcon(pmNew);
             BtnNewTeam->setMaximumWidth(pmNew.width() + 6);
+            connect(BtnNewTeam, SIGNAL(clicked()), this, SIGNAL(newTeamRequested()));
             GBTlayout->addWidget(BtnNewTeam, 0, 1);
 
             BtnEditTeam = new QPushButton(teamsBox);
@@ -83,6 +84,7 @@
             BtnEditTeam->setIconSize(pmEdit.size());
             BtnEditTeam->setIcon(pmEdit);
             BtnEditTeam->setMaximumWidth(pmEdit.width() + 6);
+            connect(BtnEditTeam, SIGNAL(clicked()), this, SLOT(requestEditSelectedTeam()));
             GBTlayout->addWidget(BtnEditTeam, 0, 2);
 
             BtnDeleteTeam = new QPushButton(teamsBox);
@@ -90,6 +92,7 @@
             BtnDeleteTeam->setIconSize(pmDelete.size());
             BtnDeleteTeam->setIcon(pmDelete);
             BtnDeleteTeam->setMaximumWidth(pmDelete.width() + 6);
+            connect(BtnDeleteTeam, SIGNAL(clicked()), this, SLOT(requestDeleteSelectedTeam()));
             GBTlayout->addWidget(BtnDeleteTeam, 0, 3);
 
             LblNoEditTeam = new QLabel(teamsBox);
@@ -457,3 +460,23 @@
 {
     editNetNick->setText(editNetNick->text().trimmed());
 }
+
+void PageOptions::requestEditSelectedTeam()
+{
+    emit editTeamRequested(CBTeamName->currentText());
+}
+
+void PageOptions::requestDeleteSelectedTeam()
+{
+    emit deleteTeamRequested(CBTeamName->currentText());
+}
+
+void PageOptions::setTeamOptionsEnabled(bool enabled)
+{
+    BtnNewTeam->setVisible(enabled);
+    BtnEditTeam->setVisible(enabled);
+    BtnDeleteTeam->setVisible(enabled);
+    CBTeamName->setVisible(enabled);
+    LblNoEditTeam->setVisible(!enabled);
+}
+
--- a/QTfrontend/pageoptions.h	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/pageoptions.h	Sun Sep 25 19:30:10 2011 +0200
@@ -43,12 +43,8 @@
 
     QComboBox *CBLanguage;
 
-    IconedGroupBox *teamsBox;
-    QPushButton *BtnNewTeam;
-    QPushButton *BtnEditTeam;
-    QPushButton *BtnDeleteTeam;
+    IconedGroupBox *teamsBox;;
     QPushButton *BtnAssociateFiles;
-    QLabel *LblNoEditTeam;
     QComboBox *CBTeamName;
     IconedGroupBox *AGGroupBox;
     QComboBox *CBResolution;
@@ -76,10 +72,22 @@
     QSlider *SLQuality;
     QCheckBox *CBFrontendEffects;
 
+    void setTeamOptionsEnabled(bool enabled);
+
+signals:
+    void newTeamRequested();
+    void editTeamRequested(const QString & teamName);
+    void deleteTeamRequested(const QString & teamName);
+
+
 private:
     bool previousFullscreenValue;
     int previousResolutionIndex;
     int previousQuality;
+    QLabel *LblNoEditTeam;
+    QPushButton *BtnNewTeam;
+    QPushButton *BtnEditTeam;
+    QPushButton *BtnDeleteTeam;
     QPushButton *BtnBack;
 
 private slots:
@@ -88,6 +96,8 @@
     void setResolution(int state);
     void setQuality(int value);
     void trimNetNick();
+    void requestEditSelectedTeam();
+    void requestDeleteSelectedTeam();
 };
 
 #endif
--- a/QTfrontend/team.cpp	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/team.cpp	Sun Sep 25 19:30:10 2011 +0200
@@ -46,8 +46,8 @@
     m_flag = "hedgewars";
     for(int i = 0; i < BINDS_NUMBER; i++)
     {
-        binds[i].action = cbinds[i].action;
-        binds[i].strbind = cbinds[i].strbind;
+        m_binds[i].action = cbinds[i].action;
+        m_binds[i].strbind = cbinds[i].strbind;
     }
     m_rounds = 0;
     m_wins = 0;
@@ -99,8 +99,8 @@
 
     for(int i = 0; i < BINDS_NUMBER; i++)
     {
-        binds[i].action = cbinds[i].action;
-        binds[i].strbind = cbinds[i].strbind;
+        m_binds[i].action = cbinds[i].action;
+        m_binds[i].strbind = cbinds[i].strbind;
     }
     m_rounds = 0;
     m_wins = 0;
@@ -132,7 +132,7 @@
         m_hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt();
     }
     for(int i = 0; i < BINDS_NUMBER; i++)
-        binds[i].strbind = teamfile.value(QString("Binds/%1").arg(binds[i].action), cbinds[i].strbind).toString();
+        m_binds[i].strbind = teamfile.value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString();
     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
         if(achievements[i][0][0])
             AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt();
@@ -186,7 +186,7 @@
         teamfile.setValue(hh + "Suicides", m_hedgehogs[i].Suicides);
     }
     for(int i = 0; i < BINDS_NUMBER; i++)
-        teamfile.setValue(QString("Binds/%1").arg(binds[i].action), binds[i].strbind);
+        teamfile.setValue(QString("Binds/%1").arg(m_binds[i].action), m_binds[i].strbind);
     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
         if(achievements[i][0][0])
             teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]);
@@ -195,54 +195,6 @@
     return true;
 }
 
-void HWTeam::SetToPage(HWForm * hwform)
-{
-    hwform->ui.pageEditTeam->TeamNameEdit->setText(m_name);
-    hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(m_difficulty);
-    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
-    {
-         hwform->ui.pageEditTeam->HHNameEdit[i]->setText(m_hedgehogs[i].Name);
-         if (m_hedgehogs[i].Hat.startsWith("Reserved"))
-            hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData("Reserved "+m_hedgehogs[i].Hat.remove(0,40), Qt::DisplayRole));
-         else
-            hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(m_hedgehogs[i].Hat, Qt::DisplayRole));
-    }
-    hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(m_grave));
-    hwform->ui.pageEditTeam->CBFlag->setCurrentIndex(hwform->ui.pageEditTeam->CBFlag->findData(m_flag));
-
-    hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(m_fort));
-    hwform->ui.pageEditTeam->CBVoicepack->setCurrentIndex(hwform->ui.pageEditTeam->CBVoicepack->findText(m_voicepack));
-    //hwform->ui.pageEditTeam->CBFort_activated(Fort);
-
-    for(int i = 0; i < BINDS_NUMBER; i++)
-    {
-        hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findData(binds[i].strbind));
-    }
-}
-
-void HWTeam::GetFromPage(HWForm * hwform)
-{
-    m_name  = hwform->ui.pageEditTeam->TeamNameEdit->text();
-    m_difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex();
-    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
-    {
-        m_hedgehogs[i].Name = hwform->ui.pageEditTeam->HHNameEdit[i]->text();
-        if (hwform->ui.pageEditTeam->HHHats[i]->currentText().startsWith("Reserved"))
-            m_hedgehogs[i].Hat = "Reserved"+playerHash+hwform->ui.pageEditTeam->HHHats[i]->currentText().remove(0,9);
-        else
-            m_hedgehogs[i].Hat = hwform->ui.pageEditTeam->HHHats[i]->currentText();
-    }
-
-    m_grave = hwform->ui.pageEditTeam->CBGrave->currentText();
-    m_fort = hwform->ui.pageEditTeam->CBFort->currentText();
-    m_voicepack = hwform->ui.pageEditTeam->CBVoicepack->currentText();
-    m_flag = hwform->ui.pageEditTeam->CBFlag->itemData(hwform->ui.pageEditTeam->CBFlag->currentIndex()).toString();
-    for(int i = 0; i < BINDS_NUMBER; i++)
-    {
-        binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->itemData(hwform->ui.pageEditTeam->CBBind[i]->currentIndex()).toString();
-    }
-}
-
 QStringList HWTeam::teamGameConfig(quint32 InitHealth) const
 {
     QStringList sl;
@@ -260,8 +212,8 @@
 
     if (!m_isNetTeam)
         for(int i = 0; i < BINDS_NUMBER; i++)
-            if(!binds[i].strbind.isEmpty())
-                sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
+            if(!m_binds[i].strbind.isEmpty())
+                sl.push_back(QString("ebind " + m_binds[i].strbind + " " + m_binds[i].action));
 
     for (int t = 0; t < m_numHedgehogs; t++)
     {
@@ -299,7 +251,7 @@
 
 // single hedgehog
 const HWHog & HWTeam::hedgehog(unsigned int idx) const { return m_hedgehogs[idx]; }
-         void HWTeam::setHedgehog(unsigned int idx, const HWHog & hh) { m_hedgehogs[idx] = hh; }
+         void HWTeam::setHedgehog(unsigned int idx, HWHog hh) { m_hedgehogs[idx] = hh; }
 
 // owner
 QString HWTeam::owner() const { return m_owner; }
@@ -315,6 +267,9 @@
   void HWTeam::setColor(const QColor & color) { m_color = color; }
 
 
+// binds
+QString HWTeam::keyBind(unsigned int idx) const { return m_binds[idx].strbind; }
+   void HWTeam::bindKey(unsigned int idx, const QString & key) { m_binds[idx].strbind = key; }
 
 // flag
 void    HWTeam::setFlag(const QString & flag) { m_flag = flag; }
--- a/QTfrontend/team.h	Sun Sep 25 16:09:55 2011 +0200
+++ b/QTfrontend/team.h	Sun Sep 25 19:30:10 2011 +0200
@@ -52,6 +52,7 @@
         HWTeam();
 
         // file operations
+        static HWTeam loadFromFile(const QString & teamName);
         bool loadFromFile();
         bool deleteFile();
         bool saveToFile();
@@ -66,18 +67,20 @@
               QString grave() const;
         const HWHog & hedgehog(unsigned int idx) const;
                  bool isNetTeam() const;
+              QString keyBind(unsigned int idx) const;
               QString name() const;
         unsigned char numHedgehogs() const;
               QString owner() const;
               QString voicepack() const;
 
         // attribute setters
+        void bindKey(unsigned int idx, const QString & key);
         void setColor(const QColor & color);
         void setDifficulty(unsigned int level);
         void setFlag(const QString & flag);
         void setFort(const QString & fort);
         void setGrave(const QString & grave);
-        void setHedgehog(unsigned int idx, const HWHog & hh);
+        void setHedgehog(unsigned int idx, HWHog hh);
         void setName(const QString & name);
         void setNumHedgehogs(unsigned char num);
         void setVoicepack(const QString & voicepack);
@@ -86,10 +89,6 @@
         void incRounds();
         void incWins();
 
-        // pages... wait... wth is THIS doing in this class? FIXME!!!!
-        void SetToPage(HWForm * hwform);
-        void GetFromPage(HWForm * hwform);
-
         // convert team info into strings for further computation
         QStringList teamGameConfig(quint32 InitHealth) const;
 
@@ -111,7 +110,7 @@
         QString m_voicepack;
         HWHog m_hedgehogs[HEDGEHOGS_PER_TEAM];
         unsigned int m_difficulty;
-        BindAction binds[BINDS_NUMBER];
+        BindAction m_binds[BINDS_NUMBER];
 
         // class members that contain info for the current game setup
         unsigned char m_numHedgehogs;