ScummVM API documentation
livingbooks.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 MOHAWK_LIVINGBOOKS_H
23 #define MOHAWK_LIVINGBOOKS_H
24 
25 #include "mohawk/mohawk.h"
26 #include "mohawk/console.h"
27 #include "mohawk/livingbooks_graphics.h"
28 #include "mohawk/livingbooks_constants.h"
29 #include "mohawk/sound.h"
30 #include "mohawk/video.h"
31 
32 #include "common/formats/ini-file.h"
33 #include "common/rect.h"
34 #include "common/queue.h"
35 #include "common/random.h"
36 
37 #include "livingbooks_code.h"
38 
39 #include "mohawk/livingbooks_itemscript.h"
40 #include "mohawk/livingbooks_item.h"
41 #include "mohawk/livingbooks_itemtypes.h"
42 #include "mohawk/livingbooks_animation.h"
43 #include "mohawk/livingbooks_page.h"
44 
45 namespace Common {
46  class SeekableReadStreamEndian;
47  class MemoryReadStreamEndian;
48 }
49 
50 namespace Mohawk {
51 
52 class MohawkEngine_LivingBooks;
53 class LBPage;
54 class LBGraphics;
55 class LBAnimation;
56 
57 bool tryOpenPage(Archive *archive, const Common::String &fileName);
58 
59 struct NotifyEvent {
60  NotifyEvent(uint t, uint p) : type(t), param(p), newUnknown(0), newMode(0), newPage(0), newSubpage(0) { }
61  uint type;
62  uint param;
63 
64  // kLBNotifyChangeMode
65  uint16 newUnknown;
66  uint16 newMode;
67  uint16 newPage;
68  uint16 newSubpage;
69  Common::String newCursor;
70 };
71 
72 enum DelayedEventType {
73  kLBDelayedEventDestroy = 0,
74  kLBDelayedEventSetNotVisible = 1,
75  kLBDelayedEventDone = 2
76 };
77 
78 struct DelayedEvent {
79  DelayedEvent(LBItem *i, DelayedEventType t) : item(i), type(t) { }
80  LBItem *item;
81  DelayedEventType type;
82 };
83 
85 protected:
86  Common::Error run() override;
87 
88 public:
90  ~MohawkEngine_LivingBooks() override;
91 
93 
94  VideoManager *_video;
95  Sound *_sound;
96  LBGraphics *_gfx;
97  bool _needsRedraw, _needsUpdate;
98 
99  void addNotifyEvent(NotifyEvent event);
100 
101  Common::SeekableReadStreamEndian *wrapStreamEndian(uint32 tag, uint16 id);
102  Common::String readString(Common::ReadStream *stream);
103  Common::Rect readRect(Common::ReadStreamEndian *stream);
104 
105  void addArchive(Archive *archive);
106  void removeArchive(Archive *archive);
107  void addItem(LBItem *item);
108  void removeItems(const Common::Array<LBItem *> &items);
109 
110  LBItem *getItemById(uint16 id);
111  LBItem *getItemByName(Common::String name);
112 
113  void setFocus(LBItem *focus);
114  void setEnableForAll(bool enable, LBItem *except = 0);
115  void notifyAll(uint16 data, uint16 from);
116  void queueDelayedEvent(DelayedEvent event);
117 
118  bool playSound(LBItem *source, uint16 resourceId);
119  void lockSound(LBItem *owner, bool lock);
120 
121  bool isBigEndian() const { return getGameType() != GType_LIVINGBOOKSV1 || getPlatform() == Common::kPlatformMacintosh; }
122  bool isPreMohawk() const;
123 
124  LBMode getCurMode() { return _curMode; }
125 
126  bool tryLoadPageStart(LBMode mode, uint page);
127  bool loadPage(LBMode mode, uint page, uint subpage);
128  void prevPage();
129  void nextPage();
130 
131  // TODO: make private
133 
134  // helper functions, also used by LBProxyItem
135  Common::String getFileNameFromConfig(const Common::String &section, const Common::String &key, Common::String &leftover);
136  Archive *createArchive() const;
137 
138 private:
139  Common::INIFile _bookInfoFile;
140 
141  Common::Path getBookInfoFileName() const;
142  void loadBookInfo(const Common::Path &filename);
143 
144  Common::String stringForMode(LBMode mode);
145 
146  bool _readOnly, _introDone;
147  LBMode _curMode;
148  uint16 _curPage, _curSubPage;
149  uint16 _phase;
150  LBPage *_page;
152  Common::List<LBItem *> _orderedItems;
153  Common::Queue<DelayedEvent> _eventQueue;
154  LBItem *_focus;
155  void destroyPage();
156  void updatePage();
157 
158  uint16 _lastSoundOwner, _lastSoundId;
159  uint16 _lastSoundPriority;
160  uint16 _soundLockOwner;
161  uint16 _maxSoundPriority;
162 
163  void loadSHP(uint16 resourceId);
164 
165  bool tryDefaultPage();
166 
167  void handleUIMenuClick(uint controlId);
168  void handleUIPoetryMenuClick(uint controlId);
169  void handleUIQuitClick(uint controlId);
170  void handleUIOptionsClick(uint controlId);
171 
172  Common::Queue<NotifyEvent> _notifyEvents;
173  void handleNotify(NotifyEvent &event);
174 
175  uint16 _screenWidth;
176  uint16 _screenHeight;
177  uint16 _numLanguages;
178  uint16 _numPages;
179  Common::String _title;
180  Common::String _copyright;
181  bool _poetryMode;
182 
183  uint16 _curLanguage;
184  uint16 _curSelectedPage;
185  bool _alreadyShowedIntro;
186 
187  // String Manipulation Functions
188  Common::String removeQuotesFromString(const Common::String &string, Common::String &leftover);
189  Common::String convertMacFileName(const Common::String &string);
190  Common::String convertWinFileName(const Common::String &string);
191 
192  // Configuration File Functions
193  Common::String getStringFromConfig(const Common::String &section, const Common::String &key);
194  Common::String getStringFromConfig(const Common::String &section, const Common::String &key, Common::String &leftover);
195  int getIntFromConfig(const Common::String &section, const Common::String &key);
196 
197  void pauseEngineIntern(bool) override;
198 };
199 
200 } // End of namespace Mohawk
201 
202 #endif
Definition: stream.h:854
Definition: str.h:59
Definition: error.h:81
Definition: array.h:52
Definition: random.h:44
Definition: livingbooks_graphics.h:31
Definition: list.h:44
Definition: livingbooks.h:78
Definition: rect.h:536
Definition: path.h:52
Definition: resource.h:134
Definition: queue.h:42
Definition: video.h:244
Definition: livingbooks_item.h:45
Definition: sound.h:102
Definition: hashmap.h:85
Definition: livingbooks.h:59
Definition: algorithm.h:29
Definition: mohawk.h:54
Definition: ini-file.h:58
Definition: stream.h:944
Definition: stream.h:385
Definition: system.h:166
Definition: livingbooks_page.h:34
Definition: bitmap.h:32
Definition: detection.h:65
Definition: livingbooks.h:84