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
34namespace Illusions {
35
36class IllusionsEngine;
37
38class BaseMenuSystem;
39class BaseMenuAction;
40
41const uint kMenuTextSize = 4096;
42
43class MenuItem {
44public:
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; };
51protected:
52 Common::String _text;
53 BaseMenuAction *_action;
54 Common::Point _mouseClickPoint;
55};
56
57class BaseMenu {
58public:
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();
69public://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
80class MenuStack : public Common::Stack<BaseMenu*> {
81};
82
84
86public:
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;
115protected:
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
174public:
176 void appendString(const Common::String &value);
177 void appendNewLine();
178 void finalize();
179 uint16 *getText() { return _text; }
180protected:
181 uint16 _text[kMenuTextSize];
182 uint _pos;
183};
184
185// Menu actions
186
188public:
189 BaseMenuAction(BaseMenuSystem *menuSystem);
190 virtual ~BaseMenuAction() {}
191 virtual void execute() = 0;
192protected:
193 BaseMenuSystem *_menuSystem;
194};
195
196// Type 1: Enter a submenu
197
199public:
200 MenuActionEnterMenu(BaseMenuSystem *menuSystem, int menuId);
201 void execute() override;
202protected:
203 int _menuId;
204};
205
206// Type 4: Leave a submenu or the whole menu if on the main menu level
207
209public:
211 void execute() override;
212};
213
214// Type 5: Return a menu choice index and exit the menu
215
217public:
218 MenuActionReturnChoice(BaseMenuSystem *menuSystem, uint choiceIndex);
219 void execute() override;
220protected:
221 int _choiceIndex;
222};
223
224// Type 8: Return a menu choice index and exit the menu after displaying a query message
225
227public:
228 MenuActionEnterQueryMenu(BaseMenuSystem *menuSystem, int menuId, uint confirmationChoiceIndex);
229 void execute() override;
230protected:
231 int _menuId;
232 uint _confirmationChoiceIndex;
233};
234
236public:
237 MenuActionLoadGame(BaseMenuSystem *menuSystem, uint choiceIndex);
238 void execute() override;
239protected:
240 uint _choiceIndex;
241};
242
244public:
245 MenuActionSaveGame(BaseMenuSystem *menuSystem, uint choiceIndex);
246 void execute() override;
247protected:
248 uint _choiceIndex;
249};
250
251} // End of namespace Illusions
252
253#endif // ILLUSIONS_MENUSYSTEM_H
Definition: stack.h:102
Definition: str.h:59
Definition: menusystem.h:187
Definition: menusystem.h:57
Definition: menusystem.h:85
Definition: actor.h:180
Definition: illusions.h:92
Definition: menusystem.h:198
Definition: menusystem.h:226
Definition: menusystem.h:208
Definition: menusystem.h:235
Definition: menusystem.h:216
Definition: menusystem.h:243
Definition: menusystem.h:43
Definition: menusystem.h:80
Definition: menusystem.h:173
Definition: rect.h:144
Definition: graphics.h:44