# HG changeset patch # User unc0rr # Date 1231512474 0 # Node ID 37aae47943ce65e629cba46f2fab5e5615f79f5a # Parent 3cbf01d31e5ca822728c4d8ebc93528d49fbbf48 Initial health graphic implementation diff -r 3cbf01d31e5c -r 37aae47943ce QTfrontend/hwform.cpp --- 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(); } } diff -r 3cbf01d31e5c -r 37aae47943ce QTfrontend/statsPage.cpp --- 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 #include +#include +#include #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 >::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 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; + } } } diff -r 3cbf01d31e5c -r 37aae47943ce QTfrontend/statsPage.h --- 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 +#include #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 > healthPoints; }; #endif // STATSPAGE_H diff -r 3cbf01d31e5c -r 37aae47943ce hedgewars/uConsts.pas --- 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); diff -r 3cbf01d31e5c -r 37aae47943ce hedgewars/uMisc.pas --- 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; diff -r 3cbf01d31e5c -r 37aae47943ce hedgewars/uStats.pas --- 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;