The Battle for Wesnoth  1.17.0-dev
editor_display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Tomasz Sniatowski <kailoran@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-editor"
17 
20 #include "lexical_cast.hpp"
21 #include "overlay.hpp"
22 #include "reports.hpp"
23 #include "team.hpp"
24 #include "terrain/builder.hpp"
25 #include "units/map.hpp"
26 
27 namespace wb {
28  class manager;
29 }
30 
31 namespace editor {
32 
33 editor_display::editor_display(editor_controller& controller, reports& reports_object, const config& theme_cfg)
34  : display(nullptr, std::shared_ptr<wb::manager>(), reports_object, theme_cfg, config())
35  , brush_locations_()
36  , controller_(controller)
37 {
38  video().clear_screen();
39 }
40 
42 {
43  brush_locations_.insert(hex);
44  invalidate(hex);
45 }
46 
47 void editor_display::set_brush_locs(const std::set<map_location>& hexes)
48 {
50  brush_locations_ = hexes;
52 }
53 
55 {
57  brush_locations_.clear();
58 }
59 
61 {
62  brush_locations_.erase(hex);
63  invalidate(hex);
64 }
65 
67  builder_->rebuild_terrain(loc);
68 }
69 
71 {
72 }
73 
75 {
76  if (map().in_selection(loc)) {
77  return image::BRIGHTENED;
78  }
79  return image::TOD_COLORED;
80 }
81 
83 {
84  int xpos = get_location_x(loc);
85  int ypos = get_location_y(loc);
86  display::draw_hex(loc);
87  if (map().on_board_with_border(loc)) {
88  if (map().in_selection(loc)) {
89  drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
90  image::get_image("editor/selection-overlay.png", image::TOD_COLORED));
91  }
92 
93  if (brush_locations_.find(loc) != brush_locations_.end()) {
95  drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
97  }
98  }
99 }
100 
102 {
103  return map_outside_area();
104 }
105 
107 {
108  config element;
109  config::attribute_value &text = element.add_child("element")["text"];
110  // Fill in the terrain report
111  if (get_map().on_board_with_border(mouseoverHex_)) {
113  refresh_report("terrain", &element);
114  refresh_report("terrain_info");
115  text = lexical_cast<std::string>(mouseoverHex_);
116  refresh_report("position", &element);
117  }
118 
119  if (dc_->teams().empty()) {
120  text = int(get_map().villages().size());
121  refresh_report("villages", &element);
122  } else {
123  refresh_report("villages");
124  refresh_report("num_units");
125  }
126 }
127 
129 {
131 }
132 
134 {
136 }
137 
138 } //end namespace editor
TYPE
Used to specify the rendering format of images.
Definition: picture.hpp:229
surface get_image(const image::locator &i_locator, TYPE type)
Caches and returns an image.
Definition: picture.cpp:816
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:3026
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:796
STL namespace.
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...
Same as SCALED_TO_HEX, but with Time of Day color tint applied.
Definition: picture.hpp:240
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:56
map_context & get_current_map_context() const
Image on the selected unit.
Definition: display.hpp:856
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:87
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:1043
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:56
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:26
Manage the empty-palette in the editor.
Definition: action.cpp:30
Generic locator abstracting the location of an image.
Definition: picture.hpp:60
Fog and shroud.
Definition: display.hpp:853
Encapsulates the map of the game.
Definition: location.hpp:38
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:63
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:755
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.hpp:242
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2588
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:514
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:1209
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:750
const gamemap & get_map() const
Definition: display.hpp:96
Image rescaled to fit into a hexagonal tile according to the zoom settings.
Definition: picture.hpp:238
const display_context * dc_
Definition: display.hpp:660
void add_brush_loc(const map_location &hex)
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:201
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:61
void clear_screen()
Clear the screen contents.
Definition: video.cpp:345
const std::unique_ptr< terrain_builder > builder_
Definition: display.hpp:758
void refresh_report(const std::string &report_name, const config *new_cfg=nullptr)
Redraws the specified report (if anything has changed).
Definition: display.cpp:2806
Same as TOD_COLORED, but also brightened.
Definition: picture.hpp:242
Definition: display.hpp:49