aboutsummaryrefslogtreecommitdiff
path: root/engines/illusions/menusystem.h
blob: 26a5931d18e34e3c40f059a64a930135d4908222 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef ILLUSIONS_MENUSYSTEM_H
#define ILLUSIONS_MENUSYSTEM_H

#include "illusions/actor.h"
#include "illusions/graphics.h"
#include "illusions/resources/fontresource.h"
#include "common/array.h"
#include "common/rect.h"
#include "common/stack.h"
#include "common/str.h"
#include "graphics/surface.h"

namespace Illusions {

class IllusionsEngine;

class BaseMenuSystem;
class BaseMenuAction;

const uint kMenuTextSize = 4096;

class MenuItem {
public:
	MenuItem(const Common::String text, BaseMenuAction *action);
	~MenuItem();
	void executeAction();
	const Common::String& getText() const { return _text; }
protected:
	Common::String _text;
	BaseMenuAction *_action;
};

class BaseMenu {
public:
	BaseMenu(BaseMenuSystem *menuSystem, uint32 fontId, byte field8, byte fieldA, byte fieldC, byte fieldE,
		uint defaultMenuItemIndex);
	virtual ~BaseMenu();
	void addText(const Common::String text);
	void addMenuItem(MenuItem *menuItem);
	uint getHeaderLinesCount();
	const Common::String& getHeaderLine(uint index);
	uint getMenuItemsCount();
	MenuItem *getMenuItem(uint index);
	virtual void enterMenu();
public://protected://TODO
	typedef Common::Array<MenuItem*> MenuItems;
	BaseMenuSystem *_menuSystem;
	uint32 _fontId;
	byte _field8, _fieldA, _fieldC, _fieldE;
	uint _field2C18;
	uint _defaultMenuItemIndex;
	Common::Array<Common::String> _text;
	MenuItems _menuItems;
};

class MenuStack : public Common::Stack<BaseMenu*> {
};

typedef Common::Array<int16> MenuChoiceOffsets;

class BaseMenuSystem {
public:
	BaseMenuSystem(IllusionsEngine *vm);
	virtual ~BaseMenuSystem();
	void playSoundEffect13();
	void playSoundEffect14();
	void selectMenuChoiceIndex(uint choiceIndex);
	void leaveMenu();
	void enterSubMenu(BaseMenu *menu);
	void leaveSubMenu();
	void enterSubMenuById(int menuId);
	uint getQueryConfirmationChoiceIndex() const;
	void setQueryConfirmationChoiceIndex(uint queryConfirmationChoiceIndex);
	bool isActive() const { return _isActive; }
	void openMenu(BaseMenu *menu);
	void closeMenu();
	void handleClick(uint menuItemIndex, const Common::Point &mousePos);
	uint drawMenuText(BaseMenu *menu);
	void update(Control *cursorControl);
	void setTimeOutDuration(uint32 duration, uint timeOutMenuChoiceIndex);
	void setMenuCallerThreadId(uint32 menuCallerThreadId);
	void setMenuChoiceOffsets(MenuChoiceOffsets menuChoiceOffsets, int16 *menuChoiceOffset);
	void setSavegameSlotNum(int slotNum);
	virtual bool initMenuCursor() = 0;
	virtual int getGameState() = 0;
	virtual void setGameState(int gameState) = 0;
	virtual void setMenuCursorNum(int cursorNum) = 0;
protected:
	IllusionsEngine *_vm;
	MenuStack _menuStack;
	
	uint32 _menuCallerThreadId;
    bool _isTimeOutEnabled;
    bool _isTimeOutReached;
    uint32 _timeOutDuration;
    uint _timeOutMenuChoiceIndex;
    uint32 _timeOutStartTime;
    uint32 _timeOutEndTime;
	
	Common::Point _savedCursorPos;
	bool _cursorInitialVisibleFlag;
	int _savedGameState;
	int _savedCursorActorIndex;
	int _savedCursorSequenceId;
	
	bool _isActive;
	
	MenuChoiceOffsets _menuChoiceOffsets;
	int16 *_menuChoiceOffset;
	
	uint _queryConfirmationChoiceIndex;
	
	uint _field54;
	uint _menuLinesCount;
	uint _menuItemCount;
	
	uint _hoveredMenuItemIndex;
	uint _hoveredMenuItemIndex2;
	uint _hoveredMenuItemIndex3;

	BaseMenu *_activeMenu;
	void setMouseCursorToMenuItem(int menuItemIndex);
	
	void calcMenuItemRect(uint menuItemIndex, WRect &rect);
	bool calcMenuItemMousePos(uint menuItemIndex, Common::Point &pt);
	bool calcMenuItemIndexAtPoint(Common::Point pt, uint &menuItemIndex);
	void setMousePos(Common::Point &mousePos);
	
	void activateMenu(BaseMenu *menu);
	
	void updateTimeOut(bool resetTimeOut);
	
	void initActor318();
	void placeActor318();
	void updateActor318();
	void hideActor318();
	
	void initActor323();
	void placeActor323();
	void hideActor323();
	
	virtual BaseMenu *getMenuById(int menuId) = 0;
};

/*


*/

class MenuTextBuilder {	
public:
	MenuTextBuilder();
	void appendString(const Common::String &value);
	void appendNewLine();
	void finalize();
	uint16 *getText() { return _text; }
protected:
	uint16 _text[kMenuTextSize];
	uint _pos;
};

// Menu actions

class BaseMenuAction {
public:
	BaseMenuAction(BaseMenuSystem *menuSystem);
	virtual ~BaseMenuAction() {}
	virtual void execute() = 0;
protected:
	BaseMenuSystem *_menuSystem;
};

// Type 1: Enter a submenu

class MenuActionEnterMenu : public BaseMenuAction {
public:
	MenuActionEnterMenu(BaseMenuSystem *menuSystem, int menuId);
	virtual void execute();
protected:
	int _menuId;
};

// Type 4: Leave a submenu or the whole menu if on the main menu level

class MenuActionLeaveMenu : public BaseMenuAction {
public:
	MenuActionLeaveMenu(BaseMenuSystem *menuSystem);
	virtual void execute();
};

// Type 5: Return a menu choice index and exit the menu

class MenuActionReturnChoice : public BaseMenuAction {
public:
	MenuActionReturnChoice(BaseMenuSystem *menuSystem, uint choiceIndex);
	virtual void execute();
protected:
	int _choiceIndex;
};

// Type 8: Return a menu choice index and exit the menu after displaying a query message

class MenuActionEnterQueryMenu : public BaseMenuAction {
public:
	MenuActionEnterQueryMenu(BaseMenuSystem *menuSystem, int menuId, uint confirmationChoiceIndex);
	virtual void execute();
protected:
	int _menuId;
	uint _confirmationChoiceIndex;
};

class MenuActionLoadGame : public BaseMenuAction {
public:
	MenuActionLoadGame(BaseMenuSystem *menuSystem, uint choiceIndex);
	virtual void execute();
protected:
	uint _choiceIndex;
};

} // End of namespace Illusions

#endif // ILLUSIONS_MENUSYSTEM_H