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:
chatlogpiece();
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,
bool p_song, QDateTime p_datetime);
bool p_song, int color, QDateTime p_datetime);
QString get_name();
QString get_showname();
@ -20,7 +20,7 @@ public:
bool is_song();
QDateTime get_datetime();
QString get_datetime_as_string();
int get_chat_color();
QString get_full();
private:
@ -28,6 +28,7 @@ private:
QString showname;
QString message;
QDateTime datetime;
int color;
bool p_is_song;
};

View File

@ -221,7 +221,7 @@ public:
// this function keeps the chatlog scrolled to the top unless there's text
// selected
// 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
// 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");
showname = tr("UNKNOWN");
message = tr("UNKNOWN");
color = 0;
p_is_song = false;
datetime = QDateTime::currentDateTime().toUTC();
}
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;
showname = p_showname;
message = p_message;
p_is_song = p_song;
color = p_color;
datetime = QDateTime::currentDateTime().toUTC();
}
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;
showname = p_showname;
message = p_message;
p_is_song = p_song;
color = p_color;
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(); }
int chatlogpiece::get_chat_color() { return color; }
QString chatlogpiece::get_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);
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);
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();
}
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();
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;
}
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 normal;
@ -2495,7 +2495,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action)
if (p_action == "")
p_text = filter_ic_text(p_text, ao_app->is_colorlog_enabled(), -1,
m_chatmessage[TEXT_COLOR].toInt());
color);
if (log_goes_downwards) {
const bool is_scrolled_down =
@ -3080,7 +3080,7 @@ void Courtroom::handle_song(QStringList *p_contents)
}
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);
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(),
tr("has played a song"));
else
append_ic_text(item.get_message(), item.get_showname());
append_ic_text(item.get_message(), item.get_showname(), "", item.get_chat_color());
}
else {
if (item.is_song())
append_ic_text(item.get_message(), item.get_name(),
tr("has played a song"));
else
append_ic_text(item.get_message(), item.get_name());
append_ic_text(item.get_message(), item.get_name(), "", item.get_chat_color());
}
}