aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrickyLeifa <date.epoch@gmail.com>2024-06-03 18:11:17 +0200
committerTrickyLeifa <date.epoch@gmail.com>2024-06-03 18:11:17 +0200
commita714bacd1aba3e54bf485580d112b42385788c50 (patch)
tree252ce858a688d2025fcdba92036bd6a935a5608f
parent5af9dce21481e1d402df701b91593ccde4049c4b (diff)
Added screen slide timer
* Added screen slide timer * Added so that the animation becomes interruptible.
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/courtroom.cpp27
-rw-r--r--src/courtroom.h12
-rw-r--r--src/screenslidetimer.cpp86
-rw-r--r--src/screenslidetimer.h46
5 files changed, 149 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b1f25290..6fabdcff 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -102,6 +102,7 @@ add_executable(Attorney_Online
src/widgets/server_editor_dialog.cpp
src/widgets/server_editor_dialog.h
data.qrc
+ src/screenslidetimer.h src/screenslidetimer.cpp
)
set_target_properties(Attorney_Online PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index c9c22f18..c2c34219 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -111,6 +111,10 @@ Courtroom::Courtroom(AOApplication *p_ao_app)
ui_vp_objection->setAttribute(Qt::WA_TransparentForMouseEvents);
ui_vp_objection->setObjectName("ui_vp_objection");
+ m_screenshake_anim_group = new QParallelAnimationGroup(this);
+
+ m_screenslide_timer = new kal::ScreenSlideTimer(this);
+
ui_ic_chatlog = new QTextEdit(this);
ui_ic_chatlog->setReadOnly(true);
ui_ic_chatlog->setObjectName("ui_ic_chatlog");
@@ -514,7 +518,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app)
connect(ui_vp_evidence_display, &AOEvidenceDisplay::show_evidence_details, this, &Courtroom::show_evidence);
- connect(transition_animation_group, &QParallelAnimationGroup::finished, this, &Courtroom::finish_transition);
+ connect(m_screenslide_timer, &kal::ScreenSlideTimer::finished, this, &Courtroom::post_transition_cleanup);
set_widgets();
@@ -2502,6 +2506,7 @@ void Courtroom::unpack_chatmessage(QStringList p_contents)
anim_state = 0;
evidence_presented = false;
ui_vp_objection->stopPlayback();
+ m_screenslide_timer->stop();
chat_tick_timer->stop();
ui_vp_evidence_display->reset();
// This chat msg is not objection so we're not waiting on the objection animation to finish to display the character.
@@ -2947,8 +2952,8 @@ void Courtroom::do_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 with the chat text being detached from the chat box!
- screenshake_animation_group->setCurrentTime(screenshake_animation_group->duration());
- screenshake_animation_group->clear();
+ m_screenshake_anim_group->setCurrentTime(m_screenshake_anim_group->duration());
+ m_screenshake_anim_group->clear();
const QList<QWidget *> &affected_list = {ui_vp_background, ui_vp_player_char, ui_vp_sideplayer_char, ui_vp_chatbox};
@@ -2975,10 +2980,10 @@ void Courtroom::do_screenshake()
}
screenshake_animation->setEndValue(pos_default);
screenshake_animation->setEasingCurve(QEasingCurve::Linear);
- screenshake_animation_group->addAnimation(screenshake_animation);
+ m_screenshake_anim_group->addAnimation(screenshake_animation);
}
- screenshake_animation_group->start();
+ m_screenshake_anim_group->start();
}
void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newPosId)
@@ -3020,7 +3025,7 @@ void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newP
ui_vp_dummy_char->setStyleSheet("background-color:rgba(255, 0, 0, 128);");
ui_vp_sidedummy_char->setStyleSheet("background-color:rgba(0, 255, 0, 128);");
- qDebug() << "STARTING TRANSITION, CURRENT TIME:" << transition_animation_group->currentTime();
+ qDebug() << "STARTING TRANSITION";
#endif
set_scene(p_desk_mod.toInt(), oldPosId);
@@ -3039,7 +3044,7 @@ void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newP
transition_animation->setEasingCurve(QEasingCurve::InOutCubic);
transition_animation->setStartValue(QPoint(-scaled_old_pos.x(), 0));
transition_animation->setEndValue(QPoint(-scaled_new_pos.x(), 0));
- transition_animation_group->addAnimation(transition_animation);
+ m_screenslide_timer->addAnimation(transition_animation);
}
auto calculate_offset_and_setup_layer = [&, this](kal::CharacterAnimationLayer *layer, QPoint newPos, QString rawOffset) {
@@ -3110,13 +3115,7 @@ void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newP
ui_vp_sideplayer_char->hide();
}
- QTimer::singleShot(TRANSITION_BOOKEND_DELAY, transition_animation_group, SLOT(start()));
-}
-
-void Courtroom::finish_transition()
-{
- transition_animation_group->clear();
- QTimer::singleShot(TRANSITION_BOOKEND_DELAY, this, SLOT(post_transition_cleanup()));
+ m_screenslide_timer->start();
}
void Courtroom::post_transition_cleanup()
diff --git a/src/courtroom.h b/src/courtroom.h
index b3b34c6a..a01102ec 100644
--- a/src/courtroom.h
+++ b/src/courtroom.h
@@ -23,6 +23,7 @@
#include "file_functions.h"
#include "hardware_functions.h"
#include "lobby.h"
+#include "screenslidetimer.h"
#include "scrolltext.h"
#include "widgets/aooptionsdialog.h"
@@ -310,9 +311,9 @@ private:
int maximumMessages = 0;
- QParallelAnimationGroup *screenshake_animation_group = new QParallelAnimationGroup;
+ QParallelAnimationGroup *m_screenshake_anim_group;
- QParallelAnimationGroup *transition_animation_group = new QParallelAnimationGroup;
+ kal::ScreenSlideTimer *m_screenslide_timer;
bool next_character_is_not_special = false; // If true, write the
// next character as it is.
@@ -446,12 +447,6 @@ private:
QString m_chatmessage[MS_MAXIMUM];
QString m_previous_chatmessage[MS_MAXIMUM];
- /**
- * @brief The amount of time to wait at the start and end of slide
- * animations
- */
- static const int TRANSITION_BOOKEND_DELAY = 300;
-
QString additive_previous;
// char id, muted or not
@@ -983,6 +978,5 @@ private Q_SLOTS:
// After attempting to play a transition animation, clean up the viewport
// objects for everyone else and continue the IC processing callstack
- void finish_transition();
void post_transition_cleanup();
};
diff --git a/src/screenslidetimer.cpp b/src/screenslidetimer.cpp
new file mode 100644
index 00000000..2bfd0cd5
--- /dev/null
+++ b/src/screenslidetimer.cpp
@@ -0,0 +1,86 @@
+#include "screenslidetimer.h"
+
+#include <QDebug>
+
+namespace kal
+{
+ScreenSlideTimer::ScreenSlideTimer(QObject *parent)
+ : QObject(parent)
+{
+ m_pause = new QTimer(this);
+ m_pause->setInterval(TRANSITION_BOOKEND_DELAY);
+ m_pause->setSingleShot(true);
+
+ m_group = new QParallelAnimationGroup(this);
+
+ connect(m_pause, &QTimer::timeout, this, &ScreenSlideTimer::startNextState);
+ connect(m_group, &QParallelAnimationGroup::finished, this, &ScreenSlideTimer::startNextState);
+}
+
+ScreenSlideTimer::~ScreenSlideTimer()
+{
+ m_group->disconnect(this);
+ m_pause->disconnect(this);
+ stop();
+}
+
+void ScreenSlideTimer::addAnimation(QAbstractAnimation *animation)
+{
+ if (m_running)
+ {
+ qWarning() << "Cannot add animations while transition is in progress";
+ return;
+ }
+ m_group->addAnimation(animation);
+}
+
+void ScreenSlideTimer::start()
+{
+ if (m_running)
+ {
+ qWarning() << "Transition already in progress";
+ return;
+ }
+ m_running = true;
+ startNextState();
+}
+
+void ScreenSlideTimer::stop()
+{
+ if (m_running)
+ {
+ m_running = false;
+ m_state = NoTransition;
+ m_group->stop();
+ m_group->clear();
+ m_pause->stop();
+ }
+}
+
+void ScreenSlideTimer::startNextState()
+{
+ switch (m_state)
+ {
+ case NoTransition:
+ m_state = PreTransition;
+ Q_EMIT started();
+ m_pause->start();
+ return;
+
+ case PreTransition:
+ m_state = GroupTransition;
+ m_group->start();
+ break;
+
+ case GroupTransition:
+ m_state = PostTransition;
+ m_pause->start();
+ break;
+
+ case PostTransition:
+ stop();
+ Q_EMIT finished();
+ break;
+ }
+}
+} // namespace kal
diff --git a/src/screenslidetimer.h b/src/screenslidetimer.h
new file mode 100644
index 00000000..c2bf7a8d
--- /dev/null
+++ b/src/screenslidetimer.h
@@ -0,0 +1,46 @@
+#pragma once
+
+#include <QObject>
+#include <QParallelAnimationGroup>
+#include <QTimer>
+
+namespace kal
+{
+class ScreenSlideTimer : public QObject
+{
+ Q_OBJECT
+
+public:
+ static const int TRANSITION_BOOKEND_DELAY = 300;
+
+ explicit ScreenSlideTimer(QObject *parent = nullptr);
+ virtual ~ScreenSlideTimer();
+
+ void addAnimation(QAbstractAnimation *animation);
+
+public Q_SLOTS:
+ void start();
+ void stop();
+
+Q_SIGNALS:
+ void started();
+ void finished();
+
+private:
+ enum TransitionState
+ {
+ NoTransition,
+ PreTransition,
+ GroupTransition,
+ PostTransition,
+ };
+
+ bool m_running = false;
+ TransitionState m_state = NoTransition;
+ QParallelAnimationGroup *m_group;
+ QTimer *m_pause;
+
+private Q_SLOTS:
+ void startNextState();
+};
+} // namespace kal