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 
30 class OSystem;
31 namespace Common {
32 class SaveFileManager;
33 }
34 
35 namespace Sky {
36 
37 class Disk;
38 class Screen;
39 class Logic;
40 class Mouse;
41 class Text;
42 class MusicBase;
43 class Sound;
44 class SkyCompact;
45 class SkyEngine;
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);
138  virtual ~ConResource() {}
139  void setSprite(void *pSpData) { _spriteData = (DataFileHeader *)pSpData; }
140  void setText(uint32 pText) { if (pText) _text = pText + 0x7000; else _text = 0; }
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  ~TextResource() override;
159  void drawToScreen(bool doMask) override;
160  void flushForRedraw();
161 private:
162  uint16 _oldX, _oldY;
163  uint8 *_oldScreen;
164 };
165 
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(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);
184  void doControlPanel();
185  void doLoadSavePanel();
186  void restartGame();
187  void showGameQuitMsg();
188  uint16 quickXRestore(uint16 slot);
189  bool loadSaveAllowed();
190  bool isControlPanelOpen();
191 
192  SkyEngine *_vm;
193 
194  uint16 _selectedGame;
195  uint16 saveGameToFile(bool fromControlPanel, const char *filename = 0, bool isAutosave = false);
196 
197  void loadDescriptions(Common::StringArray &list);
198  void saveDescriptions(const Common::StringArray &list);
199 
200 private:
201  int displayMessage(const char *altButton, MSVC_PRINTF const char *message, ...) GCC_PRINTF(3, 4);
202 
203  void initPanel();
204  void removePanel();
205 
206  void drawMainPanel();
207 
213  void delay(unsigned int amount);
214 
215  void animClick(ConResource *pButton);
216  bool getYesNo(char *text, uint bufSize);
217  void buttonControl(ConResource *pButton);
218  uint16 handleClick(ConResource *pButton);
219  uint16 doMusicSlide();
220  uint16 doSpeedSlide();
221  void toggleFx(ConResource *pButton);
222  uint16 toggleText();
223  void toggleMusic(ConResource *pButton);
224  uint16 shiftDown(uint8 speed);
225  uint16 shiftUp(uint8 speed);
226  void drawTextCross(uint32 flags);
227  void drawCross(uint16 x, uint16 y);
228 
229  uint16 saveRestorePanel(bool allowSave);
230  void setUpGameSprites(const Common::StringArray &saveGameNames, DataFileHeader **nameSprites, uint16 firstNum, uint16 selectedGame, const Common::String &dirtyString);
231  void showSprites(DataFileHeader **nameSprites, bool allowSave);
232  void handleKeyPress(Common::KeyState kbd, Common::String &textBuf);
233 
234  uint32 prepareSaveData(uint8 *destBuf);
235 
236  bool autoSaveExists();
237  uint16 restoreGameFromFile(bool autoSave);
238  void importOldMegaSet(uint8 **srcPos, MegaSet *mega);
239  void importOldCompact(Compact* destCpt, uint8 **srcPos, uint16 numElems, uint16 type, char *name);
240  uint16 parseSaveData(uint8 *srcBuf);
241 
242  Common::SaveFileManager *_saveFileMan;
243  SkyCompact *_skyCompact;
244  Screen *_skyScreen;
245  Disk *_skyDisk;
246  Mouse *_skyMouse;
247  Text *_skyText;
248  MusicBase *_skyMusic;
249  Logic *_skyLogic;
250  Sound *_skySound;
251  OSystem *_system;
252  bool _mouseClicked;
253  Common::KeyState _keyPressed;
254  Common::CustomEventType _action;
255  int _mouseWheel;
256  Common::Keymap *_shortcutsKeymap;
257 
258  struct {
259  uint8 *controlPanel;
260  uint8 *button;
261  uint8 *buttonDown;
262  uint8 *savePanel;
263  uint8 *yesNo;
264  uint8 *slide;
265  uint8 *slode;
266  uint8 *slode2;
267  uint8 *slide2;
268  uint8 *musicBodge;
269  } _sprites;
270 
271  uint8 *_screenBuf;
272  int _lastButton;
273  uint32 _curButtonText;
274  uint16 _firstText;
275  uint16 _savedMouse;
276  uint32 _savedCharSet;
277  uint16 _enteredTextWidth;
278 
279  ConResource *createResource(void *pSpData, uint32 pNSprites, uint32 pCurSprite, int16 pX, int16 pY, uint32 pText, uint8 pOnClick, uint8 panelType);
280 
281  DataFileHeader *_textSprite;
282  TextResource *_text;
283 
284  ConResource *_controlPanel, *_exitButton, *_slide, *_slide2, *_slode;
285  ConResource *_restorePanButton, *_savePanButton, *_dosPanButton, *_restartPanButton, *_fxPanButton, *_musicPanButton;
286  ConResource *_bodge, *_yesNo;
287  ConResource *_controlPanLookList[9];
288 
289  //- Save/restore panel
290  ConResource *_savePanel;
291  ConResource *_saveButton, *_downFastButton, *_downSlowButton;
292  ConResource *_upFastButton, *_upSlowButton, *_quitButton, *_restoreButton;
293  ConResource *_autoSaveButton;
294 
295  ConResource *_savePanLookList[6], *_restorePanLookList[7];
296 
297  ControlStatus *_statusBar;
298 
299  static char _quitTexts[18][35];
300  static uint8 _crossImg[594];
301 };
302 
303 } // End of namespace Sky
304 
305 #endif // CONTROL_H
Definition: keymap.h:66
Definition: logic.h:133
Definition: control.h:135
Definition: str.h:59
Definition: struc.h:78
Definition: sky.h:76
Definition: musicbase.h:50
Definition: default_display_client.h:78
uint32 CustomEventType
Definition: events.h:192
Definition: disk.h:37
Definition: struc.h:35
Definition: control.h:155
Definition: struc.h:59
int FORCEINLINE GCC_PRINTF(2, 0) int vsprintf_s(T(&dst)[N]
Definition: control.h:166
Definition: algorithm.h:29
Definition: screen.h:56
Definition: sound.h:47
Definition: keyboard.h:294
Definition: mouse.h:36
Definition: savefile.h:142
Definition: text.h:48
Definition: system.h:175
Definition: compact.h:58
Definition: autoroute.h:28
Definition: control.h:181
Definition: control.h:130