11/25
This commit is contained in:
66
ZBD_IIIDL_S_Project/Src/GameControl/gamecontainer.cpp
Normal file
66
ZBD_IIIDL_S_Project/Src/GameControl/gamecontainer.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "gamecontainer.h"
|
||||
#include "ui_gamecontainer.h"
|
||||
#include <QProcess>
|
||||
#include <QShowEvent>
|
||||
#include <QDebug>
|
||||
#include "dataformate.h"
|
||||
#include <QTimer>
|
||||
#include <windows.h>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
GameContainer::GameContainer(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::GameContainer),
|
||||
process(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
initProcess();
|
||||
}
|
||||
|
||||
GameContainer::~GameContainer()
|
||||
{
|
||||
if(process)
|
||||
delete process;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void GameContainer::initProcess()
|
||||
{
|
||||
process = new QProcess();
|
||||
connect(process,&QProcess::errorOccurred,[=](QProcess::ProcessError error){qDebug()<<error;});
|
||||
connect(process,QOverload<int,QProcess::ExitStatus>::of(&QProcess::finished),[this]
|
||||
(int exitCode,QProcess::ExitStatus exitStatus){
|
||||
m_exitCode = exitCode;
|
||||
m_exitStatus = exitStatus;
|
||||
qDebug()<<"m_exitCode"<<m_exitCode<<"m_exitStatus"<<m_exitStatus;
|
||||
});
|
||||
}
|
||||
|
||||
void GameContainer::startGame(QString path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameContainer::showEvent(QShowEvent *event)
|
||||
{
|
||||
// qDebug()<<"showEvent";
|
||||
// QString path = "./GameDemo/game801/game801/MultiplayerBicycleRace.exe";
|
||||
|
||||
// process->start(path);
|
||||
// Sleep(10);
|
||||
// WId hwnd = 0;
|
||||
|
||||
// do{
|
||||
// QEventLoop loop;
|
||||
// //1ms之后退出
|
||||
// QTimer::singleShot(1,&loop,SLOT(quit()));
|
||||
// hwnd = (WId)FindWindow(L"UnityWndClass",L"DuoRenQiChe2");
|
||||
// }while(hwnd == 0);
|
||||
// m_window = QWindow::fromWinId(hwnd);
|
||||
// QWidget *container = createWindowContainer(m_window,this);
|
||||
|
||||
// QHBoxLayout *hLayout = new QHBoxLayout(this);
|
||||
// hLayout->setMargin(0);
|
||||
// hLayout->addWidget(container);
|
||||
// this->setLayout(hLayout);
|
||||
}
|
||||
33
ZBD_IIIDL_S_Project/Src/GameControl/gamecontainer.h
Normal file
33
ZBD_IIIDL_S_Project/Src/GameControl/gamecontainer.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef GAMECONTAINER_H
|
||||
#define GAMECONTAINER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QProcess>
|
||||
#include <QWindow>
|
||||
namespace Ui {
|
||||
class GameContainer;
|
||||
}
|
||||
|
||||
class GameContainer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GameContainer(QWidget *parent = nullptr);
|
||||
~GameContainer();
|
||||
|
||||
void startGame(QString path);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event);
|
||||
private:
|
||||
void initProcess();
|
||||
private:
|
||||
Ui::GameContainer *ui;
|
||||
QProcess *process;
|
||||
int m_exitCode;
|
||||
QProcess::ExitStatus m_exitStatus;
|
||||
QWindow *m_window;
|
||||
};
|
||||
|
||||
#endif // GAMECONTAINER_H
|
||||
19
ZBD_IIIDL_S_Project/Src/GameControl/gamecontainer.ui
Normal file
19
ZBD_IIIDL_S_Project/Src/GameControl/gamecontainer.ui
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GameContainer</class>
|
||||
<widget class="QWidget" name="GameContainer">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
522
ZBD_IIIDL_S_Project/Src/GameControl/gamecontrol.cpp
Normal file
522
ZBD_IIIDL_S_Project/Src/GameControl/gamecontrol.cpp
Normal file
@@ -0,0 +1,522 @@
|
||||
#include "gamecontrol.h"
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include "readconfig.h"
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonParseError>
|
||||
#include <QDateTime>
|
||||
#include "currentuserdata.h"
|
||||
#include "cdatabaseinterface.h"
|
||||
#include <QTimer>
|
||||
|
||||
//LOG4QT_DECLARE_STATIC_LOGGER(logger, GameControl)
|
||||
|
||||
GameControl* GameControl::m_GameParamControl = NULL;
|
||||
|
||||
GameControl::GameControl(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_gameSocket(NULL),
|
||||
// m_waitingDialog(NULL),
|
||||
m_trainReport(NULL),
|
||||
waitTimer(NULL),
|
||||
m_activeMaxAngle(0),
|
||||
m_activeMinAngle(0),
|
||||
currentGameID(0)
|
||||
{
|
||||
m_Process = new QProcess();
|
||||
// initGameSocket();
|
||||
// m_waitingDialog = new WaitingDialog();
|
||||
// m_waitingDialog->setWaitingType(INITWAITING);
|
||||
m_trainReport = new TrainReport();
|
||||
|
||||
waitTimer = new QTimer();
|
||||
waitTimer->setInterval(500);
|
||||
waitTimer->setSingleShot(true);
|
||||
connect(waitTimer,SIGNAL(timeout()),this,SLOT(slotWaitTimer()));
|
||||
|
||||
player = new QMediaPlayer();
|
||||
}
|
||||
|
||||
GameControl::~GameControl()
|
||||
{
|
||||
if(m_trainReport)
|
||||
{
|
||||
delete m_trainReport;
|
||||
}
|
||||
if(waitTimer)
|
||||
{
|
||||
delete waitTimer;
|
||||
}
|
||||
if(player)
|
||||
{
|
||||
delete player;
|
||||
}
|
||||
}
|
||||
|
||||
void GameControl::initGameSocket()
|
||||
{
|
||||
m_gameSocket = new QUdpSocket();
|
||||
int16_t port;
|
||||
QString IP;
|
||||
ReadConfig::getInstance()->getGameServerAddress(port,IP);
|
||||
if(m_gameSocket->bind(port))
|
||||
{
|
||||
qDebug()<<(QString("游戏服务端口%1").arg(port));
|
||||
}
|
||||
connect(m_gameSocket,&QUdpSocket::readyRead,this,&GameControl::slotReceiveGameData);
|
||||
}
|
||||
|
||||
GameControl* GameControl::getInstance()
|
||||
{
|
||||
if(!m_GameParamControl)
|
||||
{
|
||||
m_GameParamControl = new GameControl();
|
||||
}
|
||||
return m_GameParamControl;
|
||||
}
|
||||
|
||||
void GameControl::updateXml(ST_GameParam& st_GameParam)
|
||||
{
|
||||
QFile file("./gameExecutable/gameConfig.xml");
|
||||
if(!file.open(QFile::ReadOnly))
|
||||
return;
|
||||
QDomDocument doc;
|
||||
|
||||
if(!doc.setContent(&file))
|
||||
{
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
file.close();
|
||||
|
||||
QDomElement root = doc.documentElement();
|
||||
|
||||
if(1)
|
||||
{
|
||||
QDomNodeList timeList = root.elementsByTagName("GameTime");
|
||||
QDomNode timeNode = timeList.at(0);
|
||||
QDomNode oldnode=timeNode.firstChild();
|
||||
timeNode.firstChild().setNodeValue(QString::number(st_GameParam.gameTime));
|
||||
QDomNode newNode = timeNode.firstChild();
|
||||
timeNode.replaceChild(newNode,oldnode);
|
||||
}
|
||||
if(1)
|
||||
{
|
||||
QDomNodeList levelList = root.elementsByTagName("Level");
|
||||
QDomNode levelNode = levelList.at(0);
|
||||
QDomNode oldLevelnode=levelNode.firstChild();
|
||||
levelNode.firstChild().setNodeValue(QString::number(st_GameParam.hardLevel));
|
||||
QDomNode newLevelNode = levelNode.firstChild();
|
||||
levelNode.replaceChild(newLevelNode,oldLevelnode);
|
||||
}
|
||||
if(1)
|
||||
{
|
||||
QDomNodeList List = root.elementsByTagName("Speed");
|
||||
QDomNode node = List.at(0);
|
||||
QDomNode oldLevelnode=node.firstChild();
|
||||
node.firstChild().setNodeValue(QString::number(st_GameParam.speed));
|
||||
QDomNode newLevelNode = node.firstChild();
|
||||
node.replaceChild(newLevelNode,oldLevelnode);
|
||||
}
|
||||
if(1)
|
||||
{
|
||||
QDomNodeList List = root.elementsByTagName("TrainType");
|
||||
QDomNode node = List.at(0);
|
||||
QDomNode oldLevelnode=node.firstChild();
|
||||
node.firstChild().setNodeValue(QString::number(st_GameParam.trainType));
|
||||
QDomNode newLevelNode = node.firstChild();
|
||||
node.replaceChild(newLevelNode,oldLevelnode);
|
||||
}
|
||||
if(1)
|
||||
{
|
||||
QDomNodeList List = root.elementsByTagName("AngleVlue");
|
||||
QDomNode node = List.at(0);
|
||||
QDomNode oldLevelnode=node.firstChild();
|
||||
node.firstChild().setNodeValue(QString::number(st_GameParam.angleValue));
|
||||
QDomNode newLevelNode = node.firstChild();
|
||||
node.replaceChild(newLevelNode,oldLevelnode);
|
||||
}
|
||||
if(1)
|
||||
{
|
||||
QDomNodeList List = root.elementsByTagName("WaitTime");
|
||||
QDomNode node = List.at(0);
|
||||
QDomNode oldLevelnode=node.firstChild();
|
||||
node.firstChild().setNodeValue(QString::number(st_GameParam.waitTime));
|
||||
QDomNode newLevelNode = node.firstChild();
|
||||
node.replaceChild(newLevelNode,oldLevelnode);
|
||||
}
|
||||
if(1)
|
||||
{
|
||||
QDomNodeList List = root.elementsByTagName("MaxCircle");
|
||||
QDomNode node = List.at(0);
|
||||
QDomNode oldLevelnode=node.firstChild();
|
||||
node.firstChild().setNodeValue(QString::number(st_GameParam.maxCircle));
|
||||
QDomNode newLevelNode = node.firstChild();
|
||||
node.replaceChild(newLevelNode,oldLevelnode);
|
||||
}
|
||||
if(1)
|
||||
{
|
||||
QDomNodeList List = root.elementsByTagName("ReadPosTable");
|
||||
QDomNode node = List.at(0);
|
||||
QDomNode oldLevelnode=node.firstChild();
|
||||
QString ok("false");
|
||||
if(st_GameParam.readPosTable)
|
||||
ok = "true";
|
||||
else
|
||||
ok = "false";
|
||||
node.firstChild().setNodeValue(ok);
|
||||
QDomNode newLevelNode = node.firstChild();
|
||||
node.replaceChild(newLevelNode,oldLevelnode);
|
||||
}
|
||||
|
||||
QDomNode n = root.firstChild();
|
||||
while(!n.isNull())
|
||||
{
|
||||
QDomElement e = n.toElement();
|
||||
if(!e.isNull())
|
||||
{
|
||||
if(e.tagName() == "TrainingTrack")
|
||||
{
|
||||
e.setAttribute("path",st_GameParam.trainTrackFilePath);
|
||||
}
|
||||
}
|
||||
n = n.nextSibling();
|
||||
}
|
||||
|
||||
if(!file.open(QFile::WriteOnly|QFile::Truncate))
|
||||
return;
|
||||
//输出到文件
|
||||
QTextStream out_stream(&file);
|
||||
doc.save(out_stream,4); //缩进4格
|
||||
file.close();
|
||||
}
|
||||
|
||||
void GameControl::setGamParam(ST_GameParam& st_GameParam)
|
||||
{
|
||||
//将本地参数转化成游戏中用到的参数
|
||||
if(5 == st_GameParam.trainType)
|
||||
st_GameParam.trainType = 1;
|
||||
if(6 == st_GameParam.trainType)
|
||||
st_GameParam.trainType = 2;
|
||||
updateXml(st_GameParam);
|
||||
}
|
||||
|
||||
void GameControl::readGameConfigMsg()
|
||||
{
|
||||
QList<ST_GameMsg> gameMsgList;
|
||||
QFile file("./DependFile/ConfigFile/gameListConfig.xml");
|
||||
|
||||
if(!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
qDebug()<<"read gameListConfig failed";
|
||||
return ;
|
||||
}
|
||||
QDomDocument doc;
|
||||
QString error;
|
||||
int row,colum;
|
||||
if(!doc.setContent(&file,&error,&row,&colum))
|
||||
{
|
||||
qDebug()<<"gameList error"<<error<<row<<colum;
|
||||
file.close();
|
||||
return ;
|
||||
}
|
||||
file.close();
|
||||
|
||||
QDomElement root=doc.documentElement(); //返回根节点
|
||||
|
||||
QDomNode node=root.firstChild(); //获得第一个子节点
|
||||
|
||||
while(!node.isNull())
|
||||
{
|
||||
if(node.isElement()) //如果节点是元素
|
||||
{
|
||||
ST_GameMsg st_GameMsg;
|
||||
QDomElement e=node.toElement();
|
||||
st_GameMsg.gameID = e.attribute("ID").toInt();
|
||||
st_GameMsg.gameName = e.attribute("gameName");
|
||||
st_GameMsg.gamePath = e.attribute("path");
|
||||
st_GameMsg.iconPath = e.attribute("iconPath");
|
||||
st_GameMsg.className = e.attribute("className");
|
||||
st_GameMsg.windownName = e.attribute("windownName");
|
||||
gameMsgList.append(st_GameMsg);
|
||||
m_mapGameName.insert(st_GameMsg.gameID,st_GameMsg);
|
||||
}
|
||||
node = node.nextSibling();
|
||||
}
|
||||
|
||||
m_gameMsgList = gameMsgList;
|
||||
}
|
||||
|
||||
QList<ST_GameMsg> GameControl::getGameMsgs()
|
||||
{
|
||||
return m_gameMsgList;
|
||||
}
|
||||
|
||||
ST_GameMsg GameControl::getGameMsgByName(int ID)
|
||||
{
|
||||
ST_GameMsg st_gameMsg;
|
||||
QMapIterator<int, ST_GameMsg> i(m_mapGameName);
|
||||
|
||||
while(i.hasNext())
|
||||
{
|
||||
i.next();
|
||||
}
|
||||
|
||||
if(m_mapGameName.contains(ID))
|
||||
{
|
||||
st_gameMsg = m_mapGameName.value(ID);
|
||||
}
|
||||
return st_gameMsg;
|
||||
}
|
||||
|
||||
ST_GameMsg GameControl::getCurrentGameMsg()
|
||||
{
|
||||
return getGameMsgByName(currentGameID);
|
||||
}
|
||||
|
||||
void GameControl::startGame(QString path)
|
||||
{
|
||||
//1.开启游戏进程
|
||||
if(path.isEmpty())
|
||||
return;
|
||||
QString hardDisk = path.mid(0,2);
|
||||
hardDisk.append("\n\r");
|
||||
|
||||
QString gameName = path.mid(path.lastIndexOf('/')+1);
|
||||
gameName.prepend("start ");
|
||||
gameName.append("\n\r");
|
||||
QString gamePath = path.mid(0,path.lastIndexOf('/'));
|
||||
gamePath.prepend("cd ");
|
||||
gamePath.append("\n\r");
|
||||
m_Process->start("cmd.exe");
|
||||
//切换盘符
|
||||
m_Process->write(hardDisk.toLatin1());
|
||||
//进入文件夹
|
||||
m_Process->write(gamePath.toLatin1());
|
||||
//开启进程
|
||||
m_Process->write(gameName.toLatin1());
|
||||
m_Process->write("exit\n\r");
|
||||
m_Process->waitForFinished();
|
||||
m_Process->close();
|
||||
//2.关闭设备复位中的界面
|
||||
}
|
||||
|
||||
//游戏数据接收
|
||||
void GameControl::slotReceiveGameData()
|
||||
{
|
||||
while(m_gameSocket->hasPendingDatagrams())
|
||||
{
|
||||
QByteArray buf;
|
||||
buf.resize(m_gameSocket->pendingDatagramSize());
|
||||
m_gameSocket->readDatagram(buf.data(),buf.size());
|
||||
// parseGameMsg(buf);
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
void GameControl::parseGameMsg(QByteArray jsonArray)
|
||||
{
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument doucment = QJsonDocument::fromJson(jsonArray, &jsonError); // 转化为 JSON 文档
|
||||
#if 1
|
||||
if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError))
|
||||
{
|
||||
if(doucment.isObject())
|
||||
{
|
||||
QJsonObject object = doucment.object(); // 转化为对象
|
||||
if(object.contains("msgID"))
|
||||
{
|
||||
int msgID = object.value("msgID").toInt();
|
||||
switch(msgID)
|
||||
{
|
||||
case 1: //游戏开始信号
|
||||
{
|
||||
m_spasmTimes = 0;
|
||||
isTraining = true;
|
||||
waitTimer->start();
|
||||
st_TrainReport.startTime = QDateTime::currentDateTime();
|
||||
emit signalGameState(e_TrainMode,GameStart_E);
|
||||
}
|
||||
break;
|
||||
case 2: //游戏给出的目标位置
|
||||
{
|
||||
{
|
||||
if(object.contains("m_xv"))
|
||||
{
|
||||
QJsonObject xObject = object.value("m_xv").toObject();
|
||||
int current = 0;
|
||||
int max = 1;
|
||||
if(xObject.contains("current"))
|
||||
current = xObject.value("current").toInt();
|
||||
if(xObject.contains("max"))
|
||||
max = xObject.value("max").toInt();
|
||||
}
|
||||
if(object.contains("m_yv"))
|
||||
{
|
||||
QJsonObject yObject = object.value("m_yv").toObject();
|
||||
int current = 0;
|
||||
int max = 1;
|
||||
if(yObject.contains("current"))
|
||||
current = yObject.value("current").toInt();
|
||||
if(yObject.contains("max"))
|
||||
max = yObject.value("max").toInt();
|
||||
}
|
||||
if(object.contains("tarAngle"))
|
||||
{
|
||||
float angle = 0;
|
||||
angle = object.value("tarAngle").toDouble();
|
||||
// emit signalSendDestPosition(angle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case 3: //结束信息
|
||||
{
|
||||
isTraining = false;
|
||||
if(object.contains("quitType"))
|
||||
{
|
||||
//告知下位机训练完成
|
||||
sendStopCmd();
|
||||
m_quitType = object.value("quitType").toInt();
|
||||
//正常退出
|
||||
if(1 == m_quitType)
|
||||
{
|
||||
emit signalGameState(e_TrainMode,GameEnd_E);
|
||||
st_TrainReport.endTime = QDateTime::currentDateTime();
|
||||
if(object.contains("totalTime"))
|
||||
st_TrainReport.duration = object.value("totalTime").toInt();
|
||||
if(object.contains("totalScore"))
|
||||
st_TrainReport.score = object.value("totalScore").toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit signalGameState(e_TrainMode,GameEnd_E);
|
||||
st_TrainReport.endTime = QDateTime::currentDateTime();
|
||||
if(object.contains("totalTime"))
|
||||
st_TrainReport.duration = object.value("totalTime").toInt();
|
||||
if(object.contains("totalScore"))
|
||||
st_TrainReport.score = object.value("totalScore").toInt();
|
||||
}
|
||||
//生成训练报告
|
||||
createTrainReport();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// logger()->debug(jsonError.errorString());
|
||||
//此处不该在此处停止心跳
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
***/
|
||||
void GameControl::createTrainReport()
|
||||
{
|
||||
/***
|
||||
ST_PatientMsg st_currentPatient = CurrentUserData::getInstace()->getCurrentPatientMsg();
|
||||
st_TrainReport.ID = st_currentPatient.ID;
|
||||
st_TrainReport.name = st_currentPatient.name;
|
||||
|
||||
//从数据库中查询总时间
|
||||
int lastTotalDuration;
|
||||
QString query("select * from TrainReport order by startTime DESC;");
|
||||
if(!CDatabaseInterface::getInstance()->exec(query))
|
||||
qDebug()<<CDatabaseInterface::getInstance()->getLastError()<<"ERROR";
|
||||
int count = CDatabaseInterface::getInstance()->getValuesSize();
|
||||
if(count >0)
|
||||
{
|
||||
QList<QVariantMap> maplist = CDatabaseInterface::getInstance()->getValues(0,1);
|
||||
ST_TrainReport st_trainReport = variantMapToTrainReport(maplist.at(0));
|
||||
lastTotalDuration = st_trainReport.totalDuration;
|
||||
st_TrainReport.totalDuration = lastTotalDuration + st_TrainReport.duration;
|
||||
}
|
||||
st_TrainReport.level = 1;
|
||||
if(0 == st_TrainReport.trainMode)
|
||||
m_trainReport->setReportType(tr("被动训练报告"));
|
||||
else if(1 == st_TrainReport.trainMode)
|
||||
m_trainReport->setReportType(tr("主动训练报告"));
|
||||
***/
|
||||
m_trainReport->setReportData(st_TrainReport,1);
|
||||
}
|
||||
|
||||
void GameControl::sendStopCmd()
|
||||
{
|
||||
QJsonObject object;
|
||||
object.insert("msgID",2);
|
||||
object.insert("GameState",0);
|
||||
QJsonDocument document;
|
||||
document.setObject(object);
|
||||
QByteArray sendArray = document.toJson();
|
||||
QString ip("127.0.0.1");
|
||||
int16_t port = 12000;
|
||||
for(int i = 0;i < 5;i++)
|
||||
{
|
||||
m_gameSocket->writeDatagram(sendArray,QHostAddress(ip),port);
|
||||
Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
void GameControl::setTrainParam(ST_TrainParam &st_TrainParam)
|
||||
{
|
||||
m_st_TrainParam = st_TrainParam;
|
||||
}
|
||||
|
||||
ST_TrainParam GameControl::getTrainParam()
|
||||
{
|
||||
return m_st_TrainParam;
|
||||
}
|
||||
|
||||
//游戏界面关闭时间
|
||||
void GameControl::slotWaitTimer()
|
||||
{
|
||||
//关闭等待界面
|
||||
// m_waitingDialog->setDialogCloseState(true);
|
||||
}
|
||||
|
||||
//关闭游戏
|
||||
void GameControl::stopGame()
|
||||
{
|
||||
sendStopCmd();
|
||||
}
|
||||
|
||||
void GameControl::sendGameControlData(const ST_GameControlParam &st_gameControlParam)
|
||||
{
|
||||
QJsonObject object;
|
||||
object.insert("msgID",st_gameControlParam.MsgId);
|
||||
object.insert("ID",st_gameControlParam.ID);
|
||||
object.insert("userName",st_gameControlParam.userName);
|
||||
object.insert("speed",st_gameControlParam.speed);
|
||||
object.insert("forceLeft",st_gameControlParam.forceLeft);
|
||||
object.insert("forceRight",st_gameControlParam.forceRight);
|
||||
object.insert("angle",st_gameControlParam.angle);
|
||||
|
||||
QJsonDocument document;
|
||||
document.setObject(object);
|
||||
QByteArray sendArray = document.toJson();
|
||||
}
|
||||
|
||||
void GameControl::setCurrentGame(int ID)
|
||||
{
|
||||
currentGameID = ID;
|
||||
}
|
||||
|
||||
void GameControl::playTipMusic(QString path)
|
||||
{
|
||||
player->setMedia(QUrl::fromLocalFile(path));
|
||||
player->setVolume(90);
|
||||
player->play();
|
||||
}
|
||||
|
||||
int GameControl::getCurrentGameID()
|
||||
{
|
||||
return currentGameID;
|
||||
}
|
||||
117
ZBD_IIIDL_S_Project/Src/GameControl/gamecontrol.h
Normal file
117
ZBD_IIIDL_S_Project/Src/GameControl/gamecontrol.h
Normal file
@@ -0,0 +1,117 @@
|
||||
#ifndef GAMECONTROL_H
|
||||
#define GAMECONTROL_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "dataformate.h"
|
||||
#include <QDomDocument>
|
||||
#include <QProcess>
|
||||
#include <QUdpSocket>
|
||||
#include "trainreport.h"
|
||||
#include <QtMultimedia/QMediaPlayer>
|
||||
class QTimer;
|
||||
class GameControl : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//更新游戏参数,通过该文件与游戏进行通信,游戏在启动时读取该文件
|
||||
void setGamParam(ST_GameParam&);
|
||||
|
||||
//通过配置表获取所有游戏的信息
|
||||
QList<ST_GameMsg> getGameMsgs();
|
||||
|
||||
//读取游戏配置文件
|
||||
void readGameConfigMsg();
|
||||
|
||||
//根据游戏名获得游戏信息
|
||||
ST_GameMsg getGameMsgByName(int ID);
|
||||
|
||||
//获取选中游戏信息
|
||||
ST_GameMsg getCurrentGameMsg();
|
||||
|
||||
//获取实例
|
||||
static GameControl* getInstance();
|
||||
|
||||
//启动游戏
|
||||
void startGame(QString path);
|
||||
//关闭游戏
|
||||
void stopGame();
|
||||
|
||||
//发送左右平衡以及速度
|
||||
void sendGameControlData(const ST_GameControlParam& );
|
||||
|
||||
//设置当前游戏序号
|
||||
void setCurrentGame(int ID);
|
||||
|
||||
void playTipMusic(QString path);
|
||||
|
||||
//返回ID游戏
|
||||
int getCurrentGameID();
|
||||
|
||||
//设置处方训练参数
|
||||
void setTrainParam(ST_TrainParam &);
|
||||
//返回处方参数
|
||||
ST_TrainParam getTrainParam();
|
||||
|
||||
signals:
|
||||
//游戏状态标志
|
||||
// void signalGameState(E_TRAINMODE,E_GameState);
|
||||
|
||||
void signalSendDestPosition(float angle);
|
||||
public slots:
|
||||
//游戏数据接收
|
||||
void slotReceiveGameData();
|
||||
//游戏界面关闭时间
|
||||
void slotWaitTimer();
|
||||
private:
|
||||
explicit GameControl(QWidget *parent = nullptr);
|
||||
|
||||
~GameControl();
|
||||
|
||||
void updateXml(ST_GameParam&);
|
||||
|
||||
void initGameSocket();
|
||||
|
||||
// void parseGameMsg(QByteArray jsonArray);
|
||||
|
||||
//生成报告
|
||||
void createTrainReport();
|
||||
//停止训练
|
||||
void sendStopCmd();
|
||||
|
||||
private:
|
||||
static GameControl* m_GameParamControl;
|
||||
|
||||
QMap<int,ST_GameMsg> m_mapGameName;
|
||||
|
||||
QProcess* m_Process;
|
||||
|
||||
QUdpSocket *m_gameSocket;
|
||||
|
||||
ST_TrainReport st_TrainReport;
|
||||
|
||||
//训练选择界面-配置处方的训练参数
|
||||
ST_TrainParam m_st_TrainParam;
|
||||
|
||||
int m_spasmTimes; //痉挛次数
|
||||
|
||||
bool isTraining; //训练状态
|
||||
|
||||
int m_quitType; //退出类型
|
||||
|
||||
// WaitingDialog *m_waitingDialog;
|
||||
|
||||
TrainReport *m_trainReport;
|
||||
|
||||
QTimer *waitTimer;
|
||||
|
||||
float m_activeMaxAngle; //主动训练中最大的角度
|
||||
float m_activeMinAngle; //主动训练中最小角度
|
||||
|
||||
QList<ST_GameMsg> m_gameMsgList;
|
||||
|
||||
int currentGameID;
|
||||
|
||||
QMediaPlayer * player;
|
||||
};
|
||||
|
||||
#endif // GAMECONTROL_H
|
||||
2194
ZBD_IIIDL_S_Project/Src/GameControl/gamedisplaypage.cpp
Normal file
2194
ZBD_IIIDL_S_Project/Src/GameControl/gamedisplaypage.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1298
ZBD_IIIDL_S_Project/Src/GameControl/gamedisplaypage.cpp.bak
Normal file
1298
ZBD_IIIDL_S_Project/Src/GameControl/gamedisplaypage.cpp.bak
Normal file
File diff suppressed because it is too large
Load Diff
292
ZBD_IIIDL_S_Project/Src/GameControl/gamedisplaypage.h
Normal file
292
ZBD_IIIDL_S_Project/Src/GameControl/gamedisplaypage.h
Normal file
@@ -0,0 +1,292 @@
|
||||
#ifndef GAMEDISPLAYPAGE_H
|
||||
#define GAMEDISPLAYPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
#include "dataformate.h"
|
||||
#include "dbforrmate.h"
|
||||
#include "spasmtipsdialog.h"
|
||||
#include <QUdpSocket>
|
||||
#include "trainreport.h"
|
||||
#include "quitgamedialog.h"
|
||||
#include "emergencystopdialog.h"
|
||||
#include "trainreporttwotwo.h"
|
||||
#include "trainreportthreetwo.h"
|
||||
#include "trainreporttwothree.h"
|
||||
#include "sounddialog.h"
|
||||
#include "quitbyspeeddialog.h"
|
||||
|
||||
class QPropertyAnimation;
|
||||
namespace Ui {
|
||||
class GameDisplayPage;
|
||||
}
|
||||
|
||||
class GameDisplayPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GameDisplayPage(QWidget *parent = nullptr);
|
||||
~GameDisplayPage();
|
||||
|
||||
//设置当前用户
|
||||
void setUser(const ST_PatientMsg&);
|
||||
//表头显示
|
||||
void setTitle();
|
||||
|
||||
/****设置训练部位****
|
||||
* 参数@int type 0-上肢 1-下肢 2-上下肢
|
||||
* ***/
|
||||
void setTrainPart(int type);
|
||||
|
||||
//根据参数填充实时数据
|
||||
void setSlaveParam(ST_DeviceParam& st_deviceParam);
|
||||
|
||||
//根据界面的参数设置模式
|
||||
void setTrainMode(int8_t mode);
|
||||
|
||||
//设置主被动切换的模式(实时填充)
|
||||
void setActivePassiveSwitchMode(int8_t mode);
|
||||
|
||||
//在未开始游戏,处理急停状态
|
||||
void getEmergecyState(ST_DeviceParam& st_deviceParam);
|
||||
|
||||
|
||||
/****填充设置参数***
|
||||
*参数@int direction 0-正向 1-反向
|
||||
****/
|
||||
void fillSetParam(int updown,int speed,int resistance,int direction);
|
||||
//设置脉搏血氧
|
||||
void setPulseOxygen(const ST_PulseOxygen&);
|
||||
//设置中部参数
|
||||
void setCenterParam(int left,int right,int length);
|
||||
|
||||
/***********通信相关************/
|
||||
/*****设置速度***
|
||||
* 参数@int speed 速度大小
|
||||
* @qint8 type 上下肢类型 0-被动转速 1-等速转速
|
||||
* ******/
|
||||
void setTrainSpeed(int speed = 1,qint8 type = 0);
|
||||
|
||||
/******设置阻力****
|
||||
* 参数@int force 阻力大小
|
||||
* @qint8 type 上下肢类型 0-上肢 1-下肢
|
||||
* ********/
|
||||
void setTrainFore(int force,qint8 type = 0);
|
||||
|
||||
/******设置方向****
|
||||
* 参数@qint8 direction 方向 1-顺时针 0-逆时针
|
||||
* @qint8 type 上下肢类型 0-上肢 1-下肢
|
||||
* ********/
|
||||
void setTrainDirection(qint8 direction = 1,qint8 type = 1);
|
||||
|
||||
/******设置Fes开关****
|
||||
* 参数@qint8 channel 方向 0-电刺激A 1-电刺激B
|
||||
* @bool ok 上下肢类型 false-关 true-开
|
||||
* ********/
|
||||
void switchFes(qint8 channel,bool ok);
|
||||
|
||||
void initGameSocket();
|
||||
|
||||
//设置速度使能状态
|
||||
void setSpeedState(bool);
|
||||
|
||||
//设置阻力使能状态
|
||||
void setForceState(bool);
|
||||
//连续按住改变速度
|
||||
void pressedAdjustSpeed();
|
||||
//连续按住阻力
|
||||
void pressAdjustForce();
|
||||
//设置方向是能
|
||||
void setDirectionState(bool);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
void showEvent(QShowEvent *event);
|
||||
|
||||
virtual void changeEvent(QEvent* event);
|
||||
private slots:
|
||||
void on_start_Btn_clicked();
|
||||
|
||||
void open_Btn_clicked();
|
||||
|
||||
void close_Btn_clicked();
|
||||
|
||||
void on_upSpeedMinus_Btn_clicked();
|
||||
|
||||
void on_upSpeedPlus_Btn_clicked();
|
||||
|
||||
void on_upForceMinus_Btn_clicked();
|
||||
|
||||
void on_upForcePlus_Btn_clicked();
|
||||
|
||||
void on_forward_Btn_clicked();
|
||||
|
||||
void on_backward_Btn_clicked();
|
||||
|
||||
void on_stop_Btn_clicked();
|
||||
|
||||
void on_pause_Btn_clicked();
|
||||
|
||||
void on_switchAFes_Btn_clicked();
|
||||
|
||||
//填充电刺激参数
|
||||
void slotSetChannelAData(int *data,int size);
|
||||
|
||||
void slotSetChannelBData(int *data,int size);
|
||||
|
||||
//踏车设置参数
|
||||
void slotSetBicycleParam(ST_BicycleParam st_setBicycleParam);
|
||||
|
||||
//接收下位机数据
|
||||
void slotReceiveData(QByteArray);
|
||||
|
||||
void slotHeartTimer();
|
||||
|
||||
void slotCountDownTimer();
|
||||
|
||||
void slotStopTraining();
|
||||
|
||||
//游戏数据接收
|
||||
void slotReceiveGameData();
|
||||
|
||||
void slotBackClicked();
|
||||
|
||||
void on_switchFes_Btn_clicked();
|
||||
|
||||
void on_sound_Button_clicked();
|
||||
|
||||
void on_upSpeedPlus_Btn_pressed();
|
||||
|
||||
void on_upSpeedMinus_Btn_pressed();
|
||||
|
||||
void on_upSpeedPlus_Btn_released();
|
||||
|
||||
void on_upSpeedMinus_Btn_released();
|
||||
|
||||
void on_upForcePlus_Btn_pressed();
|
||||
|
||||
void on_upForceMinus_Btn_pressed();
|
||||
|
||||
void on_upForcePlus_Btn_released();
|
||||
|
||||
void on_upForceMinus_Btn_released();
|
||||
|
||||
void slotSpeedDialogClosed();
|
||||
|
||||
//模拟数据
|
||||
void slotSimulateData();
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
/******游戏状态*****
|
||||
*@int8_t state 1-开始 0-关闭
|
||||
***/
|
||||
void signalGameStateChanged(int8_t state);
|
||||
|
||||
private:
|
||||
//解析游戏数据
|
||||
void parseGameMsg(QByteArray jsonArray);
|
||||
|
||||
//给游戏发送实时数据
|
||||
void sendGameControlParam(ST_GameControlParam);
|
||||
//停止游戏指令
|
||||
void sendStopCmd();
|
||||
//开始游戏
|
||||
void startGameCmd();
|
||||
//暂停游戏
|
||||
void pauseGameCmd();
|
||||
|
||||
void sendStopCmdThreeTimes();
|
||||
//计算结果数据
|
||||
void calculateResultData();
|
||||
|
||||
void initButton();
|
||||
|
||||
//退出训练
|
||||
void quitTrain();
|
||||
|
||||
//模式提示
|
||||
void changeModeTips(QString str);
|
||||
|
||||
//根据模式切换按钮状态
|
||||
void switchButtonState(int8_t);
|
||||
|
||||
void setbackBtVisible(bool isShow);
|
||||
|
||||
//给电刺激发送实时参数
|
||||
void sendRealTimeFesParam(ST_FESRealTimeParam);
|
||||
void testTipsDialog();
|
||||
protected:
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
private:
|
||||
Ui::GameDisplayPage *ui;
|
||||
QPropertyAnimation *m_leftAnimation,*m_rightAnimation;
|
||||
bool m_openState;
|
||||
QList<QLabel*> m_channelAList,m_channelBList;
|
||||
int upDirection; //上肢旋转方向 1-正 0-逆
|
||||
int downDirection; //下肢旋转方向 1-正 0-逆
|
||||
int8_t m_bodyPart; //训练部位 0-上肢 1-下肢 2-上下肢
|
||||
SpasmTipsDialog *m_spasmTipsDialog;
|
||||
|
||||
QTimer *heartTimer;
|
||||
QTimer *countDownTimer; //倒计时
|
||||
QTimer *paramPressTimer; //持续按主速度参数,改变值
|
||||
QTimer *paramPressForceTimer; //持续按主阻力参数,改变值
|
||||
ST_BicycleParam m_st_bicycleParam; //启动参数
|
||||
int m_startNum; //倒计时初始值
|
||||
int m_spasmTimes; //痉挛次数
|
||||
QUdpSocket *m_gameSocket;
|
||||
ST_TrainReport st_trainReport; //训练报告数据
|
||||
|
||||
ST_PatientMsg st_patientMsg; //患者信息
|
||||
|
||||
int8_t m_currentMode; //当前模式
|
||||
int8_t m_AP_mode; //切换主被动的模式
|
||||
|
||||
QList<QPair<int,int>> balanceList;//左右平衡
|
||||
|
||||
QList<uint8_t> resistentList; //阻力集合
|
||||
|
||||
QList<uint8_t> speedList; //速度集合
|
||||
|
||||
TrainReport *m_reportDialog; //正常报告,3行3图的报告
|
||||
|
||||
TrainReportTwoTwo *m_trainReportTwoTwo; //2行2图的报告
|
||||
|
||||
TrainReportTwoThree *m_trainReportTwoThree; //2行3图的报告
|
||||
|
||||
TrainReportThreeTwo *m_trainReportThreeTwo; //3行2图的报告
|
||||
|
||||
QuitGameDialog *m_quitDialog;
|
||||
|
||||
EmergencyStopDialog *m_emergencyDialog;
|
||||
|
||||
int8_t gameState; // 游戏训练状态 0-未开始 1-其他(1开始,2暂停)
|
||||
|
||||
int heartCount; //心跳次数,用于检测通信
|
||||
|
||||
E_TRAINSTATE E_gameState;
|
||||
|
||||
int8_t m_currentDirection; //当前方向
|
||||
|
||||
int8_t m_gameRebackState; //游戏反馈的状态
|
||||
|
||||
QString m_tipStr;
|
||||
|
||||
long m_switchTimes;
|
||||
|
||||
int m_currentSpeed; //当前速度
|
||||
bool m_decreasingSpeed,m_increasingSpeed; //判断连续按住速度是增还是减少
|
||||
bool m_decreasingForce,m_increasingForce; //判断连续按住阻力是增还是减少
|
||||
|
||||
SoundDialog *m_soundDialog;
|
||||
QuitBySpeedDialog *m_quitBySpeedDialog; // 速度退出提醒
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // GAMEDISPLAYPAGE_H
|
||||
2861
ZBD_IIIDL_S_Project/Src/GameControl/gamedisplaypage.ui
Normal file
2861
ZBD_IIIDL_S_Project/Src/GameControl/gamedisplaypage.ui
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user