QTfrontend/pagegamestats.cpp
author nemo
Sun, 04 Sep 2011 12:34:43 -0400
changeset 5766 ca9c7551bc8a
parent 5734 d710db47a1ef
child 5916 c76212c34192
permissions -rw-r--r--
oops
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1621
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     1
/*
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     3
 * Copyright (c) 2010-2011 Andrey Korotaev <unC0Rr@gmail.com>
1621
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     4
 *
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     8
 *
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    13
 *
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    17
 */
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    18
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    19
#include <QLabel>
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    20
#include <QGridLayout>
1625
37aae47943ce Initial health graphic implementation
unc0rr
parents: 1623
diff changeset
    21
#include <QGraphicsScene>
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    22
#include <QGroupBox>
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    23
#include <QSizePolicy>
5205
78138ae93820 some headers cleanup and rename of stats and playrecord pages for consistency
koda
parents: 5028
diff changeset
    24
78138ae93820 some headers cleanup and rename of stats and playrecord pages for consistency
koda
parents: 5028
diff changeset
    25
#include "pagegamestats.h"
3381
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
    26
#include "team.h"
1621
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    27
1636
e528696f2177 Resize health graphic when form is resized
unc0rr
parents: 1625
diff changeset
    28
FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent)
e528696f2177 Resize health graphic when form is resized
unc0rr
parents: 1625
diff changeset
    29
{
e528696f2177 Resize health graphic when form is resized
unc0rr
parents: 1625
diff changeset
    30
e528696f2177 Resize health graphic when form is resized
unc0rr
parents: 1625
diff changeset
    31
}
e528696f2177 Resize health graphic when form is resized
unc0rr
parents: 1625
diff changeset
    32
e528696f2177 Resize health graphic when form is resized
unc0rr
parents: 1625
diff changeset
    33
void FitGraphicsView::resizeEvent(QResizeEvent * event)
e528696f2177 Resize health graphic when form is resized
unc0rr
parents: 1625
diff changeset
    34
{
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4217
diff changeset
    35
    Q_UNUSED(event);
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4217
diff changeset
    36
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    37
    fitInView(sceneRect());
1636
e528696f2177 Resize health graphic when form is resized
unc0rr
parents: 1625
diff changeset
    38
}
e528696f2177 Resize health graphic when form is resized
unc0rr
parents: 1625
diff changeset
    39
1621
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    40
PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent)
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    41
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    42
    QGridLayout * pageLayout = new QGridLayout(this);
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    43
    pageLayout->setSpacing(20);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    44
    pageLayout->setColumnStretch(0, 1);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    45
    pageLayout->setColumnStretch(1, 1);
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    46
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    47
    BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    48
    BtnBack->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
1621
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    49
5734
d710db47a1ef Implement save button on game statistics page.
unc0rr
parents: 5205
diff changeset
    50
    BtnSave = addButton(":/res/Save.png", pageLayout, 3, 2, true);
d710db47a1ef Implement save button on game statistics page.
unc0rr
parents: 5205
diff changeset
    51
    BtnSave->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
d710db47a1ef Implement save button on game statistics page.
unc0rr
parents: 5205
diff changeset
    52
    BtnSave->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}");
d710db47a1ef Implement save button on game statistics page.
unc0rr
parents: 5205
diff changeset
    53
    connect(BtnSave, SIGNAL(clicked()), this, SIGNAL(saveDemoRequested()));
d710db47a1ef Implement save button on game statistics page.
unc0rr
parents: 5205
diff changeset
    54
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    55
    QGroupBox * gb = new QGroupBox(this);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    56
    QVBoxLayout * gbl = new QVBoxLayout;
1621
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    57
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    58
    // details
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    59
    labelGameStats = new QLabel(this);
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    60
    QLabel * l = new QLabel(this);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    61
    l->setTextFormat(Qt::RichText);
3815
8754f7874395 Frontend: improve statsPage (clean up translation strings)
TheXception
parents: 3788
diff changeset
    62
    l->setText("<h1><img src=\":/res/StatsD.png\"> " + PageGameStats::tr("Details") + "</h1>");
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    63
    l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    64
    labelGameStats->setTextFormat(Qt::RichText);
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    65
    labelGameStats->setAlignment(Qt::AlignTop);
5028
3c43f00b0743 This should fix http://code.google.com/p/hedgewars/issues/detail?id=153
shreyasbp@gmail.com
parents: 4976
diff changeset
    66
    labelGameStats->setWordWrap(true);
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    67
    gbl->addWidget(l);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    68
    gbl->addWidget(labelGameStats);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    69
    gb->setLayout(gbl);
