-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainwindow.cpp
109 lines (90 loc) · 3.74 KB
/
mainwindow.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/****************************************
*
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
* Copyright (C) 2020 Victor Tran
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "online/onlinecontroller.h"
#include "controllers/backgroundcontroller.h"
#include <pauseoverlay.h>
#include "online/onlinecontroller.h"
#include <online/reportcontroller.h>
#include <the-libs_global.h>
#include <QUrl>
#include <musicengine.h>
struct MainWindowPrivate {
QWidget* settingsPopWidget = nullptr;
};
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow) {
BackgroundController::instance()->setMainWindow(this);
d = new MainWindowPrivate();
ui->setupUi(this);
ui->menubar->setVisible(false);
OnlineController::instance()->setMainWindow(this);
connect(ui->mainScreen, &MainScreen::startGame, this, [ = ](GameEnginePtr engine) {
QSize imageSize = SC_DPI_T(QSize(32, 32), QSize);
ui->gameScreen->setPlayers(QIcon(":/assets/white-icon.svg").pixmap(imageSize).toImage(), tr("White"), QIcon(":/assets/black-icon.svg").pixmap(imageSize).toImage(), tr("Black"));
ui->gameScreen->setGameEngine(engine);
ui->stackedWidget->setCurrentWidget(ui->gameScreen);
});
connect(ui->mainScreen, &MainScreen::goToSettings, this, [ = ] {
d->settingsPopWidget = ui->mainScreen;
ui->stackedWidget->setCurrentWidget(ui->settingsPage);
});
connect(OnlineController::instance(), &OnlineController::isOnlineChanged, this, [ = ](bool isOnline) {
ReportController::setAutomaticReportingEnabled(this, isOnline);
if (isOnline) {
ui->stackedWidget->setCurrentWidget(ui->onlineScreen);
} else {
ui->stackedWidget->setCurrentWidget(ui->mainScreen);
}
});
connect(ui->gameScreen, &GameScreen::returnToMainMenu, this, [ = ] {
ui->stackedWidget->setCurrentWidget(ui->mainScreen);
});
connect(ui->gameScreen, &GameScreen::viewSettings, this, [ = ] {
d->settingsPopWidget = ui->gameScreen;
ui->stackedWidget->setCurrentWidget(ui->settingsPage);
});
connect(ui->settingsPage, &SettingsScreen::goBack, this, [ = ] {
ui->stackedWidget->setCurrentWidget(d->settingsPopWidget);
d->settingsPopWidget = nullptr;
});
connect(ui->onlineScreen, &OnlineScreen::viewSettings, this, [ = ] {
d->settingsPopWidget = ui->onlineScreen;
ui->stackedWidget->setCurrentWidget(ui->settingsPage);
});
PauseOverlay::registerOverlayForWindow(this, ui->centralwidget);
MusicEngine::playBackgroundMusic();
on_stackedWidget_currentChanged(0);
ui->mainScreen->setFocus();
}
MainWindow::~MainWindow() {
delete d;
delete ui;
}
void MainWindow::on_stackedWidget_currentChanged(int arg1) {
if (d->settingsPopWidget) return;
if (ui->stackedWidget->currentWidget() == ui->gameScreen) {
MusicEngine::setBackgroundMusic("ingame-intro", "ingame-loop");
} else {
MusicEngine::setBackgroundMusic("neon-intro", "neon-loop");
}
}