Fix colors not persisting when refreshing IC log (#204)

Co-authored-by: Cents02 <Cents02@Cents0.me>
This commit is contained in:
windrammer 2020-07-29 16:08:39 -06:00 committed by GitHub
parent 58180371ef
commit fc9fe6b34b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 13 deletions

View File

@ -10,9 +10,9 @@ class chatlogpiece {
public: public:
chatlogpiece(); chatlogpiece();
chatlogpiece(QString p_name, QString p_showname, QString p_message, chatlogpiece(QString p_name, QString p_showname, QString p_message,
bool p_song); bool p_song,int color);
chatlogpiece(QString p_name, QString p_showname, QString p_message, chatlogpiece(QString p_name, QString p_showname, QString p_message,
bool p_song, QDateTime p_datetime); bool p_song, int color, QDateTime p_datetime);
QString get_name(); QString get_name();
QString get_showname(); QString get_showname();
@ -20,7 +20,7 @@ public:
bool is_song(); bool is_song();
QDateTime get_datetime(); QDateTime get_datetime();
QString get_datetime_as_string(); QString get_datetime_as_string();
int get_chat_color();
QString get_full(); QString get_full();
private: private:
@ -28,6 +28,7 @@ private:
QString showname; QString showname;
QString message; QString message;
QDateTime datetime; QDateTime datetime;
int color;
bool p_is_song; bool p_is_song;
}; };

View File

@ -221,7 +221,7 @@ public:
// this function keeps the chatlog scrolled to the top unless there's text // this function keeps the chatlog scrolled to the top unless there's text
// selected // selected
// or the user isn't already scrolled to the top // or the user isn't already scrolled to the top
void append_ic_text(QString p_text, QString p_name = "", QString action = ""); void append_ic_text(QString p_text, QString p_name = "", QString action = "", int color = 0);
// prints who played the song to IC chat and plays said song(if found on local // prints who played the song to IC chat and plays said song(if found on local
// filesystem) takes in a list where the first element is the song name and the // filesystem) takes in a list where the first element is the song name and the

View File

@ -5,27 +5,31 @@ chatlogpiece::chatlogpiece()
name = tr("UNKNOWN"); name = tr("UNKNOWN");
showname = tr("UNKNOWN"); showname = tr("UNKNOWN");
message = tr("UNKNOWN"); message = tr("UNKNOWN");
color = 0;
p_is_song = false; p_is_song = false;
datetime = QDateTime::currentDateTime().toUTC(); datetime = QDateTime::currentDateTime().toUTC();
} }
chatlogpiece::chatlogpiece(QString p_name, QString p_showname, chatlogpiece::chatlogpiece(QString p_name, QString p_showname,
QString p_message, bool p_song) QString p_message, bool p_song, int p_color)
{ {
name = p_name; name = p_name;
showname = p_showname; showname = p_showname;
message = p_message; message = p_message;
p_is_song = p_song; p_is_song = p_song;
color = p_color;
datetime = QDateTime::currentDateTime().toUTC(); datetime = QDateTime::currentDateTime().toUTC();
} }
chatlogpiece::chatlogpiece(QString p_name, QString p_showname, chatlogpiece::chatlogpiece(QString p_name, QString p_showname,
QString p_message, bool p_song, QDateTime p_datetime) QString p_message, bool p_song, int p_color,
QDateTime p_datetime)
{ {
name = p_name; name = p_name;
showname = p_showname; showname = p_showname;
message = p_message; message = p_message;
p_is_song = p_song; p_is_song = p_song;
color = p_color;
datetime = p_datetime.toUTC(); datetime = p_datetime.toUTC();
} }
@ -41,6 +45,8 @@ bool chatlogpiece::is_song() { return p_is_song; }
QString chatlogpiece::get_datetime_as_string() { return datetime.toString(); } QString chatlogpiece::get_datetime_as_string() { return datetime.toString(); }
int chatlogpiece::get_chat_color() { return color; }
QString chatlogpiece::get_full() QString chatlogpiece::get_full()
{ {
QString full = "["; QString full = "[";

View File

@ -1787,7 +1787,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
f_charname = ao_app->get_showname(char_list.at(f_char_id).name); f_charname = ao_app->get_showname(char_list.at(f_char_id).name);
chatlogpiece *temp = chatlogpiece *temp =
new chatlogpiece(f_charname, f_showname, m_chatmessage[MESSAGE], false); new chatlogpiece(f_charname, f_showname, m_chatmessage[MESSAGE], false, m_chatmessage[TEXT_COLOR].toInt());
ic_chatlog_history.append(*temp); ic_chatlog_history.append(*temp);
ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true); ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true);
@ -1796,7 +1796,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
ic_chatlog_history.removeFirst(); ic_chatlog_history.removeFirst();
} }
append_ic_text(m_chatmessage[MESSAGE], f_showname); append_ic_text(m_chatmessage[MESSAGE], f_showname, "", m_chatmessage[TEXT_COLOR].toInt());
int objection_mod = m_chatmessage[OBJECTION_MOD].toInt(); int objection_mod = m_chatmessage[OBJECTION_MOD].toInt();
QString f_char = m_chatmessage[CHAR_NAME]; QString f_char = m_chatmessage[CHAR_NAME];
@ -2482,7 +2482,7 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos,
return p_text_escaped; return p_text_escaped;
} }
void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action) void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action, int color)
{ {
QTextCharFormat bold; QTextCharFormat bold;
QTextCharFormat normal; QTextCharFormat normal;
@ -2495,7 +2495,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action)
if (p_action == "") if (p_action == "")
p_text = filter_ic_text(p_text, ao_app->is_colorlog_enabled(), -1, p_text = filter_ic_text(p_text, ao_app->is_colorlog_enabled(), -1,
m_chatmessage[TEXT_COLOR].toInt()); color);
if (log_goes_downwards) { if (log_goes_downwards) {
const bool is_scrolled_down = const bool is_scrolled_down =
@ -3080,7 +3080,7 @@ void Courtroom::handle_song(QStringList *p_contents)
} }
if (!mute_map.value(n_char)) { if (!mute_map.value(n_char)) {
chatlogpiece *temp = new chatlogpiece(str_char, str_show, f_song, true); chatlogpiece *temp = new chatlogpiece(str_char, str_show, f_song, true, m_chatmessage[TEXT_COLOR].toInt());
ic_chatlog_history.append(*temp); ic_chatlog_history.append(*temp);
ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true); ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true);
@ -4516,14 +4516,14 @@ void Courtroom::on_showname_enable_clicked()
append_ic_text(item.get_message(), item.get_showname(), append_ic_text(item.get_message(), item.get_showname(),
tr("has played a song")); tr("has played a song"));
else else
append_ic_text(item.get_message(), item.get_showname()); append_ic_text(item.get_message(), item.get_showname(), "", item.get_chat_color());
} }
else { else {
if (item.is_song()) if (item.is_song())
append_ic_text(item.get_message(), item.get_name(), append_ic_text(item.get_message(), item.get_name(),
tr("has played a song")); tr("has played a song"));
else else
append_ic_text(item.get_message(), item.get_name()); append_ic_text(item.get_message(), item.get_name(), "", item.get_chat_color());
} }
} }