34 } |
35 } |
35 |
36 |
36 PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent) |
37 PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent) |
37 { |
38 { |
38 QGridLayout * pageLayout = new QGridLayout(this); |
39 QGridLayout * pageLayout = new QGridLayout(this); |
|
40 pageLayout->setSpacing(20); |
39 pageLayout->setColumnStretch(0, 1); |
41 pageLayout->setColumnStretch(0, 1); |
40 pageLayout->setColumnStretch(1, 1); |
42 pageLayout->setColumnStretch(1, 1); |
41 pageLayout->setColumnStretch(2, 1); |
43 |
42 |
44 BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); |
43 BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true); |
45 BtnBack->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
44 |
46 |
|
47 QGroupBox * gb = new QGroupBox(this); |
|
48 QVBoxLayout * gbl = new QVBoxLayout; |
|
49 |
|
50 // details |
45 labelGameStats = new QLabel(this); |
51 labelGameStats = new QLabel(this); |
|
52 QLabel * l = new QLabel(this); |
|
53 l->setTextFormat(Qt::RichText); |
|
54 l->setText("<h1><img src=\":/res/StatsD.png\"> " + PageGameStats::tr("Details") + "</h1>"); |
|
55 l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
46 labelGameStats->setTextFormat(Qt::RichText); |
56 labelGameStats->setTextFormat(Qt::RichText); |
47 pageLayout->addWidget(labelGameStats, 0, 0, 1, 3); |
57 labelGameStats->setAlignment(Qt::AlignTop); |
48 |
58 gbl->addWidget(l); |
49 graphic = new FitGraphicsView(this); |
59 gbl->addWidget(labelGameStats); |
|
60 gb->setLayout(gbl); |
|
61 pageLayout->addWidget(gb, 1, 1); |
|
62 |
|
63 // graph |
|
64 graphic = new FitGraphicsView(gb); |
|
65 l = new QLabel(this); |
|
66 l->setTextFormat(Qt::RichText); |
|
67 l->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>"); |
|
68 l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|
69 gbl->addWidget(l); |
|
70 gbl->addWidget(graphic); |
50 graphic->scale(1.0, -1.0); |
71 graphic->scale(1.0, -1.0); |
51 graphic->setBackgroundBrush(QBrush(Qt::black)); |
72 graphic->setBackgroundBrush(QBrush(Qt::black)); |
52 pageLayout->addWidget(graphic, 1, 0, 1, 3); |
73 |
|
74 labelGameWin = new QLabel(this); |
|
75 labelGameWin->setTextFormat(Qt::RichText); |
|
76 pageLayout->addWidget(labelGameWin, 0, 0, 1, 2); |
|
77 |
|
78 // ranking box |
|
79 gb = new QGroupBox(this); |
|
80 gbl = new QVBoxLayout; |
|
81 labelGameRank = new QLabel(gb); |
|
82 l = new QLabel(this); |
|
83 l->setTextFormat(Qt::RichText); |
|
84 l->setText("<h1><img src=\":/res/StatsR.png\"> " + PageGameStats::tr("Ranking") + "</h1>"); |
|
85 l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|
86 gbl->addWidget(l); |
|
87 gbl->addWidget(labelGameRank); |
|
88 gb->setLayout(gbl); |
|
89 |
|
90 labelGameRank->setTextFormat(Qt::RichText); |
|
91 labelGameRank->setAlignment(Qt::AlignTop); |
|
92 pageLayout->addWidget(gb, 1, 0); |
53 } |
93 } |
54 |
94 |
55 void PageGameStats::AddStatText(const QString & msg) |
95 void PageGameStats::AddStatText(const QString & msg) |
56 { |
96 { |
57 labelGameStats->setText(labelGameStats->text() + msg); |
97 labelGameStats->setText(labelGameStats->text() + msg); |
91 |
134 |
92 void PageGameStats::GameStats(char type, const QString & info) |
135 void PageGameStats::GameStats(char type, const QString & info) |
93 { |
136 { |
94 switch(type) { |
137 switch(type) { |
95 case 'r' : { |
138 case 'r' : { |
96 AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
139 labelGameWin->setText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
97 break; |
140 break; |
98 } |
141 } |
99 case 'D' : { |
142 case 'D' : { |
100 int i = info.indexOf(' '); |
143 int i = info.indexOf(' '); |
101 QString message = PageGameStats::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
144 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>"; |
102 .arg(info.mid(i + 1), info.left(i)); |
|
103 AddStatText(message); |
145 AddStatText(message); |
104 break; |
146 break; |
105 } |
147 } |
106 case 'k' : { |
148 case 'k' : { |
107 int i = info.indexOf(' '); |
149 int i = info.indexOf(' '); |
108 int num = info.left(i).toInt(); |
150 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) |
151 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>"; |
110 .arg(info.mid(i + 1), info.left(i)); |
|
111 AddStatText(message); |
152 AddStatText(message); |
112 break; |
153 break; |
113 } |
154 } |
114 case 'K' : { |
155 case 'K' : { |
115 int num = info.toInt(); |
156 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); |
157 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>"; |
117 AddStatText(message); |
158 AddStatText(message); |
118 break; |
159 break; |
119 } |
160 } |
120 case 'H' : { |
161 case 'H' : { |
121 int i = info.indexOf(' '); |
162 int i = info.indexOf(' '); |
134 team.Rounds++; |
175 team.Rounds++; |
135 if(infol[1].toInt() > 0) // might require some better test for winning condition (or changed flag) ... WIP! |
176 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? |
177 team.Wins++; // should draws count as wins? |
137 //team.SaveToFile(); // don't save yet |
178 //team.SaveToFile(); // don't save yet |
138 } |
179 } |
139 } |
180 break; |
|
181 } |
|
182 |
|
183 case 'P' : { |
|
184 int i = info.indexOf(' '); |
|
185 playerPosition++; |
|
186 QString color = info.left(i); |
|
187 quint32 c = color.toInt(); |
|
188 QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); |
|
189 |
|
190 QString playerinfo = info.mid(i + 1); |
|
191 |
|
192 i = playerinfo.indexOf(' '); |
|
193 |
|
194 QString kills = playerinfo.left(i); |
|
195 QString playername = playerinfo.mid(i + 1); |
|
196 QString image; |
|
197 |
|
198 if (lastColor == c && playerPosition <= 2) playerPosition = 1; |
|
199 lastColor = c; |
|
200 |
|
201 switch (playerPosition) |
|
202 { |
|
203 case 1: |
|
204 image = "<img src=\":/res/StatsMedal1.png\">"; |
|
205 break; |
|
206 case 2: |
|
207 image = "<img src=\":/res/StatsMedal2.png\">"; |
|
208 break; |
|
209 case 3: |
|
210 image = "<img src=\":/res/StatsMedal3.png\">"; |
|
211 break; |
|
212 default: |
|
213 image = "<img src=\":/res/StatsMedal4.png\">"; |
|
214 break; |
|
215 } |
|
216 |
|
217 QString message; |
|
218 QString killstring; |
|
219 if (kills.toInt() == 1) |
|
220 { |
|
221 killstring = PageGameStats::tr("(%1 kill)").arg(kills); |
|
222 } else { |
|
223 killstring = PageGameStats::tr("(%1 kills)").arg(kills); |
|
224 } |
|
225 |
|
226 message = QString("<p><h2>%1 %2. <font color=\"%4\">%3</font> ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "</h2></p>"; |
|
227 |
|
228 labelGameRank->setText(labelGameRank->text() + message); |
|
229 break; |
|
230 } |
|
231 case 's' : { |
|
232 int i = info.indexOf(' '); |
|
233 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.").arg(info.mid(i + 1), info.left(i)) + "</p>"; |
|
234 AddStatText(message); |
|
235 break; |
|
236 } |
|
237 case 'S' : { |
|
238 int i = info.indexOf(' '); |
|
239 QString message = "<p><img src=\":/res/StatsSelfKilled.png\"> " + PageGameStats::tr("<b>%1</b> killed <b>%2</b> of his own hedgehogs.").arg(info.mid(i + 1), info.left(i)) + "</p>"; |
|
240 AddStatText(message); |
|
241 break; |
|
242 } |
|
243 case 'B' : { |
|
244 int i = info.indexOf(' '); |
|
245 QString message = "<p><img src=\":/res/StatsSkipped.png\"> " + PageGameStats::tr("<b>%1</b> was scared and skipped turn <b>%2</b> times.").arg(info.mid(i + 1), info.left(i)) + "</p>"; |
|
246 AddStatText(message); |
|
247 break; |
|
248 } |
|
249 |
140 } |
250 } |
141 } |
251 } |