ScummVM API documentation
overlay.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 NANCY_ACTION_OVERLAY_H
23#define NANCY_ACTION_OVERLAY_H
24
25#include "engines/nancy/action/actionrecord.h"
26
27namespace Nancy {
28namespace Action {
29
30// Places a static image or a looping animation on top of the background
31// Can move along with the scene's background frame, however:
32// - in animation mode, the animation is the same for every background frame
33// - in static mode, every background frame gets its own static image
34// Also supports:
35// - playing a sound;
36// - playing backwards;
37// - looping (non-looping animated overlays are very rare);
38// - getting interrupted by an event flag;
39// - changing the scene/setting flags when clicked/interrupted
40// Originally introduced in nancy1, where it was split into two different types:
41// PlayStaticBitmapAnimation and PlayIntStaticBitmapAnimation (the latter was interruptible)
42// In nancy2, the two got merged inside the newly-renamed Overlay;
43// that was also when static mode got introduced.
45public:
46 enum AnimationType { kStaticAnimation, kInterruptibleAnimation };
47
48 Overlay(AnimationType animationType) : RenderActionRecord(7), _animationType(animationType), _usesAutotext(false) {}
49 virtual ~Overlay() { _fullSurface.free(); }
50
51 void init() override;
52 void handleInput(NancyInput &input) override;
53 void updateGraphics() override;
54
55 void readData(Common::SeekableReadStream &stream) override;
56 void execute() override;
57
58 Common::Path _imageName;
59
60 uint16 _transparency = kPlayOverlayPlain;
61 uint16 _hasSceneChange = kPlayOverlaySceneChange;
62 uint16 _enableHotspotNancy2 = kPlayOverlayNoHotspot;
63 uint16 _overlayType = kPlayOverlayAnimated;
64 uint16 _playDirection = kPlayOverlayForward;
65 uint16 _loop = kPlayOverlayOnce;
66 uint16 _firstFrame = 0;
67 uint16 _loopFirstFrame = 0;
68 uint16 _loopLastFrame = 0;
69 uint32 _frameTime = 0;
70 FlagDescription _interruptCondition;
71 SceneChangeDescription _sceneChange;
72 MultiEventFlagDescription _flagsOnTrigger;
73
74 SoundDescription _sound;
75
76 // Describes a single frame in this animation
78 // Describes how the animation will be displayed on a single
79 // frame of the viewport
81
82 int16 _currentFrame = -1;
83 int16 _currentViewportFrame = -1;
84 uint32 _nextFrameTime = 0;
85 AnimationType _animationType;
86 bool _usesAutotext;
87
88 bool canHaveHotspot() const override { return true; }
89 bool isViewportRelative() const override { return true; }
90 bool survivesSceneChange(bool nextSceneIsNoArt) const override { return nextSceneIsNoArt; }
91 Common::String getRecordExtraInfo() const override {
92 return Common::String::format("Scene %d, file %s", _sceneChange.sceneID, _imageName.baseName().c_str());
93 }
94
95protected:
96 Common::String getRecordTypeName() const override;
97
98 Graphics::ManagedSurface _fullSurface;
99};
100
101// Short version of a static overlay; assumes scene background doesn't move
103public:
104 OverlayStaticTerse() : Overlay(kInterruptibleAnimation) {}
105 virtual ~OverlayStaticTerse() {}
106
107 void readData(Common::SeekableReadStream &stream) override;
108
109protected:
110 Common::String getRecordTypeName() const override { return "OverlayStaticTerse"; }
111};
112
113// Short version of a static overlay for a moving scene background. Unlike
114// OverlayStaticTerse, which carries a single source/destination pair, this one
115// carries a blit description for every background frame the overlay appears on.
117public:
118 OverlayMultiframeTerse() : Overlay(kInterruptibleAnimation) {}
119 virtual ~OverlayMultiframeTerse() {}
120
121 void readData(Common::SeekableReadStream &stream) override;
122
123protected:
124 Common::String getRecordTypeName() const override { return "OverlayMultiframeTerse"; }
125};
126
127// Nancy18. A static overlay that gets drawn in one of several colors, picked at
128// random. Every color comes with an event flag, which tells the scene the pick.
130public:
131 virtual ~OverlayRandomColor() {}
132
133 void init() override;
134
135 void readData(Common::SeekableReadStream &stream) override;
136
137protected:
138 Common::String getRecordTypeName() const override { return "OverlayRandomColor"; }
139
140 struct ColorChoice {
141 uint32 color = 0xFFFFFFFF; // ARGB, multiplied with the image
142 int16 flag = -1;
143 };
144
146};
147
148// Short version of an animated overlay; assumes scene background doesn't move
149class OverlayAnimTerse : public Overlay {
150public:
151 OverlayAnimTerse() : Overlay(kInterruptibleAnimation) {}
152 virtual ~OverlayAnimTerse() {}
153
154 void readData(Common::SeekableReadStream &stream) override;
155
156protected:
157 Common::String getRecordTypeName() const override { return "OverlayAnimTerse"; }
158};
159
161public:
162 TableIndexOverlay() : Overlay(kInterruptibleAnimation) {}
163 virtual ~TableIndexOverlay() {}
164
165 void readData(Common::SeekableReadStream &stream) override;
166 void execute() override;
167
168protected:
169 Common::String getRecordTypeName() const override { return "TableIndexOverlay"; }
170
171 uint16 _tableIndex = 0;
172 int16 _lastIndexVal = -1;
173};
174
175// Draws a single line of text on top of the scene background. The text is a
176// value looked up from the player-data table (used by the nancy12 minigolf
177// scorecard, where each hole's score is a separate record). Nancy14 added a
178// digit count that the value is truncated to, and an optional image holding
179// the glyphs for digits 0-9, which replaces the font when present.
181public:
183 virtual ~TextLineOverlay() {}
184
185 void init() override;
186 void readData(Common::SeekableReadStream &stream) override;
187 void execute() override;
188
189 bool isViewportRelative() const override { return true; }
190
191protected:
192 Common::String getRecordTypeName() const override { return "TextLineOverlay"; }
193
194 Common::String getText() const;
195 void drawText(const Common::String &text);
196 void drawDigitImages(const Common::String &text);
197
198 // Table index that always displays zero
199 static const int16 kZeroTableIndex = 255;
200
201 uint16 _fontID = 0;
202 uint16 _textColor = 0;
203 Common::Point _position;
204 Common::String _textKey;
205 int16 _tableIndex = 0;
206
207 int16 _numDigits = 0;
208 Common::Path _digitImageName;
209 uint16 _digitSpacing = 0;
210 Common::Rect _digitSrcRects[10];
211
212 Graphics::ManagedSurface _digitImage;
213 Common::String _displayedText;
214};
215
216// Nancy14 AR 53. A rollover label: an image that is only drawn while the mouse
217// is inside its hotspot. Entering the hotspot plays a sound and sets an event
218// flag, and clicking it plays a second sound before setting another event flag
219// and changing the scene.
221public:
223 virtual ~RolloverOverlay() { _fullSurface.free(); }
224
225 void init() override;
226 void readData(Common::SeekableReadStream &stream) override;
227 void execute() override;
228 void handleInput(NancyInput &input) override;
229
230 bool isViewportRelative() const override { return true; }
231 bool canHaveHotspot() const override { return true; }
232 CursorManager::CursorType getHoverCursor() const override { return (CursorManager::CursorType)_hoverCursor; }
233 bool cursorSetFromScript() const override { return true; }
234 Common::String getRecordExtraInfo() const override {
235 return Common::String::format("Scene %d, file %s", _sceneChange.sceneID, _imageName.baseName().c_str());
236 }
237
238protected:
239 Common::String getRecordTypeName() const override { return "RolloverOverlay"; }
240
241 void readDataNancy16(Common::SeekableReadStream &stream);
242 void playSoundBlock(const RandomSoundBlock &block);
243
244 Common::Path _imageName;
245 uint16 _transparency = kPlayOverlayPlain;
246 uint16 _hoverCursor = 0;
247 Common::Rect _hotspotRect;
248 Common::Rect _srcRect;
249 Common::Rect _destRect;
250 // Set every time the mouse enters the hotspot
251 FlagDescription _flagOnHover;
252 // When nonzero the hover sound is only played the first time; otherwise it
253 // plays on every hover
254 uint16 _hoverSoundOnce = 0;
255 RandomSoundBlock _hoverSound;
256 SceneChangeDescription _sceneChange;
257 // Set when the click sound finishes, even when there's no scene change
258 FlagDescription _flagOnClick;
259 RandomSoundBlock _clickSound;
260
261 bool _isHovered = false;
262 bool _hoverSoundPlayed = false;
263 bool _clickSoundStarted = false;
264
265 Graphics::ManagedSurface _fullSurface;
266};
267
268} // End of namespace Action
269} // End of namespace Nancy
270
271#endif // NANCY_ACTION_OVERLAY_H
Definition: path.h:52
String baseName() const
Definition: stream.h:745
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: managed_surface.h:51
Definition: overlay.h:149
Definition: overlay.h:44
Definition: overlay.h:116
Definition: overlay.h:129
Definition: overlay.h:102
Definition: actionrecord.h:173
Definition: overlay.h:220
Definition: overlay.h:160
Definition: overlay.h:180
Definition: actionmanager.h:32
Definition: rect.h:144
Definition: rect.h:536
Definition: commontypes.h:203
Definition: commontypes.h:237
Definition: input.h:41
Definition: commontypes.h:326
Definition: commontypes.h:188
Definition: commontypes.h:308