QTfrontend/ui/page/pagegamestats.cpp
branchwebgl
changeset 9197 e4e366013e9a
parent 9178 c0902317c823
child 9998 736015b847e3
equal deleted inserted replaced
9168:20ff80421736 9197:e4e366013e9a
    38     fitInView(sceneRect());
    38     fitInView(sceneRect());
    39 }
    39 }
    40 
    40 
    41 QLayout * PageGameStats::bodyLayoutDefinition()
    41 QLayout * PageGameStats::bodyLayoutDefinition()
    42 {
    42 {
       
    43 	kindOfPoints = QString("");
       
    44 	defaultGraphTitle = true;	
    43     QGridLayout * pageLayout = new QGridLayout();
    45     QGridLayout * pageLayout = new QGridLayout();
    44     pageLayout->setSpacing(20);
    46     pageLayout->setSpacing(20);
    45     pageLayout->setColumnStretch(0, 1);
    47     pageLayout->setColumnStretch(0, 1);
    46     pageLayout->setColumnStretch(1, 1);
    48     pageLayout->setColumnStretch(1, 1);
       
    49     pageLayout->setRowStretch(0, 1);    
       
    50     pageLayout->setRowStretch(1, 20);
       
    51     //pageLayout->setRowStretch(1, -1); this should work but there is unnecessary empty space betwin lines if used
    47     pageLayout->setContentsMargins(7, 7, 7, 0);
    52     pageLayout->setContentsMargins(7, 7, 7, 0);
    48 
    53 
    49     QGroupBox * gb = new QGroupBox(this);
    54     QGroupBox * gb = new QGroupBox(this);
    50     QVBoxLayout * gbl = new QVBoxLayout;
    55     QVBoxLayout * gbl = new QVBoxLayout;
    51 
    56 
    59     labelGameStats->setAlignment(Qt::AlignTop);
    64     labelGameStats->setAlignment(Qt::AlignTop);
    60     labelGameStats->setWordWrap(true);
    65     labelGameStats->setWordWrap(true);
    61     gbl->addWidget(l);
    66     gbl->addWidget(l);
    62     gbl->addWidget(labelGameStats);
    67     gbl->addWidget(labelGameStats);
    63     gb->setLayout(gbl);
    68     gb->setLayout(gbl);
    64     pageLayout->addWidget(gb, 1, 1, 1, 2);
    69     pageLayout->addWidget(gb, 1, 1);
    65 
    70 
    66     // graph
    71     // graph
    67     graphic = new FitGraphicsView(gb);
    72     graphic = new FitGraphicsView(gb);
    68     l = new QLabel(this);
    73     labelGraphTitle = new QLabel(this);
    69     l->setTextFormat(Qt::RichText);
    74     labelGraphTitle->setTextFormat(Qt::RichText);
    70     l->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
    75     labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
    71     l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    76     labelGraphTitle->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    72     gbl->addWidget(l);
    77     gbl->addWidget(labelGraphTitle);
    73     gbl->addWidget(graphic);
    78     gbl->addWidget(graphic);
    74     graphic->scale(1.0, -1.0);
    79     graphic->scale(1.0, -1.0);
    75     graphic->setBackgroundBrush(QBrush(Qt::black));
    80     graphic->setBackgroundBrush(QBrush(Qt::black));
    76 
    81 
    77     labelGameWin = new QLabel(this);
    82     labelGameWin = new QLabel(this);
   152     btnRestart->setVisible(visible);
   157     btnRestart->setVisible(visible);
   153 }
   158 }
   154 
   159 
   155 void PageGameStats::renderStats()
   160 void PageGameStats::renderStats()
   156 {
   161 {
   157     QGraphicsScene * scene = new QGraphicsScene();
   162 	graphic->show();
   158 
   163 	labelGraphTitle-> show();
   159     QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
   164 	if(defaultGraphTitle) {
   160     while (i != healthPoints.constEnd())
   165 		labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
   161     {
   166 	} else {
   162         quint32 c = i.key();
   167 		defaultGraphTitle = true;
   163         //QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
   168 	}
   164         QVector<quint32> hps = i.value();
   169 	// if not health data sent
   165 
   170 	if(healthPoints.size() == 0) {
   166         QPainterPath path;
   171 		labelGraphTitle->hide();
   167         if (hps.size())
   172 		graphic->hide();
   168             path.moveTo(0, hps[0]);
   173 	} else {
   169 
   174 		QGraphicsScene * scene = new QGraphicsScene();
   170         for(int t = 1; t < hps.size(); ++t)
   175 
   171             path.lineTo(t, hps[t]);
   176 		QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
   172 
   177 		while (i != healthPoints.constEnd())
   173         scene->addPath(path, QPen(c));
   178 		{
   174         ++i;
   179 			quint32 c = i.key();
   175     }
   180 			//QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
   176 
   181 			QVector<quint32> hps = i.value();
   177     graphic->setScene(scene);
   182 
   178     graphic->fitInView(graphic->sceneRect());
   183 			QPainterPath path;
       
   184 			if (hps.size())
       
   185 				path.moveTo(0, hps[0]);
       
   186 
       
   187 			for(int t = 1; t < hps.size(); ++t)
       
   188 				path.lineTo(t, hps[t]);
       
   189 
       
   190 			scene->addPath(path, QPen(c));
       
   191 			++i;
       
   192 		}
       
   193 
       
   194 		graphic->setScene(scene);
       
   195 		graphic->fitInView(graphic->sceneRect());
       
   196 	}
   179 }
   197 }
   180 
   198 
   181 void PageGameStats::GameStats(char type, const QString & info)
   199 void PageGameStats::GameStats(char type, const QString & info)
   182 {
   200 {
   183     switch(type)
   201     switch(type)
   213         {
   231         {
   214             int i = info.indexOf(' ');
   232             int i = info.indexOf(' ');
   215             quint32 clan = info.left(i).toInt();
   233             quint32 clan = info.left(i).toInt();
   216             quint32 hp = info.mid(i + 1).toUInt();
   234             quint32 hp = info.mid(i + 1).toUInt();
   217             healthPoints[clan].append(hp);
   235             healthPoints[clan].append(hp);
       
   236             break;
       
   237         }
       
   238         case 'g' :
       
   239         {
       
   240 			// TODO: change default picture or add change pic capability
       
   241 			defaultGraphTitle = false;
       
   242 			labelGraphTitle->setText("<br><h1><img src=\":/res/StatsR.png\"> " + info + "</h1>");
   218             break;
   243             break;
   219         }
   244         }
   220         case 'T':   // local team stats
   245         case 'T':   // local team stats
   221         {
   246         {
   222             //AddStatText("<p>local team: " + info + "</p>");
   247             //AddStatText("<p>local team: " + info + "</p>");
   230                     team.incWins(); // should draws count as wins?
   255                     team.incWins(); // should draws count as wins?
   231                 //team.SaveToFile(); // don't save yet
   256                 //team.SaveToFile(); // don't save yet
   232             }
   257             }
   233             break;
   258             break;
   234         }
   259         }
   235 
   260 		case 'p' :
       
   261         {
       
   262             kindOfPoints = info;
       
   263             break;
       
   264         }
   236         case 'P' :
   265         case 'P' :
   237         {
   266         {
   238             int i = info.indexOf(' ');
   267             int i = info.indexOf(' ');
   239             playerPosition++;
   268             playerPosition++;
   240             QString color = info.left(i);
   269             QString color = info.left(i);
   267                     image = "<img src=\":/res/StatsMedal4.png\">";
   296                     image = "<img src=\":/res/StatsMedal4.png\">";
   268                     break;
   297                     break;
   269             }
   298             }
   270 
   299 
   271             QString message;
   300             QString message;
   272             QString killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills);
   301             QString killstring;
       
   302             if(kindOfPoints.compare("") == 0) {
       
   303 				killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills);
       
   304 			} else {
       
   305 				killstring = PageGameStats::tr("(%1 %2)", "", kills).arg(kills).arg(kindOfPoints);
       
   306 				kindOfPoints = QString("");
       
   307 			}
   273 
   308 
   274             message = QString("<p><h2>%1 %2. <font color=\"%4\">%3</font> ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "</h2></p>";
   309             message = QString("<p><h2>%1 %2. <font color=\"%4\">%3</font> ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "</h2></p>";
   275 
   310 
   276             labelGameRank->setText(labelGameRank->text() + message);
   311             labelGameRank->setText(labelGameRank->text() + message);
   277             break;
   312             break;
   298             int num = info.left(i).toInt();
   333             int num = info.left(i).toInt();
   299             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>";
   334             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>";
   300             AddStatText(message);
   335             AddStatText(message);
   301             break;
   336             break;
   302         }
   337         }
       
   338         case 'c' :
       
   339         {
       
   340             QString message = "<p><img src=\":/res/StatsCustomAchievement.png\"> "+info+" </p>";
       
   341             AddStatText(message);
       
   342             break;
       
   343         }
   303 
   344 
   304     }
   345     }
   305 }
   346 }