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 SWORD1_CONTROL_H
23 #define SWORD1_CONTROL_H
24 
25 #include "common/scummsys.h"
26 #include "common/events.h"
27 #include "common/str-array.h"
28 #include "sword1/sworddefs.h"
29 
30 class OSystem;
31 namespace Common {
32 class SaveFileManager;
33 class MemoryWriteStreamDynamic;
34 }
35 
36 namespace Sword1 {
37 
38 enum SNRStatus {
39  SNR_BLANK = 0,
40  SNR_MAINPANEL,
41  SNR_SAVE,
42  SNR_RESTORE,
43  SNR_RESTART,
44  SNR_QUIT,
45  SNR_SPEED,
46  SNR_VOLUME,
47  SNR_SUBTITLES,
48  SNR_DONE,
49  SNR_DRIVEFULL = 99
50 };
51 
52 enum SaveGameFlags {
53  SGF_DONE = 0,
54  SGF_SAVE,
55  SGF_RESTORE,
56  SGF_RESTART,
57  SGF_QUIT
58 };
59 
60 enum PsxComponents {
61  PSX_PANEL = 0,
62  PSX_DEATHPANEL,
63  PSX_CONFIRM,
64  PSX_BUTTON,
65  PSX_TEXT,
66  PSX_SLAB,
67  PSX_SCROLL
68 };
69 
70 class SwordEngine;
71 class ObjectMan;
72 class ResMan;
73 class Mouse;
74 class Sound;
75 class Screen;
76 class Logic;
77 
78 #define SAVEGAME_HEADER MKTAG('B','S','_','1')
79 #define SAVEGAME_VERSION 2
80 
81 #define FIRSTFONTCHAR ' '
82 #define LASTFONTCHAR (32 + 137)
83 #define CR 13
84 #define LF 10
85 #define ESCAPE 27
86 #define BACKSPACE 8
87 
88 #define CONTROL_NOTHING_DONE 0
89 #define CONTROL_GAME_RESTORED 1
90 #define CONTROL_RESTART_GAME 2
91 
92 #define VD1X 139
93 #define VD2X 273
94 #define VD3X 404
95 #define VDY 94
96 
97 #define SCROLL1X 311
98 #define SCROLL1Y 124
99 #define SCROLL2X 311
100 #define SCROLL2Y 188
101 
102 #define SAVEBUTTONS 14
103 #define MAXSAVEGAMES 1000
104 #define OVERLAP 3
105 #define SP_OVERLAP 2
106 #define TEXTBUTTONID 7
107 
108 #define PSX_CREDITS_SPACING (-3)
109 #define PSX_CREDITS_MIDDLE 450
110 #define PSX_CREDITS_OFFSET 150
111 #define PSX_NUM_CREDITS 14
112 
113 struct Button {
114  int32 x1;
115  int32 y1;
116  int32 x2;
117  int32 y2;
118 };
119 
120 class Control {
121 public:
122  Control(SwordEngine *vm, Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Screen *pScreen, Logic *pLogic);
123 
124  void getPlayerOptions();
125  void askForCdMessage(uint32 needCD, bool incorrectCDPhase);
126  void doRestore();
127  bool savegamesExist();
128  void saveGameToFile(uint8 slot);
129  bool restoreGameFromFile(uint8 slot);
130  bool restoreGame();
131  void checkForOldSaveGames();
132  bool isPanelShown();
133  const uint8 *getPauseString();
134  void psxEndCredits();
135 
136  void setSaveDescription(int slot, const char *desc) {
137  Common::strcpy_s((char *)_fileDescriptions[slot], sizeof(_fileDescriptions[slot]), desc);
138  }
139 
140 private:
141  void saveRestoreScreen();
142 
143  void renderSlab(int32 start, int32 i);
144  void renderSlabs();
145  void renderText(const uint8 *str, int32 x, int32 y, bool useSpeechFont = false);
146  void renderRedText(const uint8 *str, int32 x, int32 y);
147  void renderTexts();
148  int32 getTextLength(const uint8 *str, bool useSpeechFont = false);
149 
150  void putButton(int32 x, int32 y, int32 index);
151  void putSpriteButton(Sprite *spr, int32 x, int32 y, int32 index);
152  void putTextButton(int32 index);
153  int32 getCurrentButton(const Button b[]);
154 
155  void initialiseConfirmation(const uint8 *title);
156  int32 implementConfirmation();
157  void removeConfirmation();
158 
159  void volUp(int32 i, int32 j);
160  void volDown(int32 i, int32 j);
161  void renderVolumeLight(int32 i);
162  void renderVolumeDisc(int32 i, int32 j);
163  void initialiseVolume();
164  void implementVolume();
165  void removeVolume();
166 
167  void renderScrolls();
168  void initialiseSpeed();
169  void implementSpeed();
170  void removeSpeed();
171 
172  int16 readFileDescriptions();
173  void setEditDescription(int32 line);
174  bool driveSpaceAvailable();
175  bool attemptSave();
176  bool saveGame();
177  void editDescription();
178  void restoreSelected();
179  void uneditDescription();
180  void initialiseSave();
181  void implementSave();
182  void removeSave();
183 
184  void initialiseRestore();
185  void implementRestore();
186  void removeRestore();
187 
188  void initialiseControlPanel();
189  void implementControlPanel();
190  void removeControlPanel();
191 
192  void initialiseResources();
193  void releaseResources();
194 
195  uint8 *decompressPsxGfx(uint8 *src, FrameHeader *f);
196  void drawPsxComponent(int componentType, uint8 *src, uint8 *dst, FrameHeader *f);
197 
198  bool convertSaveGame(uint8 slot, char *desc);
199 
200  void delay(uint32 msecs);
201  bool gameVersionIsAkella();
202  bool gameVersionIsMediaHouse();
203  bool loadCustomStrings(const char *filename);
204 
205  int displayMessage(const char *altButton, MSVC_PRINTF const char *message, ...) GCC_PRINTF(3, 4);
206 
207  // PSX Credits functions
208  int32 getCreditsFontHeight(uint8 *font);
209  int32 getCreditsStringLength(uint8 *str, uint8 *font);
210  void renderCreditsTextSprite(uint8 *data, uint8 *dst, int16 x, int16 y, int16 width, int16 height);
211  void createCreditsTextSprite(uint8 *data, int32 pitch, uint8 *str, uint8 *font);
212 
213  Common::MemoryWriteStreamDynamic *_tempThumbnail;
214  static const uint8 _languageStrings[8 * 20][43];
215  static const uint8 _akellaLanguageStrings[20][43];
216  static const uint8 _mediaHouseLanguageStrings[20][43];
217  static const uint8 _polishTranslationLanguageStrings[20][43];
218  uint8 _customStrings[20][43];
219  const uint8(*_lStrings)[43];
220  const uint8 _psxPauseStrings[3][7] = { "Paused", "Pause", "Pausa" };
221  SwordEngine *_vm;
222  Common::SaveFileManager *_saveFileMan;
223  ObjectMan *_objMan;
224  ResMan *_resMan;
225  OSystem *_system;
226  Mouse *_mouse;
227  Sound *_sound;
228  Screen *_screen;
229  Logic *_logic;
230  uint8 *_screenBuf;
231  Common::KeyState _keyPressed;
232  Common::CustomEventType _customType;
233 
234  Common::Point _mouseCoord;
235  uint16 _mouseState;
236 
237  int _oldSnrStatus = SNR_BLANK;
238  bool _newPal = false;
239  Sprite *_slabs[SAVEBUTTONS - 6];
240  int32 _scrollIndex[2] = { 0, 0 };
241  int32 _speedFlag = 0;
242 
243  int32 _currentButton = 0;
244  int32 _buttonPressed = 0;
245  int32 _buttonHold = 0;
246  int32 _slabSelected = 0;
247  int32 _firstDescription = 0;
248  byte _fileDescriptions[MAXSAVEGAMES][40];
249  int32 _editingDescription = 0;
250  int32 _gamesSaved = 0;
251  int32 _textCursor;
252  int32 _curCharCount;
253  char _oldString[40];
254  int32 _scroll = 0;
255  int32 _scrollCount = 0;
256 
257  uint8 *_restoreBuf = nullptr;
258  uint32 _selectedSavegame = 0;
259  uint8 _numButtons = 0;
260  uint8 _selectedButton = 0;
261  bool _panelShown = false;
262 
263  static const Button panelButtons[8];
264  // We want the death screen buttons to have
265  // the same numbers as the panel buttons
266  static const Button deathButtons[8];
267  static const Button confirmButtons[2];
268  static const Button speedButtons[3];
269  static const Button saveButtons[SAVEBUTTONS];
270  static const Button restoreButtons[SAVEBUTTONS];
271  static const Button volumeButtons[25];
272 };
273 
274 } // End of namespace Sword1
275 
276 #endif //BSCONTROL_H
Definition: sworddefs.h:141
Definition: sword1.h:104
Definition: sound.h:109
Definition: resman.h:65
Definition: memstream.h:194
Definition: screen.h:75
Definition: atari-screen.h:60
uint32 CustomEventType
Definition: events.h:193
Definition: animation.h:38
Definition: control.h:113
int FORCEINLINE GCC_PRINTF(2, 0) int vsprintf_s(T(&dst)[N]
Definition: algorithm.h:29
Definition: logic.h:55
Definition: rect.h:45
Definition: sworddefs.h:108
Definition: objectman.h:33
Definition: mouse.h:70
Definition: keyboard.h:294
Definition: control.h:120
Definition: savefile.h:142
void strcpy_s(char *dst, size_t size, const char *src)
Definition: system.h:161