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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef SKY_CONTROL_H
24 #define SKY_CONTROL_H
25 
26 
27 #include "common/events.h"
28 #include "common/scummsys.h"
29 #include "common/str-array.h"
30 
31 class OSystem;
32 namespace Common {
33 class SaveFileManager;
34 }
35 
36 namespace Sky {
37 
38 class Disk;
39 class Screen;
40 class Logic;
41 class Mouse;
42 class Text;
43 class MusicBase;
44 class Sound;
45 class SkyCompact;
46 struct Compact;
47 struct DataFileHeader;
48 struct MegaSet;
49 
50 #define MAX_SAVE_GAMES 999
51 #define MAX_TEXT_LEN 80
52 #define PAN_LINE_WIDTH 184
53 #define PAN_CHAR_HEIGHT 12
54 #define STATUS_WIDTH 146
55 #define MPNL_X 60  // Main Panel
56 #define MPNL_Y 10
57 
58 #define SPNL_X 20  // Save Panel
59 #define SPNL_Y 20
60 #define SP_HEIGHT 149
61 #define SP_TOP_GAP 12
62 #define SP_BOT_GAP 27
63 #define CROSS_SZ_X 27
64 #define CROSS_SZ_Y 22
65 
66 #define TEXT_FLAG_MASK (SF_ALLOW_SPEECH | SF_ALLOW_TEXT)
67 
68 #define GAME_NAME_X (SPNL_X + 18)				// x coordinate of game names
69 #define GAME_NAME_Y (SPNL_Y + SP_TOP_GAP)		// start y coord of game names
70 #define MAX_ON_SCREEN ((SP_HEIGHT - SP_TOP_GAP - SP_BOT_GAP) / PAN_CHAR_HEIGHT) // no of save games on screen
71 #define CP_PANEL 60400 // main panel sprite
72 
73 #define MAINPANEL 0
74 #define SAVEPANEL 1
75 
76 #define NO_MASK false
77 #define WITH_MASK true
78 
79 // resource's onClick routines
80 #define DO_NOTHING		0
81 #define REST_GAME_PANEL	1
82 #define SAVE_GAME_PANEL	2
83 #define SAVE_A_GAME		3
84 #define RESTORE_A_GAME	4
85 #define SP_CANCEL		5
86 #define SHIFT_DOWN_FAST	6
87 #define SHIFT_DOWN_SLOW	7
88 #define SHIFT_UP_FAST	8
89 #define SHIFT_UP_SLOW	9
90 #define SPEED_SLIDE		10
91 #define MUSIC_SLIDE		11
92 #define TOGGLE_FX		12
93 #define TOGGLE_MS		13
94 #define TOGGLE_TEXT		14
95 #define EXIT			15
96 #define RESTART			16
97 #define QUIT_TO_DOS		17
98 #define RESTORE_AUTO	18
99 
100 // onClick return codes
101 #define CANCEL_PRESSED	100
102 #define NAME_TOO_SHORT	101
103 #define GAME_SAVED		102
104 #define SHIFTED			103
105 #define TOGGLED			104
106 #define RESTARTED		105
107 #define GAME_RESTORED	106
108 #define RESTORE_FAILED	107
109 #define NO_DISK_SPACE	108
110 #define SPEED_CHANGED	109
111 #define QUIT_PANEL		110
112 
113 #define SLOW 0
114 #define FAST 1
115 
116 #define SPEED_MULTIPLY	12
117 
118 //-
119 #define SAVE_EXT	 1
120 #define SAVE_MEGA0	 2
121 #define SAVE_MEGA1	 4
122 #define SAVE_MEGA2	 8
123 #define SAVE_MEGA3	16
124 #define SAVE_GRAFX	32
125 #define SAVE_TURNP	64
126 
127 #define SAVE_FILE_REVISION 6
128 #define OLD_SAVEGAME_TYPE 5
129 
130 struct AllocedMem {
131 	uint16 *mem;
132 	AllocedMem *next;
133 };
134 
135 class ConResource {
136 public:
137 	ConResource(void *pSpData, uint32 pNSprites, uint32 pCurSprite, uint16 pX, uint16 pY, uint32 pText, uint8 pOnClick, OSystem *system, uint8 *screen);
~ConResource()138 	virtual ~ConResource() {}
setSprite(void * pSpData)139 	void setSprite(void *pSpData) { _spriteData = (DataFileHeader *)pSpData; }
setText(uint32 pText)140 	void setText(uint32 pText) { if (pText) _text = pText + 0x7000; else _text = 0; }
setXY(uint16 x,uint16 y)141 	void setXY(uint16 x, uint16 y) { _x = x; _y = y; }
142 	bool isMouseOver(uint32 mouseX, uint32 mouseY);
143 	virtual void drawToScreen(bool doMask);
144 
145 	DataFileHeader *_spriteData;
146 	uint32 _numSprites, _curSprite;
147 	uint16 _x, _y;
148 	uint32 _text;
149 	uint8 _onClick;
150 	OSystem *_system;
151 	uint8 *_screen;
152 private:
153 };
154 
155 class TextResource : public ConResource {
156 public:
157 	TextResource(void *pSpData, uint32 pNSprites, uint32 pCurSprite, uint16 pX, uint16 pY, uint32 pText, uint8 pOnClick, OSystem *system, uint8 *screen);
158 	virtual ~TextResource();
159 	virtual void drawToScreen(bool doMask);
160 	void flushForRedraw();
161 private:
162 	uint16 _oldX, _oldY;
163 	uint8 *_oldScreen;
164 };
165 
166 class ControlStatus {
167 public:
168 	ControlStatus(Text *skyText, OSystem *system, uint8 *scrBuf);
169 	~ControlStatus();
170 	void setToText(const char *newText);
171 	void setToText(uint16 textNum);
172 	void drawToScreen();
173 private:
174 	TextResource *_statusText;
175 	DataFileHeader *_textData;
176 	Text *_skyText;
177 	OSystem *_system;
178 	uint8 *_screenBuf;
179 };
180 
181 class Control {
182 public:
183 	Control(Common::SaveFileManager *saveFileMan, Screen *screen, Disk *disk, Mouse *mouse, Text *text, MusicBase *music, Logic *logic, Sound *sound, SkyCompact *skyCompact, OSystem *system);
184 	void doControlPanel();
185 	void doLoadSavePanel();
186 	void restartGame();
187 	void showGameQuitMsg();
188 	void doAutoSave();
189 	uint16 quickXRestore(uint16 slot);
190 	bool loadSaveAllowed();
191 
192 	uint16 _selectedGame;
193 	uint16 saveGameToFile(bool fromControlPanel, const char *filename = 0);
194 
195 	void loadDescriptions(Common::StringArray &list);
196 	void saveDescriptions(const Common::StringArray &list);
197 
198 private:
199 	int displayMessage(const char *altButton, const char *message, ...) GCC_PRINTF(3, 4);
200 
201 	void initPanel();
202 	void removePanel();
203 
204 	void drawMainPanel();
205 
206 	/**
207 	 * Waits for a specified amount while still processing events.
208 	 *
209 	 * @param amount The duration in milliseconds to wait
210 	 */
211 	void delay(unsigned int amount);
212 
213 	void animClick(ConResource *pButton);
214 	bool getYesNo(char *text);
215 	void buttonControl(ConResource *pButton);
216 	uint16 handleClick(ConResource *pButton);
217 	uint16 doMusicSlide();
218 	uint16 doSpeedSlide();
219 	void toggleFx(ConResource *pButton);
220 	uint16 toggleText();
221 	void toggleMusic(ConResource *pButton);
222 	uint16 shiftDown(uint8 speed);
223 	uint16 shiftUp(uint8 speed);
224 	void drawTextCross(uint32 flags);
225 	void drawCross(uint16 x, uint16 y);
226 
227 	uint16 saveRestorePanel(bool allowSave);
228 	void setUpGameSprites(const Common::StringArray &saveGameNames, DataFileHeader **nameSprites, uint16 firstNum, uint16 selectedGame);
229 	void showSprites(DataFileHeader **nameSprites, bool allowSave);
230 	void handleKeyPress(Common::KeyState kbd, Common::String &textBuf);
231 
232 	uint32 prepareSaveData(uint8 *destBuf);
233 
234 	bool autoSaveExists();
235 	uint16 restoreGameFromFile(bool autoSave);
236 	void importOldMegaSet(uint8 **srcPos, MegaSet *mega);
237 	void importOldCompact(Compact* destCpt, uint8 **srcPos, uint16 numElems, uint16 type, char *name);
238 	uint16 parseSaveData(uint8 *srcBuf);
239 
240 	Common::SaveFileManager *_saveFileMan;
241 	SkyCompact *_skyCompact;
242 	Screen *_skyScreen;
243 	Disk *_skyDisk;
244 	Mouse *_skyMouse;
245 	Text *_skyText;
246 	MusicBase *_skyMusic;
247 	Logic *_skyLogic;
248 	Sound *_skySound;
249 	OSystem *_system;
250 	bool _mouseClicked;
251 	Common::KeyState _keyPressed;
252 	int _mouseWheel;
253 
254 	struct {
255 		uint8 *controlPanel;
256 		uint8 *button;
257 		uint8 *buttonDown;
258 		uint8 *savePanel;
259 		uint8 *yesNo;
260 		uint8 *slide;
261 		uint8 *slode;
262 		uint8 *slode2;
263 		uint8 *slide2;
264 		uint8 *musicBodge;
265 	} _sprites;
266 
267 	uint8 *_screenBuf;
268 	int _lastButton;
269 	uint32 _curButtonText;
270 	uint16 _firstText;
271 	uint16 _savedMouse;
272 	uint32 _savedCharSet;
273 	uint16 _enteredTextWidth;
274 
275 	ConResource *createResource(void *pSpData, uint32 pNSprites, uint32 pCurSprite, int16 pX, int16 pY, uint32 pText, uint8 pOnClick, uint8 panelType);
276 
277 	DataFileHeader *_textSprite;
278 	TextResource *_text;
279 
280 	ConResource *_controlPanel, *_exitButton, *_slide, *_slide2, *_slode;
281 	ConResource *_restorePanButton, *_savePanButton, *_dosPanButton, *_restartPanButton, *_fxPanButton, *_musicPanButton;
282 	ConResource *_bodge, *_yesNo;
283 	ConResource *_controlPanLookList[9];
284 
285 	//- Save/restore panel
286 	ConResource *_savePanel;
287 	ConResource *_saveButton, *_downFastButton, *_downSlowButton;
288 	ConResource *_upFastButton, *_upSlowButton, *_quitButton, *_restoreButton;
289 	ConResource *_autoSaveButton;
290 
291 	ConResource *_savePanLookList[6], *_restorePanLookList[7];
292 
293 	ControlStatus *_statusBar;
294 
295 	static char _quitTexts[18][35];
296 	static uint8 _crossImg[594];
297 };
298 
299 } // End of namespace Sky
300 
301 #endif // CONTROL_H
302