pre-alpha network weapons selection
authordisplacer
Fri, 11 Jan 2008 21:45:24 +0000
changeset 697 44f167938201
parent 696 d6f32ed6edc8
child 698 43f3ef079f53
pre-alpha network weapons selection
QTfrontend/gamecfgwidget.cpp
QTfrontend/gamecfgwidget.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
--- a/QTfrontend/gamecfgwidget.cpp	Wed Jan 09 21:22:22 2008 +0000
+++ b/QTfrontend/gamecfgwidget.cpp	Fri Jan 11 21:45:24 2008 +0000
@@ -55,6 +55,7 @@
 	L_InitHealth = new QLabel(QLabel::tr("Initial health"), GBoxOptions);
 	GBoxOptionsLayout->addWidget(L_TurnTime, 1, 0);
 	GBoxOptionsLayout->addWidget(L_InitHealth, 2, 0);
+	GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 3, 0);
 
 	SB_TurnTime = new QSpinBox(GBoxOptions);
 	SB_TurnTime->setRange(15, 90);
@@ -66,19 +67,15 @@
 	SB_InitHealth->setSingleStep(25);
 	GBoxOptionsLayout->addWidget(SB_TurnTime, 1, 1);
 	GBoxOptionsLayout->addWidget(SB_InitHealth, 2, 1);
-
-	QGroupBox *GBoxWeapons = new QGroupBox(this);
-	GBoxWeapons->setTitle(QGroupBox::tr("Weapons"));
-	QHBoxLayout* lt=new QHBoxLayout(GBoxWeapons);
-	WeaponsName = new QComboBox(GBoxWeapons);
-	lt->addWidget(WeaponsName);
-	mainLayout.addWidget(GBoxWeapons);
+	WeaponsName = new QComboBox(GBoxOptions);
+	GBoxOptionsLayout->addWidget(WeaponsName, 3, 1);
 
 	mainLayout.addWidget(new QWidget(this), 100);
 
 	connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SLOT(onInitHealthChanged(int)));
 	connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SLOT(onTurnTimeChanged(int)));
 	connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SLOT(onFortsModeChanged(bool)));
+	connect(WeaponsName, SIGNAL(activated(const QString&)), this, SIGNAL(newWeaponsName(const QString&)));
 
 	connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(onSeedChanged(const QString &)));
 	connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(onThemeChanged(const QString &)));
@@ -118,6 +115,11 @@
 	return SB_TurnTime->value();
 }
 
+QString GameCFGWidget::getNetAmmo() const
+{
+  return curNetAmmo;
+}
+
 QStringList GameCFGWidget::getFullConfig() const
 {
 	QStringList sl;
@@ -190,3 +192,8 @@
 {
 	emit themeChanged(theme);
 }
+
+void GameCFGWidget::setNetAmmo(const QString& ammo)
+{
+  curNetAmmo=ammo;
+}
--- a/QTfrontend/gamecfgwidget.h	Wed Jan 09 21:22:22 2008 +0000
+++ b/QTfrontend/gamecfgwidget.h	Fri Jan 11 21:45:24 2008 +0000
@@ -43,6 +43,8 @@
 	quint32 getTurnTime() const;
 	QStringList getFullConfig() const;
 
+	QString getNetAmmo() const; // FIXME: hack - this class should contain all ammo states itself
+
 	QComboBox* WeaponsName;
 
 public slots:
@@ -52,6 +54,7 @@
 	void setInitHealth(quint32 health);
 	void setTurnTime(quint32 time);
 	void setFortsMode(bool value);
+	void setNetAmmo(const QString&);
 
 signals:
 	void seedChanged(const QString & seed);
@@ -60,6 +63,7 @@
 	void initHealthChanged(quint32 health);
 	void turnTimeChanged(quint32 time);
 	void fortsModeChanged(bool value);
+	void newWeaponsName(const QString& weapon);
 
 private:
 	QCheckBox * CB_mode_Forts;
@@ -70,6 +74,8 @@
 	QLabel * L_TurnTime;
 	QLabel * L_InitHealth;
 
+	QString curNetAmmo;
+
 private slots:
 	void onSeedChanged(const QString & seed);
 	void onMapChanged(const QString & map);
--- a/QTfrontend/hwform.cpp	Wed Jan 09 21:22:22 2008 +0000
+++ b/QTfrontend/hwform.cpp	Fri Jan 11 21:45:24 2008 +0000
@@ -89,6 +89,7 @@
 	connect(ui.pageOptions->WeaponEdit,	SIGNAL(clicked()),	this, SLOT(GoToSelectWeapon()));
 	connect(ui.pageOptions->WeaponsButt,	SIGNAL(clicked()),	this, SLOT(GoToSelectNewWeapon()));
 	connect(ui.pageSelectWeapon->pWeapons,       SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons()));
