ScummVM API documentation
interaction.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 MM1_VIEWS_ENH_INTERACTIONS_INTERACTION_H
23 #define MM1_VIEWS_ENH_INTERACTIONS_INTERACTION_H
24 
25 #include "mm/mm1/views_enh/party_view.h"
26 #include "mm/shared/xeen/sprites.h"
27 
28 namespace MM {
29 namespace MM1 {
30 namespace ViewsEnh {
31 namespace Interactions {
32 
33 class Interaction : public PartyView {
34  struct InteractionButton {
35  Common::String _text;
36  char _c = '\0';
37  Common::Rect _bounds;
38  InteractionButton() {}
39  InteractionButton(const Common::String &text, char c) :
40  _text(text), _c(toupper(c)) {}
41  };
42 private:
45  int _tickCtr = 0;
46  int _portraitFrameNum = 0;
47 protected:
48  Common::String _title;
49  Common::StringArray _lines;
51 
52  bool _animated = true;
53  int _portraitNum = 0;
54 protected:
55  bool selectCharByDefault() const override {
56  return false;
57  }
58 
62  virtual void viewAction() {}
63 
67  void addText(const Common::String &str);
68 
72  void clearButtons() {
73  _buttons.clear();
74  }
75 
79  void addButton(const Common::String &str, char c) {
80  _buttons.push_back(InteractionButton(str, c));
81  }
82 
86  void writeLine(int lineNum, const Common::String &str,
87  TextAlign align = ALIGN_LEFT, int xp = 0) {
88  PartyView::writeLine(6 + lineNum, str, align, xp);
89  }
90 
94  void writeLine(int lineNum, int value,
95  TextAlign align = ALIGN_LEFT, int xp = 0) {
96  PartyView::writeLine(6 + lineNum,
97  Common::String::format("%d", value), align, xp);
98  }
99 
100 public:
101  Interaction(const Common::String &name, int portrait = -1);
102 
106  bool msgGame(const GameMessage &msg) override;
107 
111  bool msgUnfocus(const UnfocusMessage &msg) override;
112 
116  void draw() override;
117 
121  bool tick() override;
122 
126  void leave();
127 
131  bool msgKeypress(const KeypressMessage &msg) override;
132 
136  bool msgAction(const ActionMessage &msg) override;
137 
141  bool msgMouseDown(const MouseDownMessage &msg) override;
142 };
143 
144 } // namespace Interactions
145 } // namespace ViewsEnh
146 } // namespace MM1
147 } // namespace MM
148 
149 #endif
bool selectCharByDefault() const override
Definition: interaction.h:55
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
bool msgGame(const GameMessage &msg) override
void addButton(const Common::String &str, char c)
Definition: interaction.h:79
bool msgAction(const ActionMessage &msg) override
void clear()
Definition: array.h:320
void writeLine(int lineNum, const Common::String &str, TextAlign align=ALIGN_LEFT, int xp=0)
Definition: interaction.h:86
Definition: sprites.h:52
void writeLine(int lineNum, int value, TextAlign align=ALIGN_LEFT, int xp=0)
Definition: interaction.h:94
Definition: rect.h:144
Definition: party_view.h:32
Definition: messages.h:56
bool msgUnfocus(const UnfocusMessage &msg) override
bool msgMouseDown(const MouseDownMessage &msg) override
void writeLine(int lineNum, const Common::String &str, TextAlign align=ALIGN_LEFT, int xp=0)
Definition: messages.h:49
void push_back(const T &element)
Definition: array.h:180
Definition: messages.h:72
void clearButtons()
Definition: interaction.h:72
Definition: detection.h:27
Definition: messages.h:48
bool msgKeypress(const KeypressMessage &msg) override
Definition: messages.h:87
void addText(const Common::String &str)
virtual void viewAction()
Definition: interaction.h:62