Start refactoring some things. Frontend becomes temporarily unusable for network game
authorunc0rr
Sun, 08 Mar 2009 18:43:15 +0000
changeset 1873 815a3ff1fe4b
parent 1872 abfce825a14f
child 1874 1b145e099b75
Start refactoring some things. Frontend becomes temporarily unusable for network game
QTfrontend/gamecfgwidget.cpp
QTfrontend/gamecfgwidget.h
QTfrontend/hwform.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
--- a/QTfrontend/gamecfgwidget.cpp	Sun Mar 08 16:51:16 2009 +0000
+++ b/QTfrontend/gamecfgwidget.cpp	Sun Mar 08 18:43:15 2009 +0000
@@ -179,61 +179,6 @@
 	return sl;
 }
 
-void GameCFGWidget::setSeed(const QString & seed)
-{
-	pMapContainer->setSeed(seed);
-}
-
-void GameCFGWidget::setMap(const QString & map)
-{
-	pMapContainer->setMap(map);
-}
-
-void GameCFGWidget::setTheme(const QString & theme)
-{
-	pMapContainer->setTheme(theme);
-}
-
-void GameCFGWidget::setInitHealth(int health)
-{
-	SB_InitHealth->setValue(health);
-}
-
-void GameCFGWidget::setTurnTime(int time)
-{
-	SB_TurnTime->setValue(time);
-}
-
-void GameCFGWidget::setSuddenDeathTurns(int turns)
-{
-	SB_SuddenDeath->setValue(turns);
-}
-
-void GameCFGWidget::setCaseProbability(int prob)
-{
-	SB_CaseProb->setValue(prob);
-}
-
-void GameCFGWidget::setFortsMode(bool value)
-{
-	CB_mode_Forts->setChecked(value);
-}
-
-void GameCFGWidget::setTeamsDivide(bool value)
-{
-	CB_teamsDivide->setChecked(value);
-}
-
-void GameCFGWidget::setSolid(bool value)
-{
-	CB_solid->setChecked(value);
-}
-
-void GameCFGWidget::setBorder(bool value)
-{
-	CB_border->setChecked(value);
-}
-
 void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo)
 {
 	if (ammo.size() != cDefaultAmmoStore->size())
@@ -254,3 +199,68 @@
 	if (index >= 0)
 		emit newWeaponScheme(WeaponsName->itemText(index), WeaponsName->itemData(index).toString());
 }
+
+void GameCFGWidget::setParam(const QString & param, const QStringList & slValue)
+{
+	if (slValue.size() == 1)
+	{
+		QString value = slValue[0];
+		if (param == "MAP") {
+			pMapContainer->setMap(value);
+			return;
+		}
+		if (param == "SEED") {
+			pMapContainer->setSeed(value);
+			return;
+		}
+		if (param == "THEME") {
+			pMapContainer->setTheme(value);
+			return;
+		}
+		if (param == "HEALTH") {
+			SB_InitHealth->setValue(value.toUInt());
+			return;
+		}
+		if (param == "TURNTIME") {
+			SB_TurnTime->setValue(value.toUInt());
+			return;
+		}
+		if (param == "SD_TURNS") {
+			SB_SuddenDeath->setValue(value.toUInt());
+			return;
+		}
+		if (param == "CASEFACTOR") {
+			SB_CaseProb->setValue(value.toUInt());
+			return;
+		}
+		if (param == "FORTSMODE") {
+			CB_mode_Forts->setChecked(value.toUInt() != 0);
+			return;
+		}
+		if (param == "DIVIDETEAMS") {
+			CB_teamsDivide->setChecked(value.toUInt() != 0);
+			return;
+		}
+		if (param == "SOLIDLAND") {
+			CB_solid->setChecked(value.toUInt() != 0);
+			return;
+		}
+		if (param == "BORDER") {
+			CB_border->setChecked(value.toUInt() != 0);
+			return;
+		}
+/*		if (param == "TEMPLATE_FILTER") {
+			emit templateFilterChanged(lst[2].toUInt());
+			return;
+		}
+*/	}
+
+	if (slValue.size() == 2)
+	{
+		if (param == "AMMO") {
+			setNetAmmo(slValue[0], slValue[1]);
+			return;
+		}
+	}
+}
+
--- a/QTfrontend/gamecfgwidget.h	Sun Mar 08 16:51:16 2009 +0000
+++ b/QTfrontend/gamecfgwidget.h	Sun Mar 08 18:43:15 2009 +0000
@@ -71,20 +71,11 @@
 	HWMapContainer* pMapContainer;
 
 public slots:
