ScummVM API documentation
map_window.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_MAP_WINDOW_H
23 #define NUVIE_CORE_MAP_WINDOW_H
24 
25 #include "ultima/shared/std/containers.h"
26 
27 
28 #include "ultima/nuvie/core/nuvie_defs.h"
29 #include "ultima/nuvie/core/obj_manager.h"
30 #include "ultima/nuvie/gui/widgets/gui_widget.h"
31 #include "ultima/nuvie/core/map.h"
32 
33 namespace Ultima {
34 namespace Nuvie {
35 
36 class Configuration;
37 class TileManager;
38 class ActorManager;
39 class Actor;
40 class AnimManager;
41 class Map;
42 class MapCoord;
43 class Screen;
44 class CallBack;
45 class Game;
46 
47 #define MAPWINDOW_THUMBNAIL_SIZE 52
48 #define MAPWINDOW_THUMBNAIL_SCALE 3
49 
50 #define MAP_OVERLAY_DEFAULT 0 /* just below border */
51 #define MAP_OVERLAY_ONTOP 1 /* cover border */
52 
53 #define MAPWINDOW_ROOFTILES_IMG_W 5
54 #define MAPWINDOW_ROOFTILES_IMG_H 204
55 
56 typedef struct {
57  Tile *t;
58  uint16 x, y;
59 } TileInfo;
60 
61 typedef struct {
62  Tile *eye_tile;
63  uint16 prev_x, prev_y;
64  uint16 moves_left;
65  CallBack *caller;
66 } WizardEye;
67 
68 enum RoofDisplayType {ROOF_DISPLAY_OFF, ROOF_DISPLAY_NORMAL, ROOF_DISPLAY_FORCE_ON };
69 enum InterfaceType { INTERFACE_NORMAL, INTERFACE_FULLSCREEN, INTERFACE_IGNORE_BLOCK };
70 enum X_RayType { X_RAY_CHEAT_OFF = -1, X_RAY_OFF = 0, X_RAY_ON = 1, X_RAY_CHEAT_ON = 2};
71 enum CanDropOrMoveMsg { MSG_NOT_POSSIBLE, MSG_SUCCESS, MSG_BLOCKED, MSG_OUT_OF_RANGE, MSG_NO_TILE};
72 
73 class MapWindow: public GUI_Widget {
74  friend class AnimManager;
75  friend class ConverseGumpWOU;
76  Game *game;
77  const Configuration *config;
78  int game_type;
79  bool enable_doubleclick;
80  bool walk_with_left_button;
81  uint8 walk_button_mask;
82  X_RayType x_ray_view;
83  InterfaceType interface;
84 
85  bool custom_actor_tiles;
86 
87  Map *map;
88 
89  uint16 *tmp_map_buf; // tempory buffer for flood fill, hide rooms.
90  uint16 tmp_map_width, tmp_map_height;
91  Graphics::ManagedSurface *overlay; // used for visual effects
92  uint8 overlay_level; // where the overlay surface is placed
93  int min_brightness;
94 
95  TileManager *tile_manager;
96  ObjManager *obj_manager;
97  ActorManager *actor_manager;
98  AnimManager *anim_manager;
99 
100  sint16 cur_x, cur_y;
101  uint16 cursor_x, cursor_y, map_center_xoff;
102  sint16 mousecenter_x, mousecenter_y; // location mousecursor rotates around, relative to cur_x&cur_y
103  uint16 last_boundary_fill_x, last_boundary_fill_y; // start of boundary-fill in previous blacking update
104  Tile *cursor_tile;
105  Tile *use_tile;
106 
107  bool show_cursor;
108  bool show_use_cursor;
109  bool show_grid;
110 
111  unsigned char *thumbnail;
112  bool new_thumbnail;
113 
114  uint16 win_width, win_height, border_width;
115  uint8 cur_level;
116  uint16 map_width;
117 
118  uint8 cur_x_add, cur_y_add; // pixel offset from cur_x,cur_y (set by shiftMapRelative)
119  sint32 vel_x, vel_y; // velocity of automatic map movement (pixels per second)
120 
121  Common::Rect clip_rect;
122  Graphics::ManagedSurface _mapWinSubSurf; // sub surface of the screen clipped to MapWindow's clip_rect
123 
124  Obj *selected_obj;
125  Actor *look_actor;
126  Obj *look_obj;
127  bool hackmove;
128  bool walking;
129  bool look_on_left_click;
130  bool looking; // used to stop look_on_left_click from triggering during mouseup from left button walking, failed drag, or input mode
131 
132  bool window_updated;
133  bool freeze_blacking_location;
134  bool enable_blacking;
135 
136  bool roof_mode;
137  RoofDisplayType roof_display;
138 
139  Graphics::ManagedSurface *roof_tiles;
140 
141  WizardEye wizard_eye_info;
142 
143  bool draw_brit_lens_anim;
144  bool draw_garg_lens_anim;
145 // Std::vector<TileInfo> m_ViewableObjTiles; // shouldn't need this for in_town checks
146  Std::vector<TileInfo> m_ViewableMapTiles;
147 
148  bool lighting_update_required;
149 
150  bool game_started;
151 
152 public:
153 
154  MapWindow(const Configuration *cfg, Map *m);
155  ~MapWindow() override;
156 
157  bool init(TileManager *tm, ObjManager *om, ActorManager *am);
158 
159  sint16 get_cur_x() const {
160  return cur_x;
161  }
162  sint16 get_cur_y() const {
163  return cur_y;
164  }
165  bool set_windowSize(uint16 width, uint16 height);
166  void set_show_cursor(bool state);
167  void set_show_use_cursor(bool state);
168  void set_show_grid(bool state);
169  bool is_grid_showing() {
170  return show_grid;
171  }
172  void set_velocity(sint16 vx, sint16 vy) {
173  vel_x = vx;
174  vel_y = vy;
175  }
176  void set_overlay(Graphics::ManagedSurface *surfpt);
177  void set_overlay_level(int level = MAP_OVERLAY_DEFAULT) {
178  overlay_level = level;
179  }
180  void set_x_ray_view(X_RayType state, bool cheat_off = false);
181  X_RayType get_x_ray_view() {
182  return x_ray_view;
183  }
184  void set_freeze_blacking_location(bool state);
185  void set_enable_blacking(bool state);
186  void set_roof_mode(bool roofs);
187  void set_roof_display_mode(enum RoofDisplayType mode) {
188  roof_display = mode;
189  }
190  void set_walking(bool state);
191  void set_walk_button_mask();
192  bool will_walk_with_left_button() {
193  return walk_with_left_button;
194  }
195  void set_walk_with_left_button(bool val) {
196  walk_with_left_button = val;
197  set_walk_button_mask();
198  }
199  void set_looking(bool state) {
200  looking = state;
201  }
202  int get_min_brightness() {
203  return min_brightness;
204  }
205  void set_min_brightness(int brightness) {
206  min_brightness = brightness;
207  }
208 
209  void moveLevel(uint8 new_level);
210  void moveMap(sint16 new_x, sint16 new_y, sint8 new_level, uint8 new_x_add = 0, uint8 new_y_add = 0);
211  void moveMapRelative(sint16 rel_x, sint16 rel_y);
212  void shiftMapRelative(sint16 rel_x, sint16 rel_y);
213  void set_mousecenter(sint16 new_x, sint16 new_y) {
214  mousecenter_x = new_x;
215  mousecenter_y = new_y;
216  }
217  void reset_mousecenter() {
218  mousecenter_x = win_width / 2;
219  mousecenter_y = win_height / 2;
220  }
221  uint16 get_win_area() {
222  return win_width * win_height;
223  }
224  void centerMapOnActor(Actor *actor);
225  void centerMap(uint16 x, uint16 y, uint8 z);
226  void centerCursor();
227 
228  void moveCursor(sint16 new_x, sint16 new_y);
229  void moveCursorRelative(sint16 rel_x, sint16 rel_y);
230 
231  bool is_doubleclick_enabled() {
232  return enable_doubleclick;
233  }
234  void set_enable_doubleclick(bool val) {
235  enable_doubleclick = val;
236  }
237  void set_look_on_left_click(bool val) {
238  look_on_left_click = val;
239  }
240  void set_use_left_clicks();
241  bool will_look_on_left_click() {
242  return look_on_left_click;
243  }
244  bool is_on_screen(uint16 x, uint16 y, uint8 z);
245  bool tile_is_black(uint16 x, uint16 y, const Obj *obj = nullptr) const; // subtracts cur_x and cur_y
246  const char *look(uint16 x, uint16 y, bool show_prefix = true);
247  const char *lookAtCursor(bool show_prefix = true) {
248  return (look(cursor_x, cursor_y, show_prefix));
249  }
250  Obj *get_objAtCursor(bool for_use = false);
251  Obj *get_objAtCoord(MapCoord coord, bool top_obj, bool include_ignored_objects, bool for_use = false);
252  Actor *get_actorAtCursor();
253  MapCoord get_cursorCoord();
254  Obj *get_objAtMousePos(int x, int y);
255  Actor *get_actorAtMousePos(int x, int y);
256  void teleport_to_cursor();
257  void select_target(int x, int y);
258  void mouseToWorldCoords(int mx, int my, int &wx, int &wy);
259  void get_movement_direction(uint16 mx, uint16 my, sint16 &rel_x, sint16 &rel_y, uint8 *mptr = nullptr);
260 
261  TileManager *get_tile_manager() {
262  return tile_manager;
263  }
264  AnimManager *get_anim_manager() {
265  return anim_manager;
266  }
267  const Common::Rect *get_clip_rect() const {
268  return &clip_rect;
269  }
270  Graphics::ManagedSurface *get_overlay();
271 
272  void get_level(uint8 *level) const;
273  void get_pos(uint16 *x, uint16 *y, uint8 *px = nullptr, uint8 *py = nullptr) const;
274  void get_velocity(sint16 *vx, sint16 *vy) const {
275  *vx = vel_x;
276  *vy = vel_y;
277  }
278  void get_windowSize(uint16 *width, uint16 *height) const;
279 
280  bool in_window(uint16 x, uint16 y, uint8 z) const;
281  bool in_dungeon_level() const;
282  bool in_town() const;
283 // can put object at world location x,y?
284  CanDropOrMoveMsg can_drop_or_move_obj(uint16 x, uint16 y, Actor *actor, Obj *obj);
285  void display_can_drop_or_move_msg(CanDropOrMoveMsg msg, Std::string msg_text = "");
286  bool can_get_obj(const Actor *actor, Obj *obj);
287  bool blocked_by_wall(const Actor *actor, const Obj *obj);
288  MapCoord original_obj_loc;
289 
290  void updateBlacking();
291  void updateAmbience();
292  void update();
293  void Display(bool full_redraw) override;
294 
295  GUI_status MouseDown(int x, int y, Shared::MouseButton button) override;
296  GUI_status MouseUp(int x, int y, Shared::MouseButton button) override;
297  GUI_status MouseMotion(int x, int y, uint8 state) override;
298  GUI_status MouseDouble(int x, int y, Shared::MouseButton button) override;
299  GUI_status MouseClick(int x, int y, Shared::MouseButton button) override;
300  GUI_status Idle(void) override;
301  GUI_status MouseLeave(uint8 state) override;
302  GUI_status MouseDelayed(int x, int y, Shared::MouseButton button) override;
303  GUI_status MouseHeld(int x, int y, Shared::MouseButton button) override;
304  GUI_status KeyDown(const Common::KeyState &key) override;
305  GUI_status MouseWheel(sint32 x, sint32 y) override;
306 
307  void drag_drop_success(int x, int y, int message, void *data) override;
308  void drag_drop_failed(int x, int y, int message, void *data) override;
309 
310  bool drag_accept_drop(int x, int y, int message, void *data) override;
311  void drag_perform_drop(int x, int y, int message, void *data) override;
312  bool move_on_drop(Obj *obj);
313  void set_interface();
314  InterfaceType get_interface();
315  bool is_interface_fullscreen_in_combat();
316 
317  void drag_draw(int x, int y, int message, void *data) override;
318 
319  void update_mouse_cursor(uint32 mx, uint32 my);
320 
321  unsigned char *make_thumbnail();
322  void free_thumbnail();
323  Graphics::ManagedSurface *get_sdl_surface();
324  Graphics::ManagedSurface *get_sdl_surface(uint16 x, uint16 y, uint16 w, uint16 h);
325  Graphics::ManagedSurface *get_roof_tiles() {
326  return roof_tiles;
327  }
328 
329  Std::vector<const Obj *> m_ViewableObjects; //^^ dodgy public buffer
330 
331  void wizard_eye_start(const MapCoord &location, uint16 duration, CallBack *caller);
332 
333  bool using_map_tile_lighting;
334 
335 protected:
336  void create_thumbnail();
337 
338  void drawActors();
339  void drawAnims(bool top_anims);
340  void drawObjs();
341  void drawObjSuperBlock(bool draw_lowertiles, bool toptile);
342  inline void drawObj(const Obj *obj, bool draw_lowertiles, bool toptile);
343  inline void drawTile(const Tile *tile, uint16 x, uint16 y, bool toptile, bool use_tile_data = false);
344  inline void drawNewTile(const Tile *tile, uint16 x, uint16 y, bool toptile);
345  void drawBorder();
346  inline void drawTopTile(const Tile *tile, uint16 x, uint16 y, bool toptile);
347  inline void drawActor(const Actor *actor);
348  void drawRoofs();
349  void drawGrid();
350  void drawRain();
351  inline void drawLensAnim();
352 
353  void updateLighting();
354  void generateTmpMap();
355  void boundaryFill(const byte *map_ptr, uint16 pitch, uint16 x, uint16 y);
356  bool floorTilesVisible();
357  bool boundaryLookThroughWindow(uint16 tile_num, uint16 x, uint16 y);
358 
359  void reshapeBoundary();
360  inline bool tmpBufTileIsBlack(uint16 x, uint16 y) const;
361  bool tmpBufTileIsBoundary(uint16 x, uint16 y);
362  bool tmpBufTileIsWall(uint16 x, uint16 y, NuvieDir direction);
363 
364  void wizard_eye_stop();
365  void wizard_eye_update();
366  bool is_wizard_eye_mode() {
367  if (wizard_eye_info.moves_left != 0) return true;
368  else return false;
369  }
370 
371  void loadRoofTiles();
372 
373 private:
374  void createLightOverlay();
375 
376  void AddMapTileToVisibleList(uint16 tile_num, uint16 x, uint16 y);
377  bool can_display_obj(uint16 x, uint16 y, Obj *obj);
378 };
379 
380 } // End of namespace Nuvie
381 } // End of namespace Ultima
382 
383 #endif
Definition: managed_surface.h:51
Definition: map_window.h:73
Definition: actor.h:178
Definition: gui_widget.h:38
Definition: obj.h:84
Definition: configuration.h:61
Definition: rect.h:144
Definition: map.h:147
Definition: atari-screen.h:60
Definition: tile_manager.h:145
Definition: actor_manager.h:42
Definition: detection.h:27
Definition: map_window.h:61
Definition: call_back.h:50
Definition: converse_gump_wou.h:41
Definition: string.h:30
Definition: map_window.h:56
Definition: map.h:84
Definition: obj_manager.h:75
Definition: keyboard.h:294
Definition: tile_manager.h:113
Definition: anim_manager.h:53
Definition: containers.h:38
Definition: game.h:73