From 3b415f5a7005fd0b42ba7ccbb9a8836746a72d41 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Thu, 12 Sep 2019 15:40:19 +0300 Subject: [PATCH] Expand get_image_suffix to fall back on .png last Reorganize the file_exists checks to be an array iterator instead for much less code duplication and easier ordering of priority Reorganize desk and set_image loading on AOScene class, resolve issues with last_image setting to prevent animations from being restarted when characters talk on the same pos in succession Apply get_image_suffix for seancestand and jurystand searches TODO: At the moment, if you feed a .png shout, it will send the "Done" signal on the first frame (frame 0), not showing you the .png image at all. The shout code should be reorganized to allow static images to be displayed for exactly 720ms - the standard AA objection length. Usage of the timer similarly to the realizationflash.png might be possible. --- include/aoapplication.h | 2 +- src/aocharmovie.cpp | 31 +++++++++++----------- src/aomovie.cpp | 47 +++++++++++++------------------- src/aoscene.cpp | 53 +++++++++++++------------------------ src/courtroom.cpp | 18 ++++--------- src/text_file_functions.cpp | 14 +++++----- 6 files changed, 66 insertions(+), 99 deletions(-) diff --git a/include/aoapplication.h b/include/aoapplication.h index 68e82ce..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, WEBP? If not, fall back to 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/src/aocharmovie.cpp b/src/aocharmovie.cpp index eacf853..883530b 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -19,25 +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_image_suffix(ao_app->get_character_path(p_char, emote_prefix + p_emote)); - QString alt_path = ao_app->get_character_path(p_char, p_emote + ".png"); - QString placeholder_path = ao_app->get_image_suffix(ao_app->get_theme_path("placeholder")); - QString placeholder_default_path = ao_app->get_image_suffix(ao_app->get_default_theme_path("placeholder")); - QString gif_path; + QString emote_path; + QList pathlist; + pathlist << ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + p_emote)) <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 - 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; + 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 71a5a76..a378a3d 100644 --- a/src/aomovie.cpp +++ b/src/aomovie.cpp @@ -24,39 +24,30 @@ void AOMovie::play(QString p_gif, QString p_char, QString p_custom_theme) { m_movie->stop(); - QString gif_path; - - QString custom_path; + QString shout_path; + QList pathlist; if (p_gif == "custom") - custom_path = ao_app->get_image_suffix(ao_app->get_character_path(p_char, p_gif)); + pathlist << 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")); + pathlist << ao_app->get_image_suffix(ao_app->get_character_path(p_char, p_gif + "_bubble")); - QString misc_path = ao_app->get_image_suffix(ao_app->get_base_path() + "misc/" + p_custom_theme + "/" + p_gif + "_bubble"); - QString custom_theme_path = ao_app->get_image_suffix(ao_app->get_custom_theme_path(p_custom_theme, p_gif)); - QString theme_path = ao_app->get_image_suffix(ao_app->get_theme_path(p_gif)); - QString default_theme_path = ao_app->get_image_suffix(ao_app->get_default_theme_path(p_gif)); - QString placeholder_path = ao_app->get_image_suffix(ao_app->get_theme_path("placeholder")); - QString default_placeholder_path =ao_app->get_image_suffix( ao_app->get_default_theme_path("placeholder")); + 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 - 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; - else - gif_path = ""; + for (QString path : pathlist) + { + if (file_exists(path)) + { + shout_path = path; + break; + } + } - m_movie->setFileName(gif_path); + m_movie->setFileName(shout_path); this->show(); m_movie->start(); diff --git a/src/aoscene.cpp b/src/aoscene.cpp index 0f4e745..c931425 100644 --- a/src/aoscene.cpp +++ b/src/aoscene.cpp @@ -12,16 +12,13 @@ AOScene::AOScene(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent) void AOScene::set_image(QString p_image) { - QString background_path = ao_app->get_background_path(p_image + ".png"); - QString default_path = ao_app->get_default_background_path(p_image + ".png"); - QString animated_background_path = ao_app->get_image_suffix(ao_app->get_background_path(p_image)); + 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 - if (file_exists(animated_background_path) && animated_background_path == last_image) + if (file_exists(background_path) && background_path == last_image) return; - QPixmap background(background_path); - QPixmap default_bg(default_path); - int w = this->width(); int h = this->height(); @@ -29,74 +26,60 @@ 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()) { this->setMovie(m_movie); m_movie->start(); - last_image = animated_background_path; - } - 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 + ".png"); - QString animated_desk_path = ao_app->get_image_suffix(ao_app->get_background_path(p_image)); - QString default_path = ao_app->get_image_suffix(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 - if (file_exists(animated_desk_path) && animated_desk_path == last_image) + if (file_exists(desk_path) && desk_path == last_image) return; - QPixmap f_desk; + 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(h_modifier * f_desk.height()); this->clear(); this->setMovie(nullptr); m_movie->stop(); - m_movie->setFileName(animated_desk_path); + m_movie->setFileName(desk_path); - m_movie->setScaledSize(QSize(vp_width, vp_height)); + m_movie->setScaledSize(QSize(vp_width, final_h)); if (m_movie->isValid()) { this->setMovie(m_movie); m_movie->start(); - last_image = animated_desk_path; } else { - if (file_exists(desk_path)) - f_desk.load(desk_path); - else - f_desk.load(default_path); - - //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)); } + last_image = desk_path; } diff --git a/src/courtroom.cpp b/src/courtroom.cpp index cc69a1e..cc4410d 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -908,10 +908,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.webp"))) && - 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(); @@ -2378,6 +2376,7 @@ void Courtroom::set_scene() 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"; @@ -2409,18 +2408,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")) || - file_exists(ao_app->get_background_path("jurystand.apng")) || - file_exists(ao_app->get_background_path("jurystand.webp")))) + 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")) || - file_exists(ao_app->get_background_path("seancestand.apng")) || - file_exists(ao_app->get_background_path("seancestand.webp")))) + 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"; @@ -2436,7 +2429,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" || diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index 904e212..afe7a67 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -385,13 +385,13 @@ QString AOApplication::get_sfx_suffix(QString sound_to_check) QString AOApplication::get_image_suffix(QString path_to_check) { - QString webp_check = path_to_check + ".webp"; - QString apng_check = path_to_check + ".apng"; - if (file_exists(webp_check)) - return webp_check; - 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"; }