ScummVM API documentation
msg_scroll.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 NUVIE_CORE_MSG_SCROLL_H
23 #define NUVIE_CORE_MSG_SCROLL_H
24 
25 #include "ultima/nuvie/misc/call_back.h"
26 #include "ultima/nuvie/gui/widgets/gui_widget.h"
27 #include "ultima/shared/std/containers.h"
28 
29 #define MSGSCROLL_U6_WIDTH 17
30 #define MSGSCROLL_U6_HEIGHT 10
31 
32 #define MSGSCROLL_MD_WIDTH 16
33 #define MSGSCROLL_MD_HEIGHT 8
34 
35 #define MSGSCROLL_SE_WIDTH 16
36 #define MSGSCROLL_SE_HEIGHT 8
37 
38 #define MSGSCROLL_CURSOR_DELAY 6 // used to slow down the animated cursor
39 
40 #define MSGSCROLL_SCROLLBACK_HEIGHT 100
41 
42 #define MSGSCROLL_NO_MAP_DISPLAY false
43 
44 namespace Ultima {
45 namespace Nuvie {
46 
47 using Std::list;
48 
49 
50 class Configuration;
51 class Font;
52 class Actor;
53 
54 class MsgText {
55 public:
56 
57  Font *font;
58  Std::string s;
59  uint8 color;
60 
61  MsgText();
62  MsgText(const Std::string &new_string, Font *f);
63  ~MsgText();
64 
65  void append(const Std::string &new_string);
66  void copy(MsgText *msg_text);
67  uint32 length();
68 
69  uint16 getDisplayWidth();
70  bool operator<(const MsgText &rhs) const {
71  return (s < rhs.s);
72  }
73 };
74 
75 class MsgLine {
76 public:
77 
79  uint32 total_length;
80 
81  MsgLine() {
82  total_length = 0;
83  };
84  ~MsgLine();
85 
86  void append(MsgText *new_text);
87  void remove_char();
88  uint32 length();
89  MsgText *get_text_at_pos(uint16 pos);
90  uint16 get_display_width();
91 };
92 
93 class MsgScroll: public GUI_Widget, public CallBack {
94 protected:
95  const Configuration *config;
96  int game_type;
97  Font *font;
98  uint8 font_color;
99  uint8 font_highlight_color;
100  uint16 scroll_height;
101  uint16 scroll_width;
102  uint8 left_margin; // margin width in pixels
103 
104 // set by request_input()
105  CallBack *callback_target;
106  char *callback_user_data;
107  uint8 input_char;
108  bool input_mode;
109  const char *permit_input; // character list, or 0 = any string
110  bool yes_no_only, aye_nay_only, numbers_only; // limited input selection
111 
112  bool page_break;
113  bool just_finished_page_break;
114  bool just_displayed_prompt;
115  virtual void process_page_break();
116  Std::list<MsgLine *> msg_buf;
117 
118  Std::string input_buf;
119  bool permit_inputescape; // can RETURN or ESCAPE be used to escape input entry
120 
121  uint16 cursor_wait;
122 
123  uint16 scrollback_height;
124  bool discard_whitespace;
125  bool using_target_cursor;
126 
127  uint8 bg_color;
128  bool talking;
129 
130 private:
131  uint16 screen_x; //x offset to top left corner of MsgScroll
132  uint16 screen_y; //y offset to top left corner of MsgScroll
133 
134  bool keyword_highlight;
135 
136  MsgText prompt;
137  Std::list<MsgText *> holding_buffer;
138 
139  bool show_cursor;
140  bool autobreak; // if true, a page break will be added when the scroll is full
141 
142  bool scroll_updated;
143  uint8 cursor_char;
144  uint16 cursor_x, cursor_y;
145 
146  uint16 line_count; // count the number of lines since last page break.
147 
148  uint16 display_pos;
149 
150  bool capitalise_next_letter;
151 
152 public:
153 
154  MsgScroll(const Configuration *cfg, Font *f);
155  MsgScroll() : GUI_Widget(nullptr, 0, 0, 0, 0),
156  config(nullptr), game_type(0), font(nullptr), scroll_height(0),
157  scroll_width(0), callback_target(nullptr), callback_user_data(nullptr),
158  input_mode(false), permit_input(nullptr), page_break(false),
159  just_finished_page_break(false), permit_inputescape(false),
160  cursor_wait(0), screen_x(0), screen_y(0), bg_color(0),
161  keyword_highlight(true), talking(false), show_cursor(false),
162  autobreak(false), scroll_updated(false), cursor_char(0),
163  cursor_x(0), cursor_y(0), line_count(0), display_pos(0),
164  capitalise_next_letter(false), just_displayed_prompt(false),
165  scrollback_height(MSGSCROLL_SCROLLBACK_HEIGHT), discard_whitespace(false),
166  left_margin(0), font_color(0), font_highlight_color(0), input_char(0),
167  yes_no_only(false), aye_nay_only(false), numbers_only(false),
168  using_target_cursor(false) {
169  }
170  ~MsgScroll() override;
171 
172  void init(const Configuration *cfg, Font *f);
173 
174  bool init(const char *player_name);
175  void page_up();
176  void page_down();
177  virtual void move_scroll_down();
178  virtual void move_scroll_up();
179  void set_using_target_cursor(bool val) {
180  using_target_cursor = val;
181  }
182 
183  void process_holding_buffer();
184 
185  MsgText *holding_buffer_get_token();
186  bool is_holding_buffer_empty() const {
187  return holding_buffer.empty();
188  }
189  virtual bool can_display_prompt() const {
190  return !just_displayed_prompt;
191  }
192 
193  virtual bool parse_token(MsgText *token);
194  void add_token(MsgText *token);
195  bool remove_char();
196 
197  virtual void set_font(uint8 font_type);
198  virtual bool is_garg_font();
199 
200  template<class... TParam>
201  int print(const Std::string &format, TParam... param);
202 
203  virtual void display_string(const Std::string &s, Font *f, bool include_on_map_window);
204  void display_string(const Std::string &s, Font *f, uint8 color, bool include_on_map_window);
205  void display_string(const Std::string &s, uint16 length, uint8 lang_num);
206  void display_string(const Std::string &s, bool include_on_map_window = true);
207  void display_string(const Std::string &s, uint8 color, bool include_on_map_window);
208  void display_fmt_string(const char *format, ...);
209  void message(const char *string) {
210  display_string(string);
211  display_prompt();
212  }
213 
214  bool set_prompt(const char *new_prompt, Font *f = nullptr);
215  virtual void display_prompt();
216  virtual void display_converse_prompt();
217 
218  void set_keyword_highlight(bool state);
219 
220  void set_input_mode(bool state, const char *allowed = nullptr,
221  bool can_escape = true, bool use_target_cursor = false,
222  bool set_numbers_only_to_true = false);
223  virtual void set_talking(bool state, Actor *actor = nullptr) {
224  talking = state;
225  input_char = 0;
226  }
227  bool is_talking() const {
228  return talking;
229  }
230  void set_show_cursor(bool state) {
231  show_cursor = state;
232  }
233 
234  void set_autobreak(bool state) {
235  autobreak = state;
236  }
237  void set_discard_whitespace(bool discard) {
238  discard_whitespace = discard;
239  }
240 
241  bool get_page_break() const {
242  return page_break;
243  }
244 
245  GUI_status KeyDown(const Common::KeyState &key) override;
246  GUI_status MouseUp(int x, int y, Shared::MouseButton button) override;
247  GUI_status MouseWheel(sint32 x, sint32 y) override;
248  virtual Std::string get_token_string_at_pos(uint16 x, uint16 y);
249 //void updateScroll();
250  void Display(bool full_redraw) override;
251 
252  void clearCursor(uint16 x, uint16 y);
253  virtual void drawCursor(uint16 x, uint16 y);
254 
255  void set_page_break();
256 
257  virtual bool input_buf_add_char(char c);
258  virtual bool input_buf_remove_char();
259 
260  /* Converse uses this to tell if the scroll has finished displaying the converse dialog */
261  virtual bool is_converse_finished() {
262  return true;
263  }
264 
265  bool has_input();
266  Std::string get_input();
267  const char *peek_at_input();
268  void request_input(CallBack *caller, void *user_data);
269  void cancel_input_request() {
270  request_input(nullptr, nullptr);
271  }
272  void clear_scroll();
273 
274 protected:
275 
276  void set_scroll_dimensions(uint16 w, uint16 h);
277  void delete_front_line();
278  virtual MsgLine *add_new_line();
279  void drawLine(Screen *screen, MsgLine *msg_line, uint16 line_y);
280  inline void clear_page_break();
281 
282  virtual void set_permitted_input(const char *allowed);
283  virtual void clear_permitted_input();
284  virtual bool can_fit_token_on_msgline(MsgLine *msg_line, MsgText *token);
285  void increase_input_char();
286  void decrease_input_char();
287  uint8 get_char_from_input_char();
288  virtual uint8 get_input_font_color() const {
289  return font_color;
290  }
291 
292 private:
293  int print_internal(const Std::string *format, ...);
294 };
295 
296 template<class... TParam>
297 inline int MsgScroll::print(const Std::string &format, TParam... param) {
298  return print_internal(&format, Common::forward<TParam>(param)...);
299 }
300 
301 } // End of namespace Nuvie
302 } // End of namespace Ultima
303 
304 #endif
Definition: actor.h:178
Definition: msg_scroll.h:93
Definition: gui_widget.h:38
Definition: configuration.h:61
Definition: list.h:39
Definition: msg_scroll.h:75
Definition: screen.h:41
Definition: detection.h:27
Definition: call_back.h:50
Definition: string.h:30
Definition: msg_scroll.h:54
Definition: containers.h:200
Definition: keyboard.h:294
bool empty() const
Definition: list.h:219
Definition: font.h:42