Initial health graphic implementation
authorunc0rr
Fri, 09 Jan 2009 14:47:54 +0000
changeset 1625 37aae47943ce
parent 1624 3cbf01d31e5c
child 1626 58fd5bc49a04
Initial health graphic implementation
QTfrontend/hwform.cpp
QTfrontend/statsPage.cpp
QTfrontend/statsPage.h
hedgewars/uConsts.pas
hedgewars/uMisc.pas
hedgewars/uStats.pas
--- a/QTfrontend/hwform.cpp	Fri Jan 09 11:55:05 2009 +0000
+++ b/QTfrontend/hwform.cpp	Fri Jan 09 14:47:54 2009 +0000
@@ -298,6 +298,10 @@
 		} else if(lastid != ID_PAGE_GAMESTATS && lastid != ID_PAGE_INGAME) {
 		  curTeamSelWidget->resetPlayingTeams(teamsList);
 		}
+	} else
+	if (id == ID_PAGE_GAMESTATS)
+	{
+		ui.pageGameStats->renderStats();
 	}
 }
 
--- a/QTfrontend/statsPage.cpp	Fri Jan 09 11:55:05 2009 +0000
+++ b/QTfrontend/statsPage.cpp	Fri Jan 09 14:47:54 2009 +0000
@@ -18,6 +18,8 @@
 
 #include <QLabel>
 #include <QGridLayout>
+#include <QGraphicsScene>
+#include <QGraphicsView>
 
 #include "statsPage.h"
 
@@ -29,11 +31,15 @@
 	pageLayout->setColumnStretch(1, 1);
 	pageLayout->setColumnStretch(2, 1);
 
-	BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
+	BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true);
 
 	labelGameStats = new QLabel(this);
 	labelGameStats->setTextFormat(Qt::RichText);
 	pageLayout->addWidget(labelGameStats, 0, 0, 1, 3);
+
+	graphic = new QGraphicsView(this);
+	graphic->scale(1.0, -1.0);
+	pageLayout->addWidget(graphic, 1, 0, 1, 3);
 }
 
 void PageGameStats::AddStatText(const QString & msg)
@@ -44,6 +50,33 @@
 void PageGameStats::clear()
 {
 	labelGameStats->setText("");
+	healthPoints.clear();
+}
+
+void PageGameStats::renderStats()
+{
+	QGraphicsScene * scene = new QGraphicsScene();
+
+	QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
+	while (i != healthPoints.constEnd())
+	{
+		quint32 c = i.key();
+		QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
+		QVector<quint32> hps = i.value();
+
+		QPainterPath path;
+		if (hps.size())
+			path.moveTo(0, hps[0]);
+		
+		for(int t = 1; t < hps.size(); ++t)
+			path.lineTo(t, hps[t]);
+
+		scene->addPath(path, QPen(c));
+		++i;
+	}
+
+	graphic->setScene(scene);
+	graphic->fitInView(graphic->sceneRect());
 }
 
 void PageGameStats::GameStats(char type, const QString & info)
@@ -72,5 +105,12 @@
 			AddStatText(message);
 			break;
 		}
+		case 'H' : {
+			int i = info.indexOf(' ');
+			quint32 clan = info.left(i).toInt();
+			quint32 hp = info.mid(i + 1).toUInt();
+			healthPoints[clan].append(hp);
+			break;
+		}
 	}
 }
--- a/QTfrontend/statsPage.h	Fri Jan 09 11:55:05 2009 +0000
+++ b/QTfrontend/statsPage.h	Fri Jan 09 14:47:54 2009 +0000
@@ -19,8 +19,12 @@
 #ifndef STATSPAGE_H
 #define STATSPAGE_H
 
+#include <QVector>
+#include <QMap>
 #include "pages.h"
 
+class QGraphicsView;
+
 class PageGameStats : public AbstractPage
 {
 	Q_OBJECT
@@ -30,13 +34,17 @@
 
 	QPushButton *BtnBack;
 	QLabel *labelGameStats;
+	QGraphicsView * graphic;
 
 public slots:
 	void GameStats(char type, const QString & info);
 	void clear();
+	void renderStats();
 	
 private:
 	void AddStatText(const QString & msg);
+
+	QMap<quint32, QVector<quint32> > healthPoints;
 };
 
 #endif // STATSPAGE_H
--- a/hedgewars/uConsts.pas	Fri Jan 09 11:55:05 2009 +0000
+++ b/hedgewars/uConsts.pas	Fri Jan 09 14:47:54 2009 +0000
@@ -87,7 +87,8 @@
 
 	TCapGroup = (capgrpGameState, capgrpAmmoinfo, capgrpNetSay, capgrpVolume);
 
