# HG changeset patch # User koda # Date 1304956839 -7200 # Node ID 78138ae93820fc150ac1face731886939d808152 # Parent e1a5f4d5d86a96d51c2d1d166a6b9cff9b71799e some headers cleanup and rename of stats and playrecord pages for consistency diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/AbstractPage.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/AbstractPage.h Mon May 09 18:00:39 2011 +0200 @@ -0,0 +1,123 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef ABSTRACTPAGE_H +#define ABSTRACTPAGE_H + +#include +#include +#include +#include +#include +#include + +class QPushButton; +class QGroupBox; +class QComboBox; +class QLabel; +class QToolBox; +class QLineEdit; +class QListWidget; +class QCheckBox; +class QSpinBox; +class QTextEdit; +class QRadioButton; +class QTableView; +class QTextBrowser; +class QTableWidget; +class QAction; +class QDataWidgetMapper; +class QAbstractItemModel; +class QSettings; +class QSlider; + +class AbstractPage : public QWidget +{ + Q_OBJECT + + public: + + protected: + AbstractPage(QWidget* parent = 0) { + Q_UNUSED(parent); + + font14 = new QFont("MS Shell Dlg", 14); + //setFocusPolicy(Qt::StrongFocus); + } + virtual ~AbstractPage() {}; + + QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, bool iconed = false) { + QPushButton* butt = new QPushButton(this); + if (!iconed) { + butt->setFont(*font14); + butt->setText(btname); + //butt->setStyleSheet("background-color: #0d0544"); + } else { + const QIcon& lp=QIcon(btname); + QSize sz = lp.actualSize(QSize(65535, 65535)); + butt->setIcon(lp); + butt->setFixedSize(sz); + butt->setIconSize(sz); + butt->setFlat(true); + butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + } + grid->addWidget(butt, wy, wx); + return butt; + }; + + QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, int rowSpan, int columnSpan, bool iconed = false) { + QPushButton* butt = new QPushButton(this); + if (!iconed) { + butt->setFont(*font14); + butt->setText(btname); + } else { + const QIcon& lp=QIcon(btname); + QSize sz = lp.actualSize(QSize(65535, 65535)); + butt->setIcon(lp); + butt->setFixedSize(sz); + butt->setIconSize(sz); + butt->setFlat(true); + butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + } + grid->addWidget(butt, wy, wx, rowSpan, columnSpan); + return butt; + }; + + QPushButton* addButton(QString btname, QBoxLayout* box, int where, bool iconed = false) { + QPushButton* butt = new QPushButton(this); + if (!iconed) { + butt->setFont(*font14); + butt->setText(btname); + } else { + const QIcon& lp=QIcon(btname); + QSize sz = lp.actualSize(QSize(65535, 65535)); + butt->setIcon(lp); + butt->setFixedSize(sz); + butt->setIconSize(sz); + butt->setFlat(true); + butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + } + box->addWidget(butt, where); + return butt; + }; + + QFont * font14; +}; + +#endif + diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/CMakeLists.txt --- a/QTfrontend/CMakeLists.txt Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/CMakeLists.txt Mon May 09 18:00:39 2011 +0200 @@ -74,6 +74,8 @@ pageroomslist.cpp pageconnecting.cpp pagescheme.cpp + pagegamestats.cpp + pageplayrecord.cpp pageadmin.cpp pagenettype.cpp pagedrawmap.cpp @@ -95,14 +97,12 @@ chatwidget.cpp binds.cpp SDLs.cpp - playrecordpage.cpp ${CMAKE_CURRENT_BINARY_DIR}/hwconsts.cpp selectWeapon.cpp itemNum.cpp input_ip.cpp igbox.cpp weaponItem.cpp - statsPage.cpp misc.cpp ammoSchemeModel.cpp togglebutton.cpp @@ -139,7 +139,7 @@ vertScrollArea.h gameuiconfig.h gamecfgwidget.h - pages.h + AbstractPage.h pagenet.h pagemultiplayer.h pagenetserver.h @@ -157,9 +157,11 @@ pagenetgame.h pageeditteam.h pageroomslist.h + pagegamestats.h pageadmin.h pagescheme.h pageselectweapon.h + pageplayrecord.h SquareLabel.h hedgehogerWidget.h hwmap.h @@ -176,13 +178,11 @@ netserverslist.h chatwidget.h SDLs.h - playrecordpage.h selectWeapon.h itemNum.h input_ip.h igbox.h weaponItem.h - statsPage.h misc.h ammoSchemeModel.h togglebutton.h diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/hwform.cpp Mon May 09 18:00:39 2011 +0200 @@ -63,14 +63,14 @@ #include "pagenetserver.h" #include "pagedrawmap.h" #include "pagenettype.h" -#include "statsPage.h" +#include "pagegamestats.h" #include "hwconsts.h" #include "newnetclient.h" #include "gamecfgwidget.h" #include "netserverslist.h" #include "netudpserver.h" #include "chatwidget.h" -#include "playrecordpage.h" +#include "pageplayrecord.h" #include "input_ip.h" #include "ammoSchemeModel.h" #include "bgwidget.h" diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageadmin.h --- a/QTfrontend/pageadmin.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pageadmin.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_ADMIN_H #define PAGE_ADMIN_H -#include "pages.h" +#include "AbstractPage.h" class PageAdmin : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagecampaign.h --- a/QTfrontend/pagecampaign.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagecampaign.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_CAMPAIGN_H #define PAGE_CAMPAIGN_H -#include "pages.h" +#include "AbstractPage.h" class PageCampaign : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageconnecting.h --- a/QTfrontend/pageconnecting.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pageconnecting.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_CONNECTING_H #define PAGE_CONNECTING_H -#include "pages.h" +#include "AbstractPage.h" class PageConnecting : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagedrawmap.h --- a/QTfrontend/pagedrawmap.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagedrawmap.h Mon May 09 18:00:39 2011 +0200 @@ -16,11 +16,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ - #ifndef PAGE_DRAWMAP_H #define PAGE_DRAWMAP_H -#include "pages.h" +#include "AbstractPage.h" class DrawMapWidget; diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageeditteam.h --- a/QTfrontend/pageeditteam.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pageeditteam.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,9 @@ #ifndef PAGE_EDITTEAM_H #define PAGE_EDITTEAM_H -#include "pages.h" +#include "AbstractPage.h" +#include "binds.h" +#include "SDLs.h" class SquareLabel; diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagegamestats.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/pagegamestats.cpp Mon May 09 18:00:39 2011 +0200 @@ -0,0 +1,252 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2010-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "pagegamestats.h" +#include "team.h" + +FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent) +{ + +} + +void FitGraphicsView::resizeEvent(QResizeEvent * event) +{ + Q_UNUSED(event); + + fitInView(sceneRect()); +} + +PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent) +{ + QGridLayout * pageLayout = new QGridLayout(this); + pageLayout->setSpacing(20); + pageLayout->setColumnStretch(0, 1); + pageLayout->setColumnStretch(1, 1); + + BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); + BtnBack->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + QGroupBox * gb = new QGroupBox(this); + QVBoxLayout * gbl = new QVBoxLayout; + + // details + labelGameStats = new QLabel(this); + QLabel * l = new QLabel(this); + l->setTextFormat(Qt::RichText); + l->setText("

