302 lines
9.3 KiB
C++
302 lines
9.3 KiB
C++
|
#include "cmainwindow.h"
|
|||
|
#include "ui_cmainwindow.h"
|
|||
|
#include "mainwindowpagecontrol.h"
|
|||
|
#include "currentuserdata.h"
|
|||
|
#include <QDebug>
|
|||
|
#include <QTimer>
|
|||
|
#include <windows.h>
|
|||
|
#include <QHBoxLayout>
|
|||
|
#include <QProcess>
|
|||
|
#include "gamecontrol.h"
|
|||
|
#include "fescontroldialog.h"
|
|||
|
CMainWindow::CMainWindow(QWidget *parent) :
|
|||
|
QWidget(parent),
|
|||
|
ui(new Ui::CMainWindow),
|
|||
|
m_gameDisplayPage(NULL),
|
|||
|
gamedialog(NULL),
|
|||
|
grabWindowTimer(NULL)
|
|||
|
{
|
|||
|
ui->setupUi(this);
|
|||
|
|
|||
|
ui->title_Widget->hide();
|
|||
|
ui->stackedWidget->setGeometry(0,0,1920,1080);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
this->setWindowFlags(Qt::FramelessWindowHint); //设置无边框
|
|||
|
qRegisterMetaType<E_PAGENAME>("E_PAGENAME");
|
|||
|
connect(MainWindowPageControl::getInstance(),SIGNAL(signalSwitchPage(E_PAGENAME)),this,SLOT(slotSwitchPage(E_PAGENAME)));
|
|||
|
connect(CurrentUserData::getInstace(),SIGNAL(signalUserChanged()),this,SLOT(slotCurrentUserChanged()));
|
|||
|
//默认为主界面
|
|||
|
// setAttribute(Qt::WA_DeleteOnClose,false);
|
|||
|
ui->stackedWidget->setCurrentIndex(0);
|
|||
|
m_gameDisplayPage = new GameDisplayPage();
|
|||
|
|
|||
|
connect(m_gameDisplayPage,SIGNAL(signalGameStateChanged(int8_t)),this,SLOT(slotGameStateChanged(int8_t)));
|
|||
|
|
|||
|
m_Process = new QProcess();
|
|||
|
|
|||
|
connect(ui->title_Widget,SIGNAL(signalCloseWindow()),this,SLOT(closeWindow()));
|
|||
|
|
|||
|
gamedialog = new QDialog;
|
|||
|
m_loginWidget = new LoginWidget();
|
|||
|
gamedialog->stackUnder(m_gameDisplayPage);
|
|||
|
grabWindowTimer = new QTimer();
|
|||
|
connect(grabWindowTimer,SIGNAL(timeout()),this,SLOT(slotGrabWindow()));
|
|||
|
|
|||
|
connect(ui->FES_Page,SIGNAL(signalStartGame()),ui->FESCar_Page,SLOT(slotStartGame()));
|
|||
|
//从参数界面传递到训练界面
|
|||
|
connect(ui->trainParam_Page,&TrainingParamSetting::signalTrainParamChanged,ui->FESCar_Page,&ArmOrLeg::slotRecvTrainParamChanged);
|
|||
|
//训练页面发消息,让tittle页面保存截图
|
|||
|
connect(ui->FESCar_Page,&ArmOrLeg::saveUpPictureSignal,ui->title_Widget,&TitleWidget::slotSaveUpPicture);
|
|||
|
//从训练界面传递到参数界面
|
|||
|
connect(ui->FESCar_Page,&ArmOrLeg::signalBicycleParamChanged,ui->trainParam_Page,&TrainingParamSetting::slotBicycleParamChanged);
|
|||
|
//训练界面打开,跟新游戏配置默认参数
|
|||
|
connect(ui->Main_Page,&TrainManager::signalOpenTrainManagerPage,ui->trainParam_Page,&TrainingParamSetting::slotResetParam);
|
|||
|
|
|||
|
// connect(m_loginWidget,SIGNAL(signalCloseApp),this,SLOT(closeWindow()));
|
|||
|
}
|
|||
|
|
|||
|
CMainWindow::~CMainWindow()
|
|||
|
{
|
|||
|
if(gamedialog)
|
|||
|
delete gamedialog;
|
|||
|
if(m_gameDisplayPage)
|
|||
|
delete m_gameDisplayPage;
|
|||
|
if(grabWindowTimer)
|
|||
|
delete grabWindowTimer;
|
|||
|
delete ui;
|
|||
|
}
|
|||
|
|
|||
|
void CMainWindow::switchPage(E_PAGENAME E_Page)
|
|||
|
{
|
|||
|
switch(E_Page)
|
|||
|
{
|
|||
|
case MainPage_E:
|
|||
|
gamedialog->close();
|
|||
|
ui->stackedWidget->setGeometry(0,0,1920,1080);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->Main_Page);
|
|||
|
ui->title_Widget->hide();
|
|||
|
qDebug() <<"来到了主页";
|
|||
|
emit ui->Main_Page->signalOpenTrainManagerPage();
|
|||
|
|
|||
|
break;
|
|||
|
case TrainingPage_E://游戏训练界面
|
|||
|
// ui->stackedWidget->setCurrentWidget(ui->game_Page);
|
|||
|
startGame_Btn_clicked();
|
|||
|
// QTimer::singleShot(1000,this,SLOT(slot_Timerout()));//同上,就是参数不同
|
|||
|
break;
|
|||
|
case UserPage_E:
|
|||
|
ui->stackedWidget->setGeometry(0,100,1920,980);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->userMsg_Page);
|
|||
|
ui->title_Widget->show();
|
|||
|
break;
|
|||
|
case SettingPage_E:
|
|||
|
ui->stackedWidget->setGeometry(0,100,1920,980);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->setting_Page);
|
|||
|
ui->title_Widget->show();
|
|||
|
break;
|
|||
|
case BicycleParamSet_E:
|
|||
|
ui->stackedWidget->setGeometry(0,100,1920,980);
|
|||
|
//qDebug() <<"普通单车";
|
|||
|
ui->FESCar_Page->setTrainType(0);
|
|||
|
ui->title_Widget->setTrainType(0);
|
|||
|
ui->trainParam_Page->setTrainType(0);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->FESCar_Page);
|
|||
|
ui->title_Widget->show();
|
|||
|
break;
|
|||
|
case FesBicycleParamSet_E:
|
|||
|
ui->stackedWidget->setGeometry(0,100,1920,980);
|
|||
|
//qDebug() <<"FES单车";
|
|||
|
ui->FESCar_Page->setTrainType(1);
|
|||
|
ui->title_Widget->setTrainType(1);
|
|||
|
ui->trainParam_Page->setTrainType(1);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->FESCar_Page);
|
|||
|
ui->title_Widget->show();
|
|||
|
break;
|
|||
|
case FesParamSet_E:
|
|||
|
ui->stackedWidget->setGeometry(0,100,1920,980);
|
|||
|
ui->title_Widget->setTrainType(0);
|
|||
|
ui->FES_Page->switchPage(ONLY_FES_E);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->FES_Page);
|
|||
|
ui->title_Widget->show();
|
|||
|
break;
|
|||
|
case BicycleToFes_E:
|
|||
|
ui->stackedWidget->setGeometry(0,100,1920,980);
|
|||
|
ui->FES_Page->switchPage(BICYCLE_FES_E);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->FES_Page);
|
|||
|
ui->title_Widget->show();
|
|||
|
break;
|
|||
|
case TrainingParamSetting_E: //训练参数设置页
|
|||
|
ui->stackedWidget->setGeometry(0,100,1920,980);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->trainParam_Page);
|
|||
|
ui->title_Widget->show();
|
|||
|
break;
|
|||
|
case BrainTraining: //训练参数设置页
|
|||
|
ui->stackedWidget->setGeometry(0,100,1920,980);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->Brain_Page);
|
|||
|
ui->title_Widget->show();
|
|||
|
break;
|
|||
|
case visionTrain: //训练参数设置页
|
|||
|
ui->stackedWidget->setGeometry(0,100,1920,980);
|
|||
|
ui->stackedWidget->setCurrentWidget(ui->Vision_Page);
|
|||
|
ui->title_Widget->show();
|
|||
|
break;
|
|||
|
|
|||
|
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void CMainWindow::slotSwitchPage(E_PAGENAME page)
|
|||
|
{
|
|||
|
switchPage(page);
|
|||
|
ui->title_Widget->setTitleByPage(page);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void CMainWindow::slotCurrentUserChanged()
|
|||
|
{
|
|||
|
ui->title_Widget->setUser(CurrentUserData::getInstace()->getCurrentPatientMsg());
|
|||
|
}
|
|||
|
|
|||
|
void CMainWindow::startGame_Btn_clicked()
|
|||
|
{
|
|||
|
connect(m_Process,&QProcess::errorOccurred,[=](QProcess::ProcessError error){qDebug()<<error;});
|
|||
|
// connect(m_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;
|
|||
|
// });
|
|||
|
|
|||
|
QString destPath = GameControl::getInstance()->getCurrentGameMsg().gamePath + GameControl::getInstance()->getCurrentGameMsg().gameName;
|
|||
|
|
|||
|
startGame(destPath);
|
|||
|
|
|||
|
grabWindowTimer->start(300);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void CMainWindow::slotGrabWindow()
|
|||
|
{
|
|||
|
WId hwnd = 0;
|
|||
|
if(1 == GameControl::getInstance()->getCurrentGameMsg().gameID)
|
|||
|
hwnd = (WId)FindWindow(L"UnityWndClass",L"TJ_SXZ001_SingleplayerBicycleRace");
|
|||
|
else if(2 == GameControl::getInstance()->getCurrentGameMsg().gameID)
|
|||
|
hwnd = (WId)FindWindow(L"UnityWndClass",L"TJ_SXZ002_MultiplayerBicycleRace_LBY");
|
|||
|
else if(3 == GameControl::getInstance()->getCurrentGameMsg().gameID)
|
|||
|
hwnd = (WId)FindWindow(L"UnityWndClass",L"TJ_SXZ003_MultiplayerRaceSciFi");
|
|||
|
else if(4 == GameControl::getInstance()->getCurrentGameMsg().gameID)
|
|||
|
hwnd = (WId)FindWindow(L"UnityWndClass",L"TJ_SXZ004_CatchFish");
|
|||
|
|
|||
|
|
|||
|
if(IsHungAppWindow(HWND(hwnd)))
|
|||
|
{
|
|||
|
qDebug()<<"正在运行";
|
|||
|
}
|
|||
|
|
|||
|
if(hwnd > 0)
|
|||
|
{
|
|||
|
grabWindowTimer->stop();
|
|||
|
m_window = QWindow::fromWinId(hwnd);
|
|||
|
container = createWindowContainer(m_window,this);
|
|||
|
|
|||
|
gamedialog->setWindowFlags(Qt::FramelessWindowHint);
|
|||
|
|
|||
|
QGridLayout *hLayout = new QGridLayout(this);
|
|||
|
hLayout->setMargin(0);
|
|||
|
hLayout->addWidget(container);
|
|||
|
|
|||
|
if(gamedialog->layout() != NULL)
|
|||
|
delete gamedialog->layout();
|
|||
|
gamedialog->setLayout(hLayout);
|
|||
|
gamedialog->show();
|
|||
|
|
|||
|
gamedialog->resize(1920,980);
|
|||
|
gamedialog->move(0,100);
|
|||
|
|
|||
|
// m_gameDisplayPage->show();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void CMainWindow::slotGameStateChanged(int8_t state)
|
|||
|
{
|
|||
|
switch(state)
|
|||
|
{
|
|||
|
case 0: //停止游戏
|
|||
|
{
|
|||
|
m_gameDisplayPage->close();
|
|||
|
gamedialog->close();
|
|||
|
slotSwitchPage(MainPage_E);
|
|||
|
}
|
|||
|
break;
|
|||
|
case 1: //开始游戏
|
|||
|
m_gameDisplayPage->show();
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void CMainWindow::closeWindow()
|
|||
|
{
|
|||
|
//关闭所有设备
|
|||
|
qDebug()<<"运行了";
|
|||
|
FesControlDialog::getInstance()->turnoffDevice(1,1);
|
|||
|
this->close();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void CMainWindow::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 CMainWindow::slot_Timerout()
|
|||
|
{
|
|||
|
// m_gameDisplayPage->show();
|
|||
|
}
|
|||
|
|
|||
|
void CMainWindow::showEvent(QShowEvent *event)
|
|||
|
{
|
|||
|
Q_UNUSED(event)
|
|||
|
signalShowCompleted();
|
|||
|
}
|
|||
|
|
|||
|
void CMainWindow::changeEvent(QEvent* event)
|
|||
|
{
|
|||
|
switch (event->type())
|
|||
|
{
|
|||
|
case QEvent::LanguageChange:
|
|||
|
ui->retranslateUi(this);
|
|||
|
break;
|
|||
|
default:
|
|||
|
QWidget::changeEvent(event);
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|