-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainGameWindow.cpp
119 lines (101 loc) · 3.58 KB
/
MainGameWindow.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
110
111
112
113
114
115
116
117
118
/*
* File: MainGameWindow.cpp
* Author: brandon
*
* Created on June 27, 2011, 10:45 PM
*/
#include <QtGui/QMenuBar>
#include <QtGui/QLayout>
#include <QtGui/QKeyEvent>
#include <QtCore/QString>
#include <QtGui/QDockWidget>
#include <QtGui/QSplitter>
#include <QtGui/QMessageBox>
#include <time.h>
#include "GLFrame.h"
#include "GameDockWidget.h"
#include "StatisticsWindow.h"
#include "NetworkManager.h"
#include "SettingsWidget.h"
#include "MainGameWindow.h"
MainGameWindow::MainGameWindow() : QMainWindow() {
srand(time(NULL));
GameLibrary::setCurrentMainWindow(this);
GameLibrary* single = new GameLibrary();
NetworkManager* nm = new NetworkManager();
GameLibrary::setNetworkManager(nm);
setObjectName(QObject::tr("Settlers!"));
settingsWidget = new SettingsWidget(this);
this->setCentralWidget(settingsWidget);
settingsWidget->show();
connect(settingsWidget, SIGNAL(startGame()), this, SLOT(startConnect()));
statusBar = new QStatusBar(this);
single->setQStatusBar(statusBar);
this->setStatusBar(statusBar);
this->setGeometry(0, 0, 640, 480);
stat = NULL;
}
bool MainGameWindow::client_start() {
if (GameLibrary::getNetworkManager()->isConnected()) {
splitterWidget = new QSplitter(this);
gameFrame = new GLFrame(splitterWidget);
splitterWidget->addWidget(gameFrame);
dockContent = new GameDockWidget(splitterWidget);
splitterWidget->addWidget(dockContent);
splitterWidget->setOrientation(Qt::Vertical);
this->setCentralWidget(splitterWidget);
gameFrame->newGame();
dockContent->updatePlayerInfo();
return true;
} else {
QMessageBox::warning(this, "No Connection", "Could not connect to host server. Please check your IP and Port settings and try again. \nIf you would like to host a game, please check the 'Host Server' Option. \nIf you would like to play on a single computer, please uncheck the 'Networking' option");
return false;
}
}
MainGameWindow::~MainGameWindow() {
delete menuBar;
delete statusBar;
delete menuFile;
delete actionQuit;
delete menuWindow;
delete actionStatistics;
delete menuHelp;
delete splitterWidget;
delete dockContent;
delete gameFrame;
if (stat != NULL) {
delete stat;
}
}
void MainGameWindow::openStatistics() {
if (stat != NULL) {
delete stat;
}
stat = new StatisticsWindow();
stat->show();
}
void MainGameWindow::startConnect() {
settingsWidget->createPlayers();
GameLibrary::getNetworkManager()->setConnection(settingsWidget->getIP(), settingsWidget->getPort().toInt(), settingsWidget->serverSet());
if (GameLibrary::getNetworkManager()->isServer()) {
startGame();
}
}
void MainGameWindow::startGame() {
if (client_start()) {
menuBar = new QMenuBar(this);
menuFile = new QMenu(QObject::tr("File")); //File menu
actionQuit = new QAction(QObject::tr("&Quit"), this); // Quit Option
menuFile->addAction(actionQuit);
menuWindow = new QMenu(QObject::tr("Window")); // Window menu
actionStatistics = new QAction(QObject::tr("&Statistics"), this);
menuWindow->addAction(actionStatistics);
menuHelp = new QMenu(QObject::tr("Help")); // help menu
menuBar->addMenu(menuFile);
menuBar->addMenu(menuWindow);
menuBar->addMenu(menuHelp);
QObject::connect(actionQuit, SIGNAL(triggered()), this, SLOT(close()));
QObject::connect(actionStatistics, SIGNAL(triggered()), this, SLOT(openStatistics()));
this->setMenuBar(menuBar);
}
}