fix score
[multypo.git] / qt / multypo.cpp
index d58d247728286c90c3225df9dd2f0e72d83536f6..07d60b39dc49450fdbcf66e21d2ab36bde5b23c6 100644 (file)
@@ -5,6 +5,7 @@
 #include <QVBoxLayout>
 #include <QLabel>
 #include <QMap>
 #include <QVBoxLayout>
 #include <QLabel>
 #include <QMap>
+#include <QTextDocument>
 
 #include <X11/Xlib.h>
 #include <X11/extensions/XInput2.h>
 
 #include <X11/Xlib.h>
 #include <X11/extensions/XInput2.h>
@@ -16,12 +17,13 @@ MultypoWindow::MultypoWindow(QWidget *parent) :
        xiInited(false)
 {
        /* Prepare colors */
        xiInited(false)
 {
        /* Prepare colors */
-       setStyleSheet("background-color: black; color: green; font-size: 45pt");
+       setStyleSheet("background-color: black; font-size: 45pt");
 
        /* Prepare conents */
        setLayout(new QVBoxLayout(this));
 
        /* Prepare conents */
        setLayout(new QVBoxLayout(this));
-
-       mainLabel = new QLabel("Namen eingeben, dann Return", this);
+       mainLabel = new QLabel(this);
+    mainLabel->setTextFormat(Qt::RichText);
+    setLabel("Namen eingeben, dann Return", BASE_COLOR);
        layout()->addWidget(mainLabel);
 
        /* Fullscreen, no cursor */
        layout()->addWidget(mainLabel);
 
        /* Fullscreen, no cursor */
@@ -35,12 +37,17 @@ MultypoWindow::~MultypoWindow()
 {
 }
 
 {
 }
 
+void MultypoWindow::setLabel(QString text, QString color)
+{
+    mainLabel->setText(QString("<font color=%1>%2</span>").arg(color).arg(Qt::escape(text)));
+}
+
 void MultypoWindow::nextWord() {
        QByteArray tmp = words.readLine().trimmed();
        currentWord = QString::fromUtf8(tmp);
 void MultypoWindow::nextWord() {
        QByteArray tmp = words.readLine().trimmed();
        currentWord = QString::fromUtf8(tmp);
-       qDebug() << "New word" << currentWord;
+       qDebug() << "New word:" << currentWord;
        if (currentWord.isEmpty()) { // game over
        if (currentWord.isEmpty()) { // game over
-               mainLabel->setText("GAME OVER");
+               setLabel("GAME OVER", READY_COLOR);
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
                        it.value()->showScore();
                }
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
                        it.value()->showScore();
                }
@@ -49,7 +56,7 @@ void MultypoWindow::nextWord() {
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
             it.value()->nextWord();
         }
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
             it.value()->nextWord();
         }
-               mainLabel->setText(currentWord);
+               setLabel(currentWord, BASE_COLOR);
         state = Playing;
        }
 }
         state = Playing;
        }
 }
@@ -90,16 +97,14 @@ void MultypoWindow::handleKeyPress(int device, QString string)
     
     if (state == Naming) {
         // someone's still naming (or nobody's there yet)
     
     if (state == Naming) {
         // someone's still naming (or nobody's there yet)
-        qDebug() << "checking for game started";
         if (!players.empty() && allPlayersWaiting()) {
         if (!players.empty() && allPlayersWaiting()) {
+            qDebug() << "Game starting";
             nextWord();
         }
     }
     else if (state == Playing) { // all players are waiting or typing
             nextWord();
         }
     }
     else if (state == Playing) { // all players are waiting or typing
-               qDebug() << "current player line" << player->getCurrentWord();
-               qDebug() << "current word" << currentWord;
                if (player->getState() == Player::Typing && player->getCurrentWord() == currentWord) {
                if (player->getState() == Player::Typing && player->getCurrentWord() == currentWord) {
-            int points = typingPlayers()+1;
+            int points = typingPlayers();
             player->wordComplete(points);
                        QString readyString = QString("READY: %1 points").arg(points);
                        if (allPlayersWaiting()) {
             player->wordComplete(points);
                        QString readyString = QString("READY: %1 points").arg(points);
                        if (allPlayersWaiting()) {