The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
editor_display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2017 by Tomasz Sniatowski <kailoran@gmail.com>
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 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
18 #include "reports.hpp"
19 #include "team.hpp"
20 #include "terrain/builder.hpp"
21 #include "units/map.hpp"
22 
23 namespace wb {
24  class manager;
25 }
26 
27 namespace editor {
28 
29 // Define dummy display context;
30 
32 {
34 
37  std::vector<team> t;
38  std::vector<std::string> lbls;
39 
40 public:
41  dummy_editor_display_context() : dummy_cfg1(), em(dummy_cfg1), u(), t(), lbls() {}
43 
44  virtual const gamemap & map() const { return em; }
45  virtual const unit_map & units() const { return u; }
46  virtual const std::vector<team> & teams() const { return t; }
47  virtual const std::vector<std::string> & hidden_label_categories() const { return lbls; }
48 };
49 
52  return &dedc;
53 }
54 
55 // End dummy display context
56 
58  : display(get_dummy_display_context(), video, std::shared_ptr<wb::manager>(), reports_object, theme_cfg, config())
59  , brush_locations_()
60  , controller_(controller)
61 {
62  video.clear_screen();
63 }
64 
66 {
67  brush_locations_.insert(hex);
68  invalidate(hex);
69 }
70 
71 void editor_display::set_brush_locs(const std::set<map_location>& hexes)
72 {
74  brush_locations_ = hexes;
76 }
77 
79 {
81  brush_locations_.clear();
82 }
83 
85 {
86  brush_locations_.erase(hex);
87  invalidate(hex);
88 }
89 
91  builder_->rebuild_terrain(loc);
92 }
93 
95 {
96 }
97 
99 {
100  if (map().in_selection(loc)) {
101  return image::BRIGHTENED;
102  }
103  return image::TOD_COLORED;
104 }
105 
107 {
108  int xpos = get_location_x(loc);
109  int ypos = get_location_y(loc);
110  display::draw_hex(loc);
111  if (map().on_board_with_border(loc)) {
112  if (map().in_selection(loc)) {
113  drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
114  image::get_image("editor/selection-overlay.png", image::TOD_COLORED));
115  }
116 
117  if (brush_locations_.find(loc) != brush_locations_.end()) {
119  drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
121  }
122  }
123 }
124 
126 {
127  return map_outside_area();
128 }
129 
131 {
132  config element;
133  config::attribute_value &text = element.add_child("element")["text"];
134  // Fill in the terrain report
135  if (get_map().on_board_with_border(mouseoverHex_)) {
137  refresh_report("terrain", &element);
138  refresh_report("terrain_info");
140  refresh_report("position", &element);
141  }
142 
143  if (dc_->teams().empty()) {
144  text = int(get_map().villages().size());
145  refresh_report("villages", &element);
146  } else {
147  refresh_report("villages");
148  refresh_report("num_units");
149  }
150 }
151 
153 {
155 }
156 
158 {
159  return get_tod_man().get_time_of_day();
160 }
161 
162 } //end namespace editor
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
Definition: image.hpp:189
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
Definition: image.cpp:926
image::TYPE get_image_type(const map_location &loc) override
The editor uses different rules for terrain highlighting (e.g.
editor_display(editor_controller &controller, CVideo &video, reports &reports_object, const config &theme_cfg)
std::vector< char_t > string
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:2981
std::string get_terrain_editor_string(const map_location &loc) const
Definition: map.cpp:63
editor_controller & controller_
Variant for storing WML attributes.
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
Definition: tod_manager.hpp:54
void set_brush_locs(const std::set< map_location > &hexes)
Definition: video.hpp:29
map_location mouseoverHex_
Definition: display.hpp:765
virtual const std::vector< std::string > & hidden_label_categories() const
virtual const tod_manager & get_tod_man() const override
Inherited from display.
STL namespace.
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:736
-file sdl_utils.hpp
To lexical_cast(From value)
Lexical cast converts one type to another.
The editor_controller class contains the mouse and keyboard event handling routines for the editor...
std::vector< std::string > lbls
Unit and team statistics.
int get_location_y(const map_location &loc) const
Definition: display.cpp:741
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57
map_context & get_current_map_context() const
Image on the selected unit.
Definition: display.hpp:821
void draw_sidebar() override
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
tod_manager * get_time_manager()
void remove_brush_loc(const map_location &hex)
void pre_draw() override
Called near the beginning of each draw() call.
Encapsulates the map of the game.
Definition: map.hpp:34
virtual const time_of_day & get_time_of_day(const map_location &loc=map_location::null_location()) const override
Inherited from display.
The brush class represents a single brush – a set of relative locations around a "hotspot"...
Definition: brush.hpp:25
Manage the empty-palette in the editor.
Definition: action.cpp:29
Fog and shroud.
Definition: display.hpp:818
Encapsulates the map of the game.
Definition: location.hpp:40
size_t size(const utf8::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:69
virtual const std::vector< team > & teams() const =0
std::string editor_brush
const display_context * get_dummy_display_context()
void rebuild_terrain(const map_location &loc)
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2542
const SDL_Rect & get_clip_rect() override
Get the clipping rectangle for drawing.
std::set< map_location > brush_locations_
Definitions for the terrain builder.
config & add_child(config_key_type key)
Definition: config.cpp:408
virtual const std::vector< team > & teams() const
void drawing_buffer_add(const drawing_layer layer, const map_location &loc, int x, int y, const surface &surf, const SDL_Rect &clip=SDL_Rect())
Add an item to the drawing buffer.
Definition: display.cpp:1216
virtual const unit_map & units() const
const gamemap & get_map() const
Definition: display.hpp:92
const display_context * dc_
Definition: display.hpp:634
void add_brush_loc(const map_location &hex)
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.hpp:241
Container associating units to locations.
Definition: map.hpp:99
void draw_hex(const map_location &loc) override
Redraws a single gamemap location.
virtual const gamemap & map() const
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
void clear_screen()
Clear the screen contents.
Definition: video.cpp:358
const std::unique_ptr< terrain_builder > builder_
Definition: display.hpp:721
void refresh_report(const std::string &report_name, const config *new_cfg=nullptr)
Redraws the specified report (if anything has changed).
Definition: display.cpp:2763
Definition: display.hpp:47
const editor_map & map() const