Skip to content

Commit

Permalink
added a settings menu before game starts. Currently settings do not d…
Browse files Browse the repository at this point in the history
…o anything.

--HG--
rename : SettingsMenu.cpp => SettingsWidget.cpp
rename : SettingsMenu.h => SettingsWidget.h
  • Loading branch information
bsurmanski committed Jul 16, 2011
1 parent 359b79c commit 5b3e05b
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 77 deletions.
57 changes: 28 additions & 29 deletions MainGameWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,25 @@
#include "GameDockWidget.h"
#include "StatisticsWindow.h"
#include "NetworkManager.h"
#include "SettingsWidget.h"

#include "MainGameWindow.h"

MainGameWindow::MainGameWindow() : QMainWindow() {
GameLibrary::setCurrentMainWindow(this);
GameLibrary* single = new GameLibrary();
bool b_server = (QMessageBox::question(this, "Server Or Client?", "Is this a server?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes);

setObjectName(QObject::tr("Settlers!"));

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()));
settingsWidget = new SettingsWidget(this);
this->setCentralWidget(settingsWidget);
settingsWidget->show();
connect(settingsWidget, SIGNAL(startGame()), this, SLOT(startGame()));

statusBar = new QStatusBar(this);
single->setQStatusBar(statusBar);



this->setMenuBar(menuBar);
this->setStatusBar(statusBar);

NetworkManager* nm = new NetworkManager(b_server);
single->setNetworkManager(nm);

if (nm->isServer()) {
client_start();
} else {
// while (!nm->isConnected()) {
//
// }
}

this->setGeometry(0, 0, 640, 480);

stat = NULL;
Expand Down Expand Up @@ -103,3 +80,25 @@ void MainGameWindow::openStatistics() {
stat->show();
}

void MainGameWindow::startGame() {
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);

NetworkManager* nm = new NetworkManager(true);
GameLibrary::setNetworkManager(nm);

client_start();
}

4 changes: 3 additions & 1 deletion MainGameWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GameDockWidget;
class GLFrame;
class StatisticsWindow;
class NetworkManager;
class SettingsWidget;

