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