QTfrontend/hwform.cpp
changeset 1509 34f7dd4efe84
parent 1490 4eb4fc12cc30
child 1512 43742041c211
equal deleted inserted replaced
1508:ef093f31ced1 1509:34f7dd4efe84
    90 	connect(ui.pageOptions->BtnNewTeam,	SIGNAL(clicked()),	this, SLOT(NewTeam()));
    90 	connect(ui.pageOptions->BtnNewTeam,	SIGNAL(clicked()),	this, SLOT(NewTeam()));
    91 	connect(ui.pageOptions->BtnEditTeam,	SIGNAL(clicked()),	this, SLOT(EditTeam()));
    91 	connect(ui.pageOptions->BtnEditTeam,	SIGNAL(clicked()),	this, SLOT(EditTeam()));
    92 	connect(ui.pageOptions->BtnSaveOptions,	SIGNAL(clicked()),	config, SLOT(SaveOptions()));
    92 	connect(ui.pageOptions->BtnSaveOptions,	SIGNAL(clicked()),	config, SLOT(SaveOptions()));
    93 	connect(ui.pageOptions->BtnSaveOptions,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    93 	connect(ui.pageOptions->BtnSaveOptions,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    94 
    94 
    95 	connect(ui.pageOptions->WeaponEdit,	SIGNAL(clicked()),	this, SLOT(GoToSelectWeapon()));
    95 	connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon()));
    96 	connect(ui.pageOptions->WeaponsButt,	SIGNAL(clicked()),	this, SLOT(GoToSelectNewWeapon()));
    96 	connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon()));
    97 	connect(ui.pageSelectWeapon->pWeapons,       SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons()));
    97 	connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons()));
    98 	connect(ui.pageNetGame->pGameCFG,       SIGNAL(newWeaponsName(const QString&)), this, SLOT(NetWeaponNameChanged(const QString&)));
    98 	connect(ui.pageNetGame->pGameCFG, SIGNAL(newWeaponsName(const QString&)), this, SLOT(NetWeaponNameChanged(const QString&)));
    99 
    99 
   100 	connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
   100 	connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
   101 	connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect()));
   101 	connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect()));
   102 	connect(ui.pageNet->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   102 	connect(ui.pageNet->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   103 	connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(GoToNetServer()));
   103 	connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(GoToNetServer()));
   172 	combos.push_back(ui.pageNetGame->pGameCFG->WeaponsName);
   172 	combos.push_back(ui.pageNetGame->pGameCFG->WeaponsName);
   173 
   173 
   174 	for(QVector<QComboBox*>::iterator it=combos.begin(); it!=combos.end(); ++it) {
   174 	for(QVector<QComboBox*>::iterator it=combos.begin(); it!=combos.end(); ++it) {
   175 		(*it)->clear();
   175 		(*it)->clear();
   176 		(*it)->addItems(ui.pageSelectWeapon->pWeapons->getWeaponNames());
   176 		(*it)->addItems(ui.pageSelectWeapon->pWeapons->getWeaponNames());
   177 		int pos=(*it)->findText("Default");
   177 		int pos = (*it)->findText("Default");
   178 		if (pos!=-1) {
   178 		if (pos != -1) {
   179 			(*it)->setCurrentIndex(pos);
   179 			(*it)->setCurrentIndex(pos);
   180 		}
   180 		}
   181 	}
   181 	}
   182 }
   182 }
   183 
   183 
   184 void HWForm::NetWeaponNameChanged(const QString& name)
   184 void HWForm::NetWeaponNameChanged(const QString& name)
   185 {
   185 {
   186 	QString ammo = ui.pageSelectWeapon->pWeapons->getWeaponsString(
   186 	QString ammo = ui.pageSelectWeapon->pWeapons->getWeaponsString(name);
   187 			ui.pageNetGame->pGameCFG->WeaponsName->currentText()
   187 
   188 			);
   188 	if (hwnet)
   189 
   189 		hwnet->onWeaponsNameChanged(name, ammo);
   190 	hwnet->onWeaponsNameChanged(name, ammo);
       
   191 }
   190 }
   192 
   191 
   193 void HWForm::UpdateTeamsLists(const QStringList* editable_teams)
   192 void HWForm::UpdateTeamsLists(const QStringList* editable_teams)
   194 {
   193 {
   195 	QStringList teamslist;
   194 	QStringList teamslist;
   196 	if(editable_teams) {
   195 	if(editable_teams) {
   197 	  teamslist=*editable_teams;
   196 	  teamslist =* editable_teams;
   198 	} else {
   197 	} else {
   199 	  teamslist = config->GetTeamsList();
   198 	  teamslist = config->GetTeamsList();
   200 	}
   199 	}
   201 
   200 
   202 	if(teamslist.empty()) {
   201 	if(teamslist.empty()) {
   229 	GoToPage(ID_PAGE_SETUP);
   228 	GoToPage(ID_PAGE_SETUP);
   230 }
   229 }
   231 
   230 
   232 void HWForm::GoToSelectNewWeapon()
   231 void HWForm::GoToSelectNewWeapon()
   233 {
   232 {
   234   ui.pageSelectWeapon->pWeapons->setWeaponsName("", false);
   233 	ui.pageSelectWeapon->pWeapons->setWeaponsName(tr("new"));
   235 	GoToPage(ID_PAGE_SELECTWEAPON);
   234 	GoToPage(ID_PAGE_SELECTWEAPON);
   236 }
   235 }
   237 
   236 
   238 void HWForm::GoToSelectWeapon()
   237 void HWForm::GoToSelectWeapon()
   239 {
   238 {
   240   ui.pageSelectWeapon->pWeapons->setWeaponsName(ui.pageOptions->WeaponsName->currentText(), true);
   239 	ui.pageSelectWeapon->pWeapons->setWeaponsName(ui.pageOptions->WeaponsName->currentText());
   241 	GoToPage(ID_PAGE_SELECTWEAPON);
   240 	GoToPage(ID_PAGE_SELECTWEAPON);
   242 }
   241 }
   243 
   242 
   244 void HWForm::GoToInfo()
   243 void HWForm::GoToInfo()
   245 {
   244 {
   348 	}
   347 	}
   349 }
   348 }
   350 
   349 
   351 void HWForm::IntermediateSetup()
   350 void HWForm::IntermediateSetup()
   352 {
   351 {
   353   quint8 id=ui.Pages->currentIndex();
   352 	quint8 id=ui.Pages->currentIndex();
   354   TeamSelWidget* curTeamSelWidget;
   353 	TeamSelWidget* curTeamSelWidget;
   355   if(id == ID_PAGE_MULTIPLAYER) {
   354 	
   356     curTeamSelWidget=ui.pageMultiplayer->teamsSelect;
   355 	if(id == ID_PAGE_MULTIPLAYER) {
   357   } else {
   356 		curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
   358     curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget;
   357 	} else {
   359   }
   358 		curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   360   QList<HWTeam> teams=curTeamSelWidget->getDontPlayingTeams();
   359 	}
   361   QStringList tmnames;
   360 	
   362   for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) {
   361 	QList<HWTeam> teams = curTeamSelWidget->getDontPlayingTeams();
   363     tmnames+=it->TeamName;
   362 	QStringList tmnames;
   364   }
   363 	for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) {
   365   UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring
   364 		tmnames += it->TeamName;
   366 
   365 	}
   367   GoToPage(ID_PAGE_SETUP);
   366 	UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring
       
   367 
       
   368 	GoToPage(ID_PAGE_SETUP);
   368 }
   369 }
   369 
   370 
   370 void HWForm::NewTeam()
   371 void HWForm::NewTeam()
   371 {
   372 {
   372 	editedTeam = new HWTeam("unnamed");
   373 	editedTeam = new HWTeam("unnamed");
   534 
   535 
   535 	pnetserver = new HWNetServer;
   536 	pnetserver = new HWNetServer;
   536 	if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
   537 	if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
   537 	{
   538 	{
   538 		QMessageBox::critical(0, tr("Error"),
   539 		QMessageBox::critical(0, tr("Error"),
   539 					tr("Unable to start the server"));
   540 				tr("Unable to start the server"));
   540 		delete pnetserver;
   541 		delete pnetserver;
   541 		pnetserver = 0;
   542 		pnetserver = 0;
   542 		return;
   543 		return;
   543 	}
   544 	}
   544 
   545 
   554 	NetConnectServer("localhost", pnetserver->getRunningPort());
   555 	NetConnectServer("localhost", pnetserver->getRunningPort());
   555 }
   556 }
   556 
   557 
   557 void HWForm::NetDisconnect()
   558 void HWForm::NetDisconnect()
   558 {
   559 {
   559   if(hwnet) {
   560 	if(hwnet) {
   560     hwnet->Disconnect();
   561 		hwnet->Disconnect();
   561     delete hwnet;
   562 		delete hwnet;
   562     hwnet = 0;
   563 		hwnet = 0;
   563   }
   564 	}
   564   if(pnetserver) {
   565 	if(pnetserver) {
   565     if (pRegisterServer)
   566 		if (pRegisterServer)
   566     {
   567 		{
   567       pRegisterServer->unregister();
   568 			pRegisterServer->unregister();
   568       pRegisterServer = 0;
   569 			pRegisterServer = 0;
   569     }
   570 		}
   570 
   571 
   571     pnetserver->StopServer();
   572 		pnetserver->StopServer();
   572     delete pnetserver;
   573 		delete pnetserver;
   573     pnetserver = 0;
   574 		pnetserver = 0;
   574   }
   575 	}
   575 }
   576 }
   576 
   577 
   577 void HWForm::ForcedDisconnect()
   578 void HWForm::ForcedDisconnect()
   578 {
   579 {
   579 	if(pnetserver) return; // we have server - let it care of all things
   580 	if(pnetserver) return; // we have server - let it care of all things