aboutsummaryrefslogtreecommitdiff
path: root/engines/m4/mads_views.h
blob: f0ded634b13c6a5635506ca9074f40e9842eab40 (plain)
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/* 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#ifndef M4_MADS_VIEWS_H
#define M4_MADS_VIEWS_H

#include "m4/gui.h"
#include "m4/viewmgr.h"
#include "common/rect.h"
#include "common/list.h"
#include "common/ptr.h"

namespace M4 {

class MadsView;

enum AbortTimerMode {ABORTMODE_0 = 0, ABORTMODE_1 = 1, ABORTMODE_2 = 2};

class SpriteSlotSubset {
public:
	int spriteListIndex;
	int frameNumber;
	int xp;
	int yp;
	int depth;
	int scale;
};

class MadsSpriteSlot {
public:
	int spriteType;
	int seqIndex;
	int spriteListIndex;
	int frameNumber;
	int xp;
	int yp;
	int depth;
	int scale;

	MadsSpriteSlot() { }

	bool operator==(const SpriteSlotSubset &other) const;
	void copy(const SpriteSlotSubset &other);
};

#define SPRITE_SLOTS_SIZE 50

enum SpriteIdSpecial {
	BACKGROUND_SPRITE = -4, FULL_SCREEN_REFRESH = -2, EXPIRED_SPRITE = -1, SPRITE_ZERO = 0, FOREGROUND_SPRITE = 1
};

class MadsSpriteSlots {
private:
	MadsView &_owner;
	Common::Array<MadsSpriteSlot> _entries;
	Common::Array<SpriteAsset *> _sprites;
public:
	int startIndex;

	MadsSpriteSlots(MadsView &owner);
	~MadsSpriteSlots();

	MadsSpriteSlot &operator[](int idx) {
		assert(idx < SPRITE_SLOTS_SIZE);
		return _entries[idx];
	}
	SpriteAsset &getSprite(int idx) {
		assert(idx < (int)_sprites.size());
		return *_sprites[idx];
	}

	int getIndex();
	int addSprites(const char *resName);
	void deleteSprites(int listIndex);
	void clear();
	void deleteTimer(int seqIndex);

	void drawBackground();
	void drawForeground(View *view, int yOffset);
	void setDirtyAreas();
	void fullRefresh();
	void cleanUp();
};

class MadsTextDisplayEntry {
public:
	bool active;
	int expire;
	int spacing;
	Common::Rect bounds;
	uint8 colour1;
	uint8 colour2;
	Font *font;
	const char *msg;

	MadsTextDisplayEntry() { active = false; }
};

#define TEXT_DISPLAY_SIZE 40

class MadsTextDisplay {
private:
	MadsView &_owner;
	Common::Array<MadsTextDisplayEntry> _entries;
public:
	MadsTextDisplay(MadsView &owner);

	MadsTextDisplayEntry &operator[](int idx) {
		assert(idx < TEXT_DISPLAY_SIZE);
		return _entries[idx];
	}

	void expire(int idx) {
		assert(idx < TEXT_DISPLAY_SIZE);
		_entries[idx].expire = -1;
	}

	int add(int xp, int yp, uint fontColour, int charSpacing, const char *msg, Font *font);
	void clear();
	void draw(View *view, int yOffset);
	void setDirtyAreas();
	void setDirtyAreas2();
	void cleanUp();
};

#define TIMED_TEXT_SIZE 10
#define INDEFINITE_TIMEOUT 9999999

enum KernelMessageFlags {KMSG_QUOTED = 1, KMSG_OWNER_TIMEOUT = 2, KMSG_SEQ_ENTRY = 4, KMSG_SCROLL = 8, KMSG_RIGHT_ALIGN = 0x10, 
	KMSG_CENTER_ALIGN = 0x20, KMSG_EXPIRE = 0x40, KMSG_ACTIVE = 0x80};

class MadsKernelMessageEntry {
public:
	uint8 flags;
	int sequenceIndex;
	char asciiChar;
	char asciiChar2;
	int colour1;
	int colour2;
	Common::Point position;
	int textDisplayIndex;
	int msgOffset;
	int numTicks;
	uint32 frameTimer2;
	uint32 frameTimer;
	uint32 timeout;
	int abortTimers;
	AbortTimerMode abortMode;
	uint16 actionNouns[3];
	char msg[100];
};

class MadsKernelMessageList {
private:
	MadsView &_owner;
	Common::Array<MadsKernelMessageEntry> _entries;
	Font *_talkFont;
public:
	int word_8469E;
public:
	MadsKernelMessageList(MadsView &owner);

	void clear();
	int add(const Common::Point &pt, uint fontColour, uint8 flags, uint8 abortTimers, uint32 timeout, const char *msg);
	int addQuote(int quoteId, int abortTimers, uint32 timeout);
	void scrollMessage(int msgIndex, int numTicks, bool quoted);
	void setSeqIndex(int msgIndex, int seqIndex);
	void remove(int msgIndex);
	void reset();
	void update();
	void processText(int msgIndex);
};

class ScreenObjectEntry {
public:
	Common::Rect bounds;
	int category;
	int index;
	int layer;
	bool active;

	ScreenObjectEntry() { active = false; }
};

class ScreenObjects {
private:
	Common::Array<ScreenObjectEntry> _entries;
public:
	ScreenObjects() {}

	ScreenObjectEntry &operator[](uint idx) {
		assert(idx <= _entries.size());
		return _entries[idx - 1];
	}

	void clear();
	void add(const Common::Rect &bounds, int layer, int idx, int category);
	void draw(View *view);
	int scan(int xp, int yp, int layer);
	int scanBackwards(int xp, int yp, int layer);
	void setActive(int category, int idx, bool active);
};

class DynamicHotspot {
public:
	bool active;
	int seqIndex;
	Common::Rect bounds;
	Common::Point pos;
	int facing;
	int descId;
	int field_14;
	int articleNumber;
	int field_17;

	DynamicHotspot() { active = false; }
};

#define DYNAMIC_HOTSPOTS_SIZE 8

class MadsDynamicHotspots {
private:
	MadsView &_owner;
	Common::Array<DynamicHotspot> _entries;
	int _count;
public:
	bool _flag;
public:
	MadsDynamicHotspots(MadsView &owner);

	DynamicHotspot &operator[](uint idx) { return _entries[idx]; }
	int add(int descId, int field14, int seqIndex, const Common::Rect &bounds);
	int setPosition(int index, int xp, int yp, int facing);
	int set17(int index, int v);
	void remove(int index);
	void reset();
};

class MadsDirtyArea {
public:
	Common::Rect bounds;
	Common::Rect bounds2;
	bool textActive;
	bool active;

	MadsDirtyArea() { active = false; }
	void setArea(int width, int height, int maxWidth, int maxHeight);
};

#define DIRTY_AREAS_SIZE 90
#define DIRTY_AREAS_TEXT_DISPLAY_IDX 50

class MadsDirtyAreas {
private:
	MadsView &_owner;
	Common::Array<MadsDirtyArea> _entries;
public:
	MadsDirtyAreas(MadsView &owner);

	MadsDirtyArea &operator[](uint idx) {
		assert(idx < _entries.size());
		return _entries[idx];
	}

	void setSpriteSlot(int dirtyIdx, const MadsSpriteSlot &spriteSlot);
	void setTextDisplay(int dirtyIdx, const MadsTextDisplayEntry &textDisplay);
	void merge(int startIndex, int count);
	bool intersects(int idx1, int idx2);
	void mergeAreas(int idx1, int idx2);
	void copy(M4Surface *dest, M4Surface *src, int yOffset, const Common::Point &posAdjust);
};

enum SpriteAnimType {ANIMTYPE_CYCLED = 1, ANIMTYPE_REVERSIBLE = 2};

enum SequenceSubEntryMode {SM_0 = 0, SM_1 = 1, SM_FRAME_INDEX = 2};

#define TIMER_ENTRY_SUBSET_MAX 5

struct MadsSequenceSubEntries {
	int count;
	SequenceSubEntryMode mode[TIMER_ENTRY_SUBSET_MAX];
	int16 frameIndex[TIMER_ENTRY_SUBSET_MAX];
	int8 abortVal[TIMER_ENTRY_SUBSET_MAX];
};

struct MadsSequenceEntry {
	int8 active;
	int8 spriteListIndex;
	
	int field_2;
	
	int frameIndex;
	int frameStart;
	int numSprites;

	SpriteAnimType animType;
	int frameInc;

	int depth;
	int scale;
	int dynamicHotspotIndex;

	bool nonFixed;
	int field_13;
	
	Common::Point msgPos;
	int triggerCountdown;
	bool doneFlag;
	MadsSequenceSubEntries entries;
	AbortTimerMode abortMode;

	uint16 actionNouns[3];
	int numTicks;
	int extraTicks;
	uint32 timeout;
};

#define TIMER_LIST_SIZE 30

class MadsSequenceList {
private:
	MadsView &_owner;
	Common::Array<MadsSequenceEntry> _entries;
public:
	MadsSequenceList(MadsView &owner);

	MadsSequenceEntry &operator[](int index) { return _entries[index]; }	
	void clear();
	bool addSubEntry(int index, SequenceSubEntryMode mode, int frameIndex, int abortVal);
	int add(int spriteListIndex, int v0, int v1, int triggerCountdown, int delayTicks, int extraTicks, int numTicks, 
		int msgX, int msgY, bool nonFixed, char scale, uint8 depth, int frameInc, SpriteAnimType animType, 
		int numSprites, int frameStart);
	void remove(int seqIndex);
	void setSpriteSlot(int seqIndex, MadsSpriteSlot &spriteSlot);
	bool loadSprites(int seqIndex);
	void tick();
	void delay(uint32 v1, uint32 v2);
	void setAnimRange(int seqIndex, int startVal, int endVal);
	void scan();
};

class Animation {
protected:
	MadsM4Engine *_vm;
public:
	Animation(MadsM4Engine *vm);
	virtual ~Animation();
	virtual void initialise(const Common::String &filename, uint16 flags, M4Surface *surface, M4Surface *depthSurface) = 0;
	virtual void load(const Common::String &filename, int v0) = 0;
	virtual void update() = 0;
	virtual void setCurrentFrame(int frameNumber) = 0;
};
	

class MadsView {
private:
	View *_view;
public:
	Animation *_sceneAnimation;
	MadsSpriteSlots _spriteSlots;
	MadsTextDisplay _textDisplay;
	MadsKernelMessageList _kernelMessages;
	ScreenObjects _screenObjects;
	MadsDynamicHotspots _dynamicHotspots;
	MadsSequenceList _sequenceList;
	MadsDirtyAreas _dirtyAreas;

	int _textSpacing;
	int _ticksAmount;
	uint32 _newTimeout;
	int _abortTimers;
	int8 _abortTimers2;
	AbortTimerMode _abortTimersMode;
	AbortTimerMode _abortTimersMode2;
	Common::Point _posAdjust;

	M4Surface *_depthSurface;
	M4Surface *_bgSurface;
	int _yOffset;
public:
	MadsView(View *view);
	~MadsView();

	void refresh();
	void clearLists();
};

}

#endif