ScummVM API documentation
events.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_EVENT_H
23 #define NUVIE_CORE_EVENT_H
24 
25 #include "ultima/shared/engine/events.h"
26 #include "ultima/shared/std/containers.h"
27 #include "ultima/shared/std/string.h"
28 #include "ultima/nuvie/misc/call_back.h"
29 #include "ultima/nuvie/keybinding/keys_enum.h"
30 #include "ultima/nuvie/core/obj_manager.h"
31 
32 namespace Ultima {
33 namespace Nuvie {
34 
35 class Actor;
36 class CallbackTarget;
37 class Configuration;
38 class Converse;
39 class Book;
40 class Game;
41 class TimeQueue;
42 class MapWindow;
43 class MsgScroll;
44 class GameClock;
45 class Player;
46 class ViewManager;
47 class UseCode;
48 class GUI;
49 class GUI_Dialog;
50 class Magic;
51 class KeyBinder;
52 class FpsCounter;
53 class ScriptThread;
54 
55 #define NUVIE_INTERVAL 50
56 #define PUSH_FROM_PLAYER false
57 #define PUSH_FROM_OBJECT true
58 
59 enum EventMode {
60  LOOK_MODE = 0,
61  USE_MODE,
62  GET_MODE,
63  MOVE_MODE,
64  DROP_MODE,
65  TALK_MODE, /* finding an actor to talk to */
66  ATTACK_MODE,
67  PUSH_MODE,
68  REST_MODE, /* modes before this need targets if using the command bar selected action */
69  CAST_MODE,
70  COMBAT_MODE, /* only used to cancel previous actions */
71  SPELL_MODE, //direct spell casting without spell select etc.
72  EQUIP_MODE,
73  WAIT_MODE, /* waiting for something, optionally display prompt when finished */
74  INPUT_MODE,
75  MULTIUSE_MODE,
76  KEYINPUT_MODE,
77  SCRIPT_MODE
78 };
79 
80 extern uint32 nuvieGameCounter;
81 
82 // type of input that event may collect and send somewhere
83 #define EVENTINPUT_MAPCOORD 0
84 #define EVENTINPUT_KEY 1
85 #define EVENTINPUT_STRING 2
86 #define EVENTINPUT_OBJECT 3
87 #define EVENTINPUT_MAPCOORD_DIR 4
88 #define EVENTINPUT_SPELL_NUM 5
89 
93 const Common::KeyCode FIRST_JOY = (Common::KeyCode)400;
94 const Common::KeyCode JOY_UP = FIRST_JOY; // PS d-pad when analog is disabled. left stick when enabled
95 const Common::KeyCode JOY_DOWN = (Common::KeyCode)(FIRST_JOY + 1);
96 const Common::KeyCode JOY_LEFT = (Common::KeyCode)(FIRST_JOY + 2);
97 const Common::KeyCode JOY_RIGHT = (Common::KeyCode)(FIRST_JOY + 3);
98 const Common::KeyCode JOY_RIGHTUP = (Common::KeyCode)(FIRST_JOY + 4);
99 const Common::KeyCode JOY_RIGHTDOWN = (Common::KeyCode)(FIRST_JOY + 5);
100 const Common::KeyCode JOY_LEFTUP = (Common::KeyCode)(FIRST_JOY + 6);
101 const Common::KeyCode JOY_LEFTDOWN = (Common::KeyCode)(FIRST_JOY + 7);
102 const Common::KeyCode JOY_UP2 = (Common::KeyCode)(FIRST_JOY + 8); // PS right stick when analog is enabled
103 const Common::KeyCode JOY_DOWN2 = (Common::KeyCode)(FIRST_JOY + 9);
104 const Common::KeyCode JOY_LEFT2 = (Common::KeyCode)(FIRST_JOY + 10);
105 const Common::KeyCode JOY_RIGHT2 = (Common::KeyCode)(FIRST_JOY + 11);
106 const Common::KeyCode JOY_RIGHTUP2 = (Common::KeyCode)(FIRST_JOY + 12);
107 const Common::KeyCode JOY_RIGHTDOWN2 = (Common::KeyCode)(FIRST_JOY + 13);
108 const Common::KeyCode JOY_LEFTUP2 = (Common::KeyCode)(FIRST_JOY + 14);
109 const Common::KeyCode JOY_LEFTDOWN2 = (Common::KeyCode)(FIRST_JOY + 15);
110 const Common::KeyCode JOY_UP3 = (Common::KeyCode)(FIRST_JOY + 16);
111 const Common::KeyCode JOY_DOWN3 = (Common::KeyCode)(FIRST_JOY + 17);
112 const Common::KeyCode JOY_LEFT3 = (Common::KeyCode)(FIRST_JOY + 18);
113 const Common::KeyCode JOY_RIGHT3 = (Common::KeyCode)(FIRST_JOY + 19);
114 const Common::KeyCode JOY_RIGHTUP3 = (Common::KeyCode)(FIRST_JOY + 20);
115 const Common::KeyCode JOY_RIGHTDOWN3 = (Common::KeyCode)(FIRST_JOY + 21);
116 const Common::KeyCode JOY_LEFTUP3 = (Common::KeyCode)(FIRST_JOY + 22);
117 const Common::KeyCode JOY_LEFTDOWN3 = (Common::KeyCode)(FIRST_JOY + 23);
118 const Common::KeyCode JOY_UP4 = (Common::KeyCode)(FIRST_JOY + 24);
119 const Common::KeyCode JOY_DOWN4 = (Common::KeyCode)(FIRST_JOY + 25);
120 const Common::KeyCode JOY_LEFT4 = (Common::KeyCode)(FIRST_JOY + 26);
121 const Common::KeyCode JOY_RIGHT4 = (Common::KeyCode)(FIRST_JOY + 27);
122 const Common::KeyCode JOY_RIGHTUP4 = (Common::KeyCode)(FIRST_JOY + 28);
123 const Common::KeyCode JOY_RIGHTDOWN4 = (Common::KeyCode)(FIRST_JOY + 29);
124 const Common::KeyCode JOY_LEFTUP4 = (Common::KeyCode)(FIRST_JOY + 30);
125 const Common::KeyCode JOY_LEFTDOWN4 = (Common::KeyCode)(FIRST_JOY + 31);
126 const Common::KeyCode JOY_HAT_UP = (Common::KeyCode)(FIRST_JOY + 32); // PS d-pad when analog is enabled
127 const Common::KeyCode JOY_HAT_DOWN = (Common::KeyCode)(FIRST_JOY + 33);
128 const Common::KeyCode JOY_HAT_LEFT = (Common::KeyCode)(FIRST_JOY + 34);
129 const Common::KeyCode JOY_HAT_RIGHT = (Common::KeyCode)(FIRST_JOY + 35);
130 const Common::KeyCode JOY_HAT_RIGHTUP = (Common::KeyCode)(FIRST_JOY + 36);
131 const Common::KeyCode JOY_HAT_RIGHTDOWN = (Common::KeyCode)(FIRST_JOY + 37);
132 const Common::KeyCode JOY_HAT_LEFTUP = (Common::KeyCode)(FIRST_JOY + 38);
133 const Common::KeyCode JOY_HAT_LEFTDOWN = (Common::KeyCode)(FIRST_JOY + 39);
134 const Common::KeyCode JOY0 = (Common::KeyCode)(FIRST_JOY + 40); // PS triangle
135 const Common::KeyCode JOY1 = (Common::KeyCode)(FIRST_JOY + 41); // PS circle
136 const Common::KeyCode JOY2 = (Common::KeyCode)(FIRST_JOY + 42); // PS x
137 const Common::KeyCode JOY3 = (Common::KeyCode)(FIRST_JOY + 43); // PS square
138 const Common::KeyCode JOY4 = (Common::KeyCode)(FIRST_JOY + 44); // PS L2
139 const Common::KeyCode JOY5 = (Common::KeyCode)(FIRST_JOY + 45); // PS R2
140 const Common::KeyCode JOY6 = (Common::KeyCode)(FIRST_JOY + 46); // PS L1
141 const Common::KeyCode JOY7 = (Common::KeyCode)(FIRST_JOY + 47); // PS R1
142 const Common::KeyCode JOY8 = (Common::KeyCode)(FIRST_JOY + 48); // PS select
143 const Common::KeyCode JOY9 = (Common::KeyCode)(FIRST_JOY + 49); // PS start
144 const Common::KeyCode JOY10 = (Common::KeyCode)(FIRST_JOY + 50); // PS L3 (analog must be enabled)
145 const Common::KeyCode JOY11 = (Common::KeyCode)(FIRST_JOY + 51); // PS R3 (analog must be enabled)
146 const Common::KeyCode JOY12 = (Common::KeyCode)(FIRST_JOY + 52);
147 const Common::KeyCode JOY13 = (Common::KeyCode)(FIRST_JOY + 53);
148 const Common::KeyCode JOY14 = (Common::KeyCode)(FIRST_JOY + 54);
149 const Common::KeyCode JOY15 = (Common::KeyCode)(FIRST_JOY + 55);
150 const Common::KeyCode JOY16 = (Common::KeyCode)(FIRST_JOY + 56);
151 const Common::KeyCode JOY17 = (Common::KeyCode)(FIRST_JOY + 57);
152 const Common::KeyCode JOY18 = (Common::KeyCode)(FIRST_JOY + 58);
153 const Common::KeyCode JOY19 = (Common::KeyCode)(FIRST_JOY + 59);
154 
155 
156 struct EventInput_s {
157  uint8 type; // 0=loc,1=key,2=str,3=obj,4=actor
158 // union
159 // {
160  Common::KeyCode key; // last key entered, if capturing input
161  ActionKeyType action_key_type; // last ActionKeyType entered if capturing input
162  MapCoord *loc; // target location, or direction if relative ???
163  Std::string *str; // ???
164 // };
165  void set_loc(const MapCoord &c);
166  EventInput_s() : loc(0), str(0), obj(0), actor(0), get_direction(false), get_text(false),
167  target_init(0), select_from_inventory(false), select_range(0), key(Common::KEYCODE_INVALID),
168  action_key_type(ActionKeyType::CANCEL_ACTION_KEY), spell_num(0), type(0) {
169  }
170  ~EventInput_s();
171 
172  Obj *obj; // top object at loc (or object from inventory)
173  Actor *actor; // actor at loc
174  bool get_direction; // if true, entering directions selects a target
175  bool get_text; // if true, the MsgScroll is polled for text input
176  MapCoord *target_init; // where MapWindow cursor is centered when targeting
177  bool select_from_inventory; // if true, objects from inventory will be selected (and not from the map)
178  uint8 select_range; // limits movement of MapWindow cursor from center
179  sint16 spell_num;
180 };
181 typedef struct EventInput_s EventInput;
182 
184  friend class Magic; // FIXME
185 private:
186  const Configuration *config;
187  GUI *gui;
188  Game *game;
189  ObjManager *obj_manager;
190  MapWindow *map_window;
191  MsgScroll *scroll;
192  GameClock *clock;
193  Player *player;
194  Converse *converse;
195  ViewManager *view_manager;
196  UseCode *usecode;
197  Magic *magic;
198  KeyBinder *keybinder;
199  GUI_Dialog *gamemenu_dialog;
200  GUI_Dialog *assetviewer_dialog;
201 
202  Common::Event event;
203  EventMode mode, last_mode;
204  EventInput input; // collected/received input (of any type)
205 // Std::vector<EventMode> mode_stack; // current mode is at the end of the list
206  int ts; //timestamp for TimeLeft() method.
207  int altCodeVal;
208  uint16 active_alt_code; // alt-code that needs more input
209  uint8 alt_code_input_num; // alt-code can get multiple inputs
210 
211  TimeQueue *time_queue, *game_time_queue;
212  Obj *drop_obj;
213  uint16 drop_qty;
214  sint32 drop_x, drop_y; // only to allow pre-targeting from MapWindow, feel free to ignore this
215  uint8 rest_time; // How many hours?
216  uint8 rest_guard; // Who will guard?
217  Obj *push_obj;
218  Actor *push_actor;
219 
220  bool drop_from_key;
221  bool showingDialog;
222  bool showingQuitDialog;
223  bool ignore_timeleft; // do not wait for NUVIE_INTERVAL
224  bool move_in_inventory;
225  bool in_control_cheat;
226  bool looking_at_spellbook;
227  bool direction_selects_target;
228  bool _keymapperStateBeforeKEYINPUT;
229 
230  uint32 fps_timestamp;
231  uint16 fps_counter;
232  FpsCounter *fps_counter_widget;
233  ScriptThread *scriptThread;
234 
235  static Events *g_events;
236 protected:
237  inline uint32 TimeLeft();
238 
239  uint16 callback(uint16 msg, CallBack *caller, void *data = nullptr) override;
240  bool handleSDL_KEYDOWN(const Common::Event *event);
241  const char *print_mode(EventMode mode);
242  void try_next_attack();
243 
244 public:
245  Events(Shared::EventsCallback *callback, const Configuration *cfg);
246  ~Events() override;
247 
248  void clear();
249 
250  bool init(ObjManager *om, MapWindow *mw, MsgScroll *ms, Player *p, Magic *mg,
251  GameClock *gc, ViewManager *vm, UseCode *uc, GUI *g, KeyBinder *kb);
252  GUI_Dialog *get_gamemenu_dialog() {
253  return gamemenu_dialog;
254  }
255  TimeQueue *get_time_queue() {
256  return time_queue;
257  }
258  TimeQueue *get_game_time_queue() {
259  return game_time_queue;
260  }
261  EventMode get_mode() const {
262  return mode;
263  }
264  EventMode get_last_mode() const {
265  return last_mode;
266  }
267  void set_mode(EventMode new_mode);
268 
269  bool is_direction_selecting_targets() const {
270  return direction_selects_target;
271  }
272  void set_direction_selects_target(bool val) {
273  direction_selects_target = val;
274  }
275  bool using_pickpocket_cheat;
276  bool cursor_mode;
277  void update_timers();
278  bool update();
279  bool handleEvent(const Common::Event *event);
280  void request_input(CallBack *caller, void *user_data = nullptr);
281  void target_spell();
282  void close_spellbook();
283 // Prompt for input.
284 // obsolete:
285 // void useselect_mode(Obj *src, const char *prompt = nullptr); // deprecated
286 // void freeselect_mode(Obj *src, const char *prompt = nullptr); // deprecated
287  void get_scroll_input(const char *allowed = nullptr, bool can_escape = true, bool using_target_cursor = false, bool set_numbers_only_to_true = true);
288  void get_inventory_obj(Actor *actor, bool getting_target = true);
289  void get_spell_num(Actor *caster, Obj *spell_container);
290 // void get_amount();
291  void get_direction(const char *prompt);
292  void get_direction(const MapCoord &from, const char *prompt);
293  void get_target(const char *prompt);
294  void get_target(const MapCoord &init, const char *prompt);
295 // void get_obj_from_inventory(Actor *actor, const char *prompt);
296  void display_portrait(Actor *actor, const char *name = nullptr);
297 // Start a new action, setting a new mode and prompting for input.
298  bool newAction(EventMode new_mode);
299 // void doAction(sint16 rel_x = 0, sint16 rel_y = 0);
300 // void doAction(Obj *obj);
301  void doAction();
302  void cancelAction();
303  void endAction(bool prompt = false);
304 // Send input back to Events, performing an action for the current mode.
305  bool select_obj(Obj *obj, Actor *actor = nullptr);
306  bool select_view_obj(Obj *obj, Actor *actor);
307  bool select_actor(Actor *actor);
308  bool select_direction(sint16 rel_x, sint16 rel_y);
309  bool select_target(uint16 x, uint16 y, uint8 z = 0);
310  bool select_party_member(uint8 num);
311  bool select_spell_num(sint16 spell_num);
312 // bool select_obj(Obj *obj = nullptr, Actor *actor = nullptr);
313 // bool select_obj(sint16 rel_x, sint16 rel_y);
314 // There is no "select_text", as Events polls MsgScroll for new input.
315 // Similiarly, a "select_key" is unnecessary. The following method
316 // starts sending all keyboard input to 'caller'. (with the CB_DATA_READY message)
317  void key_redirect(CallBack *caller, void *user_data);
318  void cancel_key_redirect();
319 
320  /* These will be replaced in the future with an InputAction class. */
321  bool move(sint16 rel_x, sint16 rel_y);
322 
323  bool use_start();
324  bool use(sint16 rel_x, sint16 rel_y);
325  bool use(const MapCoord &coord);
326  bool use(Obj *obj);
327  bool use(Actor *actor, uint16 x, uint16 y);
328 
329  bool get_start();
330  bool get(const MapCoord &coord);
331  bool get(sint16 rel_x, sint16 rel_y);
332  bool perform_get(Obj *obj, Obj *container_obj = nullptr, Actor *actor = nullptr);
333 
334  bool look_start();
335  bool lookAtCursor(bool delayed = false, uint16 x = 0, uint16 y = 0, uint8 z = 0, Obj *obj = nullptr, Actor *actor = nullptr);
336  bool look(Obj *obj);
337  bool look(Actor *actor);
338  bool search(Obj *obj);
339 
340  bool talk_start();
341  bool talk_cursor();
342  bool talk(Actor *actor);
343  bool talk(Obj *obj);
344  bool perform_talk(Actor *actor);
345 
346  bool attack();
347 
348  bool push_start();
349  bool pushFrom(Obj *obj);
350  bool pushFrom(sint16 rel_x, sint16 rel_y);
351  bool pushFrom(const MapCoord &target);
352  bool pushTo(Obj *obj, Actor *actor);
353  bool pushTo(sint16 rel_x, sint16 rel_y, bool push_from = PUSH_FROM_PLAYER);
354 
355  void solo_mode(uint32 actor_num);
356  bool party_mode();
357  bool toggle_combat();
358 
359  bool ready(Obj *obj, Actor *actor = nullptr);
360  bool unready(Obj *obj);
361 
362  bool drop_start();
363  bool drop_select(Obj *obj, uint16 qty = 0);
364  bool drop_count(uint16 qty);
365  bool perform_drop();
366  void set_drop_from_key(bool closing_gumps) {
367  drop_from_key = closing_gumps;
368  }
369  bool drop(Obj *obj, uint16 qty, uint16 x, uint16 y);
370  bool drop(uint16 x, uint16 y) {
371  return (drop(drop_obj, drop_qty, x, y));
372  }
373  void set_drop_target(uint16 x, uint16 y) {
374  drop_x = sint32(x);
375  drop_y = sint32(y);
376  }
377  bool can_move_obj_between_actors(Obj *obj, Actor *src_actor, Actor *target_actor, bool display_name = false);
378  void display_not_aboard_vehicle(bool show_prompt = true);
379  void display_move_text(Actor *target_actor, Obj *obj);
380  bool can_get_to_actor(const Actor *actor, uint16 x, uint16 y);
381  bool using_control_cheat() const {
382  return in_control_cheat;
383  }
384  void set_control_cheat(bool control_cheat) {
385  in_control_cheat = control_cheat;
386  }
387  bool is_looking_at_spellbook() const {
388  return looking_at_spellbook;
389  }
390  void set_looking_at_spellbook(bool looking) {
391  looking_at_spellbook = looking;
392  }
393 
394  bool rest();
395  bool rest_input(uint16 input);
396 
397  void cast_spell_directly(uint8 spell_num);
398  bool can_target_icon(); // Target the actor or container tile in inventory and party view
399 
400 // these are both for mouse-using convenience
401  void walk_to_mouse_cursor(uint32 mx, uint32 my);
402  void multiuse(uint16 wx, uint16 wy);
403 
404  void alt_code(int c);
405  void alt_code_input(const char *in);
406  void clear_alt_code() { altCodeVal = 0; }
407 
408  void toggleAltCodeMode(bool enable);
409  void appendAltCode(int code);
410 
411  bool alt_code_teleport(const char *location_string);
412  void alt_code_infostring();
413  void alt_code_teleport_menu(uint32 selection);
414  bool alt_code_teleport_to_person(uint32 npc);
415 
416  void wait();
417  void set_ignore_timeleft(bool newsetting) {
418  ignore_timeleft = newsetting;
419  }
420  EventInput *get_input() {
421  return &input;
422  }
423 // These cursor methods are use to make sure Events knows where the cursor is
424 // when objects are selected with ENTER. (since MapWindow and InventoryView
425 // may each independently show/hide their own cursors)
426  void moveCursorToMapWindow(bool ToggleCursor = false);
427  void moveCursorToInventory();
428 
429  void toggleFpsDisplay();
430  void close_gumps();
431  bool do_not_show_target_cursor;
432  bool dont_show_target_cursor() const;
433  bool input_really_needs_directon() const;
434  void quitDialog();
435  void gameMenuDialog();
436  void assetViewer();
437  bool actor_exists(const Actor *a) const;
438 
439  /* FIXME: Some of the above (action) functions can be removed from public, so
440  that we don't need to check for WAIT mode in all of them. */
441 
445  static Events *get() { return g_events; }
446 };
447 
448 extern bool shouldQuit();
449 
450 } // End of namespace Nuvie
451 } // End of namespace Ultima
452 
453 #endif
Definition: map_window.h:73
Definition: actor.h:178
Definition: msg_scroll.h:93
Definition: magic.h:79
Definition: obj.h:84
Definition: configuration.h:61
Definition: keys.h:60
Definition: usecode.h:151
Definition: game_clock.h:49
Definition: gui_dialog.h:36
Definition: player.h:41
Definition: events.h:183
Definition: system.h:46
Definition: events.h:156
Definition: detection.h:27
Definition: timed_event.h:45
Definition: call_back.h:50
Definition: string.h:30
Definition: events.h:199
Definition: map.h:84
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
Definition: events.h:139
Definition: obj_manager.h:75
Definition: script.h:59
Definition: fps_counter.h:33
Definition: events.h:124
Definition: view_manager.h:57
Definition: game.h:73
Definition: converse.h:81