ScummVM API documentation
subtitles.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 BLADERUNNER_SUBTITLES_H
23 #define BLADERUNNER_SUBTITLES_H
24 
25 #include "bladerunner/bladerunner.h"
26 
27 #include "bladerunner/color.h"
28 #include "common/str.h"
29 #include "common/ustr.h"
30 
31 namespace Graphics {
32 class Font;
33 }
34 
35 namespace BladeRunner {
36 
37 class BladeRunnerEngine;
38 class TextResource;
39 
40 class Subtitles {
41  friend class Debugger;
42  friend class KIASectionSettings;
43  //
44  // Subtitles could be in 6 possible languages are EN_ANY, DE_DEU, FR_FRA, IT_ITA, RU_RUS, ES_ESP
45  // with corresponding _vm->_languageCode values: "E", "G", "F", "I", "E", "S" (Russian version is built on top of English one)
46  static const uint kPreferedLine = 2; // Prefer drawing from this line (the bottom-most of available subtitle lines index is 0) by default
47  static const int kMarginBottom = 12; // In pixels. This is the bottom margin beneath the subtitles space
48  static const int kMarginTop = 12; // In pixels. This is the top margin before secondary subtitles
49  static const int kTextMaxWidth = 610; // In pixels
50  static const int kMaxTextResourceEntries = 27; // Support in-game subs (1) and all possible VQAs (26) with spoken dialogue or translatable text
51  static const int kMaxLanguageSelectionNum = 1024; // Max allowed number of languages to select from (should be available in the MIX file)
52  static const uint32 kMinDuration = 1000; // Min allowed duration for a queued subtitle
53 
54  static const char *SUBTITLES_FILENAME_PREFIXES[kMaxTextResourceEntries];
55  static const char *SUBTITLES_FONT_FILENAME_EXTERNAL;
56  static const char *SUBTITLES_VERSION_TRENAME;
57  static const char *EXTRA_TRENAME;
58 
59  static const Color256 kTextColors[];
60 
61  static const int kNumOfSubtitleRoles = 2;
62 
63  static const int kxcLineCount = 22;
64  static const int kxcStringCount = 14; // 15 - 1
65  Common::String _xcStrings[kxcStringCount];
66  int _xcStringIndex;
67 
68  Common::String _xcLineTexts[kxcLineCount];
69  int _xcLineTimeouts[kxcLineCount];
70  int _xcLineOffsets[kxcLineCount];
71  uint32 _xcTimeLast;
72 
73  BladeRunnerEngine *_vm;
74 
75  enum SubtitlesFontType {
76  kSubtitlesFontTypeInternal,
77  kSubtitlesFontTypeTTF
78  };
79 
80  struct SubtitlesInfo {
81  Common::String versionStr;
82  Common::String dateOfCompile;
83  Common::String languageMode;
84  Common::String credits;
85  SubtitlesFontType fontType;
86  Common::String fontName;
87 
88  SubtitlesInfo() : versionStr(""), dateOfCompile(""), languageMode(""), credits(""), fontName("") { fontType = kSubtitlesFontTypeInternal; };
89  };
90 
91  struct SubtitlesData {
92  bool isVisible;
93  bool forceShowWhenNoSpeech;
94  // U32String for when we use an external font that supports UTF-32 encoding
95  Common::U32String currentText32;
96  Common::U32String prevText32;
98 
99  // For now, we're using the original game's FON format for native font
100  // and the original MIX for file for text resources.
101  // This means that when not explicitly using an external font,
102  // the text resources are in extended ASCII format that index the native font FON.
103  // FUTURE On a next revision we should support UTF-8 text in the MIX files which
104  // would work with external font.
105  Common::String currentText;
106  Common::String prevText;
108 
109  SubtitlesData() : isVisible(false), forceShowWhenNoSpeech(false) { };
110  };
111 
112  struct SubtitlesQueueEntry {
113  Common::String quote;
114  uint32 timeStarted;
115  uint32 duration;
116  //uint8 subsRole; // only support secondary subtitles to be queued
117  bool started;
118 
119  SubtitlesQueueEntry() : timeStarted(0), duration(kMinDuration), started(false) { };
120  };
121 
122  SubtitlesInfo _subtitlesInfo;
123  TextResource *_vqaSubsTextResourceEntries[kMaxTextResourceEntries];
124 
125  Graphics::Font *_font;
126  bool _useUTF8;
127  bool _useHDC;
128  Common::Array<Common::String> _subtitlesEXC;
129  Common::Array<SubtitlesData> _subtitlesDataActive;
130  Common::Array<SubtitlesQueueEntry> _subtitlesDataQueue;
131  Common::String _loadAvgStr;
132  Common::String _excTitlStr;
133  Common::String _goVib;
134 
135  bool _gameSubsResourceEntriesFound[kMaxTextResourceEntries]; // false if a TRE file did not open successfully
136  bool _isSystemActive; // true if the whole subtitles subsystem should be disabled (due to missing required resources)
137 
138 public:
140  ~Subtitles();
141 
142  bool isSystemActive() const { return _isSystemActive; }
143 
144  void init();
145  SubtitlesInfo getSubtitlesInfo() const;
146  void loadInGameSubsText(int actorId, int speech_id); // get the text for actorId, quoteId (in-game subs)
147  void loadOuttakeSubsText(const Common::String &outtakesName, int frame); // get the text for this frame if any
148 
149  void setGameSubsText(int subsRole, Common::String dbgQuote, bool force); // for debugging - explicit set subs text
150  void addGameSubsTextToQueue(Common::String dbgQuote, uint32 duration);
151  void clearQueue();
152 
153  bool show(int subsRole);
154  bool hide(int subsRole);
155  void clear();
156  bool isHDCPresent();
157  void xcReload();
158  Common::String getLoadAvgStr() const { return _loadAvgStr; }
159  const char *getGoVib() const { return _goVib.c_str(); }
160 
161  bool isVisible(int subsRole) const;
162  void tick(Graphics::Surface &s);
163  void tickOuttakes(Graphics::Surface &s);
164 
165  enum SubtitlesRole {
166  kSubtitlesPrimary,
167  kSubtitlesSecondary
168  };
169 
170 private:
171  void draw(Graphics::Surface &s);
172 
173  int getIdxForSubsTreName(const Common::String &treName) const;
174 
175  void reset();
176 
177  bool isNotEmptyCurrentSubsText(int subsRole);
178  void mergeSubtitleQuotes(int actorId, int quoteFirst, int quoteSecond);
179 };
180 
181 } // End of namespace BladeRunner
182 
183 #endif // BLADERUNNER_SUBTITLES_H
Definition: str.h:59
Definition: font.h:83
Definition: surface.h:67
Definition: subtitles.h:40
Definition: actor.h:31
Definition: ustr.h:57
Definition: formatinfo.h:28
Definition: debugger.h:56
Definition: kia_section_settings.h:42
Definition: text_resource.h:32
Definition: bladerunner.h:113
Definition: color.h:47