Skip to content

Commit fe00c6b

Browse files
Crystalwarriorin1tiate
andauthored
Animated Themes. Subthemes. Custom default_theme. Overhaul asset paths. 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 <radwoodward@vikings.grayson.edu>
1 parent b78479f commit fe00c6b

21 files changed

Lines changed: 514 additions & 480 deletions

include/aoapplication.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,22 @@ class AOApplication : public QApplication {
130130
// implementation in path_functions.cpp
131131
QString get_base_path();
132132
QString get_data_path();
133-
QString get_theme_path(QString p_file);
134-
QString get_default_theme_path(QString p_file);
135-
QString get_custom_theme_path(QString p_theme, QString p_file);
133+
QString get_theme_path(QString p_file, QString p_theme="");
136134
QString get_character_path(QString p_char, QString p_file);
137135
QString get_misc_path(QString p_misc, QString p_file);
138136
QString get_sounds_path(QString p_file);
139137
QString get_music_path(QString p_song);
140138
QString get_background_path(QString p_file);
141139
QString get_default_background_path(QString p_file);
142140
QString get_evidence_path(QString p_file);
141+
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="");
142+
QString get_asset_path(QStringList pathlist);
143+
QString get_image_path(QStringList pathlist, bool static_image=false);
144+
QString get_sfx_path(QStringList pathlist);
145+
QString get_config_value(QString p_identifier, QString p_config, QString p_theme="", QString p_subtheme="", QString p_default_theme="", QString p_misc="");
146+
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="");
147+
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="");
148+
QString get_sfx(QString p_sfx, QString p_misc="", QString p_character="");
143149
QString get_case_sensitive_path(QString p_file);
144150

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

307313
// Returns the value to you
308314
QString get_design_element(QString p_identifier, QString p_file,
309-
QString p_char = "");
310-
311-
// Returns the name of the font with p_identifier from p_file
312-
QString get_font_name(QString p_identifier, QString p_file);
315+
QString p_misc = "");
313316

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

326-
// Returns the sfx with p_identifier from sounds.ini in the current theme path
327-
QString get_sfx(QString p_identifier, QString p_misc="default");
329+
// Returns the sfx with p_identifier from courtroom_sounds.ini in the current theme path
330+
QString get_court_sfx(QString p_identifier, QString p_misc="");
328331

329332
// Figure out if we can opus this or if we should fall back to wav
330333
QString get_sfx_suffix(QString sound_to_check);
331334

332335
// Can we use APNG for this? If not, WEBP? If not, GIF? If not, fall back to
333336
// PNG.
334-
QString get_image_suffix(QString path_to_check);
335-
336-
// If this image is static and non-animated, return the supported static image
337-
// formats. Currently only PNG.
338-
QString get_static_image_suffix(QString path_to_check);
337+
QString get_image_suffix(QString path_to_check, bool static_image=false);
339338

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

375-
// Returns the value of shouts from the specified p_char's ini file
376-
QString get_char_shouts(QString p_char);
377-
378374
// Returns the preanim duration of p_char's p_emote
379375
int get_preanim_duration(QString p_char, QString p_emote);
380376

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

