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