-	void setSeed(const QString & seed);
-	void setMap(const QString & map);
-	void setTheme(const QString & theme);
-	void setInitHealth(int health);
-	void setTurnTime(int time);
-	void setSuddenDeathTurns(int turns);
-	void setCaseProbability(int prob);
-	void setFortsMode(bool value);
-	void setTeamsDivide(bool value);
-	void setSolid(bool value);
-	void setBorder(bool value);
-	void setNetAmmo(const QString& name, const QString& ammo);
+	void setParam(const QString & param, const QStringList & value);
 
 signals:
+	void paramChanged(const QString & param, const QStringList & value);
+	
 	void seedChanged(const QString & seed);
 	void mapChanged(const QString & map);
 	void themeChanged(const QString & theme);
@@ -118,6 +109,8 @@
 
 	QString curNetAmmoName;
 	QString curNetAmmo;
+
+	void setNetAmmo(const QString& name, const QString& ammo);
 };
 
 #endif // GAMECONFIGWIDGET_H
--- a/QTfrontend/hwform.cpp	Sun Mar 08 16:51:16 2009 +0000
+++ b/QTfrontend/hwform.cpp	Sun Mar 08 18:43:15 2009 +0000
@@ -552,41 +552,17 @@
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamNotPlaying(const HWTeam&)), hwnet, SLOT(RemoveTeam(const HWTeam&)));
 
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(seedChanged(const QString &)), hwnet, SLOT(onSeedChanged(const QString &)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(mapChanged(const QString &)), hwnet, SLOT(onMapChanged(const QString &)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(themeChanged(const QString &)), hwnet, SLOT(onThemeChanged(const QString &)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(initHealthChanged(int)), hwnet, SLOT(onInitHealthChanged(int)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(turnTimeChanged(int)), hwnet, SLOT(onTurnTimeChanged(int)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(suddenDeathTurnsChanged(int)), hwnet, SLOT(onSuddenDeathTurnsChanged(int)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(caseProbabilityChanged(int)), hwnet, SLOT(onCaseProbabilityChanged(int)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(fortsModeChanged(bool)), hwnet, SLOT(onFortsModeChanged(bool)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(teamsDivideChanged(bool)), hwnet, SLOT(onTeamsDivideChanged(bool)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(solidChanged(bool)), hwnet, SLOT(onSolidChanged(bool)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(borderChanged(bool)), hwnet, SLOT(onBorderChanged(bool)));
-	connect(ui.pageNetGame->pGameCFG, SIGNAL(newWeaponScheme(const QString &, const QString &)),
-			hwnet, SLOT(onWeaponsNameChanged(const QString &, const QString &)));
-	connect(ui.pageNetGame->pGameCFG->pMapContainer, SIGNAL(newTemplateFilter(int)), hwnet, SLOT(onTemplateFilterChanged(int)));
+	//connect(ui.pageNetGame->pGameCFG->pMapContainer, SIGNAL(newTemplateFilter(int)), hwnet, SLOT(onTemplateFilterChanged(int)));
 
-	connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection);
-	connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &)));
-	connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &)));
-	connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &)));
-	connect(hwnet, SIGNAL(initHealthChanged(int)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(int)));
-	connect(hwnet, SIGNAL(turnTimeChanged(int)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(int)));
-	connect(hwnet, SIGNAL(suddenDeathTurnsChanged(int)), ui.pageNetGame->pGameCFG, SLOT(setSuddenDeathTurns(int)));
-	connect(hwnet, SIGNAL(caseProbabilityChanged(int)), ui.pageNetGame->pGameCFG, SLOT(setCaseProbability(int)));
-	connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool)));
-	connect(hwnet, SIGNAL(teamsDivideChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setTeamsDivide(bool)));
-	connect(hwnet, SIGNAL(solidChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setSolid(bool)));
-	connect(hwnet, SIGNAL(borderChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setBorder(bool)));
 	connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)),
 		ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&)));
 	connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)),
 		ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&)));