" + PageGameStats::tr("Details") + "

"); + l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + labelGameStats->setTextFormat(Qt::RichText); + labelGameStats->setAlignment(Qt::AlignTop); + labelGameStats->setWordWrap(true); + gbl->addWidget(l); + gbl->addWidget(labelGameStats); + gb->setLayout(gbl); + pageLayout->addWidget(gb, 1, 1); + + // graph + graphic = new FitGraphicsView(gb); + l = new QLabel(this); + l->setTextFormat(Qt::RichText); + l->setText("

" + PageGameStats::tr("Health graph") + "

"); + l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + gbl->addWidget(l); + gbl->addWidget(graphic); + graphic->scale(1.0, -1.0); + graphic->setBackgroundBrush(QBrush(Qt::black)); + + labelGameWin = new QLabel(this); + labelGameWin->setTextFormat(Qt::RichText); + pageLayout->addWidget(labelGameWin, 0, 0, 1, 2); + + // ranking box + gb = new QGroupBox(this); + gbl = new QVBoxLayout; + labelGameRank = new QLabel(gb); + l = new QLabel(this); + l->setTextFormat(Qt::RichText); + l->setText("

" + PageGameStats::tr("Ranking") + "

"); + l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + gbl->addWidget(l); + gbl->addWidget(labelGameRank); + gb->setLayout(gbl); + + labelGameRank->setTextFormat(Qt::RichText); + labelGameRank->setAlignment(Qt::AlignTop); + pageLayout->addWidget(gb, 1, 0); +} + +void PageGameStats::AddStatText(const QString & msg) +{ + labelGameStats->setText(labelGameStats->text() + msg); +} + +void PageGameStats::clear() +{ + labelGameStats->setText(""); + healthPoints.clear(); + labelGameRank->setText(""); + playerPosition = 0; + lastColor = 0; +} + +void PageGameStats::renderStats() +{ + QGraphicsScene * scene = new QGraphicsScene(); + + QMap >::const_iterator i = healthPoints.constBegin(); + while (i != healthPoints.constEnd()) + { + quint32 c = i.key(); + QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); + QVector hps = i.value(); + + QPainterPath path; + if (hps.size()) + path.moveTo(0, hps[0]); + + for(int t = 1; t < hps.size(); ++t) + path.lineTo(t, hps[t]); + + scene->addPath(path, QPen(c)); + ++i; + } + + graphic->setScene(scene); + graphic->fitInView(graphic->sceneRect()); +} + +void PageGameStats::GameStats(char type, const QString & info) +{ + switch(type) { + case 'r' : { + labelGameWin->setText(QString("

