From 8775464c660bd7eb9a445c29c313b1815753c19d Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 28 Mar 2024 19:15:53 +0100 Subject: [PATCH] add a waiting for the tirette --- CMakeLists.txt | 2 ++ MainWindow.h | 31 ++++++++++++++++--- WaintingForTirette.cpp | 5 +++ WaintingForTirette.h | 70 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 WaintingForTirette.cpp create mode 100644 WaintingForTirette.h diff --git a/CMakeLists.txt b/CMakeLists.txt index fb6eddf..bb049bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,8 @@ set(SOURCES preparation/Lidar.cpp preparation/OneItemPreparation.cpp preparation/TiretteState.cpp + WaintingForTirette.cpp + WaintingForTirette.h ) add_executable(ihm_robot resource.qrc ${HEADERS} ${SOURCES}) diff --git a/MainWindow.h b/MainWindow.h index 6260b68..ca6eafd 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -13,6 +13,7 @@ #include "PreparationMatch.h" #include "TeamChooser.h" #include "TestMode.h" +#include "WaintingForTirette.h" class MainWindow : public QMainWindow, public TCPClient { Q_OBJECT @@ -50,7 +51,7 @@ public: this->mainLayout->addLayout(this->topLayout); - this->setFixedSize(QSize(480, 320)); + this->setFixedSize(QSize(800, 480)); this->home = new homeButton(centralWidget); @@ -68,11 +69,19 @@ public: connect(this->teamChooser, &TeamChooser::spawnPointChoose, this, &MainWindow::onSpawnPointChoose); this->preparationMatch = new PreparationMatch(centralWidget); - connect(this->preparationMatch, &PreparationMatch::startGame, this, &MainWindow::onStartGame); + connect(this->preparationMatch, &PreparationMatch::startGame, [&]() + { + this->waitingForTiretteValue = true; + this->waintingForTirette->startWaiting(); + emit this->onWaitingForTirette(); + }); connect(this->preparationMatch, &PreparationMatch::askTCPServer, [&](const std::string& message) { this->sendMessage(message.c_str()); }); + this->waintingForTirette = new WaintingForTirette(centralWidget); + connect(this->waintingForTirette, &WaintingForTirette::startGame, this, &MainWindow::onStartGame); + this->testMode = new TestMode(centralWidget); connect(this->testMode, &TestMode::goPressed, this, &MainWindow::moveRobot); @@ -84,6 +93,7 @@ public: this->stackedWidget->addWidget(this->teamChooser); this->stackedWidget->addWidget(this->preparationMatch); this->stackedWidget->addWidget(this->testMode); + this->stackedWidget->addWidget(this->waintingForTirette); this->stackedWidget->addWidget(this->inGame); this->mainLayout->addWidget(this->stackedWidget); @@ -137,11 +147,16 @@ protected slots: this->setWidgetNb(3); } - void onStartGame() + void onWaitingForTirette() { this->setWidgetNb(5); } + void onStartGame() + { + this->setWidgetNb(6); + } + void onDeplierRobot() { emit deplierRobot(); @@ -163,7 +178,13 @@ protected slots: } if (TCPSocket::contains(list[0], "tirette") && TCPSocket::contains(list[2], "set state")) { - preparationMatch->responseTiretteState(QString::fromStdString(message)); + if (waitingForTiretteValue) + { + waintingForTirette->responseFromTirette(message); + } else + { + preparationMatch->responseTiretteState(QString::fromStdString(message)); + } } if (TCPSocket::contains(list[0], "lidar")) { @@ -190,6 +211,8 @@ private: TeamChooser* teamChooser; PreparationMatch* preparationMatch; TestMode* testMode; + WaintingForTirette* waintingForTirette; InGame* inGame; + bool waitingForTiretteValue = false; }; diff --git a/WaintingForTirette.cpp b/WaintingForTirette.cpp new file mode 100644 index 0000000..b083c15 --- /dev/null +++ b/WaintingForTirette.cpp @@ -0,0 +1,5 @@ +// +// Created by acki on 3/28/24. +// + +#include "WaintingForTirette.h" diff --git a/WaintingForTirette.h b/WaintingForTirette.h new file mode 100644 index 0000000..0102873 --- /dev/null +++ b/WaintingForTirette.h @@ -0,0 +1,70 @@ +#pragma once + +#include +#include +#include +#include +#include + +class WaintingForTirette : public QWidget { + Q_OBJECT +public: + WaintingForTirette(QWidget* parent = nullptr) : QWidget(parent) + { + this->mainLayout = new QVBoxLayout(this); + this->title = new QLabel("Wainting for tirette", this); + this->title->setStyleSheet("font-size: 30px; color: black;"); + this->wating = new QLabel("Waiting", this); + this->wating->setStyleSheet("font-size: 24px; color: black;"); + + this->mainLayout->addWidget(this->title, 0, Qt::AlignCenter | Qt::AlignTop); + this->mainLayout->addWidget(this->wating, 0, Qt::AlignCenter | Qt::AlignTop); + + this->timer = new QTimer(this); + + connect(this->timer, &QTimer::timeout, this, [=]() { + this->i = (this->i + 1) % 3; + QString message = "Waiting"; + for (int j = 0; j < this->i; j++) + { + message += "."; + } + this->wating->setText(message); + }); + } + + ~WaintingForTirette() + { + delete this->title; + delete this->wating; + delete this->timer; + delete this->mainLayout; + } + + void responseFromTirette(const std::string& response) + { + std::vector list = TCPSocket::split(response, ";"); + + if (list[3] == "1") + { + emit startGame(); + } + } + + void startWaiting() + { + this->timer->start(1000); + } + +signals: + void startGame(); + + +private: + QVBoxLayout* mainLayout; + QLabel* title; + QLabel* wating; + QTimer* timer; + + int i = 0; +};