1621
|
1 |
/*
|
|
2 |
* Hedgewars, a free turn based strategy game
|
|
3 |
* Copyright (c) 2009 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
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
|
|
8 |
*
|
|
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.
|
|
13 |
*
|
|
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
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include <QLabel>
|
|
20 |
#include <QGridLayout>
|
1625
|
21 |
#include <QGraphicsScene>
|
1621
|
22 |
|
|
23 |
#include "statsPage.h"
|
|
24 |
|
1636
|
25 |
FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent)
|
|
26 |
{
|
|
27 |
|
|
28 |
}
|
|
29 |
|
|
30 |
void FitGraphicsView::resizeEvent(QResizeEvent * event)
|
|
31 |
{
|
|
32 |
fitInView(sceneRect());
|
|
33 |
}
|
|
34 |
|
1621
|
35 |
PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent)
|
|
36 |
{
|
|
37 |
QGridLayout * pageLayout = new QGridLayout(this);
|
|
38 |
pageLayout->setColumnStretch(0, 1);
|
|
39 |
pageLayout->setColumnStretch(1, 1);
|
|
40 |
pageLayout->setColumnStretch(2, 1);
|
|
41 |
|
1625
|
42 |
BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true);
|
1621
|
43 |
|
|
44 |
labelGameStats = new QLabel(this);
|
|
45 |
labelGameStats->setTextFormat(Qt::RichText);
|
|
46 |
pageLayout->addWidget(labelGameStats, 0, 0, 1, 3);
|
1625
|
47 |
|
1636
|
48 |
graphic = new FitGraphicsView(this);
|
1625
|
49 |
graphic->scale(1.0, -1.0);
|
1637
|
50 |
graphic->setBackgroundBrush(QBrush(Qt::black));
|
1625
|
51 |
pageLayout->addWidget(graphic, 1, 0, 1, 3);
|
1621
|
52 |
}
|
1622
|
53 |
|
|
54 |
void PageGameStats::AddStatText(const QString & msg)
|
|
55 |
{
|
|
56 |
labelGameStats->setText(labelGameStats->text() + msg);
|
|
57 |
}
|
|
58 |
|
|
59 |
void PageGameStats::clear()
|
|
60 |
{
|
|
61 |
labelGameStats->setText("");
|
1625
|
62 |
healthPoints.clear();
|
|
63 |
}
|
|
64 |
|
|
65 |
void PageGameStats::renderStats()
|
|
66 |
{
|
|
67 |
QGraphicsScene * scene = new QGraphicsScene();
|
|
68 |
|
|
69 |
QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
|
|
70 |
while (i != healthPoints.constEnd())
|
|
71 |
{
|
|
72 |
quint32 c = i.key();
|
|
73 |
QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
|
|
74 |
QVector<quint32> hps = i.value();
|
|
75 |
|
|
76 |
QPainterPath path;
|
|
77 |
if (hps.size())
|
|
78 |
path.moveTo(0, hps[0]);
|
|
79 |
|
|
80 |
for(int t = 1; t < hps.size(); ++t)
|
|
81 |
path.lineTo(t, hps[t]);
|
|
82 |
|
|
83 |
scene->addPath(path, QPen(c));
|
|
84 |
++i;
|
|
85 |
}
|
|
86 |
|
|
87 |
graphic->setScene(scene);
|
1673
|
88 |
graphic->fitInView(graphic->sceneRect());
|
1622
|
89 |
}
|
|
90 |
|
|
91 |
void PageGameStats::GameStats(char type, const QString & info)
|
|
92 |
{
|
|
93 |
switch(type) {
|
|
94 |
case 'r' : {
|
|
95 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info));
|
|
96 |
break;
|
|
97 |
}
|
|
98 |
case 'D' : {
|
|
99 |
int i = info.indexOf(' ');
|
1673
|
100 |
QString message = PageGameStats::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>")
|
1622
|
101 |
.arg(info.mid(i + 1), info.left(i));
|
|
102 |
AddStatText(message);
|
|
103 |
break;
|
|
104 |
}
|
|
105 |
case 'k' : {
|
|
106 |
int i = info.indexOf(' ');
|
1673
|
107 |
int num = info.left(i).toInt();
|
|
108 |
QString message = PageGameStats::tr("<p>The best killer is <b>%1</b> with <b>%2</b> kills in a turn.</p>", "", num)
|
1622
|
109 |
.arg(info.mid(i + 1), info.left(i));
|
|
110 |
AddStatText(message);
|
|
111 |
break;
|
|
112 |
}
|
|
113 |
case 'K' : {
|
1673
|
114 |
int num = info.toInt();
|
|
115 |
QString message = PageGameStats::tr("<p>A total of <b>%1</b> hedgehog(s) were killed during this round.</p>", "", num).arg(num);
|
1622
|
116 |
AddStatText(message);
|
|
117 |
break;
|
|
118 |
}
|
1625
|
119 |
case 'H' : {
|
|
120 |
int i = info.indexOf(' ');
|
|
121 |
quint32 clan = info.left(i).toInt();
|
|
122 |
quint32 hp = info.mid(i + 1).toUInt();
|
|
123 |
healthPoints[clan].append(hp);
|
|
124 |
break;
|
|
125 |
}
|
1622
|
126 |
}
|
|
127 |
}
|