Commit 140a9b9d authored by Denis Kuplyakov's avatar Denis Kuplyakov

Fixed animation

I've made the same fixes as for deniskup/animationfix branch
parent 7ce7d640
......@@ -93,9 +93,11 @@ void KReversiGame::makeMove(const KReversiMove &move)
m_lastPlayer = m_curPlayer;
m_curPlayer = NoColor; // both players wait for animations
m_delayTimer.singleShot(m_delay, this, SLOT(onDelayTimer()));
turnChips(move);
m_delayTimer.singleShot(m_delay * (qMax(1, m_changedChips.count() - 1)), this, SLOT(onDelayTimer()));
emit boardChanged();
}
void KReversiGame::startNextTurn()
......@@ -195,8 +197,6 @@ void KReversiGame::turnChips(const KReversiMove &move)
}
m_undoStack.push(m_changedChips);
emit boardChanged();
}
bool KReversiGame::isMovePossible(const KReversiMove& move) const
......@@ -273,6 +273,16 @@ void KReversiGame::setDelay(int delay)
m_delay = delay;
}
int KReversiGame::getPreAnimationDelay(KReversiPos pos) const
{
for (int i = 1; i < m_changedChips.size(); i++) {
if (m_changedChips[i].row == pos.row && m_changedChips[i].col == pos.col) {
return (i - 1) * m_delay;
}
}
return 0;
}
MoveList KReversiGame::getHistory() const
{
MoveList l;
......
......@@ -114,7 +114,10 @@ public:
* Sets animation times from players to @p delay milliseconds
*/
void setDelay(int delay);
/**
* Get wait time for given cell before animating. Used for sequental turning of chips
*/
int getPreAnimationDelay(KReversiPos pos) const;
/**
* @return History of moves as MoveList
*/
......
......@@ -118,6 +118,15 @@ KReversiView::~KReversiView()
void KReversiView::updateBoard()
{
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
QMetaObject::invokeMethod(m_qml_root, "setPreAnimationTime",
Q_ARG(QVariant, i),
Q_ARG(QVariant, j),
Q_ARG(QVariant, m_game ? m_game->getPreAnimationDelay(KReversiPos(i, j)) : 0));
}
}
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++) {
QString new_state = "";
......
......@@ -90,6 +90,16 @@ Item {
function setLastMove(row, column, value) {
cells.itemAt(row * Globals.COLUMN_COUNT + column).isLastMove = value
}
/**
* Sets time to wait before starting animation
* @param row row index of cell (starting from 0)
* @param column column index of cell (starting from 0)
* @param value time to wait
*/
function setPreAnimationTime(row, column, value) {
cells.itemAt(row * Globals.COLUMN_COUNT + column).chipPreAnimationTime = value
}
CanvasItem {
id: boardBackground
......
......@@ -49,6 +49,10 @@ Item {
* Duration of chip's turning animation
*/
property int chipAnimationTime: 25 * 12
/**
* How long to wait before start of animation
*/
property int chipPreAnimationTime: 0
/**
* Chips state:
* "Black" turns chip to black side
......@@ -79,6 +83,7 @@ Item {
imagePrefix: parent.chipImagePrefix + "_"
animationTime: parent.chipAnimationTime
preAnimationTime: parent.chipPreAnimationTime
}
MouseArea {
......
......@@ -31,6 +31,10 @@ import "globals.js" as Globals
Item {
id: chipContainer
/**
* Total frames in animation
*/
property int framesCount: 12
/**
* Current chip's frame
*/
......@@ -44,6 +48,10 @@ Item {
* Duration of chip's turning animation
*/
property int animationTime: 25 * 12
/**
* How long to wait before start of animation
*/
property int preAnimationTime: 0
CanvasItem {
id: chipImage
......@@ -51,7 +59,13 @@ Item {
visible: false
spriteKey: imagePrefix + currentFrame
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: chipContainer.clicked()
}
Timer {
id: blinkingTimer
interval: 500
......@@ -59,89 +73,108 @@ Item {
repeat: true
onTriggered: chipImage.visible = !chipImage.visible
}
states: [
State {
name: "Black"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: 1
}
PropertyChanges {
target: blinkingTimer
running: false
}
},
State {
name: "Black_blinking"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: 1
}
PropertyChanges {
target: blinkingTimer
running: true
}
},
State {
name: "White"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: Globals.CHIP_ANIMATION_FRAMES_COUNT
}
PropertyChanges {
target: blinkingTimer
running: false
}
},
State {
name: "White_blinking"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: Globals.CHIP_ANIMATION_FRAMES_COUNT
}
PropertyChanges {
target: blinkingTimer
running: true
}
State {
name: "Black"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: 1
}
PropertyChanges {
target: blinkingTimer
running: false
}
},
State {
name: "Black_blinking"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: 1
}
PropertyChanges {
target: blinkingTimer
running: true
}
},
State {
name: "White"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: framesCount
}
PropertyChanges {
target: blinkingTimer
running: false
}
},
State {
name: "White_blinking"
PropertyChanges {
target: chipImage
visible: true
}
PropertyChanges {
target: chipContainer
currentFrame: framesCount
}
PropertyChanges {
target: blinkingTimer
running: true
}
}
]
Behavior on currentFrame {
SequentialAnimation {
PauseAnimation {
duration: preAnimationTime
}
NumberAnimation {
duration: animationTime
easing.type: Easing.InOutQuad
}
}
}
transitions: [
Transition {
from: ""
to: "*"
reversible: false
NumberAnimation {
duration: animationTime
easing.type: Easing.InOutQuad
property: "currentFrame"
duration: 0
}
}
]
}
......@@ -87,6 +87,15 @@ Item {
function setLastMove(row, column, value) {
board.setLastMove(row, column, value)
}
/**
* Sets time to wait before starting animation
* @param row row index of cell (starting from 0)
* @param column column index of cell (starting from 0)
* @param value time to wait
*/
function setPreAnimationTime(row, column, value) {
board.setPreAnimationTime(row, column, value);
}
/**
* Shows popup with specified text
* @param text Text to show
......
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