%1

").arg(info)); + break; + } + case 'D' : { + int i = info.indexOf(' '); + QString message = "

" + PageGameStats::tr("The best shot award was won by %1 with %2 pts.").arg(info.mid(i + 1), info.left(i)) + "

"; + AddStatText(message); + break; + } + case 'k' : { + int i = info.indexOf(' '); + int num = info.left(i).toInt(); + QString message = "

" + PageGameStats::tr("The best killer is %1 with %2 kills in a turn.", "", num).arg(info.mid(i + 1), info.left(i)) + "

"; + AddStatText(message); + break; + } + case 'K' : { + int num = info.toInt(); + QString message = "

" + PageGameStats::tr("A total of %1 hedgehog(s) were killed during this round.", "", num).arg(num) + "

"; + AddStatText(message); + break; + } + case 'H' : { + int i = info.indexOf(' '); + quint32 clan = info.left(i).toInt(); + quint32 hp = info.mid(i + 1).toUInt(); + healthPoints[clan].append(hp); + break; + } + case 'T': { // local team stats + //AddStatText("

local team: " + info + "

"); + QStringList infol = info.split(":"); + HWTeam team(infol[0]); + if(team.FileExists()) // do some better test to avoid influence from scripted/predefined teams? + { + team.LoadFromFile(); + team.Rounds++; + if(infol[1].toInt() > 0) // might require some better test for winning condition (or changed flag) ... WIP! + team.Wins++; // should draws count as wins? + //team.SaveToFile(); // don't save yet + } + break; + } + + case 'P' : { + int i = info.indexOf(' '); + playerPosition++; + QString color = info.left(i); + quint32 c = color.toInt(); + QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); + + QString playerinfo = info.mid(i + 1); + + i = playerinfo.indexOf(' '); + + int kills = playerinfo.left(i).toInt(); + QString playername = playerinfo.mid(i + 1); + QString image; + + if (lastColor == c) playerPosition--; + lastColor = c; + + switch (playerPosition) + { + case 1: + image = ""; + break; + case 2: + image = ""; + break; + case 3: + image = ""; + break; + default: + image = ""; + break; + } + + QString message; + QString killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills); + + message = QString("

%1 %2. %3 ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "

"; + + labelGameRank->setText(labelGameRank->text() + message); + break; + } + case 's' : { + int i = info.indexOf(' '); + int num = info.left(i).toInt(); + QString message = "

" + PageGameStats::tr("%1 thought it's good to shoot his own hedgehogs with %2 pts.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; + AddStatText(message); + break; + } + case 'S' : { + int i = info.indexOf(' '); + int num = info.left(i).toInt(); + QString message = "

