QTfrontend/statsPage.cpp
changeset 3793 46e6fa2cdbc6
parent 3788 9aa8a832e296
child 3815 8754f7874395
equal deleted inserted replaced
3792:dd9345e74b66 3793:46e6fa2cdbc6
    17  */
    17  */
    18 
    18 
    19 #include <QLabel>
    19 #include <QLabel>
    20 #include <QGridLayout>
    20 #include <QGridLayout>
    21 #include <QGraphicsScene>
    21 #include <QGraphicsScene>
    22 
    22 #include <QGroupBox>
       
    23 #include <QSizePolicy>
    23 #include "statsPage.h"
    24 #include "statsPage.h"
    24 #include "team.h"
    25 #include "team.h"
    25 
    26 
    26 FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent)
    27 FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent)
    27 {
    28 {
    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(PageGameStats::tr("<h1><img src=\":/res/StatsD.png\"> 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(PageGameStats::tr("<br><h1><img src=\":/res/StatsH.png\"> 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(PageGameStats::tr("<h1><img src=\":/res/StatsR.png\"> 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);
    59 
    99 
    60 void PageGameStats::clear()
   100 void PageGameStats::clear()
    61 {
   101 {
    62     labelGameStats->setText("");
   102     labelGameStats->setText("");
    63     healthPoints.clear();
   103     healthPoints.clear();
       
   104     labelGameRank->setText("");
       
   105     playerPosition = 0;
       
   106     lastColor = 0;
    64 }
   107 }
    65 
   108 
    66 void PageGameStats::renderStats()
   109 void PageGameStats::renderStats()
    67 {
   110 {
    68     QGraphicsScene * scene = new QGraphicsScene();
   111     QGraphicsScene * scene = new QGraphicsScene();
    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 = PageGameStats::tr("<p><img src=\":/res/StatsBestShot.png\"> The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>")
   102                     .arg(info.mid(i + 1), info.left(i));
   145                     .arg(info.mid(i + 1), info.left(i));
   103             AddStatText(message);
   146             AddStatText(message);
   104             break;
   147             break;
   105         }
   148         }
   106         case 'k' : {
   149         case 'k' : {
   107             int i = info.indexOf(' ');
   150             int i = info.indexOf(' ');
   108             int num = info.left(i).toInt();
   151             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)
   152             QString message = PageGameStats::tr("<p><img src=\":/res/StatsBestKiller.png\"> The best killer is <b>%1</b> with <b>%2</b> kills in a turn.</p>", "", num)
   110                     .arg(info.mid(i + 1), info.left(i));
   153                     .arg(info.mid(i + 1), info.left(i));
   111             AddStatText(message);
   154             AddStatText(message);
   112             break;
   155             break;
   113         }
   156         }
   114         case 'K' : {
   157         case 'K' : {
   115             int num = info.toInt();
   158             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);
   159             QString message = PageGameStats::tr("<p><img src=\":/res/StatsHedgehogsKilled.png\"> A total of <b>%1</b> hedgehog(s) were killed during this round.</p>", "", num).arg(num);
   117             AddStatText(message);
   160             AddStatText(message);
   118             break;
   161             break;
   119         }
   162         }
   120         case 'H' : {
   163         case 'H' : {
   121             int i = info.indexOf(' ');
   164             int i = info.indexOf(' ');
   134                 team.Rounds++;
   177                 team.Rounds++;
   135                 if(infol[1].toInt() > 0) // might require some better test for winning condition (or changed flag) ... WIP!
   178                 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?
   179                     team.Wins++; // should draws count as wins?
   137                 //team.SaveToFile(); // don't save yet
   180                 //team.SaveToFile(); // don't save yet
   138             }
   181             }
   139         }
   182 	    break;
       
   183         }
       
   184 	
       
   185         case 'P' : {
       
   186             int i = info.indexOf(' ');
       
   187 	    playerPosition++;
       
   188 	    QString color = info.left(i);
       
   189 	    quint32 c = color.toInt();
       
   190 	    QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
       
   191 
       
   192 	    QString playerinfo = info.mid(i + 1);
       
   193 	    
       
   194 	    i = playerinfo.indexOf(' ');
       
   195 
       
   196 	    QString kills = playerinfo.left(i);
       
   197 	    QString playername = playerinfo.mid(i + 1);
       
   198 	    QString image;
       
   199 
       
   200             if (lastColor == c && playerPosition <= 2) playerPosition = 1;
       
   201 	    lastColor = c;
       
   202 
       
   203 	    switch (playerPosition)
       
   204 	    {
       
   205 	    	case 1:
       
   206 			image = "<img src=\":/res/StatsMedal1.png\">";
       
   207 			break;
       
   208 		case 2:
       
   209 			image = "<img src=\":/res/StatsMedal2.png\">";
       
   210 			break;
       
   211 		case 3:
       
   212 			image = "<img src=\":/res/StatsMedal3.png\">";
       
   213 			break;
       
   214 		default:
       
   215 			image = "<img src=\":/res/StatsMedal4.png\">";
       
   216 			break;
       
   217 	    }
       
   218 
       
   219             QString message;
       
   220 	    if (kills.toInt() == 1)
       
   221 	    {
       
   222 	    	message = PageGameStats::tr("<p><h2>%1 %2. <font color=\"%5\">%3</font>  (%4 kill).</h2></p>").arg(image, QString::number(playerPosition), playername, kills, clanColor.name());
       
   223 	    } else {
       
   224 	        message = PageGameStats::tr("<p><h2>%1 %2. <font color=\"%5\">%3</font>  (%4 kills).</h2></p>").arg(image, QString::number(playerPosition), playername, kills, clanColor.name());
       
   225             }
       
   226             labelGameRank->setText(labelGameRank->text() + message);
       
   227             break;
       
   228 	}
       
   229         case 's' : {
       
   230             int i = info.indexOf(' ');
       
   231             QString message = PageGameStats::tr("<p><img src=\":/res/StatsMostSelfDamage.png\"> <b>%1</b> thought it's good to shoot his own hedgehogs with <b>%2</b> pts.</p>")
       
   232                     .arg(info.mid(i + 1), info.left(i));
       
   233             AddStatText(message);
       
   234             break;
       
   235         }
       
   236         case 'S' : {
       
   237             int i = info.indexOf(' ');
       
   238             QString message = PageGameStats::tr("<p><img src=\":/res/StatsSelfKilled.png\"> <b>%1</b> killed <b>%2</b> of his own hedgehogs.</p>")
       
   239                     .arg(info.mid(i + 1), info.left(i));
       
   240             AddStatText(message);
       
   241             break;
       
   242         }
       
   243         case 'B' : {
       
   244             int i = info.indexOf(' ');
       
   245             QString message = PageGameStats::tr("<p><img src=\":/res/StatsSkipped.png\"> <b>%1</b> was scared and skipped turn <b>%2</b> times.</p>")
       
   246                     .arg(info.mid(i + 1), info.left(i));
       
   247             AddStatText(message);
       
   248             break;
       
   249         }
       
   250 
   140     }
   251     }
   141 }
   252 }