Commit 2a761ddc authored by Denis Kuplyakov's avatar Denis Kuplyakov
Browse files

Fixed many aspects about animation

1) I am using QTimer::setInterval, QTimer::setSingleShot
 and QTimer::start instead of static singleShot method to
 control user moves during animation.
2) Animation is sequental now
3) Added empty transition to not animate just placed white chip
parent 63125fe2
......@@ -24,6 +24,9 @@ KReversiView::KReversiView(KReversiGame* game, QWidget *parent) :
m_demoMode(false), m_showLastMove(false), m_showLegalMoves(false),
m_showLabels(false), m_maxDelay(0)
{
m_delayTimer.setSingleShot(true);
connect(&m_delayTimer, SIGNAL(timeout()), this, SLOT(slotOnDelay()));
qmlRegisterType<ColorScheme>("ColorScheme", 1, 0, "ColorScheme");
m_provider = new KgThemeProvider();
......@@ -111,33 +114,24 @@ KReversiView::~KReversiView()
void KReversiView::updateBoard()
{
KReversiPos lastmove = m_game ? m_game->getLastMove() : KReversiPos();
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++) {
int delay = 0;
if (lastmove.isValid()) {
delay = qMax(abs(i - lastmove.row), abs(j - lastmove.col));
delay = qMax(0, delay - 1);
}
QMetaObject::invokeMethod(m_qml_root, "setPreAnimationTicks",
Q_ARG(QVariant, i),
Q_ARG(QVariant, j),
Q_ARG(QVariant, delay));
Q_ARG(QVariant, 0));
}
m_maxDelay = 0;
if (m_game) {
PosList changed_chips = m_game->changedChips();
for (int i = 0; i < changed_chips.size(); i++) {
int delay = 0;
if (lastmove.isValid()) {
delay = qMax(abs(changed_chips[i].row - lastmove.row),
abs(changed_chips[i].col - lastmove.col));
delay = qMax(0, delay - 1);
}
m_maxDelay = qMax(m_maxDelay, delay);
for (int i = 1; i < changed_chips.size(); i++) { //i == 0 is new chip it don't need animation time
QMetaObject::invokeMethod(m_qml_root, "setPreAnimationTicks",
Q_ARG(QVariant, changed_chips[i].row),
Q_ARG(QVariant, changed_chips[i].col),
Q_ARG(QVariant, i - 1));
}
m_maxDelay = qMax(0, (int)(changed_chips.size()) - 2);
}
for (int i = 0; i < 8; i++)
......@@ -257,6 +251,9 @@ void KReversiView::onPlayerMove(int row, int col)
// user moves not allowed in demo mode
if (m_demoMode)
return;
if (m_delayTimer.isActive())
return;
if (m_game->isComputersTurn())
return;
......@@ -269,7 +266,8 @@ void KReversiView::slotGameMoveFinished()
m_hint = KReversiPos();
updateBoard();
emit moveFinished();
m_delayTimer.singleShot(m_delay * (m_maxDelay + 2), this, SLOT(slotOnDelay()));
m_delayTimer.setInterval(m_delay * (m_maxDelay + 1));
m_delayTimer.start();
}
void KReversiView::slotGameOver()
......
......@@ -51,12 +51,12 @@ Item {
states: [
State {
name: "Black"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: 1
......@@ -70,12 +70,12 @@ Item {
State {
name: "Black_blinking"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: 1
......@@ -89,12 +89,12 @@ Item {
State {
name: "White"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: framesCount
......@@ -108,7 +108,7 @@ Item {
State {
name: "White_blinking"
PropertyChanges {
target: chipImage
visible: true
......@@ -138,4 +138,17 @@ Item {
}
}
}
transitions: [
Transition {
from: ""
to: "*"
reversible: false
NumberAnimation {
property: "currentFrame"
duration: 0
}
}
]
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment