File indexing completed on 2024-04-21 04:02:38

0001 /*
0002     SPDX-FileCopyrightText: 1997 Mathias Mueller <in5y158@public.uni-hamburg.de>
0003     SPDX-FileCopyrightText: 2006-2007 Mauricio Piacentini <mauricio@tabuleiro.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KMAHJONGG_H
0009 #define KMAHJONGG_H
0010 
0011 // KF
0012 #include <KXmlGuiWindow>
0013 
0014 class KToggleAction;
0015 class QLabel;
0016 class KGameClock;
0017 class Editor;
0018 class GameView;
0019 class GameScene;
0020 class GameData;
0021 class KMahjonggLayout;
0022 
0023 /**
0024  * @author Mathias */
0025 class KMahjongg : public KXmlGuiWindow
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     explicit KMahjongg(QWidget * parent = nullptr);
0031     ~KMahjongg() override;
0032 
0033 public Q_SLOTS:
0034     void startNewGame();
0035 
0036     /**
0037      * Load the settings... */
0038     void loadSettings();
0039 
0040     void showStatusText(const QString & msg, long board);
0041 
0042     void showItemNumber(int maximum, int current, int left);
0043 
0044     void gameOver(unsigned short numRemoved, unsigned short cheats);
0045 
0046     /**
0047      * Connected to GameView::demoOrMoveListAnimationOver(bool) signal. */
0048     void demoOrMoveListAnimationOver(bool demoGameLost);
0049 
0050 protected:
0051     void setupKAction();
0052     void setupStatusBar();
0053     void startNewGameWithNumber(int num);
0054 
0055     void changeEvent(QEvent * event) override;
0056     void closeEvent(QCloseEvent * event) override;
0057 
0058 private Q_SLOTS:
0059     void showSettings();
0060     void startNewNumeric();
0061     void saveGame();
0062     void loadGame();
0063     void restartGame();
0064     void undo();
0065     void redo();
0066     void pause();
0067     void demoMode();
0068     void displayTime(const QString & timestring);
0069     void showHighscores();
0070     void slotBoardEditor();
0071     void noMovesAvailable();
0072     void toggleFullscreen(bool fullscreen);
0073 
0074 private:
0075     enum class GameState { Gameplay,
0076                            Demo,
0077                            Paused,
0078                            Finished,
0079                            Stuck };
0080     GameState m_gameState;
0081 
0082     void updateState(GameState state);
0083     void updateUndoAndRedoStates();
0084     void loadLayout();
0085     void saveSettings();
0086 
0087     /**
0088      * @brief Ask the user if the game should be saved.
0089      * @return False if user cancel action. True does not mean, that the user has saved the game, but
0090      * has taken a decision to save it or not and wants to go on.
0091      */
0092     bool askSaveGame(const QString &dontAskAgainName);
0093 
0094     /**
0095      * @brief Test if game has changed and ask user for saving the game.
0096      * @return False if user cancels action, else true. 
0097      */
0098     bool testForGameChangeSave(const QString &dontAskAgainName);
0099 
0100     bool m_gameChanged = false;
0101     bool m_bLastRandomSetting;
0102 
0103     GameView * m_gameView;
0104     GameData * m_gameData;
0105     GameScene * m_gameScene;
0106 
0107     KMahjonggLayout * m_boardLayout;
0108 
0109     Editor * m_boardEditor;
0110 
0111     QLabel * m_gameNumLabel;
0112     QLabel * m_tilesLeftLabel;
0113     QLabel * m_statusLabel;
0114     QLabel * m_gameTimerLabel;
0115 
0116     QAction * m_undoAction;
0117     QAction * m_redoAction;
0118 
0119     KGameClock * m_gameTimer;
0120 
0121     KToggleAction * m_pauseAction;
0122     KToggleAction * m_fullscreenAction;
0123     KToggleAction * m_demoAction;
0124 };
0125 
0126 #endif