class MainGameWindow : public QMainWindow {
Q_OBJECT
Expand All @@ -26,6 +27,7 @@ class MainGameWindow : public QMainWindow {

protected slots:
void openStatistics();
void startGame();
private:
QMenuBar* menuBar;
QStatusBar* statusBar;
Expand All @@ -39,7 +41,7 @@ protected slots:
GLFrame* gameFrame;

StatisticsWindow* stat;

SettingsWidget* settingsWidget;
NetworkManager* networker;

};
Expand Down
15 changes: 0 additions & 15 deletions SettingsMenu.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions SettingsMenu.h

This file was deleted.

89 changes: 89 additions & 0 deletions SettingsWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* File: SettingsWidget.cpp
* Author: brandon
*
* Created on June 29, 2011, 10:51 AM
*/

#include "SettingsWidget.h"
#include "GameLibrary.h"

SettingsWidget::SettingsWidget(QWidget* parent) : QWidget(parent) {
layout = new QGridLayout();
networkCheckBox = new QCheckBox();
networkCheckBox->setText("Enable Networking");
networkCheckBox->setChecked(true);
connect(networkCheckBox, SIGNAL(stateChanged(int)), this, SLOT(toggleNetworking(int)));
layout->addWidget(networkCheckBox, 0, 0, 1, 1);
networkBox = new QGroupBox();
networkLayout = new QFormLayout();
networkBox->setTitle("Networking");
serverCheckBox = new QCheckBox();
serverCheckBox->setText("Host Server");
connect(serverCheckBox, SIGNAL(stateChanged(int)), this, SLOT(toggleServer(int)));
networkLayout->addWidget(serverCheckBox);
ipLabel = new QLabel();
ipLabel->setText("Host IP");
ipLine = new QLineEdit();
ipLine->setText("127.0.0.1");
//ipLine->setInputMask("000.000.000.000;");
networkLayout->addRow(ipLabel, ipLine);
tcpPortLabel = new QLabel();
tcpPortLabel->setText("TCP Network Port");
tcpPortLine = new QLineEdit();
tcpPortLine->setText("9876");
networkLayout->addRow(tcpPortLabel, tcpPortLine);
networkBox->setLayout(networkLayout);
layout->addWidget(networkBox, 1, 0, 1, 2);

playerBox = new QGroupBox();
playerBox->setTitle("Local Players");
playerLayout = new QGridLayout();
playerTable = new QTableWidget();
playerTable->setColumnCount(2);
QStringList columns;
columns.append("Name");
columns.append("Color");
playerTable->setHorizontalHeaderLabels(columns);
addPlayerButton = new QPushButton();
addPlayerButton->setText("Add Player");
removePlayerButton = new QPushButton();
removePlayerButton->setText("Remove Player");
playerLayout->addWidget(playerTable, 0, 0, 2, 1);
playerLayout->addWidget(addPlayerButton, 0, 1, 1, 1);
playerLayout->addWidget(removePlayerButton, 1, 1, 1, 1);
playerBox->setLayout(playerLayout);
layout->addWidget(playerBox, 2, 0, 1, 2);
startButton = new QPushButton();
startButton->setText("Start Game!");
connect(startButton, SIGNAL(pressed()), this, SLOT(startPressed()));
layout->addWidget(startButton, 3, 1, 1, 1);
this->setLayout(layout);
}

SettingsWidget::~SettingsWidget() {
}

//void SettingsWidget::initialize() {
// int rows = playerTable->rowCount();
// int cols = playerTable->columnCount();
// QString cellText;
// for (int i = 0; i < rows; i++) {
// for (int j = 0; j < cols; j++) {
// cellText = playerTable->takeItem(i, j)->text();
// }
// }
//}

void SettingsWidget::toggleNetworking(int state) {
networkBox->setEnabled(state);
}

void SettingsWidget::toggleServer(int state) {
ipLine->setEnabled(state == 0);
}

void SettingsWidget::startPressed() {
emit startGame();
}

57 changes: 57 additions & 0 deletions SettingsWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* File: SettingsMenu.h
* Author: brandon
*
* Created on June 29, 2011, 10:51 AM
*/

#ifndef SETTINGSWIDGET_H
#define SETTINGSWIDGET_H

#include <QtGui/QWidget>
#include <QtGui/QLabel>
#include <QtGui/QGridLayout>
#include <QtGui/QFormLayout>
#include <QtGui/QLineEdit>
#include <QtGui/QCheckBox>
#include <QtGui/QTableWidget>
#include <QtGui/QGroupBox>
#include <QtGui/QSpacerItem>
#include <QtGui/QPushButton>

class SettingsWidget : public QWidget {
Q_OBJECT
public:
SettingsWidget(QWidget* parent = 0);
virtual ~SettingsWidget();
//void initialize();

signals:
void startGame();
protected slots:
void startPressed();
void toggleNetworking(int state);
void toggleServer(int state);
private:
QGridLayout* layout;
QCheckBox* networkCheckBox;
QGroupBox* networkBox;
QFormLayout* networkLayout;
QCheckBox* serverCheckBox;
QLabel* ipLabel;
QLineEdit* ipLine;
QLabel* tcpPortLabel;
QLineEdit* tcpPortLine;

QGroupBox* playerBox;
QGridLayout* playerLayout;
QTableWidget* playerTable;
QPushButton* addPlayerButton;
QPushButton* removePlayerButton;

QPushButton* startButton;
QSpacerItem* spacer;
};

#endif /* SETTINGSWIDGET_H */

9 changes: 6 additions & 3 deletions moc_MainGameWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'MainGameWindow.h'
**
** Created: Thu Jul 14 21:06:38 2011
** Created: Fri Jul 15 14:00:26 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.3)
**
** WARNING! All changes made in this file will be lost!
Expand All @@ -23,7 +23,7 @@ static const uint qt_meta_data_MainGameWindow[] = {
5, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
2, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
Expand All @@ -32,12 +32,14 @@ static const uint qt_meta_data_MainGameWindow[] = {

// slots: signature, parameters, type, tag, flags
16, 15, 15, 15, 0x09,
33, 15, 15, 15, 0x09,

0 // eod
};

static const char qt_meta_stringdata_MainGameWindow[] = {
"MainGameWindow\0\0openStatistics()\0"
"startGame()\0"
};

const QMetaObject MainGameWindow::staticMetaObject = {
Expand Down Expand Up @@ -70,9 +72,10 @@ int MainGameWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_c == QMetaObject::InvokeMetaMethod) {
switch (_id) {
case 0: openStatistics(); break;
case 1: startGame(); break;
default: ;
}
_id -= 1;
_id -= 2;
}
return _id;
}
Expand Down
Loading

0 comments on commit 5b3e05b

Please sign in to comment.