o0 merge
authorburp <mail@tobias-neumann.eu>
Mon, 30 Aug 2010 22:05:41 +0200
changeset 3793 46e6fa2cdbc6
parent 3792 dd9345e74b66 (current diff)
parent 3788 9aa8a832e296 (diff)
child 3794 dc359b2ab872
o0 merge
--- a/QTfrontend/hedgewars.qrc	Mon Aug 30 06:33:56 2010 +0200
+++ b/QTfrontend/hedgewars.qrc	Mon Aug 30 22:05:41 2010 +0200
@@ -96,5 +96,18 @@
     <file>res/follow.png</file>
     <file>res/info.png</file>
     <file>res/kick.png</file>
+    <file>res/StatsMedal1.png</file>
+    <file>res/StatsMedal2.png</file>
+    <file>res/StatsMedal3.png</file>
+    <file>res/StatsMedal4.png</file>
+    <file>res/StatsR.png</file>
+    <file>res/StatsH.png</file>
+    <file>res/StatsD.png</file>
+    <file>res/StatsBestKiller.png</file>
+    <file>res/StatsBestShot.png</file>
+    <file>res/StatsHedgehogsKilled.png</file>
+    <file>res/StatsMostSelfDamage.png</file>
+    <file>res/StatsSelfKilled.png</file>
+    <file>res/StatsSkipped.png</file>
 </qresource>
 </RCC>
--- a/QTfrontend/pages.cpp	Mon Aug 30 06:33:56 2010 +0200
+++ b/QTfrontend/pages.cpp	Mon Aug 30 22:05:41 2010 +0200
@@ -1063,22 +1063,81 @@
     roomsList->setAlternatingRowColors(true);
     pageLayout->addWidget(roomsList, 1, 0, 3, 1);
     pageLayout->setRowStretch(2, 100);
+    
+    QHBoxLayout * filterLayout = new QHBoxLayout();
+    
+    QLabel * stateLabel = new QLabel(this);
+    stateLabel->setText(tr("State:"));
+    CBState = new QComboBox(this);
+    CBState->addItem(QComboBox::tr("Any"));
+    CBState->addItem(QComboBox::tr("In lobby"));
+    CBState->addItem(QComboBox::tr("In progress"));
+    filterLayout->addWidget(stateLabel);
+    filterLayout->addWidget(CBState);
+    filterLayout->addSpacing(30);
+    
+    QLabel * ruleLabel = new QLabel(this);
+    ruleLabel->setText(tr("Rules:"));
+    CBRules = new QComboBox(this);
+    CBRules->addItem(QComboBox::tr("Any"));
+    CBRules->addItem(QComboBox::tr("Default"));
+    CBRules->addItem(QComboBox::tr("Pro mode"));
+    CBRules->addItem(QComboBox::tr("Shoppa"));
+    CBRules->addItem(QComboBox::tr("Basketball"));
+    CBRules->addItem(QComboBox::tr("Minefield"));
+    CBRules->addItem(QComboBox::tr("Barrel mayhem"));
+    CBRules->addItem(QComboBox::tr("Tunnel hogs"));
+    filterLayout->addWidget(ruleLabel);
+    filterLayout->addWidget(CBRules);
+    filterLayout->addSpacing(30);
+    
+    QLabel * weaponLabel = new QLabel(this);
+    weaponLabel->setText(tr("Weapons:"));
+    CBWeapons = new QComboBox(this);
+    CBWeapons->addItem(QComboBox::tr("Any"));
+    CBWeapons->addItem(QComboBox::tr("Basketball"));
+    CBWeapons->addItem(QComboBox::tr("Crazy"));
+    CBWeapons->addItem(QComboBox::tr("Default"));
+    CBWeapons->addItem(QComboBox::tr("Minefield"));
+    CBWeapons->addItem(QComboBox::tr("Pro mode"));
+    CBWeapons->addItem(QComboBox::tr("Shoppa"));
+    filterLayout->addWidget(weaponLabel);
+    filterLayout->addWidget(CBWeapons);
+    filterLayout->addSpacing(30);
+
+    QLabel * searchLabel = new QLabel(this);
+    searchLabel->setText(tr("Search:"));
+    searchText = new QLineEdit(this);
+    searchText->setMaxLength(60);
+    filterLayout->addWidget(searchLabel);
+    filterLayout->addWidget(searchText);
+
+    pageLayout->addLayout(filterLayout, 4, 0);
 
     chatWidget = new HWChatWidget(this, gameSettings, sdli, false);
