QTfrontend/hwform.cpp
changeset 6024 d38da7c19e43
parent 6015 daffc14a518a
child 6026 2833862a7e00
equal deleted inserted replaced
6022:8ed6e810051a 6024:d38da7c19e43
    42 #include <QInputDialog>
    42 #include <QInputDialog>
    43 
    43 
    44 #include "hwform.h"
    44 #include "hwform.h"
    45 #include "game.h"
    45 #include "game.h"
    46 #include "team.h"
    46 #include "team.h"
    47 #include "namegen.h"
       
    48 #include "teamselect.h"
    47 #include "teamselect.h"
    49 #include "selectWeapon.h"
    48 #include "selectWeapon.h"
    50 #include "gameuiconfig.h"
    49 #include "gameuiconfig.h"
    51 #include "pageinfo.h"
    50 #include "pageinfo.h"
    52 #include "pagetraining.h"
    51 #include "pagetraining.h"
   113 
   112 
   114     ui.pageOptions->CBResolution->addItems(sdli.getResolutions());
   113     ui.pageOptions->CBResolution->addItems(sdli.getResolutions());
   115 
   114 
   116     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
   115     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
   117 
   116 
   118     namegen = new HWNamegen();
       
   119 
   117 
   120 #ifdef __APPLE__
   118 #ifdef __APPLE__
   121     panel = new M3Panel;
   119     panel = new M3Panel;
   122 
   120 
   123 #ifdef SPARKLE_ENABLED
   121 #ifdef SPARKLE_ENABLED
   168     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   166     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   169 
   167 
   170     connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   168     connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
   171     connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   169     connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
   172 
   170 
   173     connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
   171     connect(ui.pageEditTeam, SIGNAL(teamEdited()), this, SLOT(AfterTeamEdit()));
   174     connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard()));
       
   175 
       
   176     connect(ui.pageEditTeam->signalMapper2, SIGNAL(mapped(const int &)), this, SLOT(RandomName(const int &)));
       
   177     connect(ui.pageEditTeam->randTeamButton, SIGNAL(clicked()), this, SLOT(RandomNames()));
       
   178 
   172 
   179     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
   173     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
   180     connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)),
   174     connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)),
   181         ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool)));
   175         ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool)));
   182     connect(ui.pageMultiplayer, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   176     connect(ui.pageMultiplayer, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   187 
   181 
   188 
   182 
   189     connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo()));
   183     connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo()));
   190     connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo()));
   184     connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo()));
   191 
   185 
   192     connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam()));
   186     connect(ui.pageOptions, SIGNAL(newTeamRequested()), this, SLOT(NewTeam()));
   193     connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam()));
   187     connect(ui.pageOptions, SIGNAL(editTeamRequested(const QString&)), this, SLOT(EditTeam(const QString&)));
   194     connect(ui.pageOptions->BtnDeleteTeam, SIGNAL(clicked()), this, SLOT(DeleteTeam()));
   188     connect(ui.pageOptions, SIGNAL(deleteTeamRequested(const QString&)), this, SLOT(DeleteTeam(const QString&)));
   195     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions()));
   189     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions()));
   196     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack()));
   190     connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack()));
   197     connect(ui.pageOptions->BtnAssociateFiles, SIGNAL(clicked()), this, SLOT(AssociateFiles()));
   191     connect(ui.pageOptions->BtnAssociateFiles, SIGNAL(clicked()), this, SLOT(AssociateFiles()));
   198 
   192 
   199     connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon()));
   193     connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon()));
   474     }
   468     }
   475 
   469 
   476     if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) {
   470     if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) {
   477         QStringList tmNames = config->GetTeamsList();
   471         QStringList tmNames = config->GetTeamsList();
   478         TeamSelWidget* curTeamSelWidget;
   472         TeamSelWidget* curTeamSelWidget;
   479         ui.pageOptions->BtnNewTeam->setVisible(false);
   473         ui.pageOptions->setTeamOptionsEnabled(false);
   480         ui.pageOptions->BtnEditTeam->setVisible(false);
       
   481         ui.pageOptions->BtnDeleteTeam->setVisible(false);
       
   482         ui.pageOptions->CBTeamName->setVisible(false);
       
   483         ui.pageOptions->LblNoEditTeam->setVisible(true);
       
   484 
   474 
   485         if (id == ID_PAGE_MULTIPLAYER) {
   475         if (id == ID_PAGE_MULTIPLAYER) {
   486             curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
   476             curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
   487         } else {
   477         } else {
   488             curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   478             curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   509         if (id == ID_PAGE_GAMESTATS) {
   499         if (id == ID_PAGE_GAMESTATS) {
   510             ui.pageGameStats->renderStats();
   500             ui.pageGameStats->renderStats();
   511         }
   501         }
   512 
   502 
   513     if (id == ID_PAGE_MAIN) {
   503     if (id == ID_PAGE_MAIN) {
   514         ui.pageOptions->BtnNewTeam->setVisible(true);
   504         ui.pageOptions->setTeamOptionsEnabled(true);
   515         ui.pageOptions->BtnEditTeam->setVisible(true);
       
   516         ui.pageOptions->BtnDeleteTeam->setVisible(true);
       
   517         ui.pageOptions->CBTeamName->setVisible(true);
       
   518         ui.pageOptions->LblNoEditTeam->setVisible(false);
       
   519     }
   505     }
   520 
   506 
   521     // load and save ignore/friends lists
   507     // load and save ignore/friends lists
   522     if (lastid == ID_PAGE_NETGAME) // leaving a room
   508     if (lastid == ID_PAGE_NETGAME) // leaving a room
   523         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   509         ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text());
   622     GoToPage(ID_PAGE_SETUP);
   608     GoToPage(ID_PAGE_SETUP);
   623 }
   609 }
   624 
   610 
   625 void HWForm::NewTeam()
   611 void HWForm::NewTeam()
   626 {
   612 {
   627     editedTeam = new HWTeam(QLineEdit::tr("unnamed"));
   613     ui.pageEditTeam->createTeam(QLineEdit::tr("unnamed"), playerHash);
   628     editedTeam->SetToPage(this);
   614     UpdateTeamsLists();
   629     GoToPage(ID_PAGE_SETUP_TEAM);
   615     GoToPage(ID_PAGE_SETUP_TEAM);
   630 }
   616 }
   631 
   617 
   632 void HWForm::EditTeam()
   618 void HWForm::EditTeam(const QString & teamName)
   633 {
   619 {
   634     editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
   620     ui.pageEditTeam->editTeam(teamName, playerHash);
   635     editedTeam->loadFromFile();
       
   636     editedTeam->SetToPage(this);
       
   637     GoToPage(ID_PAGE_SETUP_TEAM);
   621     GoToPage(ID_PAGE_SETUP_TEAM);
   638 }
   622 }
   639 
   623 
   640 void HWForm::DeleteTeam()
   624 void HWForm::AfterTeamEdit()
   641 {
   625 {
   642     QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel);
       
   643 
       
   644     if (reallyDelete.exec() == QMessageBox::Ok) {
       
   645         editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
       
   646         editedTeam->deleteFile();
       
   647 
       
   648         // Remove from lists
       
   649         ui.pageOptions->CBTeamName->removeItem(ui.pageOptions->CBTeamName->currentIndex());
       
   650     }
       
   651 }
       
   652 
       
   653 void HWForm::RandomNames()
       
   654 {
       
   655     editedTeam->GetFromPage(this);
       
   656     namegen->teamRandomNames(*editedTeam, true);
       
   657     editedTeam->SetToPage(this);
       
   658 }
       
   659 
       
   660 void HWForm::RandomName(const int &i)
       
   661 {
       
   662     editedTeam->GetFromPage(this);
       
   663     namegen->teamRandomName(*editedTeam,i);
       
   664     editedTeam->SetToPage(this);
       
   665 }
       
   666 
       
   667 void HWForm::TeamSave()
       
   668 {
       
   669     editedTeam->GetFromPage(this);
       
   670     editedTeam->saveToFile();
       
   671     delete editedTeam;
       
   672     editedTeam=0;
       
   673     UpdateTeamsLists();
   626     UpdateTeamsLists();
   674     GoBack();
   627     GoBack();
   675 }
   628 }
   676 
   629 
   677 void HWForm::TeamDiscard()
   630 
   678 {
   631 void HWForm::DeleteTeam(const QString & teamName)
   679     delete editedTeam;
   632 {
   680     editedTeam=0;
   633     ui.pageEditTeam->deleteTeam(teamName);
   681     GoBack();
   634     QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel);
       
   635 
       
   636     UpdateTeamsLists();
   682 }
   637 }
   683 
   638 
   684 void HWForm::DeleteScheme()
   639 void HWForm::DeleteScheme()
   685 {
   640 {
   686     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   641     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());