The Battle for Wesnoth  1.15.0-dev
editor_display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Tomasz Sniatowski <kailoran@gmail.com>
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 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
18 #include "lexical_cast.hpp"
19 #include "overlay.hpp"
20 #include "reports.hpp"
21 #include "team.hpp"
22 #include "terrain/builder.hpp"
23 #include "units/map.hpp"
24 
25 namespace wb {
26  class manager;
27 }
28 
29 namespace editor {
30 
31 editor_display::editor_display(editor_controller& controller, reports& reports_object, const config& theme_cfg)
32  : display(nullptr, std::shared_ptr<wb::manager>(), reports_object, theme_cfg, config())
33  , brush_locations_()
34  , controller_(controller)
35 {
36  video().clear_screen();
37 }
38 
40 {
41  brush_locations_.insert(hex);
42  invalidate(hex);
43 }
44 
45 void editor_display::set_brush_locs(const std::set<map_location>& hexes)
46 {
48  brush_locations_ = hexes;
50 }
51 
53 {
55  brush_locations_.clear();
56 }
57 
59 {
60  brush_locations_.erase(hex);
61  invalidate(hex);
62 }
63 
65  builder_->rebuild_terrain(loc);
66 }
67 
69 {
70 }
71 
73 {
74  if (map().in_selection(loc)) {
75  return image::BRIGHTENED;
76  }
77  return image::TOD_COLORED;
78 }
79 
81 {
82  int xpos = get_location_x(loc);
83  int ypos = get_location_y(loc);
84  display::draw_hex(loc);
85  if (map().on_board_with_border(loc)) {
86  if (map().in_selection(loc)) {
87  drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
88  image::get_image("editor/selection-overlay.png", image::TOD_COLORED));
89  }
90 
91  if (brush_locations_.find(loc) != brush_locations_.end()) {
93  drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
95  }
96  }
97 }
98 
100 {
101  return map_outside_area();
102 }
103 
105 {
106  config element;
107  config::attribute_value &text = element.add_child("element")["text"];
108  // Fill in the terrain report
109  if (get_map().on_board_with_border(mouseoverHex_)) {
111  refresh_report("terrain", &element);
112  refresh_report("terrain_info");
113  text = lexical_cast<std::string>(mouseoverHex_);
114  refresh_report("position", &element);
115  }
116 
117  if (dc_->teams().empty()) {
118  text = int(get_map().villages().size());
119  refresh_report("villages", &element);
120  } else {
121  refresh_report("villages");
122  refresh_report("num_units");
123  }
124 }
125 
127 {
129 }
130 
132 {
134 }
135 
136 } //end namespace editor
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
Definition: picture.hpp:190
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
Definition: picture.cpp:1022
const editor_map & map() const
image::TYPE get_image_type(const map_location &loc) override
The editor uses different rules for terrain highlighting (e.g.
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:2979
editor_controller & controller_
virtual overlay_map & get_overlays() override
Inherited from display.
Variant for storing WML attributes.
New lexcical_cast header.
void set_brush_locs(const std::set< map_location > &hexes)
map_location mouseoverHex_
Definition: display.hpp:787
STL namespace.
-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...
Unit and team statistics.
overlay_map & get_overlays()
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:847
void draw_sidebar() override
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
void remove_brush_loc(const map_location &hex)
void pre_draw() override
Called near the beginning of each draw() call.
std::map< map_location, std::vector< overlay > > overlay_map
Definition: display.hpp:1030
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
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:844
Encapsulates the map of the game.
Definition: location.hpp:42
virtual const std::vector< team > & teams() const =0
std::string editor_brush
std::string get_terrain_editor_string(const map_location &loc) const
Definition: map.cpp:62
void rebuild_terrain(const map_location &loc)
const tod_manager * get_time_manager() const
int get_location_y(const map_location &loc) const
Definition: display.cpp:726
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.hpp:237
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2547
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:479
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:1178
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:721
const gamemap & get_map() const
Definition: display.hpp:92
const display_context * dc_
Definition: display.hpp:656
void add_brush_loc(const map_location &hex)
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:196
void draw_hex(const map_location &loc) override
Redraws a single gamemap location.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
void clear_screen()
Clear the screen contents.
Definition: video.cpp:374
const std::unique_ptr< terrain_builder > builder_
Definition: display.hpp:743
void refresh_report(const std::string &report_name, const config *new_cfg=nullptr)
Redraws the specified report (if anything has changed).
Definition: display.cpp:2761
Definition: display.hpp:48