-    pageLayout->addWidget(chatWidget, 4, 0, 1, 2);
-    pageLayout->setRowStretch(4, 350);
+    pageLayout->addWidget(chatWidget, 5, 0, 1, 2);
+    pageLayout->setRowStretch(5, 350);
 
     BtnCreate = addButton(tr("Create"), pageLayout, 0, 1);
     BtnJoin = addButton(tr("Join"), pageLayout, 1, 1);
     BtnRefresh = addButton(tr("Refresh"), pageLayout, 3, 1);
+    BtnClear = addButton(tr("Clear"), pageLayout, 4, 1);
 
-    BtnBack = addButton(":/res/Exit.png", pageLayout, 5, 0, true);
-    BtnAdmin = addButton(tr("Admin features"), pageLayout, 5, 1);
+    BtnBack = addButton(":/res/Exit.png", pageLayout, 6, 0, true);
+    BtnAdmin = addButton(tr("Admin features"), pageLayout, 6, 1);
 
     connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick()));
     connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick()));
     connect(BtnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClick()));
+    connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick()));
     connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick()));
+    connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
+    connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
+    connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
+    connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onRefreshClick()));
+    connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection);
+    
+    gameInLobby = false;
 }
 
 void PageRoomsList::setAdmin(bool flag)
@@ -1088,6 +1147,8 @@
 
 void PageRoomsList::setRoomsList(const QStringList & list)
 {
+    listFromServer = list;
+    
     roomsList->clear();
     roomsList->setColumnCount(7);
     roomsList->setHorizontalHeaderLabels(
@@ -1113,12 +1174,45 @@
     // set resize modes
 //  roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
 
+    bool gameCanBeJoined = true;
+
     if (list.size() % 8)
         return;
 
     roomsList->setRowCount(list.size() / 8);
     for(int i = 0, r = 0; i < list.size(); i += 8, r++)
     {
+        // if we are joining a game
+        if (gameInLobby) {
+            if (gameInLobbyName == list[i + 1]) {
+                gameCanBeJoined = list[i].compare("True");
+            }
+        }
+        
+        // check filter settings
+        #define NO_FILTER_MATCH roomsList->setRowCount(roomsList->rowCount() - 1); --r; continue
+        
+        if (list[i].compare("True") && CBState->currentIndex() == 2) { NO_FILTER_MATCH; }
+        if (list[i].compare("False") && CBState->currentIndex() == 1) { NO_FILTER_MATCH; }
+        if (CBRules->currentIndex() != 0 && list[i + 6].compare(CBRules->currentText())) { NO_FILTER_MATCH; }
+        if (CBWeapons->currentIndex() != 0 && list[i + 7].compare(CBWeapons->currentText())) { NO_FILTER_MATCH; }
+        bool found = list[i + 1].contains(searchText->text(), Qt::CaseInsensitive);
+        if (!found) {
+            for (int a = 4; a <= 7; ++a) {
+                QString compString = list[i + a];
+                if (a == 5 && compString == "+rnd+") {
+                    compString = "Random Map";
+                } else if (a == 5 && compString == "+maze+") {
+                    compString = "Random Maze";
+                }
+                if (compString.contains(searchText->text(), Qt::CaseInsensitive)) {
+                    found = true;
+                    break;
+                }
+            }
+        }
+        if (!searchText->text().isEmpty() && !found) { NO_FILTER_MATCH; }
+        
         QTableWidgetItem * item;
         item = new QTableWidgetItem(list[i + 1]); // room name
         item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
@@ -1191,6 +1285,15 @@
    roomsList->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents);
    roomsList->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents);
 
+    if (gameInLobby) {
+        gameInLobby = false;
+        if (gameCanBeJoined) {
+            emit askForJoinRoom(gameInLobbyName);
+        } else {
+            emit askJoinConfirmation(gameInLobbyName);
+        }
+    }
+
 //  roomsList->resizeColumnsToContents();
 }
 
@@ -1214,9 +1317,22 @@
                 tr("Error"),
                 tr("Please select room from the list"),
                 tr("OK"));
-        return ;
+        return;
     }
-    emit askForJoinRoom(curritem->data(Qt::DisplayRole).toString());
+
+    for (int i = 0; i < listFromServer.size(); i += 8) {
+        if (listFromServer[i + 1] == curritem->data(Qt::DisplayRole).toString()) {
+            gameInLobby = listFromServer[i].compare("True");
+            break;
+        }
+    }
+    
+    if (gameInLobby) {
+        gameInLobbyName = curritem->data(Qt::DisplayRole).toString();
+        emit askForRoomList();
+    } else {
+        emit askForJoinRoom(curritem->data(Qt::DisplayRole).toString());
+    }
 }
 
 void PageRoomsList::onRefreshClick()