-	connect(hwnet, SIGNAL(ammoChanged(const QString&, const QString&)), ui.pageNetGame->pGameCFG, SLOT(setNetAmmo(const QString&, const QString&)));
-	connect(hwnet, SIGNAL(templateFilterChanged(int)), ui.pageNetGame->pGameCFG->pMapContainer, SLOT(setTemplateFilter(int)));
+	//connect(hwnet, SIGNAL(templateFilterChanged(int)), ui.pageNetGame->pGameCFG->pMapContainer, SLOT(setTemplateFilter(int)));
 
-	hwnet->Connect(hostName, port, nick);
+	
+	connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection);
+hwnet->Connect(hostName, port, nick);
 }
 
 void HWForm::NetConnect()
--- a/QTfrontend/newnetclient.cpp	Sun Mar 08 16:51:16 2009 +0000
+++ b/QTfrontend/newnetclient.cpp	Sun Mar 08 18:43:15 2009 +0000
@@ -462,60 +462,10 @@
 			qWarning("Net: Bad CFG message");
 			return;
 		}
-		if (lst[1] == "MAP") {
-			emit mapChanged(lst[2]);
-			return;
-		}
-		if (lst[1] == "SEED") {
-			emit seedChanged(lst[2]);
-			return;
-		}
-		if (lst[1] == "THEME") {
-			emit themeChanged(lst[2]);
-			return;
-		}
-		if (lst[1] == "HEALTH") {
-			emit initHealthChanged(lst[2].toUInt());
-			return;
-		}
-		if (lst[1] == "TURNTIME") {
-			emit turnTimeChanged(lst[2].toUInt());
-			return;
-		}
-		if (lst[1] == "SD_TURNS") {
-			emit suddenDeathTurnsChanged(lst[2].toUInt());
-			return;
-		}
-		if (lst[1] == "CASEFACTOR") {
-			emit caseProbabilityChanged(lst[2].toUInt());
-			return;
-		}
-		if (lst[1] == "FORTSMODE") {
-			emit fortsModeChanged(lst[2].toInt() != 0);
-			return;
-		}
-		if (lst[1] == "DIVIDETEAMS") {
-			emit teamsDivideChanged(lst[2].toInt() != 0);
-			return;
-		}
-		if (lst[1] == "SOLIDLAND") {
-			emit solidChanged(lst[2].toInt() != 0);
-			return;
-		}
-		if (lst[1] == "BORDER") {
-			emit borderChanged(lst[2].toInt() != 0);
-			return;
-		}
-		if (lst[1] == "AMMO") {
-			if(lst.size() < 4) return;
-			emit ammoChanged(lst[3], lst[2]);
-			return;
-		}
-		if (lst[1] == "TEMPLATE_FILTER") {
-			emit templateFilterChanged(lst[2].toUInt());
-			return;
-		}
-		qWarning() << "Net: Unknown 'CFG' message:" << lst;
+		QStringList tmp = lst;
+		tmp.removeFirst();
+		tmp.removeFirst();
+		emit paramChanged(lst[1], tmp);
 		return;
 	}
 
@@ -579,7 +529,7 @@
 
 void HWNewNet::ConfigAsked()
 {
-	QString map = m_pGameCFGWidget->getCurrentMap();
+/*	QString map = m_pGameCFGWidget->getCurrentMap();
 	if (map.size())
 		onMapChanged(map);
 
@@ -599,7 +549,7 @@
 			m_pGameCFGWidget->WeaponsName->currentIndex()
 			).toString();
 	onWeaponsNameChanged(name, ammo);
-	onTemplateFilterChanged(m_pGameCFGWidget->pMapContainer->getTemplateFilter());
+	onTemplateFilterChanged(m_pGameCFGWidget->pMapContainer->getTemplateFilter());*/
 }
 
 void HWNewNet::RunGame()
@@ -625,69 +575,15 @@
 			.arg(team.teamColor.name()));
 }
 
