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
16 #include "editor/controller/editor_controller.hpp"
17 #include "editor/editor_display.hpp"
18 #include "lexical_cast.hpp"
19 #include "reports.hpp"
20 #include "team.hpp"
21 #include "terrain/builder.hpp"
22 #include "units/map.hpp"
23
24 namespace wb {
25 class manager;
26 }
27
28 namespace editor {
29
editor_display(editor_controller & controller,reports & reports_object,const config & theme_cfg)30 editor_display::editor_display(editor_controller& controller, reports& reports_object, const config& theme_cfg)
31 : display(nullptr, std::shared_ptr<wb::manager>(), reports_object, theme_cfg, config())
32 , brush_locations_()
33 , controller_(controller)
34 {
35 video().clear_screen();
36 }
37
add_brush_loc(const map_location & hex)38 void editor_display::add_brush_loc(const map_location& hex)
39 {
40 brush_locations_.insert(hex);
41 invalidate(hex);
42 }
43
set_brush_locs(const std::set<map_location> & hexes)44 void editor_display::set_brush_locs(const std::set<map_location>& hexes)
45 {
46 invalidate(brush_locations_);
47 brush_locations_ = hexes;
48 invalidate(brush_locations_);
49 }
50
clear_brush_locs()51 void editor_display::clear_brush_locs()
52 {
53 invalidate(brush_locations_);
54 brush_locations_.clear();
55 }
56
remove_brush_loc(const map_location & hex)57 void editor_display::remove_brush_loc(const map_location& hex)
58 {
59 brush_locations_.erase(hex);
60 invalidate(hex);
61 }
62
rebuild_terrain(const map_location & loc)63 void editor_display::rebuild_terrain(const map_location &loc) {
64 builder_->rebuild_terrain(loc);
65 }
66
pre_draw()67 void editor_display::pre_draw()
68 {
69 }
70
get_image_type(const map_location & loc)71 image::TYPE editor_display::get_image_type(const map_location& loc)
72 {
73 if (map().in_selection(loc)) {
74 return image::BRIGHTENED;
75 }
76 return image::TOD_COLORED;
77 }
78
draw_hex(const map_location & loc)79 void editor_display::draw_hex(const map_location& loc)
80 {
81 int xpos = get_location_x(loc);
82 int ypos = get_location_y(loc);
83 display::draw_hex(loc);
84 if (map().on_board_with_border(loc)) {
85 if (map().in_selection(loc)) {
86 drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
87 image::get_image("editor/selection-overlay.png", image::TOD_COLORED));
88 }
89
90 if (brush_locations_.find(loc) != brush_locations_.end()) {
91 static const image::locator brush(game_config::images::editor_brush);
92 drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
93 image::get_image(brush, image::SCALED_TO_HEX));
94 }
95 }
96 }
97
get_clip_rect()98 const SDL_Rect& editor_display::get_clip_rect()
99 {
100 return map_outside_area();
101 }
102
draw_sidebar()103 void editor_display::draw_sidebar()
104 {
105 config element;
106 config::attribute_value &text = element.add_child("element")["text"];
107 // Fill in the terrain report
108 if (get_map().on_board_with_border(mouseoverHex_)) {
109 text = get_map().get_terrain_editor_string(mouseoverHex_);
110 refresh_report("terrain", &element);
111 refresh_report("terrain_info");
112 text = lexical_cast<std::string>(mouseoverHex_);
113 refresh_report("position", &element);
114 }
115
116 if (dc_->teams().empty()) {
117 text = int(get_map().villages().size());
118 refresh_report("villages", &element);
119 } else {
120 refresh_report("villages");
121 refresh_report("num_units");
122 }
123 }
124
get_time_of_day(const map_location &) const125 const time_of_day& editor_display::get_time_of_day(const map_location& /*loc*/) const
126 {
127 return controller_.get_current_map_context().get_time_manager()->get_time_of_day();
128 }
129
130 } //end namespace editor
131