" + PageGameStats::tr("%1 killed %2 of his own hedgehogs.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; + AddStatText(message); + break; + } + case 'B' : { + int i = info.indexOf(' '); + int num = info.left(i).toInt(); + QString message = "

" + PageGameStats::tr("%1 was scared and skipped turn %2 times.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; + AddStatText(message); + break; + } + + } +} diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagegamestats.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/pagegamestats.h Mon May 09 18:00:39 2011 +0200 @@ -0,0 +1,65 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2010-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef STATSPAGE_H +#define STATSPAGE_H + +#include +#include +#include + +#include "AbstractPage.h" + +class FitGraphicsView : public QGraphicsView +{ + Q_OBJECT + +public: + FitGraphicsView(QWidget* parent = 0); + +protected: + void resizeEvent(QResizeEvent * event); +}; + +class PageGameStats : public AbstractPage +{ + Q_OBJECT + +public: + PageGameStats(QWidget* parent = 0); + + QPushButton *BtnBack; + QLabel *labelGameStats; + QLabel *labelGameWin; + QLabel *labelGameRank; + FitGraphicsView * graphic; + +public slots: + void GameStats(char type, const QString & info); + void clear(); + void renderStats(); + +private: + void AddStatText(const QString & msg); + + QMap > healthPoints; + unsigned int playerPosition; + quint32 lastColor; +}; + +#endif // STATSPAGE_H diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageinfo.h --- a/QTfrontend/pageinfo.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pageinfo.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_INFO_H #define PAGE_INFO_H -#include "pages.h" +#include "AbstractPage.h" class About; diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageingame.h --- a/QTfrontend/pageingame.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pageingame.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_INGAME_H #define PAGE_INGAME_H -#include "pages.h" +#include "AbstractPage.h" class PageInGame : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagemain.cpp --- a/QTfrontend/pagemain.cpp Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagemain.cpp Mon May 09 18:00:39 2011 +0200 @@ -23,6 +23,7 @@ #include "pagemain.h" #include "hwconsts.h" +#include "hwform.h" PageMain::PageMain(QWidget* parent) : AbstractPage(parent) diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagemain.h --- a/QTfrontend/pagemain.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagemain.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_MAIN_H #define PAGE_MAIN_H -#include "pages.h" +#include "AbstractPage.h" class PageMain : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagemultiplayer.h --- a/QTfrontend/pagemultiplayer.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagemultiplayer.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_MULTIPLAYER_H #define PAGE_MULTIPLAYER_H -#include "pages.h" +#include "AbstractPage.h" class GameCFGWidget; class TeamSelWidget; diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagenet.h --- a/QTfrontend/pagenet.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagenet.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_NET_H #define PAGE_NET_H -#include "pages.h" +#include "AbstractPage.h" class PageNet : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagenetgame.h --- a/QTfrontend/pagenetgame.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagenetgame.h Mon May 09 18:00:39 2011 +0200 @@ -19,8 +19,12 @@ #ifndef PAGE_NETGAME_H #define PAGE_NETGAME_H -#include "pages.h" +#include "AbstractPage.h" +#include "SDLs.h" + class HWChatWidget; +class TeamSelWidget; +class GameCFGWidget; class PageNetGame : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagenetserver.h --- a/QTfrontend/pagenetserver.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagenetserver.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_NETSERVER_H #define PAGE_NETSERVER_H -#include "pages.h" +#include "AbstractPage.h" class PageNetServer : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagenettype.h --- a/QTfrontend/pagenettype.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagenettype.h Mon May 09 18:00:39 2011 +0200 @@ -19,8 +19,7 @@ #ifndef PAGE_NETTYPE_H #define PAGE_NETTYPE_H -#include "pages.h" - +#include "AbstractPage.h" class PageNetType : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageoptions.h --- a/QTfrontend/pageoptions.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pageoptions.h Mon May 09 18:00:39 2011 +0200 @@ -19,9 +19,10 @@ #ifndef PAGE_OPTIONS_H #define PAGE_OPTIONS_H -#include "pages.h" +#include "AbstractPage.h" class FPSEdit; +class IconedGroupBox; class PageOptions : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageplayrecord.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/pageplayrecord.cpp Mon May 09 18:00:39 2011 +0200 @@ -0,0 +1,152 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hwconsts.h" +#include "pageplayrecord.h" + +PagePlayDemo::PagePlayDemo(QWidget* parent) : AbstractPage(parent) +{ + QFont * font14 = new QFont("MS Shell Dlg", 14); + QGridLayout * pageLayout = new QGridLayout(this); + pageLayout->setColumnStretch(0, 1); + pageLayout->setColumnStretch(1, 2); + pageLayout->setColumnStretch(2, 1); + pageLayout->setRowStretch(2, 100); + + BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); + + BtnPlayDemo = new QPushButton(this); + BtnPlayDemo->setFont(*font14); + BtnPlayDemo->setText(QPushButton::tr("Play demo")); + pageLayout->addWidget(BtnPlayDemo, 3, 2); + + BtnRenameRecord = new QPushButton(this); + BtnRenameRecord->setText(QPushButton::tr("Rename")); + pageLayout->addWidget(BtnRenameRecord, 0, 2); + + BtnRemoveRecord = new QPushButton(this); + BtnRemoveRecord->setText(QPushButton::tr("Delete")); + pageLayout->addWidget(BtnRemoveRecord, 1, 2); + + DemosList = new QListWidget(this); + DemosList->setGeometry(QRect(170, 10, 311, 311)); + pageLayout->addWidget(DemosList, 0, 1, 3, 1); + + connect(BtnRenameRecord, SIGNAL(clicked()), this, SLOT(renameRecord())); + connect(BtnRemoveRecord, SIGNAL(clicked()), this, SLOT(removeRecord())); +} + +void PagePlayDemo::FillFromDir(RecordType rectype) +{ + QDir dir; + QString extension; + + recType = rectype; + + dir.cd(cfgdir->absolutePath()); + if (rectype == RT_Demo) + { + dir.cd("Demos"); + extension = "hwd"; + BtnPlayDemo->setText(QPushButton::tr("Play demo")); + } else + { + dir.cd("Saves"); + extension = "hws"; + BtnPlayDemo->setText(QPushButton::tr("Load")); + } + dir.setFilter(QDir::Files); + + QStringList sl = dir.entryList(QStringList(QString("*.%2.%1").arg(extension, *cProtoVer))); + sl.replaceInStrings(QRegExp(QString("^(.*)\\.%2\\.%1$").arg(extension, *cProtoVer)), "\\1"); + + DemosList->clear(); + DemosList->addItems(sl); + + for (int i = 0; i < DemosList->count(); ++i) + { + DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%3.%2").arg(sl[i], extension, *cProtoVer))); + DemosList->item(i)->setIcon(recType == RT_Demo ? QIcon(":/res/file_demo.png") : QIcon(":/res/file_save.png")); + } +} + +void PagePlayDemo::renameRecord() +{ + QListWidgetItem * curritem = DemosList->currentItem(); + if (!curritem) + { + QMessageBox::critical(this, + tr("Error"), + tr("Please select record from the list"), + tr("OK")); + return ; + } + QFile rfile(curritem->data(Qt::UserRole).toString()); + + QFileInfo finfo(rfile); + + bool ok; + + QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName().replace("." + *cProtoVer, ""), &ok); + + if(ok && newname.size()) + { + QString newfullname = QString("%1/%2.%3.%4") + .arg(finfo.absolutePath()) + .arg(newname) + .arg(*cProtoVer) + .arg(finfo.suffix()); + + ok = rfile.rename(newfullname); + if(!ok) + QMessageBox::critical(this, tr("Error"), tr("Cannot rename to") + newfullname); + else + FillFromDir(recType); + } +} + +void PagePlayDemo::removeRecord() +{ + QListWidgetItem * curritem = DemosList->currentItem(); + if (!curritem) + { + QMessageBox::critical(this, + tr("Error"), + tr("Please select record from the list"), + tr("OK")); + return ; + } + QFile rfile(curritem->data(Qt::UserRole).toString()); + + bool ok; + + ok = rfile.remove(); + if(!ok) + QMessageBox::critical(this, tr("Error"), tr("Cannot delete file")); + else + FillFromDir(recType); +} diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageplayrecord.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/pageplayrecord.h Mon May 09 18:00:39 2011 +0200 @@ -0,0 +1,58 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PLAYRECORDPAGE_H +#define PLAYRECORDPAGE_H + +#include + +#include "AbstractPage.h" + +class QPushButton; +class QListWidget; + +class PagePlayDemo : public AbstractPage +{ + Q_OBJECT + +public: + enum RecordType { + RT_Demo, + RT_Save + }; + + PagePlayDemo(QWidget* parent = 0); + + void FillFromDir(RecordType rectype); + + QPushButton *BtnBack; + QPushButton *BtnPlayDemo; + QPushButton *BtnRenameRecord; + QPushButton *BtnRemoveRecord; + QListWidget *DemosList; + +private: + RecordType recType; + +private slots: + void renameRecord(); + void removeRecord(); +}; + + +#endif // PLAYRECORDPAGE_H diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageroomslist.h --- a/QTfrontend/pageroomslist.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pageroomslist.h Mon May 09 18:00:39 2011 +0200 @@ -1,10 +1,29 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ #ifndef PAGE_ROOMLIST_H #define PAGE_ROOMLIST_H -#include "pages.h" +#include "AbstractPage.h" +#include "SDLs.h" class HWChatWidget; +class AmmoSchemeModel; class PageRoomsList : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pages.h --- a/QTfrontend/pages.h Mon May 09 16:56:29 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGES_H -#define PAGES_H - -#include -#include -#include -#include -#include - -#include "binds.h" -#include "hwform.h" -#include "mapContainer.h" -#include "togglebutton.h" - -class QPushButton; -class QGroupBox; -class QComboBox; -class QLabel; -class QToolBox; -class QLineEdit; -class QListWidget; -class QCheckBox; -class QSpinBox; -class QTextEdit; -class QRadioButton; -class QTableView; -class QTextBrowser; -class QTableWidget; -class QAction; -class QDataWidgetMapper; -class QAbstractItemModel; -class QSettings; -class QSlider; - -class AbstractPage : public QWidget -{ - Q_OBJECT - - public: - - protected: - AbstractPage(QWidget* parent = 0) { - Q_UNUSED(parent); - - font14 = new QFont("MS Shell Dlg", 14); - //setFocusPolicy(Qt::StrongFocus); - } - virtual ~AbstractPage() {}; - - QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, bool iconed = false) { - QPushButton* butt = new QPushButton(this); - if (!iconed) { - butt->setFont(*font14); - butt->setText(btname); - //butt->setStyleSheet("background-color: #0d0544"); - } else { - const QIcon& lp=QIcon(btname); - QSize sz = lp.actualSize(QSize(65535, 65535)); - butt->setIcon(lp); - butt->setFixedSize(sz); - butt->setIconSize(sz); - butt->setFlat(true); - butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - } - grid->addWidget(butt, wy, wx); - return butt; - }; - - QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, int rowSpan, int columnSpan, bool iconed = false) { - QPushButton* butt = new QPushButton(this); - if (!iconed) { - butt->setFont(*font14); - butt->setText(btname); - } else { - const QIcon& lp=QIcon(btname); - QSize sz = lp.actualSize(QSize(65535, 65535)); - butt->setIcon(lp); - butt->setFixedSize(sz); - butt->setIconSize(sz); - butt->setFlat(true); - butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - } - grid->addWidget(butt, wy, wx, rowSpan, columnSpan); - return butt; - }; - - QPushButton* addButton(QString btname, QBoxLayout* box, int where, bool iconed = false) { - QPushButton* butt = new QPushButton(this); - if (!iconed) { - butt->setFont(*font14); - butt->setText(btname); - } else { - const QIcon& lp=QIcon(btname); - QSize sz = lp.actualSize(QSize(65535, 65535)); - butt->setIcon(lp); - butt->setFixedSize(sz); - butt->setIconSize(sz); - butt->setFlat(true); - butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - } - box->addWidget(butt, where); - return butt; - }; - - QFont * font14; -}; - -#endif // PAGES_H diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagescheme.h --- a/QTfrontend/pagescheme.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagescheme.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,8 @@ #ifndef PAGE_SCHEME_H #define PAGE_SCHEME_H -#include "pages.h" +#include "AbstractPage.h" +#include "togglebutton.h" class FreqSpinBox; diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pageselectweapon.h --- a/QTfrontend/pageselectweapon.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pageselectweapon.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_SELECTWEAPON_H #define PAGE_SELECTWEAPON_H -#include "pages.h" +#include "AbstractPage.h" class SelWeaponWidget; diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagesingleplayer.h --- a/QTfrontend/pagesingleplayer.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagesingleplayer.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_SINGLE_PLAYER_H #define PAGE_SINGLE_PLAYER_H -#include "pages.h" +#include "AbstractPage.h" class GameCFGWidget; diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/pagetraining.h --- a/QTfrontend/pagetraining.h Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/pagetraining.h Mon May 09 18:00:39 2011 +0200 @@ -19,7 +19,7 @@ #ifndef PAGE_TRAINING_H #define PAGE_TRAINING_H -#include "pages.h" +#include "AbstractPage.h" class PageTraining : public AbstractPage { diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/playrecordpage.cpp --- a/QTfrontend/playrecordpage.cpp Mon May 09 16:56:29 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hwconsts.h" -#include "playrecordpage.h" - -PagePlayDemo::PagePlayDemo(QWidget* parent) : AbstractPage(parent) -{ - QFont * font14 = new QFont("MS Shell Dlg", 14); - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 2); - pageLayout->setColumnStretch(2, 1); - pageLayout->setRowStretch(2, 100); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); - - BtnPlayDemo = new QPushButton(this); - BtnPlayDemo->setFont(*font14); - BtnPlayDemo->setText(QPushButton::tr("Play demo")); - pageLayout->addWidget(BtnPlayDemo, 3, 2); - - BtnRenameRecord = new QPushButton(this); - BtnRenameRecord->setText(QPushButton::tr("Rename")); - pageLayout->addWidget(BtnRenameRecord, 0, 2); - - BtnRemoveRecord = new QPushButton(this); - BtnRemoveRecord->setText(QPushButton::tr("Delete")); - pageLayout->addWidget(BtnRemoveRecord, 1, 2); - - DemosList = new QListWidget(this); - DemosList->setGeometry(QRect(170, 10, 311, 311)); - pageLayout->addWidget(DemosList, 0, 1, 3, 1); - - connect(BtnRenameRecord, SIGNAL(clicked()), this, SLOT(renameRecord())); - connect(BtnRemoveRecord, SIGNAL(clicked()), this, SLOT(removeRecord())); -} - -void PagePlayDemo::FillFromDir(RecordType rectype) -{ - QDir dir; - QString extension; - - recType = rectype; - - dir.cd(cfgdir->absolutePath()); - if (rectype == RT_Demo) - { - dir.cd("Demos"); - extension = "hwd"; - BtnPlayDemo->setText(QPushButton::tr("Play demo")); - } else - { - dir.cd("Saves"); - extension = "hws"; - BtnPlayDemo->setText(QPushButton::tr("Load")); - } - dir.setFilter(QDir::Files); - - QStringList sl = dir.entryList(QStringList(QString("*.%2.%1").arg(extension, *cProtoVer))); - sl.replaceInStrings(QRegExp(QString("^(.*)\\.%2\\.%1$").arg(extension, *cProtoVer)), "\\1"); - - DemosList->clear(); - DemosList->addItems(sl); - - for (int i = 0; i < DemosList->count(); ++i) - { - DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%3.%2").arg(sl[i], extension, *cProtoVer))); - DemosList->item(i)->setIcon(recType == RT_Demo ? QIcon(":/res/file_demo.png") : QIcon(":/res/file_save.png")); - } -} - -void PagePlayDemo::renameRecord() -{ - QListWidgetItem * curritem = DemosList->currentItem(); - if (!curritem) - { - QMessageBox::critical(this, - tr("Error"), - tr("Please select record from the list"), - tr("OK")); - return ; - } - QFile rfile(curritem->data(Qt::UserRole).toString()); - - QFileInfo finfo(rfile); - - bool ok; - - QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName().replace("." + *cProtoVer, ""), &ok); - - if(ok && newname.size()) - { - QString newfullname = QString("%1/%2.%3.%4") - .arg(finfo.absolutePath()) - .arg(newname) - .arg(*cProtoVer) - .arg(finfo.suffix()); - - ok = rfile.rename(newfullname); - if(!ok) - QMessageBox::critical(this, tr("Error"), tr("Cannot rename to") + newfullname); - else - FillFromDir(recType); - } -} - -void PagePlayDemo::removeRecord() -{ - QListWidgetItem * curritem = DemosList->currentItem(); - if (!curritem) - { - QMessageBox::critical(this, - tr("Error"), - tr("Please select record from the list"), - tr("OK")); - return ; - } - QFile rfile(curritem->data(Qt::UserRole).toString()); - - bool ok; - - ok = rfile.remove(); - if(!ok) - QMessageBox::critical(this, tr("Error"), tr("Cannot delete file")); - else - FillFromDir(recType); -} diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/playrecordpage.h --- a/QTfrontend/playrecordpage.h Mon May 09 16:56:29 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PLAYRECORDPAGE_H -#define PLAYRECORDPAGE_H - -#include - -#include "pages.h" - -class QPushButton; -class QListWidget; - -class PagePlayDemo : public AbstractPage -{ - Q_OBJECT - -public: - enum RecordType { - RT_Demo, - RT_Save - }; - - PagePlayDemo(QWidget* parent = 0); - - void FillFromDir(RecordType rectype); - - QPushButton *BtnBack; - QPushButton *BtnPlayDemo; - QPushButton *BtnRenameRecord; - QPushButton *BtnRemoveRecord; - QListWidget *DemosList; - -private: - RecordType recType; - -private slots: - void renameRecord(); - void removeRecord(); -}; - - -#endif // PLAYRECORDPAGE_H diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/statsPage.cpp --- a/QTfrontend/statsPage.cpp Mon May 09 16:56:29 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,251 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2010-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include "statsPage.h" -#include "team.h" - -FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent) -{ - -} - -void FitGraphicsView::resizeEvent(QResizeEvent * event) -{ - Q_UNUSED(event); - - fitInView(sceneRect()); -} - -PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setSpacing(20); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 1); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); - BtnBack->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - - QGroupBox * gb = new QGroupBox(this); - QVBoxLayout * gbl = new QVBoxLayout; - - // details - labelGameStats = new QLabel(this); - QLabel * l = new QLabel(this); - l->setTextFormat(Qt::RichText); - l->setText("