-void HWNewNet::onSeedChanged(const QString & seed)
-{
-	if (isChief) RawSendNet(QString("CFG%1SEED%1%2").arg(delimeter).arg(seed));
-}
-
-void HWNewNet::onMapChanged(const QString & map)
-{
-	if (isChief) RawSendNet(QString("CFG%1MAP%1%2").arg(delimeter).arg(map));
-}
-
-void HWNewNet::onThemeChanged(const QString & theme)
-{
-	if (isChief) RawSendNet(QString("CFG%1THEME%1%2").arg(delimeter).arg(theme));
-}
-
-void HWNewNet::onInitHealthChanged(int health)
-{
-	if (isChief) RawSendNet(QString("CFG%1HEALTH%1%2").arg(delimeter).arg(health));
-}
-
-void HWNewNet::onTurnTimeChanged(int time)
-{
-	if (isChief) RawSendNet(QString("CFG%1TURNTIME%1%2").arg(delimeter).arg(time));
-}
-
-void HWNewNet::onSuddenDeathTurnsChanged(int turns)
-{
-	if (isChief) RawSendNet(QString("CFG%1SD_TURNS%1%2").arg(delimeter).arg(turns));
-}
-
-void HWNewNet::onCaseProbabilityChanged(int prob)
+void HWNewNet::onParamChanged(const QString & param, const QStringList & value)
 {
-	if (isChief) RawSendNet(QString("CFG%1CASEFACTOR%1%2").arg(delimeter).arg(prob));
-}
-
-void HWNewNet::onFortsModeChanged(bool value)
-{
-	if (isChief) RawSendNet(QString("CFG%1FORTSMODE%1%2").arg(delimeter).arg(value));
-}
-
-void HWNewNet::onTeamsDivideChanged(bool value)
-{
-	if (isChief) RawSendNet(QString("CFG%1DIVIDETEAMS%1%2").arg(delimeter).arg(value));
-}
-
-void HWNewNet::onSolidChanged(bool value)
-{
-	if (isChief) RawSendNet(QString("CFG%1SOLIDLAND%1%2").arg(delimeter).arg(value));
-}
-
-void HWNewNet::onBorderChanged(bool value)
-{
-	if (isChief) RawSendNet(QString("CFG%1BORDER%1%2").arg(delimeter).arg(value));
-}
-
-void HWNewNet::onWeaponsNameChanged(const QString& name, const QString& ammo)
-{
-	if (isChief) RawSendNet(QString("CFG%1AMMO%1%2%1%3").arg(delimeter).arg(ammo).arg(name));
-}
-
-void HWNewNet::onTemplateFilterChanged(int filter)
-{
-	if (isChief) RawSendNet(QString("CFG%1TEMPLATE_FILTER%1%2").arg(delimeter).arg(filter));
+	if (isChief)
+		RawSendNet(
+				QString("CFG%1%2%1%3")
+					.arg(delimeter)
+					.arg(param)
+					.arg(value.join(QString(delimeter)))
+				);
 }
 
 void HWNewNet::chatLineToNet(const QString& str)
--- a/QTfrontend/newnetclient.h	Sun Mar 08 16:51:16 2009 +0000
+++ b/QTfrontend/newnetclient.h	Sun Mar 08 18:43:15 2009 +0000
@@ -102,6 +102,8 @@
   void adminAccess(bool);
   void roomMaster(bool);
 
+  void paramChanged(const QString & param, const QStringList & value);
+  
   void AddNetTeam(const HWTeam&);
   void seedChanged(const QString & seed);
   void mapChanged(const QString & map);
@@ -137,21 +139,11 @@
   void SendNet(const QByteArray & buf);
   void AddTeam(const HWTeam & team);
   void RemoveTeam(const HWTeam& team);
-  void onSeedChanged(const QString & seed);
-  void onMapChanged(const QString & map);
-  void onThemeChanged(const QString & theme);
-  void onInitHealthChanged(int health);
-  void onTurnTimeChanged(int time);
-  void onSuddenDeathTurnsChanged(int turns);
-  void onCaseProbabilityChanged(int prob);
-  void onFortsModeChanged(bool value);
-  void onTeamsDivideChanged(bool value);
-  void onSolidChanged(bool value);
-  void onBorderChanged(bool value);
   void onHedgehogsNumChanged(const HWTeam& team);
   void onTeamColorChanged(const HWTeam& team);
-  void onWeaponsNameChanged(const QString& name, const QString& ammo);
-  void onTemplateFilterChanged(int filter);
+  void onParamChanged(const QString & param, const QStringList & value);
+
+
   void JoinRoom(const QString & room);
   void CreateRoom(const QString & room);
   void askRoomsList();