The Battle for Wesnoth  1.17.12+dev
editor_display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2022
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 
18 #include "draw.hpp"
21 #include "lexical_cast.hpp"
22 #include "overlay.hpp"
23 #include "reports.hpp"
24 #include "team.hpp"
25 #include "terrain/builder.hpp"
26 #include "units/map.hpp"
27 
28 namespace wb {
29  class manager;
30 }
31 
32 namespace editor {
33 
34 editor_display::editor_display(editor_controller& controller, reports& reports_object)
35  : display(nullptr, std::shared_ptr<wb::manager>(), reports_object, "editor", config())
36  , brush_locations_()
37  , controller_(controller)
38  , mouseover_hex_overlay_()
39 {
40 }
41 
43 {
44  brush_locations_.insert(hex);
45  invalidate(hex);
46 }
47 
48 void editor_display::set_brush_locs(const std::set<map_location>& hexes)
49 {
51  brush_locations_ = hexes;
53 }
54 
56 {
58  brush_locations_.clear();
59 }
60 
62 {
63  brush_locations_.erase(hex);
64  invalidate(hex);
65 }
66 
68  builder_->rebuild_terrain(loc);
69 }
70 
72 {
73  display::draw_hex(loc);
74 
75  if(!map().on_board_with_border(loc) || map_screenshot_) {
76  return;
77  }
78 
79  if(map().in_selection(loc)) {
81  [tex = image::get_texture("editor/selection-overlay.png", image::TOD_COLORED)](const rect& d) {
82  draw::blit(tex, scaled_to_zoom({d.x, d.y, tex.w(), tex.h()}));
83  });
84  }
85 
86  if(brush_locations_.find(loc) != brush_locations_.end()) {
89  draw::blit(tex, scaled_to_zoom({d.x, d.y, tex.w(), tex.h()}));
90  });
91  }
92 
93  // Paint mouseover overlays
95  drawing_buffer_add(LAYER_MOUSEOVER_OVERLAY, loc, [this](const rect& dest) {
98  mouseover_hex_overlay_.set_alpha_mod(SDL_ALPHA_OPAQUE);
99  });
100  }
101 }
102 
104 {
105  return map_outside_area();
106 }
107 
109 {
110  display::layout();
111 
112  config element;
113  config::attribute_value &text = element.add_child("element")["text"];
114  // Fill in the terrain report
115  if (get_map().on_board_with_border(mouseoverHex_)) {
117  refresh_report("terrain", &element);
118  refresh_report("terrain_info");
119  text = lexical_cast<std::string>(mouseoverHex_);
120  refresh_report("position", &element);
121  }
122 
123  if (dc_->teams().empty()) {
124  text = int(get_map().villages().size());
125  refresh_report("villages", &element);
126  } else {
127  refresh_report("villages");
128  refresh_report("num_units");
129  }
130 }
131 
133 {
135 }
136 
138 {
140 }
141 
142 } //end namespace editor
Drawing functions, for drawing things on the screen.
const editor_map & map() const
void set_alpha_mod(uint8_t alpha)
Alpha modifier.
Definition: texture.cpp:151
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3141
editor_controller & controller_
static rect scaled_to_zoom(const SDL_Rect &r)
Scale the width and height of a rect by the current zoom factor.
Definition: display.hpp:262
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:765
Mouseover overlay used by editor.
Definition: display.hpp:798
STL namespace.
#define d
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...
Standard hexagonal tile mask applied, removing portions that don&#39;t fit.
Definition: picture.hpp:233
Same as HEXED, but with Time of Day color tint applied.
Definition: picture.hpp:235
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:824
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 drawing_buffer_add(const drawing_layer layer, const map_location &loc, decltype(draw_helper::do_draw) draw_func)
Add an item to the drawing buffer.
Definition: display.cpp:1278
std::map< map_location, std::vector< overlay > > overlay_map
Definition: display.hpp:946
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
bool map_screenshot_
Used to indicate to drawing functions that we are doing a map screenshot.
Definition: display.hpp:926
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:62
Fog and shroud.
Definition: display.hpp:821
Encapsulates the map of the game.
Definition: location.hpp:38
virtual void layout() override
TLD layout() override.
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
rect get_clip_rect() const override
Get the clipping rectangle for drawing.
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:46
virtual void layout() override
Finalize screen layout.
Definition: display.cpp:2444
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Definition: display.cpp:2675
std::set< map_location > brush_locations_
Definitions for the terrain builder.
config & add_child(config_key_type key)
Definition: config.cpp:514
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
Definition: draw.cpp:301
const gamemap & get_map() const
Definition: display.hpp:102
const display_context * dc_
Definition: display.hpp:666
void add_brush_loc(const map_location &hex)
rect map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.cpp:564
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:60
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
Definition: picture.cpp:1128
const std::unique_ptr< terrain_builder > builder_
Definition: display.hpp:729
void refresh_report(const std::string &report_name, const config *new_cfg=nullptr)
Update the given report.
Definition: display.cpp:2890
Definition: display.hpp:49