2
* Hedgewars, a free turn based strategy game
3
* Copyright (c) 2010-2011 Andrey Korotaev <unC0Rr@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; version 2 of the License
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20
#include <QGridLayout>
21
#include <QHBoxLayout>
22
#include <QGraphicsScene>
24
#include <QSizePolicy>
26
#include "pagegamestats.h"
29
FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent)
34
void FitGraphicsView::resizeEvent(QResizeEvent * event)
38
fitInView(sceneRect());
41
QLayout * PageGameStats::bodyLayoutDefinition()
43
QGridLayout * pageLayout = new QGridLayout();
44
pageLayout->setSpacing(20);
45
pageLayout->setColumnStretch(0, 1);
46
pageLayout->setColumnStretch(1, 1);
47
pageLayout->setContentsMargins(7, 7, 7, 0);
49
QGroupBox * gb = new QGroupBox(this);
50
QVBoxLayout * gbl = new QVBoxLayout;
53
labelGameStats = new QLabel(this);
54
QLabel * l = new QLabel(this);
55
l->setTextFormat(Qt::RichText);
56
l->setText("<h1><img src=\":/res/StatsD.png\"> " + PageGameStats::tr("Details") + "</h1>");
57
l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
58
labelGameStats->setTextFormat(Qt::RichText);
59
labelGameStats->setAlignment(Qt::AlignTop);
60
labelGameStats->setWordWrap(true);
62
gbl->addWidget(labelGameStats);
64
pageLayout->addWidget(gb, 1, 1, 1, 2);
67
graphic = new FitGraphicsView(gb);
69
l->setTextFormat(Qt::RichText);
70
l->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
71
l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
73
gbl->addWidget(graphic);
74
graphic->scale(1.0, -1.0);
75
graphic->setBackgroundBrush(QBrush(Qt::black));
77
labelGameWin = new QLabel(this);
78
labelGameWin->setTextFormat(Qt::RichText);
79
pageLayout->addWidget(labelGameWin, 0, 0, 1, 2);
82
gb = new QGroupBox(this);
83
gbl = new QVBoxLayout;
84
labelGameRank = new QLabel(gb);
86
l->setTextFormat(Qt::RichText);
87
l->setText("<h1><img src=\":/res/StatsR.png\"> " + PageGameStats::tr("Ranking") + "</h1>");
88
l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
90
gbl->addWidget(labelGameRank);
93
labelGameRank->setTextFormat(Qt::RichText);
94
labelGameRank->setAlignment(Qt::AlignTop);
95
pageLayout->addWidget(gb, 1, 0);
100
QLayout * PageGameStats::footerLayoutDefinition()
102
QHBoxLayout * bottomLayout = new QHBoxLayout();
104
btnSave = addButton(":/res/Save.png", bottomLayout, 0, true);
105
btnSave->setStyleSheet("QPushButton{margin: 24px 0 0 0;}");
106
bottomLayout->setAlignment(btnSave, Qt::AlignRight | Qt::AlignBottom);
111
void PageGameStats::connectSignals()
113
connect(btnSave, SIGNAL(clicked()), this, SIGNAL(saveDemoRequested()));
116
PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent)
121
void PageGameStats::AddStatText(const QString & msg)
123
labelGameStats->setText(labelGameStats->text() + msg);
126
void PageGameStats::clear()
128
labelGameStats->setText("");
129
healthPoints.clear();
130
labelGameRank->setText("");
135
void PageGameStats::renderStats()
137
QGraphicsScene * scene = new QGraphicsScene();
139
QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
140
while (i != healthPoints.constEnd())
143
QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
144
QVector<quint32> hps = i.value();
148
path.moveTo(0, hps[0]);
150
for(int t = 1; t < hps.size(); ++t)
151
path.lineTo(t, hps[t]);
153
scene->addPath(path, QPen(c));
157
graphic->setScene(scene);
158
graphic->fitInView(graphic->sceneRect());
161
void PageGameStats::GameStats(char type, const QString & info)
165
labelGameWin->setText(QString("<h1 align=\"center\">%1</h1>").arg(info));
169
int i = info.indexOf(' ');
170
QString message = "<p><img src=\":/res/StatsBestShot.png\"> " + PageGameStats::tr("The best shot award was won by <b>%1</b> with <b>%2</b> pts.").arg(info.mid(i + 1), info.left(i)) + "</p>";
171
AddStatText(message);
175
int i = info.indexOf(' ');
176
int num = info.left(i).toInt();
177
QString message = "<p><img src=\":/res/StatsBestKiller.png\"> " + PageGameStats::tr("The best killer is <b>%1</b> with <b>%2</b> kills in a turn.", "", num).arg(info.mid(i + 1), info.left(i)) + "</p>";
178
AddStatText(message);
182
int num = info.toInt();
183
QString message = "<p><img src=\":/res/StatsHedgehogsKilled.png\"> " + PageGameStats::tr("A total of <b>%1</b> hedgehog(s) were killed during this round.", "", num).arg(num) + "</p>";
184
AddStatText(message);
188
int i = info.indexOf(' ');
189
quint32 clan = info.left(i).toInt();
190
quint32 hp = info.mid(i + 1).toUInt();
191
healthPoints[clan].append(hp);
194
case 'T': { // local team stats
195
//AddStatText("<p>local team: " + info + "</p>");
196
QStringList infol = info.split(":");
197
HWTeam team(infol[0]);
198
if(team.fileExists()) // do some better test to avoid influence from scripted/predefined teams?
202
if(infol[1].toInt() > 0) // might require some better test for winning condition (or changed flag) ... WIP!
203
team.incWins(); // should draws count as wins?
204
//team.SaveToFile(); // don't save yet
210
int i = info.indexOf(' ');
212
QString color = info.left(i);
213
quint32 c = color.toInt();
214
QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
216
QString playerinfo = info.mid(i + 1);
218
i = playerinfo.indexOf(' ');
220
int kills = playerinfo.left(i).toInt();
221
QString playername = playerinfo.mid(i + 1);
224
if (lastColor == c) playerPosition--;
227
switch (playerPosition)
230
image = "<img src=\":/res/StatsMedal1.png\">";
233
image = "<img src=\":/res/StatsMedal2.png\">";
236
image = "<img src=\":/res/StatsMedal3.png\">";
239
image = "<img src=\":/res/StatsMedal4.png\">";
244
QString killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills);
246
message = QString("<p><h2>%1 %2. <font color=\"%4\">%3</font> ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "</h2></p>";
248
labelGameRank->setText(labelGameRank->text() + message);
252
int i = info.indexOf(' ');
253
int num = info.left(i).toInt();
254
QString message = "<p><img src=\":/res/StatsMostSelfDamage.png\"> " + PageGameStats::tr("<b>%1</b> thought it's good to shoot his own hedgehogs with <b>%2</b> pts.", "", num).arg(info.mid(i + 1)).arg(num) + "</p>";
255
AddStatText(message);
259
int i = info.indexOf(' ');
260
int num = info.left(i).toInt();
261
QString message = "<p><img src=\":/res/StatsSelfKilled.png\"> " + PageGameStats::tr("<b>%1</b> killed <b>%2</b> of his own hedgehogs.", "", num).arg(info.mid(i + 1)).arg(num) + "</p>";
262
AddStatText(message);
266
int i = info.indexOf(' ');
267
int num = info.left(i).toInt();
268
QString message = "<p><img src=\":/res/StatsSkipped.png\"> " + PageGameStats::tr("<b>%1</b> was scared and skipped turn <b>%2</b> times.", "", num).arg(info.mid(i + 1)).arg(num) + "</p>";
269
AddStatText(message);