- Fix a bug in map widget
authorunc0rr
Sun, 08 Mar 2009 20:22:52 +0000
changeset 1874 1b145e099b75
parent 1873 815a3ff1fe4b
child 1875 189370d394db
- Fix a bug in map widget - New way of passing game parameters. Less code, and code is in one class. (mostly works, but not finished yet)
QTfrontend/gamecfgwidget.cpp
QTfrontend/gamecfgwidget.h
QTfrontend/hwform.cpp
QTfrontend/mapContainer.cpp
QTfrontend/newnetclient.h
--- a/QTfrontend/gamecfgwidget.cpp	Sun Mar 08 18:43:15 2009 +0000
+++ b/QTfrontend/gamecfgwidget.cpp	Sun Mar 08 20:22:52 2009 +0000
@@ -95,20 +95,20 @@
 	
 	WeaponsName = new QComboBox(GBoxOptions);
 	GBoxOptionsLayout->addWidget(WeaponsName, 8, 1);
-
-	connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SIGNAL(initHealthChanged(int)));
-	connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SIGNAL(turnTimeChanged(int)));
-	connect(SB_SuddenDeath, SIGNAL(valueChanged(int)), this, SIGNAL(suddenDeathTurnsChanged(int)));
-	connect(SB_CaseProb, SIGNAL(valueChanged(int)), this, SIGNAL(caseProbabilityChanged(int)));
-	connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SIGNAL(fortsModeChanged(bool)));
-	connect(CB_teamsDivide, SIGNAL(toggled(bool)), this, SIGNAL(teamsDivideChanged(bool)));
-	connect(CB_solid, SIGNAL(toggled(bool)), this, SIGNAL(solidChanged(bool)));
-	connect(CB_border, SIGNAL(toggled(bool)), this, SIGNAL(borderChanged(bool)));
+	
+	connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SLOT(initHealthChanged(int)));
+	connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SLOT(turnTimeChanged(int)));
+	connect(SB_SuddenDeath, SIGNAL(valueChanged(int)), this, SLOT(suddenDeathTurnsChanged(int)));
+	connect(SB_CaseProb, SIGNAL(valueChanged(int)), this, SLOT(caseProbabilityChanged(int)));
+	connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SLOT(fortsModeChanged(bool)));
+	connect(CB_teamsDivide, SIGNAL(toggled(bool)), this, SLOT(teamsDivideChanged(bool)));
+	connect(CB_solid, SIGNAL(toggled(bool)), this, SLOT(solidChanged(bool)));
+	connect(CB_border, SIGNAL(toggled(bool)), this, SLOT(borderChanged(bool)));
 	connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
 
-	connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SIGNAL(seedChanged(const QString &)));
-	connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SIGNAL(mapChanged(const QString &)));
-	connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SIGNAL(themeChanged(const QString &)));
+	connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
+	connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &)));
+	connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &)));
 }
 
 quint32 GameCFGWidget::getGameFlags() const
@@ -194,12 +194,6 @@
 	}
 }
 
-void GameCFGWidget::ammoChanged(int index)
-{
-	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)
@@ -264,3 +258,67 @@
 	}
 }
 
