QTfrontend/hwform.cpp
changeset 322 e7175ae57945
parent 314 83773ccf4f09
child 323 ea947f2c3d2f
equal deleted inserted replaced
321:1148eeb0557e 322:e7175ae57945
    75 	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    75 	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    76 	connect(ui.pageNet->BtnNetConnect,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
    76 	connect(ui.pageNet->BtnNetConnect,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
    77 	connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
    77 	connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
    78 
    78 
    79 	connect(ui.pageNetGame->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    79 	connect(ui.pageNetGame->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    80 	connect(ui.pageNetGame->BtnAddTeam,	SIGNAL(clicked()),	this, SLOT(NetAddTeam()));
    80 	connect(ui.pageNetGame->pNetTeamsWidget,	SIGNAL(teamWillPlay(HWTeam)),	this, SLOT(NetAddTeam(HWTeam)));
    81 	connect(ui.pageNetGame->BtnGo,	SIGNAL(clicked()),	this, SLOT(NetStartGame()));
    81 	connect(ui.pageNetGame->BtnGo,	SIGNAL(clicked()),	this, SLOT(NetStartGame()));
    82 
    82 
    83 	connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect()));
    83 	connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect()));
    84 	connect(ui.pageNetChat->BtnJoin,	SIGNAL(clicked()),	this, SLOT(NetJoin()));
    84 	connect(ui.pageNetChat->BtnJoin,	SIGNAL(clicked()),	this, SLOT(NetJoin()));
    85 	connect(ui.pageNetChat->BtnCreate,	SIGNAL(clicked()),	this, SLOT(NetCreate()));
    85 	connect(ui.pageNetChat->BtnCreate,	SIGNAL(clicked()),	this, SLOT(NetCreate()));
   154 	GoToPage(ID_PAGE_NETCHAT);
   154 	GoToPage(ID_PAGE_NETCHAT);
   155 }
   155 }
   156 
   156 
   157 void HWForm::OnPageShown(quint8 id)
   157 void HWForm::OnPageShown(quint8 id)
   158 {
   158 {
   159 	if (id == ID_PAGE_MULTIPLAYER) {
   159 	if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETCFG) {
   160 		QStringList tmNames=config->GetTeamsList();
   160 		QStringList tmNames=config->GetTeamsList();
       
   161 		TeamSelWidget* curTeamSelWidget;
       
   162 		id == ID_PAGE_MULTIPLAYER ? curTeamSelWidget=ui.pageMultiplayer->teamsSelect : 
       
   163 		  curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget;
   161 		QList<HWTeam> teamsList;
   164 		QList<HWTeam> teamsList;
   162 		for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) {
   165 		for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) {
   163 		  HWTeam team(*it);
   166 		  HWTeam team(*it);
   164 		  team.LoadFromFile();
   167 		  team.LoadFromFile();
   165 		  teamsList.push_back(team);
   168 		  teamsList.push_back(team);
   166 		}
   169 		}
   167 		ui.pageMultiplayer->teamsSelect->resetPlayingTeams(teamsList);
   170 		curTeamSelWidget->resetPlayingTeams(teamsList);
   168 	}
   171 	}
   169 }
   172 }
   170 
   173 
   171 void HWForm::GoToPage(quint8 id)
   174 void HWForm::GoToPage(quint8 id)
   172 {
   175 {
   234 }
   237 }
   235 
   238 
   236 void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick)
   239 void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick)
   237 {
   240 {
   238 	hwnet = new HWNewNet(config);
   241 	hwnet = new HWNewNet(config);
   239 	connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
       
   240 	connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
   242 	connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
   241 	connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
   243 	connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
   242 	connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
   244 	connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
   243 	hwnet->Connect(hostName, port, nick);
   245 	hwnet->Connect(hostName, port, nick);
   244 	config->SaveOptions();
   246 	config->SaveOptions();
   287 void HWForm::NetCreate()
   289 void HWForm::NetCreate()
   288 {
   290 {
   289 	hwnet->JoinGame("#hw");
   291 	hwnet->JoinGame("#hw");
   290 }
   292 }
   291 
   293 
   292 void HWForm::NetAddTeam()
   294 void HWForm::NetAddTeam(HWTeam team)
   293 {
   295 {
   294 	HWTeam team("DefaultTeam");
   296   hwnet->AddTeam(team);
   295 	team.LoadFromFile();
       
   296 	hwnet->AddTeam(team);
       
   297 }
   297 }
   298 
   298 
   299 void HWForm::NetStartGame()
   299 void HWForm::NetStartGame()
   300 {
   300 {
   301 	hwnet->StartGame();
   301 	hwnet->StartGame();
   302 }
   302 }
   303 
   303 
   304 void HWForm::ChangeInNetTeams(const QStringList & teams)
   304 void HWForm::ChangeInNetTeams(const QStringList & teams)
   305 {
   305 {
   306 	ui.pageNetGame->listNetTeams->clear();
   306   QStringList addedTeams=teams;
   307 	ui.pageNetGame->listNetTeams->addItems(teams);
   307   list<HWTeam> lstPlaying=ui.pageNetGame->pNetTeamsWidget->getPlayingTeams();
       
   308   for(list<HWTeam>::iterator it=lstPlaying.begin(); it!=lstPlaying.end(); ++it) {
       
   309     QString nm=it->TeamName;
       
   310     QStringList::iterator itt=std::find(addedTeams.begin(), addedTeams.end(), nm);
       
   311     if(itt!=addedTeams.end()) addedTeams.erase(itt);
       
   312   }
       
   313   for(QStringList::iterator it=addedTeams.begin(); it!=addedTeams.end(); ++it) {
       
   314     ui.pageNetGame->pNetTeamsWidget->addTeam(*it, true);
       
   315   }
   308 }
   316 }
   309 
   317 
   310 void HWForm::StartMPGame()
   318 void HWForm::StartMPGame()
   311 {
   319 {
   312 	CreateGame(ui.pageMultiplayer->gameCFG);
   320 	CreateGame(ui.pageMultiplayer->gameCFG);