Commit 4bf31c4f authored by Dmitry Suzdalev's avatar Dmitry Suzdalev

Implemented setting animation speed

svn path=/branches/work/kreversi_rewrite/; revision=581074
parent 94267028
......@@ -9,23 +9,26 @@
<label>Whether to use a grayscale board instead of colored.</label>
<default>false</default>
</entry>
<entry name="AnimationSpeed" type="Int">
<entry name="AnimationSpeed" type="Enum">
<label>The speed of the animations.</label>
<default>25</default>
<min>10</min>
<max>40</max>
<choices>
<choice name="Slow" />
<choice name="Normal" />
<choice name="Fast" />
</choices>
<default>Normal</default>
</entry>
<entry name="CompetitiveGameChoice" type="Bool">
<label>Whether to play competitively in contrast to casually.</label>
<default>true</default>
</entry>
<entry name="skill" type="Int">
<entry name="Skill" type="Int">
<label>The strength of the computer player.</label>
<default>1</default>
<min>1</min>
<max>7</max>
</entry>
<entry name="backgroundImageName" type="String">
<entry name="BackgroundImageName" type="String">
<label>Background image name</label>
<default>Light_Wood</default>
</entry>
......
......@@ -14,7 +14,7 @@
const int CHIP_SIZE = 36;
KReversiScene::KReversiScene( KReversiGame* game , const QPixmap& chipsPixmap )
: m_hintChip(0), m_lastMoveChip(0), m_showingHint(false), m_demoMode(false),
: m_hintChip(0), m_lastMoveChip(0), m_timerDelay(25), m_showingHint(false), m_demoMode(false),
m_showLastMove(false), m_showPossibleMoves(false)
{
setBackgroundBrush( Qt::lightGray );
......@@ -71,6 +71,16 @@ void KReversiScene::setShowLegalMoves( bool show )
}
}
void KReversiScene::setAnimationSpeed(int speed)
{
if( speed == 0 ) // slow
m_timerDelay = 35;
else if( speed == 1 ) // normal
m_timerDelay = 20;
else if( speed == 2 ) // fast
m_timerDelay = 10;
}
bool KReversiScene::isBusy() const
{
return m_animTimer->isActive();
......@@ -143,7 +153,7 @@ void KReversiScene::slotGameMoveFinished()
// start animation
if( m_lastMoveChip )
m_lastMoveChip->showLastMoveMarker( false );
m_animTimer->start(10);
m_animTimer->start(m_timerDelay);
}
void KReversiScene::slotAnimationStep()
......
......@@ -45,6 +45,10 @@ public:
* @return whether the scene is in demo-mode
*/
bool isDemoModeToggled() const { return m_demoMode; }
/**
* Sets the animation speed (0 - slow, 1 - normal, 2 - fast)
*/
void setAnimationSpeed(int speed);
public slots:
void updateBoard();
void slotGameMoveFinished();
......@@ -140,6 +144,10 @@ private:
* This will hold a pointer to chip which has "last-move" mark
*/
KReversiChip* m_lastMoveChip;
/**
* Delay between animation frames
*/
int m_timerDelay;
/**
* Holds true if the scene is showing hint to the player
*/
......
......@@ -69,15 +69,18 @@ void KReversiMainWindow::setupActions()
KToggleAction *showLegal = new KToggleAction(KIcon("legalmoves"), i18n("Show legal moves"), actionCollection(), "show_legal_moves" );
connect( showLegal, SIGNAL(triggered(bool)), m_scene, SLOT(setShowLegalMoves(bool)) );
KSelectAction *animSpeed = new KSelectAction(i18n("Animation speed"), actionCollection(), "anim_speed");
m_animSpeedAct = new KSelectAction(i18n("Animation speed"), actionCollection(), "anim_speed");
QStringList acts;
acts << "Slow" << "Normal" << "Fast";
animSpeed->setItems(acts);
acts << i18n("Slow") << i18n("Normal") << i18n("Fast");
m_animSpeedAct->setItems(acts);
connect( m_animSpeedAct, SIGNAL(triggered(int)), SLOT(slotAnimSpeedChanged(int)) );
m_skillAct = new KSelectAction(i18n("Computer skill"), actionCollection(), "skill" );
acts.clear();
// FIXME dimsuz: this utilises 5 skills. although 7 is possible
acts << "Very easy" << "Easy" << "Normal" << "Hard" << "Unbeatable";
// also give them good names
acts << i18n("Very easy") << i18n("Easy") << i18n("Normal");
acts << i18n("Hard") << i18n("Beatable") << i18n("Unbeatable");
m_skillAct->setItems(acts);
connect(m_skillAct, SIGNAL(triggered(int)), SLOT(slotSkillChanged(int)) );
......@@ -96,6 +99,9 @@ void KReversiMainWindow::loadSettings()
int skill = Preferences::skill();
m_skillAct->setCurrentItem( skill - 1 );
slotSkillChanged( skill - 1 );
m_animSpeedAct->setCurrentItem( Preferences::animationSpeed() );
slotAnimSpeedChanged( Preferences::animationSpeed() );
}
void KReversiMainWindow::slotBackgroundChanged( const QString& text )
......@@ -124,6 +130,13 @@ void KReversiMainWindow::slotSkillChanged(int skill)
Preferences::writeConfig();
}
void KReversiMainWindow::slotAnimSpeedChanged(int speed)
{
m_scene->setAnimationSpeed(speed);
Preferences::setAnimationSpeed(speed);
Preferences::writeConfig();
}
void KReversiMainWindow::slotDemoMode(bool toggled)
{
kDebug() << k_funcinfo << endl;
......
......@@ -18,6 +18,7 @@ public slots:
void slotNewGame();
void slotBackgroundChanged(const QString& text);
void slotSkillChanged(int);
void slotAnimSpeedChanged(int);
void slotUndo();
void slotMoveFinished();
void slotGameOver();
......@@ -33,6 +34,7 @@ private:
KAction* m_undoAct;
KAction* m_hintAct;
KAction* m_demoAct;
KSelectAction* m_animSpeedAct;
KSelectAction* m_bkgndAct;
KSelectAction* m_skillAct;
};
......
......@@ -4,4 +4,4 @@ File=kreversi.kcfg
ClassName=Preferences
Singleton=true
CustomAdditions=false
Mutators=skill,backgroundImageName
Mutators=Skill,BackgroundImageName,AnimationSpeed
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