Skip to content

Commit 5063880

Browse files
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
1 parent 005ecca commit 5063880

5 files changed

Lines changed: 50 additions & 94 deletions

File tree

include/courtroom.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class Courtroom : public QMainWindow {
121121

122122
void character_loading_finished();
123123

124+
//
125+
void set_courtroom_size();
126+
124127
// sets position of widgets based on theme ini files
125128
void set_widgets();
126129

@@ -147,11 +150,8 @@ class Courtroom : public QMainWindow {
147150

148151
void set_window_title(QString p_title);
149152

150-
// reads theme inis and sets size and pos based on the identifier
151-
void set_size_and_pos(QWidget *p_widget, QString p_identifier);
152-
153-
// reads theme and char inis and sets size and pos based on the identifier
154-
void set_size_and_pos(QWidget *p_widget, QString p_identifier, QString p_char);
153+
// reads theme and sets size and pos based on the identifier (using p_misc if provided)
154+
void set_size_and_pos(QWidget *p_widget, QString p_identifier, QString p_misc="");
155155

156156
// reads theme inis and returns the size and pos as defined by it
157157
QPoint get_theme_pos(QString p_identifier);
@@ -576,10 +576,6 @@ class Courtroom : public QMainWindow {
576576
int evidence_rows = 3;
577577
int max_evidence_on_page = 18;
578578

579-
// is set to true if the bg folder contains defensedesk.png,
580-
// prosecutiondesk.png and stand.png
581-
bool is_ao2_bg = false;
582-
583579
// whether the ooc chat is server or master chat, true is server
584580
bool server_ooc = true;
585581

src/aolayer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ void CharLayer::load_network_effects()
450450

451451
void CharLayer::play_frame_effect(int p_frame)
452452
{
453+
if (p_frame >= movie_effects.size()) {
454+
qDebug() << "W: Attempted to play a frame effect bigger than the size of movie_effects";
455+
return;
456+
}
453457
if (p_frame < max_frames) {
454458
foreach (QString effect, movie_effects[p_frame]) {
455459
if (effect == "shake") {

src/charselect.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ void Courtroom::char_clicked(int n_char)
177177
}
178178
else {
179179
update_character(n_char);
180-
set_widgets(); // so we don't erroneously keep the charselect's fixedSize
180+
enter_courtroom();
181+
set_courtroom_size();
181182
}
182183

183184
if (n_char != -1)

src/courtroom.cpp

Lines changed: 36 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,28 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
437437
set_char_select();
438438
}
439439

440+
void Courtroom::set_courtroom_size()
441+
{
442+
QString filename = "courtroom_design.ini";
443+
pos_size_type f_courtroom =
444+
ao_app->get_element_dimensions("courtroom", filename);
445+
446+
if (f_courtroom.width < 0 || f_courtroom.height < 0) {
447+
qDebug() << "W: did not find courtroom width or height in " << filename;
448+
449+
this->setFixedSize(714, 668);
450+
}
451+
else {
452+
m_courtroom_width = f_courtroom.width;
453+
m_courtroom_height = f_courtroom.height;
454+
455+
this->setFixedSize(f_courtroom.width, f_courtroom.height);
456+
}
457+
ui_background->move(0, 0);
458+
ui_background->resize(m_courtroom_width, m_courtroom_height);
459+
ui_background->set_image("courtroombackground");
460+
}
461+
440462
void Courtroom::set_mute_list()
441463
{
442464
mute_map.clear();
@@ -480,27 +502,7 @@ void Courtroom::set_widgets()
480502
QSettings settings(ao_app->get_theme_path(filename, ao_app->current_theme), QSettings::IniFormat);
481503
ao_app->default_theme = settings.value("default_theme", "default").toString();
482504

483-
pos_size_type f_courtroom =
484-
ao_app->get_element_dimensions("courtroom", filename);
485-
486-
if (f_courtroom.width < 0 || f_courtroom.height < 0) {
487-
qDebug() << "W: did not find courtroom width or height in " << filename;
488-
489-
this->setFixedSize(714, 668);
490-
}
491-
else {
492-
m_courtroom_width = f_courtroom.width;
493-
m_courtroom_height = f_courtroom.height;
494-
495-
this->setFixedSize(f_courtroom.width, f_courtroom.height);
496-
}
497-
498505
set_fonts();
499-
500-
ui_background->move(0, 0);
501-
ui_background->resize(m_courtroom_width, m_courtroom_height);
502-
ui_background->set_image("courtroombackground");
503-
504506
set_size_and_pos(ui_viewport, "viewport");
505507

506508
// If there is a point to it, show all CCCC features.
@@ -680,17 +682,8 @@ void Courtroom::set_widgets()
680682
for (int i = 0; i < max_clocks; i++) {
681683
set_size_and_pos(ui_clock[i], "clock_" + QString::number(i));
682684
}
683-
684-
if (is_ao2_bg) {
685-
set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message");
686-
// set_size_and_pos(ui_vp_chatbox, "ao2_chatbox");
687-
set_size_and_pos(ui_ic_chat_name, "ao2_ic_chat_name");
688-
}
689-
else {
690-
set_size_and_pos(ui_ic_chat_message, "ic_chat_message");
691-
// set_size_and_pos(ui_vp_chatbox, "chatbox");
692-
set_size_and_pos(ui_ic_chat_name, "ic_chat_name");
693-
}
685+
set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message");
686+
set_size_and_pos(ui_ic_chat_name, "ao2_ic_chat_name");
694687

695688
ui_ic_chat_message->setStyleSheet(
696689
"QLineEdit{background-color: rgba(100, 100, 100, 255);}");
@@ -1137,30 +1130,12 @@ void Courtroom::set_window_title(QString p_title)
11371130
this->setWindowTitle(p_title);
11381131
}
11391132

1140-
void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier)
1133+
void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier, QString p_misc)
11411134
{
11421135
QString filename = "courtroom_design.ini";
11431136

11441137
pos_size_type design_ini_result =
1145-
ao_app->get_element_dimensions(p_identifier, filename);
1146-
1147-
if (design_ini_result.width < 0 || design_ini_result.height < 0) {
1148-
qDebug() << "W: could not find \"" << p_identifier << "\" in " << filename;
1149-
p_widget->hide();
1150-
}
1151-
else {
1152-
p_widget->move(design_ini_result.x, design_ini_result.y);
1153-
p_widget->resize(design_ini_result.width, design_ini_result.height);
1154-
}
1155-
}
1156-
1157-
void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier,
1158-
QString p_char)
1159-
{
1160-
QString filename = "courtroom_design.ini";
1161-
1162-
pos_size_type design_ini_result =
1163-
ao_app->get_element_dimensions(p_identifier, filename, ao_app->get_chat(p_char));
1138+
ao_app->get_element_dimensions(p_identifier, filename, p_misc);
11641139

11651140
if (design_ini_result.width < 0 || design_ini_result.height < 0) {
11661141
qDebug() << "W: could not find \"" << p_identifier << "\" in " << filename;
@@ -1268,17 +1243,6 @@ void Courtroom::set_background(QString p_background, bool display)
12681243

12691244
set_pos_dropdown(pos_list);
12701245

1271-
is_ao2_bg = true;
1272-
1273-
if (is_ao2_bg) {
1274-
// set_size_and_pos(ui_vp_chatbox, "ao2_chatbox");
1275-
set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message");
1276-
}
1277-
else {
1278-
// set_size_and_pos(ui_vp_chatbox, "chatbox");
1279-
set_size_and_pos(ui_ic_chat_message, "ic_chat_message");
1280-
}
1281-
12821246
if (display) {
12831247
ui_vp_speedlines->stop();
12841248
ui_vp_player_char->stop();
@@ -1461,12 +1425,6 @@ void Courtroom::update_character(int p_cid)
14611425
}
14621426
}
14631427
}
1464-
if (is_ao2_bg) {
1465-
set_size_and_pos(ui_vp_chatbox, "ao2_chatbox", f_char);
1466-
}
1467-
else {
1468-
set_size_and_pos(ui_vp_chatbox, "chatbox", f_char);
1469-
}
14701428

14711429
if (m_cid != -1) // there is no name at char_list -1, and we crash if we try
14721430
// to find one
@@ -1483,8 +1441,6 @@ void Courtroom::update_character(int p_cid)
14831441

14841442
void Courtroom::enter_courtroom()
14851443
{
1486-
set_widgets();
1487-
14881444
current_evidence_page = 0;
14891445
current_evidence = 0;
14901446

@@ -2546,23 +2502,18 @@ void Courtroom::initialize_chatbox()
25462502
else {
25472503
ui_vp_showname->setText(m_chatmessage[SHOWNAME]);
25482504
}
2505+
QString customchar;
2506+
if (ao_app->is_customchat_enabled())
2507+
customchar = m_chatmessage[CHAR_NAME];
2508+
QString p_misc = ao_app->get_chat(customchar);
25492509

2550-
if (is_ao2_bg) {
2551-
set_size_and_pos(ui_vp_chatbox, "ao2_chatbox", m_chatmessage[CHAR_NAME]);
2552-
}
2553-
else {
2554-
set_size_and_pos(ui_vp_chatbox, "chatbox", m_chatmessage[CHAR_NAME]);
2555-
}
2556-
set_size_and_pos(ui_vp_showname, "showname", m_chatmessage[CHAR_NAME]);
2557-
set_size_and_pos(ui_vp_message, "message", m_chatmessage[CHAR_NAME]);
2510+
set_size_and_pos(ui_vp_chatbox, "ao2_chatbox", p_misc);
2511+
set_size_and_pos(ui_vp_showname, "showname", p_misc);
2512+
set_size_and_pos(ui_vp_message, "message", p_misc);
25582513
ui_vp_message->move(ui_vp_message->x() + ui_vp_chatbox->x(),
25592514
ui_vp_message->y() + ui_vp_chatbox->y());
25602515
ui_vp_message->setTextInteractionFlags(Qt::NoTextInteraction);
25612516

2562-
QString customchar;
2563-
if (ao_app->is_customchat_enabled())
2564-
customchar = m_chatmessage[CHAR_NAME];
2565-
QString p_misc = ao_app->get_chat(customchar);
25662517
if (ui_vp_showname->text().trimmed().isEmpty()) // Whitespace showname
25672518
{
25682519
ui_vp_chatbox->set_image("chatblank", p_misc);
@@ -5264,8 +5215,10 @@ void Courtroom::on_reload_theme_clicked()
52645215
{
52655216
ao_app->reload_theme();
52665217

5267-
enter_courtroom();
5218+
set_courtroom_size();
5219+
set_widgets();
52685220
update_character(m_cid);
5221+
enter_courtroom();
52695222

52705223
anim_state = 4;
52715224
text_state = 3;

src/packet_distribution.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,10 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
493493

494494
w_courtroom->enter_courtroom();
495495

496-
if (courtroom_constructed)
496+
if (courtroom_constructed) {
497+
w_courtroom->set_courtroom_size();
497498
w_courtroom->update_character(f_contents.at(2).toInt());
499+
}
498500
}
499501
else if (header == "MS") {
500502
if (courtroom_constructed && courtroom_loaded)

0 commit comments

Comments
 (0)