add a waiting for the tirette

This commit is contained in:
ackimixs
2024-03-28 19:15:53 +01:00
parent b26fe3916b
commit 8775464c66
4 changed files with 104 additions and 4 deletions

View File

@@ -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})

View File

@@ -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;
};

5
WaintingForTirette.cpp Normal file
View File

@@ -0,0 +1,5 @@
//
// Created by acki on 3/28/24.
//
#include "WaintingForTirette.h"

70
WaintingForTirette.h Normal file
View File

@@ -0,0 +1,70 @@
#pragma once
#include <QLabel>
#include <QWidget>
#include <QTimer>
#include <QVBoxLayout>
#include <TCPSocket/TCPUtils.hpp>
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<std::string> 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;
};