@@ -1224,6 +1340,24 @@
     emit askForRoomList();
 }
 
+void PageRoomsList::onClearClick()
+{
+    CBState->setCurrentIndex(0);
+    CBRules->setCurrentIndex(0);
+    CBWeapons->setCurrentIndex(0);
+    searchText->clear();
+}
+
+void PageRoomsList::onJoinConfirmation(const QString & room)
+{
+    if (QMessageBox::warning(this,
+        tr("Warning"),
+        tr("The game you are trying to join has started.\nDo you still want to join the room?"),
+        QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
+    {
+        emit askForJoinRoom(room);
+    }
+}
 
 PageConnecting::PageConnecting(QWidget* parent) :
     AbstractPage(parent)
--- a/QTfrontend/pages.h	Mon Aug 30 06:33:56 2010 +0200
+++ b/QTfrontend/pages.h	Mon Aug 30 22:05:41 2010 +0200
@@ -397,14 +397,24 @@
     PageRoomsList(QWidget* parent, QSettings * config, SDLInteraction * sdli);
 
     QLineEdit * roomName;
+    QLineEdit * searchText;
     QTableWidget * roomsList;
     QPushButton * BtnBack;
     QPushButton * BtnCreate;
     QPushButton * BtnJoin;
     QPushButton * BtnRefresh;
     QPushButton * BtnAdmin;
+    QPushButton * BtnClear;
+    QComboBox * CBState;
+    QComboBox * CBRules;
+    QComboBox * CBWeapons;
     HWChatWidget * chatWidget;
 
+private:
+    bool gameInLobby;
+    QString gameInLobbyName;
+    QStringList listFromServer;
+
 public slots:
     void setRoomsList(const QStringList & list);
     void setAdmin(bool);
@@ -413,11 +423,14 @@
     void onCreateClick();
     void onJoinClick();
     void onRefreshClick();
+    void onClearClick();
+    void onJoinConfirmation(const QString &);
 
 signals:
     void askForCreateRoom(const QString &);
     void askForJoinRoom(const QString &);
     void askForRoomList();
+    void askJoinConfirmation(const QString &);
 };
 
 class PageConnecting : public AbstractPage
Binary file QTfrontend/res/StatsBestKiller.png has changed
Binary file QTfrontend/res/StatsBestShot.png has changed
Binary file QTfrontend/res/StatsD.png has changed
Binary file QTfrontend/res/StatsH.png has changed
Binary file QTfrontend/res/StatsHedgehogsKilled.png has changed
Binary file QTfrontend/res/StatsMedal1.png has changed
Binary file QTfrontend/res/StatsMedal2.png has changed
Binary file QTfrontend/res/StatsMedal3.png has changed
Binary file QTfrontend/res/StatsMedal4.png has changed
Binary file QTfrontend/res/StatsMostSelfDamage.png has changed
Binary file QTfrontend/res/StatsR.png has changed
Binary file QTfrontend/res/StatsSelfKilled.png has changed
Binary file QTfrontend/res/StatsSkipped.png has changed
--- a/QTfrontend/statsPage.cpp	Mon Aug 30 06:33:56 2010 +0200
+++ b/QTfrontend/statsPage.cpp	Mon Aug 30 22:05:41 2010 +0200
@@ -19,7 +19,8 @@
 #include <QLabel>
 #include <QGridLayout>
 #include <QGraphicsScene>
-
+#include <QGroupBox>
+#include <QSizePolicy>
 #include "statsPage.h"
 #include "team.h"
 
@@ -36,20 +37,59 @@
 PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent)
 {
     QGridLayout * pageLayout = new QGridLayout(this);
+    pageLayout->setSpacing(20);
     pageLayout->setColumnStretch(0, 1);
     pageLayout->setColumnStretch(1, 1);
-    pageLayout->setColumnStretch(2, 1);
+
+    BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true);
+    BtnBack->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
 
-    BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true);
+    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("<h1><img src=\":/res/StatsD.png\"> Details</h1>"));
+    l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
     labelGameStats->setTextFormat(Qt::RichText);
