diff options
| author | Crystalwarrior <Varsash@Gmail.com> | 2021-02-13 11:52:12 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-13 11:52:12 +0300 |
| commit | fe00c6b7defe10a2c63b690c04ae2779fcccf859 (patch) | |
| tree | e2cafb15a8be710f2a676706c6d9eb652c0d3a57 /src/text_file_functions.cpp | |
| parent | b78479f4cc1d4cec41edcd40f4817db368e4acb0 (diff) | |
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>
Diffstat (limited to 'src/text_file_functions.cpp')
| -rw-r--r-- | src/text_file_functions.cpp | 276 |
1 files changed, 92 insertions, 184 deletions
diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index cc28628d..919657cb 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -281,9 +281,10 @@ QString AOApplication::read_design_ini(QString p_identifier, if (value.type() == QVariant::StringList) { return value.toStringList().join(","); } - else { + else if (!value.isNull()) { return value.toString(); } + return ""; } Qt::TransformationMode AOApplication::get_scaling(QString p_scaling) @@ -295,23 +296,16 @@ Qt::TransformationMode AOApplication::get_scaling(QString p_scaling) QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path(p_file); - QString default_path = get_default_theme_path(p_file); - QString f_result = read_design_ini(p_identifier, design_ini_path); - + QString value = get_config_value(p_identifier, p_file, current_theme, get_subtheme(), default_theme); QPoint return_value; return_value.setX(0); return_value.setY(0); - if (f_result == "") { - f_result = read_design_ini(p_identifier, default_path); + if (value == "") + return return_value; - if (f_result == "") - return return_value; - } - - QStringList sub_line_elements = f_result.split(","); + QStringList sub_line_elements = value.split(","); if (sub_line_elements.size() < 2) return return_value; @@ -346,63 +340,32 @@ pos_size_type AOApplication::get_element_dimensions(QString p_identifier, return return_value; } QString AOApplication::get_design_element(QString p_identifier, QString p_file, - QString p_char) -{ - QStringList paths{get_theme_path("misc/" + get_chat(p_char) + "/" + - p_file), // user theme overrides base/misc - get_base_path() + "misc/" + get_chat(p_char) + "/" + p_file, - get_theme_path(p_file), get_default_theme_path(p_file)}; - for (const QString &path : paths) { - QString value = read_design_ini(p_identifier, path); - if (!value.isEmpty()) - return value; - } - return ""; -} -QString AOApplication::get_font_name(QString p_identifier, QString p_file) + QString p_misc) { - QString design_ini_path = get_theme_path(p_file); - QString f_result = read_design_ini(p_identifier, design_ini_path); - QString default_path = get_default_theme_path(p_file); - if (f_result == "") { - f_result = read_design_ini(p_identifier, default_path); - if (f_result == "") - return ""; - } - return f_result; + QString value = get_config_value(p_identifier, p_file, current_theme, get_subtheme(), default_theme, p_misc); + if (!value.isEmpty()) + return value; + return ""; } + +// tfw this function is only used for lobby and nowhere else int AOApplication::get_font_size(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path(p_file); - QString default_path = get_default_theme_path(p_file); - QString f_result = read_design_ini(p_identifier, design_ini_path); - - if (f_result == "") { - f_result = read_design_ini(p_identifier, default_path); - - if (f_result == "") - return 10; - } - - return f_result.toInt(); + QString value = get_config_value(p_identifier, p_file, current_theme, get_subtheme(), default_theme); + if (!value.isEmpty()) + return value.toInt(); + return 10; } QColor AOApplication::get_color(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path(p_file); - QString default_path = get_default_theme_path(p_file); - QString f_result = read_design_ini(p_identifier, design_ini_path); - + QString value = get_config_value(p_identifier, p_file, current_theme, get_subtheme(), default_theme); QColor return_color(0, 0, 0); - if (f_result == "") { - f_result = read_design_ini(p_identifier, default_path); - - if (f_result == "") - return return_color; - } + if (value.isEmpty()) + return return_color; - QStringList color_list = f_result.split(","); + QStringList color_list = value.split(","); if (color_list.size() < 3) return return_color; @@ -416,18 +379,11 @@ QColor AOApplication::get_color(QString p_identifier, QString p_file) QString AOApplication::get_stylesheet(QString p_file) { - QString design_ini_path = get_theme_path(p_file); - QString default_path = get_default_theme_path(p_file); - + QString path = get_asset(p_file, current_theme, get_subtheme(), default_theme); QFile design_ini; - - design_ini.setFileName(design_ini_path); - - if (!design_ini.open(QIODevice::ReadOnly)) { - design_ini.setFileName(default_path); - if (!design_ini.open(QIODevice::ReadOnly)) - return ""; - } + design_ini.setFileName(path); + if (!design_ini.open(QIODevice::ReadOnly)) + return ""; QTextStream in(&design_ini); @@ -443,12 +399,9 @@ QString AOApplication::get_stylesheet(QString p_file) QString AOApplication::get_tagged_stylesheet(QString target_tag, QString p_file) { - QString design_ini_path = get_theme_path(p_file); - + QString path = get_asset(p_file, current_theme, get_subtheme(), default_theme); QFile design_ini; - - design_ini.setFileName(design_ini_path); - + design_ini.setFileName(path); if (!design_ini.open(QIODevice::ReadOnly)) return ""; @@ -479,14 +432,19 @@ QString AOApplication::get_tagged_stylesheet(QString target_tag, QString p_file) QString AOApplication::get_chat_markup(QString p_identifier, QString p_chat) { - QStringList paths{get_theme_path("misc/" + get_chat(p_chat) + "/config.ini"), - get_base_path() + "misc/" + get_chat(p_chat) + + // New Chadly method + QString value = get_config_value(p_identifier, "chat_config.ini", current_theme, get_subtheme(), default_theme, p_chat); + if (!value.isEmpty()) + return value.toLatin1(); + + // Backwards ass compatibility + QStringList backwards_paths{get_theme_path("misc/" + p_chat + "/config.ini"), + get_base_path() + "misc/" + p_chat + "/config.ini", get_base_path() + "misc/default/config.ini", get_theme_path("misc/default/config.ini")}; - - for (const QString &path : paths) { - QString value = read_design_ini(p_identifier, path); + for (const QString &p : backwards_paths) { + QString value = read_design_ini(p_identifier, p); if (!value.isEmpty()) { return value.toLatin1(); } @@ -514,22 +472,12 @@ QColor AOApplication::get_chat_color(QString p_identifier, QString p_chat) return return_color; } -QString AOApplication::get_sfx(QString p_identifier, QString p_misc) +QString AOApplication::get_court_sfx(QString p_identifier, QString p_misc) { - QStringList paths{get_theme_path("misc/" + p_misc + "/courtroom_sounds.ini"), - get_misc_path(p_misc, "courtroom_sounds.ini"), - get_theme_path("courtroom_sounds.ini"), - get_default_theme_path("courtroom_sounds.ini")}; - - QString return_sfx = ""; - - for (const QString &path : paths) { - QString value = read_design_ini(p_identifier, path); - if (!value.isEmpty()) { - return value.toLatin1(); - } - } - return return_sfx; + QString value = get_config_value(p_identifier, "courtroom_sounds.ini", current_theme, get_subtheme(), default_theme, p_misc); + if (!value.isEmpty()) + return value.toLatin1(); + return ""; } QString AOApplication::get_sfx_suffix(QString sound_to_check) @@ -547,21 +495,20 @@ QString AOApplication::get_sfx_suffix(QString sound_to_check) return sound_to_check + ".wav"; } -QString AOApplication::get_image_suffix(QString path_to_check) +QString AOApplication::get_image_suffix(QString path_to_check, bool static_image) { if (file_exists(path_to_check)) return path_to_check; - 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"; -} - -QString AOApplication::get_static_image_suffix(QString path_to_check) -{ + // A better method would to actually use AOImageReader and see if these images have more than 1 frame. + // However, that might not be performant. + if (!static_image) { + 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"; } @@ -574,7 +521,7 @@ QString AOApplication::read_char_ini(QString p_char, QString p_search_line, QSettings settings(get_character_path(p_char, "char.ini"), QSettings::IniFormat); settings.beginGroup(target_tag); - QString value = settings.value(p_search_line).toString(); + QString value = settings.value(p_search_line).value<QString>(); settings.endGroup(); return value; } @@ -598,7 +545,7 @@ QStringList AOApplication::read_ini_tags(QString p_path, QString target_tag) settings.beginGroup(target_tag); QStringList keys = settings.allKeys(); foreach (QString key, keys) { - QString value = settings.value(key).toString(); + QString value = settings.value(key).value<QString>(); r_values << key + "=" + value; } if (!settings.group().isEmpty()) @@ -691,9 +638,6 @@ QString AOApplication::get_chat(QString p_char) if (p_char == "default") return "default"; QString f_result = read_char_ini(p_char, "chat", "Options"); - - // handling the correct order of chat is a bit complicated, we let the caller - // do it return f_result; } @@ -713,14 +657,6 @@ int AOApplication::get_chat_size(QString p_char) return f_result.toInt(); } -QString AOApplication::get_char_shouts(QString p_char) -{ - QString f_result = read_char_ini(p_char, "shouts", "Options"); - if (f_result == "") - return current_theme; // The default option is the current theme. - return f_result; -} - int AOApplication::get_preanim_duration(QString p_char, QString p_emote) { QString f_result = read_char_ini(p_char, p_emote, "Time"); @@ -854,7 +790,6 @@ QString AOApplication::get_sfx_looping(QString p_char, int p_emote) QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "SoundL"); - qDebug() << f_result; if (f_result == "") return "0"; else @@ -903,37 +838,18 @@ int AOApplication::get_text_delay(QString p_char, QString p_emote) return f_result.toInt(); } -QStringList AOApplication::get_theme_effects() +QStringList AOApplication::get_effects(QString p_char) { - QString p_path = get_theme_path("effects/effects.ini"); - QString default_path = get_default_theme_path("effects/effects.ini"); - + QString p_misc = read_char_ini(p_char, "effects", "Options"); + QString p_path = get_asset("effects/effects.ini", current_theme, get_subtheme(), default_theme, ""); + QString p_misc_path = get_asset("effects/effects.ini", current_theme, get_subtheme(), default_theme, p_misc); QStringList effects; - if (!file_exists(p_path)) { - p_path = default_path; - if (!file_exists(p_path)) - return effects; - } QStringList lines = read_file(p_path).split("\n"); - foreach (QString effect, lines) { - effect = effect.split("=")[0].trimmed().split("_")[0]; - if (!effect.isEmpty() && !effects.contains(effect)) - effects.append(effect); + // Misc path different from default path, stack the new miscs on top of the defaults + if (p_misc_path != p_path) { + lines << read_file(p_misc_path).split("\n"); } - return effects; -} - -QStringList AOApplication::get_effects(QString p_char) -{ - QString p_effect = read_char_ini(p_char, "effects", "Options"); - QString p_path = get_base_path() + "misc/" + p_effect + "/effects.ini"; - - QStringList effects = get_theme_effects(); - if (!file_exists(p_path)) - return effects; - - QStringList lines = read_file(p_path).split("\n"); foreach (QString effect, lines) { effect = effect.split("=")[0].trimmed().split("_")[0]; if (!effect.isEmpty() && !effects.contains(effect)) @@ -946,27 +862,13 @@ QStringList AOApplication::get_effects(QString p_char) QString AOApplication::get_effect(QString effect, QString p_char, QString p_folder) { - QString p_effect = p_folder; if (p_folder == "") - p_effect = read_char_ini(p_char, "effects", "Options"); - - QString p_path = - get_image_suffix(get_base_path() + "misc/" + p_effect + "/" + effect); - QString design_ini_path = - get_image_suffix(get_theme_path("effects/" + effect)); - QString default_path = - get_image_suffix(get_default_theme_path("effects/" + effect)); - - if (!file_exists(p_path)) { - p_path = design_ini_path; - if (!file_exists(p_path)) { - p_path = default_path; - if (!file_exists(p_path)) { - return ""; - } - } - } + p_folder = read_char_ini(p_char, "effects", "Options"); + + QString p_path = get_image("effects/" + effect, current_theme, get_subtheme(), default_theme, p_folder); + if (!file_exists(p_path)) + return ""; return p_path; } @@ -978,36 +880,20 @@ QString AOApplication::get_effect_property(QString fx_name, QString p_char, f_property = fx_name; else f_property = fx_name + "_" + p_property; - QString p_effect = read_char_ini(p_char, "effects", "Options"); - QString p_path = get_base_path() + "misc/" + p_effect + "/effects.ini"; - QString design_ini_path = get_theme_path("effects/effects.ini"); - QString default_path = get_default_theme_path("effects/effects.ini"); - - QString f_result = read_design_ini(f_property, p_path); - if (f_result == "") { - f_result = read_design_ini(f_property, design_ini_path); - if (f_result == "") { - f_result = read_design_ini(f_property, default_path); - } - } + QString f_result = get_config_value(f_property, "effects/effects.ini", current_theme, get_subtheme(), default_theme, read_char_ini(p_char, "effects", "Options")); if (fx_name == "realization" && p_property == "sound") { f_result = get_custom_realization(p_char); } - - qDebug() << "got" << f_property << "of" << fx_name << "==" << f_result; - return f_result; } QString AOApplication::get_custom_realization(QString p_char) { QString f_result = read_char_ini(p_char, "realization", "Options"); - if (f_result == "") - return get_sfx("realization"); - else - return get_sfx_suffix(get_sounds_path(f_result)); + return get_court_sfx("realization"); + return get_sfx_suffix(get_sounds_path(f_result)); } bool AOApplication::get_blank_blip() @@ -1162,9 +1048,31 @@ QString AOApplication::get_casing_can_host_cases() .value<QString>(); return result; } + bool AOApplication::get_auto_logging_enabled() { QString result = configini->value("automatic_logging_enabled", "true").value<QString>(); return result.startsWith("true"); } + +QString AOApplication::get_subtheme() +{ + QString result = + configini->value("subtheme", "server").value<QString>(); + // Server means we want the server to decide for us + if (result == "server") + // 'subtheme' variable is affected by the server + result = subtheme; + // Default means we don't want any subthemes + else if (result == "default") + result = ""; + return result; +} + +bool AOApplication::get_animated_theme() +{ + QString result = + configini->value("animated_theme", "true").value<QString>(); + return result.startsWith("true"); +} |
