File indexing completed on 2024-04-14 03:59:24

0001 /******************************************************************************
0002 *   KBlocks, a falling blocks game by KDE                                     *
0003 *   SPDX-FileCopyrightText: 2010-2021 Mauricio Piacentini <mauricio@tabuleiro.com>      *
0004 *                           Zhongjie Cai <squall.leonhart.cai@gmail.com>      *
0005 *                           Julian Helfferich <julian.helfferich@mailbox.org> *
0006 *                                                                             *
0007 *   SPDX-License-Identifier: GPL-2.0-or-later
0008 ******************************************************************************/
0009 
0010 #ifndef KBLOCKSITEMGROUP_H
0011 #define KBLOCKSITEMGROUP_H
0012 
0013 #include <QGraphicsItemGroup>
0014 #include <QTimer>
0015 #include <QList>
0016 
0017 #include "KBlocksAnimator.h"
0018 
0019 #include "SingleGameInterface.h"
0020 
0021 #include "KBlocksDefine.h"
0022 
0023 class GraphicsInterface;
0024 class KBlocksLayout;
0025 class KBlocksSvgItem;
0026 class SoundInterface;
0027 class SvgItemInterface;
0028 
0029 class KBlocksItemGroup : public QObject, public QGraphicsItemGroup
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, SoundInterface *pS, bool snapshotMode = false);
0035     ~KBlocksItemGroup() override;
0036 
0037 public:
0038     void setUpdateInterval(int interval);
0039     void setGameAnimEnabled(bool flag);
0040     void setWaitForAllUpdate(bool flag);
0041     void refreshPosition();
0042 
0043     void startGame();
0044     void stopGame();
0045 
0046     void pauseGame(bool flag);
0047 
0048 Q_SIGNALS:
0049     void readyForAction(int groupID);
0050 
0051 protected Q_SLOTS:
0052     void updateGame();
0053 
0054 private Q_SLOTS:
0055     void updateSnapshot();
0056     void endAnimation(int animType);
0057 
0058 private:
0059     bool updateLayout();
0060     void refreshItems();
0061 
0062     void refreshItemByPos(const QList<int> &dataList);
0063 
0064     void fadeInNewPiece();
0065     void fadeOutOldLine();
0066     void dropFreezeLine();
0067 
0068     void updateGraphicInfo();
0069 
0070 protected:
0071     int mMaxFreezeCellNum;
0072     SvgItemInterface **maFreezeCells;
0073 
0074     int mMaxPrepareCellNum;
0075     SvgItemInterface **maPrepareCells;
0076 
0077 private:
0078     int mGroupID;
0079 
0080     KBlocksSvgItem  *mpBackground;
0081 
0082     SingleGameInterface *mpSingleGame;
0083     KBlocksLayout *mpGameLayout = nullptr;
0084     GraphicsInterface *mpGrafx = nullptr;
0085     SoundInterface *mpSnd = nullptr;
0086 
0087     QTimer mUpdateTimer;
0088     int mUpdateInterval;
0089     bool mGameAnimEnabled;
0090     bool mWaitForAllUpdate;
0091 
0092     KBlocksAnimator *mpAnimator;
0093     QList<SvgItemInterface *> mFadeInItems;
0094     QList<SvgItemInterface *> mFadeOutItems;
0095     QList<SvgItemInterface *> mDropItems;
0096 
0097     QList<int> mRemovedLine;
0098     QList<int> mPunishLine;
0099     QList<int> mNewPiecePos;
0100 
0101     int mFieldWidth;
0102     int mFieldHeight;
0103 
0104     int mItemSize;
0105     int mPrepareLeft;
0106     int mPrepareTop;
0107     int mFieldLeft;
0108     int mFieldTop;
0109 };
0110 
0111 #endif
0112