The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
game_display.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /** @file */
16 
17 #ifndef GAME_DISPLAY_H_INCLUDED
18 #define GAME_DISPLAY_H_INCLUDED
19 
20 class config;
21 class tod_manager;
22 class team;
23 class unit_map;
24 class game_board;
25 
26 #include "animated.hpp"
27 #include "chat_events.hpp"
28 #include "display.hpp"
29 #include "display_chat_manager.hpp"
30 #include "pathfind/pathfind.hpp"
31 
32 #include <deque>
33 
34 // This needs to be separate from display.h because of the static
35 // singleton member, which will otherwise trigger link failure
36 // when building the editor.
37 
38 class game_display : public display
39 {
40 public:
42  boost::weak_ptr<wb::manager> wb,
43  reports & reports_object,
44  const tod_manager& tod_manager,
45  const config& theme_cfg,
46  const config& level,
47  bool dummy=false);
48 
50 
51  ~game_display();
53  {
54  return static_cast<game_display*>(singleton_);
55  }
56 
57  /**
58  * Update lighting settings.
59  *
60  * Should be called on every new turn.
61  */
62  void new_turn();
63 
64  const std::set<std::string>& observers() const { return chat_man_->observers(); }
65  /**
66  * Scrolls to the leader of a certain side.
67  *
68  * This will normally be the playing team.
69  */
70  void scroll_to_leader(int side, SCROLL_TYPE scroll_type = ONSCREEN,bool force = true);
71 
72  /**
73  * Function to display a location as selected.
74  *
75  * If a unit is in the location, and there is no unit in the currently
76  * highlighted hex, the unit will be displayed in the sidebar.
77  */
78  virtual void select_hex(map_location hex);
79 
80  /**
81  * Function to highlight a location.
82  *
83  * If a unit is in the location, it will be displayed in the sidebar.
84  * Selection is used when a unit has been clicked on, while highlighting is
85  * used when a location has been moused over.
86  */
87  virtual void highlight_hex(map_location hex);
88 
89  /**
90  * Change the unit to be displayed in the sidebar.
91  *
92  * This is used when selecting or highlighting is not wanted.
93  */
95 
96  /**
97  * Sets the paths that are currently displayed as available
98  * for the unit to move along.
99  * All other paths will be grayed out.
100  */
101  void highlight_reach(const pathfind::paths &paths_list);
102 
103  /**
104  * Add more paths to highlight. Print numbers where they overlap.
105  * Used only by Show Enemy Moves.
106  */
107  void highlight_another_reach(const pathfind::paths &paths_list);
108 
109  /** Reset highlighting of paths. */
110  void unhighlight_reach();
111 
112  /**
113  * Sets the route along which footsteps are drawn to show movement of a
114  * unit. If nullptr, no route is displayed. @a route does not have to remain
115  * valid after being set.
116  */
117  void set_route(const pathfind::marked_route *route);
118 
119  /** Function to float a label above a tile */
120  void float_label(const map_location& loc, const std::string& text, const SDL_Color& color);
121 
122  /** Draws the movement info (turns available) for a given location. */
123  void draw_movement_info(const map_location& loc);
124 
125  /** Function to invalidate that unit status displayed on the sidebar. */
127 
128  /** Same as invalidate_unit() if moving the displayed unit. */
130 
131  const time_of_day& get_time_of_day(const map_location& loc) const;
132 
133  bool has_time_area() const;
134 
135  const tod_manager & get_tod_man() const { return *tod_manager_; } /**< Allows this class to properly implement filter context, used for animations */
136 
137 protected:
138  /**
139  * game_display pre_draw does specific things related e.g. to unit rendering
140  * and calls the whiteboard pre-draw method.
141  */
142  void pre_draw();
143  /**
144  * Calls the whiteboard's post-draw method.
145  */
146  void post_draw();
147 
148  void draw_invalidated();
149 
150  void post_commit();
151 
152  void draw_hex(const map_location& loc);
153 
154 
155 public:
156 
157 
158 
159  /** Set the attack direction indicator. */
161  void clear_attack_indicator();
162 
163  /** Function to get attack direction suffix. */
167  }
168 
169  // Functions used in the editor:
170 
171  //void draw_terrain_palette(int x, int y, terrain_type::TERRAIN selected);
172  t_translation::t_terrain get_terrain_on(int palx, int paly, int x, int y);
173 
174  /**
175  * Sets the team controlled by the player using the computer.
176  *
177  * Data from this team will be displayed in the game status.
178  * set_playing_team sets the team whose turn it currently is
179  */
180  void set_playing_team(size_t team);
181 
182 
184 
185 
186  /**
187  * annotate hex with number, useful for debugging or UI prototype
188  */
189  static int& debug_highlight(const map_location& loc);
190  static void clear_debug_highlights() { debugHighlights_.clear(); }
191 
192 
193  /** The playing team is the team whose turn it is. */
194  int playing_side() const { return activeTeam_ + 1; }
195 
196 
198 
200 
201  void begin_game();
202 
203  virtual bool in_game() const { return in_game_; }
204 
205 
206  /**
207  * Sets the linger mode for the display.
208  * There have been some discussions on what to do with fog and shroud
209  * the extra variables make it easier to modify the behavior. There
210  * might even be a split between victory and defeat.
211  *
212  * @todo if the current implementation is wanted we can change
213  * the stuff back to a boolean
214  */
215  enum tgame_mode {
216  RUNNING, /**< no linger overlay, show fog and shroud. */
217  LINGER }; /**< linger overlay, show fog and shroud. */
218 
219  void set_game_mode(const tgame_mode game_mode);
220 
221  /// Sets whether the screen (map visuals) needs to be rebuilt. This is typically after the map has been changed by wml.
222  void needs_rebuild(bool b);
223 
224  /// Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
225  bool maybe_rebuild();
226  void reset_tod_manager(const tod_manager& tod_manager)
227  {
229  }
230 private:
231  game_display(const game_display&);
232  void operator=(const game_display&);
233 
234  void draw_sidebar();
235 
237 
238  // Locations of the attack direction indicator's parts
241 
242 
243 
245 
246  const tod_manager* tod_manager_;
247 
248  void invalidate_route();
249 
251 
253 
255 
256  boost::scoped_ptr<display_chat_manager> chat_man_;
257 
259 
260  // For debug mode
261  static std::map<map_location, int> debugHighlights_;
262 
264 
265 };
266 
267 #endif
virtual void highlight_hex(map_location hex)
Function to highlight a location.
void invalidate_unit_after_move(const map_location &src, const map_location &dst)
Same as invalidate_unit() if moving the displayed unit.
Game board class.
Definition: game_board.hpp:55
std::string attack_indicator_direction() const
Function to get attack direction suffix.
::tod_manager * tod_manager
Definition: resources.cpp:31
static game_display * create_dummy_display(CVideo &video)
double sidebarScaling_
static int & debug_highlight(const map_location &loc)
annotate hex with number, useful for debugging or UI prototype
GLint level
Definition: glew.h:1220
void invalidate_route()
std::string current_team_name() const
map_location attack_indicator_src_
Definition: video.hpp:58
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
void float_label(const map_location &loc, const std::string &text, const SDL_Color &color)
Function to float a label above a tile.
DIRECTION get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
Definition: location.cpp:220
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
map_location displayedUnitHex_
GLenum src
Definition: glew.h:2392
static display * singleton_
Definition: display.hpp:1178
no linger overlay, show fog and shroud.
void draw_invalidated()
Only called when there's actual redrawing to do.
void new_turn()
Update lighting settings.
static std::map< map_location, int > debugHighlights_
Unit and team statistics.
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
const tod_manager & get_tod_man() const
Allows this class to properly implement filter context, used for animations.
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:48
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
void scroll_to_leader(int side, SCROLL_TYPE scroll_type=ONSCREEN, bool force=true)
Scrolls to the leader of a certain side.
tgame_mode game_mode_
const time_of_day & get_time_of_day(const map_location &loc) const
void pre_draw()
game_display pre_draw does specific things related e.g.
Animate units.
virtual void select_hex(map_location hex)
Function to display a location as selected.
GLenum GLenum dst
Definition: glew.h:2392
const map_location & displayed_unit_hex() const
Virtual functions shadowed in game_display.
void highlight_another_reach(const pathfind::paths &paths_list)
Add more paths to highlight.
bool invalidateGameStatus_
Definition: display.hpp:789
void highlight_reach(const pathfind::paths &paths_list)
Sets the paths that are currently displayed as available for the unit to move along.
map_display and display: classes which take care of displaying the map and game-data on the screen...
void set_game_mode(const tgame_mode game_mode)
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:141
void needs_rebuild(bool b)
Sets whether the screen (map visuals) needs to be rebuilt. This is typically after the map has been c...
pathfind::marked_route route_
GLuint color
Definition: glew.h:5801
void draw_sidebar()
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
tgame_mode
Sets the linger mode for the display.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:47
Encapsulates the map of the game.
Definition: location.hpp:38
void unhighlight_reach()
Reset highlighting of paths.
void post_draw()
Calls the whiteboard's post-draw method.
int playing_side() const
The playing team is the team whose turn it is.
static void clear_debug_highlights()
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
const tod_manager * tod_manager_
void reset_tod_manager(const tod_manager &tod_manager)
game_display(game_board &board, CVideo &video, boost::weak_ptr< wb::manager > wb, reports &reports_object, const tod_manager &tod_manager, const config &theme_cfg, const config &level, bool dummy=false)
display_chat_manager & get_chat_manager()
size_t activeTeam_
Definition: display.hpp:959
overlay_map overlay_map_
bool has_time_area() const
void post_commit()
Hook for actions to take right after draw() calls drawing_buffer_commit No action here by default...
const std::set< std::string > & observers() const
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:202
Object which contains all the possible locations a unit can move to, with associated best routes to t...
Definition: pathfind.hpp:71
Container associating units to locations.
Definition: map.hpp:90
void set_playing_team(size_t team)
Sets the team controlled by the player using the computer.
map_location attack_indicator_dst_
virtual bool in_game() const
void draw_movement_info(const map_location &loc)
Draws the movement info (turns available) for a given location.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void set_route(const pathfind::marked_route *route)
Sets the route along which footsteps are drawn to show movement of a unit.
boost::scoped_ptr< display_chat_manager > chat_man_
void clear_attack_indicator()
This module contains various pathfinding functions and utilities.
static std::string write_direction(DIRECTION dir)
Definition: location.cpp:144
void draw_hex(const map_location &loc)
Redraws a single gamemap location.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void display_unit_hex(map_location hex)
Change the unit to be displayed in the sidebar.
std::multimap< map_location, overlay > overlay_map
Definition: display.hpp:1134
t_translation::t_terrain get_terrain_on(int palx, int paly, int x, int y)
void set_attack_indicator(const map_location &src, const map_location &dst)
Set the attack direction indicator.
Definition: display.hpp:47
static game_display * get_singleton()
bool maybe_rebuild()
Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
void operator=(const game_display &)