diff options
| -rw-r--r-- | include/aoapplication.h | 2 | ||||
| -rw-r--r-- | include/aomovie.h | 5 | ||||
| -rw-r--r-- | include/aoscene.h | 1 | ||||
| -rw-r--r-- | include/courtroom.h | 25 | ||||
| -rw-r--r-- | src/aocharmovie.cpp | 36 | ||||
| -rw-r--r-- | src/aomovie.cpp | 87 | ||||
| -rw-r--r-- | src/aoscene.cpp | 65 | ||||
| -rw-r--r-- | src/courtroom.cpp | 101 | ||||
| -rw-r--r-- | src/text_file_functions.cpp | 15 |
9 files changed, 143 insertions, 194 deletions
diff --git a/include/aoapplication.h b/include/aoapplication.h index 5475eb7..19924e4 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -219,7 +219,7 @@ public: //Figure out if we can opus this or if we should fall back to wav QString get_sfx_suffix(QString sound_to_check); - // Can we use APNG for this? If not, fall back to a gif. + // Can we use APNG for this? If not, WEBP? If not, GIF? If not, fall back to PNG. QString get_image_suffix(QString path_to_check); //Returns the value of p_search_line within target_tag and terminator_tag diff --git a/include/aomovie.h b/include/aomovie.h index 1f278bf..33b3158 100644 --- a/include/aomovie.h +++ b/include/aomovie.h @@ -15,13 +15,15 @@ public: AOMovie(QWidget *p_parent, AOApplication *p_ao_app); void set_play_once(bool p_play_once); - void play(QString p_gif, QString p_char = "", QString p_custom_theme = ""); + void start_timer(int delay); + void play(QString p_gif, QString p_char = "", QString p_custom_theme = "", int duration = 0); void combo_resize(int w, int h); void stop(); private: QMovie *m_movie; AOApplication *ao_app; + QTimer *timer; bool play_once = true; signals: @@ -29,6 +31,7 @@ signals: private slots: void frame_change(int n_frame); + void timer_done(); }; #endif // AOMOVIE_H diff --git a/include/aoscene.h b/include/aoscene.h index b58c0fd..ddbefe0 100644 --- a/include/aoscene.h +++ b/include/aoscene.h @@ -21,6 +21,7 @@ private: QWidget *m_parent; QMovie *m_movie; AOApplication *ao_app; + QString last_image; }; diff --git a/include/courtroom.h b/include/courtroom.h index baefbfa..a3c4736 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -308,14 +308,6 @@ private: //delay before sfx plays QTimer *sfx_delay_timer; - //keeps track of how long realization is visible(it's just a white square and should be visible less than a second) - QTimer *realization_timer; - - //times how long the blinking testimony should be shown(green one in the corner) - QTimer *testimony_show_timer; - //times how long the blinking testimony should be hidden - QTimer *testimony_hide_timer; - //every time point in char.inis times this equals the final time const int time_mod = 40; @@ -325,14 +317,6 @@ private: QString previous_ic_message = ""; - bool testimony_in_progress = false; - - //in milliseconds - const int testimony_show_time = 1500; - - //in milliseconds - const int testimony_hide_time = 500; - //char id, muted or not QMap<int, bool> mute_map; @@ -409,8 +393,8 @@ private: AOImage *ui_vp_chatbox; QLabel *ui_vp_showname; QTextEdit *ui_vp_message; - AOImage *ui_vp_testimony; - AOImage *ui_vp_realization; + AOMovie *ui_vp_realization; + AOMovie *ui_vp_testimony; AOMovie *ui_vp_wtce; AOMovie *ui_vp_objection; @@ -553,11 +537,6 @@ public slots: void objection_done(); void preanim_done(); - void realization_done(); - - void show_testimony(); - void hide_testimony(); - void mod_called(QString p_ip); void case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno); diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 5748723..883530b 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -19,28 +19,26 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) { - QString original_path = ao_app->get_character_path(p_char, emote_prefix + p_emote + ".gif"); - QString alt_path = ao_app->get_character_path(p_char, p_emote + ".png"); - QString apng_path = ao_app->get_character_path(p_char, emote_prefix + p_emote + ".apng"); - QString placeholder_path = ao_app->get_theme_path("placeholder.gif"); - QString placeholder_default_path = ao_app->get_default_theme_path("placeholder.gif"); - QString gif_path; - - if (file_exists(apng_path)) - gif_path = apng_path; - else if (file_exists(original_path)) - gif_path = original_path; - else if (file_exists(alt_path)) - gif_path = alt_path; - else if (file_exists(placeholder_path)) - gif_path = placeholder_path; - else - gif_path = placeholder_default_path; + QString emote_path; + QList<QString> pathlist; + pathlist << ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + p_emote)) <<//Default path + ao_app->get_character_path(p_char, p_emote + ".png") << //Non-animated path if emote_prefix fails + ao_app->get_image_suffix(ao_app->get_theme_path("placeholder")) << //Theme placeholder path + ao_app->get_image_suffix(ao_app->get_default_theme_path("placeholder")); //Default theme placeholder path + + for (QString path : pathlist) + { + if (file_exists(path)) + { + emote_path = path; + break; + } + } m_movie->stop(); - m_movie->setFileName(gif_path); + m_movie->setFileName(emote_path); - QImageReader *reader = new QImageReader(gif_path); + QImageReader *reader = new QImageReader(emote_path); movie_frames.clear(); QImage f_image = reader->read(); diff --git a/src/aomovie.cpp b/src/aomovie.cpp index edf5bdb..2598bb7 100644 --- a/src/aomovie.cpp +++ b/src/aomovie.cpp @@ -12,7 +12,11 @@ AOMovie::AOMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_parent) this->setMovie(m_movie); + timer = new QTimer(this); + timer->setSingleShot(true); + connect(m_movie, SIGNAL(frameChanged(int)), this, SLOT(frame_change(int))); + connect(timer, SIGNAL(timeout()), this, SLOT(timer_done())); } void AOMovie::set_play_once(bool p_play_once) @@ -20,46 +24,44 @@ void AOMovie::set_play_once(bool p_play_once) play_once = p_play_once; } -void AOMovie::play(QString p_gif, QString p_char, QString p_custom_theme) +void AOMovie::start_timer(int delay) { - m_movie->stop(); + timer->start(delay); +} - QString gif_path; +void AOMovie::play(QString p_gif, QString p_char, QString p_custom_theme, int duration) +{ + m_movie->stop(); - QString custom_path; + QString shout_path; + QList<QString> pathlist; if (p_gif == "custom") - custom_path = ao_app->get_image_suffix(ao_app->get_character_path(p_char, p_gif)); - else - custom_path = ao_app->get_image_suffix(ao_app->get_character_path(p_char, p_gif + "_bubble")); - - QString misc_path = ao_app->get_base_path() + "misc/" + p_custom_theme + "/" + p_gif + "_bubble.gif"; - QString custom_theme_path = ao_app->get_custom_theme_path(p_custom_theme, p_gif + ".gif"); - QString theme_path = ao_app->get_theme_path(p_gif + ".gif"); - QString default_theme_path = ao_app->get_default_theme_path(p_gif + ".gif"); - QString placeholder_path = ao_app->get_theme_path("placeholder.gif"); - QString default_placeholder_path = ao_app->get_default_theme_path("placeholder.gif"); - - if (file_exists(custom_path)) - gif_path = custom_path; - else if (file_exists(misc_path)) - gif_path = misc_path; - else if (file_exists(custom_theme_path)) - gif_path = custom_theme_path; - else if (file_exists(theme_path)) - gif_path = theme_path; - else if (file_exists(default_theme_path)) - gif_path = default_theme_path; - else if (file_exists(placeholder_path)) - gif_path = placeholder_path; - else if (file_exists(default_placeholder_path)) - gif_path = default_placeholder_path; + pathlist << ao_app->get_image_suffix(ao_app->get_character_path(p_char, p_gif)); else - gif_path = ""; + pathlist << ao_app->get_image_suffix(ao_app->get_character_path(p_char, p_gif + "_bubble")); - m_movie->setFileName(gif_path); + pathlist << ao_app->get_image_suffix(ao_app->get_base_path() + "misc/" + p_custom_theme + "/" + p_gif + "_bubble") << //Misc path + ao_app->get_image_suffix(ao_app->get_custom_theme_path(p_custom_theme, p_gif)) << //Custom theme path + ao_app->get_image_suffix(ao_app->get_theme_path(p_gif)) << //Theme path + ao_app->get_image_suffix(ao_app->get_default_theme_path(p_gif)) << //Default theme path + ao_app->get_image_suffix(ao_app->get_theme_path("placeholder")) << //Placeholder path + ao_app->get_image_suffix( ao_app->get_default_theme_path("placeholder")); //Default placeholder path + + for (QString path : pathlist) + { + if (file_exists(path)) + { + shout_path = path; + break; + } + } + + m_movie->setFileName(shout_path); this->show(); m_movie->start(); + if (m_movie->frameCount() == 0 && duration > 0) + this->start_timer(duration); } void AOMovie::stop() @@ -70,16 +72,23 @@ void AOMovie::stop() void AOMovie::frame_change(int n_frame) { - if (n_frame == (m_movie->frameCount() - 1) && play_once) - { - //we need this or else the last frame wont show - delay(m_movie->nextFrameDelay()); + //If it's a "static movie" (only one frame - png image), we can't change frames - ignore this function (use timer instead). + //If the frame didn't reach the last frame or the movie is continuous, don't stop the movie. + if (m_movie->frameCount() == 0 || n_frame < (m_movie->frameCount() - 1) || !play_once) + return; + //we need this or else the last frame wont show + delay(m_movie->nextFrameDelay()); - this->stop(); + this->stop(); - //signal connected to courtroom object, let it figure out what to do - done(); - } + //signal connected to courtroom object, let it figure out what to do + done(); +} + +void AOMovie::timer_done() +{ + this->stop(); + done(); } void AOMovie::combo_resize(int w, int h) diff --git a/src/aoscene.cpp b/src/aoscene.cpp index 344522b..c931425 100644 --- a/src/aoscene.cpp +++ b/src/aoscene.cpp @@ -7,16 +7,17 @@ AOScene::AOScene(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent) m_parent = parent; ao_app = p_ao_app; m_movie = new QMovie(this); + last_image = ""; } void AOScene::set_image(QString p_image) { - QString background_path = ao_app->get_background_path(p_image + ".png"); - QString animated_background_path = ao_app->get_background_path(p_image + ".gif"); - QString default_path = ao_app->get_default_background_path(p_image + ".png"); + QString background_path = ao_app->get_image_suffix(ao_app->get_background_path(p_image)); + if (!file_exists(background_path)) + background_path = ao_app->get_image_suffix(ao_app->get_default_background_path(p_image)); //Default path - QPixmap background(background_path); - QPixmap default_bg(default_path); + if (file_exists(background_path) && background_path == last_image) + return; int w = this->width(); int h = this->height(); @@ -25,7 +26,7 @@ void AOScene::set_image(QString p_image) this->setMovie(nullptr); m_movie->stop(); - m_movie->setFileName(animated_background_path); + m_movie->setFileName(background_path); m_movie->setScaledSize(QSize(w, h)); if (m_movie->isValid()) @@ -33,44 +34,52 @@ void AOScene::set_image(QString p_image) this->setMovie(m_movie); m_movie->start(); } - else if (file_exists(background_path)) - { - this->setPixmap(background.scaled(w, h)); - } else { - this->setPixmap(default_bg.scaled(w, h)); + QPixmap background(background_path); + this->setPixmap(background.scaled(w, h)); } + last_image = background_path; } void AOScene::set_legacy_desk(QString p_image) { - //vanilla desks vary in both width and height. in order to make that work with viewport rescaling, - //some INTENSE math is needed. - QString desk_path = ao_app->get_background_path(p_image); - QString default_path = ao_app->get_default_background_path(p_image); + QString desk_path = ao_app->get_image_suffix(ao_app->get_background_path(p_image)); + if (!file_exists(desk_path)) + desk_path = ao_app->get_image_suffix(ao_app->get_default_background_path(p_image)); //Default path - QPixmap f_desk; + if (file_exists(desk_path) && desk_path == last_image) + return; - if (file_exists(desk_path)) - f_desk.load(desk_path); - else - f_desk.load(default_path); + QPixmap f_desk(desk_path); + //vanilla desks vary in both width and height. in order to make that work with viewport rescaling, + //some INTENSE math is needed. int vp_width = m_parent->width(); int vp_height = m_parent->height(); - //double y_modifier = 147 / 192; - //double w_modifier = vp_width / 256; double h_modifier = vp_height / 192; - //int final_y = y_modifier * vp_height; - //int final_w = w_modifier * f_desk.width(); int final_h = static_cast<int>(h_modifier * f_desk.height()); - //this->resize(final_w, final_h); - //this->setPixmap(f_desk.scaled(final_w, final_h)); - this->resize(vp_width, final_h); - this->setPixmap(f_desk.scaled(vp_width, final_h)); + this->clear(); + this->setMovie(nullptr); + + m_movie->stop(); + m_movie->setFileName(desk_path); + + m_movie->setScaledSize(QSize(vp_width, final_h)); + + if (m_movie->isValid()) + { + this->setMovie(m_movie); + m_movie->start(); + } + else + { + this->resize(vp_width, final_h); + this->setPixmap(f_desk.scaled(vp_width, final_h)); + } + last_image = desk_path; } diff --git a/src/courtroom.cpp b/src/courtroom.cpp index c6a8749..db97bb9 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -55,15 +55,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() sfx_delay_timer = new QTimer(this); sfx_delay_timer->setSingleShot(true); - realization_timer = new QTimer(this); - realization_timer->setSingleShot(true); - - testimony_show_timer = new QTimer(this); - testimony_show_timer->setSingleShot(true); - - testimony_hide_timer = new QTimer(this); - testimony_hide_timer->setSingleShot(true); - music_player = new AOMusicPlayer(this, ao_app); music_player->set_volume(0); @@ -101,8 +92,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_vp_message->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); ui_vp_message->setReadOnly(true); - ui_vp_testimony = new AOImage(this, ao_app); - ui_vp_realization = new AOImage(this, ao_app); + ui_vp_testimony = new AOMovie(this, ao_app); + ui_vp_testimony->set_play_once(false); + ui_vp_realization = new AOMovie(this, ao_app); ui_vp_wtce = new AOMovie(this, ao_app); ui_vp_objection = new AOMovie(this, ao_app); @@ -278,11 +270,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(chat_tick_timer, SIGNAL(timeout()), this, SLOT(chat_tick())); - connect(realization_timer, SIGNAL(timeout()), this, SLOT(realization_done())); - - connect(testimony_show_timer, SIGNAL(timeout()), this, SLOT(hide_testimony())); - connect(testimony_hide_timer, SIGNAL(timeout()), this, SLOT(show_testimony())); - connect(ui_emote_left, SIGNAL(clicked()), this, SLOT(on_emote_left_clicked())); connect(ui_emote_right, SIGNAL(clicked()), this, SLOT(on_emote_right_clicked())); @@ -492,14 +479,10 @@ void Courtroom::set_widgets() "color: white"); ui_vp_testimony->move(ui_viewport->x(), ui_viewport->y()); - ui_vp_testimony->resize(ui_viewport->width(), ui_viewport->height()); - ui_vp_testimony->set_image("testimony.png"); - ui_vp_testimony->hide(); + ui_vp_testimony->combo_resize(ui_viewport->width(), ui_viewport->height()); ui_vp_realization->move(ui_viewport->x(), ui_viewport->y()); - ui_vp_realization->resize(ui_viewport->width(), ui_viewport->height()); - ui_vp_realization->set_image("realizationflash.png"); - ui_vp_realization->hide(); + ui_vp_realization->combo_resize(ui_viewport->width(), ui_viewport->height()); ui_vp_wtce->move(ui_viewport->x(), ui_viewport->y()); ui_vp_wtce->combo_resize(ui_viewport->width(), ui_viewport->height()); @@ -824,8 +807,7 @@ void Courtroom::done_received() void Courtroom::set_background(QString p_background) { - testimony_in_progress = false; - + ui_vp_testimony->stop(); current_background = p_background; is_ao2_bg = file_exists(ao_app->get_background_path("defensedesk.png")) && @@ -908,9 +890,8 @@ void Courtroom::enter_courtroom(int p_cid) } if (ao_app->custom_objection_enabled && - (file_exists(ao_app->get_character_path(current_char, "custom.gif")) || - file_exists(ao_app->get_character_path(current_char, "custom.apng"))) && - file_exists(ao_app->get_character_path(current_char, "custom.wav"))) + (file_exists(ao_app->get_image_suffix(ao_app->get_character_path(current_char, "custom"))) && + file_exists(ao_app->get_character_path(current_char, "custom.wav")))) ui_custom_objection->show(); else ui_custom_objection->hide(); @@ -933,7 +914,7 @@ void Courtroom::enter_courtroom(int p_cid) objection_player->set_volume(ui_sfx_slider->value()); blip_player->set_volume(ui_blip_slider->value()); - testimony_in_progress = false; + ui_vp_testimony->stop(); set_widgets(); @@ -1350,20 +1331,20 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) switch (objection_mod) { case 1: - ui_vp_objection->play("holdit", f_char, f_custom_theme); + ui_vp_objection->play("holdit", f_char, f_custom_theme, 724); objection_player->play("holdit.wav", f_char, f_custom_theme); break; case 2: - ui_vp_objection->play("objection", f_char, f_custom_theme); + ui_vp_objection->play("objection", f_char, f_custom_theme, 724); objection_player->play("objection.wav", f_char, f_custom_theme); break; case 3: - ui_vp_objection->play("takethat", f_char, f_custom_theme); + ui_vp_objection->play("takethat", f_char, f_custom_theme, 724); objection_player->play("takethat.wav", f_char, f_custom_theme); break; //case 4 is AO2 only case 4: - ui_vp_objection->play("custom", f_char, f_custom_theme); + ui_vp_objection->play("custom", f_char, f_custom_theme, 724); objection_player->play("custom.wav", f_char, f_custom_theme); break; default: @@ -1983,10 +1964,6 @@ void Courtroom::preanim_done() handle_chatmessage_3(); } -void Courtroom::realization_done() -{ - ui_vp_realization->hide(); -} void Courtroom::start_chat_ticking() { @@ -1996,8 +1973,7 @@ void Courtroom::start_chat_ticking() if (m_chatmessage[REALIZATION] == "1") { - realization_timer->start(60); - ui_vp_realization->show(); + ui_vp_realization->play("realizationflash", "", "", 60); sfx_player->play(ao_app->get_custom_realization(m_chatmessage[CHAR_NAME])); } @@ -2335,27 +2311,6 @@ void Courtroom::chat_tick() } } - -void Courtroom::show_testimony() -{ - if (!testimony_in_progress || m_chatmessage[SIDE] != "wit") - return; - - ui_vp_testimony->show(); - - testimony_show_timer->start(testimony_show_time); -} - -void Courtroom::hide_testimony() -{ - ui_vp_testimony->hide(); - - if (!testimony_in_progress) - return; - - testimony_hide_timer->start(testimony_hide_time); -} - void Courtroom::play_sfx() { QString sfx_name = m_chatmessage[SFX_NAME]; @@ -2368,15 +2323,13 @@ void Courtroom::play_sfx() void Courtroom::set_scene() { - if (testimony_in_progress) - show_testimony(); - //witness is default if pos is invalid QString f_background = "witnessempty"; QString f_desk_image = "stand"; QString f_desk_mod = m_chatmessage[DESK_MOD]; QString f_side = m_chatmessage[SIDE]; + //This thing desperately needs to be made into an array iteration. if (f_side == "def") { f_background = "defenseempty"; @@ -2408,14 +2361,12 @@ void Courtroom::set_scene() f_background = "prohelperstand"; f_desk_image = "prohelperdesk"; } - else if (f_side == "jur" && (file_exists(ao_app->get_background_path("jurystand.png")) || - file_exists(ao_app->get_background_path("jurystand.gif")))) + else if (f_side == "jur" && (file_exists(ao_app->get_image_suffix(ao_app->get_background_path("jurystand"))))) { f_background = "jurystand"; f_desk_image = "jurydesk"; } - else if (f_side == "sea" && (file_exists(ao_app->get_background_path("seancestand.png")) || - file_exists(ao_app->get_background_path("seancestand.gif")))) + else if (f_side == "sea" && (file_exists(ao_app->get_image_suffix(ao_app->get_background_path("seancestand"))))) { f_background = "seancestand"; f_desk_image = "seancedesk"; @@ -2431,7 +2382,6 @@ void Courtroom::set_scene() ui_vp_background->set_image(f_background); ui_vp_desk->set_image(f_desk_image); ui_vp_legacy_desk->set_legacy_desk(f_desk_image); - if (f_desk_mod == "0" || (f_desk_mod != "1" && (f_side == "jud" || f_side == "hld" || @@ -2574,29 +2524,28 @@ void Courtroom::handle_wtce(QString p_wtce, int variant) if (p_wtce == "testimony1") { sfx_player->play(ao_app->get_sfx("witness_testimony")); - ui_vp_wtce->play("witnesstestimony"); - testimony_in_progress = true; - show_testimony(); + ui_vp_wtce->play("witnesstestimony", "", "", 1500); + ui_vp_testimony->play("testimony"); } //cross examination else if (p_wtce == "testimony2") { sfx_player->play(ao_app->get_sfx("cross_examination")); - ui_vp_wtce->play("crossexamination"); - testimony_in_progress = false; + ui_vp_wtce->play("crossexamination", "", "", 1500); + ui_vp_testimony->stop(); } else if (p_wtce == "judgeruling") { if (variant == 0) { sfx_player->play(ao_app->get_sfx("not_guilty")); - ui_vp_wtce->play("notguilty"); - testimony_in_progress = false; + ui_vp_wtce->play("notguilty", "", "", 3000); + ui_vp_testimony->stop(); } else if (variant == 1) { sfx_player->play(ao_app->get_sfx("guilty")); - ui_vp_wtce->play("guilty"); - testimony_in_progress = false; + ui_vp_wtce->play("guilty", "", "", 3000); + ui_vp_testimony->stop(); } } } diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index 5a34ac8..837e7e8 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -385,12 +385,13 @@ QString AOApplication::get_sfx_suffix(QString sound_to_check) QString AOApplication::get_image_suffix(QString path_to_check) { - QString apng_check = path_to_check + ".apng"; - if (file_exists(apng_check)) - { - return apng_check; - } - return path_to_check + ".gif"; + if (file_exists(path_to_check + ".webp")) + return path_to_check + ".webp"; + if (file_exists(path_to_check + ".apng")) + return path_to_check + ".apng"; + if (file_exists(path_to_check + ".gif")) + return path_to_check + ".gif"; + return path_to_check + ".png"; } @@ -592,7 +593,7 @@ QString AOApplication::get_custom_realization(QString p_char) if (f_result == "") return get_sfx("realization"); - else return f_result; + else return get_sfx_suffix(f_result); } bool AOApplication::get_blank_blip() |
