Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated Themes. Subthemes. Custom default_theme. Overhaul asset paths. Fix a ton of asset resolution bugs. #466

Merged
merged 33 commits into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
55a45bf
Remove get_static_image_suffix (webp, gif etc. can be non-animated)
Crystalwarrior Feb 11, 2021
9dde531
forgot to remove static image from aoimage
Crystalwarrior Feb 11, 2021
cc92e25
Simplify get_theme_path, get_custom_theme_path and get_default_theme_…
Crystalwarrior Feb 11, 2021
e30b9fd
Simplify AOImage set_image function to use get_asset_path
Crystalwarrior Feb 11, 2021
ecd18c4
Add p_default_theme for get_asset_path
Crystalwarrior Feb 11, 2021
ec04fe8
Condense aolayer path lookups into the get_asset_path function
Crystalwarrior Feb 11, 2021
94c33cc
Get rid of get_font_name due to underuse (and it just does the same t…
Crystalwarrior Feb 11, 2021
b60b173
Adapt a whole bunch of text_file_functions to the get_asset_path meth…
Crystalwarrior Feb 11, 2021
5f8f702
Program doesn't run, color lists stop generating for some reason
Crystalwarrior Feb 11, 2021
d56237b
Fix a really tricky issue that popped up regarding char_color_rgb_lis…
Crystalwarrior Feb 11, 2021
403b327
Address the sfx player path resolution being really, really stupid an…
Crystalwarrior Feb 11, 2021
07454f8
Fix sfx path resolution being funky (apparently D:/Qt/Projects/AO2-Cl…
Crystalwarrior Feb 11, 2021
51015ae
Implement:
Crystalwarrior Feb 12, 2021
fac4f34
Add a new get_config_value that obtains a value from the config that …
Crystalwarrior Feb 12, 2021
d1cb5b9
Merge remote-tracking branch 'origin/master' into feature/subthemes
Crystalwarrior Feb 12, 2021
7488ea1
Fix effects.ini sounds not working
Crystalwarrior Feb 12, 2021
d44ae63
Make it so even if you miss the required asset, and don't have a miss…
Crystalwarrior Feb 12, 2021
7c101a3
Implement default_theme option for courtroom_design.ini, allowing you…
Crystalwarrior Feb 12, 2021
a79ff64
move sounds folder lower in sfx pathlist
Feb 12, 2021
4aabf0b
fix realization sfx not being fetched from config
Feb 12, 2021
cbcc073
Make aosfxplayer actually use get_sfx I made
Crystalwarrior Feb 12, 2021
a930ecb
I thought this would fix QSettings::value: Empty key passed but I gue…
Crystalwarrior Feb 12, 2021
4e0a740
Remove silly .png exception for SplashLayer
Crystalwarrior Feb 12, 2021
70f5d86
Make WTCE cooler by including a stop method for witness testimony ind…
Crystalwarrior Feb 12, 2021
c310fc2
Reduce code duplication for get_sfx
Crystalwarrior Feb 12, 2021
1067b96
Fix the program hanging/entering an infinite loop/segfaults/a number …
Crystalwarrior Feb 12, 2021
301acfd
Fix segfaults with AOLayers by sanity checking using max_frames
Crystalwarrior Feb 12, 2021
7301ef3
You'll hate me for this.
Crystalwarrior Feb 12, 2021
68e908a
Add a settings option to toggle animated themes on or off
Crystalwarrior Feb 12, 2021
165b5f1
Add a setting for animated theme elements
Crystalwarrior Feb 12, 2021
5f815fb
Fix custom chat and generally the chat boxes not having consistent be…
Crystalwarrior Feb 12, 2021
16b2da8
Add SubTheme (ST) packet. Pass subtheme as arg0, and "1" if you want …
Crystalwarrior Feb 12, 2021
c805979
Merge branch 'feature/subthemes-for-real' into feature/subthemes
Crystalwarrior Feb 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cursed


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