-
Notifications
You must be signed in to change notification settings - Fork 0
/
FiveChess.cpp
94 lines (85 loc) · 2.47 KB
/
FiveChess.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "fivechess.h"
#include "battlegui.h"
#include "clientthread.h"
#include "networksettingdialog.h"
#include "serverthread.h"
#include "ui_FiveChess.h"
#include "ui_chooseCorS.h"
#include "waitdialog.h"
#include <QDebug>
#include <QLocale>
FiveChess::FiveChess(QWidget* parent) : QMainWindow(parent), ui(new Ui::FiveChess)
{
ui->setupUi(this);
connect(ui->pushButtonNew, &QPushButton::clicked, this, &FiveChess::newFiveChessGame);
connect(ui->pushButtonLoad, &QPushButton::clicked, this,
&FiveChess::loadFiveChessGame);
connect(ui->actionEnglish, &QAction::triggered, this, [&] {
translateUi(QLocale::UnitedStates);
qDebug() << "!!#en_us";
});
connect(ui->actionChinese, &QAction::triggered, this, [&] {
translateUi(QLocale::China);
qDebug() << "!!#zh_cn";
});
connect(ui->pushButtonNetworkGame, &QPushButton::clicked, this,
&FiveChess::newNetworkFiveChessGame);
}
FiveChess::~FiveChess() { delete ui; }
void FiveChess::newFiveChessGame()
{
hide();
battleGui* gameGui = new battleGui();
gameGui->setTranslator(tsor);
gameGui->show();
}
void FiveChess::loadFiveChessGame()
{
if (chessBoard.loadBoard())
{
chessBoard.setOpt(ChessBoardCore::PaintOptType::chess);
qDebug() << "OK!" << endl;
newFiveChessGame();
}
}
void FiveChess::newNetworkFiveChessGame()
{
NetworkSettingDialog settingDialog;
settingDialog.exec();
QDialog* chooseDialog = new QDialog(this);
Ui::ChooseCorSDialog* chooseDialogUi = new Ui::ChooseCorSDialog;
chooseDialogUi->setupUi(chooseDialog);
connect(chooseDialogUi->clientPushButton, &QPushButton::clicked, this, [&] {
clientThread = new ClientThread;
clientThread->run();
chessBoard.setPlayMode(ChessBoardCore::PlayMode::client);
chooseDialog->close();
});
connect(chooseDialogUi->serverPushButton, &QPushButton::clicked, this, [&] {
serverThread = new ServerThread;
serverThread->run();
chessBoard.setPlayMode(ChessBoardCore::PlayMode::server);
chooseDialog->close();
});
chooseDialog->exec();
newFiveChessGame();
}
void FiveChess::translateUi(int value)
{
switch (value)
{
case QLocale::China:
{
tsor->load(":/lang/zh_CN.qm");
break;
}
case QLocale::UnitedStates:
{
tsor->load(":/lang/en_US.qm");
break;
}
default: { break;
}
}
ui->retranslateUi(this);
}