#include <QDebug>
#include <QVBoxLayout>
#include <QLabel>
+#include <QMap>
#include <X11/Xlib.h>
#include <X11/extensions/XInput2.h>
/* Fullscreen, no cursor */
setWindowState(Qt::WindowFullScreen);
setCursor(QCursor(Qt::BlankCursor));
+
+ words.open(stdin,QIODevice::ReadOnly);
}
MultypoWindow::~MultypoWindow()
{
}
+void MultypoWindow::resetPlayerText() {
+ for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
+ it.value()->resetText();
+ }
+}
+
+void MultypoWindow::nextWord() {
+ QByteArray tmp = words.readLine();
+ QString word = QString::fromUtf8(tmp);
+ mainLabel->setText(word);
+}
+
void MultypoWindow::handleKeyPress(int device, QString string)
{
qDebug() << "Device" << device << "String" << string;
players[device] = new Player(this);
}
players[device]->handleKey(string);
+
+ if (gameStarted) { // ingame
+
+ } else { // name entering phase
+ bool allHaveNames = true;
+ for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
+ if (! it.value()->hasName()) {
+ allHaveNames = false;
+ break;
+ }
+ }
+ if (!players.empty() && allHaveNames) {
+ gameStarted = true;
+ nextWord();
+ }
+ }
}
bool MultypoWindow::handleX11Event(XEvent *event)
parent->layout()->addWidget(theLabel);
}
+
+bool Player::hasName() {
+ return !name.isNull();
+}
+
+QString Player::getName() {
+ return name;
+}
+
+QString Player::getCurrentLine() {
+ return currentLine;
+}
+
+void Player::resetText() {
+ currentLine.clear();
+ theLabel->setText(currentLine);
+}
+
void Player::handleKey(QString str) {
if (str.length() == 1) {
currentLine += str;
- } else if (name.isNull() && str == "Return") {
+ } else if (!hasName() && str == "Return") {
// set name
name = currentLine;
currentLine = "";