+
+void GameCFGWidget::ammoChanged(int index)
+{
+	if (index >= 0)
+		emit paramChanged(
+			"AMMO",
+			QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString()
+		);
+}
+
+void GameCFGWidget::borderChanged(bool value)
+{
+	emit paramChanged("BORDER", QStringList(value ? "1" : "0"));
+}
+
+void GameCFGWidget::caseProbabilityChanged(int value)
+{
+	emit paramChanged("CASEFACTOR", QStringList(QString::number(value)));
+}
+
+void GameCFGWidget::fortsModeChanged(bool value)
+{
+	emit paramChanged("FORTSMODE", QStringList(value ? "1" : "0"));
+}
+
+void GameCFGWidget::initHealthChanged(int value)
+{
+	emit paramChanged("HEALTH", QStringList(QString::number(value)));
+}
+
+void GameCFGWidget::mapChanged(const QString & value)
+{
+	emit paramChanged("MAP", QStringList(value));
+}
+
+void GameCFGWidget::seedChanged(const QString & value)
+{
+	emit paramChanged("SEED", QStringList(value));
+}
+
+void GameCFGWidget::solidChanged(bool value)
+{
+	emit paramChanged("SOLIDLAND", QStringList(value ? "1" : "0"));
+}
+
+void GameCFGWidget::suddenDeathTurnsChanged(int value)
+{
+	emit paramChanged("SD_TURNS", QStringList(QString::number(value)));
+}
+
+void GameCFGWidget::teamsDivideChanged(bool value)
+{
+	emit paramChanged("DIVIDETEAMS", QStringList(value ? "1" : "0"));
+}
+
+void GameCFGWidget::themeChanged(const QString & value)
+{
+	emit paramChanged("THEME", QStringList(value));
+}
+
+void GameCFGWidget::turnTimeChanged(int value)
+{
+	emit paramChanged("TURNTIME", QStringList(QString::number(value)));
+}
--- a/QTfrontend/gamecfgwidget.h	Sun Mar 08 18:43:15 2009 +0000
+++ b/QTfrontend/gamecfgwidget.h	Sun Mar 08 20:22:52 2009 +0000
@@ -75,22 +75,20 @@
 
 signals:
 	void paramChanged(const QString & param, const QStringList & value);
-	
-	void seedChanged(const QString & seed);
-	void mapChanged(const QString & map);
-	void themeChanged(const QString & theme);
-	void initHealthChanged(int health);
-	void turnTimeChanged(int time);
-	void suddenDeathTurnsChanged(int turns);
-	void caseProbabilityChanged(int prob);
-	void fortsModeChanged(bool value);
-	void teamsDivideChanged(bool value);
-	void solidChanged(bool value);
-	void borderChanged(bool value);
-	void newWeaponScheme(const QString & name, const QString & ammo);
 
 private slots:
 	void ammoChanged(int index);
+	void borderChanged(bool);
+	void caseProbabilityChanged(int);
+	void fortsModeChanged(bool);
+	void initHealthChanged(int);
+	void mapChanged(const QString &);
+	void seedChanged(const QString &);
+	void solidChanged(bool);
+	void suddenDeathTurnsChanged(int);
+	void teamsDivideChanged(bool);
+	void themeChanged(const QString &);
+	void turnTimeChanged(int);
 
 private:
 	QCheckBox * CB_mode_Forts;
--- a/QTfrontend/hwform.cpp	Sun Mar 08 18:43:15 2009 +0000
+++ b/QTfrontend/hwform.cpp	Sun Mar 08 20:22:52 2009 +0000
@@ -480,6 +480,7 @@
 	connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)));
 	connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom()));
 
+// rooms list page stuff
 	connect(hwnet, SIGNAL(roomsList(const QStringList&)),
 		ui.pageRoomsList, SLOT(setRoomsList(const QStringList&)));
 	connect(hwnet, SIGNAL(adminAccess(bool)),
@@ -501,6 +502,7 @@
 	connect(ui.pageRoomsList, SIGNAL(askForRoomList()),
 		hwnet, SLOT(askRoomsList()));
 
+// net page stuff
 	connect(hwnet, SIGNAL(chatStringFromNet(const QString&)),
 		ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)));
 	connect(hwnet, SIGNAL(setReadyStatus(const QString &, bool)),
@@ -515,6 +517,7 @@
 	connect(hwnet, SIGNAL(setMyReadyStatus(bool)),
 		ui.pageNetGame, SLOT(setReadyStatus(bool)));
 
+// chat widget actions
 	connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)),
 		hwnet, SLOT(kickPlayer(const QString&)));
 	connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)),
@@ -528,6 +531,7 @@
 	connect(ui.pageRoomsList->chatWidget, SIGNAL(info(const QString&)),
 		hwnet, SLOT(infoPlayer(const QString&)));
 
+// chatting
 	connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)),
 		hwnet, SLOT(chatLineToLobby(const QString&)));
 	connect(hwnet, SIGNAL(chatStringLobby(const QString&)),
@@ -535,6 +539,7 @@
 	connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)),
 		ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)));
 
+// nick list stuff
 	connect(hwnet, SIGNAL(nickAdded(const QString&)),
 		ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&)));
 	connect(hwnet, SIGNAL(nickRemoved(const QString&)),
@@ -544,6 +549,7 @@
 	connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)),
 		ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)));
 
