aboutsummaryrefslogtreecommitdiff
path: root/src/courtroom.cpp
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2019-09-15 17:44:02 +0300
committerCrystalwarrior <varsash@gmail.com>2019-09-15 17:44:02 +0300
commita2f9df4042585ab0849b54e2bb0b9699f9064aed (patch)
treee2ae5b98111959c75232ab24b9f909b742658e9c /src/courtroom.cpp
parent4db114007456f12c77f002cac4e26cd3f6917638 (diff)
Finally implement frame-specific effects such as screenshake, realization flash, sound effects, etc.
Fix screenshake animation modifying the default positions of shook elements Fix aomovie sometimes not playing the last frame and causing lagspikes due to the delay() method
Diffstat (limited to 'src/courtroom.cpp')
-rw-r--r--src/courtroom.cpp114
1 files changed, 75 insertions, 39 deletions
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index 47e3a0e7..30921d84 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -265,6 +265,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
connect(ui_vp_objection, SIGNAL(done()), this, SLOT(objection_done()));
connect(ui_vp_player_char, SIGNAL(done()), this, SLOT(preanim_done()));
+ connect(ui_vp_player_char, SIGNAL(shake()), this, SLOT(do_screenshake()));
+ connect(ui_vp_player_char, SIGNAL(flash()), this, SLOT(do_flash()));
+ connect(ui_vp_player_char, SIGNAL(play_sfx(QString)), this, SLOT(play_char_sfx(QString)));
connect(text_delay_timer, SIGNAL(timeout()), this, SLOT(start_chat_ticking()));
connect(sfx_delay_timer, SIGNAL(timeout()), this, SLOT(play_sfx()));
@@ -1655,47 +1658,58 @@ void Courtroom::handle_chatmessage_2()
void Courtroom::do_screenshake()
{
-//Code below causes segfault, do not uncomment unless you know what you're doing.
-// if (screenshake_animation_group != nullptr && screenshake_animation_group->state() == QAbstractAnimation::Running)
-// screenshake_animation_group->setCurrentTime(screenshake_animation_group->duration()); //Force it to finish and delete itself
-
- screenshake_animation_group = new QParallelAnimationGroup;
-
- QList<QWidget *> affected_list = {
- ui_vp_background,
- ui_vp_player_char,
- ui_vp_sideplayer_char,
- ui_vp_chatbox
- };
-
- int i = 0;
- //I would prefer if this was its own "shake" function to be honest.
- foreach (QWidget* ui_element, affected_list)
+ //This way, the animation is reset in such a way that last played screenshake would return to its "final frame" properly.
+ //This properly resets all UI elements without having to bother keeping track of "origin" positions.
+ //Works great wit the chat text being detached from the chat box!
+ screenshake_animation_group->setCurrentTime(screenshake_animation_group->duration());
+ screenshake_animation_group->clear();
+
+ QList<QWidget *> affected_list = {
+ ui_vp_background,
+ ui_vp_player_char,
+ ui_vp_sideplayer_char,
+ ui_vp_chatbox
+ };
+
+ int i = 0;
+ //I would prefer if this was its own "shake" function to be honest.
+ foreach (QWidget* ui_element, affected_list)
+ {
+ qDebug() << ++i;
+ QPropertyAnimation *screenshake_animation = new QPropertyAnimation(ui_element, "pos", this);
+ QPoint pos_default = QPoint(ui_element->x(), ui_element->y());
+
+ int duration = 300; //How long does the screenshake last
+ int frequency = 20; //How often in ms is there a "jolt" frame
+ int maxframes = duration/frequency;
+ int max_x = 7; //Max deviation from origin on x axis
+ int max_y = 7; //Max deviation from origin on y axis
+ screenshake_animation->setDuration(duration);
+ for (int frame=0; frame < maxframes; frame++)
{
- qDebug() << ++i;
- QPropertyAnimation *screenshake_animation = new QPropertyAnimation(ui_element, "pos", this);
- QPoint pos_default = QPoint(ui_element->x(), ui_element->y());
-
- int duration = 300; //How long does the screenshake last
- int frequency = 20; //How often in ms is there a "jolt" frame
- int maxframes = duration/frequency;
- int max_x = 7; //Max deviation from origin on x axis
- int max_y = 7; //Max deviation from origin on y axis
- screenshake_animation->setDuration(duration);
- for (int frame=0; frame < maxframes; frame++)
- {
- double fraction = double(frame*frequency)/duration;
- quint32 rng = QRandomGenerator::global()->generate();
- int rand_x = int(rng) % max_x;
- int rand_y = int(rng+100) % max_y;
- screenshake_animation->setKeyValueAt(fraction, QPoint(pos_default.x() + rand_x, pos_default.y() + rand_y));
- }
- screenshake_animation->setEndValue(pos_default);
- screenshake_animation->setEasingCurve(QEasingCurve::Linear);
- screenshake_animation_group->addAnimation(screenshake_animation);
+ double fraction = double(frame*frequency)/duration;
+ quint32 rng = QRandomGenerator::global()->generate();
+ int rand_x = int(rng) % max_x;
+ int rand_y = int(rng+100) % max_y;
+ screenshake_animation->setKeyValueAt(fraction, QPoint(pos_default.x() + rand_x, pos_default.y() + rand_y));
}
+ screenshake_animation->setEndValue(pos_default);
+ screenshake_animation->setEasingCurve(QEasingCurve::Linear);
+ screenshake_animation_group->addAnimation(screenshake_animation);
+ }
- screenshake_animation_group->start(QAbstractAnimation::DeletionPolicy::DeleteWhenStopped);
+ screenshake_animation_group->start();
+}
+
+void Courtroom::do_flash()
+{
+ ui_vp_realization->play("realizationflash", "", "", 60);
+}
+
+void Courtroom::play_char_sfx(QString sfx_name)
+{
+ sfx_player->play(ao_app->get_sfx_suffix(sfx_name));
+ sfx_player->set_looping(ao_app->get_sfx_looping(current_char, sfx_name)!="0");
}
void Courtroom::handle_chatmessage_3()
@@ -1829,6 +1843,16 @@ QString Courtroom::filter_ic_text(QString p_text)
p_text.remove(trick_check_pos,1);
}
+ else if (f_character == "$" and !ic_next_is_not_special)
+ {
+ p_text.remove(trick_check_pos,1);
+ }
+
+ else if (f_character == "@" and !ic_next_is_not_special)
+ {
+ p_text.remove(trick_check_pos,1);
+ }
+
// Orange inline colourisation.
else if (f_character == "|" and !ic_next_is_not_special)
{
@@ -2089,7 +2113,7 @@ void Courtroom::start_chat_ticking()
if (m_chatmessage[REALIZATION] == "1")
{
- ui_vp_realization->play("realizationflash", "", "", 60);
+ this->do_flash();
sfx_player->play(ao_app->get_custom_realization(m_chatmessage[CHAR_NAME]));
}
@@ -2208,6 +2232,18 @@ void Courtroom::chat_tick()
formatting_char = true;
}
+ else if (f_character == "@" and !next_character_is_not_special)
+ {
+ this->do_screenshake();
+ formatting_char = true;
+ }
+
+ else if (f_character == "$" and !next_character_is_not_special)
+ {
+ this->do_flash();
+ formatting_char = true;
+ }
+
// Orange inline colourisation.
else if (f_character == "|" and !next_character_is_not_special)
{