Added penalty effects (#786)

Themes can be configured to play an SFX and/or effect when the HP bar increases or decreases. Effects can be any defined effect, or a built-in effect such as "screenshake" or "flash".

Resolves AttorneyOnline/AO2-Client#743
This commit is contained in:
Leifa♥ 2022-06-24 01:58:17 +02:00 committed by GitHub
parent 0be8d0f5ae
commit 7b4b297a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View File

@ -361,6 +361,10 @@ public:
// Returns the color from the misc folder. // Returns the color from the misc folder.
QColor get_chat_color(QString p_identifier, QString p_chat); QColor get_chat_color(QString p_identifier, QString p_chat);
// Returns the value with p_identifier from penalty/penalty.ini in the current
// theme path
QString get_penalty_value(QString p_identifier);
// Returns the sfx with p_identifier from courtroom_sounds.ini in the current theme path // 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=""); QString get_court_sfx(QString p_identifier, QString p_misc="");

View File

@ -3994,14 +3994,45 @@ void Courtroom::set_hp_bar(int p_bar, int p_state)
if (p_state < 0 || p_state > 10) if (p_state < 0 || p_state > 10)
return; return;
int prev_state = p_state;
if (p_bar == 1) { if (p_bar == 1) {
ui_defense_bar->set_image("defensebar" + QString::number(p_state)); ui_defense_bar->set_image("defensebar" + QString::number(p_state));
prev_state = defense_bar_state;
defense_bar_state = p_state; defense_bar_state = p_state;
} }
else if (p_bar == 2) { else if (p_bar == 2) {
ui_prosecution_bar->set_image("prosecutionbar" + QString::number(p_state)); ui_prosecution_bar->set_image("prosecutionbar" + QString::number(p_state));
prev_state = prosecution_bar_state;
prosecution_bar_state = p_state; prosecution_bar_state = p_state;
} }
QString sfx_name;
QString effect_name;
if (p_state > prev_state) {
sfx_name = ao_app->get_penalty_value("hp_increased_sfx");
effect_name = ao_app->get_penalty_value("hp_increased_effect").toLower();
}
else if (p_state < prev_state) {
sfx_name = ao_app->get_penalty_value("hp_decreased_sfx");
effect_name = ao_app->get_penalty_value("hp_decreased_effect").toLower();
}
else {
return;
}
if (effect_name == "screenshake") {
do_screenshake();
}
else if (effect_name == "flash") {
do_flash();
}
else {
do_effect(effect_name, "", "", "");
}
if (!sfx_name.isEmpty()) {
sfx_player->play(sfx_name);
}
} }
void Courtroom::show_judge_controls(bool visible) void Courtroom::show_judge_controls(bool visible)

View File

@ -521,6 +521,13 @@ QColor AOApplication::get_chat_color(QString p_identifier, QString p_chat)
return return_color; return return_color;
} }
QString AOApplication::get_penalty_value(QString p_identifier)
{
return get_config_value(p_identifier, "penalty/penalty.ini", current_theme,
get_subtheme(), default_theme, "");
}
QString AOApplication::get_court_sfx(QString p_identifier, QString p_misc) QString AOApplication::get_court_sfx(QString p_identifier, QString p_misc)
{ {
QString value = get_config_value(p_identifier, "courtroom_sounds.ini", current_theme, get_subtheme(), default_theme, p_misc); QString value = get_config_value(p_identifier, "courtroom_sounds.ini", current_theme, get_subtheme(), default_theme, p_misc);