5734
d710db47a1ef Implement save button on game statistics page.
unc0rr
parents: 5205
diff changeset
    70
    pageLayout->addWidget(gb, 1, 1, 1, 2);
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    71
    
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    72
    // graph
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    73
    graphic = new FitGraphicsView(gb);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    74
    l = new QLabel(this);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    75
    l->setTextFormat(Qt::RichText);
3815
8754f7874395 Frontend: improve statsPage (clean up translation strings)
TheXception
parents: 3788
diff changeset
    76
    l->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    77
    l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    78
    gbl->addWidget(l);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    79
    gbl->addWidget(graphic);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    80
    graphic->scale(1.0, -1.0);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
    81
    graphic->setBackgroundBrush(QBrush(Qt::black));
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    82
    
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    83
    labelGameWin = new QLabel(this);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    84
    labelGameWin->setTextFormat(Qt::RichText);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    85
    pageLayout->addWidget(labelGameWin, 0, 0, 1, 2);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    86
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    87
    // ranking box
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    88
    gb = new QGroupBox(this);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    89
    gbl = new QVBoxLayout;
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    90
    labelGameRank = new QLabel(gb);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    91
    l = new QLabel(this);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    92
    l->setTextFormat(Qt::RichText);
3815
8754f7874395 Frontend: improve statsPage (clean up translation strings)
TheXception
parents: 3788
diff changeset
    93
    l->setText("<h1><img src=\":/res/StatsR.png\"> " + PageGameStats::tr("Ranking") + "</h1>");
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    94
    l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    95
    gbl->addWidget(l);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    96
    gbl->addWidget(labelGameRank);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    97
    gb->setLayout(gbl);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    98
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
    99
    labelGameRank->setTextFormat(Qt::RichText);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   100
    labelGameRank->setAlignment(Qt::AlignTop);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   101
    pageLayout->addWidget(gb, 1, 0);
1621
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
   102
}
1622
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   103
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   104
void PageGameStats::AddStatText(const QString & msg)
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   105
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   106
    labelGameStats->setText(labelGameStats->text() + msg);
1622
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   107
}
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   108
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   109
void PageGameStats::clear()
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   110
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   111
    labelGameStats->setText("");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   112
    healthPoints.clear();
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   113
    labelGameRank->setText("");
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   114
    playerPosition = 0;
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   115
    lastColor = 0;
1625
37aae47943ce Initial health graphic implementation
unc0rr
parents: 1623
diff changeset
   116
}
37aae47943ce Initial health graphic implementation
unc0rr
parents: 1623
diff changeset
   117
37aae47943ce Initial health graphic implementation
unc0rr
parents: 1623
diff changeset
   118
void PageGameStats::renderStats()
37aae47943ce Initial health graphic implementation
unc0rr
parents: 1623
diff changeset
   119
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   120
    QGraphicsScene * scene = new QGraphicsScene();
1625
37aae47943ce Initial health graphic implementation
unc0rr
parents: 1623
diff changeset
   121
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   122
    QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   123
    while (i != healthPoints.constEnd())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   124
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   125
        quint32 c = i.key();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   126
        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
   127
        QVector<quint32> hps = i.value();
1625
37aae47943ce Initial health graphic implementation
unc0rr
parents: 1623
diff changeset
   128
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   129
        QPainterPath path;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   130
        if (hps.size())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   131
            path.moveTo(0, hps[0]);
2377
f3fab2b09e0c And in frontend
nemo
parents: 1904
diff changeset
   132
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   133
        for(int t = 1; t < hps.size(); ++t)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   134
            path.lineTo(t, hps[t]);
1625
37aae47943ce Initial health graphic implementation
unc0rr
parents: 1623
diff changeset
   135
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   136
        scene->addPath(path, QPen(c));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   137
        ++i;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   138
    }
1625
37aae47943ce Initial health graphic implementation
unc0rr
parents: 1623
diff changeset
   139
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   140
    graphic->setScene(scene);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   141
    graphic->fitInView(graphic->sceneRect());
