diff --git a/aoapplication.cpp b/aoapplication.cpp index d15ced1..d337601 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -51,6 +51,9 @@ void AOApplication::construct_courtroom() w_courtroom = new Courtroom(this); courtroom_constructed = true; + + //D3BUG + w_courtroom->show(); } void AOApplication::destruct_courtroom() diff --git a/aoimage.h b/aoimage.h index 93fa6fd..d83751c 100644 --- a/aoimage.h +++ b/aoimage.h @@ -12,6 +12,7 @@ public: ~AOImage(); void set_image(QString p_image); + void set_size_and_pos(QString identifier); }; #endif // AOIMAGE_H diff --git a/courtroom.cpp b/courtroom.cpp index 0c2fe55..bc02498 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1,6 +1,8 @@ #include "courtroom.h" #include "aoapplication.h" +#include "text_file_functions.h" +#include "path_functions.h" #include @@ -91,6 +93,8 @@ Courtroom::Courtroom(AOApplication *parent) : QMainWindow() ui_spectator = new AOButton(ui_char_select_background); + connect(ui_reload_theme, SIGNAL(clicked()), this, SLOT(on_reload_theme_clicked())); + set_widgets(); } @@ -102,26 +106,24 @@ void Courtroom::set_widgets() ui_background->move(0, 0); ui_background->resize(m_courtroom_width, m_courtroom_height); - //viewport elements like background, desk, etc. + //viewport elements like background, desk, etc. go here - ui_ic_chatlog->move(231, 319); - ui_ic_chatlog->resize(260, 0); + set_size_and_pos(ui_ic_chatlog, "ic_chatlog"); - ui_ms_chatlog->move(490, 1); - ui_ms_chatlog->move(224, 277); + set_size_and_pos(ui_ms_chatlog, "ms_chatlog"); + + //T0D0: finish the rest of this using set_size_and_pos ui_server_chatlog->move(490, 1); ui_server_chatlog->resize(224, 277); - - ui_mute_list->move(260, 160); ui_mute_list->resize(231, 159); ui_area_list->move(266, 494); //ui_area_list->resize(); - /* + QListWidget *ui_music_list; QLineEdit *ui_ic_chat_message; @@ -148,13 +150,18 @@ void Courtroom::set_widgets() AOButton *ui_objection; AOButton *ui_take_that; - ui_ooc_toggle->move(100,100); + //ui_ooc_toggle->move(100,100); AOButton *ui_witness_testimony; AOButton *ui_cross_examination; AOButton *ui_change_character; - AOButton *ui_reload_theme; + + + set_size_and_pos(ui_reload_theme, "reload_theme"); + ui_reload_theme->setText("Reload theme"); + + AOButton *ui_call_mod; QCheckBox *ui_pre; @@ -191,7 +198,37 @@ void Courtroom::set_widgets() QLineEdit *ui_char_password; AOButton *ui_spectator; - */ +} + +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"; + + pos_size_type design_ini_result = 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); + + if (design_ini_result.width < 0 || design_ini_result.height < 0) + { + //at this point it's pretty much game over + //T0D0: add message box + qDebug() << "CRITICAL ERROR: NO SUITABLE DATA FOR SETTING " << p_identifier; + ao_app->quit(); + } + } + + p_widget->move(design_ini_result.x, design_ini_result.y); + p_widget->resize(design_ini_result.width, design_ini_result.height); +} + +void Courtroom::on_reload_theme_clicked() +{ + get_user_theme() = get_user_theme(); + + set_widgets(); } Courtroom::~Courtroom() diff --git a/courtroom.h b/courtroom.h index 8c24fad..b20b63c 100644 --- a/courtroom.h +++ b/courtroom.h @@ -5,6 +5,7 @@ #include "aobutton.h" #include "aocharbutton.h" #include "aopacket.h" +#include "datatypes.h" #include #include @@ -24,6 +25,8 @@ class Courtroom : public QMainWindow public: explicit Courtroom(AOApplication *parent = 0); void set_widgets(); + void set_size_and_pos(QWidget *p_widget, QString p_identifier); + ~Courtroom(); private: @@ -117,6 +120,8 @@ private: QLineEdit *ui_char_password; AOButton *ui_spectator; +private slots: + void on_reload_theme_clicked(); }; diff --git a/datatypes.h b/datatypes.h index 172c32f..0d396bf 100644 --- a/datatypes.h +++ b/datatypes.h @@ -65,4 +65,12 @@ struct pos_type int y; }; +struct pos_size_type +{ + int x = 0; + int y = 0; + int width = 0; + int height = 0; +}; + #endif // DATATYPES_H diff --git a/lobby.cpp b/lobby.cpp index baf7d3b..e1704b7 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -189,6 +189,14 @@ void Lobby::on_connect_released() { ui_connect->set_image("connect.png"); + //D3BUG START + + ao_app->construct_courtroom(); + + ao_app->destruct_lobby(); + + //D3BUG END + //T0D0: call ao_app to initialize loading sequence } diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 18f1aa0..bd5699c 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -6,6 +6,7 @@ #include #include #include +#include QString get_user_theme(){ QFile config_file(get_base_path() + "config.ini"); @@ -84,3 +85,58 @@ QVector read_serverlist_txt() return f_server_list; } + +pos_size_type get_pos_and_size(QString p_identifier, QString p_design_path) +{ + QFile design_ini; + + pos_size_type return_value; + + design_ini.setFileName(p_design_path); + + if (!design_ini.open(QIODevice::ReadOnly)) + { + qDebug() << "W: Could not open or read " << p_design_path; + //caller should deal with the result properly(check width and height of output for negatives) + return_value.height = -1; + return_value.width = -1; + + return return_value; + } + + QTextStream in(&design_ini); + + while (!in.atEnd()) + { + QString f_line = in.readLine(); + + if (!f_line.startsWith(p_identifier)) + continue; + + QStringList line_elements = f_line.split("="); + + if (line_elements.size() < 2) + continue; + + QStringList sub_line_elements = line_elements.at(1).split(","); + + if (sub_line_elements.size() < 4) + continue; + + //T0D0 check if integer conversion actually succeeded + return_value.x = sub_line_elements.at(0).toInt(); + return_value.y = sub_line_elements.at(1).toInt(); + return_value.width = sub_line_elements.at(2).toInt(); + return_value.height = sub_line_elements.at(3).toInt(); + + return return_value; + } + + qDebug() << "W: Could not find proper " << p_identifier << " in " << p_design_path; + //caller should deal with the result properly(check width and height of output for negatives) + return_value.height = -1; + return_value.width = -1; + + return return_value; +} + diff --git a/text_file_functions.h b/text_file_functions.h index 96cb941..5e3a0b3 100644 --- a/text_file_functions.h +++ b/text_file_functions.h @@ -9,5 +9,6 @@ QString get_user_theme(); void write_to_serverlist_txt(QString p_line); QVector read_serverlist_txt(); +pos_size_type get_pos_and_size(QString p_identifier, QString p_design_path); #endif // TEXT_FILE_FUNCTIONS_H