+// teams selecting stuff
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)),
 		hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&)));
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)),
@@ -551,18 +557,23 @@
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
 	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->pMapContainer, SIGNAL(newTemplateFilter(int)), hwnet, SLOT(onTemplateFilterChanged(int)));
-
 	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(ui.pageNetGame->pGameCFG->pMapContainer, SIGNAL(newTemplateFilter(int)), hwnet, SLOT(onTemplateFilterChanged(int)));
+
 	//connect(hwnet, SIGNAL(templateFilterChanged(int)), ui.pageNetGame->pGameCFG->pMapContainer, SLOT(setTemplateFilter(int)));
 
-	
+// config stuff
+	connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
+
+
 	connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection);
-hwnet->Connect(hostName, port, nick);
+	
+	hwnet->Connect(hostName, port, nick);
 }
 
 void HWForm::NetConnect()
--- a/QTfrontend/mapContainer.cpp	Sun Mar 08 18:43:15 2009 +0000
+++ b/QTfrontend/mapContainer.cpp	Sun Mar 08 20:22:52 2009 +0000
@@ -183,7 +183,7 @@
         lblFilter->show();
         CB_TemplateFilter->show();
 		emit mapChanged("+rnd+");
-		emit themeChanged(chooseMap->itemData(0).toString());
+		emit themeChanged(chooseMap->itemData(0).toList()[0].toString());
 	} else
 	{
 		loadMap(index);
@@ -238,9 +238,9 @@
 void HWMapContainer::themeSelected(int currentRow)
 {
 	QString theme = Themes->at(currentRow);
-    QList<QVariant> mapInfo;
-    mapInfo.push_back(theme);
-    mapInfo.push_back(18);
+	QList<QVariant> mapInfo;
+	mapInfo.push_back(theme);
+	mapInfo.push_back(18);
 	chooseMap->setItemData(0, mapInfo);
 	gbThemes->setIcon(QIcon(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(theme)));
 	emit themeChanged(theme);
@@ -248,13 +248,13 @@
 
 QString HWMapContainer::getCurrentSeed() const
 {
-  return m_seed;
+	return m_seed;
 }
 
 QString HWMapContainer::getCurrentMap() const
 {
-  if(!chooseMap->currentIndex()) return QString();
-  return chooseMap->currentText();
+	if(!chooseMap->currentIndex()) return QString();
+	return chooseMap->currentText();
 }
 
 QString HWMapContainer::getCurrentTheme() const
@@ -312,9 +312,9 @@
 
 void HWMapContainer::setRandomSeed()
 {
-  m_seed = QUuid::createUuid().toString();
-  emit seedChanged(m_seed);
-  changeImage();
+	m_seed = QUuid::createUuid().toString();
+	emit seedChanged(m_seed);
+	changeImage();
 }
 
 void HWMapContainer::setRandomTheme()
@@ -331,7 +331,7 @@
 
 void HWMapContainer::templateFilterChanged(int filter)
 {
-    changeImage();
+	changeImage();
 	emit newTemplateFilter(filter);
 }
 
--- a/QTfrontend/newnetclient.h	Sun Mar 08 18:43:15 2009 +0000
+++ b/QTfrontend/newnetclient.h	Sun Mar 08 20:22:52 2009 +0000
@@ -105,25 +105,12 @@
   void paramChanged(const QString & param, const QStringList & value);
   
   void AddNetTeam(const HWTeam&);
-  void seedChanged(const QString & seed);
-  void mapChanged(const QString & map);
-  void themeChanged(const QString & theme);
-  void initHealthChanged(int health);
-  void turnTimeChanged(int time);
-  void suddenDeathTurnsChanged(int turns);
-  void caseProbabilityChanged(int prob);
-  void fortsModeChanged(bool value);
-  void teamsDivideChanged(bool value);
-  void solidChanged(bool value);
-  void borderChanged(bool value);
   void hhnumChanged(const HWTeam&);
   void teamColorChanged(const HWTeam&);
   void chatStringLobby(const QString&);
   void chatStringFromNet(const QString&);
   void chatStringFromMe(const QString&);
   void chatStringFromMeLobby(const QString&);
-  void ammoChanged(const QString& name, const QString& ammo);
-  void templateFilterChanged(int filter);
 
   void roomsList(const QStringList&);
   void serverMessage(const QString &);