From f9de75881d3bcb71464e4fc1a8fa6814ac5c5a8b Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Mon, 23 Jul 2007 14:01:17 +0200 Subject: [PATCH] Animation settings are now honored. Fixes ticket #20. --- src/animationfactory.cpp | 76 +++++++++++++++++++++++++++++++++++++----------- src/animationfactory.h | 34 +++++++++++++++------- src/board.cpp | 5 ++-- src/board.h | 5 +++- src/chesstable.cpp | 9 ++++-- src/chesstable.h | 4 ++- src/graphicalsystem.cpp | 2 +- src/piecepool.cpp | 7 +++-- src/piecepool.h | 5 ++-- 9 files changed, 108 insertions(+), 39 deletions(-) diff --git a/src/animationfactory.cpp b/src/animationfactory.cpp index 9a61f98..619c45a 100644 --- a/src/animationfactory.cpp +++ b/src/animationfactory.cpp @@ -5,9 +5,13 @@ #include "pointconverter.h" #include "indexconverter.h" #include "graphicalapi.h" +#include "mastersettings.h" namespace Common { - AnimationPtr appear(const NamedSprite& sprite, Animate::AnimationType type) { + AnimationPtr appear(const AnimationSettings& s, const NamedSprite& sprite, Animate::AnimationType type) { + if (!s.fading) + type = Animate::Instant; + switch (type) { case Animate::Normal: return AnimationPtr(new FadeAnimation(sprite.sprite(), 0, 255)); @@ -17,7 +21,10 @@ namespace Common { } } - AnimationPtr disappear(const NamedSprite& sprite, Animate::AnimationType type) { + AnimationPtr disappear(const AnimationSettings& s, const NamedSprite& sprite, Animate::AnimationType type) { + if (!s.fading) + type = Animate::Instant; + switch (type) { case Animate::Normal: return AnimationPtr(new FadeAnimation(sprite.sprite(), 255, 0)); @@ -28,6 +35,24 @@ namespace Common { } }; +AnimationSettings::AnimationSettings() { + reload(); +} + +void AnimationSettings::reload() { + Settings s = settings().group("animations"); + + enabled = s.flag("enabled", true); + maxSequence = + s.group("sequence").flag("enabled", true) + ? s.group("sequence")["max"].value() + : 0; + movement = s["movement"].flag("enabled", true); + explode = s["explode"].flag("enabled", true); + fading = s["fading"].flag("enabled", true); + transform = s["transform"].flag("enabled", true); +} + AnimationFactory::AnimationFactory(GraphicalAPI* api) : m_api(api) { m_group = AnimationGroupPtr(new AnimationGroup); @@ -62,18 +87,25 @@ namespace Animate { , m_to(to) , m_type(type) { } - AnimationPtr move::run(const PointConverter* converter, AnimationType type) const { + AnimationPtr move::run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const { + int mov_type = m_type; + if (!s.movement) + type = Instant; + else if (!s.transform) { + mov_type &= ~Rotating; + } + switch (type) { case Normal: { MovementAnimation* mov; QPoint destination = converter->toReal(m_to); Point origin = converter->toLogical(m_sprite.sprite()->pos() + Point(converter->squareSize(), converter->squareSize()) / 2); - if ((m_type & LShaped) && origin != m_to) { - mov = new KnightMovementAnimation(m_sprite.sprite(), destination, m_type & Rotating); + if ((mov_type & LShaped) && origin != m_to) { + mov = new KnightMovementAnimation(m_sprite.sprite(), destination, mov_type & Rotating); } else { - mov = new MovementAnimation(m_sprite.sprite(), destination, m_type & Rotating); + mov = new MovementAnimation(m_sprite.sprite(), destination, mov_type & Rotating); } return AnimationPtr(mov); } @@ -86,21 +118,25 @@ namespace Animate { appear::appear(const NamedSprite& sprite) : m_sprite(sprite) { } - AnimationPtr appear::run(const PointConverter*, AnimationType type) const { - return Common::appear(m_sprite, type); + AnimationPtr appear::run(const AnimationSettings& s, const PointConverter*, AnimationType type) const { + return Common::appear(s, m_sprite, type); } disappear::disappear(const NamedSprite& sprite) : m_sprite(sprite) { } - AnimationPtr disappear::run(const PointConverter*, AnimationType type) const { - return Common::disappear(m_sprite, type); + AnimationPtr disappear::run(const AnimationSettings& s, const PointConverter*, AnimationType type) const { + return Common::disappear(s, m_sprite, type); } destroy::destroy(const NamedSprite& sprite) : m_sprite(sprite) { } - AnimationPtr destroy::run(const PointConverter*, AnimationType type) const { + AnimationPtr destroy::run(const AnimationSettings& s, const PointConverter*, AnimationType type) const { + if (!s.explode) { + return Common::disappear(s, m_sprite, type); + } + switch (type) { case Normal: return AnimationPtr(new ExplodeAnimation(m_sprite.sprite(), Random::instance())); @@ -114,7 +150,10 @@ namespace Animate { : m_sprite(sprite) , m_new_sprite(new_sprite) { } - AnimationPtr morph::run(const PointConverter*, AnimationType type) const { + AnimationPtr morph::run(const AnimationSettings& s, const PointConverter*, AnimationType type) const { + if (!s.fading) + type = Instant; + switch (type) { case Normal: return AnimationPtr(new CrossFadingAnimation(m_sprite.sprite(), m_new_sprite.sprite())); @@ -130,7 +169,10 @@ namespace Animate { : m_sprite(sprite) , m_to(to) { } - AnimationPtr move::run(const IndexConverter* converter, AnimationType type) const { + AnimationPtr move::run(const AnimationSettings& s, const IndexConverter* converter, AnimationType type) const { + if (!s.movement) + type = Instant; + switch (type) { case Normal: return AnimationPtr(new MovementAnimation(m_sprite.sprite(), converter->toReal(m_to))); @@ -143,15 +185,15 @@ namespace Animate { appear::appear(const NamedSprite& sprite) : m_sprite(sprite) { } - AnimationPtr appear::run(const IndexConverter*, AnimationType type) const { - return Common::appear(m_sprite, type); + AnimationPtr appear::run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const { + return Common::appear(s, m_sprite, type); } disappear::disappear(const NamedSprite& sprite) : m_sprite(sprite) { } - AnimationPtr disappear::run(const IndexConverter*, AnimationType type) const { - return Common::disappear(m_sprite, type); + AnimationPtr disappear::run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const { + return Common::disappear(s, m_sprite, type); } } diff --git a/src/animationfactory.h b/src/animationfactory.h index db80194..c38fa8e 100644 --- a/src/animationfactory.h +++ b/src/animationfactory.h @@ -19,6 +19,7 @@ class NamedSprite; class PointConverter; class IndexConverter; class GraphicalAPI; +class AnimationSettings; namespace Animate { @@ -47,11 +48,24 @@ namespace Animate { * Convert the scheme into an actual animation which can be enqueued in the * animation system, or grouped into an AnimationGroup. */ - virtual AnimationPtr run(const PointConverter*, AnimationType) const = 0; + virtual AnimationPtr run(const AnimationSettings& s, const PointConverter*, AnimationType) const = 0; }; } +struct AnimationSettings { + bool enabled; + + int maxSequence; + bool movement; + bool explode; + bool fading; + bool transform; + + AnimationSettings(); + void reload(); +}; + /** * @brief A convenience wrapper around an AnimationGroup, useful for Animators. * @@ -112,7 +126,7 @@ namespace Animate { int m_type; public: move(const NamedSprite& sprite, const Point& to, int type = Straight); - virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const; + virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const; }; /** @@ -126,7 +140,7 @@ namespace Animate { const NamedSprite& m_sprite; public: appear(const NamedSprite& sprite); - virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const; + virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const; }; /** @@ -138,7 +152,7 @@ namespace Animate { const NamedSprite& m_sprite; public: disappear(const NamedSprite& sprite); - virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const; + virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const; }; /** @@ -152,7 +166,7 @@ namespace Animate { const NamedSprite& m_sprite; public: destroy(const NamedSprite& sprite); - virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const; + virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const; }; /** @@ -165,7 +179,7 @@ namespace Animate { const NamedSprite& m_new_sprite; public: morph(const NamedSprite& sprite, const NamedSprite& new_sprite); - virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const; + virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const; }; /** @@ -176,7 +190,7 @@ namespace Animate { class Scheme { public: virtual ~Scheme() { } - virtual AnimationPtr run(const IndexConverter* converter, AnimationType) const = 0; + virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter* converter, AnimationType) const = 0; }; class move : public Scheme { @@ -184,21 +198,21 @@ namespace Animate { int m_to; public: move(const NamedSprite& sprite, int to); - virtual AnimationPtr run(const IndexConverter*, AnimationType type) const; + virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const; }; class appear : public Scheme { const NamedSprite& m_sprite; public: appear(const NamedSprite& sprite); - virtual AnimationPtr run(const IndexConverter*, AnimationType type) const; + virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const; }; class disappear : public Scheme { const NamedSprite& m_sprite; public: disappear(const NamedSprite& sprite); - virtual AnimationPtr run(const IndexConverter*, AnimationType type) const; + virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const; }; } diff --git a/src/board.cpp b/src/board.cpp index 7939c89..f9c910a 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -30,7 +30,7 @@ using namespace boost; class BoardTags : public std::map > > { }; -Board::Board(KGameCanvasAbstract* parent) +Board::Board(const AnimationSettings& animSettings, KGameCanvasAbstract* parent) : ClickableCanvas(parent) , m_flipped(false) , m_square_size(0) @@ -40,7 +40,8 @@ Board::Board(KGameCanvasAbstract* parent) , selection(Point::invalid()) , lastSelection(Point::invalid()) , m_dropped_pool(-1) -, m_dropped_index(-1) { +, m_dropped_index(-1) +, m_anim_settings(animSettings) { m_main_animation = new MainAnimation( 1.0 ); diff --git a/src/board.h b/src/board.h index bb95e0e..37823bb 100644 --- a/src/board.h +++ b/src/board.h @@ -32,6 +32,7 @@ class DragInfo; class Animation; class UserEntity; class ConstrainedText; +class AnimationSettings; class BoardTags; typedef boost::shared_ptr BoardTagsPtr; @@ -151,6 +152,8 @@ private: int m_dropped_pool; int m_dropped_index; + + const AnimationSettings& m_anim_settings; /** the text items for the border */ std::vector m_border_text; @@ -187,7 +190,7 @@ private: public: /** constructor, requires the canvas parent */ - Board(KGameCanvasAbstract* parent); + Board(const AnimationSettings& animSettings, KGameCanvasAbstract* parent); ~Board(); /** set the board flipping */ diff --git a/src/chesstable.cpp b/src/chesstable.cpp index b17855e..9e8a0e9 100644 --- a/src/chesstable.cpp +++ b/src/chesstable.cpp @@ -34,7 +34,7 @@ ChessTable::ChessTable(QWidget* parent) setMouseTracking(true); // create m_board - m_board = new Board(this); + m_board = new Board(m_anim_settings, this); m_board->show(); // create move list @@ -53,7 +53,7 @@ ChessTable::ChessTable(QWidget* parent) // create pools for(int i=0;i<2;i++) { - m_pools[i] = new PiecePool(i, m_board, this); + m_pools[i] = new PiecePool(i, m_board, m_anim_settings, this); m_pools[i]->show(); } @@ -72,6 +72,8 @@ ChessTable::~ChessTable() { } void ChessTable::settingsChanged() { + m_anim_settings.reload(); + m_board->settingsChanged(); for(int i=0;i<2;i++) m_clocks[i]->settingsChanged(); @@ -330,4 +332,7 @@ void ChessTable::displayMessage(const QString& msg) { message(msg); } +const AnimationSettings& ChessTable::animationSettings() const { + return m_anim_settings; +} diff --git a/src/chesstable.h b/src/chesstable.h index 4fb4c2c..c896389 100644 --- a/src/chesstable.h +++ b/src/chesstable.h @@ -17,6 +17,7 @@ #include "positioninfo.h" #include "board.h" #include "common.h" +#include "animationfactory.h" class PiecePool; class Player; @@ -47,6 +48,7 @@ class ChessTable : public KGameCanvasWidget { void layout(bool force_reload = false); + AnimationSettings m_anim_settings; public: ChessTable(QWidget* parent = 0); ~ChessTable(); @@ -74,7 +76,7 @@ public: virtual void leaveEvent (QEvent * event); void settingsChanged(); //called by GraphicalInfo, for better theme change - + const AnimationSettings& animationSettings() const; public Q_SLOTS: void updateTurn(int color); void changeClock(int color); diff --git a/src/graphicalsystem.cpp b/src/graphicalsystem.cpp index 217c809..760c98c 100644 --- a/src/graphicalsystem.cpp +++ b/src/graphicalsystem.cpp @@ -163,7 +163,7 @@ std::pair GraphicalSystem::droppedPoolPiece() { } AnimationPtr GraphicalSystem::animate(const Animate::Scheme& scheme, Animate::AnimationType type) { - return scheme.run(converter(), type); + return scheme.run(m_view->animationSettings(), converter(), type); } diff --git a/src/piecepool.cpp b/src/piecepool.cpp index b9726b4..8ff5f58 100755 --- a/src/piecepool.cpp +++ b/src/piecepool.cpp @@ -13,14 +13,15 @@ #include "piecepool.h" -PiecePool::PiecePool(int num, Board* b, KGameCanvasAbstract* parent) +PiecePool::PiecePool(int num, Board* b, const AnimationSettings& animSettings, KGameCanvasAbstract* parent) : ClickableCanvas(parent) , m_pool_num(num) , m_board(b) , m_flipped(false) , m_square_size(0) , m_width(1) -, m_dragged_index(-1) { +, m_dragged_index(-1) +, m_anim_settings(animSettings) { m_main_animation = new MainAnimation( 1.0 ); setGridWidth(1); } @@ -93,7 +94,7 @@ void PiecePool::clear() { } void PiecePool::animate(const Animate::Pool::Scheme& scheme, Animate::AnimationType type) { - m_main_animation->addAnimation(scheme.run(this, type)); + m_main_animation->addAnimation(scheme.run(m_anim_settings, this, type)); } void PiecePool::insertSprite(int index, const NamedSprite& nsprite) { diff --git a/src/piecepool.h b/src/piecepool.h index ffa3bb8..4cc5fe9 100644 --- a/src/piecepool.h +++ b/src/piecepool.h @@ -12,12 +12,12 @@ #define PIECEPOOL_H #include +#include "animationfactory.h" #include "clickablecanvas.h" #include "indexconverter.h" #include "mainanimation.h" #include "namedsprite.h" #include "pixmaploader.h" -#include "animationfactory.h" /** * @class PiecePool @@ -60,6 +60,7 @@ private: /** main animation structure */ MainAnimation* m_main_animation; + const AnimationSettings& m_anim_settings; /** internal function, resizes the grid vector to hold x pieces */ void setFill(int x); @@ -86,7 +87,7 @@ public: friend class ChessTable; /** Constructor, requires the board the pool will be attached to */ - PiecePool(int num, Board* b, KGameCanvasAbstract* parent); + PiecePool(int num, Board* b, const AnimationSettings&, KGameCanvasAbstract* parent); ~PiecePool(); /** returns the sprite loader */ -- 2.11.4.GIT