Added screen slide timer
* Added screen slide timer * Added so that the animation becomes interruptible.
This commit is contained in:
parent
5af9dce214
commit
a714bacd1a
@ -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")
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
};
|
||||
|
86
src/screenslidetimer.cpp
Normal file
86
src/screenslidetimer.cpp
Normal file
@ -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
|
46
src/screenslidetimer.h
Normal file
46
src/screenslidetimer.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user