aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Skoland <davidskoland@gmail.com>2017-01-18 15:39:04 +0100
committerDavid Skoland <davidskoland@gmail.com>2017-01-18 15:39:04 +0100
commit50fe02cd77408da05ee33844085c8bdd5b361c96 (patch)
treeeace854a0cbaf21c675fcf6cd054194886349449
parent75e9c9b8ecb1852e5dc57e0920cafe4cbdfaf0e5 (diff)
changing structure from globals to OO with a flat construction
-rw-r--r--aoapplication.cpp29
-rw-r--r--aoapplication.h42
-rw-r--r--aobutton.cpp8
-rw-r--r--aobutton.h6
-rw-r--r--aocharbutton.cpp8
-rw-r--r--aocharbutton.h6
-rw-r--r--aoimage.cpp9
-rw-r--r--aoimage.h7
-rw-r--r--courtroom.cpp66
-rw-r--r--courtroom.h2
-rw-r--r--global_variables.cpp1
-rw-r--r--global_variables.h2
-rw-r--r--lobby.cpp45
-rw-r--r--lobby.h2
-rw-r--r--path_functions.cpp14
-rw-r--r--path_functions.h6
-rw-r--r--text_file_functions.cpp10
-rw-r--r--text_file_functions.h5
18 files changed, 172 insertions, 96 deletions
diff --git a/aoapplication.cpp b/aoapplication.cpp
index d3376019..87525a80 100644
--- a/aoapplication.cpp
+++ b/aoapplication.cpp
@@ -3,6 +3,7 @@
#include "lobby.h"
#include "courtroom.h"
#include "networkmanager.h"
+#include "text_file_functions.h"
#include "aoapplication.h"
@@ -68,4 +69,32 @@ void AOApplication::destruct_courtroom()
courtroom_constructed = false;
}
+QString AOApplication::get_version_string(){
+ return
+ QString::number(RELEASE) + "." +
+ QString::number(MAJOR_VERSION) + "." +
+ QString::number(MINOR_VERSION);
+}
+
+void AOApplication::set_user_theme(){
+ user_theme = read_user_theme();
+}
+void AOApplication::set_favorite_list()
+{
+ favorite_list = read_serverlist_txt();
+}
+
+void AOApplication::add_favorite_server(int p_server)
+{
+ if (p_server < 0 || p_server >= server_list.size())
+ return;
+
+ server_type fav_server = server_list.at(p_server);
+
+ QString str_port = QString::number(fav_server.port);
+
+ QString server_line = fav_server.ip + ":" + str_port + ":" + fav_server.name;
+
+ write_to_serverlist_txt(server_line);
+}
diff --git a/aoapplication.h b/aoapplication.h
index 34f1fefb..77d7af01 100644
--- a/aoapplication.h
+++ b/aoapplication.h
@@ -6,6 +6,7 @@
#include <QApplication>
#include <QVector>
+#include <QFile>
class NetworkManager;
class Lobby;
@@ -32,9 +33,6 @@ public:
void construct_courtroom();
void destruct_courtroom();
- QVector<server_type> server_list;
- QVector<server_type> favorite_list;
-
void ms_packet_received(AOPacket *p_packet);
void server_packet_received(AOPacket *p_packet);
@@ -50,6 +48,44 @@ public:
bool s_pv = 0;
//////////////////////////////////////////////////
+
+ int get_release() {return RELEASE;}
+ int get_major_version() {return MAJOR_VERSION;}
+ int get_minor_version() {return MINOR_VERSION;}
+ QString get_version_string();
+
+ void set_favorite_list();
+ QVector<server_type>& get_favorite_list() {return favorite_list;}
+ void add_favorite_server(int p_server);
+
+ void set_server_list();
+ QVector<server_type>& get_server_list() {return server_list;}
+
+ void set_user_theme();
+ QString get_user_theme() {return user_theme;}
+
+ //path functions
+ QString get_base_path();
+ QString get_theme_path();
+ QString get_default_theme_path();
+ QString get_character_path(QString p_character);
+ QString get_demothings_path();
+
+ //text file functions
+ QString read_user_theme();
+ void write_to_serverlist_txt(QString p_line);
+ QVector<server_type> read_serverlist_txt();
+ pos_size_type get_pos_and_size(QString p_identifier, QString p_design_path);
+
+private:
+ const int RELEASE = 2;
+ const int MAJOR_VERSION = 1;
+ const int MINOR_VERSION = 0;
+
+ QString user_theme = "default";
+
+ QVector<server_type> server_list;
+ QVector<server_type> favorite_list;
};
#endif // AOAPPLICATION_H
diff --git a/aobutton.cpp b/aobutton.cpp
index 9f6ba232..0938f51b 100644
--- a/aobutton.cpp
+++ b/aobutton.cpp
@@ -6,9 +6,9 @@
#include <QDebug>
-AOButton::AOButton(QWidget *parent) : QPushButton(parent)
+AOButton::AOButton(QWidget *parent, AOApplication *p_ao_app) : QPushButton(parent)
{
-
+ ao_app = p_ao_app;
}
AOButton::~AOButton()
@@ -18,8 +18,8 @@ AOButton::~AOButton()
void AOButton::set_image(QString p_image)
{
- QString image_path = get_theme_path() + p_image;
- QString default_image_path = get_default_theme_path() + p_image;
+ QString image_path = ao_app->get_theme_path() + p_image;
+ QString default_image_path = ao_app->get_default_theme_path() + p_image;
if (file_exists(image_path))
this->setStyleSheet("border-image:url(\"" + image_path + "\")");
diff --git a/aobutton.h b/aobutton.h
index f0c5697f..04923755 100644
--- a/aobutton.h
+++ b/aobutton.h
@@ -1,6 +1,8 @@
#ifndef AOBUTTON_H
#define AOBUTTON_H
+#include "aoapplication.h"
+
#include <QPushButton>
class AOButton : public QPushButton
@@ -8,9 +10,11 @@ class AOButton : public QPushButton
Q_OBJECT
public:
- AOButton(QWidget *parent);
+ AOButton(QWidget *parent, AOApplication *p_ao_app);
~AOButton();
+ AOApplication *ao_app;
+
void set_image(QString p_image);
};
diff --git a/aocharbutton.cpp b/aocharbutton.cpp
index 1c0b4f79..79dc4e8a 100644
--- a/aocharbutton.cpp
+++ b/aocharbutton.cpp
@@ -5,17 +5,19 @@
#include <QFile>
-AOCharButton::AOCharButton(QWidget *parent)
+AOCharButton::AOCharButton(QWidget *parent, AOApplication *p_ao_app)
{
m_parent = parent;
+ ao_app = p_ao_app;
+
this->resize(60, 60);
}
void AOCharButton::set_image(QString p_character)
{
- QString image_path = get_character_path(p_character) + "char_icon.png";
- QString legacy_path = get_demothings_path() + p_character.toLower() + "_char_icon.png";
+ QString image_path = ao_app->get_character_path(p_character) + "char_icon.png";
+ QString legacy_path = ao_app->get_demothings_path() + p_character.toLower() + "_char_icon.png";
if (file_exists(image_path))
this->setStyleSheet("border-image:url(\"" + image_path + "\")");
diff --git a/aocharbutton.h b/aocharbutton.h
index 231fe66d..e91a1201 100644
--- a/aocharbutton.h
+++ b/aocharbutton.h
@@ -1,6 +1,8 @@
#ifndef AOCHARBUTTON_H
#define AOCHARBUTTON_H
+#include "aoapplication.h"
+
#include <QPushButton>
#include <QString>
#include <QWidget>
@@ -10,7 +12,9 @@ class AOCharButton : public QPushButton
Q_OBJECT
public:
- AOCharButton(QWidget *parent);
+ AOCharButton(QWidget *parent, AOApplication *p_ao_app);
+
+ AOApplication *ao_app;
void set_image(QString p_character);
diff --git a/aoimage.cpp b/aoimage.cpp
index 0f03a7b6..2e09f6a0 100644
--- a/aoimage.cpp
+++ b/aoimage.cpp
@@ -4,9 +4,10 @@
#include "aoimage.h"
-AOImage::AOImage(QWidget *parent) : QLabel(parent)
+AOImage::AOImage(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent)
{
-
+ m_parent = parent;
+ ao_app = p_ao_app;
}
AOImage::~AOImage()
@@ -16,8 +17,8 @@ AOImage::~AOImage()
void AOImage::set_image(QString p_image)
{
- QString theme_image_path = get_theme_path() + p_image;
- QString default_image_path = get_default_theme_path() + p_image;
+ QString theme_image_path = ao_app->get_theme_path() + p_image;
+ QString default_image_path = ao_app->get_default_theme_path() + p_image;
if (file_exists(theme_image_path))
this->setPixmap(theme_image_path);
diff --git a/aoimage.h b/aoimage.h
index d83751c5..95f10ca2 100644
--- a/aoimage.h
+++ b/aoimage.h
@@ -3,14 +3,19 @@
#ifndef AOIMAGE_H
#define AOIMAGE_H
+#include "aoapplication.h"
+
#include <QLabel>
class AOImage : public QLabel
{
public:
- AOImage(QWidget *parent);
+ AOImage(QWidget *parent, AOApplication *p_ao_app);
~AOImage();
+ QWidget *m_parent;
+ AOApplication *ao_app;
+
void set_image(QString p_image);
void set_size_and_pos(QString identifier);
};
diff --git a/courtroom.cpp b/courtroom.cpp
index 98b544ee..bc1bf1f9 100644
--- a/courtroom.cpp
+++ b/courtroom.cpp
@@ -7,11 +7,11 @@
#include <QDebug>
-Courtroom::Courtroom(AOApplication *parent) : QMainWindow()
+Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
{
- ao_app = parent;
+ ao_app = p_ao_app;
- ui_background = new AOImage(this);
+ ui_background = new AOImage(this, ao_app);
//viewport elements like background, desk, etc.
@@ -35,41 +35,41 @@ Courtroom::Courtroom(AOApplication *parent) : QMainWindow()
//emote buttons
- ui_emote_left = new AOButton(this);
- ui_emote_right = new AOButton(this);
+ ui_emote_left = new AOButton(this, ao_app);
+ ui_emote_right = new AOButton(this, ao_app);
- ui_defense_bar = new AOImage(this);
- ui_prosecution_bar = new AOImage(this);
+ ui_defense_bar = new AOImage(this, ao_app);
+ ui_prosecution_bar = new AOImage(this, ao_app);
ui_music_label = new QLabel(this);
ui_sfx_label = new QLabel(this);
ui_blip_label = new QLabel(this);
- ui_hold_it = new AOButton(this);
- ui_objection = new AOButton(this);
- ui_take_that = new AOButton(this);
+ ui_hold_it = new AOButton(this, ao_app);
+ ui_objection = new AOButton(this, ao_app);
+ ui_take_that = new AOButton(this, ao_app);
- ui_ooc_toggle = new AOButton(this);
- ui_witness_testimony = new AOButton(this);
- ui_cross_examination = new AOButton(this);
+ ui_ooc_toggle = new AOButton(this, ao_app);
+ ui_witness_testimony = new AOButton(this, ao_app);
+ ui_cross_examination = new AOButton(this, ao_app);
- ui_change_character = new AOButton(this);
- ui_reload_theme = new AOButton(this);
- ui_call_mod = new AOButton(this);
+ ui_change_character = new AOButton(this, ao_app);
+ ui_reload_theme = new AOButton(this, ao_app);
+ ui_call_mod = new AOButton(this, ao_app);
ui_pre = new QCheckBox(this);
ui_flip = new QCheckBox(this);
ui_guard = new QCheckBox(this);
- ui_custom_objection = new AOButton(this);
- ui_realization = new AOButton(this);
- ui_mute = new AOButton(this);
+ ui_custom_objection = new AOButton(this, ao_app);
+ ui_realization = new AOButton(this, ao_app);
+ ui_mute = new AOButton(this, ao_app);
- ui_defense_plus = new AOButton(this);
- ui_defense_minus = new AOButton(this);
+ ui_defense_plus = new AOButton(this, ao_app);
+ ui_defense_minus = new AOButton(this, ao_app);
- ui_prosecution_plus = new AOButton(this);
- ui_prosecution_minus = new AOButton(this);
+ ui_prosecution_plus = new AOButton(this, ao_app);
+ ui_prosecution_minus = new AOButton(this, ao_app);
ui_text_color = new QComboBox(this);
@@ -77,22 +77,22 @@ Courtroom::Courtroom(AOApplication *parent) : QMainWindow()
ui_sfx_slider = new QSlider(this);
ui_blip_slider = new QSlider(this);
- ui_muted = new AOImage(this);
+ ui_muted = new AOImage(this, ao_app);
/////////////char select widgets under here///////////////
- ui_char_select_background = new AOImage(this);
+ ui_char_select_background = new AOImage(this, ao_app);
//T0D0: allocate and position charbuttons
//QVector<AOCharButton*> ui_char_button_list;
- ui_selector = new AOImage(ui_char_select_background);
+ ui_selector = new AOImage(ui_char_select_background, ao_app);
- ui_back_to_lobby = new AOButton(ui_char_select_background);
+ ui_back_to_lobby = new AOButton(ui_char_select_background, ao_app);
ui_char_password = new QLineEdit(ui_char_select_background);
- ui_spectator = new AOButton(ui_char_select_background);
+ ui_spectator = new AOButton(ui_char_select_background, ao_app);
connect(ui_reload_theme, SIGNAL(clicked()), this, SLOT(on_reload_theme_clicked()));
@@ -203,14 +203,14 @@ void Courtroom::set_widgets()
void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier)
{
- QString design_ini_path = get_theme_path() + "courtroom_design.ini";
- QString default_ini_path = get_base_path() + "themes/default/courtroom_design.ini";
+ QString design_ini_path = ao_app->get_theme_path() + "courtroom_design.ini";
+ QString default_ini_path = ao_app->get_base_path() + "themes/default/courtroom_design.ini";
- pos_size_type design_ini_result = get_pos_and_size(p_identifier, design_ini_path);
+ pos_size_type design_ini_result = ao_app->get_pos_and_size(p_identifier, design_ini_path);
if (design_ini_result.width < 0 || design_ini_result.height < 0)
{
- design_ini_result = get_pos_and_size(p_identifier, default_ini_path);
+ design_ini_result = ao_app->get_pos_and_size(p_identifier, default_ini_path);
if (design_ini_result.width < 0 || design_ini_result.height < 0)
{
@@ -227,7 +227,7 @@ void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier)
void Courtroom::on_reload_theme_clicked()
{
- g_user_theme = get_user_theme();
+ ao_app->set_user_theme();
set_widgets();
}
diff --git a/courtroom.h b/courtroom.h
index b20b63c1..e0dee82f 100644
--- a/courtroom.h
+++ b/courtroom.h
@@ -23,7 +23,7 @@ class Courtroom : public QMainWindow
{
Q_OBJECT
public:
- explicit Courtroom(AOApplication *parent = 0);
+ explicit Courtroom(AOApplication *p_ao_app);
void set_widgets();
void set_size_and_pos(QWidget *p_widget, QString p_identifier);
diff --git a/global_variables.cpp b/global_variables.cpp
index a496a10d..b3a7e125 100644
--- a/global_variables.cpp
+++ b/global_variables.cpp
@@ -1,4 +1,5 @@
#include "global_variables.h"
+#include "text_file_functions.h"
const int RELEASE = 2;
const int MAJOR_VERSION = 1;
diff --git a/global_variables.h b/global_variables.h
index 7b8a469b..941ac49f 100644
--- a/global_variables.h
+++ b/global_variables.h
@@ -3,6 +3,6 @@
#include <QString>
-extern QString g_user_theme;
+
#endif // GLOBAL_VARIABLES_H
diff --git a/lobby.cpp b/lobby.cpp
index e1704b78..17cae5fc 100644
--- a/lobby.cpp
+++ b/lobby.cpp
@@ -9,21 +9,21 @@
#include <QDebug>
-Lobby::Lobby(AOApplication *parent) : QMainWindow()
+Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow()
{
- ao_app = parent;
+ ao_app = p_ao_app;
this->setWindowTitle("Attorney Online 2");
this->resize(m_lobby_width, m_lobby_height);
this->setFixedSize(m_lobby_width, m_lobby_height);
- ui_background = new AOImage(this);
- ui_public_servers = new AOButton(this);
- ui_favorites = new AOButton(this);
- ui_refresh = new AOButton(this);
- ui_add_to_fav = new AOButton(this);
- ui_connect = new AOButton(this);
- ui_about = new AOButton(this);
+ ui_background = new AOImage(this, ao_app);
+ ui_public_servers = new AOButton(this, ao_app);
+ ui_favorites = new AOButton(this, ao_app);
+ ui_refresh = new AOButton(this, ao_app);
+ ui_add_to_fav = new AOButton(this, ao_app);
+ ui_connect = new AOButton(this, ao_app);
+ ui_about = new AOButton(this, ao_app);
ui_server_list = new QListWidget(this);
ui_player_count = new QLabel(this);
ui_description = new QPlainTextEdit(this);
@@ -49,8 +49,7 @@ Lobby::Lobby(AOApplication *parent) : QMainWindow()
//sets images, position and size
void Lobby::set_widgets()
{
- //global to efficiently set images on button presses
- g_user_theme = get_user_theme();
+ ao_app->set_user_theme();
ui_background->set_image("lobbybackground.png");
ui_background->move(0, 0);
@@ -130,7 +129,8 @@ void Lobby::on_favorites_clicked()
ui_favorites->set_image("favorites_selected.png");
ui_public_servers->set_image("publicservers.png");
- ao_app->favorite_list = read_serverlist_txt();
+ ao_app->set_favorite_list();
+ //ao_app->favorite_list = read_serverlist_txt();
list_favorites();
@@ -166,18 +166,19 @@ void Lobby::on_add_to_fav_released()
if (!public_servers_selected)
return;
- int n_server = ui_server_list->currentRow();
-
- if (n_server < 0 || n_server >= ao_app->server_list.size())
+ ao_app->add_favorite_server(ui_server_list->currentRow());
+ /*
+ if (n_server < 0 || n_server >= ao_app->get_server_list().size())
return;
- server_type fav_server = ao_app->server_list.at(n_server);
+ server_type fav_server = ao_app->get_server_list().at(n_server);
QString str_port = QString::number(fav_server.port);
QString server_line = fav_server.ip + ":" + str_port + ":" + fav_server.name;
write_to_serverlist_txt(server_line);
+ */
}
void Lobby::on_connect_pressed()
@@ -216,17 +217,17 @@ void Lobby::on_server_list_clicked(QModelIndex p_model)
if (public_servers_selected)
{
- if (n_server >= ao_app->server_list.size())
+ if (n_server >= ao_app->get_server_list().size())
return;
- f_server = ao_app->server_list.at(p_model.row());
+ f_server = ao_app->get_server_list().at(p_model.row());
}
else
{
- if (n_server >= ao_app->favorite_list.size())
+ if (n_server >= ao_app->get_favorite_list().size())
return;
- f_server = ao_app->favorite_list.at(p_model.row());
+ f_server = ao_app->get_favorite_list().at(p_model.row());
}
ui_description->clear();
@@ -258,7 +259,7 @@ void Lobby::list_servers()
{
ui_server_list->clear();
- for (server_type i_server : ao_app->server_list)
+ for (server_type i_server : ao_app->get_server_list())
{
ui_server_list->addItem(i_server.name);
}
@@ -268,7 +269,7 @@ void Lobby::list_favorites()
{
ui_server_list->clear();
- for (server_type i_server : ao_app->favorite_list)
+ for (server_type i_server : ao_app->get_favorite_list())
{
ui_server_list->addItem(i_server.name);
}
diff --git a/lobby.h b/lobby.h
index 8ee384b9..e4d6499f 100644
--- a/lobby.h
+++ b/lobby.h
@@ -18,7 +18,7 @@ class Lobby : public QMainWindow
Q_OBJECT
public:
- Lobby(AOApplication *parent);
+ Lobby(AOApplication *p_ao_app);
void set_widgets();
void list_servers();
diff --git a/path_functions.cpp b/path_functions.cpp
index 0282bd4f..46f80ef3 100644
--- a/path_functions.cpp
+++ b/path_functions.cpp
@@ -1,4 +1,4 @@
-#include "path_functions.h"
+#include "aoapplication.h"
#include "global_variables.h"
#include "text_file_functions.h"
@@ -6,26 +6,26 @@
#include <QDir>
#include <QDebug>
-QString get_base_path(){
+QString AOApplication::get_base_path(){
return (QDir::currentPath() + "/base/");
}
-QString get_theme_path()
+QString AOApplication::get_theme_path()
{
- return get_base_path() + "themes/" + g_user_theme.toLower() + "/";
+ return get_base_path() + "themes/" + user_theme.toLower() + "/";
}
-QString get_default_theme_path()
+QString AOApplication::get_default_theme_path()
{
return get_base_path() + "themes/default/";
}
-QString get_character_path(QString p_character)
+QString AOApplication::get_character_path(QString p_character)
{
return get_base_path() + "characters/" + p_character.toLower() + "/";
}
-QString get_demothings_path()
+QString AOApplication::get_demothings_path()
{
return get_base_path() + "misc/demothings/";
}
diff --git a/path_functions.h b/path_functions.h
index 67cbd29c..2f37a0ce 100644
--- a/path_functions.h
+++ b/path_functions.h
@@ -3,10 +3,6 @@
#include <QString>
-QString get_base_path();
-QString get_theme_path();
-QString get_default_theme_path();
-QString get_character_path(QString p_character);
-QString get_demothings_path();
+
#endif // PATH_FUNCTIONS_H
diff --git a/text_file_functions.cpp b/text_file_functions.cpp
index bd5699cf..db1ecc74 100644
--- a/text_file_functions.cpp
+++ b/text_file_functions.cpp
@@ -1,4 +1,4 @@
-#include "text_file_functions.h"
+#include "aoapplication.h"
#include "path_functions.h"
#include "file_functions.h"
@@ -8,7 +8,7 @@
#include <QVector>
#include <QDebug>
-QString get_user_theme(){
+QString AOApplication::read_user_theme(){
QFile config_file(get_base_path() + "config.ini");
if (!config_file.open(QIODevice::ReadOnly))
return "default";
@@ -31,7 +31,7 @@ QString get_user_theme(){
return "default";
}
-void write_to_serverlist_txt(QString p_line)
+void AOApplication::write_to_serverlist_txt(QString p_line)
{
QFile serverlist_txt;
QString serverlist_txt_path = get_base_path() + "serverlist.txt";
@@ -50,7 +50,7 @@ void write_to_serverlist_txt(QString p_line)
serverlist_txt.close();
}
-QVector<server_type> read_serverlist_txt()
+QVector<server_type> AOApplication::read_serverlist_txt()
{
QVector<server_type> f_server_list;
@@ -86,7 +86,7 @@ QVector<server_type> read_serverlist_txt()
return f_server_list;
}
-pos_size_type get_pos_and_size(QString p_identifier, QString p_design_path)
+pos_size_type AOApplication::get_pos_and_size(QString p_identifier, QString p_design_path)
{
QFile design_ini;
diff --git a/text_file_functions.h b/text_file_functions.h
index 5e3a0b3e..54abd4d8 100644
--- a/text_file_functions.h
+++ b/text_file_functions.h
@@ -6,9 +6,6 @@
#include <QString>
#include <QFile>
-QString get_user_theme();
-void write_to_serverlist_txt(QString p_line);
-QVector<server_type> read_serverlist_txt();
-pos_size_type get_pos_and_size(QString p_identifier, QString p_design_path);
+
#endif // TEXT_FILE_FUNCTIONS_H