diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 71c14d9..9e31fa0 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -49,7 +49,8 @@ SOURCES += main.cpp\ aotextedit.cpp \ aoevidencedisplay.cpp \ discord_rich_presence.cpp \ - aooptionsdialog.cpp + aooptionsdialog.cpp \ + chatlogpiece.cpp HEADERS += lobby.h \ aoimage.h \ @@ -82,7 +83,8 @@ HEADERS += lobby.h \ discord_rich_presence.h \ discord-rpc.h \ aooptionsdialog.h \ - text_file_functions.h + text_file_functions.h \ + chatlogpiece.h # 1. You need to get BASS and put the x86 bass DLL/headers in the project root folder # AND the compilation output folder. If you want a static link, you'll probably diff --git a/chatlogpiece.cpp b/chatlogpiece.cpp new file mode 100644 index 0000000..6c861f0 --- /dev/null +++ b/chatlogpiece.cpp @@ -0,0 +1,76 @@ +#include "chatlogpiece.h" + +chatlogpiece::chatlogpiece() +{ + name = "UNKNOWN"; + showname = "UNKNOWN"; + message = "UNKNOWN"; + is_song = false; + datetime = QDateTime::currentDateTime().toUTC(); +} + +chatlogpiece::chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song) +{ + name = p_name; + showname = p_showname; + message = p_message; + is_song = p_song; + datetime = QDateTime::currentDateTime().toUTC(); +} + +chatlogpiece::chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song, QDateTime p_datetime) +{ + name = p_name; + showname = p_showname; + message = p_message; + is_song = p_song; + datetime = p_datetime.toUTC(); +} + +QString chatlogpiece::get_name() +{ + return name; +} + +QString chatlogpiece::get_showname() +{ + return showname; +} + +QString chatlogpiece::get_message() +{ + return message; +} + +QDateTime chatlogpiece::get_datetime() +{ + return datetime; +} + +bool chatlogpiece::get_is_song() +{ + return is_song; +} + +QString chatlogpiece::get_datetime_as_string() +{ + return datetime.toString(); +} + + +QString chatlogpiece::get_full() +{ + QString full = "["; + + full.append(get_datetime_as_string()); + full.append(" UTC] "); + full.append(get_showname()); + full.append(" ("); + full.append(get_name()); + full.append(")"); + if (is_song) + full.append(" has played a song: "); + full.append(get_message()); + + return full; +} diff --git a/chatlogpiece.h b/chatlogpiece.h new file mode 100644 index 0000000..34c5926 --- /dev/null +++ b/chatlogpiece.h @@ -0,0 +1,31 @@ +#ifndef CHATLOGPIECE_H +#define CHATLOGPIECE_H + +#include +#include + +class chatlogpiece +{ +public: + chatlogpiece(); + chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song); + chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song, QDateTime p_datetime); + + QString get_name(); + QString get_showname(); + QString get_message(); + bool get_is_song(); + QDateTime get_datetime(); + QString get_datetime_as_string(); + + QString get_full(); + +private: + QString name; + QString showname; + QString message; + QDateTime datetime; + bool is_song; +}; + +#endif // CHATLOGPIECE_H diff --git a/courtroom.cpp b/courtroom.cpp index 6c66c3f..2eb7d94 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1268,6 +1268,14 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) ui_evidence_present->set_image("present_disabled.png"); } + chatlogpiece* temp = new chatlogpiece(ao_app->get_showname(char_list.at(f_char_id).name), f_showname, ": " + m_chatmessage[MESSAGE], false); + ic_chatlog_history.append(*temp); + + while(ic_chatlog_history.size() > log_maximum_blocks) + { + ic_chatlog_history.removeFirst(); + } + append_ic_text(": " + m_chatmessage[MESSAGE], f_showname); previous_ic_message = f_message; @@ -2555,16 +2563,24 @@ void Courtroom::handle_song(QStringList *p_contents) else { QString str_char = char_list.at(n_char).name; + QString str_show = char_list.at(n_char).name; if (p_contents->length() > 2) { - if (ui_showname_enable->isChecked()) - str_char = p_contents->at(2); + str_show = p_contents->at(2); } if (!mute_map.value(n_char)) { - append_ic_songchange(f_song_clear, str_char); + chatlogpiece* temp = new chatlogpiece(str_char, str_show, f_song, true); + ic_chatlog_history.append(*temp); + + while(ic_chatlog_history.size() > log_maximum_blocks) + { + ic_chatlog_history.removeFirst(); + } + + append_ic_songchange(f_song_clear, str_show); music_player->play(f_song); } } @@ -2768,6 +2784,29 @@ void Courtroom::on_ooc_return_pressed() ui_ooc_chat_message->clear(); return; } + else if (ooc_message.startsWith("/save_chatlog")) + { + QFile file("chatlog.txt"); + + if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) + { + append_server_chatmessage("CLIENT", "Couldn't open chatlog.txt to write into.", "1"); + ui_ooc_chat_message->clear(); + return; + } + + QTextStream out(&file); + + foreach (chatlogpiece item, ic_chatlog_history) { + out << item.get_full() << '\n'; + } + + file.close(); + + append_server_chatmessage("CLIENT", "The IC chatlog has been saved.", "1"); + ui_ooc_chat_message->clear(); + return; + } QStringList packet_contents; packet_contents.append(ui_ooc_chat_name->text()); @@ -3295,6 +3334,26 @@ void Courtroom::on_guard_clicked() void Courtroom::on_showname_enable_clicked() { + ui_ic_chatlog->clear(); + first_message_sent = false; + + foreach (chatlogpiece item, ic_chatlog_history) { + if (ui_showname_enable->isChecked()) + { + if (item.get_is_song()) + append_ic_songchange(item.get_message(), item.get_showname()); + else + append_ic_text(item.get_message(), item.get_showname()); + } + else + { + if (item.get_is_song()) + append_ic_songchange(item.get_message(), item.get_name()); + else + append_ic_text(item.get_message(), item.get_name()); + } + } + ui_ic_chat_message->setFocus(); } diff --git a/courtroom.h b/courtroom.h index 341d6df..1115e36 100644 --- a/courtroom.h +++ b/courtroom.h @@ -18,6 +18,7 @@ #include "aotextedit.h" #include "aoevidencedisplay.h" #include "datatypes.h" +#include "chatlogpiece.h" #include #include @@ -257,6 +258,8 @@ private: QSignalMapper *char_button_mapper; + QVector ic_chatlog_history; + // These map music row items and area row items to their actual IDs. QVector music_row_to_number; QVector area_row_to_number;