From 61afbabfa49edb9bdf68685042d83fc8c3a27ae5 Mon Sep 17 00:00:00 2001 From: parax0 Date: Sun, 10 Apr 2016 07:54:49 -0600 Subject: [PATCH] Character editor UI improvements --- .../CharacterEditor/CCharacterEditor.cpp | 40 +++++++++++++++---- src/Editor/CharacterEditor/CCharacterEditor.h | 4 +- .../CharacterEditor/CCharacterEditor.ui | 2 +- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/Editor/CharacterEditor/CCharacterEditor.cpp b/src/Editor/CharacterEditor/CCharacterEditor.cpp index c74d82df..1df32897 100644 --- a/src/Editor/CharacterEditor/CCharacterEditor.cpp +++ b/src/Editor/CharacterEditor/CCharacterEditor.cpp @@ -9,6 +9,7 @@ CCharacterEditor::CCharacterEditor(QWidget *parent) , ui(new Ui::CCharacterEditor) , mpScene(new CScene()) , mpCharNode(new CCharacterNode(mpScene, -1)) + , mAnimTime(0.f) , mPlayAnim(true) , mLoopAnim(true) , mPlaybackSpeed(1.f) @@ -42,8 +43,8 @@ CCharacterEditor::CCharacterEditor(QWidget *parent) connect(mpAnimComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(SetActiveAnimation(int))); connect(ui->AnimSlider, SIGNAL(valueChanged(int)), this, SLOT(SetAnimTime(int))); - connect(ui->PlayPauseButton, SIGNAL(pressed()), this, SLOT(PlayPauseButtonPressed())); - connect(ui->LoopButton, SIGNAL(toggled(bool)), this, SLOT(LoopButtonToggled(bool))); + connect(ui->PlayPauseButton, SIGNAL(pressed()), this, SLOT(TogglePlay())); + connect(ui->LoopButton, SIGNAL(toggled(bool)), this, SLOT(ToggleLoop(bool))); connect(ui->AnimSpeedSpinBox, SIGNAL(valueChanged(double)), this, SLOT(AnimSpeedSpinBoxChanged(double))); } @@ -58,7 +59,9 @@ void CCharacterEditor::UpdateAnimTime() double DeltaTime = Time - mLastAnimUpdate; mLastAnimUpdate = Time; - if (mPlayAnim && !ui->AnimSlider->isSliderDown()) + CAnimation *pAnim = CurrentAnimation(); + + if (pAnim && mPlayAnim && !ui->AnimSlider->isSliderDown()) { mAnimTime += DeltaTime * mPlaybackSpeed; @@ -68,17 +71,27 @@ void CCharacterEditor::UpdateAnimTime() if (mAnimTime > AnimLength) { if (mLoopAnim) + { mAnimTime = fmodf(mAnimTime, AnimLength); + } else + { mAnimTime = AnimLength; + TogglePlay(); + } } if (mAnimTime < 0.f) { if (mLoopAnim) + { mAnimTime = AnimLength + fmodf(mAnimTime, AnimLength); + } else + { mAnimTime = 0.f; + TogglePlay(); + } } SetAnimTime(mAnimTime); @@ -191,19 +204,32 @@ void CCharacterEditor::SetAnimTime(float Time) CurKey = Math::Min((u32) (Time / pAnim->TickInterval()) + 1, NumKeys - 1); } - ui->FrameLabel->setText(QString("Frame %1 / %2").arg(CurKey).arg(NumKeys - 1)); + ui->FrameLabel->setText(QString("Frame %1 / %2 (%3s/%4s)").arg(CurKey).arg(NumKeys - 1).arg(mAnimTime, 0, 'f', 3).arg(pAnim ? pAnim->Duration() : 0.f, 0, 'f', 3)); } -void CCharacterEditor::PlayPauseButtonPressed() +void CCharacterEditor::TogglePlay() { mPlayAnim = !mPlayAnim; QString NewText = (mPlayAnim ? "Pause" : "Play"); ui->PlayPauseButton->setText(NewText); + + CAnimation *pAnim = CurrentAnimation(); + + if (pAnim && mPlayAnim) + { + if (mPlaybackSpeed < 0.f && mAnimTime == 0.f) + SetAnimTime(pAnim->Duration()); + if (mPlaybackSpeed >= 0.f && mAnimTime == pAnim->Duration()) + SetAnimTime(0.f); + } } -void CCharacterEditor::LoopButtonToggled(bool Checked) +void CCharacterEditor::ToggleLoop(bool Loop) { - mLoopAnim = Checked; + mLoopAnim = Loop; + + if (sender() != ui->LoopButton) + ui->LoopButton->setChecked(Loop); } void CCharacterEditor::AnimSpeedSpinBoxChanged(double NewVal) diff --git a/src/Editor/CharacterEditor/CCharacterEditor.h b/src/Editor/CharacterEditor/CCharacterEditor.h index ce38ddeb..6e1fe883 100644 --- a/src/Editor/CharacterEditor/CCharacterEditor.h +++ b/src/Editor/CharacterEditor/CCharacterEditor.h @@ -51,8 +51,8 @@ public slots: void SetAnimTime(int Time); void SetAnimTime(float Time); - void PlayPauseButtonPressed(); - void LoopButtonToggled(bool Checked); + void TogglePlay(); + void ToggleLoop(bool Loop); void AnimSpeedSpinBoxChanged(double NewVal); }; diff --git a/src/Editor/CharacterEditor/CCharacterEditor.ui b/src/Editor/CharacterEditor/CCharacterEditor.ui index 8cc6875f..750b7712 100644 --- a/src/Editor/CharacterEditor/CCharacterEditor.ui +++ b/src/Editor/CharacterEditor/CCharacterEditor.ui @@ -113,7 +113,7 @@ - Frame 0 / 0 + Frame 0 / 0 (0.000s/0.000s) Qt::PlainText