author | koda |
Fri, 23 Jul 2010 15:08:44 +0200 | |
changeset 3664 | f5bdf26c843e |
parent 3381 | f8800c44b3de |
child 3788 | 9aa8a832e296 |
permissions | -rw-r--r-- |
1621 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3236
4ab3917d7d44
Update (c) lines to 2010 as unc0rr requested - they all had varying values so I just took the first year mentioned, then tacked on -2010
nemo
parents:
2948
diff
changeset
|
3 |
* Copyright (c) 2010 Andrey Korotaev <unC0Rr@gmail.com> |
1621 | 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" |
|
3381 | 24 |
#include "team.h" |
1621 | 25 |
|
1636 | 26 |
FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent) |
27 |
{ |
|
28 |
||
29 |
} |
|
30 |
||
31 |
void FitGraphicsView::resizeEvent(QResizeEvent * event) |
|
32 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
33 |
fitInView(sceneRect()); |
1636 | 34 |
} |
35 |
||
1621 | 36 |
PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent) |
37 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
38 |
QGridLayout * pageLayout = new QGridLayout(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
39 |
pageLayout->setColumnStretch(0, 1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
40 |
pageLayout->setColumnStretch(1, 1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
41 |
pageLayout->setColumnStretch(2, 1); |
1621 | 42 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
43 |
BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true); |
1621 | 44 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
45 |
labelGameStats = new QLabel(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
46 |
labelGameStats->setTextFormat(Qt::RichText); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
47 |
pageLayout->addWidget(labelGameStats, 0, 0, 1, 3); |
1625 | 48 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
49 |
graphic = new FitGraphicsView(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
50 |
graphic->scale(1.0, -1.0); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
51 |
graphic->setBackgroundBrush(QBrush(Qt::black)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
52 |
pageLayout->addWidget(graphic, 1, 0, 1, 3); |
1621 | 53 |
} |
1622 | 54 |
|
55 |
void PageGameStats::AddStatText(const QString & msg) |
|
56 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
57 |
labelGameStats->setText(labelGameStats->text() + msg); |
1622 | 58 |
} |
59 |
||
60 |
void PageGameStats::clear() |
|
61 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
62 |
labelGameStats->setText(""); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
63 |
healthPoints.clear(); |
1625 | 64 |
} |
65 |
||
66 |
void PageGameStats::renderStats() |
|
67 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
68 |
QGraphicsScene * scene = new QGraphicsScene(); |
1625 | 69 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
70 |
QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
71 |
while (i != healthPoints.constEnd()) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
72 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
73 |
quint32 c = i.key(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
74 |
QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
75 |
QVector<quint32> hps = i.value(); |
1625 | 76 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
77 |
QPainterPath path; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
78 |
if (hps.size()) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
79 |
path.moveTo(0, hps[0]); |
2377 | 80 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
81 |
for(int t = 1; t < hps.size(); ++t) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
82 |
path.lineTo(t, hps[t]); |
1625 | 83 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
84 |
scene->addPath(path, QPen(c)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
85 |
++i; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
86 |
} |
1625 | 87 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
88 |
graphic->setScene(scene); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
89 |
graphic->fitInView(graphic->sceneRect()); |
1622 | 90 |
} |
91 |
||
92 |
void PageGameStats::GameStats(char type, const QString & info) |
|
93 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
94 |
switch(type) { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
95 |
case 'r' : { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
96 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
97 |
break; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
98 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
99 |
case 'D' : { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
100 |
int i = info.indexOf(' '); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
101 |
QString message = PageGameStats::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
102 |
.arg(info.mid(i + 1), info.left(i)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
103 |
AddStatText(message); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
104 |
break; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
105 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
106 |
case 'k' : { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
107 |
int i = info.indexOf(' '); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
108 |
int num = info.left(i).toInt(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
109 |
QString message = PageGameStats::tr("<p>The best killer is <b>%1</b> with <b>%2</b> kills in a turn.</p>", "", num) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
110 |
.arg(info.mid(i + 1), info.left(i)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
111 |
AddStatText(message); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
112 |
break; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
113 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
114 |
case 'K' : { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
115 |
int num = info.toInt(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
116 |
QString message = PageGameStats::tr("<p>A total of <b>%1</b> hedgehog(s) were killed during this round.</p>", "", num).arg(num); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
117 |
AddStatText(message); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
118 |
break; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
119 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
120 |
case 'H' : { |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
121 |
int i = info.indexOf(' '); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
122 |
quint32 clan = info.left(i).toInt(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
123 |
quint32 hp = info.mid(i + 1).toUInt(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
124 |
healthPoints[clan].append(hp); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
125 |
break; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
126 |
} |
3381 | 127 |
case 'T': { // local team stats |
128 |
//AddStatText("<p>local team: " + info + "</p>"); |
|
129 |
QStringList infol = info.split(":"); |
|
130 |
HWTeam team(infol[0]); |
|
131 |
if(team.FileExists()) // do some better test to avoid influence from scripted/predefined teams? |
|
132 |
{ |
|
133 |
team.LoadFromFile(); |
|
134 |
team.Rounds++; |
|
135 |
if(infol[1].toInt() > 0) // might require some better test for winning condition (or changed flag) ... WIP! |
|
136 |
team.Wins++; // should draws count as wins? |
|
137 |
//team.SaveToFile(); // don't save yet |
|
138 |
} |
|
139 |
} |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2377
diff
changeset
|
140 |
} |
1622 | 141 |
} |