From 9682087667e2de26e14406efde960b8c7f0c3c98 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Fri, 27 Jan 2017 01:17:33 +0100 Subject: [PATCH] implemented ooc chat and cleaned up some old headers --- Attorney_Online_remake.pro | 2 - aoapplication.cpp | 17 +++++- aoapplication.h | 1 + aobutton.cpp | 1 - aocharbutton.cpp | 1 - aoimage.cpp | 1 - courtroom.cpp | 110 ++++++++++++++++++++++++++++++++++++- courtroom.h | 18 +++++- lobby.cpp | 15 ++++- lobby.h | 1 + packet_distribution.cpp | 22 +++++--- path_functions.cpp | 2 - path_functions.h | 8 --- text_file_functions.cpp | 36 +++++++++++- text_file_functions.h | 11 ---- 15 files changed, 202 insertions(+), 44 deletions(-) delete mode 100644 path_functions.h delete mode 100644 text_file_functions.h diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 0ce693a..c784578 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -32,8 +32,6 @@ SOURCES += main.cpp\ hardware_functions.cpp HEADERS += lobby.h \ - text_file_functions.h \ - path_functions.h \ aoimage.h \ file_functions.h \ aobutton.h \ diff --git a/aoapplication.cpp b/aoapplication.cpp index 5388fc0..f0576ee 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -1,11 +1,12 @@ -#include +#include "aoapplication.h" #include "lobby.h" #include "courtroom.h" #include "networkmanager.h" -#include "text_file_functions.h" -#include "aoapplication.h" +#include +#include +#include AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) { @@ -29,6 +30,11 @@ void AOApplication::construct_lobby() w_lobby = new Lobby(this); lobby_constructed = true; + QRect screenGeometry = QApplication::desktop()->screenGeometry(); + int x = (screenGeometry.width()-w_lobby->width()) / 2; + int y = (screenGeometry.height()-w_lobby->height()) / 2; + w_lobby->move(x, y); + w_lobby->show(); } @@ -54,6 +60,11 @@ void AOApplication::construct_courtroom() w_courtroom = new Courtroom(this); courtroom_constructed = true; + + QRect screenGeometry = QApplication::desktop()->screenGeometry(); + int x = (screenGeometry.width()-w_courtroom->width()) / 2; + int y = (screenGeometry.height()-w_courtroom->height()) / 2; + w_courtroom->move(x, y); } void AOApplication::destruct_courtroom() diff --git a/aoapplication.h b/aoapplication.h index a63ec41..5cd255c 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -86,6 +86,7 @@ public: 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); + QString get_char_side(QString p_char); private: const int RELEASE = 2; diff --git a/aobutton.cpp b/aobutton.cpp index 0938f51..370eca9 100644 --- a/aobutton.cpp +++ b/aobutton.cpp @@ -1,7 +1,6 @@ #include "aobutton.h" #include "debug_functions.h" -#include "path_functions.h" #include "file_functions.h" #include diff --git a/aocharbutton.cpp b/aocharbutton.cpp index 01b3c1c..d6edf80 100644 --- a/aocharbutton.cpp +++ b/aocharbutton.cpp @@ -1,6 +1,5 @@ #include "aocharbutton.h" -#include "path_functions.h" #include "file_functions.h" #include diff --git a/aoimage.cpp b/aoimage.cpp index bfe1142..4b0e973 100644 --- a/aoimage.cpp +++ b/aoimage.cpp @@ -1,5 +1,4 @@ #include "file_functions.h" -#include "path_functions.h" #include "aoimage.h" diff --git a/courtroom.cpp b/courtroom.cpp index 381d159..f408b14 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2,8 +2,8 @@ #include "aoapplication.h" #include "lobby.h" -#include "text_file_functions.h" -#include "path_functions.h" +#include "hardware_functions.h" +#include "file_functions.h" #include @@ -18,22 +18,33 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() //viewport elements like background, desk, etc. ui_ic_chatlog = new QPlainTextEdit(this); + ui_ic_chatlog->setReadOnly(true); ui_ms_chatlog = new QPlainTextEdit(this); - ui_server_chatlog = new QPlainTextEdit(this); + ui_ms_chatlog->setReadOnly(true); + ui_ms_chatlog->hide(); + ui_server_chatlog = new QPlainTextEdit(this); + ui_server_chatlog->setReadOnly(true); ui_mute_list = new QListWidget(this); ui_area_list = new QListWidget(this); ui_music_list = new QListWidget(this); ui_ic_chat_message = new QLineEdit(this); + ui_ic_chat_message->setFrame(false); ui_ooc_chat_message = new QLineEdit(this); + ui_ooc_chat_message->setFrame(false); + ui_ooc_chat_name = new QLineEdit(this); + ui_ooc_chat_name->setFrame(false); + ui_ooc_chat_name->setPlaceholderText("Name"); ui_area_password = new QLineEdit(this); + ui_area_password->setFrame(false); ui_music_search = new QLineEdit(this); + ui_music_search->setFrame(false); //emote buttons @@ -138,6 +149,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_spectator = new AOButton(ui_char_select_background, ao_app); + connect(ui_ooc_chat_message, SIGNAL(returnPressed()), this, SLOT(on_ooc_return_pressed())); + connect(ui_ooc_toggle, SIGNAL(clicked()), this, SLOT(on_ooc_toggle_clicked())); connect(ui_change_character, SIGNAL(clicked()), this, SLOT(on_change_character_clicked())); connect(ui_reload_theme, SIGNAL(clicked()), this, SLOT(on_reload_theme_clicked())); @@ -390,6 +403,86 @@ void Courtroom::set_char_select_page() } +void Courtroom::enter_courtroom(int p_cid) +{ + m_cid = p_cid; + QString f_char = char_list.at(m_cid).name; + + //T0D0: set emote buttons + + QString side = ao_app->get_char_side(f_char); + + if (side == "jud") + { + ui_witness_testimony->show(); + ui_cross_examination->show(); + ui_defense_minus->show(); + ui_defense_plus->show(); + ui_prosecution_minus->show(); + ui_prosecution_plus->show(); + } + else + { + ui_witness_testimony->hide(); + ui_cross_examination->hide(); + ui_defense_minus->hide(); + ui_defense_plus->hide(); + ui_prosecution_minus->hide(); + ui_prosecution_plus->hide(); + } + + ui_char_select_background->hide(); +} + +void Courtroom::append_ms_chatmessage(QString f_message) +{ + ui_ms_chatlog->appendPlainText(f_message); +} + +void Courtroom::append_server_chatmessage(QString f_message) +{ + ui_server_chatlog->appendPlainText(f_message); +} + +void Courtroom::on_ooc_return_pressed() +{ + if (ui_ooc_chat_message->text() == "" || ui_ooc_chat_name->text() == "") + return; + + QStringList packet_contents; + packet_contents.append(ui_ooc_chat_name->text()); + packet_contents.append(ui_ooc_chat_message->text()); + + AOPacket *f_packet = new AOPacket("CT", packet_contents); + + if (server_ooc) + ao_app->send_server_packet(f_packet); + else + ao_app->send_ms_packet(f_packet); + + ui_ooc_chat_message->clear(); +} + +void Courtroom::on_ooc_toggle_clicked() +{ + if (server_ooc) + { + ui_ms_chatlog->show(); + ui_server_chatlog->hide(); + ui_ooc_toggle->setText("Master"); + + server_ooc = false; + } + else + { + ui_ms_chatlog->hide(); + ui_server_chatlog->show(); + ui_ooc_toggle->setText("Server"); + + server_ooc = true; + } +} + void Courtroom::on_change_character_clicked() { ui_char_select_background->show(); @@ -428,7 +521,18 @@ void Courtroom::on_spectator_clicked() void Courtroom::char_clicked(int n_char) { + int n_real_char = n_char + current_char_page * 90; + QString char_ini_path = ao_app->get_character_path(char_list.at(n_real_char).name) + "char.ini"; + + if (!file_exists(char_ini_path)) + { + qDebug() << "did not find " << char_ini_path; + //T0D0: call error + return; + } + + ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_real_char) + "#" + get_hdid() + "#%")); } Courtroom::~Courtroom() diff --git a/courtroom.h b/courtroom.h index 5b2a111..9f25387 100644 --- a/courtroom.h +++ b/courtroom.h @@ -35,6 +35,11 @@ public: void set_taken(int n_char, bool p_taken); void set_char_select_page(); + void enter_courtroom(int p_cid); + + void append_ms_chatmessage(QString f_message); + void append_server_chatmessage(QString f_message); + ~Courtroom(); private: @@ -59,6 +64,12 @@ private: //makes char arithmetic easier int current_char_page = 0; + //character id, which index of the char_list the player is + int m_cid = 0; + + //wether the ooc chat is server or master chat, true is server + bool server_ooc = true; + AOImage *ui_background; //T0D0: add viewport elements like background, desk, etc. @@ -143,16 +154,19 @@ private: AOButton *ui_spectator; private slots: + void on_ooc_return_pressed(); + void on_ooc_toggle_clicked(); + void on_change_character_clicked(); void on_reload_theme_clicked(); void on_back_to_lobby_clicked(); - void on_spectator_clicked(); - void on_char_select_left_clicked(); void on_char_select_right_clicked(); + void on_spectator_clicked(); + void char_clicked(int n_char); }; diff --git a/lobby.cpp b/lobby.cpp index 3709114..8bc67bd 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -1,7 +1,5 @@ #include "lobby.h" -#include "path_functions.h" -#include "text_file_functions.h" #include "debug_functions.h" #include "aoapplication.h" #include "networkmanager.h" @@ -27,6 +25,7 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() ui_description = new QPlainTextEdit(this); ui_chatbox = new QPlainTextEdit(this); ui_chatname = new QLineEdit(this); + ui_chatname->setPlaceholderText("Name"); ui_chatmessage = new QLineEdit(this); ui_loading_background = new AOImage(this, ao_app); ui_loading_text = new QTextEdit(ui_loading_background); @@ -152,6 +151,13 @@ void Lobby::set_loading_text(QString p_text) ui_loading_text->append(p_text); } +QString Lobby::get_chatlog() +{ + QString return_value = ui_chatbox->toPlainText(); + + return return_value; +} + void Lobby::on_public_servers_clicked() { ui_public_servers->set_image("publicservers_selected.png"); @@ -260,6 +266,11 @@ void Lobby::on_server_list_clicked(QModelIndex p_model) void Lobby::on_chatfield_return_pressed() { + //no you can't send empty messages + if (ui_chatname->text() == "" || ui_chatmessage->text() == "") + return; + + QString f_header = "CT"; QStringList f_contents{ui_chatname->text(), ui_chatmessage->text()}; diff --git a/lobby.h b/lobby.h index 8f9b5ea..ebdc05b 100644 --- a/lobby.h +++ b/lobby.h @@ -29,6 +29,7 @@ public: void set_loading_text(QString p_text); void show_loading_overlay(){ui_loading_background->show();} void hide_loading_overlay(){ui_loading_background->hide();} + QString get_chatlog(); ~Lobby(); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index d53b5a6..163c744 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -63,8 +63,7 @@ void AOApplication::ms_packet_received(AOPacket *p_packet) } if (courtroom_constructed) { - //T0D0: uncomment this when it's implemented - //w_courtroom->append_ms_chat_message(message_line); + w_courtroom->append_ms_chatmessage(message_line); } } } @@ -77,7 +76,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) QStringList f_contents = p_packet->get_contents(); QString f_packet = p_packet->to_string(); - qDebug() << "R: " << f_packet; + if (header != "checkconnection") + qDebug() << "R: " << f_packet; if (header == "decryptor") { @@ -113,10 +113,9 @@ void AOApplication::server_packet_received(AOPacket *p_packet) return; } - //QString message_line = f_contents.at(0) + ": " + f_contents.at(1); + QString message_line = f_contents.at(0) + ": " + f_contents.at(1); - //T0D0, uncomment when implemented - //w_courtroom->append_ooc_chatmessage(message_line) + w_courtroom->append_server_chatmessage(message_line); } else if (header == "PN") { @@ -176,7 +175,6 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_lobby->set_loading_text("Loading chars:\n" + QString::number(loaded_chars) + "/" + QString::number(char_list_size)); w_courtroom->append_char(f_char); - //qDebug() << "appended " << f_char.name << " to char_list"; } if (loaded_chars < char_list_size) @@ -281,10 +279,20 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->set_char_select_page(); + w_courtroom->append_ms_chatmessage(w_lobby->get_chatlog()); + w_courtroom->show(); destruct_lobby(); } + //server accepting char request(CC) packet + if (header == "PV") + { + if (f_contents.size() < 3) + return; + + w_courtroom->enter_courtroom(f_contents.at(2).toInt()); + } } void AOApplication::send_ms_packet(AOPacket *p_packet) diff --git a/path_functions.cpp b/path_functions.cpp index 7afd923..5b9e92e 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -1,7 +1,5 @@ #include "aoapplication.h" -#include "text_file_functions.h" - #include #include diff --git a/path_functions.h b/path_functions.h deleted file mode 100644 index 2f37a0c..0000000 --- a/path_functions.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef PATH_FUNCTIONS_H -#define PATH_FUNCTIONS_H - -#include - - - -#endif // PATH_FUNCTIONS_H diff --git a/text_file_functions.cpp b/text_file_functions.cpp index db1ecc7..dc97c60 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -1,6 +1,5 @@ #include "aoapplication.h" -#include "path_functions.h" #include "file_functions.h" #include @@ -140,3 +139,38 @@ pos_size_type AOApplication::get_pos_and_size(QString p_identifier, QString p_de return return_value; } +QString AOApplication::get_char_side(QString p_char) +{ + QString char_ini_path = get_character_path(p_char) + "char.ini"; + + QFile char_ini; + + char_ini.setFileName(char_ini_path); + + if (!char_ini.open(QIODevice::ReadOnly)) + { + //default to wit and don't make a big deal about it + return "wit"; + } + + QTextStream in(&char_ini); + + while(!in.atEnd()) + { + QString line = in.readLine(); + + if (!line.startsWith("side")) + continue; + + QStringList line_elements = line.split("="); + + if (line_elements.size() < 2) + continue; + + //note that we do not validate if this is a valid side or not. that's up to the caller + return line_elements.at(1).trimmed().toLower(); + } + + return "wit"; +} + diff --git a/text_file_functions.h b/text_file_functions.h deleted file mode 100644 index 54abd4d..0000000 --- a/text_file_functions.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef TEXT_FILE_FUNCTIONS_H -#define TEXT_FILE_FUNCTIONS_H - -#include "datatypes.h" - -#include -#include - - - -#endif // TEXT_FILE_FUNCTIONS_H