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 
27 namespace Nancy {
28 namespace 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.
44 class Overlay : public RenderActionRecord {
45 public:
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
80  Common::Array<FrameBlitDescription> _blitDescriptions;
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 
95 protected:
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
102 class OverlayStaticTerse : public Overlay {
103 public:
104  OverlayStaticTerse() : Overlay(kInterruptibleAnimation) {}
105  virtual ~OverlayStaticTerse() {}
106 
107  void readData(Common::SeekableReadStream &stream) override;
108 
109 protected:
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.
117 public:
118  OverlayMultiframeTerse() : Overlay(kInterruptibleAnimation) {}
119  virtual ~OverlayMultiframeTerse() {}
120 
121  void readData(Common::SeekableReadStream &stream) override;
122 
123 protected:
124  Common::String getRecordTypeName() const override { return "OverlayMultiframeTerse"; }
125 };
126 
127 // Short version of an animated overlay; assumes scene background doesn't move
128 class OverlayAnimTerse : public Overlay {
129 public:
130  OverlayAnimTerse() : Overlay(kInterruptibleAnimation) {}
131  virtual ~OverlayAnimTerse() {}
132 
133  void readData(Common::SeekableReadStream &stream) override;
134 
135 protected:
136  Common::String getRecordTypeName() const override { return "OverlayAnimTerse"; }
137 };
138 
139 class TableIndexOverlay : public Overlay {
140 public:
141  TableIndexOverlay() : Overlay(kInterruptibleAnimation) {}
142  virtual ~TableIndexOverlay() {}
143 
144  void readData(Common::SeekableReadStream &stream) override;
145  void execute() override;
146 
147 protected:
148  Common::String getRecordTypeName() const override { return "TableIndexOverlay"; }
149 
150  uint16 _tableIndex = 0;
151  int16 _lastIndexVal = -1;
152 };
153 
154 // Draws a single line of text on top of the scene background. The text is a
155 // value looked up from the player-data table (used by the nancy12 minigolf
156 // scorecard, where each hole's score is a separate record). Nancy14 added a
157 // digit count that the value is truncated to, and an optional image holding
158 // the glyphs for digits 0-9, which replaces the font when present.
160 public:
162  virtual ~TextLineOverlay() {}
163 
164  void init() override;
165  void readData(Common::SeekableReadStream &stream) override;
166  void execute() override;
167 
168  bool isViewportRelative() const override { return true; }
169 
170 protected:
171  Common::String getRecordTypeName() const override { return "TextLineOverlay"; }
172 
173  Common::String getText() const;
174  void drawText(const Common::String &text);
175  void drawDigitImages(const Common::String &text);
176 
177  // Table index that always displays zero
178  static const int16 kZeroTableIndex = 255;
179 
180  uint16 _fontID = 0;
181  uint16 _textColor = 0;
182  Common::Point _position;
183  Common::String _textKey;
184  int16 _tableIndex = 0;
185 
186  int16 _numDigits = 0;
187  Common::Path _digitImageName;
188  uint16 _digitSpacing = 0;
189  Common::Rect _digitSrcRects[10];
190 
191  Graphics::ManagedSurface _digitImage;
192  Common::String _displayedText;
193 };
194 
195 // Nancy14 AR 53. A rollover label: an image that is only drawn while the mouse
196 // is inside its hotspot. Entering the hotspot plays a sound and sets an event
197 // flag, and clicking it plays a second sound before changing the scene.
199 public:
201  virtual ~RolloverOverlay() { _fullSurface.free(); }
202 
203  void init() override;
204  void readData(Common::SeekableReadStream &stream) override;
205  void execute() override;
206  void handleInput(NancyInput &input) override;
207 
208  bool isViewportRelative() const override { return true; }
209  bool canHaveHotspot() const override { return true; }
210  CursorManager::CursorType getHoverCursor() const override { return (CursorManager::CursorType)_hoverCursor; }
211  bool cursorSetFromScript() const override { return true; }
212  Common::String getRecordExtraInfo() const override {
213  return Common::String::format("Scene %d, file %s", _sceneChange.sceneID, _imageName.baseName().c_str());
214  }
215 
216 protected:
217  Common::String getRecordTypeName() const override { return "RolloverOverlay"; }
218 
219  void playSoundBlock(const RandomSoundBlock &block);
220 
221  Common::Path _imageName;
222  uint16 _transparency = kPlayOverlayPlain;
223  uint16 _hoverCursor = 0;
224  Common::Rect _hotspotRect;
225  Common::Rect _srcRect;
226  Common::Rect _destRect;
227  // Set every time the mouse enters the hotspot
228  FlagDescription _flagOnHover;
229  // When nonzero the hover sound is only played the first time; otherwise it
230  // plays on every hover
231  uint16 _hoverSoundOnce = 0;
232  RandomSoundBlock _hoverSound;
233  SceneChangeDescription _sceneChange;
234  RandomSoundBlock _clickSound;
235 
236  bool _isHovered = false;
237  bool _hoverSoundPlayed = false;
238  bool _clickSoundStarted = false;
239 
240  Graphics::ManagedSurface _fullSurface;
241 };
242 
243 } // End of namespace Action
244 } // End of namespace Nancy
245 
246 #endif // NANCY_ACTION_OVERLAY_H
Definition: managed_surface.h:51
Definition: commontypes.h:227
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: overlay.h:198
Definition: commontypes.h:179
Definition: overlay.h:159
Definition: rect.h:536
Definition: path.h:52
Definition: stream.h:745
Definition: input.h:41
Definition: overlay.h:139
Definition: actionrecord.h:169
Definition: overlay.h:102
Definition: commontypes.h:314
Definition: rect.h:144
String baseName() const
Definition: overlay.h:44
Definition: commontypes.h:296
Definition: overlay.h:116
Definition: commontypes.h:194
Definition: overlay.h:128
Definition: actionmanager.h:32