Commit e2fc4822 authored by Denis Kuplyakov's avatar Denis Kuplyakov

Added ability to change animation speed.

All animation speed functionality is restored.
Now delay is synced between KReversiView and KReversiGame, without
KReversiMainWindow between.
parent e54181d7
......@@ -27,7 +27,7 @@ const int KReversiGame::DX[KReversiGame::DIRECTIONS_COUNT] = {0, 0, 1, 1, 1, -1,
const int KReversiGame::DY[KReversiGame::DIRECTIONS_COUNT] = {1, -1, 1, 0, -1, 1, 0, -1};
KReversiGame::KReversiGame(KReversiPlayer *blackPlayer, KReversiPlayer *whitePlayer)
: m_curPlayer(Black)
: m_curPlayer(Black), m_delay(300)
{
m_isReady[White] = m_isReady[Black] = false;
......
......@@ -63,8 +63,9 @@ void KReversiView::setGame(KReversiGame *game)
connect(m_game, SIGNAL(gameOver()), this, SLOT(gameOver()));
connect(m_game, SIGNAL(whitePlayerCantMove()), this, SLOT(whitePlayerCantMove()));
connect(m_game, SIGNAL(blackPlayerCantMove()), this, SLOT(blackPlayerCantMove()));
}
m_game->setDelay(m_delay);
}
m_hint = KReversiMove();
......@@ -88,7 +89,7 @@ void KReversiView::setShowBoardLabels(bool show)
updateBoard();
}
int KReversiView::setAnimationSpeed(int speed)
void KReversiView::setAnimationSpeed(int speed)
{
int value = ANIMATION_SPEED_NORMAL;
switch (speed) {
......@@ -105,8 +106,11 @@ int KReversiView::setAnimationSpeed(int speed)
}
m_delay = value;
if (m_game)
m_game->setDelay(value);
m_qml_root->setProperty("chipsAnimationTime", value);
return value;
}
KReversiView::~KReversiView()
......
......@@ -77,7 +77,7 @@ public:
*
* @return time for animation in milliseconds to pass it to KReversiGame
*/
int setAnimationSpeed(int speed);
void setAnimationSpeed(int speed);
/**
* Destructor used to delete game object owned by class
......
......@@ -100,16 +100,17 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
// addDockWidget(Qt::RightDockWidgetArea, m_historyDock);
// m_historyDock->hide();
// create main game view
m_view = new KReversiView(m_game, this);
// m_view->setChipsPrefix(Preferences::useColoredChips() ? Colored : BlackWhite);
setCentralWidget(m_view);
// initialise actions
setupActionsInit();
// load saved settings
loadSettings();
m_view = new KReversiView(m_game, this);
// m_view->setChipsPrefix(Preferences::useColoredChips() ? Colored : BlackWhite);
setCentralWidget(m_view);
setupGUI(qApp->desktop()->availableGeometry().size() * 0.7);
// initialise dialog handlers
......@@ -141,14 +142,14 @@ void KReversiMainWindow::setupActionsInit()
// actionCollection()->addAction(QLatin1String("show_legal_moves"), m_showLegal);
// connect(m_showLegal, SIGNAL(triggered(bool)), m_view, SLOT(setShowLegalMoves(bool)));
// // Animation speed
// m_animSpeedAct = new KSelectAction(i18n("Animation Speed"), this);
// actionCollection()->addAction(QLatin1String("anim_speed"), m_animSpeedAct);
// Animation speed
m_animSpeedAct = new KSelectAction(i18n("Animation Speed"), this);
actionCollection()->addAction(QLatin1String("anim_speed"), m_animSpeedAct);
// QStringList acts;
// acts << i18n("Slow") << i18n("Normal") << i18n("Fast");
// m_animSpeedAct->setItems(acts);
// connect(m_animSpeedAct, SIGNAL(triggered(int)), SLOT(slotAnimSpeedChanged(int)));
QStringList acts;
acts << i18n("Slow") << i18n("Normal") << i18n("Fast");
m_animSpeedAct->setItems(acts);
connect(m_animSpeedAct, SIGNAL(triggered(int)), SLOT(slotAnimSpeedChanged(int)));
// // Chip's color
// m_coloredChipsAct = new KToggleAction(i18n("Use Colored Chips"), this);
......@@ -164,8 +165,9 @@ void KReversiMainWindow::setupActionsInit()
void KReversiMainWindow::loadSettings()
{
// // Animation speed
// m_animSpeedAct->setCurrentItem(Preferences::animationSpeed());
// Animation speed
m_animSpeedAct->setCurrentItem(Preferences::animationSpeed());
m_view->setAnimationSpeed(Preferences::animationSpeed());
// // Chip's color
// m_coloredChipsAct->setChecked(Preferences::useColoredChips());
......@@ -178,9 +180,9 @@ void KReversiMainWindow::levelChanged()
void KReversiMainWindow::slotAnimSpeedChanged(int speed)
{
// m_game->setDelay(m_view->setAnimationSpeed(speed));
// Preferences::setAnimationSpeed(speed);
// Preferences::self()->writeConfig();
m_view->setAnimationSpeed(speed);
Preferences::setAnimationSpeed(speed);
Preferences::self()->writeConfig();
}
void KReversiMainWindow::slotUseColoredChips(bool toggled)
......@@ -400,6 +402,7 @@ void KReversiMainWindow::clearPlayers() {
for (int i = 0; i < 2; i++) // iterating through white to black
if (m_player[i])
{
m_player[i]->disconnect();
delete m_player[i];
m_player[i] = 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