changing structure from globals to OO with a flat construction

This commit is contained in:
David Skoland 2017-01-18 15:39:04 +01:00
parent 75e9c9b8ec
commit 50fe02cd77
18 changed files with 172 additions and 96 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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 + "\")");

View File

@ -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);
};

View File

@ -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 + "\")");

View File

@ -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);

View File

@ -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);

View File

@ -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);
};

View File

@ -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();
}

View File

@ -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);

View File

@ -1,4 +1,5 @@
#include "global_variables.h"
#include "text_file_functions.h"
const int RELEASE = 2;
const int MAJOR_VERSION = 1;

View File

@ -3,6 +3,6 @@
#include <QString>
extern QString g_user_theme;
#endif // GLOBAL_VARIABLES_H

View File

@ -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);
}

View File

@ -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();

View File

@ -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/";
}

View File

@ -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

View File

@ -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;

View File

@ -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