1/***************************************************************************
2* KBlocks, a falling blocks game for KDE *
3* Copyright (C) 2010 Mauricio Piacentini <mauricio@tabuleiro.com> *
4* Zhongjie Cai <squall.leonhart.cai@gmail.com> *
5* *
6* This program is free software; you can redistribute it and/or modify *
7* it under the terms of the GNU General Public License as published by *
8* the Free Software Foundation; either version 2 of the License, or *
9* (at your option) any later version. *
10***************************************************************************/
11
12#ifndef KBLOCKSITEMGROUP_H
13#define KBLOCKSITEMGROUP_H
14
15#include <QGraphicsItemGroup>
16#include <QTimer>
17#include <QList>
18
19#include "KBlocksGraphics.h"
20#include "KBlocksSound.h"
21#include "KBlocksSvgItem.h"
22#include "KBlocksAnimator.h"
23
24#include "SingleGameInterface.h"
25
26#include "KBlocksDefine.h"
27
28class KBlocksItemGroup : public QObject, public QGraphicsItemGroup
29{
30 Q_OBJECT
31
32 public:
33 KBlocksItemGroup(int groupID, SingleGameInterface * p, KBlocksGraphics * pG, KBlocksSound * pS, bool snapshotMode = false);
34 ~KBlocksItemGroup();
35
36 public:
37 void setUpdateInterval(int interval);
38 void setGameAnimEnabled(bool flag);
39 void setWaitForAllUpdate(bool flag);
40 void refreshPosition();
41
42 void startGame();
43 void stopGame();
44
45 void pauseGame(bool flag);
46
47 signals:
48 void readyForAction(int groupID);
49
50 private slots:
51 void updateGame();
52 void updateSnapshot();
53 void endAnimation(int animType);
54
55 private:
56 bool updateLayout();
57 void refreshItems();
58
59 void refreshItemByPos(const QList<int> & dataList);
60
61 void fadeInNewPiece();
62 void fadeOutOldLine();
63 void dropFreezeLine();
64
65 void updateGraphicInfo();
66
67 private:
68 int mGroupID;
69
70 KBlocksSvgItem* mpBackground;
71
72 int mMaxFreezeCellNum;
73 KBlocksSvgItem** maFreezeCells;
74 int mMaxPrepareCellNum;
75 KBlocksSvgItem** maPrepareCells;
76
77 SingleGameInterface* mpSingleGame;
78 KBlocksLayout* mpGameLayout;
79 KBlocksGraphics* mpGrafx;
80 KBlocksSound* mpSnd;
81
82 QTimer mUpdateTimer;
83 int mUpdateInterval;
84 bool mGameAnimEnabled;
85 bool mWaitForAllUpdate;
86
87 KBlocksAnimator* mpAnimator;
88 QList<KBlocksSvgItem*> mFadeInItems;
89 QList<KBlocksSvgItem*> mFadeOutItems;
90 QList<KBlocksSvgItem*> mDropItems;
91
92 QList<int> mRemovedLine;
93 QList<int> mPunishLine;
94 QList<int> mNewPiecePos;
95
96 int mFieldWidth;
97 int mFieldHeight;
98
99 int mItemSize;
100 int mPrepareLeft;
101 int mPrepareTop;
102 int mFieldLeft;
103 int mFieldTop;
104};
105
106#endif
107
108