File: control.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (276 lines) | stat: -rw-r--r-- 7,103 bytes parent folder | download | duplicates (2)
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/* 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef SWORD1_CONTROL_H
#define SWORD1_CONTROL_H

#include "common/scummsys.h"
#include "common/events.h"
#include "common/str-array.h"
#include "sword1/sworddefs.h"

class OSystem;
namespace Common {
class SaveFileManager;
class MemoryWriteStreamDynamic;
}

namespace Sword1 {

enum SNRStatus {
	SNR_BLANK = 0,
	SNR_MAINPANEL,
	SNR_SAVE,
	SNR_RESTORE,
	SNR_RESTART,
	SNR_QUIT,
	SNR_SPEED,
	SNR_VOLUME,
	SNR_SUBTITLES,
	SNR_DONE,
	SNR_DRIVEFULL = 99
};

enum SaveGameFlags {
	SGF_DONE = 0,
	SGF_SAVE,
	SGF_RESTORE,
	SGF_RESTART,
	SGF_QUIT
};

enum PsxComponents {
	PSX_PANEL = 0,
	PSX_DEATHPANEL,
	PSX_CONFIRM,
	PSX_BUTTON,
	PSX_TEXT,
	PSX_SLAB,
	PSX_SCROLL
};

class SwordEngine;
class ObjectMan;
class ResMan;
class Mouse;
class Sound;
class Screen;
class Logic;

#define SAVEGAME_HEADER MKTAG('B','S','_','1')
#define SAVEGAME_VERSION 2

#define FIRSTFONTCHAR ' '
#define LASTFONTCHAR  (32 + 137)
#define CR             13
#define LF             10
#define ESCAPE         27
#define BACKSPACE      8

#define CONTROL_NOTHING_DONE 0
#define CONTROL_GAME_RESTORED 1
#define CONTROL_RESTART_GAME 2

#define VD1X 139
#define VD2X 273
#define VD3X 404
#define VDY  94

#define SCROLL1X 311
#define SCROLL1Y 124
#define SCROLL2X 311
#define SCROLL2Y 188

#define SAVEBUTTONS  14
#define MAXSAVEGAMES 1000
#define OVERLAP      3
#define SP_OVERLAP   2
#define TEXTBUTTONID 7

#define PSX_CREDITS_SPACING (-3)
#define PSX_CREDITS_MIDDLE  450
#define PSX_CREDITS_OFFSET  150
#define PSX_NUM_CREDITS     14

struct Button {
	int32 x1;
	int32 y1;
	int32 x2;
	int32 y2;
};

class Control {
public:
	Control(SwordEngine *vm, Common::SaveFileManager *saveFileMan, ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Screen *pScreen, Logic *pLogic);

	void getPlayerOptions();
	void askForCdMessage(uint32 needCD, bool incorrectCDPhase);
	void doRestore();
	bool savegamesExist();
	void saveGameToFile(uint8 slot);
	bool restoreGameFromFile(uint8 slot);
	bool restoreGame();
	void checkForOldSaveGames();
	bool isPanelShown();
	const uint8 *getPauseString();
	void psxEndCredits();

	void setSaveDescription(int slot, const char *desc) {
		Common::strcpy_s((char *)_fileDescriptions[slot], sizeof(_fileDescriptions[slot]), desc);
	}

private:
	void saveRestoreScreen();

	void renderSlab(int32 start, int32 i);
	void renderSlabs();
	void renderText(const uint8 *str, int32 x, int32 y, bool useSpeechFont = false);
	void renderRedText(const uint8 *str, int32 x, int32 y);
	void renderTexts();
	int32 getTextLength(const uint8 *str, bool useSpeechFont = false);

	void putButton(int32 x, int32 y, int32 index);
	void putSpriteButton(Sprite *spr, int32 x, int32 y, int32 index);
	void putTextButton(int32 index);
	int32 getCurrentButton(const Button b[]);

	void initialiseConfirmation(const uint8 *title);
	int32 implementConfirmation();
	void removeConfirmation();

	void volUp(int32 i, int32 j);
	void volDown(int32 i, int32 j);
	void renderVolumeLight(int32 i);
	void renderVolumeDisc(int32 i, int32 j);
	void initialiseVolume();
	void implementVolume();
	void removeVolume();

	void renderScrolls();
	void initialiseSpeed();
	void implementSpeed();
	void removeSpeed();

	int16 readFileDescriptions();
	void setEditDescription(int32 line);
	bool driveSpaceAvailable();
	bool attemptSave();
	bool saveGame();
	void editDescription();
	void restoreSelected();
	void uneditDescription();
	void initialiseSave();
	void implementSave();
	void removeSave();

	void initialiseRestore();
	void implementRestore();
	void removeRestore();

	void initialiseControlPanel();
	void implementControlPanel();
	void removeControlPanel();

	void initialiseResources();
	void releaseResources();

	uint8 *decompressPsxGfx(uint8 *src, FrameHeader *f);
	void drawPsxComponent(int componentType, uint8 *src, uint8 *dst, FrameHeader *f);

	bool convertSaveGame(uint8 slot, char *desc);

	void delay(uint32 msecs);
	bool gameVersionIsAkella();
	bool gameVersionIsMediaHouse();
	bool loadCustomStrings(const char *filename);

	int displayMessage(const char *altButton, MSVC_PRINTF const char *message, ...) GCC_PRINTF(3, 4);

	// PSX Credits functions
	int32 getCreditsFontHeight(uint8 *font);
	int32 getCreditsStringLength(uint8 *str, uint8 *font);
	void renderCreditsTextSprite(uint8 *data, uint8 *dst, int16 x, int16 y, int16 width, int16 height);
	void createCreditsTextSprite(uint8 *data, int32 pitch, uint8 *str, uint8 *font);

	Common::MemoryWriteStreamDynamic *_tempThumbnail;
	static const uint8 _languageStrings[8 * 20][43];
	static const uint8 _akellaLanguageStrings[20][43];
	static const uint8 _mediaHouseLanguageStrings[20][43];
	static const uint8 _polishTranslationLanguageStrings[20][43];
	uint8 _customStrings[20][43];
	const uint8(*_lStrings)[43];
	const uint8 _psxPauseStrings[3][7] = { "Paused", "Pause", "Pausa" };
	SwordEngine *_vm;
	Common::SaveFileManager *_saveFileMan;
	ObjectMan *_objMan;
	ResMan *_resMan;
	OSystem *_system;
	Mouse *_mouse;
	Sound *_sound;
	Screen *_screen;
	Logic *_logic;
	uint8 *_screenBuf;
	Common::KeyState _keyPressed;
	Common::CustomEventType _customType;

	Common::Point _mouseCoord;
	uint16 _mouseState;

	int _oldSnrStatus = SNR_BLANK;
	bool _newPal = false;
	Sprite *_slabs[SAVEBUTTONS - 6];
	int32 _scrollIndex[2] = { 0, 0 };
	int32 _speedFlag = 0;

	int32 _currentButton = 0;
	int32 _buttonPressed = 0;
	int32 _buttonHold = 0;
	int32 _slabSelected = 0;
	int32 _firstDescription = 0;
	byte  _fileDescriptions[MAXSAVEGAMES][40];
	int32 _editingDescription = 0;
	int32 _gamesSaved = 0;
	int32 _textCursor;
	int32 _curCharCount;
	char  _oldString[40];
	int32 _scroll = 0;
	int32 _scrollCount = 0;

	uint8 *_restoreBuf = nullptr;
	uint32 _selectedSavegame = 0;
	uint8 _numButtons = 0;
	uint8 _selectedButton = 0;
	bool _panelShown = false;

	static const Button panelButtons[8];
	// We want the death screen buttons to have
	// the same numbers as the panel buttons
	static const Button deathButtons[8];
	static const Button confirmButtons[2];
	static const Button speedButtons[3];
	static const Button saveButtons[SAVEBUTTONS];
	static const Button restoreButtons[SAVEBUTTONS];
	static const Button volumeButtons[25];
};

} // End of namespace Sword1

#endif //BSCONTROL_H