aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/myst_card.h
blob: 7a4070171c8a721596393cd633b6905fde1a870a (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
/* 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 MYST_CARD_H
#define MYST_CARD_H

#include "common/rect.h"

#include "mohawk/myst.h"

namespace Mohawk {

/**
 * A game view
 *
 * The names Card and Stack are legacy from the HyperCard engine used in
 * the original mac version.
 *
 * Cards contain resources (hotspots), images, sounds, and cursor hints.
 */
class MystCard {
public:
	MystCard(MohawkEngine_Myst *vm, uint16 id);
	~MystCard();

	/** Get the id of the card */
	uint16 getId() const;

	/** Initialization routine used to draw a card for the first time */
	void enter();

	/** Run the card's leave scripts */
	void leave();

	/** Get a card resource (hotspot) by its index in the resource list */
	template<class T>
	T *getResource(uint index);

	/** The list of resources in the card */
	Common::Array<MystArea *> _resources;

	/** Enable or disable a card resource */
	void setResourceEnabled(uint16 resourceIndex, bool enable);

	/** Update the card's active resource according to the mouse position */
	void updateActiveResource(const Common::Point &mouse);

	/** Set the card's currently clicked resource to the currently active resource */
	MystArea *forceUpdateClickedResource(const Common::Point &mouse);

	/** Clear the card's currently clicked resource
	 *
	 * Used to indicate the mouse up event handler should not be called.
	 * (Possibly because it was already called by the gameplay logic
	 */
	void resetClickedResource();

	/**
	 * Get the mouse cursor that should be used when hovering the currently active resource
	 *
	 * -1 means that no specific cursor is defined for the active resource, or that there is no
	 * currently active resource. In that case the default main cursor should be used by the caller.
	 */
	int16 getActiveResourceCursor();

	/**
	 * Call the resource event handlers to account for the new specified input
	 *
	 * For example call the mouse down event handler for the currently active resource
	 * if the mouse is clicked and there was no clicked resource previously.
	 */
	void updateResourcesForInput(const Common::Point &mouse, bool mouseClicked, bool mouseMoved);

	/** Is there a currently clicked resource */
	bool isDraggingResource() const;

	/** Retrieve the id of the background image to use when drawing the card */
	uint16 getBackgroundImageId();

	/** Draw the card's background image to the backbuffer */
	void drawBackground();

	/** Draw the card's image resources to the backbuffer */
	void drawResourceImages();

	/** Draw debug rectangles around the card's resources */
	void drawResourceRects();

	/** Redraw the card's resources that are affected by the specified variable */
	void redrawArea(uint16 var, bool updateScreen = true);

private:
	// View flags
	enum {
		kMystZipDestination = (1 << 0)
	};

	struct MystCursorHint {
		uint16 id;
		int16 cursor;

		MystCondition variableHint;
	};

	MohawkEngine_Myst *_vm;

	// General card data
	uint16 _id;
	uint16 _flags;

	// Image Data
	Common::Array<MystCondition> _conditionalImages;
	uint16 _mainImage;

	// Sound Data
	MystSoundBlock _soundBlock;

	// Script Resources
	enum ScriptResourceType {
		kResourceImage = 1,
		kResourceSound = 2,
		kResourceSwitch = 3,
		kResourceImageNoCache = 4,
		kResourceSoundNoCache = 5
	};

	struct ScriptResource {
		ScriptResourceType type;
		uint16 id;
		uint16 switchVar;
		ScriptResourceType switchResourceType;
		Common::Array<int16> switchResourceIds;
	};
	Common::Array<ScriptResource> _scriptResources;

	uint16 _resourceListId;
	uint16 _hintResourceId;
	uint16 _initScriptId;
	uint16 _exitScriptId;

	Common::Array<MystCursorHint> _cursorHints;

	/** Area of type kMystAreaHover being hovered by the mouse, if any */
	MystAreaHover *_hoverResource;

	/** Active area being hovered by the mouse, if any */
	MystArea *_activeResource;

	/** Active area being clicked on / dragged, if any */
	MystArea *_clickedResource;

	void loadView();
	void loadResources();
	void loadCursorHints();

	void runInitScript();
	void runExitScript();
};

template<class T>
T *MystCard::getResource(uint index) {
	T *resource = dynamic_cast<T *>(_resources[index]);

	if (!resource) {
		error("View resource '%d' has unexpected type", index);
	}

	return resource;
}

} // End of namespace Mohawk

#endif