File indexing completed on 2024-04-14 04:02:25

0001 /*
0002     This file is part of the KDE games lskat program
0003     SPDX-FileCopyrightText: 2006 Martin Heni <kde@heni-online.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 
0007                           Lskat
0008                           -----
0009     begin                : March 2000
0010     copyright            : (C) 1995-2006 by Martin Heni
0011     email                : kde@heni-online.de
0012 */
0013 
0014 #ifndef LSKAT_MAINWINDOW_H
0015 #define LSKAT_MAINWINDOW_H
0016 
0017 // Qt includes
0018 #include <QHash>
0019 
0020 // KF includes
0021 #include <KXmlGuiWindow>
0022 
0023 // Local includes
0024 #include "abstractinput.h"
0025 #include "thememanager.h"
0026 
0027 // Forward declaration
0028 class GameView;
0029 class Deck;
0030 class AbstractEngine;
0031 class AbstractDisplay;
0032 class Player;
0033 class ConfigTwo;
0034 class QGraphicsScene;
0035 
0036 using namespace InputDevice;
0037 
0038 /**
0039  * The main application window.
0040  */
0041 class Mainwindow : public KXmlGuiWindow
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     /**
0047      * Game mode type
0048      */
0049     enum GameMode {Intro = 0, LSkat = 1, Skat = 2};
0050 
0051     /**
0052      * Construct the main window.
0053      * @param parent The parent widget
0054      */
0055     explicit Mainwindow(QWidget *parent = nullptr);
0056 
0057     /**
0058      * Destructor
0059      */
0060     ~Mainwindow() override;
0061 
0062 public Q_SLOTS:
0063     /**
0064      * A new game is started from the menu.
0065      */
0066     void menuNewLSkatGame();
0067 
0068     /**
0069      * A game is stopped in the menu.
0070      */
0071     void menuEndGame();
0072 
0073     /**
0074      * The start player is changed in the menu.
0075      */
0076     void menuStartplayer();
0077 
0078     /**
0079      * The input device for player 1 is changed in the menu.
0080      */
0081     void menuPlayer1By();
0082 
0083     /**
0084      * The input device for player 2 is changed in the menu.
0085      */
0086     void menuPlayer2By();
0087 
0088     /**
0089      * A card deck is chosen from the menu.
0090      */
0091     void menuCardDeck();
0092 
0093     /**
0094      * The player names shall be changed.
0095      */
0096     void menuPlayerNames();
0097 
0098     /**
0099      * The all time statistics is cleared from the menu.
0100      */
0101     void menuClearStatistics();
0102 
0103     /**
0104      * A game over signal arrived.
0105      */
0106     void gameOver(int winner);
0107 
0108     /**
0109      * Next players turn.
0110      */
0111     void nextPlayer(Player *player);
0112 
0113     /**
0114      * A new theme is selected from the menu.
0115      * @param idx The theme index
0116      */
0117     void changeTheme(int idx);
0118 
0119 protected:
0120     /**
0121      * A new input device is created.
0122      * @param inputType The type of input
0123      * @param display   The display.
0124      * @param engine    The game engine.
0125      * @return The new input device.
0126      */
0127     AbstractInput *createInput(
0128                          InputDevice::InputDeviceType inputType,
0129                          AbstractDisplay *display,
0130                          AbstractEngine *engine);
0131 
0132     /**
0133      * Initialize all GUI elements.
0134      */
0135     void initGUI();
0136 
0137     /**
0138      * Start a new game
0139      */
0140     void startGame();
0141 
0142     /**
0143      * Set-up the start player.
0144      * @param no The start player.
0145      */
0146     void setStartPlayer(int no);
0147 
0148     /**
0149      * Saves the window properties
0150      * @see KMainWindow#saveProperties
0151      */
0152     virtual void saveProperties();
0153 
0154     /**
0155      * Reads the session config file and restores the application's state.
0156      * @see KMainWindow#readProperties
0157      */
0158     virtual void readProperties();
0159 
0160     /**
0161      * Called by KMainWindow when closing the window.
0162      */
0163     void closeEvent(QCloseEvent *event) override;
0164 
0165     /**
0166      * Retrieve the theme file from the theme index number give.
0167      * @param idx The theme index number [0..]
0168      * @return The theme file name.
0169      */
0170     QString themefileFromIdx(int idx);
0171 
0172     /**
0173      * Retrieve the theme idx number from the theme name give.
0174      * @param name The theme file name.
0175      * @return The theme index number [0..]
0176      */
0177     int themeIdxFromName(const QString &name);
0178 
0179 protected Q_SLOTS:
0180     /**
0181      * Set the input type for a given player number.
0182      * @param no The player number
0183      * @param type The input type (Ai, Mouse, ...)
0184      */
0185     void setInputType(int no, InputDeviceType type);
0186 
0187 private:
0188     // Attributes not to be saved
0189     // The game engine
0190     AbstractEngine *mEngine;
0191     // The game display
0192     AbstractDisplay *mDisplay;
0193     // The main view
0194     GameView *mView;
0195     // The card deck
0196     Deck *mDeck;
0197     // LSkat config
0198     ConfigTwo *mLSkatConfig;
0199     // The graphics scene
0200     QGraphicsScene *mCanvas;
0201     // The theme manager used
0202     ThemeManager *mTheme;
0203     // The available themes
0204     QHash<QString, QString> mThemeFiles;
0205     // Current theme index
0206     int mThemeIndexNo;
0207     // Default theme
0208     QString mThemeDefault;
0209 
0210     // Properties to be saved
0211     // The cards directory
0212     QString mCardTheme;
0213     // Current game mode (Intro, LSkat, ...)
0214     GameMode mGameMode;
0215     // Who starts the next game round/
0216     int mStartPlayer;
0217 };
0218 
0219 #endif // LSKAT_MAINWINDOW_H