From 01e80dd307f475d1dcc00233d87244b3c03421d8 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Fri, 25 Mar 2022 14:54:42 +0300 Subject: [PATCH 01/18] Fix effect offsets only applying after the effect already plays Add "_layer" property which can be "behind", "character" or default "chat". This deprecates the "under_chatbox" property --- include/courtroom.h | 3 +- src/courtroom.cpp | 79 +++++++++++++++++++++++++++++---------------- 2 files changed, 53 insertions(+), 29 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index bf688b50d..7365db1f7 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -188,8 +188,7 @@ class Courtroom : public QMainWindow { void set_scene(QString f_desk_mod, QString f_side); // sets ui_vp_player_char according to SELF_OFFSET, only a function bc it's used with desk_mod 4 and 5 - // sets ui_effects_layer according to the SELF_OFFSET, unless it is overwritten by effects.ini - void set_self_offset(QString p_list, QString p_effect); + void set_self_offset(QString p_list); // takes in serverD-formatted IP list as prints a converted version to server // OOC admittedly poorly named diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 0afbeb24e..db586bbee 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2447,13 +2447,10 @@ void Courtroom::display_character() else ui_vp_player_char->network_strings.clear(); - // Determine if we should flip the character or not (what servers don't support flipping at this point?) - if (ao_app->flipping_enabled && m_chatmessage[FLIP].toInt() == 1) - ui_vp_player_char->set_flipped(true); - else - ui_vp_player_char->set_flipped(false); + // Determine if we should flip the character or not + ui_vp_player_char->set_flipped(m_chatmessage[FLIP].toInt() == 1); // Move the character on the viewport according to the offsets - set_self_offset(m_chatmessage[SELF_OFFSET], m_chatmessage[EFFECTS]); + set_self_offset(m_chatmessage[SELF_OFFSET]); } void Courtroom::display_pair_character(QString other_charid, QString other_offset) @@ -2659,9 +2656,12 @@ void Courtroom::do_flash() QString f_char = m_chatmessage[CHAR_NAME]; QString f_custom_theme = ao_app->get_chat(f_char); ui_vp_effect->stretch = true; + ui_vp_effect->setParent(this); + ui_vp_effect->stackUnder(ui_vp_objection); // go above the chatbox + ui_vp_effect->move(ui_viewport->x(), ui_viewport->y()); + ui_vp_effect->set_static_duration(60); ui_vp_effect->set_max_duration(60); - ui_vp_player_char->stackUnder(ui_vp_objection); // go above the chatbox ui_vp_effect->load_image( ao_app->get_effect("realization", f_char, f_custom_theme), false); } @@ -2686,14 +2686,52 @@ void Courtroom::do_effect(QString fx_name, QString fx_sound, QString p_char, ui_vp_effect->stretch = ao_app->get_effect_property(fx_name, p_char, "stretch") .startsWith("true"); - bool under_chatbox = ao_app->get_effect_property(fx_name, p_char, "under_chatbox").startsWith("true"); - if (under_chatbox) - ui_vp_effect->stackUnder(ui_vp_chatbox); - else - ui_vp_effect->stackUnder(ui_vp_objection); + ui_vp_effect->set_flipped(ao_app->get_effect_property(fx_name, p_char, "respect_flip").startsWith("true") && m_chatmessage[FLIP].toInt() == 1); ui_vp_effect->set_play_once( false); // The effects themselves dictate whether or not they're looping. // Static effects will linger. + + // Possible values: "chat", "character", "behind" + QString layer = ao_app->get_effect_property(fx_name, p_char, "layer").toLower(); + if (layer == "behind"){ + ui_vp_effect->setParent(ui_viewport); + ui_vp_effect->stackUnder(ui_vp_player_char); + } + else if (layer == "character") { + ui_vp_effect->setParent(this); + ui_vp_effect->stackUnder(ui_vp_chatbox); + } + else { // if (layer == "chat") { + ui_vp_effect->setParent(this); + ui_vp_effect->stackUnder(ui_vp_objection); + } + + int effect_x = 0; + int effect_y = 0; + if (ui_vp_effect->parentWidget() != ui_viewport) { + //We need to add the viewport as an offset as effects are not bound to it. + effect_x = ui_viewport->x(); + effect_y = ui_viewport->y(); + } + //If an effect is ignoring the users offset, we force it to the default position of the viewport. + if (ao_app->get_effect_property(fx_name, p_char, "ignore_offset") == "true") { + ui_vp_effect->move(effect_x, effect_y); + } + else { + QStringList self_offsets = m_chatmessage[SELF_OFFSET].split("&"); + int self_offset = self_offsets[0].toInt(); + int self_offset_v; + if (self_offsets.length() <= 1) + self_offset_v = 0; + else + self_offset_v = self_offsets[1].toInt(); + + //Offset is not disabled, we move the effects layer to match the position of our character + effect_x += ui_viewport->width() * self_offset / 100; + effect_y += ui_viewport->height() * self_offset_v / 100; + ui_vp_effect->move(effect_x, effect_y); + } + ui_vp_effect->set_static_duration(0); ui_vp_effect->set_max_duration(0); ui_vp_effect->load_image(effect, true); @@ -3378,7 +3416,7 @@ void Courtroom::start_chat_ticking() // handle expanded desk mods switch(m_chatmessage[DESK_MOD].toInt()) { case 4: - set_self_offset(m_chatmessage[SELF_OFFSET], QString("||")); + set_self_offset(m_chatmessage[SELF_OFFSET]); [[fallthrough]]; case 2: set_scene("1", m_chatmessage[SIDE]); @@ -3834,9 +3872,8 @@ void Courtroom::set_scene(QString f_desk_mod, QString f_side) } } -void Courtroom::set_self_offset(QString p_list, QString p_effect) { +void Courtroom::set_self_offset(QString p_list) { QStringList self_offsets = p_list.split("&"); - QStringList play_effect = p_effect.split("|"); int self_offset = self_offsets[0].toInt(); int self_offset_v; if (self_offsets.length() <= 1) @@ -3844,18 +3881,6 @@ void Courtroom::set_self_offset(QString p_list, QString p_effect) { else self_offset_v = self_offsets[1].toInt(); ui_vp_player_char->move(ui_viewport->width() * self_offset / 100, ui_viewport->height() * self_offset_v / 100); - - //If an effect is ignoring the users offset, we force it to the default position of the viewport. - if (ao_app->get_effect_property(play_effect[0], current_char, "ignore_offset") == "true") { - ui_vp_effect->move(ui_viewport->x(), ui_viewport->y()); - return; - } - - //Offset is not disabled, we move the effects layer to match the position of our character - //We need to add the viewport as an offset as effects are not bound to it. - int effect_x = (ui_viewport->width() * self_offset / 100) + ui_viewport->x(); - int effect_y = (ui_viewport->height() * self_offset_v / 100) + ui_viewport->y(); - ui_vp_effect->move(effect_x, effect_y); } void Courtroom::set_ip_list(QString p_list) From e5516cf68d70a0631c83782c4972d4cc1429b592 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Fri, 25 Mar 2022 15:02:08 +0300 Subject: [PATCH 02/18] Add a "sticky" effect property which is the same as "stickyeffects" setting being enabled but just for that 1 effect --- src/courtroom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index db586bbee..b8d7dddf1 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2073,7 +2073,7 @@ void Courtroom::on_chat_return_pressed() QString p_effect = ao_app->read_char_ini(current_char, "effects", "Options"); packet_contents.append(effect + "|" + p_effect + "|" + fx_sound); - if (!ao_app->is_stickyeffects_enabled()) { + if (!ao_app->is_stickyeffects_enabled() && !ao_app->get_effect_property(effect, current_char, "sticky").startsWith("true")) { ui_effects_dropdown->blockSignals(true); ui_effects_dropdown->setCurrentIndex(0); ui_effects_dropdown->blockSignals(false); From cfe3b1fa91efafd14d357f1139972389ece3dae1 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Fri, 25 Mar 2022 15:05:08 +0300 Subject: [PATCH 03/18] Clang is tidy, clang is caring --- include/courtroom.h | 2 +- src/courtroom.cpp | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index 7365db1f7..fe60a1b3f 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -188,7 +188,7 @@ class Courtroom : public QMainWindow { void set_scene(QString f_desk_mod, QString f_side); // sets ui_vp_player_char according to SELF_OFFSET, only a function bc it's used with desk_mod 4 and 5 - void set_self_offset(QString p_list); + void set_self_offset(const QString& p_list); // takes in serverD-formatted IP list as prints a converted version to server // OOC admittedly poorly named diff --git a/src/courtroom.cpp b/src/courtroom.cpp index b8d7dddf1..e3dc9234d 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -3872,15 +3872,18 @@ void Courtroom::set_scene(QString f_desk_mod, QString f_side) } } -void Courtroom::set_self_offset(QString p_list) { +void Courtroom::set_self_offset(const QString& p_list) { QStringList self_offsets = p_list.split("&"); int self_offset = self_offsets[0].toInt(); int self_offset_v; - if (self_offsets.length() <= 1) + if (self_offsets.length() <= 1) { self_offset_v = 0; - else + } + else { self_offset_v = self_offsets[1].toInt(); - ui_vp_player_char->move(ui_viewport->width() * self_offset / 100, ui_viewport->height() * self_offset_v / 100); + } + const int percent = 100; + ui_vp_player_char->move(ui_viewport->width() * self_offset / percent, ui_viewport->height() * self_offset_v / percent); } void Courtroom::set_ip_list(QString p_list) From d34835a47cbfe758567412c1cd3ace04ac187d32 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Fri, 25 Mar 2022 17:34:12 +0300 Subject: [PATCH 04/18] make character layer actually stack over the character but under the desk add new "over" layer which is over everything in the viewport but under the chat box --- src/courtroom.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index e3dc9234d..b618ffdca 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2698,8 +2698,12 @@ void Courtroom::do_effect(QString fx_name, QString fx_sound, QString p_char, ui_vp_effect->stackUnder(ui_vp_player_char); } else if (layer == "character") { - ui_vp_effect->setParent(this); - ui_vp_effect->stackUnder(ui_vp_chatbox); + ui_vp_effect->setParent(ui_viewport); + ui_vp_effect->stackUnder(ui_vp_desk); + } + else if (layer == "over") { + ui_vp_effect->setParent(ui_viewport); + ui_vp_effect->raise(); } else { // if (layer == "chat") { ui_vp_effect->setParent(this); From f7cc32960705a0ebb660fd4950f90a616ea1485d Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 27 Mar 2022 13:46:17 +0300 Subject: [PATCH 05/18] Switch "ignore_offset" to "respect_offset" so effects only respect character offsets if explicitly told to --- src/courtroom.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index b618ffdca..2f860781e 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2712,16 +2712,14 @@ void Courtroom::do_effect(QString fx_name, QString fx_sound, QString p_char, int effect_x = 0; int effect_y = 0; + // The effect is not parented to viewport, meaning we're overlaying ui elements if (ui_vp_effect->parentWidget() != ui_viewport) { //We need to add the viewport as an offset as effects are not bound to it. effect_x = ui_viewport->x(); effect_y = ui_viewport->y(); } - //If an effect is ignoring the users offset, we force it to the default position of the viewport. - if (ao_app->get_effect_property(fx_name, p_char, "ignore_offset") == "true") { - ui_vp_effect->move(effect_x, effect_y); - } - else { + // This effect respects the character offset settings + if (ao_app->get_effect_property(fx_name, p_char, "respect_offset") == "true") { QStringList self_offsets = m_chatmessage[SELF_OFFSET].split("&"); int self_offset = self_offsets[0].toInt(); int self_offset_v; @@ -2730,11 +2728,11 @@ void Courtroom::do_effect(QString fx_name, QString fx_sound, QString p_char, else self_offset_v = self_offsets[1].toInt(); - //Offset is not disabled, we move the effects layer to match the position of our character + // Move the effects layer to match the position of our character effect_x += ui_viewport->width() * self_offset / 100; effect_y += ui_viewport->height() * self_offset_v / 100; - ui_vp_effect->move(effect_x, effect_y); } + ui_vp_effect->move(effect_x, effect_y); ui_vp_effect->set_static_duration(0); ui_vp_effect->set_max_duration(0); From 6cf7efcb787c01078ba07581ada8a9f859975bda Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 27 Mar 2022 15:52:12 +0300 Subject: [PATCH 06/18] Appease clang tidy... mostly. I don't understand the last thing it's talking about. --- include/courtroom.h | 4 ++-- src/courtroom.cpp | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index fe60a1b3f..5c6275c2f 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -810,8 +810,8 @@ public slots: void preanim_done(); void do_screenshake(); void do_flash(); - void do_effect(QString fx_path, QString fx_sound, QString p_char, - QString p_folder); + void do_effect(QString& fx_path, QString& fx_sound, QString& p_char, + QString& p_folder); void play_char_sfx(QString sfx_name); void mod_called(QString p_ip); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 2f860781e..4b1655695 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2666,21 +2666,25 @@ void Courtroom::do_flash() ao_app->get_effect("realization", f_char, f_custom_theme), false); } -void Courtroom::do_effect(QString fx_name, QString fx_sound, QString p_char, - QString p_folder) +void Courtroom::do_effect(QString& fx_name, QString& fx_sound, QString& p_char, + QString& p_folder) { - if (fx_name == "") + if (fx_name == "") { return; + } QString effect = ao_app->get_effect(fx_name, p_char, p_folder); - if (effect == "") + if (effect == "") { return; + } - if (fx_sound != "") + if (fx_sound != "") { sfx_player->play(fx_sound); + } // Only check if effects are disabled after playing the sound if it exists - if (!ao_app->is_effects_enabled()) + if (!ao_app->is_effects_enabled()) { return; + } ui_vp_effect->transform_mode = ao_app->get_scaling( ao_app->get_effect_property(fx_name, p_char, "scaling")); ui_vp_effect->stretch = @@ -2723,14 +2727,17 @@ void Courtroom::do_effect(QString fx_name, QString fx_sound, QString p_char, QStringList self_offsets = m_chatmessage[SELF_OFFSET].split("&"); int self_offset = self_offsets[0].toInt(); int self_offset_v; - if (self_offsets.length() <= 1) + if (self_offsets.length() <= 1) { self_offset_v = 0; - else + } + else { self_offset_v = self_offsets[1].toInt(); + } // Move the effects layer to match the position of our character - effect_x += ui_viewport->width() * self_offset / 100; - effect_y += ui_viewport->height() * self_offset_v / 100; + const int percent = 100; + effect_x += ui_viewport->width() * self_offset / percent; + effect_y += ui_viewport->height() * self_offset_v / percent; } ui_vp_effect->move(effect_x, effect_y); From e996315b9a0ed71cf2da13dcb047b01be273c770 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 27 Mar 2022 16:09:18 +0300 Subject: [PATCH 07/18] Appease clang tidy further --- src/courtroom.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 4b1655695..e77fd2a66 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2666,13 +2666,13 @@ void Courtroom::do_flash() ao_app->get_effect("realization", f_char, f_custom_theme), false); } -void Courtroom::do_effect(QString& fx_name, QString& fx_sound, QString& p_char, +void Courtroom::do_effect(QString& fx_path, QString& fx_sound, QString& p_char, QString& p_folder) { - if (fx_name == "") { + if (fx_path == "") { return; } - QString effect = ao_app->get_effect(fx_name, p_char, p_folder); + QString effect = ao_app->get_effect(fx_path, p_char, p_folder); if (effect == "") { return; } @@ -2686,17 +2686,17 @@ void Courtroom::do_effect(QString& fx_name, QString& fx_sound, QString& p_char, return; } ui_vp_effect->transform_mode = ao_app->get_scaling( - ao_app->get_effect_property(fx_name, p_char, "scaling")); + ao_app->get_effect_property(fx_path, p_char, "scaling")); ui_vp_effect->stretch = - ao_app->get_effect_property(fx_name, p_char, "stretch") + ao_app->get_effect_property(fx_path, p_char, "stretch") .startsWith("true"); - ui_vp_effect->set_flipped(ao_app->get_effect_property(fx_name, p_char, "respect_flip").startsWith("true") && m_chatmessage[FLIP].toInt() == 1); + ui_vp_effect->set_flipped(ao_app->get_effect_property(fx_path, p_char, "respect_flip").startsWith("true") && m_chatmessage[FLIP].toInt() == 1); ui_vp_effect->set_play_once( false); // The effects themselves dictate whether or not they're looping. // Static effects will linger. // Possible values: "chat", "character", "behind" - QString layer = ao_app->get_effect_property(fx_name, p_char, "layer").toLower(); + QString layer = ao_app->get_effect_property(fx_path, p_char, "layer").toLower(); if (layer == "behind"){ ui_vp_effect->setParent(ui_viewport); ui_vp_effect->stackUnder(ui_vp_player_char); @@ -2723,7 +2723,7 @@ void Courtroom::do_effect(QString& fx_name, QString& fx_sound, QString& p_char, effect_y = ui_viewport->y(); } // This effect respects the character offset settings - if (ao_app->get_effect_property(fx_name, p_char, "respect_offset") == "true") { + if (ao_app->get_effect_property(fx_path, p_char, "respect_offset") == "true") { QStringList self_offsets = m_chatmessage[SELF_OFFSET].split("&"); int self_offset = self_offsets[0].toInt(); int self_offset_v; From 9261283f018adce3d827264ac764e426026a885c Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 27 Mar 2022 17:46:03 +0300 Subject: [PATCH 08/18] Remove "effect_done" due to it overwriting the AOLayers behavior Add "loop" effect property so you set up in the ini if the effect should loop rather than it using the file's loop settings Add "max_duration" effect property Add "cull" effect property which decides whether to clear the effect or not when it's done (if loop is false) --- include/courtroom.h | 1 - src/courtroom.cpp | 27 ++++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index 5c6275c2f..60863d3f2 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -806,7 +806,6 @@ class Courtroom : public QMainWindow { void regenerate_ic_chatlog(); public slots: void objection_done(); - void effect_done(); void preanim_done(); void do_screenshake(); void do_flash(); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index e77fd2a66..b0b5492ab 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -406,8 +406,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(keepalive_timer, &QTimer::timeout, this, &Courtroom::ping_server); connect(ui_vp_objection, &SplashLayer::done, this, &Courtroom::objection_done); - connect(ui_vp_effect, &EffectLayer::done, this, &Courtroom::effect_done); - connect(ui_vp_wtce, &SplashLayer::done, this, &Courtroom::effect_done); connect(ui_vp_player_char, &CharLayer::done, this, &Courtroom::preanim_done); connect(ui_vp_player_char, &CharLayer::shake, this, &Courtroom::do_screenshake); connect(ui_vp_player_char, &CharLayer::flash, this, &Courtroom::do_flash); @@ -2413,12 +2411,6 @@ bool Courtroom::handle_objection() return false; } -void Courtroom::effect_done() -{ - ui_vp_effect->stop(); - ui_vp_wtce->stop(); -} - void Courtroom::display_character() { // Stop all previously playing animations, effects etc. @@ -2695,6 +2687,18 @@ void Courtroom::do_effect(QString& fx_path, QString& fx_sound, QString& p_char, false); // The effects themselves dictate whether or not they're looping. // Static effects will linger. + bool looping = + ao_app->get_effect_property(fx_path, p_char, "loop") + .startsWith("true"); + + int max_duration = + ao_app->get_effect_property(fx_path, p_char, "max_duration") + .toInt(); + + bool cull = + ao_app->get_effect_property(fx_path, p_char, "cull") + .startsWith("true"); + // Possible values: "chat", "character", "behind" QString layer = ao_app->get_effect_property(fx_path, p_char, "layer").toLower(); if (layer == "behind"){ @@ -2741,9 +2745,10 @@ void Courtroom::do_effect(QString& fx_path, QString& fx_sound, QString& p_char, } ui_vp_effect->move(effect_x, effect_y); - ui_vp_effect->set_static_duration(0); - ui_vp_effect->set_max_duration(0); - ui_vp_effect->load_image(effect, true); + ui_vp_effect->set_static_duration(max_duration); + ui_vp_effect->set_max_duration(max_duration); + ui_vp_effect->load_image(effect, looping); + ui_vp_effect->set_cull_image(cull); } void Courtroom::play_char_sfx(QString sfx_name) From 0d9fb00b6c86dcd0d444b08cc93191f90d5c46bd Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 27 Mar 2022 22:09:03 +0300 Subject: [PATCH 09/18] Fix effects not allowed to have underscores (_) in them without breaking --- src/text_file_functions.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index e3a285d45..d0d1ccb6c 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -855,14 +855,35 @@ QStringList AOApplication::get_effects(QString p_char) QString p_misc_path = get_asset("effects.ini", current_theme, get_subtheme(), default_theme, p_misc); QStringList effects; + // This is horrible and due for a rethink. + QStringList test = { + "cull", + "layer", + "loop", + "max_duration", + "respect_flip", + "respect_offset", + "scaling", + "sticky", + "stretch", + }; + QStringList lines = read_file(p_path).split("\n"); // 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"); } foreach (QString effect, lines) { - effect = effect.split("=")[0].trimmed().split("_")[0]; - if (!effect.isEmpty() && !effects.contains(effect)) + effect = effect.split("=")[0].trimmed(); + QStringList effect_args = effect.split("_"); + bool is_arg = false; + foreach (QString arg, test) { + if (effect.endsWith(arg)) { + is_arg = true; + break; + } + } + if (!is_arg && !effect.isEmpty() && !effects.contains(effect)) effects.append(effect); } From c36c02b29d9b1c5a9304178e0b6d9382c06f3367 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 27 Mar 2022 23:19:56 +0300 Subject: [PATCH 10/18] Change the way effects.ini looks and is parsed to be more sane and doable. However, since order may or may not matter, you can optionally include index:name and it orders it properly. --- src/courtroom.cpp | 10 ++++++- src/text_file_functions.cpp | 54 +++++++++---------------------------- 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index b0b5492ab..36e43fe5e 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -4638,7 +4638,15 @@ void Courtroom::set_effects_dropdown() ui_effects_dropdown->hide(); return; } - QStringList effectslist = ao_app->get_effects(current_char); + QStringList effectslist; + QStringList char_effects = ao_app->get_effects(current_char); + for (int i = 0; i < char_effects.size(); ++i) { + QString effect = char_effects[i]; + if (effect.contains(":")) { + effect = effect.section(':', 1); + } + effectslist.append(effect); + } if (effectslist.size() <= 0) { ui_effects_dropdown->hide(); diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index d0d1ccb6c..571d6ea24 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -853,40 +853,18 @@ QStringList AOApplication::get_effects(QString p_char) 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.ini", current_theme, get_subtheme(), default_theme, p_misc); - QStringList effects; - - // This is horrible and due for a rethink. - QStringList test = { - "cull", - "layer", - "loop", - "max_duration", - "respect_flip", - "respect_offset", - "scaling", - "sticky", - "stretch", - }; - - QStringList lines = read_file(p_path).split("\n"); - // 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"); + QSettings effects_config = QSettings(p_path, QSettings::IniFormat); + effects_config.setIniCodec("UTF-8"); + QStringList effects = effects_config.childGroups(); + std::sort(effects.begin(), effects.end(), [] (const QString &a, const QString &b) {return a.split(":")[0].toInt() < b.split(":")[0].toInt();}); + if (p_path != p_misc_path) { + // If misc path is different from default path, stack the new miscs on top of the defaults + QSettings effects_config_misc = QSettings(p_misc_path, QSettings::IniFormat); + effects_config_misc.setIniCodec("UTF-8"); + QStringList misc_effects = effects_config_misc.childGroups(); + std::sort(misc_effects.begin(), misc_effects.end(), [] (const QString &a, const QString &b) {return a.split(":")[0].toInt() < b.split(":")[0].toInt();}); + effects += misc_effects; } - foreach (QString effect, lines) { - effect = effect.split("=")[0].trimmed(); - QStringList effect_args = effect.split("_"); - bool is_arg = false; - foreach (QString arg, test) { - if (effect.endsWith(arg)) { - is_arg = true; - break; - } - } - if (!is_arg && !effect.isEmpty() && !effects.contains(effect)) - effects.append(effect); - } - return effects; } @@ -910,15 +888,9 @@ QString AOApplication::get_effect(QString effect, QString p_char, QString AOApplication::get_effect_property(QString fx_name, QString p_char, QString p_property) { - QString f_property; - if (p_property == "sound") - f_property = fx_name; - else - f_property = fx_name + "_" + p_property; - - QString f_result = get_config_value(f_property, "effects.ini", current_theme, get_subtheme(), default_theme, read_char_ini(p_char, "effects", "Options")); + QString f_result = get_config_value(fx_name + "/" + p_property, "effects.ini", current_theme, get_subtheme(), default_theme, read_char_ini(p_char, "effects", "Options")); if (f_result == "") - f_result = get_config_value(f_property, "effects/effects.ini", current_theme, get_subtheme(), default_theme, ""); + f_result = get_config_value(fx_name + "/" + p_property, "effects/effects.ini", current_theme, get_subtheme(), default_theme, ""); if (fx_name == "realization" && p_property == "sound") { f_result = get_custom_realization(p_char); } From 978413aa301251838efa6e8aeff89cdb4f2bd815 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 27 Mar 2022 23:33:10 +0300 Subject: [PATCH 11/18] Appeal to clang --- src/courtroom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 36e43fe5e..f6b406e7b 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -4648,7 +4648,7 @@ void Courtroom::set_effects_dropdown() effectslist.append(effect); } - if (effectslist.size() <= 0) { + if (effectslist.empty()) { ui_effects_dropdown->hide(); return; } From c539525799182ea2ac2279eed5639849368f9a97 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sun, 27 Mar 2022 23:46:23 +0300 Subject: [PATCH 12/18] Fix a dumb way I created QSettings in get_effects --- src/text_file_functions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index 571d6ea24..36f9b3f83 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -853,13 +853,13 @@ QStringList AOApplication::get_effects(QString p_char) 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.ini", current_theme, get_subtheme(), default_theme, p_misc); - QSettings effects_config = QSettings(p_path, QSettings::IniFormat); + QSettings effects_config(p_path, QSettings::IniFormat); effects_config.setIniCodec("UTF-8"); QStringList effects = effects_config.childGroups(); std::sort(effects.begin(), effects.end(), [] (const QString &a, const QString &b) {return a.split(":")[0].toInt() < b.split(":")[0].toInt();}); if (p_path != p_misc_path) { // If misc path is different from default path, stack the new miscs on top of the defaults - QSettings effects_config_misc = QSettings(p_misc_path, QSettings::IniFormat); + QSettings effects_config_misc(p_misc_path, QSettings::IniFormat); effects_config_misc.setIniCodec("UTF-8"); QStringList misc_effects = effects_config_misc.childGroups(); std::sort(misc_effects.begin(), misc_effects.end(), [] (const QString &a, const QString &b) {return a.split(":")[0].toInt() < b.split(":")[0].toInt();}); From c27646267da25e3b2aeaeb15e11061ce0c2734e0 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Mon, 28 Mar 2022 00:13:04 +0300 Subject: [PATCH 13/18] Fix effect properties being broken due to optional index --- src/text_file_functions.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index 36f9b3f83..f30cd95db 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -888,9 +888,30 @@ QString AOApplication::get_effect(QString effect, QString p_char, QString AOApplication::get_effect_property(QString fx_name, QString p_char, QString p_property) { - QString f_result = get_config_value(fx_name + "/" + p_property, "effects.ini", current_theme, get_subtheme(), default_theme, read_char_ini(p_char, "effects", "Options")); - if (f_result == "") - f_result = get_config_value(fx_name + "/" + p_property, "effects/effects.ini", current_theme, get_subtheme(), default_theme, ""); + const auto paths = get_asset_paths("effects.ini", current_theme, get_subtheme(), default_theme, read_char_ini(p_char, "effects", "Options")); + QString path; + QString f_result; + for (const VPath &p : paths) { + path = get_real_path(p); + if (!path.isEmpty()) { + QSettings settings(path, QSettings::IniFormat); + settings.setIniCodec("UTF-8"); + QStringList char_effects = settings.childGroups(); + for (int i = 0; i < char_effects.size(); ++i) { + QString effect = char_effects[i]; + if (effect.contains(":")) { + effect = effect.section(':', 1); + } + if (effect.toLower() == fx_name.toLower()) { + f_result = settings.value(char_effects[i] + "/" + p_property).toString(); + if (!f_result.isEmpty()) { + // Only break the loop if we get a non-empty result, continue the search otherwise + break; + } + } + } + } + } if (fx_name == "realization" && p_property == "sound") { f_result = get_custom_realization(p_char); } From f036f315347dbc5627fb169c1e2ed0d602dfe6f6 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Mon, 28 Mar 2022 01:37:26 +0300 Subject: [PATCH 14/18] Fix get_effect_property not getting the current theme properties if a misc theme exists --- src/text_file_functions.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index f30cd95db..a9365d59d 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -888,10 +888,11 @@ QString AOApplication::get_effect(QString effect, QString p_char, QString AOApplication::get_effect_property(QString fx_name, QString p_char, QString p_property) { - const auto paths = get_asset_paths("effects.ini", current_theme, get_subtheme(), default_theme, read_char_ini(p_char, "effects", "Options")); + const auto paths = get_asset_paths("effects/effects.ini", current_theme, get_subtheme(), default_theme, ""); + const auto misc_paths = get_asset_paths("effects.ini", current_theme, get_subtheme(), default_theme, read_char_ini(p_char, "effects", "Options")); QString path; QString f_result; - for (const VPath &p : paths) { + for (const VPath &p : paths + misc_paths) { path = get_real_path(p); if (!path.isEmpty()) { QSettings settings(path, QSettings::IniFormat); From 4f1ebe6a7bcc8ec0cedd2e2b05545b32a1bb166a Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Mon, 28 Mar 2022 21:49:03 +0300 Subject: [PATCH 15/18] If sound list has a sound effect selected, if pre is not checked, don't play effect sound and prefer the sfx we chose instead. --- src/courtroom.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index f6b406e7b..c06a2ae25 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2070,6 +2070,12 @@ void Courtroom::on_chat_return_pressed() ao_app->get_effect_property(effect, current_char, "sound"); QString p_effect = ao_app->read_char_ini(current_char, "effects", "Options"); + + // Don't overlap the two sfx + if (!ui_pre->isChecked() && (!custom_sfx.isEmpty() || ui_sfx_dropdown->currentIndex() == 1)) { + fx_sound = "0"; + } + packet_contents.append(effect + "|" + p_effect + "|" + fx_sound); if (!ao_app->is_stickyeffects_enabled() && !ao_app->get_effect_property(effect, current_char, "sticky").startsWith("true")) { ui_effects_dropdown->blockSignals(true); From dab16a6e75bd4a09a88e3731185f7850f3fca402 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Wed, 30 Mar 2022 02:43:13 +0300 Subject: [PATCH 16/18] Fix \f not using the theme's realization effect --- include/courtroom.h | 4 ++-- src/courtroom.cpp | 14 +++----------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index 60863d3f2..774c83710 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -809,8 +809,8 @@ public slots: void preanim_done(); void do_screenshake(); void do_flash(); - void do_effect(QString& fx_path, QString& fx_sound, QString& p_char, - QString& p_folder); + void do_effect(QString fx_path, QString fx_sound, QString p_char, + QString p_folder); void play_char_sfx(QString sfx_name); void mod_called(QString p_ip); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 7c69382f5..3785f5511 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2643,19 +2643,11 @@ void Courtroom::do_flash() QString f_char = m_chatmessage[CHAR_NAME]; QString f_custom_theme = ao_app->get_chat(f_char); - ui_vp_effect->stretch = true; - ui_vp_effect->setParent(this); - ui_vp_effect->stackUnder(ui_vp_objection); // go above the chatbox - ui_vp_effect->move(ui_viewport->x(), ui_viewport->y()); - - ui_vp_effect->set_static_duration(60); - ui_vp_effect->set_max_duration(60); - ui_vp_effect->load_image( - ao_app->get_effect("realization", f_char, f_custom_theme), false); + do_effect("realization", "", f_char, f_custom_theme); } -void Courtroom::do_effect(QString& fx_path, QString& fx_sound, QString& p_char, - QString& p_folder) +void Courtroom::do_effect(QString fx_path, QString fx_sound, QString p_char, + QString p_folder) { if (fx_path == "") { return; From 12d105ded22606dc74c10012c76fc768b00c261c Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Sun, 19 Jun 2022 23:40:56 +0200 Subject: [PATCH 17/18] Add missing curly bracket --- src/courtroom.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 712b92e35..d2f7a016e 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -3851,6 +3851,7 @@ void Courtroom::set_self_offset(const QString& p_list) { } const int percent = 100; ui_vp_player_char->move(ui_viewport->width() * self_offset / percent, ui_viewport->height() * self_offset_v / percent); + } } void Courtroom::set_ip_list(QString p_list) From 5d1132fe80f7dc33e53adcb8ca2a94b0cf7eb1df Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Mon, 20 Jun 2022 00:08:10 +0200 Subject: [PATCH 18/18] Yolo --- src/courtroom.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 4f2f4ac2b..3492582b9 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -3843,14 +3843,8 @@ void Courtroom::set_self_offset(const QString& p_list) { else { self_offset_v = self_offsets[1].toInt(); ui_vp_player_char->move_and_center(ui_viewport->width() * self_offset / 100, ui_viewport->height() * self_offset_v / 100); - - //If an effect is ignoring the users offset, we force it to the default position of the viewport. - if (ao_app->get_effect_property(play_effect[0], current_char, "ignore_offset") == "true") { - ui_vp_effect->move(ui_viewport->x(), ui_viewport->y()); - return; - } - const int percent = 100; - ui_vp_player_char->move(ui_viewport->width() * self_offset / percent, ui_viewport->height() * self_offset_v / percent); + const int percent = 100; + ui_vp_player_char->move(ui_viewport->width() * self_offset / percent, ui_viewport->height() * self_offset_v / percent); } }