aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/pet_control/pet_glyphs.h
blob: 7271d6cd61a912d3c077101af2722941302db01b (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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
/* 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.
 *
 */

#ifndef TITANIC_PET_GLYPHS_H
#define TITANIC_PET_GLYPHS_H

#include "common/keyboard.h"
#include "titanic/core/list.h"
#include "titanic/messages/mouse_messages.h"
#include "titanic/pet_control/pet_gfx_element.h"
#include "titanic/support/rect.h"

namespace Titanic {

#define TOTAL_GLYPHS 7

class CPetGlyphs;
class CPetSection;
class CPetText;

enum GlyphActionMode { ACTION_REMOVE = 0, ACTION_REMOVED = 1, ACTION_CHANGE = 2 };

enum GlyphFlag { GFLAG_1 = 1, GFLAG_2 = 2, GFLAG_4 = 4, GFLAG_8 = 8, GFLAG_16 = 16 };

class CGlyphAction {
protected:
	GlyphActionMode _mode;
public:
	CGlyphAction() : _mode(ACTION_REMOVED) {}
	CGlyphAction(GlyphActionMode mode) : _mode(mode) {}

	GlyphActionMode getMode() const { return _mode; }
};

class CPetGlyph : public ListItem {
protected:
	/**
	 * Get the overall pet section owner
	 */
	CPetSection *getPetSection() const;
public:
	CPetGfxElement _element;
	CPetGlyphs *_owner;
public:
	CPetGlyph() : ListItem(), _owner(nullptr) {}

	/**
	 * Setup the glyph
	 */
	virtual bool setup(CPetControl *petControl, CPetGlyphs *owner);

	/**
	 * Reset the glyph
	 */
	virtual bool reset() { return false; }

	/**
	 * Called when the PET area is entered
	 */
	virtual void enter() {}
	
	/**
	 * Called when the PET area is left
	 */
	virtual void leave() {}

	/**
	 * Draw the glyph at a specified position
	 */
	virtual void drawAt(CScreenManager *screenManager, const Point &pt, bool isHighlighted);

	/**
	 * Handles any secondary drawing of the glyph
	 */
	virtual void draw2(CScreenManager *screenManager) {}

	/**
	 * Updates the tooltip being shown for the glyph
	 */
	virtual void updateTooltip();

	/**
	 * Get the bounds for the glyph
	 */
	virtual Rect getBounds() { return Rect(); }

	/**
	 * Called for mouse button down messages
	 */
	virtual bool MouseButtonDownMsg(const Point &pt) { return false; }

	/**
	 * Called when mouse drag starts
	 */
	virtual bool MouseDragStartMsg(CMouseDragStartMsg *msg) { return false; }

	/**
	 * Called during mouse drags
	 */
	virtual bool MouseDragMoveMsg(CMouseDragMoveMsg *msg) { return false; }

	/**
	 * Called when mouse drag ends
	 */
	virtual bool MouseDragEndMsg(CMouseDragEndMsg *msg) { return false; }

	/**
	 * Handles mouse button up messages
	 */
	virtual bool MouseButtonUpMsg(const Point &pt) { return false; }

	/**
	 * Handles mouse double-click messages
	 */
	virtual bool MouseDoubleClickMsg(const CMouseDoubleClickMsg *msg) { return false; }

	/**
	 * Handles keypresses
	 */
	virtual bool KeyCharMsg(int key) { return false; }
	
	/**
	 * Handles keypresses
	 */
	virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { return false; }

	/**
	 * Unhighlight any currently highlighted element
	 */
	virtual void unhighlightCurrent() {}

	/**
	 * Highlight any currently highlighted element
	 */
	virtual void highlightCurrent(const Point &pt) {}

	/**
	 * Glyph has been shifted to be first visible one
	 */
	virtual void glyphFocused(const Point &topLeft, bool flag) {}

	/**
	 * Selects a glyph
	 */
	virtual void selectGlyph(const Point &topLeft, const Point &pt) {}
	
	/**
	 * Called when a glyph drag starts
	 */
	virtual bool dragGlyph(const Point &topLeft, CMouseDragStartMsg *msg) { return false; }

	/**
	 * Returns true if the glyph's bounds, shifted to a given position,
	 * will contain the specified point
	 */
	virtual bool contains(const Point &delta, const Point &pt);

	/**
	 * Returns the tooltip text for when the glyph is selected
	 */
	virtual void getTooltip(CPetText *text) {}

	/**
	 * Saves the data for the glyph
	 */
	virtual void saveGlyph(SimpleFile *file, int indent) {}

	virtual bool proc33(CPetGlyph *glyph) { return true; }

	/**
	 * Return whether the glyph is currently valid
	 */
	virtual bool isValid() const { return true; }

	/**
	 * Called on a highlighted item when PET area is entered
	 */
	virtual bool enterHighlighted() { return false; }
	
	/**
	 * Called on a highlighted item when PET area is left
	 */
	virtual void leaveHighlighted() {}

	/**
	 * Returns the object associated with the glyph
	 */
	virtual CGameObject *getObjectAt() { return nullptr; }

	/**
	 * Does a processing action on the glyph
	 */
	virtual bool doAction(CGlyphAction *action) { return true; }

	/**
	 * Translate the glyph's position
	 */
	void translate(const Point &pt) { _element.translate(pt.x, pt.y); }

	/**
	 * Translate the glyph's position back
	 */
	void translateBack(const Point &pt) { _element.translate(-pt.x, -pt.y); }

	/**
	 * Get the parent RealLife area
	 */
	CPetGlyphs *getOwner() { return _owner; }

	/**
	 * Get the PET control
	 */
	CPetControl *getPetControl() const;

	/**
	 * Sets new name and default bounds for glyph
	 */
	void setName(const CString &name, CPetControl *petControl);

	/**
	 * Returns true if the specified glyph is the currently highlighted one
	 */
	bool isHighlighted() const;
};
		
class CPetGlyphs : public List<CPetGlyph> {
private:
	/**
	 * Get a position for the glyph
	 */
	Point getPosition(int index) const;

	/**
	 * Get a rect for the glyph
	 */
	Rect getRect(int index) const;

	/**
	 * Returns the on-screen index for the highlight to be shown at
	 */
	int getHighlightedIndex(int index) const;

	/**
	 * Returns the index of a glyph given the visible on-screen glyph number
	 */
	int getItemIndex(int index) const;

	/**
	 * Set the item index
	 */
	void setSelectedIndex(int index);

	/**
	 * Return a specified glyph
	 */
	CPetGlyph *getGlyph(int index) const;

	/**
	 * Scrolls the glyphs to the left
	 */
	void scrollLeft();

	/**
	 * Scrolls the glyphs to the right
	 */
	void scrollRight();

	/**
	 * Set the first visible glyph index
	 */
	void setFirstVisible(int index);

	/**
	 * Make the PET dirty
	 */
	void makePetDirty();

	/**
	 * Returns true if all the glyphs are in a valid state
	 */
	bool areItemsValid() const;
protected:
	int _firstVisibleIndex;
	int _totalGlyphs;
	int _numVisibleGlyphs;
	int _highlightIndex;
	int _field1C;
	int _flags;
	CPetGlyph *_dragGlyph;
	CPetSection *_owner;
	CPetGfxElement _selection;
	CPetGfxElement _scrollLeft;
	CPetGfxElement _scrollRight;
protected:
	/**
	 * Change the currently selected glyph
	 */
	void changeHighlight(int index);
public:
	CPetGlyphs();

	/**
	 * Set the number of visible glyphs
	 */
	void setNumVisible(int total);

	/**
	 * Clears the glyph list
	 */
	void clear();


	/**
	 * The visual dimensions for the control and it's components
	 */
	virtual void setup(int numVisible, CPetSection *owner);

	/**
	 * Set up the control
	 */
	virtual void reset();

	/**
	 * Called when PET area is entered
	 */
	virtual void enter();

	/**
	 * Called when PET area is left
	 */
	virtual void leave();

	void setFlags(int flags) { _flags = flags; }

	/**
	 * Draw the control
	 */
	void draw(CScreenManager *screenManager);

	/**
	 * Highlight a specific glyph by indexe
	 */
	void highlight(int index);

	/**
	 * Highlight a specific glyph
	 */
	void highlight(const CPetGlyph *glyph);

	/**
	 * Get the owning section for the glyphs
	 */
	CPetSection *getOwner() const { return _owner; }

	/**
	 * Get the PET control
	 */
	CPetControl *getPetControl() const;

	/**
	 * Mouse button down message
	 */
	bool MouseButtonDownMsg(const Point &pt);

	/**
	 * Mouse button up message
	 */
	bool MouseButtonUpMsg(const Point &pt);

	/**
	 * Mouse double click message
	 */
	bool MouseDoubleClickMsg(const Point &pt) { return true; }

	/**
	 * Mouse drag start messagge
	 */
	bool MouseDragStartMsg(CMouseDragStartMsg *msg);

	/**
	 * Mouse drag move message
	 */
	bool MouseDragMoveMsg(CMouseDragMoveMsg *msg);

	/**
	 * Mouse drag end message
	 */
	bool MouseDragEndMsg(CMouseDragEndMsg *msg);

	/**
	 * Key character message
	 */
	bool KeyCharMsg(int key);

	/**
	 * Virtual key message
	 */
	bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg);

	/**
	 * When the PET section is entered, passes onto the highlighted
	 * glyph, if any
	 */
	bool enterHighlighted();

	/**
	 * When the PET section is left, passes onto the highlighted
	 * glyph, if any
	 */
	void leaveHighlighted();

	/**
	 * Called when a dragging operation starts
	 */
	void startDragging(CPetGlyph *glyph, CMouseDragStartMsg *msg);

	/**
	 * Called when a dragging operation ends
	 */
	void endDragging();

	/**
	 * Reset the highlight
	 */
	void resetHighlight() { changeHighlight(-1); }

	bool highlighted14();

	/**
	 * Returns the index of the specified glyph in the lsit
	 */
	int indexOf(const CPetGlyph *glyph) const;

	/**
	 * Resets the scrolling of the glyphs list back to the start
	 */
	void scrollToStart() { _firstVisibleIndex = 0; }

	/**
	 * Increment the currently selected index
	 */
	void incSelection();

	/**
	 * Decrement the currently selected index
	 */
	void decSelection();

	/**
	 * Returns the object associated the glyph under the specified position
	 */
	CGameObject *getObjectAt(const Point &pt) const;

	/**
	 * Returns true if the specified glyph is the currently highlighted one
	 */
	bool isGlyphHighlighted(const CPetGlyph *glyph) const;

	/**
	 * Get the top-left position of the currently highlighted glyph
	 */
	Point getHighlightedGlyphPos() const;

	/**
	 * Removes any glyphs from the list that no longer have any images
	 * associated with them
	 */
	void removeInvalid();
};

} // End of namespace Titanic

#endif /* TITANIC_PET_GLYPHS_H */