+	connect(ui.pageNetGame->pGameCFG,       SIGNAL(newWeaponsName(const QString&)), this, SLOT(NetWeaponNameChanged(const QString&)));
 
 	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
 	connect(ui.pageNet->BtnSpecifyServer,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
@@ -134,6 +135,12 @@
   ui.pageNetGame->pGameCFG->WeaponsName->addItems(ui.pageSelectWeapon->pWeapons->getWeaponNames());
 }
 
+void HWForm::NetWeaponNameChanged(const QString& name)
+{
+  QString ammo=ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageNetGame->pGameCFG->WeaponsName->currentText());
+  hwnet->onWeaponsNameChanged(ammo);
+}
+
 void HWForm::UpdateTeamsLists(const QStringList* editable_teams)
 {
 	QStringList teamslist;
@@ -415,6 +422,7 @@
 		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&)), ui.pageNetGame->pGameCFG, SLOT(setNetAmmo(const QString&)));
 
 	hwnet->Connect(hostName, port, nick);
 }
@@ -627,7 +635,12 @@
 
 void HWForm::CreateNetGame()
 {
-	QString ammo=ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageNetGame->pGameCFG->WeaponsName->currentText());
+	QString ammo;
+	if (pnetserver) {
+	  ammo=ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageNetGame->pGameCFG->WeaponsName->currentText());
+	} else {
+	  ammo=ui.pageNetGame->pGameCFG->getNetAmmo();
+	}
 	CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
 
 	connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &)));
--- a/QTfrontend/hwform.h	Wed Jan 09 21:22:22 2008 +0000
+++ b/QTfrontend/hwform.h	Fri Jan 11 21:45:24 2008 +0000
@@ -83,6 +83,7 @@
 	void GetRecord(bool isDemo, const QByteArray & record);
 	void CreateNetGame();
 	void UpdateWeapons();
+	void NetWeaponNameChanged(const QString& name);
 
 private:
 	void _NetConnect(const QString & hostName, quint16 port, const QString & nick);
--- a/QTfrontend/newnetclient.cpp	Wed Jan 09 21:22:22 2008 +0000
+++ b/QTfrontend/newnetclient.cpp	Fri Jan 11 21:45:24 2008 +0000
@@ -18,6 +18,7 @@
 
 #include <QMessageBox>
 
+#include "hwconsts.h"
 #include "newnetclient.h"
 #include "proto.h"
 #include "gameuiconfig.h"
@@ -282,6 +283,10 @@
 	  emit fortsModeChanged(lst[2].toInt() != 0);
 	  return;
   	}
+	if (lst[1] == "AMMO") {
+	  emit ammoChanged(lst[2]);
+	  return;
+	}
 	QStringList hhTmpList=lst[1].split('+');
   	if (hhTmpList[0] == "TEAM_COLOR") {
 	  HWTeam tmptm(hhTmpList[1], hhTmpList[2].toUInt());
@@ -334,6 +339,8 @@
   onInitHealthChanged(m_pGameCFGWidget->getInitHealth());
   onTurnTimeChanged(m_pGameCFGWidget->getTurnTime());
   onFortsModeChanged(m_pGameCFGWidget->getGameFlags() & 0x1);
+  // always initialize with default ammo (also avoiding complicated cross-class dependencies)
+  onWeaponsNameChanged(cDefaultAmmoStore->mid(10)); 
 }
 
 void HWNewNet::RunGame()
@@ -385,6 +392,11 @@
   RawSendNet(QString("CONFIG_PARAM%1FORTSMODE%1%2").arg(delimeter).arg(value));
 }
 
+void HWNewNet::onWeaponsNameChanged(const QString& ammo)
+{
+  RawSendNet(QString("CONFIG_PARAM%1AMMO%1%2").arg(delimeter).arg(ammo));
+}
+
 void HWNewNet::chatLineToNet(const QString& str)
 {
   if(str!="") {
--- a/QTfrontend/newnetclient.h	Wed Jan 09 21:22:22 2008 +0000
+++ b/QTfrontend/newnetclient.h	Fri Jan 11 21:45:24 2008 +0000
@@ -102,6 +102,7 @@
   void hhnumChanged(const HWTeam&);
   void teamColorChanged(const HWTeam&);
   void chatStringFromNet(const QStringList&);
+  void ammoChanged(const QString&);
 
  public slots:
   void chatLineToNet(const QString& str);
@@ -116,6 +117,7 @@
   void onFortsModeChanged(bool value);
   void onHedgehogsNumChanged(const HWTeam& team);
   void onTeamColorChanged(const HWTeam& team);
+  void onWeaponsNameChanged(const QString& ammo);
 
  private slots:
   void ClientRead();