-    pageLayout->addWidget(labelGameStats, 0, 0, 1, 3);
-
-    graphic = new FitGraphicsView(this);
+    labelGameStats->setAlignment(Qt::AlignTop);
+    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("<br><h1><img src=\":/res/StatsH.png\"> Health graph</h1>"));
+    l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+    gbl->addWidget(l);
+    gbl->addWidget(graphic);
     graphic->scale(1.0, -1.0);
     graphic->setBackgroundBrush(QBrush(Qt::black));
-    pageLayout->addWidget(graphic, 1, 0, 1, 3);
+    
+    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("<h1><img src=\":/res/StatsR.png\"> Ranking</h1>"));
+    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)
@@ -61,6 +101,9 @@
 {
     labelGameStats->setText("");
     healthPoints.clear();
+    labelGameRank->setText("");
+    playerPosition = 0;
+    lastColor = 0;
 }
 
 void PageGameStats::renderStats()
@@ -93,12 +136,12 @@
 {
     switch(type) {
         case 'r' : {
-            AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info));
+            labelGameWin->setText(QString("<h1 align=\"center\">%1</h1>").arg(info));
             break;
         }
         case 'D' : {
             int i = info.indexOf(' ');
-            QString message = PageGameStats::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>")
+            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>")
                     .arg(info.mid(i + 1), info.left(i));
             AddStatText(message);
             break;
@@ -106,14 +149,14 @@
         case 'k' : {
             int i = info.indexOf(' ');
             int num = info.left(i).toInt();
-            QString message = PageGameStats::tr("<p>The best killer is <b>%1</b> with <b>%2</b> kills in a turn.</p>", "", num)
+            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)
                     .arg(info.mid(i + 1), info.left(i));
             AddStatText(message);
             break;
         }
         case 'K' : {
             int num = info.toInt();
-            QString message = PageGameStats::tr("<p>A total of <b>%1</b> hedgehog(s) were killed during this round.</p>", "", num).arg(num);
+            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);
             AddStatText(message);
             break;
         }
@@ -136,6 +179,74 @@
                     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(' ');
+
+	    QString kills = playerinfo.left(i);
+	    QString playername = playerinfo.mid(i + 1);
+	    QString image;
+
+            if (lastColor == c && playerPosition <= 2) playerPosition = 1;
+	    lastColor = c;
+
+	    switch (playerPosition)
+	    {
+	    	case 1:
+			image = "<img src=\":/res/StatsMedal1.png\">";
+			break;
+		case 2:
+			image = "<img src=\":/res/StatsMedal2.png\">";
+			break;
+		case 3:
+			image = "<img src=\":/res/StatsMedal3.png\">";
+			break;
+		default:
+			image = "<img src=\":/res/StatsMedal4.png\">";
+			break;
+	    }
+
+            QString message;
+	    if (kills.toInt() == 1)
+	    {
+	    	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());
+	    } else {
+	        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());
+            }
+            labelGameRank->setText(labelGameRank->text() + message);
+            break;
+	}
+        case 's' : {
+            int i = info.indexOf(' ');
+            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>")
+                    .arg(info.mid(i + 1), info.left(i));
+            AddStatText(message);
+            break;
+        }
+        case 'S' : {
+            int i = info.indexOf(' ');
+            QString message = PageGameStats::tr("<p><img src=\":/res/StatsSelfKilled.png\"> <b>%1</b> killed <b>%2</b> of his own hedgehogs.</p>")
+                    .arg(info.mid(i + 1), info.left(i));
+            AddStatText(message);
+            break;
+        }
+        case 'B' : {
+            int i = info.indexOf(' ');
+            QString message = PageGameStats::tr("<p><img src=\":/res/StatsSkipped.png\"> <b>%1</b> was scared and skipped turn <b>%2</b> times.</p>")
+                    .arg(info.mid(i + 1), info.left(i));
+            AddStatText(message);
+            break;
+        }
+
     }
 }
--- a/QTfrontend/statsPage.h	Mon Aug 30 06:33:56 2010 +0200
+++ b/QTfrontend/statsPage.h	Mon Aug 30 22:05:41 2010 +0200
@@ -44,6 +44,8 @@
 
     QPushButton *BtnBack;
     QLabel *labelGameStats;
+    QLabel *labelGameWin;
+    QLabel *labelGameRank;
     FitGraphicsView * graphic;
 
 public slots:
@@ -55,6 +57,8 @@
     void AddStatText(const QString & msg);
 
     QMap<quint32, QVector<quint32> > healthPoints;
+    unsigned int playerPosition;
+    quint32 lastColor;
 };
 
 #endif // STATSPAGE_H