ScummVM API documentation
menusystem.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ILLUSIONS_MENUSYSTEM_H
23 #define ILLUSIONS_MENUSYSTEM_H
24 
25 #include "illusions/actor.h"
26 #include "illusions/graphics.h"
27 #include "illusions/resources/fontresource.h"
28 #include "common/array.h"
29 #include "common/rect.h"
30 #include "common/stack.h"
31 #include "common/str.h"
32 #include "graphics/surface.h"
33 
34 namespace Illusions {
35 
36 class IllusionsEngine;
37 
38 class BaseMenuSystem;
39 class BaseMenuAction;
40 
41 const uint kMenuTextSize = 4096;
42 
43 class MenuItem {
44 public:
45  MenuItem(const Common::String text, BaseMenuAction *action);
46  ~MenuItem();
47  void executeAction(const Common::Point &point);
48  const Common::String& getText() const { return _text; }
49  void setText(const Common::String &text) { _text = text; }
50  const Common::Point& getMouseClickPoint() { return _mouseClickPoint; };
51 protected:
52  Common::String _text;
53  BaseMenuAction *_action;
54  Common::Point _mouseClickPoint;
55 };
56 
57 class BaseMenu {
58 public:
59  BaseMenu(BaseMenuSystem *menuSystem, uint32 fontId, byte backgroundColor, byte borderColor, byte textColor, byte fieldE,
60  uint defaultMenuItemIndex);
61  virtual ~BaseMenu();
62  void addText(const Common::String text);
63  void addMenuItem(MenuItem *menuItem);
64  uint getHeaderLinesCount();
65  const Common::String& getHeaderLine(uint index);
66  uint getMenuItemsCount();
67  MenuItem *getMenuItem(uint index);
68  virtual void enterMenu();
69 public://protected://TODO
71  BaseMenuSystem *_menuSystem;
72  uint32 _fontId;
73  byte _backgroundColor, _borderColor, _textColor, _fieldE;
74  uint _field2C18;
75  uint _defaultMenuItemIndex;
77  MenuItems _menuItems;
78 };
79 
80 class MenuStack : public Common::Stack<BaseMenu*> {
81 };
82 
84 
86 public:
88  virtual ~BaseMenuSystem();
89  void playSoundEffect13();
90  void playSoundEffect14();
91  void selectMenuChoiceIndex(uint choiceIndex);
92  void leaveMenu();
93  void enterSubMenu(BaseMenu *menu);
94  void leaveSubMenu();
95  void enterSubMenuById(int menuId);
96  uint getQueryConfirmationChoiceIndex() const;
97  void setQueryConfirmationChoiceIndex(uint queryConfirmationChoiceIndex);
98  bool isActive() const { return _isActive; }
99  void openMenu(BaseMenu *menu);
100  void closeMenu();
101  void handleClick(uint menuItemIndex, const Common::Point &mousePos);
102  uint drawMenuText(BaseMenu *menu);
103  void redrawMenuText(BaseMenu *menu);
104  void update(Control *cursorControl);
105  void setTimeOutDuration(uint32 duration, uint timeOutMenuChoiceIndex);
106  void setMenuCallerThreadId(uint32 menuCallerThreadId);
107  void setMenuChoiceOffsets(MenuChoiceOffsets menuChoiceOffsets, int16 *menuChoiceOffset);
108  void setSavegameSlotNum(int slotNum);
109  void setSavegameDescription(Common::String desc);
110  bool calcMenuItemTextPositionAtPoint(Common::Point pt, int &offset);
111  virtual bool initMenuCursor() = 0;
112  virtual int getGameState() = 0;
113  virtual void setGameState(int gameState) = 0;
114  virtual void setMenuCursorNum(int cursorNum) = 0;
115 protected:
116  IllusionsEngine *_vm;
117  MenuStack _menuStack;
118 
119  uint32 _menuCallerThreadId;
120  bool _isTimeOutEnabled;
121  bool _isTimeOutReached;
122  uint32 _timeOutDuration;
123  uint _timeOutMenuChoiceIndex;
124  uint32 _timeOutStartTime;
125  uint32 _timeOutEndTime;
126 
127  Common::Point _savedCursorPos;
128  bool _cursorInitialVisibleFlag;
129  int _savedGameState;
130  int _savedCursorActorIndex;
131  int _savedCursorSequenceId;
132 
133  bool _isActive;
134 
135  MenuChoiceOffsets _menuChoiceOffsets;
136  int16 *_menuChoiceOffset;
137 
138  uint _queryConfirmationChoiceIndex;
139 
140  uint _field54;
141  uint _menuLinesCount;
142  uint _menuItemCount;
143 
144  uint _hoveredMenuItemIndex;
145  uint _hoveredMenuItemIndex2;
146  uint _hoveredMenuItemIndex3;
147 
148  BaseMenu *_activeMenu;
149  void setMouseCursorToMenuItem(int menuItemIndex);
150 
151  void calcMenuItemRect(uint menuItemIndex, WRect &rect);
152  bool calcMenuItemMousePos(uint menuItemIndex, Common::Point &pt);
153  bool calcMenuItemIndexAtPoint(Common::Point pt, uint &menuItemIndex);
154  void setMousePos(Common::Point &mousePos);
155 
156  void activateMenu(BaseMenu *menu);
157 
158  void updateTimeOut(bool resetTimeOut);
159 
160  void initActorHoverBackground();
161  void placeActorHoverBackground();
162  void updateActorHoverBackground();
163  void hideActorHoverBackground();
164 
165  void initActorTextColorRect();
166  void placeActorTextColorRect();
167  void hideActorTextColorRect();
168 
169  virtual BaseMenu *getMenuById(int menuId) = 0;
170  virtual void playSoundEffect(int sfxId) = 0;
171 };
172 
174 public:
175  MenuTextBuilder();
176  void appendString(const Common::String &value);
177  void appendNewLine();
178  void finalize();
179  uint16 *getText() { return _text; }
180 protected:
181  uint16 _text[kMenuTextSize];
182  uint _pos;
183 };
184 
185 // Menu actions
186 
188 public:
189  BaseMenuAction(BaseMenuSystem *menuSystem);
190  virtual ~BaseMenuAction() {}
191  virtual void execute() = 0;
192 protected:
193  BaseMenuSystem *_menuSystem;
194 };
195 
196 // Type 1: Enter a submenu
197 
199 public:
200  MenuActionEnterMenu(BaseMenuSystem *menuSystem, int menuId);
201  void execute() override;
202 protected:
203  int _menuId;
204 };
205 
206 // Type 4: Leave a submenu or the whole menu if on the main menu level
207 
209 public:
210  MenuActionLeaveMenu(BaseMenuSystem *menuSystem);
211  void execute() override;
212 };
213 
214 // Type 5: Return a menu choice index and exit the menu
215 
217 public:
218  MenuActionReturnChoice(BaseMenuSystem *menuSystem, uint choiceIndex);
219  void execute() override;
220 protected:
221  int _choiceIndex;
222 };
223 
224 // Type 8: Return a menu choice index and exit the menu after displaying a query message
225 
227 public:
228  MenuActionEnterQueryMenu(BaseMenuSystem *menuSystem, int menuId, uint confirmationChoiceIndex);
229  void execute() override;
230 protected:
231  int _menuId;
232  uint _confirmationChoiceIndex;
233 };
234 
236 public:
237  MenuActionLoadGame(BaseMenuSystem *menuSystem, uint choiceIndex);
238  void execute() override;
239 protected:
240  uint _choiceIndex;
241 };
242 
244 public:
245  MenuActionSaveGame(BaseMenuSystem *menuSystem, uint choiceIndex);
246  void execute() override;
247 protected:
248  uint _choiceIndex;
249 };
250 
251 } // End of namespace Illusions
252 
253 #endif // ILLUSIONS_MENUSYSTEM_H
Definition: menusystem.h:216
Definition: menusystem.h:57
Definition: graphics.h:44
Definition: str.h:59
Definition: menusystem.h:243
Definition: menusystem.h:85
Definition: menusystem.h:80
Definition: menusystem.h:187
Definition: actor.h:34
Definition: menusystem.h:173
Definition: menusystem.h:43
Definition: menusystem.h:198
Definition: rect.h:45
Definition: menusystem.h:226
Definition: menusystem.h:208
Definition: menusystem.h:235
Definition: actor.h:180
Definition: stack.h:102
Definition: illusions.h:92