The Battle for Wesnoth  1.15.1+dev
game_display.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
18 
19 class config;
20 class team;
21 class game_board;
22 
23 #include "chat_events.hpp"
24 #include "display.hpp"
25 #include "display_chat_manager.hpp"
26 #include "pathfind/pathfind.hpp"
27 
28 #include <deque>
29 
30 // This needs to be separate from display.h because of the static
31 // singleton member, which will otherwise trigger link failure
32 // when building the editor.
33 
34 class game_display : public display
35 {
36 public:
37  game_display(game_board& board,
38  std::weak_ptr<wb::manager> wb,
39  reports & reports_object,
40  const config& theme_cfg,
41  const config& level,
42  bool dummy=false);
43 
44  ~game_display();
46  {
47  return static_cast<game_display*>(singleton_);
48  }
49 
50  /**
51  * Update lighting settings.
52  *
53  * Should be called on every new turn.
54  */
55  void new_turn();
56 
57  virtual const std::set<std::string>& observers() const override { return chat_man_->observers(); }
58  /**
59  * Scrolls to the leader of a certain side.
60  *
61  * This will normally be the playing team.
62  */
63  void scroll_to_leader(int side, SCROLL_TYPE scroll_type = ONSCREEN,bool force = true);
64 
65  /**
66  * Function to display a location as selected.
67  *
68  * If a unit is in the location, and there is no unit in the currently
69  * highlighted hex, the unit will be displayed in the sidebar.
70  */
71  virtual void select_hex(map_location hex) override;
72 
73  /**
74  * Function to highlight a location.
75  *
76  * If a unit is in the location, it will be displayed in the sidebar.
77  * Selection is used when a unit has been clicked on, while highlighting is
78  * used when a location has been moused over.
79  */
80  virtual void highlight_hex(map_location hex) override;
81 
82  /**
83  * Change the unit to be displayed in the sidebar.
84  *
85  * This is used when selecting or highlighting is not wanted.
86  */
88 
89  /**
90  * Sets the paths that are currently displayed as available
91  * for the unit to move along.
92  * All other paths will be grayed out.
93  */
94  void highlight_reach(const pathfind::paths &paths_list);
95 
96  /**
97  * Add more paths to highlight. Print numbers where they overlap.
98  * Used by Show Enemy Moves. If @a goal is not @c null_location, highlight
99  * enemy units that can reach @a goal.
100  */
101  void highlight_another_reach(const pathfind::paths &paths_list,
102  const map_location& goal = map_location::null_location());
103  /**
104  * Return the locations of units that can reach @a goal (@see highlight_another_reach()).
105  */
106  const std::set<map_location>& units_that_can_reach_goal() const { return units_that_can_reach_goal_; }
107 
108  /** Reset highlighting of paths. */
109  bool unhighlight_reach();
110 
111  /**
112  * Sets the route along which footsteps are drawn to show movement of a
113  * unit. If nullptr, no route is displayed. @a route does not have to remain
114  * valid after being set.
115  */
116  void set_route(const pathfind::marked_route *route);
117  /**
118  * Gets the route along which footsteps are drawn to show movement of a
119  * unit. If no route is currently being shown, the array get_route().steps
120  * will be empty.
121  */
123 
124  /** Function to float a label above a tile */
125  void float_label(const map_location& loc, const std::string& text, const color_t& color);
126 
127  /** Draws the movement info (turns available) for a given location. */
128  void draw_movement_info(const map_location& loc);
129 
130  /** Function to invalidate that unit status displayed on the sidebar. */
132 
133  /** Same as invalidate_unit() if moving the displayed unit. */
134  void invalidate_unit_after_move(const map_location& src, const map_location& dst);
135 
136  virtual const time_of_day& get_time_of_day(const map_location& loc) const override;
137 
138  virtual bool has_time_area() const override;
139 
140 protected:
141  /**
142  * game_display pre_draw does specific things related e.g. to unit rendering
143  * and calls the whiteboard pre-draw method.
144  */
145  virtual void pre_draw() override;
146  /**
147  * Calls the whiteboard's post-draw method.
148  */
149  virtual void post_draw() override;
150 
151  virtual void draw_invalidated() override;
152 
153  virtual void post_commit() override;
154 
155  virtual void draw_hex(const map_location& loc) override;
156 
157  /** Inherited from display. */
158  virtual overlay_map& get_overlays() override;
159 
160  std::set<map_location> units_that_can_reach_goal_;
161 
162 public:
163  /** Set the attack direction indicator. */
164  void set_attack_indicator(const map_location& src, const map_location& dst);
165  void clear_attack_indicator();
166  // TODO: compare reports::context::mhb()->current_unit_attacks_from()
168 
169  /** Function to get attack direction suffix. */
170  std::string attack_indicator_direction() const {
173  }
174 
175  // Functions used in the editor:
176 
177  //void draw_terrain_palette(int x, int y, terrain_type::TERRAIN selected);
178  t_translation::terrain_code get_terrain_on(int palx, int paly, int x, int y);
179 
180  virtual const map_location &displayed_unit_hex() const override { return displayedUnitHex_; }
181 
182  /**
183  * annotate hex with number, useful for debugging or UI prototype
184  */
185  static int& debug_highlight(const map_location& loc);
186  static void clear_debug_highlights() { debugHighlights_.clear(); }
187 
188 
189  /** The playing team is the team whose turn it is. */
190  virtual int playing_side() const override { return activeTeam_ + 1; }
191 
192 
193  std::string current_team_name() const;
194 
196 
197  void begin_game();
198 
199  virtual bool in_game() const override { return in_game_; }
200 
201  /**
202  * Sets the linger mode for the display.
203  * There have been some discussions on what to do with fog and shroud
204  * the extra variables make it easier to modify the behavior. There
205  * might even be a split between victory and defeat.
206  *
207  * @todo if the current implementation is wanted we can change
208  * the stuff back to a boolean
209  */
210  enum game_mode {
211  RUNNING, /**< no linger overlay, show fog and shroud. */
212  LINGER }; /**< linger overlay, show fog and shroud. */
213 
214  void set_game_mode(const game_mode mode);
215 
216  /// Sets whether the screen (map visuals) needs to be rebuilt. This is typically after the map has been changed by wml.
217  void needs_rebuild(bool b);
218 
219  /// Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
220  bool maybe_rebuild();
221 
222 private:
223  game_display(const game_display&);
224  void operator=(const game_display&);
225 
226  virtual void draw_sidebar() override;
227 
229 
230  // Locations of the attack direction indicator's parts
233 
235 
236  void invalidate_route();
237 
239 
241 
243 
244  const std::unique_ptr<display_chat_manager> chat_man_;
245 
247 
248  // For debug mode
249  static std::map<map_location, int> debugHighlights_;
250 
252 
253 };
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:50
void set_game_mode(const game_mode mode)
double sidebarScaling_
static int & debug_highlight(const map_location &loc)
annotate hex with number, useful for debugging or UI prototype
game_mode
Sets the linger mode for the display.
DIRECTION get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
Definition: location.cpp:226
int dummy
Definition: lstrlib.cpp:1125
virtual overlay_map & get_overlays() override
Inherited from display.
void invalidate_route()
virtual const map_location & displayed_unit_hex() const override
Virtual functions shadowed in game_display.
const std::set< map_location > & units_that_can_reach_goal() const
Return the locations of units that can reach goal (.
const map_location & get_attack_indicator_src()
map_location attack_indicator_src_
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
std::set< map_location > units_that_can_reach_goal_
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:50
game_mode mode_
map_location displayedUnitHex_
virtual void post_commit() override
Hook for actions to take right after draw() calls drawing_buffer_commit No action here by default...
static display * singleton_
Definition: display.hpp:1073
virtual int playing_side() const override
The playing team is the team whose turn it is.
void new_turn()
Update lighting settings.
static std::map< map_location, int > debugHighlights_
Unit and team statistics.
#define b
void highlight_another_reach(const pathfind::paths &paths_list, const map_location &goal=map_location::null_location())
Add more paths to highlight.
no linger overlay, show fog and shroud.
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
game_display(game_board &board, std::weak_ptr< wb::manager > wb, reports &reports_object, const config &theme_cfg, const config &level, bool dummy=false)
void scroll_to_leader(int side, SCROLL_TYPE scroll_type=ONSCREEN, bool force=true)
Scrolls to the leader of a certain side.
virtual void draw_invalidated() override
Only called when there&#39;s actual redrawing to do.
std::map< map_location, std::vector< overlay > > overlay_map
Definition: display.hpp:1038
const pathfind::marked_route & get_route()
Gets the route along which footsteps are drawn to show movement of a unit.
virtual const time_of_day & get_time_of_day(const map_location &loc) const override
virtual const std::set< std::string > & observers() const override
bool invalidateGameStatus_
Definition: display.hpp:762
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...
Structure which holds a single route and marks for special events.
Definition: pathfind.hpp:140
void needs_rebuild(bool b)
Sets whether the screen (map visuals) needs to be rebuilt. This is typically after the map has been c...
virtual void draw_sidebar() override
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
pathfind::marked_route route_
virtual void draw_hex(const map_location &loc) override
Redraws a single gamemap location.
std::string attack_indicator_direction() const
Function to get attack direction suffix.
Encapsulates the map of the game.
Definition: location.hpp:42
void float_label(const map_location &loc, const std::string &text, const color_t &color)
Function to float a label above a tile.
virtual bool in_game() const override
std::string current_team_name() const
virtual void highlight_hex(map_location hex) override
Function to highlight a location.
std::size_t activeTeam_
Definition: display.hpp:894
static void clear_debug_highlights()
virtual void select_hex(map_location hex) override
Function to display a location as selected.
virtual bool has_time_area() const override
display_chat_manager & get_chat_manager()
overlay_map overlay_map_
bool unhighlight_reach()
Reset highlighting of paths.
Object which contains all the possible locations a unit can move to, with associated best routes to t...
Definition: pathfind.hpp:70
virtual void pre_draw() override
game_display pre_draw does specific things related e.g.
static const map_location & null_location()
Definition: location.hpp:85
virtual void post_draw() override
Calls the whiteboard&#39;s post-draw method.
map_location attack_indicator_dst_
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:68
void set_route(const pathfind::marked_route *route)
Sets the route along which footsteps are drawn to show movement of a unit.
void clear_attack_indicator()
This module contains various pathfinding functions and utilities.
t_translation::terrain_code get_terrain_on(int palx, int paly, int x, int y)
static std::string write_direction(DIRECTION dir)
Definition: location.cpp:140
void display_unit_hex(map_location hex)
Change the unit to be displayed in the sidebar.
void set_attack_indicator(const map_location &src, const map_location &dst)
Set the attack direction indicator.
Definition: display.hpp:48
static game_display * get_singleton()
const std::unique_ptr< display_chat_manager > chat_man_
bool maybe_rebuild()
Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
void operator=(const game_display &)