Commit 1c5f1fb9 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev
Browse files

Now that KGamePopupItem is in libkdegames, use it in klines to report when ball can't be moved.

Native speakers, does the "Selected ball can not be moved to this cell" phrase
sounds native enough? :)

Please fix me if it isn't...

svn path=/trunk/KDE/kdegames/klines/; revision=679705
parent f3b2feaf
......@@ -77,12 +77,12 @@ bool KLinesAnimator::isAnimating() const
|| m_removeTimeLine.state() == QTimeLine::Running);
}
void KLinesAnimator::animateMove( const FieldPos& from, const FieldPos& to )
bool KLinesAnimator::animateMove( const FieldPos& from, const FieldPos& to )
{
findPath(from, to);
if(m_foundPath.isEmpty())
return;
return false;
m_movingBall = m_scene->ballAt(from);
m_movingBall->stopAnimation();
......@@ -95,6 +95,7 @@ void KLinesAnimator::animateMove( const FieldPos& from, const FieldPos& to )
m_moveTimeLine.setFrameRange(0, (numPoints-1)*KLinesRenderer::self()->cellSize());
m_moveTimeLine.setCurrentTime(0);
m_moveTimeLine.start();
return true;
}
void KLinesAnimator::animateRemove( const QList<BallItem*>& list )
......
......@@ -42,8 +42,10 @@ public:
* When animation finishes moveFinished() signal is emitted
* @param from starting field position
* @param to target field position
*
* @return true is there exists a path (from,to), false otherwise
*/
void animateMove( const FieldPos& from, const FieldPos& to );
bool animateMove( const FieldPos& from, const FieldPos& to );
/**
* Starts animation of ball deletion from field.
* Note that it doesn't do actual deletion - it just runs
......
......@@ -29,6 +29,8 @@
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
#include <kgamepopupitem.h>
#include <KLocale>
#include <KDebug>
KLinesScene::KLinesScene( QObject* parent )
......@@ -47,6 +49,15 @@ KLinesScene::KLinesScene( QObject* parent )
m_previewItem = new PreviewItem(this);
m_previewItem->setPos( 0, 0 );
m_popupItem = new KGamePopupItem;
addItem(m_popupItem);
// NOTE: when adding non-ball items watch out! all items are deleted in startNewGame,
// so don't forget to put non-ball item in (if item != myNonBallItem)
// TODO: better use qgraphicsitem_cast<BallItem*> == 0 as criteria. After that remove
// this NOTE
startNewGame();
}
......@@ -68,7 +79,9 @@ void KLinesScene::startNewGame()
QList<QGraphicsItem*> itemlist = items();
foreach( QGraphicsItem* item, itemlist )
{
if( item != m_focusItem && item != m_previewItem )
// TODO: better use qgraphicsitem_cast<BallItem*> == 0 as criteria. After that remove
// NOTE in constructor
if( item != m_focusItem && item != m_previewItem && item != m_popupItem)
{
removeItem(item);
delete item;
......@@ -249,7 +262,9 @@ void KLinesScene::selectOrMove( const FieldPos& fpos )
saveUndoInfo();
// start move animation
// slot moveAnimFinished() will be called when it finishes
m_animator->animateMove(m_selPos, fpos);
bool pathExists = m_animator->animateMove(m_selPos, fpos);
if(!pathExists)
m_popupItem->showMessage(i18n("Selected ball can not be moved to this cell"), KGamePopupItem::BottomLeft);
}
}
}
......
......@@ -34,6 +34,7 @@ class KLinesAnimator;
class BallItem;
class PreviewItem;
class QGraphicsRectItem;
class KGamePopupItem;
/**
* Displays and drives the game
......@@ -230,6 +231,10 @@ private:
* Item which displays next balls preview
*/
PreviewItem *m_previewItem;
/**
* Item to show popup messages to user
*/
KGamePopupItem *m_popupItem;
/**
* Struct for holding game state - used on undos
*/
......
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