From b56421365ab75173facef74cdaf8d77d51df6d0f Mon Sep 17 00:00:00 2001 From: iamgoofball Date: Wed, 17 Oct 2018 08:11:52 -0700 Subject: [PATCH] APNG Support --- Attorney_Online_remake.pro | 4 ++-- aoapplication.h | 3 +++ aocharmovie.cpp | 8 +++++++- courtroom.cpp | 6 +++--- main.cpp | 6 +++--- text_file_functions.cpp | 16 ++++++++++++++++ 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 24ecf7d..cf8b47d 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -5,7 +5,7 @@ #------------------------------------------------- QT += core gui multimedia network - +QTPLUGIN += qapng greaterThan(QT_MAJOR_VERSION, 4): QT += widgets RC_ICONS = logo.ico @@ -88,7 +88,7 @@ HEADERS += lobby.h \ # in the same way as BASS. Discord RPC uses CMake, which does not play nicely with # QMake, so this step must be manual. unix:LIBS += -L$$PWD -lbass -ldiscord-rpc -win32:LIBS += -L$$PWD "$$PWD/bass.dll" -L$$PWD "$$PWD/discord-rpc.dll" +win32:LIBS += -L$$PWD "$$PWD/bass.dll" -L$$PWD "$$PWD/discord-rpc.dll" -lpng -lqapng -lz android:LIBS += -L$$PWD\android\libs\armeabi-v7a\ -lbass CONFIG += c++11 diff --git a/aoapplication.h b/aoapplication.h index b9d3fd1..29988c0 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -172,6 +172,9 @@ 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. + QString get_image_suffix(QString path_to_check); + //Returns the value of p_search_line within target_tag and terminator_tag QString read_char_ini(QString p_char, QString p_search_line, QString target_tag, QString terminator_tag); diff --git a/aocharmovie.cpp b/aocharmovie.cpp index b591c22..786cab2 100644 --- a/aocharmovie.cpp +++ b/aocharmovie.cpp @@ -3,6 +3,8 @@ #include "misc_functions.h" #include "file_functions.h" #include "aoapplication.h" +#include "debug_functions.h" +#include AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_parent) { @@ -21,11 +23,14 @@ 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.toLower() + ".gif"; QString alt_path = ao_app->get_character_path(p_char) + p_emote.toLower() + ".png"; + QString apng_path = ao_app->get_character_path(p_char) + emote_prefix + p_emote.toLower() + ".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(original_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; @@ -148,6 +153,7 @@ void AOCharMovie::combo_resize(int w, int h) void AOCharMovie::frame_change(int n_frame) { + if (movie_frames.size() > n_frame) { QPixmap f_pixmap = QPixmap::fromImage(movie_frames.at(n_frame)); diff --git a/courtroom.cpp b/courtroom.cpp index 1ccae30..fdb5e8c 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1219,13 +1219,13 @@ void Courtroom::play_preanim() preanim_duration = ao2_duration; sfx_delay_timer->start(sfx_delay); - - if (!file_exists(ao_app->get_character_path(f_char) + f_preanim.toLower() + ".gif") || + QString anim_to_find = ao_app->get_image_suffix(ao_app->get_character_path(f_char) + f_preanim.toLower()); + if (!file_exists(anim_to_find) || preanim_duration < 0) { anim_state = 1; preanim_done(); - qDebug() << "could not find " + ao_app->get_character_path(f_char) + f_preanim.toLower() + ".gif"; + qDebug() << "could not find " + anim_to_find; return; } diff --git a/main.cpp b/main.cpp index 5696e2e..cf51b0a 100644 --- a/main.cpp +++ b/main.cpp @@ -5,9 +5,9 @@ #include "networkmanager.h" #include "lobby.h" #include "courtroom.h" - +#include #include - +Q_IMPORT_PLUGIN(ApngImagePlugin); int main(int argc, char *argv[]) { #if QT_VERSION > QT_VERSION_CHECK(5, 6, 0) @@ -16,10 +16,10 @@ int main(int argc, char *argv[]) // packages up to Qt 5.6, so this is conditional. AOApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif + AOApplication main_app(argc, argv); main_app.construct_lobby(); main_app.net_manager->connect_to_master(); main_app.w_lobby->show(); - return main_app.exec(); } diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 5b057a4..a6ad4f7 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -360,6 +360,22 @@ QString AOApplication::get_sfx_suffix(QString sound_to_check) return sound_to_check + ".wav"; } +QString AOApplication::get_image_suffix(QString path_to_check) +{ + QString apng_check = path_to_check + ".apng"; + QString gif_check = path_to_check + ".gif"; + if(file_exists(apng_check)) + { + return path_to_check + ".apng"; + } + if(file_exists(gif_check)) + { + return path_to_check + ".gif"; + } + return path_to_check + ".gif"; +} + + //returns whatever is to the right of "search_line =" within target_tag and terminator_tag, trimmed //returns the empty string if the search line couldnt be found QString AOApplication::read_char_ini(QString p_char, QString p_search_line, QString target_tag, QString terminator_tag)