Skip to content

Commit

Permalink
Animated Themes. Subthemes. Custom default_theme. Overhaul asset path…
Browse files Browse the repository at this point in the history
…s. Fix a ton of asset resolution bugs. (#466)

* Remove get_static_image_suffix (webp, gif etc. can be non-animated)
Replace QList<QString> with QStringList

* forgot to remove static image from aoimage

* Simplify get_theme_path, get_custom_theme_path and get_default_theme_path all into a single get_theme_path func
Add a default_theme variable which defines the currently recognized default theme
Add a new "get_asset_path" that will be used to simplify asset resolution considerably

* Simplify AOImage set_image function to use get_asset_path
Begin working on the subtheme system

* Add p_default_theme for get_asset_path
Implement get_asset_path for AOButton

* Condense aolayer path lookups into the get_asset_path function

* Get rid of get_font_name due to underuse (and it just does the same thing as get_design_element anyway)
Get rid of get_char_shouts (use chat= instead)
Use get_subtheme() instead of subtheme (because get_subtheme() can perform overrides based on the user's settings)
Make get_color() use get_asset_path()
Make get_design_element() use get_asset_path()

* Adapt a whole bunch of text_file_functions to the get_asset_path method, fixing an enormous amount of invalid path resolutions
Unfortunately I have to keep backwards compatibility for the backwards ass config.ini method for the chat markup (new way is chat_config.ini)
Get rid of get_theme_effects and implement the stacking behavior into get_effects instead

* Program doesn't run, color lists stop generating for some reason
Also implement safety checks for the asset path generator

* Fix a really tricky issue that popped up regarding char_color_rgb_list not being generated, causing segfaults

* Address the sfx player path resolution being really, really stupid and resolve major inconsistencies (such as the bug where objection sfx wouldn't be playing despite the default theme or default misc folder having them)

* Fix sfx path resolution being funky (apparently D:/Qt/Projects/AO2-Client/bin/base/themes/default//objection.wav is a valid qt5 path...)

* Implement:
get_asset_paths - Return an untested list of universal paths from the provided args
get_asset_path - Loop through the list of provided asset paths and return the first valid file
get_image_path - Loop through the list of provided asset paths, apply get_image_suffix and return the first valid image file
get_sfx_path - Loop through the list of provided asset paths, apply get_sfx_suffix and return the first valid sound file
get_asset - return an asset (must contain file extension) from the get_asset_path() applied on the get_asset_paths()
get_image - return an image with get_image_suffix() applied on the get_image_path() for the get_asset_paths()
get_sfx - return a sfx from provided args with the uniquely constructed asset path list for sounds

Rename old get_sfx to get_court_sfx for better clarity of its function
This replaces previous asset stuff I implemented, as I think this is a better solution lol

* Add a new get_config_value that obtains a value from the config that matches identifier
Adjust all calls to get_asset() to actually look for a config identifier value instead, so even if a config.ini is found if it doesn't contain the identifier we want we keep looking

* Fix effects.ini sounds not working
Remove debug text

* Make it so even if you miss the required asset, and don't have a missingno, the viewport still doesn't freeze up due to waiting on Objections etc. due to signals.

* Implement default_theme option for courtroom_design.ini, allowing you to make themes that inherit from other themes that are not default.

* move sounds folder lower in sfx pathlist

* fix realization sfx not being fetched from config

* Make aosfxplayer actually use get_sfx I made
Move sounds folder path check last in get_sfx

* I thought this would fix QSettings::value: Empty key passed but I guess not, that annoying error will keep pestering us :(((

* Remove silly .png exception for SplashLayer
Fix static image Objections freezing the viewport due to done(); signal that never arrives

* Make WTCE cooler by including a stop method for witness testimony indicator, and add support for custom WTCE

* Reduce code duplication for get_sfx

* Fix the program hanging/entering an infinite loop/segfaults/a number of nasty issues due to done(); signal being sent as soon as playback begins if the image is invalid.
This is done by removing the file_exists check, and letting the rest of the functionality handle this case - the system is robust enough and treats an invalid image as a static image.

* Fix segfaults with AOLayers by sanity checking using max_frames
Fix "Pixmap is null" console spam

* You'll hate me for this.
Make it possible to have fully animated AOButton and AOImage

* Add a settings option to toggle animated themes on or off

* Add a setting for animated theme elements
Add a "static image" toggle for get_image_suffix

* Fix custom chat and generally the chat boxes not having consistent behaivor with subthemes
Add a settings option for subthemes
Have AOImage keep track of its last valid path

* Add SubTheme (ST) packet. Pass subtheme as arg0, and "1" if you want the client's theme to be reloaded.
ST packet sets ao_app->subtheme no matter what. It will not reload theme unless the user has their subtheme set to "server".
Fix showname widths by rearranging font metrics to do its calculations *after* the showname font is set, and not before (making it lag behind the correct display size by 1 msg)

Co-authored-by: in1tiate <[email protected]>
  • Loading branch information
Crystalwarrior and in1tiate authored Feb 13, 2021
1 parent b78479f commit fe00c6b
Show file tree
Hide file tree
Showing 21 changed files with 514 additions and 480 deletions.
48 changes: 25 additions & 23 deletions include/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,22 @@ class AOApplication : public QApplication {
// implementation in path_functions.cpp
QString get_base_path();
QString get_data_path();
QString get_theme_path(QString p_file);
QString get_default_theme_path(QString p_file);
QString get_custom_theme_path(QString p_theme, QString p_file);
QString get_theme_path(QString p_file, QString p_theme="");
QString get_character_path(QString p_char, QString p_file);
QString get_misc_path(QString p_misc, QString p_file);
QString get_sounds_path(QString p_file);
QString get_music_path(QString p_song);
QString get_background_path(QString p_file);
QString get_default_background_path(QString p_file);
QString get_evidence_path(QString p_file);
QStringList get_asset_paths(QString p_element, QString p_theme="", QString p_subtheme="", QString p_default_theme="", QString p_misc="", QString p_character="", QString p_placeholder="");
QString get_asset_path(QStringList pathlist);
QString get_image_path(QStringList pathlist, bool static_image=false);
QString get_sfx_path(QStringList pathlist);
QString get_config_value(QString p_identifier, QString p_config, QString p_theme="", QString p_subtheme="", QString p_default_theme="", QString p_misc="");
QString get_asset(QString p_element, QString p_theme="", QString p_subtheme="", QString p_default_theme="", QString p_misc="", QString p_character="", QString p_placeholder="");
QString get_image(QString p_element, QString p_theme="", QString p_subtheme="", QString p_default_theme="", QString p_misc="", QString p_character="", QString p_placeholder="");
QString get_sfx(QString p_sfx, QString p_misc="", QString p_character="");
QString get_case_sensitive_path(QString p_file);

////// Functions for reading and writing files //////
Expand Down Expand Up @@ -306,10 +312,7 @@ class AOApplication : public QApplication {

// Returns the value to you
QString get_design_element(QString p_identifier, QString p_file,
QString p_char = "");

// Returns the name of the font with p_identifier from p_file
QString get_font_name(QString p_identifier, QString p_file);
QString p_misc = "");

// Returns the value of font_size with p_identifier from p_file
int get_font_size(QString p_identifier, QString p_file);
Expand All @@ -323,19 +326,15 @@ class AOApplication : public QApplication {
// Returns the color from the misc folder.
QColor get_chat_color(QString p_identifier, QString p_chat);

// Returns the sfx with p_identifier from sounds.ini in the current theme path
QString get_sfx(QString p_identifier, QString p_misc="default");
// Returns the sfx with p_identifier from courtroom_sounds.ini in the current theme path
QString get_court_sfx(QString p_identifier, QString p_misc="");

// 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, GIF? If not, fall back to
// PNG.
QString get_image_suffix(QString path_to_check);

// If this image is static and non-animated, return the supported static image
// formats. Currently only PNG.
QString get_static_image_suffix(QString path_to_check);
QString get_image_suffix(QString path_to_check, bool static_image=false);

// Returns the value of p_search_line within target_tag and terminator_tag
QString read_char_ini(QString p_char, QString p_search_line,
Expand Down Expand Up @@ -372,9 +371,6 @@ class AOApplication : public QApplication {
// Returns the value of chat font size from the specific p_char's ini file
int get_chat_size(QString p_char);

// Returns the value of shouts from the specified p_char's ini file
QString get_char_shouts(QString p_char);

// Returns the preanim duration of p_char's p_emote
int get_preanim_duration(QString p_char, QString p_emote);

Expand All @@ -385,10 +381,6 @@ class AOApplication : public QApplication {
// Not in use
int get_text_delay(QString p_char, QString p_emote);

// Get the effects folder referenced by the char.ini, read it and return the
// list of filenames in a string
QStringList get_theme_effects();

// Get the theme's effects folder, read it and return the list of filenames in
// a string
QStringList get_effects(QString p_char);
Expand Down Expand Up @@ -488,6 +480,18 @@ class AOApplication : public QApplication {
// Get if automatic logging is enabled
bool get_auto_logging_enabled();

// Get the subtheme from settings
QString get_subtheme();

// Get if the theme is animated
bool get_animated_theme();

// Currently defined subtheme
QString subtheme;

QString default_theme = "default";
QString current_theme = default_theme;

// The file name of the log file in base/logs.
QString log_filename;

Expand All @@ -505,8 +509,6 @@ class AOApplication : public QApplication {
const int MAJOR_VERSION = 9;
const int MINOR_VERSION = 0;

QString current_theme = "default";

QVector<server_type> server_list;
QVector<server_type> favorite_list;

Expand Down
4 changes: 3 additions & 1 deletion include/aobutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <QDebug>
#include <QPushButton>
#include <QMovie>

class AOButton : public QPushButton {
Q_OBJECT
Expand All @@ -14,8 +15,9 @@ class AOButton : public QPushButton {
~AOButton();

AOApplication *ao_app;
QMovie *movie;

void set_image(QString p_image);
void set_image(QString p_image, QString p_misc="");
};

#endif // AOBUTTON_H
7 changes: 5 additions & 2 deletions include/aoimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <QDebug>
#include <QLabel>
#include <QMovie>

class AOImage : public QLabel {
public:
Expand All @@ -15,9 +16,11 @@ class AOImage : public QLabel {

QWidget *m_parent;
AOApplication *ao_app;
QMovie *movie;

bool set_image(QString p_image);
bool set_chatbox(QString p_path);
QString path;

bool set_image(QString p_image, QString p_misc = "");
void set_size_and_pos(QString identifier);
};

Expand Down
2 changes: 1 addition & 1 deletion include/aolayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AOLayer : public QLabel {

// iterate through a list of paths and return the first entry that exists. if
// none exist, return NULL (safe because we check again for existence later)
QString find_image(QList<QString> p_list);
QString find_image(QStringList p_list);

protected:
AOApplication *ao_app;
Expand Down
5 changes: 5 additions & 0 deletions include/aooptionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class AOOptionsDialog : public QDialog {
QFormLayout *ui_gameplay_form;
QLabel *ui_theme_label;
QComboBox *ui_theme_combobox;
QLabel *ui_subtheme_label;
QComboBox *ui_subtheme_combobox;
QPushButton *ui_theme_reload_button;
QLabel *ui_animated_theme_lbl;
QCheckBox *ui_animated_theme_cb;
QFrame *ui_theme_log_divider;
QLabel *ui_downwards_lbl;
QCheckBox *ui_downwards_cb;
Expand Down Expand Up @@ -173,6 +177,7 @@ public slots:
void discard_pressed();
void button_clicked(QAbstractButton *button);
void on_reload_theme_clicked();
void theme_changed(int i);
};

#endif // AOOPTIONSDIALOG_H
2 changes: 1 addition & 1 deletion include/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class Courtroom : public QMainWindow {
QVector<QColor> default_color_rgb_list;

// Get a color index from an arbitrary misc config
void gen_char_rgb_list(QString p_char);
void gen_char_rgb_list(QString p_misc);
QVector<QColor> char_color_rgb_list;

// Misc we used for the last message, and the one we're using now. Used to avoid loading assets when it's not needed
Expand Down
54 changes: 31 additions & 23 deletions src/aobutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,42 @@ AOButton::AOButton(QWidget *parent, AOApplication *p_ao_app)
: QPushButton(parent)
{
ao_app = p_ao_app;
movie = new QMovie(this);
connect(movie, &QMovie::frameChanged, [=]{
this->setIcon(movie->currentPixmap().scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
this->setIconSize(QSize(this->width(), this->height()));
});
}

AOButton::~AOButton() {}

void AOButton::set_image(QString p_image)
void AOButton::set_image(QString p_path, QString p_misc)
{
QString image_path =
ao_app->get_static_image_suffix(ao_app->get_theme_path(p_image));
QString default_image_path =
ao_app->get_static_image_suffix(ao_app->get_default_theme_path(p_image));

if (file_exists(image_path)) {
this->setText("");
this->setStyleSheet("QPushButton { border-image: url(\"" + image_path +
"\") 0 0 0 0 stretch stretch; }"
"QToolTip { background-image: url(); color: #000000; "
"background-color: #ffffff; border: 0px; }");
movie->stop();
QString p_image;
// Check if the user wants animated themes
if (ao_app->get_animated_theme())
// We want an animated image
p_image = ao_app->get_image(p_path, ao_app->current_theme, ao_app->get_subtheme(), ao_app->default_theme, p_misc);
else
// Grab a static variant of the image
p_image = ao_app->get_image_path(ao_app->get_asset_paths(p_path, ao_app->current_theme, ao_app->get_subtheme(), ao_app->default_theme, p_misc), true);
if (!file_exists(p_image)) {
this->setIcon(QIcon());
this->setIconSize(this->size());
this->setStyleSheet("");
return;
}
else if (file_exists(default_image_path)) {
this->setText("");
this->setStyleSheet("QPushButton { border-image: url(\"" +
default_image_path +
"\"); }"
"QToolTip { background-image: url(); color: #000000; "
"background-color: #ffffff; border: 0px; }");
this->setText("");
this->setStyleSheet("QPushButton { background-color: transparent; border: 0px }");
movie->setFileName(p_image);
// We double-check if the user wants animated themes, so even if an animated image slipped through,
// we still set it static
if (ao_app->get_animated_theme() && movie->frameCount() > 1) {
movie->start();
}
else {
this->setIcon(QPixmap(p_image).scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
this->setIconSize(this->size());
}
else
this->setStyleSheet("QPushButton { border-image: url(); }"
"QToolTip { background-image: url(); color: #000000; "
"background-color: #ffffff; border: 0px; }");
}
2 changes: 1 addition & 1 deletion src/aocharbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void AOCharButton::set_passworded() { ui_passworded->show(); }

void AOCharButton::set_image(QString p_character)
{
QString image_path = ao_app->get_static_image_suffix(
QString image_path = ao_app->get_image_suffix(
ao_app->get_character_path(p_character, "char_icon"));

this->setText("");
Expand Down
2 changes: 1 addition & 1 deletion src/aoemotebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void AOEmoteButton::set_char_image(QString p_char, int p_emote, QString suffix)
{
QString emotion_number = QString::number(p_emote + 1);
QString image_path =
ao_app->get_static_image_suffix(ao_app->get_character_path(
ao_app->get_image_suffix(ao_app->get_character_path(
p_char, "emotions/button" + emotion_number + suffix));

this->set_image(image_path, ao_app->get_emote_comment(p_char, p_emote));
Expand Down
2 changes: 1 addition & 1 deletion src/aoevidencebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void AOEvidenceButton::set_image(QString p_image)
void AOEvidenceButton::set_theme_image(QString p_image)
{
QString theme_image_path = ao_app->get_theme_path(p_image);
QString default_image_path = ao_app->get_default_theme_path(p_image);
QString default_image_path = ao_app->get_theme_path(p_image, ao_app->default_theme);

QString final_image_path;

Expand Down
3 changes: 1 addition & 2 deletions src/aoevidencedisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void AOEvidenceDisplay::show_evidence(QString p_evidence_image,

sfx_player->set_volume(p_volume);

QString final_gif_path;
QString gif_name;
QString icon_identifier;

Expand All @@ -50,7 +49,7 @@ void AOEvidenceDisplay::show_evidence(QString p_evidence_image,
evidence_movie->max_duration = 1000;
evidence_movie->set_play_once(true);
evidence_movie->load_image(gif_name, "");
sfx_player->play(ao_app->get_sfx("evidence_present", "default"));
sfx_player->play(ao_app->get_court_sfx("evidence_present"));
}

void AOEvidenceDisplay::reset()
Expand Down
64 changes: 30 additions & 34 deletions src/aoimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,45 @@ AOImage::AOImage(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent)
{
m_parent = parent;
ao_app = p_ao_app;
movie = new QMovie();
connect(movie, &QMovie::frameChanged, [=]{
QPixmap f_pixmap = movie->currentPixmap();
f_pixmap =
f_pixmap.scaled(this->size(), Qt::IgnoreAspectRatio);
this->setPixmap(f_pixmap);
this->setMask(f_pixmap.mask());
});
}

AOImage::~AOImage() {}

bool AOImage::set_image(QString p_image)
bool AOImage::set_image(QString p_path, QString p_misc)
{
QString theme_image_path =
ao_app->get_static_image_suffix(ao_app->get_theme_path(p_image));
QString default_image_path =
ao_app->get_static_image_suffix(ao_app->get_default_theme_path(p_image));
// Check if the user wants animated themes
if (ao_app->get_animated_theme())
// We want an animated image
p_path = ao_app->get_image(p_path, ao_app->current_theme, ao_app->get_subtheme(), ao_app->default_theme, p_misc);
else
// Grab a static variant of the image
p_path = ao_app->get_image_path(ao_app->get_asset_paths(p_path, ao_app->current_theme, ao_app->get_subtheme(), ao_app->default_theme, p_misc), true);

QString final_image_path;

if (file_exists(theme_image_path))
final_image_path = theme_image_path;
else if (file_exists(default_image_path))
final_image_path = default_image_path;
else {
qDebug() << "Warning: Image" << p_image << "not found! Can't set!";
return false;
}

QPixmap f_pixmap(final_image_path);
f_pixmap =
f_pixmap.scaled(this->width(), this->height(), Qt::IgnoreAspectRatio);
this->setPixmap(f_pixmap);
this->setMask(f_pixmap.mask());
return true;
}

bool AOImage::set_chatbox(QString p_path)
{
p_path = ao_app->get_static_image_suffix(p_path);
if (!file_exists(p_path)) {
qDebug() << "Warning: Chatbox" << p_path << "not found! Can't set!";
qDebug() << "Warning: Image" << p_path << "not found! Can't set!";
return false;
}
path = p_path;
movie->stop();
movie->setFileName(path);
if (ao_app->get_animated_theme() && movie->frameCount() > 1) {
movie->start();
}
else {
QPixmap f_pixmap(path);

QPixmap f_pixmap(p_path);

f_pixmap =
f_pixmap.scaled(this->width(), this->height(), Qt::IgnoreAspectRatio);
this->setPixmap(f_pixmap);
this->setMask(f_pixmap.mask());
f_pixmap =
f_pixmap.scaled(this->size(), Qt::IgnoreAspectRatio);
this->setPixmap(f_pixmap);
this->setMask(f_pixmap.mask());
}
return true;
}
Loading

0 comments on commit fe00c6b

Please sign in to comment.