" + PageGameStats::tr("Details") + "

"); - l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - labelGameStats->setTextFormat(Qt::RichText); - labelGameStats->setAlignment(Qt::AlignTop); - labelGameStats->setWordWrap(true); - gbl->addWidget(l); - gbl->addWidget(labelGameStats); - gb->setLayout(gbl); - pageLayout->addWidget(gb, 1, 1); - - // graph - graphic = new FitGraphicsView(gb); - l = new QLabel(this); - l->setTextFormat(Qt::RichText); - l->setText("

" + PageGameStats::tr("Health graph") + "

"); - l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - gbl->addWidget(l); - gbl->addWidget(graphic); - graphic->scale(1.0, -1.0); - graphic->setBackgroundBrush(QBrush(Qt::black)); - - labelGameWin = new QLabel(this); - labelGameWin->setTextFormat(Qt::RichText); - pageLayout->addWidget(labelGameWin, 0, 0, 1, 2); - - // ranking box - gb = new QGroupBox(this); - gbl = new QVBoxLayout; - labelGameRank = new QLabel(gb); - l = new QLabel(this); - l->setTextFormat(Qt::RichText); - l->setText("

" + PageGameStats::tr("Ranking") + "

"); - l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - gbl->addWidget(l); - gbl->addWidget(labelGameRank); - gb->setLayout(gbl); - - labelGameRank->setTextFormat(Qt::RichText); - labelGameRank->setAlignment(Qt::AlignTop); - pageLayout->addWidget(gb, 1, 0); -} - -void PageGameStats::AddStatText(const QString & msg) -{ - labelGameStats->setText(labelGameStats->text() + msg); -} - -void PageGameStats::clear() -{ - labelGameStats->setText(""); - healthPoints.clear(); - labelGameRank->setText(""); - playerPosition = 0; - lastColor = 0; -} - -void PageGameStats::renderStats() -{ - QGraphicsScene * scene = new QGraphicsScene(); - - QMap >::const_iterator i = healthPoints.constBegin(); - while (i != healthPoints.constEnd()) - { - quint32 c = i.key(); - QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); - QVector hps = i.value(); - - QPainterPath path; - if (hps.size()) - path.moveTo(0, hps[0]); - - for(int t = 1; t < hps.size(); ++t) - path.lineTo(t, hps[t]); - - scene->addPath(path, QPen(c)); - ++i; - } - - graphic->setScene(scene); - graphic->fitInView(graphic->sceneRect()); -} - -void PageGameStats::GameStats(char type, const QString & info) -{ - switch(type) { - case 'r' : { - labelGameWin->setText(QString("

