ScummVM API documentation
dialogs_manager.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 CRYOMNI3D_DIALOGS_MANAGER_H
23 #define CRYOMNI3D_DIALOGS_MANAGER_H
24 
25 #include "common/array.h"
26 #include "common/hash-str.h"
27 #include "common/hashmap.h"
28 #include "common/path.h"
29 #include "common/rect.h"
30 #include "common/str.h"
31 #include "common/str-array.h"
32 
33 namespace CryOmni3D {
34 
36 public:
38  SubtitlesSettings() { }
39  SubtitlesSettings(int16 textLeft, int16 textTop, int16 textRight, int16 textBottom,
40  int16 drawLeft, int16 drawTop, int16 drawRight, int16 drawBottom) :
41  textRect(textLeft, textTop, textRight, textBottom), drawRect(drawLeft, drawTop, drawRight,
42  drawBottom) { }
43  Common::Rect textRect;
44  Common::Rect drawRect;
45  };
46 
47  DialogsManager() : _gtoBuffer(nullptr), _gtoEnd(nullptr),
48  _ignoreNoEndOfConversation(false) { }
49  virtual ~DialogsManager();
50 
51  void init(uint arraySize, const Common::String &endOfConversationText) { _dialogsVariables.resize(arraySize); _endOfConversationText = endOfConversationText; }
52  void loadGTO(const Common::Path &gtoFilePath);
53 
54  void setupVariable(uint id, const Common::String &variable) { _dialogsVariables[id] = DialogVariable(variable, 'N'); }
55  void reinitVariables();
56  uint size() const { return _dialogsVariables.size(); }
57  byte &operator[](uint idx) { return _dialogsVariables[idx].value; }
58  const byte &operator[](uint idx) const { return _dialogsVariables[idx].value; }
59  byte &operator[](const Common::String &name) { return find(name).value; }
60  const byte &operator[](const Common::String &name) const { return find(name).value; }
61 
62  void registerSubtitlesSettings(const Common::String &videoName, const SubtitlesSettings &settings);
63 
64  void setIgnoreNoEndOfConversation(bool ignore) { _ignoreNoEndOfConversation = ignore; }
65  bool play(const Common::String &sequence, bool &slowStop);
66 
67 protected:
68  virtual void executeShow(const Common::String &show) = 0;
69  virtual void playDialog(const Common::String &video, const Common::String &sound,
70  const Common::String &text, const SubtitlesSettings &settings) = 0;
71  virtual void displayMessage(const Common::String &text) = 0;
72  virtual uint askPlayerQuestions(const Common::String &video,
73  const Common::StringArray &questions) = 0;
74 
75 private:
76  struct Goto {
77  Goto() : label(), text(nullptr) {
78  }
79  Goto(const Common::String &label_, const char *text_) : label(label_), text(text_) {
80  }
81 
82  Common::String label;
83  const char *text;
84  };
85 
86  struct DialogVariable {
87  DialogVariable() : name(), value(0) {
88  }
89  DialogVariable(const Common::String &name_, byte value_) : name(name_), value(value_) {
90  }
91 
92  Common::String name;
93  byte value;
94  };
95 
96  const DialogVariable &find(const Common::String &name) const;
97  DialogVariable &find(const Common::String &name);
98  Common::Array<DialogVariable> _dialogsVariables;
99 
100  void populateLabels();
101  const char *findLabel(const char *label, const char **realLabel = nullptr) const;
102  Common::String getLabelSound(const char *label) const;
103 
104  const char *findSequence(const char *sequence) const;
105  Common::String findVideo(const char *data) const;
106  Common::String getText(const char *text) const;
107 
108  Common::Array<Goto> executeAfterPlayAndBuildGotoList(const char *actions);
109  void buildGotoGoto(const char *gotoLine, Common::Array<Goto> &gotos);
110  bool buildGotoIf(const char *ifLine, Common::Array<Goto> &gotos);
111  void executeLet(const char *letLine);
112  void executeShow(const char *showLine);
113 
114  const char *executePlayerQuestion(const char *text, bool dryRun, const char **realLabel = nullptr);
115  const char *parseIf(const char *ifLine);
116 
117  const char *nextLine(const char *currentPtr) const;
118  const char *nextChar(const char *currentPtr) const;
119  const char *previousMatch(const char *currentPtr, const char *str) const;
120 
121  char *_gtoBuffer;
122  const char *_gtoEnd;
124 
125  Common::String _endOfConversationText;
126  bool _ignoreNoEndOfConversation;
127 
129 };
130 
131 } // End of namespace CryOmni3D
132 
133 #endif
Definition: cryomni3d.h:62
Definition: str.h:59
Definition: rect.h:144
Definition: path.h:52
Definition: dialogs_manager.h:37
Definition: dialogs_manager.h:35
Definition: hashmap.h:85