388-
// Get the effects folder referenced by the char.ini, read it and return the
389-
// list of filenames in a string
390-
QStringList get_theme_effects();
391-
392384
// Get the theme's effects folder, read it and return the list of filenames in
393385
// a string
394386
QStringList get_effects(QString p_char);
@@ -488,6 +480,18 @@ class AOApplication : public QApplication {
488480
// Get if automatic logging is enabled
489481
bool get_auto_logging_enabled();
490482

483+
// Get the subtheme from settings
484+
QString get_subtheme();
485+
486+
// Get if the theme is animated
487+
bool get_animated_theme();
488+
489+
// Currently defined subtheme
490+
QString subtheme;
491+
492+
QString default_theme = "default";
493+
QString current_theme = default_theme;
494+
491495
// The file name of the log file in base/logs.
492496
QString log_filename;
493497

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

508-
QString current_theme = "default";
509-
510512
QVector<server_type> server_list;
511513
QVector<server_type> favorite_list;
512514

include/aobutton.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <QDebug>
77
#include <QPushButton>
8+
#include <QMovie>
89

910
class AOButton : public QPushButton {
1011
Q_OBJECT
@@ -14,8 +15,9 @@ class AOButton : public QPushButton {
1415
~AOButton();
1516

1617
AOApplication *ao_app;
18+
QMovie *movie;
1719

18-
void set_image(QString p_image);
20+
void set_image(QString p_image, QString p_misc="");
1921
};
2022

2123
#endif // AOBUTTON_H

include/aoimage.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <QDebug>
99
#include <QLabel>
10+
#include <QMovie>
1011

1112
class AOImage : public QLabel {
1213
public:
@@ -15,9 +16,11 @@ class AOImage : public QLabel {
1516

1617
QWidget *m_parent;
1718
AOApplication *ao_app;
19+
QMovie *movie;
1820

19-
bool set_image(QString p_image);
20-
bool set_chatbox(QString p_path);
21+
QString path;
22+
23+
bool set_image(QString p_image, QString p_misc = "");
2124
void set_size_and_pos(QString identifier);
2225
};
2326

include/aolayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class AOLayer : public QLabel {
8585

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

9090
protected:
9191
AOApplication *ao_app;

include/aooptionsdialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ class AOOptionsDialog : public QDialog {
4545
QFormLayout *ui_gameplay_form;
4646
QLabel *ui_theme_label;
4747
QComboBox *ui_theme_combobox;
48+
QLabel *ui_subtheme_label;
49+
QComboBox *ui_subtheme_combobox;
4850
QPushButton *ui_theme_reload_button;
51+
QLabel *ui_animated_theme_lbl;
52+
QCheckBox *ui_animated_theme_cb;
4953
QFrame *ui_theme_log_divider;
5054
QLabel *ui_downwards_lbl;
5155
QCheckBox *ui_downwards_cb;
@@ -173,6 +177,7 @@ public slots:
173177
void discard_pressed();
174178
void button_clicked(QAbstractButton *button);
175179
void on_reload_theme_clicked();
180+
void theme_changed(int i);
176181
};
177182

178183
#endif // AOOPTIONSDIALOG_H

include/courtroom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class Courtroom : public QMainWindow {
505505
QVector<QColor> default_color_rgb_list;
506506

507507
// Get a color index from an arbitrary misc config
508-
void gen_char_rgb_list(QString p_char);
508+
void gen_char_rgb_list(QString p_misc);
509509
QVector<QColor> char_color_rgb_list;
510510

511511
// Misc we used for the last message, and the one we're using now. Used to avoid loading assets when it's not needed

src/aobutton.cpp

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,42 @@ AOButton::AOButton(QWidget *parent, AOApplication *p_ao_app)
77
: QPushButton(parent)
88
{
99
ao_app = p_ao_app;
10+
movie = new QMovie(this);
11+
connect(movie, &QMovie::frameChanged, [=]{
12+
this->setIcon(movie->currentPixmap().scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
13+
this->setIconSize(QSize(this->width(), this->height()));
14+
});
1015
}
1116

1217
AOButton::~AOButton() {}
1318

14-
void AOButton::set_image(QString p_image)
19+
void AOButton::set_image(QString p_path, QString p_misc)
1520
{
16-
QString image_path =
17-
ao_app->get_static_image_suffix(ao_app->get_theme_path(p_image));
18-
QString default_image_path =
19-
ao_app->get_static_image_suffix(ao_app->get_default_theme_path(p_image));
20-
21-
if (file_exists(image_path)) {
22-
this->setText("");
23-
this->setStyleSheet("QPushButton { border-image: url(\"" + image_path +
24-
"\") 0 0 0 0 stretch stretch; }"
25-
"QToolTip { background-image: url(); color: #000000; "
26-
"background-color: #ffffff; border: 0px; }");
21+
movie->stop();
22+
QString p_image;
23+
// Check if the user wants animated themes
24+
if (ao_app->get_animated_theme())
25+
// We want an animated image
26+
p_image = ao_app->get_image(p_path, ao_app->current_theme, ao_app->get_subtheme(), ao_app->default_theme, p_misc);
27+
else
28+
// Grab a static variant of the image
29+
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);
30+
if (!file_exists(p_image)) {
31+
this->setIcon(QIcon());
32+
this->setIconSize(this->size());
33+
this->setStyleSheet("");
34+
return;
2735
}
28-
else if (file_exists(default_image_path)) {
29-
this->setText("");
30-
this->setStyleSheet("QPushButton { border-image: url(\"" +
31-
default_image_path +
32-
"\"); }"
33-
"QToolTip { background-image: url(); color: #000000; "
34-
"background-color: #ffffff; border: 0px; }");
36+
this->setText("");
37+
this->setStyleSheet("QPushButton { background-color: transparent; border: 0px }");
38+
movie->setFileName(p_image);
39+
// We double-check if the user wants animated themes, so even if an animated image slipped through,
40+
// we still set it static
41+
if (ao_app->get_animated_theme() && movie->frameCount() > 1) {
42+
movie->start();
43+
}
44+
else {
45+
this->setIcon(QPixmap(p_image).scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
46+
this->setIconSize(this->size());
3547
}
36-
else
37-
this->setStyleSheet("QPushButton { border-image: url(); }"
38-
"QToolTip { background-image: url(); color: #000000; "
39-
"background-color: #ffffff; border: 0px; }");
4048
}

src/aocharbutton.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void AOCharButton::set_passworded() { ui_passworded->show(); }
5959

6060
void AOCharButton::set_image(QString p_character)
6161
{
62-
QString image_path = ao_app->get_static_image_suffix(
62+
QString image_path = ao_app->get_image_suffix(
6363
ao_app->get_character_path(p_character, "char_icon"));
6464

6565
this->setText("");

src/aoemotebutton.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void AOEmoteButton::set_char_image(QString p_char, int p_emote, QString suffix)
6161
{
6262
QString emotion_number = QString::number(p_emote + 1);
6363
QString image_path =
64-
ao_app->get_static_image_suffix(ao_app->get_character_path(
64+
ao_app->get_image_suffix(ao_app->get_character_path(
6565
p_char, "emotions/button" + emotion_number + suffix));
6666

6767
this->set_image(image_path, ao_app->get_emote_comment(p_char, p_emote));

src/aoevidencebutton.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void AOEvidenceButton::set_image(QString p_image)
5858
void AOEvidenceButton::set_theme_image(QString p_image)
5959
{
6060
QString theme_image_path = ao_app->get_theme_path(p_image);
61-
QString default_image_path = ao_app->get_default_theme_path(p_image);
61+
QString default_image_path = ao_app->get_theme_path(p_image, ao_app->default_theme);
6262

6363
QString final_image_path;
6464

0 commit comments

Comments
 (0)