1 /*
2 	SPDX-FileCopyrightText: 2021 Graeme Gott <graeme@gottcode.org>
3 
4 	SPDX-License-Identifier: GPL-3.0-or-later
5 */
6 
7 #ifndef SIMSU_NEW_GAME_PAGE_H
8 #define SIMSU_NEW_GAME_PAGE_H
9 
10 #include <QWidget>
11 class QLineEdit;
12 class QListWidget;
13 class QPushButton;
14 class QStackedWidget;
15 
16 /**
17  * @brief The NewGamePage class allows the player to choose the settings for a new game.
18  */
19 class NewGamePage : public QWidget
20 {
21 	Q_OBJECT
22 
23 public:
24 	/**
25 	 * Constructs the page.
26 	 */
27 	explicit NewGamePage(QWidget* parent = nullptr);
28 
29 	/**
30 	 * Resets values and shows settings for computer generated games.
31 	 */
32 	void reset();
33 
34 signals:
35 	/**
36 	 * This signal is emitted when the player cancels starting a new game.
37 	 */
38 	void cancel();
39 
40 	/**
41 	 * This signal is emitted when the player starts a new game.
42 	 *
43 	 * @param symmetry specify mirroring of givens
44 	 * @param difficulty specify how hard to make puzzle
45 	 */
46 	void generatePuzzle(int symmetry, int difficulty);
47 
48 	/**
49 	 * This signal is emitted when the player starts a custom game.
50 	 *
51 	 * @param givens the values chosen by the player to build the board
52 	 */
53 	void loadPuzzle(const std::array<int, 81>& givens);
54 
55 protected:
56 	/**
57 	 * Override parent function to start new game when enter is pressed.
58 	 */
59 	void keyPressEvent(QKeyEvent* event) override;
60 
61 private slots:
62 	/**
63 	 * Handles starting a player-entered game.
64 	 */
65 	void playGame();
66 
67 	/**
68 	 * Shows if player has entered givens that conflict with each other.
69 	 */
70 	void showConflicts();
71 
72 	/**
73 	 * Switches what settings are visible to the player.
74 	 *
75 	 * @param show if @c true, show the widgets for building a custom game
76 	 */
77 	void showCustom(bool show);
78 
79 private:
80 	QStackedWidget* m_contents; /**< contains widgets for computer games and player entered games */
81 	QPushButton* m_create_button; /**< button to show settings for a custom game */
82 	QPushButton* m_play_button; /**< button to start a custom game */
83 
84 	QListWidget* m_symmetry; /**< list of board symmetries */
85 	QList<QPushButton*> m_difficulty; /**< buttons to choose difficulty and start game */
86 	int m_current_difficulty; /**< the difficulty most recently chosen by the player */
87 
88 	QList<QLineEdit*> m_custom; /**< buttons to set the givens of a new game */
89 };
90 
91 #endif // SIMSU_NEW_GAME_PAGE_H
92