%1

").arg(info)); - break; - } - case 'D' : { - int i = info.indexOf(' '); - QString message = "

" + PageGameStats::tr("The best shot award was won by %1 with %2 pts.").arg(info.mid(i + 1), info.left(i)) + "

"; - AddStatText(message); - break; - } - case 'k' : { - int i = info.indexOf(' '); - int num = info.left(i).toInt(); - QString message = "

" + PageGameStats::tr("The best killer is %1 with %2 kills in a turn.", "", num).arg(info.mid(i + 1), info.left(i)) + "

"; - AddStatText(message); - break; - } - case 'K' : { - int num = info.toInt(); - QString message = "

" + PageGameStats::tr("A total of %1 hedgehog(s) were killed during this round.", "", num).arg(num) + "

"; - AddStatText(message); - break; - } - case 'H' : { - int i = info.indexOf(' '); - quint32 clan = info.left(i).toInt(); - quint32 hp = info.mid(i + 1).toUInt(); - healthPoints[clan].append(hp); - break; - } - case 'T': { // local team stats - //AddStatText("

local team: " + info + "

"); - QStringList infol = info.split(":"); - HWTeam team(infol[0]); - if(team.FileExists()) // do some better test to avoid influence from scripted/predefined teams? - { - team.LoadFromFile(); - team.Rounds++; - if(infol[1].toInt() > 0) // might require some better test for winning condition (or changed flag) ... WIP! - team.Wins++; // should draws count as wins? - //team.SaveToFile(); // don't save yet - } - break; - } - - case 'P' : { - int i = info.indexOf(' '); - playerPosition++; - QString color = info.left(i); - quint32 c = color.toInt(); - QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); - - QString playerinfo = info.mid(i + 1); - - i = playerinfo.indexOf(' '); - - int kills = playerinfo.left(i).toInt(); - QString playername = playerinfo.mid(i + 1); - QString image; - - if (lastColor == c) playerPosition--; - lastColor = c; - - switch (playerPosition) - { - case 1: - image = ""; - break; - case 2: - image = ""; - break; - case 3: - image = ""; - break; - default: - image = ""; - break; - } - - QString message; - QString killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills); - - message = QString("

