Commit 847e7af5 authored by Denis Kuplyakov's avatar Denis Kuplyakov

Added ability to change animation speed

Added ability to change animation speed by setting corresponding value
to ReversiChip animation time.
parent 130f7cb7
......@@ -82,6 +82,26 @@ void KReversiView::setShowBoardLabels(bool show)
updateBoard();
}
void KReversiView::setAnimationSpeed(int speed)
{
int value;
switch (speed) {
case 0:
value = ANIMATION_SPEED_SLOW;
break;
default:
case 1:
value = ANIMATION_SPEED_NORMAL;
break;
case 2:
value = ANIMATION_SPEED_FAST;
break;
}
QMetaObject::invokeMethod(m_qml_root, "setAnimationTime",
Q_ARG(QVariant, value));
}
void KReversiView::updateBoard()
{
for (int i = 0; i < 8; i++)
......
......@@ -56,7 +56,7 @@ public:
/**
* Sets the animation speed (0 - slow, 1 - normal, 2 - fast)
*/
// void setAnimationSpeed(int speed);
void setAnimationSpeed(int speed);
public slots:
void onPlayerMove(int row, int col);
/**
......@@ -98,6 +98,9 @@ private slots:
signals:
void moveFinished();
private:
static const int ANIMATION_SPEED_SLOW = 40 * 12;
static const int ANIMATION_SPEED_NORMAL = 25 * 12;
static const int ANIMATION_SPEED_FAST = 15 * 12;
QObject *m_qml_root;
KgThemeProvider *m_provider;
QTimer m_delayTimer;
......
......@@ -189,7 +189,7 @@ void KReversiMainWindow::levelChanged()
void KReversiMainWindow::slotAnimSpeedChanged(int speed)
{
// m_scene->setAnimationSpeed(speed);
m_view->setAnimationSpeed(speed);
Preferences::setAnimationSpeed(speed);
Preferences::self()->writeConfig();
}
......@@ -258,7 +258,7 @@ void KReversiMainWindow::slotNewGame()
QString chipsPrefix = Preferences::useColoredChips() ? QLatin1String("chip_color") : QLatin1String("chip_bw");
m_view = new KReversiView(m_game, this);
setCentralWidget(m_view);
// m_view->setAnimationSpeed( Preferences::animationSpeed() );
m_view->setAnimationSpeed( Preferences::animationSpeed() );
connect(m_view, SIGNAL(moveFinished()), SLOT(slotMoveFinished()));
} else {
m_view->setGame(m_game);
......
......@@ -52,6 +52,13 @@ Item {
cells.itemAt(row * Globals.COLUMN_COUNT + column).setLastMove(value)
}
function setAnimationTime(value) {
for (var i = 0; i < Globals.ROW_COUNT; i++)
for (var j = 0; j < Globals.COLUMN_COUNT; j++)
cells.itemAt(i * Globals.COLUMN_COUNT + j).setAnimationTime(
value)
}
KgCore.KgItem {
id: board_background
z: 0
......
......@@ -49,6 +49,10 @@ Item {
cell_last_move_marker.visible = value;
}
function setAnimationTime(value) {
reversi_chip.animation_time = value;
}
KgCore.KgItem {
id: cell_legal_image
z: 1
......
......@@ -23,6 +23,7 @@ Item {
property int frames_count: 12
property int current_frame: 1
property string image_prefix: "chip_bw_"
property int animation_time: 300
signal clicked
......@@ -129,7 +130,7 @@ Item {
Behavior on current_frame {
NumberAnimation {
duration: 300
duration: animation_time
easing.type: Easing.InOutQuad
}
}
......
......@@ -49,6 +49,10 @@ Item {
board.setLastMove(row, column, value)
}
function setAnimationTime(value) {
board.setAnimationTime(value)
}
function showPopup(text) {}
KgCore.KgItem {
......
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