From a699b6eb9cfb0d6ba98bf94881f85cbf7d6c6ebf Mon Sep 17 00:00:00 2001 From: David Skoland Date: Tue, 3 Jan 2017 13:22:43 +0100 Subject: [PATCH] made fundamental app structure, now with more OO --- Attorney_Online_remake.pro | 11 +++++-- aoapplication.cpp | 63 ++++++++++++++++++++++++++++++++++++++ aoapplication.h | 28 +++++++++++++++++ aobutton.cpp | 1 + aobutton.h | 5 --- debug_functions.cpp | 15 +++++++++ debug_functions.h | 8 +++++ global_variables.cpp | 4 +++ lobby.cpp | 46 +++++++++++++++++++--------- lobby.h | 8 +++++ main.cpp | 13 ++++---- networkmanager.cpp | 13 ++++++++ networkmanager.h | 16 ++++++++++ 13 files changed, 203 insertions(+), 28 deletions(-) create mode 100644 aoapplication.cpp create mode 100644 aoapplication.h create mode 100644 debug_functions.cpp create mode 100644 debug_functions.h create mode 100644 networkmanager.cpp create mode 100644 networkmanager.h diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 8f92ab1..38374f2 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -11,6 +11,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Attorney_Online_remake TEMPLATE = app +VERSION = 2.1.0.0 SOURCES += main.cpp\ lobby.cpp \ @@ -19,7 +20,10 @@ SOURCES += main.cpp\ aoimage.cpp \ file_functions.cpp \ aobutton.cpp \ - global_variables.cpp + global_variables.cpp \ + debug_functions.cpp \ + networkmanager.cpp \ + aoapplication.cpp HEADERS += lobby.h \ text_file_functions.h \ @@ -27,4 +31,7 @@ HEADERS += lobby.h \ aoimage.h \ file_functions.h \ aobutton.h \ - global_variables.h + global_variables.h \ + debug_functions.h \ + networkmanager.h \ + aoapplication.h diff --git a/aoapplication.cpp b/aoapplication.cpp new file mode 100644 index 0000000..cb7c44d --- /dev/null +++ b/aoapplication.cpp @@ -0,0 +1,63 @@ +#include + +#include "aoapplication.h" + +AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) +{ + +} + +AOApplication::~AOApplication() +{ + +} + +void AOApplication::construct_lobby() +{ + if (lobby_constructed) + { + qDebug() << "W: lobby was attempted constructed when it already exists"; + return; + } + + w_lobby = new Lobby(); + lobby_constructed = true; +} + +void AOApplication::destruct_lobby() +{ + if(!lobby_constructed) + { + qDebug() << "W: lobby was attempted destructed when it did not exist"; + return; + } + + delete w_lobby; + lobby_constructed = false; +} + +void AOApplication::construct_courtroom() +{ + if (courtroom_constructed) + { + qDebug() << "W: courtroom was attempted constructed when it already exists"; + return; + } + + w_courtroom = new QMainWindow(); + courtroom_constructed = true; +} + +void AOApplication::destruct_courtroom() +{ + if (!courtroom_constructed) + { + qDebug() << "W: courtroom was attempted destructed when it did not exist"; + return; + } + + delete w_courtroom; + courtroom_constructed = false; +} + + diff --git a/aoapplication.h b/aoapplication.h new file mode 100644 index 0000000..9523824 --- /dev/null +++ b/aoapplication.h @@ -0,0 +1,28 @@ +#ifndef AOAPPLICATION_H +#define AOAPPLICATION_H + +#include +#include + +#include "lobby.h" + +class AOApplication : public QApplication +{ +public: + AOApplication(int &argc, char **argv); + ~AOApplication(); + + Lobby *w_lobby; + QMainWindow *w_courtroom; + + bool lobby_constructed = false; + bool courtroom_constructed = false; + + void construct_lobby(); + void destruct_lobby(); + + void construct_courtroom(); + void destruct_courtroom(); +}; + +#endif // AOAPPLICATION_H diff --git a/aobutton.cpp b/aobutton.cpp index 3566c2b..f701e3d 100644 --- a/aobutton.cpp +++ b/aobutton.cpp @@ -1,5 +1,6 @@ #include +#include "debug_functions.h" #include "path_functions.h" #include "file_functions.h" diff --git a/aobutton.h b/aobutton.h index c89aa02..f0c5697 100644 --- a/aobutton.h +++ b/aobutton.h @@ -12,11 +12,6 @@ public: ~AOButton(); void set_image(QString p_image); - -signals: - void clicked(); - void pressed(); - void released(); }; #endif // AOBUTTON_H diff --git a/debug_functions.cpp b/debug_functions.cpp new file mode 100644 index 0000000..a77e4ea --- /dev/null +++ b/debug_functions.cpp @@ -0,0 +1,15 @@ +#include + +#include "debug_functions.h" + +void call_error(QString p_message) +{ + QMessageBox *msgBox = new QMessageBox; + + msgBox->setText("Error: " + p_message); + msgBox->setWindowTitle("Error"); + + + msgBox->setWindowModality(Qt::NonModal); + msgBox->show(); +} diff --git a/debug_functions.h b/debug_functions.h new file mode 100644 index 0000000..38275b0 --- /dev/null +++ b/debug_functions.h @@ -0,0 +1,8 @@ +#ifndef DEBUG_FUNCTIONS_H +#define DEBUG_FUNCTIONS_H + +#include + +void call_error(QString message); + +#endif // DEBUG_FUNCTIONS_H diff --git a/global_variables.cpp b/global_variables.cpp index cfef8be..a496a10 100644 --- a/global_variables.cpp +++ b/global_variables.cpp @@ -1,3 +1,7 @@ #include "global_variables.h" +const int RELEASE = 2; +const int MAJOR_VERSION = 1; +const int MINOR_VERSION = 0; + QString g_user_theme = "default"; diff --git a/lobby.cpp b/lobby.cpp index 7aadcca..45aadec 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -19,6 +19,16 @@ Lobby::Lobby(QWidget *parent) : QMainWindow(parent) ui_connect = new AOButton(this); connect(ui_public_servers, SIGNAL(clicked()), this, SLOT(on_public_servers_clicked())); + connect(ui_favorites, SIGNAL(clicked()), this, SLOT(on_favorites_clicked())); + + connect(ui_refresh, SIGNAL(pressed()), this, SLOT(on_refresh_pressed())); + connect(ui_refresh, SIGNAL(released()), this, SLOT(on_refresh_released())); + connect(ui_add_to_fav, SIGNAL(pressed()), this, SLOT(on_add_to_fav_pressed())); + connect(ui_add_to_fav, SIGNAL(released()), this, SLOT(on_add_to_fav_released())); + connect(ui_connect, SIGNAL(pressed()), this, SLOT(on_connect_pressed())); + connect(ui_connect, SIGNAL(released()), this, SLOT(on_connect_released())); + + set_widgets(); } Lobby::~Lobby() @@ -36,7 +46,7 @@ void Lobby::set_widgets() ui_background->move(0, 0); ui_background->resize(m_lobby_width, m_lobby_height); - ui_public_servers->set_image("publicservers.png"); + ui_public_servers->set_image("publicservers_selected.png"); ui_public_servers->move(46, 88); ui_public_servers->resize(114, 30); @@ -60,46 +70,52 @@ void Lobby::set_widgets() void Lobby::on_public_servers_clicked() { ui_public_servers->set_image("publicservers_selected.png"); + ui_favorites->set_image("favorites.png"); - //clear server list and show public servers + //T0D0: clear server list and show public servers +} + +void Lobby::on_favorites_clicked() +{ + ui_favorites->set_image("favorites_selected.png"); + ui_public_servers->set_image("publicservers.png"); + + //T0D0: clear server list and show favorites from serverlist.txt } -/* void Lobby::on_refresh_pressed() { - ui->refresh->setStyleSheet(get_stylesheet_path("refresh_pressed.png")); + ui_refresh->set_image("refresh_pressed.png"); } void Lobby::on_refresh_released() { - ui->refresh->setStyleSheet(get_stylesheet_path("refresh.png")); + ui_refresh->set_image("refresh.png"); - all_servers_requested(); + //T0D0: clear serverlist, request new list from MS and show them } -void Lobby::on_addtofav_pressed() +void Lobby::on_add_to_fav_pressed() { - ui->addtofav->setStyleSheet(get_stylesheet_path("addtofav_pressed.png")); + ui_add_to_fav->set_image("addtofav_pressed.png"); } -void Lobby::on_addtofav_released() +void Lobby::on_add_to_fav_released() { - ui->addtofav->setStyleSheet(get_stylesheet_path("addtofav.png")); + ui_add_to_fav->set_image("addtofav.png"); //T0D0, add selected element to serverlist.txt - } void Lobby::on_connect_pressed() { - ui->connect->setStyleSheet(get_stylesheet_path("connect_pressed.png")); + ui_connect->set_image("connect_pressed.png"); } void Lobby::on_connect_released() { - ui->connect->setStyleSheet(get_stylesheet_path("connect.png")); + ui_connect->set_image("connect.png"); - enter_server_requested(); + //T0D0: connect to selected server(show loading overlay?) } -*/ diff --git a/lobby.h b/lobby.h index 56659b2..a8f20e8 100644 --- a/lobby.h +++ b/lobby.h @@ -30,6 +30,14 @@ private: public slots: void on_public_servers_clicked(); + void on_favorites_clicked(); + + void on_refresh_pressed(); + void on_refresh_released(); + void on_add_to_fav_pressed(); + void on_add_to_fav_released(); + void on_connect_pressed(); + void on_connect_released(); }; #endif // LOBBY_H diff --git a/main.cpp b/main.cpp index 9ae6ab2..1c79671 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,14 @@ -#include +#include + +#include "aoapplication.h" #include "lobby.h" int main(int argc, char *argv[]) { - QApplication a(argc, argv); - Lobby w; - w.set_widgets(); - w.show(); + AOApplication main_app(argc, argv); + main_app.construct_lobby(); + main_app.w_lobby->show(); - return a.exec(); + return main_app.exec(); } diff --git a/networkmanager.cpp b/networkmanager.cpp new file mode 100644 index 0000000..89413e4 --- /dev/null +++ b/networkmanager.cpp @@ -0,0 +1,13 @@ +#include "networkmanager.h" + +NetworkManager::NetworkManager() +{ + ms_socket = new QTcpSocket(); + server_socket = new QTcpSocket(); +} + +NetworkManager::~NetworkManager() +{ + +} + diff --git a/networkmanager.h b/networkmanager.h new file mode 100644 index 0000000..7aaf001 --- /dev/null +++ b/networkmanager.h @@ -0,0 +1,16 @@ +#ifndef NETWORKMANAGER_H +#define NETWORKMANAGER_H + +#include + +class NetworkManager +{ +public: + NetworkManager(); + ~NetworkManager(); + + QTcpSocket *ms_socket; + QTcpSocket *server_socket; +}; + +#endif // NETWORKMANAGER_H