Debian Codegraph @

src/game/MTFH/menumanager.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2015 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef MENUMANAGER_HPP
17 #define MENUMANAGER_HPP
18
19 #include <chrono>
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <vector>
24
25 namespace MTFH {
26
27 class Menu;
28
29 using MenuPtr = std::shared_ptr<Menu>;
30
31 //! The singleton MenuManager manages menus.
32 class MenuManager
33 {
34 public:
35 //! Constructor.
36 MenuManager();
37
38 //! Returns the active menu or nullptr.
39 MenuPtr activeMenu() const;
40
41 //! Add the given menu.
42 void addMenu(MenuPtr newMenu);
43
44 //! Returns matching menu or explode.
45 MenuPtr getMenuById(std::string menuId);
46
47 //! Enter the given menu & clear the menu stack.
48 void enterMenu(MenuPtr newMenu);
49
50 //! Enter the given menu & clear the menu stack.
51 void enterMenu(std::string menuId);
52
53 //! Enter the given menu & push to stack.
54 void pushMenu(MenuPtr newMenu);
55
56 //! Enter the given menu & push to stack.
57 void pushMenu(std::string menuId);
58
59 //! Force exit on current menu and enter the previous menu.
60 void popMenu();
61
62 //! Force exit on current menu and enter the given menu.
63 void popToMenu(std::string menuId);
64
65 //! Force enter on current menu.
66 void enterCurrentMenu();
67
68 //! Force exit on all menus.
69 void exit();
70
71 //! Render the menu.
72 void render();
73
74 //! Selection up.
75 void up();
76
77 //! Selection down.
78 void down();
79
80 //! Current item left.
81 void left();
82
83 //! Current item right.
84 void right();
85
86 //! Select the current item.
87 void selectCurrentItem();
88
89 //! Give a time tick to the whole menu tree.
90 void stepTime(std::chrono::milliseconds timeStep);
91
92 /*! Handle mouse press at given screen coordinates.
93 * \return true if on a valid item. */
94 bool mousePress(int x, int y, int screenWidth, int screenHeight);
95
96 /*! Handle mouse release at given screen coordinates.
97 * \return true if on a valid item. */
98 bool mouseRelease(int x, int y, int screenWidth, int screenHeight);
99
100 //! \returns true when done.
101 bool isDone() const;
102
103 static MenuManager & instance();
104
105 private:
106 std::map<std::string, MenuPtr> m_idToMenuMap;
107
108 std::vector<MenuPtr> m_menuStack;
109
110 MenuPtr m_prevMenu;
111
112 static MenuManager * m_instance;
113 };
114
115 } // namespace MTFH
116
117 #endif // MENUMANAGER_HPP