%1 %2. %3 ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "

"; - - labelGameRank->setText(labelGameRank->text() + message); - break; - } - case 's' : { - int i = info.indexOf(' '); - int num = info.left(i).toInt(); - QString message = "

" + PageGameStats::tr("%1 thought it's good to shoot his own hedgehogs with %2 pts.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; - AddStatText(message); - break; - } - case 'S' : { - int i = info.indexOf(' '); - int num = info.left(i).toInt(); - QString message = "

" + PageGameStats::tr("%1 killed %2 of his own hedgehogs.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; - AddStatText(message); - break; - } - case 'B' : { - int i = info.indexOf(' '); - int num = info.left(i).toInt(); - QString message = "

" + PageGameStats::tr("%1 was scared and skipped turn %2 times.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; - AddStatText(message); - break; - } - - } -} diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/statsPage.h --- a/QTfrontend/statsPage.h Mon May 09 16:56:29 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2010-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef STATSPAGE_H -#define STATSPAGE_H - -#include -#include -#include -#include "pages.h" - -class FitGraphicsView : public QGraphicsView -{ - Q_OBJECT - -public: - FitGraphicsView(QWidget* parent = 0); - -protected: - void resizeEvent(QResizeEvent * event); -}; - -class PageGameStats : public AbstractPage -{ - Q_OBJECT - -public: - PageGameStats(QWidget* parent = 0); - - QPushButton *BtnBack; - QLabel *labelGameStats; - QLabel *labelGameWin; - QLabel *labelGameRank; - FitGraphicsView * graphic; - -public slots: - void GameStats(char type, const QString & info); - void clear(); - void renderStats(); - -private: - void AddStatText(const QString & msg); - - QMap > healthPoints; - unsigned int playerPosition; - quint32 lastColor; -}; - -#endif // STATSPAGE_H diff -r e1a5f4d5d86a -r 78138ae93820 QTfrontend/ui_hwform.cpp --- a/QTfrontend/ui_hwform.cpp Mon May 09 16:56:29 2011 +0200 +++ b/QTfrontend/ui_hwform.cpp Mon May 09 18:00:39 2011 +0200 @@ -42,8 +42,8 @@ #include "pageselectweapon.h" #include "pagecampaign.h" #include "pagemain.h" -#include "statsPage.h" -#include "playrecordpage.h" +#include "pagegamestats.h" +#include "pageplayrecord.h" #include "hwconsts.h" void Ui_HWForm::setupUi(HWForm *HWForm)