Commit 0fb6a7f8 authored by Denis Kuplyakov's avatar Denis Kuplyakov

Fixed order of chip's turning.

Now chips are turned "as wave" from the players move.
parent a89e3607
......@@ -22,7 +22,7 @@
KReversiView::KReversiView(KReversiGame* game, QWidget *parent) :
KgDeclarativeView(parent), m_delay(ANIMATION_SPEED_NORMAL), m_game(0),
m_demoMode(false), m_showLastMove(false), m_showLegalMoves(false),
m_showLabels(false)
m_showLabels(false), m_maxDelay(0)
{
qmlRegisterType<ColorScheme>("ColorScheme", 1, 0, "ColorScheme");
......@@ -111,6 +111,30 @@ 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));
QMetaObject::invokeMethod(m_qml_root, "setPreAnimationTicks",
Q_ARG(QVariant, i),
Q_ARG(QVariant, j),
Q_ARG(QVariant, delay));
}
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));
m_maxDelay = qMax(m_maxDelay, delay);
}
}
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++) {
QString new_state = "";
......@@ -235,13 +259,12 @@ void KReversiView::onPlayerMove(int row, int col)
m_game->makePlayerMove(row, col, false);
}
void KReversiView::slotGameMoveFinished()
{
m_hint = KReversiPos();
updateBoard();
emit moveFinished();
m_delayTimer.singleShot(m_delay, this, SLOT(slotOnDelay()));
m_delayTimer.singleShot(m_delay * (m_maxDelay + 2), this, SLOT(slotOnDelay()));
}
void KReversiView::slotGameOver()
......
......@@ -225,5 +225,10 @@ private:
* If true board labels will be rendered
*/
bool m_showLabels;
/**
* Used to handle animation duration due to sequental turning of chips
*/
int m_maxDelay;
};
#endif
......@@ -41,6 +41,10 @@ Item {
function setLastMove(row, column, value) {
cells.itemAt(row * Globals.COLUMN_COUNT + column).isLastMove = value
}
function setPreAnimationTicks(row, column, value) {
cells.itemAt(row * Globals.COLUMN_COUNT + column).chipPreAnimationTicks = value
}
CanvasItem {
id: boardBackground
......
......@@ -25,6 +25,7 @@ Item {
property bool isHint: false
property string chipImagePrefix: "chip_bw"
property int chipAnimationTime: 25 * 12
property int chipPreAnimationTicks: 0
property string chipState: ""
CanvasItem {
......@@ -49,6 +50,7 @@ Item {
imagePrefix: parent.chipImagePrefix + "_"
animationTime: parent.chipAnimationTime
preAnimationTicks: parent.chipPreAnimationTicks
onClicked: cellContainer.clicked()
}
......
......@@ -23,6 +23,7 @@ Item {
property int currentFrame: 1
property string imagePrefix: "chip_bw_"
property int animationTime: 25 * 12
property int preAnimationTicks: 0
signal clicked
......@@ -126,9 +127,15 @@ Item {
]
Behavior on currentFrame {
NumberAnimation {
duration: animationTime
easing.type: Easing.InOutQuad
SequentialAnimation {
PauseAnimation {
duration: preAnimationTicks * animationTime
}
NumberAnimation {
duration: animationTime
easing.type: Easing.InOutQuad
}
}
}
}
......@@ -43,6 +43,10 @@ Item {
function setLastMove(row, column, value) {
board.setLastMove(row, column, value)
}
function setPreAnimationTicks(row, column, value) {
board.setPreAnimationTicks(row, column, value);
}
function showPopup(text) {
popup.show(text, "SHOWING");
......
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