-	TStatInfoType = (siGameResult, siMaxStepDamage, siMaxStepKills, siKilledHHs);
+	TStatInfoType = (siGameResult, siMaxStepDamage, siMaxStepKills, siKilledHHs,
+			siClanHealth);
 
 	TWave = (waveRollup, waveSad,waveWave, waveHurrah, waveLemonade);
 
--- a/hedgewars/uMisc.pas	Fri Jan 09 11:55:05 2009 +0000
+++ b/hedgewars/uMisc.pas	Fri Jan 09 14:47:54 2009 +0000
@@ -244,7 +244,7 @@
 end;
 
 procedure SendStat(sit: TStatInfoType; s: shortstring);
-const stc: array [TStatInfoType] of char = 'rDkK';
+const stc: array [TStatInfoType] of char = 'rDkKH';
 begin
 SendIPC('i' + stc[sit] + s)
 end;
--- a/hedgewars/uStats.pas	Fri Jan 09 11:55:05 2009 +0000
+++ b/hedgewars/uStats.pas	Fri Jan 09 14:47:54 2009 +0000
@@ -89,45 +89,46 @@
 TryDo(not bBetweenTurns, 'Engine bug: TurnReaction between turns', true);
 
 inc(FinishedTurnsTotal);
-if FinishedTurnsTotal = 0 then exit;
+if FinishedTurnsTotal <> 0 then
+	begin
+	inc(CurrentHedgehog^.stats.FinishedTurns);
 
-inc(CurrentHedgehog^.stats.FinishedTurns);
+	if (DamageGiven = DamageTotal) and (DamageTotal > 0) then
+		PlaySound(sndFirstBlood, false)
 
-if (DamageGiven = DamageTotal) and (DamageTotal > 0) then
-	PlaySound(sndFirstBlood, false)
+	else if CurrentHedgehog^.stats.StepDamageRecv > 0 then
+		PlaySound(sndStupid, false)
 
-else if CurrentHedgehog^.stats.StepDamageRecv > 0 then
-	PlaySound(sndStupid, false)
+	else if DamageClan <> 0 then
+		if DamageTotal > DamageClan then
+			if random(2) = 0 then
+				PlaySound(sndNutter, false)
+			else
+				PlaySound(sndWatchIt, false)
+		else
+			if random(2) = 0 then
+				PlaySound(sndSameTeam, false)
+			else
+				PlaySound(sndTraitor, false)
 
-else if DamageClan <> 0 then
-	if DamageTotal > DamageClan then
-		if random(2) = 0 then
-			PlaySound(sndNutter, false)
+	else if DamageGiven <> 0 then
+		if Kills > 0 then
+			PlaySound(sndEnemyDown, false)
 		else
-			PlaySound(sndWatchIt, false)
+			PlaySound(sndRegret, false)
+
+	else if AmmoDamagingUsed then
+		PlaySound(sndMissed, false)
+	else if (AmmoUsedCount > 0) and not isTurnSkipped then
+		// nothing ?
+	else if isTurnSkipped then
+		PlaySound(sndBoring, false)
 	else
-		if random(2) = 0 then
-			PlaySound(sndSameTeam, false)
-		else
-			PlaySound(sndTraitor, false)
-
-else if DamageGiven <> 0 then
-	if Kills > 0 then
-		PlaySound(sndEnemyDown, false)
-	else
-		PlaySound(sndRegret, false)
-
-else if AmmoDamagingUsed then
-	PlaySound(sndMissed, false)
-else if (AmmoUsedCount > 0) and not isTurnSkipped then
-	// nothing ?
-else if isTurnSkipped then
-	PlaySound(sndBoring, false)
-else
-	PlaySound(sndCoward, false);
+		PlaySound(sndCoward, false);
+	end;
 
 
-for t:= 0 to Pred(TeamsCount) do
+for t:= 0 to Pred(TeamsCount) do // send even on zero turn
 	with TeamsArray[t]^ do
 		for i:= 0 to cMaxHHIndex do
 			with Hedgehogs[i].stats do
@@ -142,6 +143,12 @@
 				StepDamageGiven:= 0
 				end;
 
+for t:= 0 to Pred(ClansCount) do
+	with ClansArray[t]^ do
+		begin
+		SendStat(siClanHealth, inttostr(Color) + ' ' + inttostr(ClanHealth));
+		end;
+
 Kills:= 0;
 KillsClan:= 0;
 DamageGiven:= 0;