Fully separate statistics code from main form code
authorunc0rr
Fri, 09 Jan 2009 11:27:52 +0000
changeset 1622 8e0d62727f01
parent 1621 d1ded2532d3f
child 1623 d590e6da04da
Fully separate statistics code from main form code
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/statsPage.cpp
QTfrontend/statsPage.h
--- a/QTfrontend/hwform.cpp	Fri Jan 09 11:22:46 2009 +0000
+++ b/QTfrontend/hwform.cpp	Fri Jan 09 11:27:52 2009 +0000
@@ -643,7 +643,7 @@
 		case gsStarted: {
 			Music(false);
 			GoToPage(ID_PAGE_INGAME);
-			ui.pageGameStats->labelGameStats->setText("");
+			ui.pageGameStats->clear();
 			if (pRegisterServer)
 			{
 				pRegisterServer->unregister();
@@ -669,46 +669,11 @@
 	}
 }
 
-void HWForm::AddStatText(const QString & msg)
-{
-	ui.pageGameStats->labelGameStats->setText(
-		ui.pageGameStats->labelGameStats->text() + msg);
-}
-
-void HWForm::GameStats(char type, const QString & info)
-{
-	switch(type) {
-		case 'r' : {
-			AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info));
-			break;
-		}
-		case 'D' : {
-			int i = info.indexOf(' ');
-			QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>")
-					.arg(info.mid(i + 1), info.left(i));
-			AddStatText(message);
-			break;
-		}
-		case 'k' : {
-			int i = info.indexOf(' ');
-			QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> kills.</p>")
-					.arg(info.mid(i + 1), info.left(i));
-			AddStatText(message);
-			break;
-		}
-		case 'K' : {
-			QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info);
-			AddStatText(message);
-			break;
-		}
-	}
-}
-
 void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo)
 {
 	game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
 	connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
-	connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &)));
+	connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
 	connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
 	connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &)));
 }
--- a/QTfrontend/hwform.h	Fri Jan 09 11:22:46 2009 +0000
+++ b/QTfrontend/hwform.h	Fri Jan 09 11:27:52 2009 +0000
@@ -78,7 +78,6 @@
 	void AddNetTeam(const HWTeam& team);
 	void StartMPGame();
 	void GameStateChanged(GameState gameState);
-	void GameStats(char type, const QString & info);
 	void ForcedDisconnect();
 	void ShowErrorMessage(const QString &);
 	void GetRecord(bool isDemo, const QByteArray & record);
@@ -124,7 +123,6 @@
 	HWNetRegisterServer* pRegisterServer;
 	QTime eggTimer;
 	SDLInteraction sdli;
-	void AddStatText(const QString & msg);
 	void OnPageShown(quint8 id, quint8 lastid=0);
 };
 
--- a/QTfrontend/statsPage.cpp	Fri Jan 09 11:22:46 2009 +0000
+++ b/QTfrontend/statsPage.cpp	Fri Jan 09 11:27:52 2009 +0000
@@ -35,3 +35,42 @@
 	labelGameStats->setTextFormat(Qt::RichText);
 	pageLayout->addWidget(labelGameStats, 0, 0, 1, 3);
 }
+
+void PageGameStats::AddStatText(const QString & msg)
+{
+	labelGameStats->setText(labelGameStats->text() + msg);
+}
+
+void PageGameStats::clear()
+{
+	labelGameStats->setText("");
+}
+
+void PageGameStats::GameStats(char type, const QString & info)
+{
+	switch(type) {
+		case 'r' : {
+			AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info));
+			break;
+		}
+		case 'D' : {
+			int i = info.indexOf(' ');
+			QString message = tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>")
+					.arg(info.mid(i + 1), info.left(i));
+			AddStatText(message);
+			break;
+		}
+		case 'k' : {
+			int i = info.indexOf(' ');
+			QString message = tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> kills.</p>")
+					.arg(info.mid(i + 1), info.left(i));
+			AddStatText(message);
+			break;
+		}
+		case 'K' : {
+			QString message = tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info);
+			AddStatText(message);
+			break;
+		}
+	}
+}
--- a/QTfrontend/statsPage.h	Fri Jan 09 11:22:46 2009 +0000
+++ b/QTfrontend/statsPage.h	Fri Jan 09 11:27:52 2009 +0000
@@ -30,6 +30,13 @@
 
 	QPushButton *BtnBack;
 	QLabel *labelGameStats;
+
+public slots:
+	void GameStats(char type, const QString & info);
+	void clear();
+	
+private:
+	void AddStatText(const QString & msg);
 };
 
 #endif // STATSPAGE_H