1622
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   142
}
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   143
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   144
void PageGameStats::GameStats(char type, const QString & info)
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   145
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   146
    switch(type) {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   147
        case 'r' : {
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   148
            labelGameWin->setText(QString("<h1 align=\"center\">%1</h1>").arg(info));
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   149
            break;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   150
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   151
        case 'D' : {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   152
            int i = info.indexOf(' ');
3815
8754f7874395 Frontend: improve statsPage (clean up translation strings)
TheXception
parents: 3788
diff changeset
   153
            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>";
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   154
            AddStatText(message);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   155
            break;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   156
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   157
        case 'k' : {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   158
            int i = info.indexOf(' ');
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   159
            int num = info.left(i).toInt();
3815
8754f7874395 Frontend: improve statsPage (clean up translation strings)
TheXception
parents: 3788
diff changeset
   160
            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>";
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   161
            AddStatText(message);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   162
            break;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   163
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   164
        case 'K' : {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   165
            int num = info.toInt();
3815
8754f7874395 Frontend: improve statsPage (clean up translation strings)
TheXception
parents: 3788
diff changeset
   166
            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>";
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   167
            AddStatText(message);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   168
            break;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   169
        }
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   170
        case 'H' : {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   171
            int i = info.indexOf(' ');
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   172
            quint32 clan = info.left(i).toInt();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   173
            quint32 hp = info.mid(i + 1).toUInt();
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   174
            healthPoints[clan].append(hp);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   175
            break;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   176
        }
3381
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   177
        case 'T': { // local team stats
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   178
            //AddStatText("<p>local team: " + info + "</p>");
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   179
            QStringList infol = info.split(":");
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   180
            HWTeam team(infol[0]);
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   181
            if(team.FileExists()) // do some better test to avoid influence from scripted/predefined teams?
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   182
            {
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   183
                team.LoadFromFile();
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   184
                team.Rounds++;
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   185
                if(infol[1].toInt() > 0) // might require some better test for winning condition (or changed flag) ... WIP!
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   186
                    team.Wins++; // should draws count as wins?
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   187
                //team.SaveToFile(); // don't save yet
f8800c44b3de Engine:
smxx
parents: 3236
diff changeset
   188
            }
4176
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   189
            break;
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   190
            }
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   191
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   192
        case 'P' : {
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   193
            int i = info.indexOf(' ');
4176
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   194
            playerPosition++;
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   195
            QString color = info.left(i);
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   196
            quint32 c = color.toInt();
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   197
            QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   198
4176
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   199
            QString playerinfo = info.mid(i + 1);
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   200
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   201
            i = playerinfo.indexOf(' ');
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   202
4176
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   203
            int kills = playerinfo.left(i).toInt();
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   204
            QString playername = playerinfo.mid(i + 1);
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   205
            QString image;
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   206
4217
721bfa5f4f31 Fix wrong order in results screen when players team up
TheException
parents: 4192
diff changeset
   207
            if (lastColor == c) playerPosition--;
4176
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   208
            lastColor = c;
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   209
4176
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   210
            switch (playerPosition)
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   211
            {
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   212
                case 1:
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   213
                image = "<img src=\":/res/StatsMedal1.png\">";
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   214
                break;
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   215
            case 2:
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   216
                image = "<img src=\":/res/StatsMedal2.png\">";
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   217
                break;
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   218
            case 3:
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   219
                image = "<img src=\":/res/StatsMedal3.png\">";
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   220
                break;
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   221
            default:
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   222
                image = "<img src=\":/res/StatsMedal4.png\">";
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   223
                break;
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   224
            }
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   225
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   226
            QString message;
4176
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   227
            QString killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills);
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   228
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   229
            message = QString("<p><h2>%1 %2. <font color=\"%4\">%3</font> ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "</h2></p>";
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   230
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   231
            labelGameRank->setText(labelGameRank->text() + message);
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   232
                break;
4e3942f5827c Fix i18n of plural forms
unc0rr
parents: 3815
diff changeset
   233
        }
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   234
        case 's' : {
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   235
            int i = info.indexOf(' ');
4177
6acd599eee52 Fix some more messages
unc0rr
parents: 4176
diff changeset
   236
            int num = info.left(i).toInt();
4192
67e1a683e9b3 Fix stats messages
unc0rr
parents: 4177
diff changeset
   237
            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>";
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   238
            AddStatText(message);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   239
            break;
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   240
        }
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   241
        case 'S' : {
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   242
            int i = info.indexOf(' ');
4177
6acd599eee52 Fix some more messages
unc0rr
parents: 4176
diff changeset
   243
            int num = info.left(i).toInt();
4192
67e1a683e9b3 Fix stats messages
unc0rr
parents: 4177
diff changeset
   244
            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>";
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   245
            AddStatText(message);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   246
            break;
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   247
        }
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   248
        case 'B' : {
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   249
            int i = info.indexOf(' ');
4177
6acd599eee52 Fix some more messages
unc0rr
parents: 4176
diff changeset
   250
            int num = info.left(i).toInt();
4192
67e1a683e9b3 Fix stats messages
unc0rr
parents: 4177
diff changeset
   251
            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>";
3788
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   252
            AddStatText(message);
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   253
            break;
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   254
        }
9aa8a832e296 adds prettier after-game statistics page with more stats
TheXception
parents: 3381
diff changeset
   255
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2377
diff changeset
   256
    }
1622
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
   257
}