diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e0e1653..14c3129 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -58,6 +58,12 @@ MainWindow::MainWindow(QWidget *parent) this->pActionRenju = new QAction("Renju", this); this->pActionCaro = new QAction("Caro", this); this->pActionNumOfMove = new QAction("Number of move", this); + this->pActionXAxisLetter = new QAction("X-axis Letter", this); + this->pActionYAxisLetter = new QAction("Y-axis Letter", this); + this->pActionXAxisStartFrom_1 = new QAction("X-axis start from 1", this); + this->pActionYAxisStartFrom_1 = new QAction("Y-axis start from 1", this); + this->pActionTimeSecond = new QAction("Countdown With Second", this); + this->pActionGridSize = new QAction("Grid Size", this); this->pActionPlayerSetting = new QAction("Setting", this); this->pActionVer = new QAction("Ver Info", this); this->pActionFeedback = new QAction("Feedback", this); @@ -83,6 +89,22 @@ MainWindow::MainWindow(QWidget *parent) this->pActionNumOfMove->setShortcut(QKeySequence(Qt::Key_V)); this->pActionNumOfMove->setCheckable(true); this->pActionNumOfMove->setChecked(false); + this->pActionXAxisLetter->setShortcut(QKeySequence(Qt::Key_X)); + this->pActionXAxisLetter->setCheckable(true); + this->pActionXAxisLetter->setChecked(false); + this->pActionYAxisLetter->setShortcut(QKeySequence(Qt::Key_Y)); + this->pActionYAxisLetter->setCheckable(true); + this->pActionYAxisLetter->setChecked(false); + this->pActionXAxisStartFrom_1->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); + this->pActionXAxisStartFrom_1->setCheckable(true); + this->pActionXAxisStartFrom_1->setChecked(false); + this->pActionYAxisStartFrom_1->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Y)); + this->pActionYAxisStartFrom_1->setCheckable(true); + this->pActionYAxisStartFrom_1->setChecked(false); + this->pActionTimeSecond->setShortcut(QKeySequence(Qt::Key_Z)); + this->pActionTimeSecond->setCheckable(true); + this->pActionTimeSecond->setChecked(false); + this->pActionGridSize->setShortcut(QKeySequence(Qt::Key_G)); this->pMenuSetting->addAction(this->pActionBoardSize); this->pMenuSetting->addAction(this->pActionTimeoutMatch); this->pMenuSetting->addAction(this->pActionTimeoutTurn); @@ -95,6 +117,12 @@ MainWindow::MainWindow(QWidget *parent) this->pMenuGame->addAction(this->pActionTakeBack); this->pMenuPlayer->addAction(this->pActionPlayerSetting); this->pMenuShow->addAction(this->pActionNumOfMove); + this->pMenuShow->addAction(this->pActionXAxisLetter); + this->pMenuShow->addAction(this->pActionYAxisLetter); + this->pMenuShow->addAction(this->pActionXAxisStartFrom_1); + this->pMenuShow->addAction(this->pActionYAxisStartFrom_1); + this->pMenuShow->addAction(this->pActionTimeSecond); + this->pMenuShow->addAction(this->pActionGridSize); this->pMenuShow->addAction(this->pActionSkin); this->pMenuAbout->addAction(this->pActionVer); this->pMenuAbout->addAction(this->pActionFeedback); @@ -127,6 +155,8 @@ MainWindow::MainWindow(QWidget *parent) #endif this->setWindowIcon(QIcon(":/icon/icon.jpg")); + this->RECT_WIDTH = 36; + this->RECT_HEIGHT = 36; this->mBoard = new Board(); // pair pBSize(15, 15); @@ -151,6 +181,7 @@ MainWindow::MainWindow(QWidget *parent) for (size_t i = 0; i < 5; i++) this->m_images.push_back(pm.copy((int)(i * (pm.width()) * 0.2), 0, (int)((pm.width()) * 0.2), pm.height()).scaled(RECT_WIDTH, RECT_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation)); } + this->m_cur_skin_idx = 6; if (this->m_images.size() != 5) this->m_bSkin = false; @@ -206,6 +237,7 @@ MainWindow::MainWindow(QWidget *parent) connect(this->pRuleActionGroup,SIGNAL(triggered(QAction *)),this,SLOT(On_ClickedRuleActionGroup(QAction*))); connect(this->pActionPlayerSetting, SIGNAL(triggered()), this, SLOT(OnActionPlayerSetting())); connect(this->pActionNumOfMove, SIGNAL(triggered()), this, SLOT(OnActionNumOfMove())); + connect(this->pActionGridSize, SIGNAL(triggered()), this, SLOT(OnActionGridSize())); connect(this->pActionVer, SIGNAL(triggered()), this, SLOT(OnActionVer())); connect(this->pActionFeedback, SIGNAL(triggered()), this, SLOT(OnActionFeedback())); connect(this->pActionLicense, SIGNAL(triggered()), this, SLOT(OnActionLicense())); @@ -368,6 +400,36 @@ MainWindow::~MainWindow() delete this->pActionNumOfMove; this->pActionNumOfMove = nullptr; } + if (nullptr != pActionXAxisLetter) + { + delete this->pActionXAxisLetter; + this->pActionXAxisLetter = nullptr; + } + if (nullptr != pActionYAxisLetter) + { + delete this->pActionYAxisLetter; + this->pActionYAxisLetter = nullptr; + } + if (nullptr != pActionXAxisStartFrom_1) + { + delete this->pActionXAxisStartFrom_1; + this->pActionXAxisStartFrom_1 = nullptr; + } + if (nullptr != pActionYAxisStartFrom_1) + { + delete this->pActionYAxisStartFrom_1; + this->pActionYAxisStartFrom_1 = nullptr; + } + if (nullptr != pActionTimeSecond) + { + delete this->pActionTimeSecond; + this->pActionTimeSecond = nullptr; + } + if (nullptr != pActionGridSize) + { + delete this->pActionGridSize; + this->pActionGridSize = nullptr; + } if (nullptr != this->pActionLicense) { delete this->pActionLicense; @@ -574,7 +636,10 @@ void MainWindow::DrawTimeLeft() { this->m_time_left_p1 = this->m_timeout_match - this->m_T1->getElapsed(); painter.setPen(QPen(QColor(Qt::black), 2)); - painter.drawText(50, (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignLeft, QString::fromStdString(to_string(this->m_time_left_p1) + "ms")); + if (this->pActionTimeSecond->isChecked()) + painter.drawText(this->RECT_WIDTH + 15, (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignLeft, QString::fromStdString(to_string(this->m_time_left_p1 / 1000) + "s")); + else + painter.drawText(this->RECT_WIDTH + 15, (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignLeft, QString::fromStdString(to_string(this->m_time_left_p1) + "ms")); } else { @@ -591,7 +656,10 @@ void MainWindow::DrawTimeLeft() { this->m_time_left_p2 = this->m_timeout_match - this->m_T2->getElapsed(); painter.setPen(QPen(QColor(Qt::black), 2)); - painter.drawText(this->geometry().width() - 200, (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignRight, QString::fromStdString(to_string(this->m_time_left_p2) + "ms")); + if (this->pActionTimeSecond->isChecked()) + painter.drawText((int)(this->geometry().width() - 170 - this->RECT_WIDTH), (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignRight, QString::fromStdString(to_string(this->m_time_left_p2 / 1000) + "s")); + else + painter.drawText((int)(this->geometry().width() - 170 - this->RECT_WIDTH), (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignRight, QString::fromStdString(to_string(this->m_time_left_p2) + "ms")); } else { @@ -724,18 +792,18 @@ void MainWindow::DrawPlayerName() painter.setPen(QPen(QColor(Qt::black), 2)); if (!this->m_p1_name.isEmpty()) - painter.drawText(50, this->geometry().height() - 30, 150, 50, Qt::AlignLeft, this->m_p1_name); + painter.drawText(this->RECT_WIDTH + 15, this->geometry().height() - 30, 150, 50, Qt::AlignLeft, this->m_p1_name); else if (this->m_manager->m_p1->m_isComputer) - painter.drawText(50, this->geometry().height() - 30, 150, 50, Qt::AlignLeft, "AI"); + painter.drawText(this->RECT_WIDTH + 15, this->geometry().height() - 30, 150, 50, Qt::AlignLeft, "AI"); else - painter.drawText(50, this->geometry().height() - 30, 150, 50, Qt::AlignLeft, "Human"); + painter.drawText(this->RECT_WIDTH + 15, this->geometry().height() - 30, 150, 50, Qt::AlignLeft, "Human"); if (!this->m_p2_name.isEmpty()) - painter.drawText(this->geometry().width() - 200, this->geometry().height() - 30, 150, 50, Qt::AlignRight, this->m_p2_name); + painter.drawText((int)(this->geometry().width() - 170 - this->RECT_WIDTH), (int)(this->geometry().height() - 30), 150, 50, Qt::AlignRight, this->m_p2_name); else if (this->m_manager->m_p2->m_isComputer) - painter.drawText(this->geometry().width() - 200, this->geometry().height() - 30, 150, 50, Qt::AlignRight, "AI"); + painter.drawText((int)(this->geometry().width() - 170 - this->RECT_WIDTH), (int)(this->geometry().height() - 30), 150, 50, Qt::AlignRight, "AI"); else - painter.drawText(this->geometry().width() - 200, this->geometry().height() - 30, 150, 50, Qt::AlignRight, "Human"); + painter.drawText((int)(this->geometry().width() - 170 - this->RECT_WIDTH), (int)(this->geometry().height() - 30), 150, 50, Qt::AlignRight, "Human"); } void MainWindow::DrawIndication() @@ -743,19 +811,39 @@ void MainWindow::DrawIndication() if (nullptr != this->mBoard) { QFont font; - font.setPixelSize(10); + font.setPixelSize(12); font.setItalic(true); - // font.setBold(true); + font.setBold(true); QPainter painter(this); painter.setFont(font); painter.setPen(QPen(QColor(Qt::black), 2)); for (size_t i = 0; i < this->mBoard->getBSize().first; i++) - painter.drawText((i + 1) * RECT_WIDTH + 5, (int)(RECT_HEIGHT * 1.5), 20, 20, Qt::AlignRight, QString::fromStdString(to_string(i))); + { + if (this->pActionXAxisLetter->isChecked() && i < 26) + painter.drawText((i + 1) * RECT_WIDTH + 5, (int)(RECT_HEIGHT * 1.5), 20, 20, Qt::AlignRight, QString::fromStdString(string(1, 'A' + i))); + else + { + if (this->pActionXAxisStartFrom_1->isChecked()) + painter.drawText((i + 1) * RECT_WIDTH + 5, (int)(RECT_HEIGHT * 1.5), 20, 20, Qt::AlignRight, QString::fromStdString(to_string(i + 1))); + else + painter.drawText((i + 1) * RECT_WIDTH + 5, (int)(RECT_HEIGHT * 1.5), 20, 20, Qt::AlignRight, QString::fromStdString(to_string(i))); + } + } for (size_t i = 0; i < this->mBoard->getBSize().second; i++) - painter.drawText((int)(RECT_WIDTH * 0.5), (i + 2) * RECT_HEIGHT + 5, 20, 20, Qt::AlignBottom, QString::fromStdString(to_string(i))); + { + if (this->pActionYAxisLetter->isChecked() && i < 26) + painter.drawText((int)(RECT_WIDTH * 0.4), (i + 2) * RECT_HEIGHT + 5, 20, 20, Qt::AlignBottom, QString::fromStdString(string(1, 'A' + i))); + else + { + if (this->pActionYAxisStartFrom_1->isChecked()) + painter.drawText((int)(RECT_WIDTH * 0.4), (i + 2) * RECT_HEIGHT + 5, 20, 20, Qt::AlignBottom, QString::fromStdString(to_string(i + 1))); + else + painter.drawText((int)(RECT_WIDTH * 0.4), (i + 2) * RECT_HEIGHT + 5, 20, 20, Qt::AlignBottom, QString::fromStdString(to_string(i))); + } + } } } @@ -1511,6 +1599,83 @@ void MainWindow::OnActionMaxMemory() } } +void MainWindow::OnActionGridSize() +{ + // if (this->mState != GAME_STATE::PLAYING) + // { + bool ok = false; + int i_get = QInputDialog::getInt(this, "Grid Size", "Please input grid size:", 36, 25, 50, + 1, &ok, Qt::MSWindowsFixedSizeDialogHint); + if (ok) + { + this->RECT_WIDTH = i_get; + this->RECT_HEIGHT = i_get; + bool bLoad = false; + QPixmap pm; + this->m_images.clear(); + + switch (this->m_cur_skin_idx) + { + case 1: + bLoad = pm.load(":/skins/bold.bmp"); + break; + case 2: + bLoad = pm.load(":/skins/fontanGomo.bmp"); + break; + case 3: + bLoad = pm.load(":/skins/gems.bmp"); + break; + case 4: + bLoad = pm.load(":/skins/gomoku.bmp"); + break; + case 5: + bLoad = pm.load(":/skins/HGarden.bmp"); + break; + case 6: + bLoad = pm.load(":/skins/HGarden2.bmp"); + break; + case 7: + bLoad = pm.load(":/skins/light.bmp"); + break; + case 8: + bLoad = pm.load(":/skins/pisq.bmp"); + break; + case 9: + bLoad = pm.load(":/skins/rain.bmp"); + break; + case 10: + bLoad = pm.load(":/skins/star.bmp"); + break; + case 11: + bLoad = pm.load(":/skins/whitex.bmp"); + break; + case 12: + bLoad = pm.load(":/skins/wood.bmp"); + break; + case 13: + bLoad = pm.load(":/skins/yellow.bmp"); + break; + default: + // bLoad = pm.load(":/skins/HGarden2.bmp"); + break; + } + + if (!pm.isNull() && bLoad) + { + for (size_t i = 0; i < 5; i++) + this->m_images.push_back(pm.copy((int)(i * (pm.width()) * 0.2), 0, (int)((pm.width()) * 0.2), pm.height()).scaled(RECT_WIDTH, RECT_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + + if (this->m_images.size() != 5) + this->m_bSkin = false; + else + this->m_bSkin = true; + } + + resize((this->mBoard->getBSize().first + 2) * RECT_WIDTH, (this->mBoard->getBSize().second + 3) * RECT_HEIGHT + this->pMenuBar->height()); + } + // } +} + void MainWindow::OnActionSkin() { if (this->mState != GAME_STATE::PLAYING) @@ -1518,7 +1683,7 @@ void MainWindow::OnActionSkin() bool ok = false; QStringList s_items; s_items << "none" << "bold" << "fontanGomo" << "gems" << "gomoku" << "HGarden" << "HGarden2" << "light" << "pisq" << "rain" << "star" << "whitex" << "wood" << "yellow"; - QString s_get = QInputDialog::getItem(this, "Skin", "Please choose skin:", s_items, 0, false, + QString s_get = QInputDialog::getItem(this, "Skin", "Please choose skin:", s_items, this->m_cur_skin_idx, false, &ok, Qt::MSWindowsFixedSizeDialogHint); if (ok) { @@ -1526,6 +1691,7 @@ void MainWindow::OnActionSkin() { this->m_bSkin = false; this->m_images.clear(); + this->m_cur_skin_idx = 0; } else { @@ -1534,31 +1700,70 @@ void MainWindow::OnActionSkin() this->m_images.clear(); if (QString::compare(s_get, "bold") == 0) + { bLoad = pm.load(":/skins/bold.bmp"); + this->m_cur_skin_idx = 1; + } else if (QString::compare(s_get, "fontanGomo") == 0) + { bLoad = pm.load(":/skins/fontanGomo.bmp"); + this->m_cur_skin_idx = 2; + } else if (QString::compare(s_get, "gems") == 0) + { bLoad = pm.load(":/skins/gems.bmp"); + this->m_cur_skin_idx = 3; + } else if (QString::compare(s_get, "gomoku") == 0) + { bLoad = pm.load(":/skins/gomoku.bmp"); + this->m_cur_skin_idx = 4; + } else if (QString::compare(s_get, "HGarden") == 0) + { bLoad = pm.load(":/skins/HGarden.bmp"); + this->m_cur_skin_idx = 5; + } else if (QString::compare(s_get, "HGarden2") == 0) + { bLoad = pm.load(":/skins/HGarden2.bmp"); + this->m_cur_skin_idx = 6; + } else if (QString::compare(s_get, "light") == 0) + { bLoad = pm.load(":/skins/light.bmp"); + this->m_cur_skin_idx = 7; + } else if (QString::compare(s_get, "pisq") == 0) + { bLoad = pm.load(":/skins/pisq.bmp"); + this->m_cur_skin_idx = 8; + } else if (QString::compare(s_get, "rain") == 0) + { bLoad = pm.load(":/skins/rain.bmp"); + this->m_cur_skin_idx = 9; + } else if (QString::compare(s_get, "star") == 0) + { bLoad = pm.load(":/skins/star.bmp"); + this->m_cur_skin_idx = 10; + } else if (QString::compare(s_get, "whitex") == 0) + { bLoad = pm.load(":/skins/whitex.bmp"); + this->m_cur_skin_idx = 11; + } else if (QString::compare(s_get, "wood") == 0) + { bLoad = pm.load(":/skins/wood.bmp"); + this->m_cur_skin_idx = 12; + } else if (QString::compare(s_get, "yellow") == 0) + { bLoad = pm.load(":/skins/yellow.bmp"); + this->m_cur_skin_idx = 13; + } if (!pm.isNull() && bLoad) { @@ -1701,7 +1906,7 @@ void MainWindow::OnActionNumOfMove() void MainWindow::OnActionVer() { - const QString strVerNum = "Ver Num: 0.5.30-features\n"; + const QString strVerNum = "Ver Num: 0.5.42-features\n"; QString strBuildTime = "Build at "; strBuildTime.append(__TIMESTAMP__); strBuildTime.append("\n"); diff --git a/src/mainwindow.h b/src/mainwindow.h index 7f3e3b8..6e67188 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -44,9 +44,6 @@ #include "S2BResDialog.h" #include "timer.h" -#define RECT_WIDTH (36) -#define RECT_HEIGHT (36) - typedef enum game_state { IDLE, @@ -96,6 +93,12 @@ class MainWindow : public QMainWindow QAction *pActionRenju; QAction *pActionCaro; QAction *pActionNumOfMove; + QAction *pActionXAxisLetter; + QAction *pActionYAxisLetter; + QAction *pActionXAxisStartFrom_1; + QAction *pActionYAxisStartFrom_1; + QAction *pActionTimeSecond; + QAction *pActionGridSize; QAction *pActionPlayerSetting; QAction *pActionVer; QAction *pActionFeedback; @@ -113,6 +116,7 @@ public slots: void OnActionTimeoutMatch(); void OnActionTimeoutTurn(); void OnActionMaxMemory(); + void OnActionGridSize(); void OnActionSkin(); void On_ClickedRuleActionGroup(QAction *); void OnActionPlayerSetting(); @@ -183,7 +187,10 @@ public slots: long long m_max_memory; long long m_time_left_p1; long long m_time_left_p2; + unsigned int m_cur_skin_idx; int m_Rule; + int RECT_WIDTH; + int RECT_HEIGHT; GAME_STATE mState; bool m_bBoard; bool m_bSwap2Board;