diff options
| author | Crystalwarrior <varsash@gmail.com> | 2021-02-16 11:04:07 +0300 |
|---|---|---|
| committer | Crystalwarrior <varsash@gmail.com> | 2021-02-16 11:04:07 +0300 |
| commit | 5063880530c98d17e6d15a888f7c4a8462351e52 (patch) | |
| tree | 06c1d2e35d997d76ac41465e65ad96c8535ddb46 /src | |
| parent | 005ecca9d79e6a5973df487b6b4e094003e361a6 (diff) | |
Patch a segfault by play_frame_effect being wacky
Split behavior for courtroom resizing into its own function
Use that function to optimize character changing screen
Fix reload theme breaking the background positioning
Fix changing character breaking the background positioning
Fix excessive set_widgets() calls that caused unnecessary lag
Fix unnecessary set_size_and_pos calls that didn't need to be there
Only call size_and_pos on the chatbox in the initialize_chatbox func
Remove checks for a boolean that will always be true
Simplify two functions that copy-paste code called set_size_and_pos into a single one
Fix "disable custom chat" setting not being used when setting chat sizes and pos
Diffstat (limited to 'src')
| -rw-r--r-- | src/aolayer.cpp | 4 | ||||
| -rw-r--r-- | src/charselect.cpp | 3 | ||||
| -rw-r--r-- | src/courtroom.cpp | 119 | ||||
| -rw-r--r-- | src/packet_distribution.cpp | 4 |
4 files changed, 45 insertions, 85 deletions
diff --git a/src/aolayer.cpp b/src/aolayer.cpp index e766495..8d2c796 100644 --- a/src/aolayer.cpp +++ b/src/aolayer.cpp @@ -450,6 +450,10 @@ void CharLayer::load_network_effects() void CharLayer::play_frame_effect(int p_frame) { + if (p_frame >= movie_effects.size()) { + qDebug() << "W: Attempted to play a frame effect bigger than the size of movie_effects"; + return; + } if (p_frame < max_frames) { foreach (QString effect, movie_effects[p_frame]) { if (effect == "shake") { diff --git a/src/charselect.cpp b/src/charselect.cpp index 4f3ba99..510d8c0 100644 --- a/src/charselect.cpp +++ b/src/charselect.cpp @@ -177,7 +177,8 @@ void Courtroom::char_clicked(int n_char) } else { update_character(n_char); - set_widgets(); // so we don't erroneously keep the charselect's fixedSize + enter_courtroom(); + set_courtroom_size(); } if (n_char != -1) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index b9ca070..3d67def 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -437,6 +437,28 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() set_char_select(); } +void Courtroom::set_courtroom_size() +{ + QString filename = "courtroom_design.ini"; + pos_size_type f_courtroom = + ao_app->get_element_dimensions("courtroom", filename); + + if (f_courtroom.width < 0 || f_courtroom.height < 0) { + qDebug() << "W: did not find courtroom width or height in " << filename; + + this->setFixedSize(714, 668); + } + else { + m_courtroom_width = f_courtroom.width; + m_courtroom_height = f_courtroom.height; + + this->setFixedSize(f_courtroom.width, f_courtroom.height); + } + ui_background->move(0, 0); + ui_background->resize(m_courtroom_width, m_courtroom_height); + ui_background->set_image("courtroombackground"); +} + void Courtroom::set_mute_list() { mute_map.clear(); @@ -480,27 +502,7 @@ void Courtroom::set_widgets() QSettings settings(ao_app->get_theme_path(filename, ao_app->current_theme), QSettings::IniFormat); ao_app->default_theme = settings.value("default_theme", "default").toString(); - pos_size_type f_courtroom = - ao_app->get_element_dimensions("courtroom", filename); - - if (f_courtroom.width < 0 || f_courtroom.height < 0) { - qDebug() << "W: did not find courtroom width or height in " << filename; - - this->setFixedSize(714, 668); - } - else { - m_courtroom_width = f_courtroom.width; - m_courtroom_height = f_courtroom.height; - - this->setFixedSize(f_courtroom.width, f_courtroom.height); - } - set_fonts(); - - ui_background->move(0, 0); - ui_background->resize(m_courtroom_width, m_courtroom_height); - ui_background->set_image("courtroombackground"); - set_size_and_pos(ui_viewport, "viewport"); // If there is a point to it, show all CCCC features. @@ -680,17 +682,8 @@ void Courtroom::set_widgets() for (int i = 0; i < max_clocks; i++) { set_size_and_pos(ui_clock[i], "clock_" + QString::number(i)); } - - if (is_ao2_bg) { - set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); - // set_size_and_pos(ui_vp_chatbox, "ao2_chatbox"); - set_size_and_pos(ui_ic_chat_name, "ao2_ic_chat_name"); - } - else { - set_size_and_pos(ui_ic_chat_message, "ic_chat_message"); - // set_size_and_pos(ui_vp_chatbox, "chatbox"); - set_size_and_pos(ui_ic_chat_name, "ic_chat_name"); - } + set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); + set_size_and_pos(ui_ic_chat_name, "ao2_ic_chat_name"); ui_ic_chat_message->setStyleSheet( "QLineEdit{background-color: rgba(100, 100, 100, 255);}"); @@ -1137,30 +1130,12 @@ void Courtroom::set_window_title(QString p_title) this->setWindowTitle(p_title); } -void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier) +void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier, QString p_misc) { QString filename = "courtroom_design.ini"; pos_size_type design_ini_result = - ao_app->get_element_dimensions(p_identifier, filename); - - if (design_ini_result.width < 0 || design_ini_result.height < 0) { - qDebug() << "W: could not find \"" << p_identifier << "\" in " << filename; - p_widget->hide(); - } - else { - p_widget->move(design_ini_result.x, design_ini_result.y); - p_widget->resize(design_ini_result.width, design_ini_result.height); - } -} - -void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier, - QString p_char) -{ - QString filename = "courtroom_design.ini"; - - pos_size_type design_ini_result = - ao_app->get_element_dimensions(p_identifier, filename, ao_app->get_chat(p_char)); + ao_app->get_element_dimensions(p_identifier, filename, p_misc); if (design_ini_result.width < 0 || design_ini_result.height < 0) { qDebug() << "W: could not find \"" << p_identifier << "\" in " << filename; @@ -1268,17 +1243,6 @@ void Courtroom::set_background(QString p_background, bool display) set_pos_dropdown(pos_list); - is_ao2_bg = true; - - if (is_ao2_bg) { - // set_size_and_pos(ui_vp_chatbox, "ao2_chatbox"); - set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); - } - else { - // set_size_and_pos(ui_vp_chatbox, "chatbox"); - set_size_and_pos(ui_ic_chat_message, "ic_chat_message"); - } - if (display) { ui_vp_speedlines->stop(); ui_vp_player_char->stop(); @@ -1461,12 +1425,6 @@ void Courtroom::update_character(int p_cid) } } } - if (is_ao2_bg) { - set_size_and_pos(ui_vp_chatbox, "ao2_chatbox", f_char); - } - else { - set_size_and_pos(ui_vp_chatbox, "chatbox", f_char); - } if (m_cid != -1) // there is no name at char_list -1, and we crash if we try // to find one @@ -1483,8 +1441,6 @@ void Courtroom::update_character(int p_cid) void Courtroom::enter_courtroom() { - set_widgets(); - current_evidence_page = 0; current_evidence = 0; @@ -2546,23 +2502,18 @@ void Courtroom::initialize_chatbox() else { ui_vp_showname->setText(m_chatmessage[SHOWNAME]); } + QString customchar; + if (ao_app->is_customchat_enabled()) + customchar = m_chatmessage[CHAR_NAME]; + QString p_misc = ao_app->get_chat(customchar); - if (is_ao2_bg) { - set_size_and_pos(ui_vp_chatbox, "ao2_chatbox", m_chatmessage[CHAR_NAME]); - } - else { - set_size_and_pos(ui_vp_chatbox, "chatbox", m_chatmessage[CHAR_NAME]); - } - set_size_and_pos(ui_vp_showname, "showname", m_chatmessage[CHAR_NAME]); - set_size_and_pos(ui_vp_message, "message", m_chatmessage[CHAR_NAME]); + set_size_and_pos(ui_vp_chatbox, "ao2_chatbox", p_misc); + set_size_and_pos(ui_vp_showname, "showname", p_misc); + set_size_and_pos(ui_vp_message, "message", p_misc); ui_vp_message->move(ui_vp_message->x() + ui_vp_chatbox->x(), ui_vp_message->y() + ui_vp_chatbox->y()); ui_vp_message->setTextInteractionFlags(Qt::NoTextInteraction); - QString customchar; - if (ao_app->is_customchat_enabled()) - customchar = m_chatmessage[CHAR_NAME]; - QString p_misc = ao_app->get_chat(customchar); if (ui_vp_showname->text().trimmed().isEmpty()) // Whitespace showname { ui_vp_chatbox->set_image("chatblank", p_misc); @@ -5264,8 +5215,10 @@ void Courtroom::on_reload_theme_clicked() { ao_app->reload_theme(); - enter_courtroom(); + set_courtroom_size(); + set_widgets(); update_character(m_cid); + enter_courtroom(); anim_state = 4; text_state = 3; diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 1c88120..1053c20 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -493,8 +493,10 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->enter_courtroom(); - if (courtroom_constructed) + if (courtroom_constructed) { + w_courtroom->set_courtroom_size(); w_courtroom->update_character(f_contents.at(2).toInt()); + } } else if (header == "MS") { if (courtroom_constructed && courtroom_loaded) |
