Merge lp:~widelands-dev/widelands/kill_overlay_manager into lp:widelands
- kill_overlay_manager
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 8454 |
Proposed branch: | lp:~widelands-dev/widelands/kill_overlay_manager |
Merge into: | lp:widelands |
Diff against target: |
1325 lines (+206/-493) 31 files modified
src/editor/CMakeLists.txt (+0/-1) src/editor/editorinteractive.cc (+8/-12) src/editor/tools/decrease_resources_tool.h (+6/-0) src/editor/tools/increase_resources_tool.h (+5/-0) src/editor/tools/set_port_space_tool.cc (+20/-5) src/editor/tools/set_port_space_tool.h (+4/-2) src/editor/tools/set_resources_tool.cc (+10/-0) src/editor/tools/set_resources_tool.h (+9/-0) src/editor/tools/set_starting_pos_tool.cc (+16/-7) src/editor/tools/set_starting_pos_tool.h (+2/-3) src/editor/tools/tool.h (+9/-0) src/editor/ui_menus/player_menu.cc (+0/-14) src/editor/ui_menus/tool_change_resources_options_menu.cc (+0/-12) src/editor/ui_menus/tool_menu.cc (+0/-7) src/graphic/CMakeLists.txt (+0/-1) src/graphic/game_renderer.cc (+0/-1) src/logic/map.cc (+1/-1) src/logic/map.h (+1/-1) src/wui/CMakeLists.txt (+0/-12) src/wui/buildingwindow.h (+0/-1) src/wui/field_overlay_manager.cc (+0/-181) src/wui/field_overlay_manager.h (+0/-172) src/wui/fieldaction.cc (+0/-1) src/wui/interactive_base.cc (+66/-5) src/wui/interactive_base.h (+18/-18) src/wui/interactive_gamebase.cc (+0/-4) src/wui/interactive_gamebase.h (+0/-1) src/wui/interactive_player.cc (+7/-8) src/wui/interactive_player.h (+0/-1) src/wui/interactive_spectator.cc (+24/-21) src/wui/interactive_spectator.h (+0/-1) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/kill_overlay_manager |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
GunChleoc | Approve | ||
kaputtnik (community) | testing | Approve | |
Review via email: mp+330651@code.launchpad.net |
Commit message
Delete the overlay_manager.
- Draw build help in the draw routines directly.
- Give Editor tools the ability to modify which field caps should be used for overlays. This is used to restrict resources, player starting positions and port positions.
Description of the change
SirVer (sirver) wrote : | # |
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 2665. State: failed. Details: https:/
Appveyor build 2486. State: success. Details: https:/
kaputtnik (franku) wrote : | # |
When compiling this branch:
.../kill_
.../kill_
All is working imho. In Editor i tested overlays, playing starting positions, resources and ports.
In an older save game tested the buildhelp.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 2666. State: passed. Details: https:/
Appveyor build 2487. State: success. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
Goodbye, you won't be missed :)
@bunnybot merge
Preview Diff
1 | === modified file 'src/editor/CMakeLists.txt' |
2 | --- src/editor/CMakeLists.txt 2017-08-17 13:37:32 +0000 |
3 | +++ src/editor/CMakeLists.txt 2017-09-13 18:51:31 +0000 |
4 | @@ -108,6 +108,5 @@ |
5 | ui_basic |
6 | wui |
7 | wui_common |
8 | - wui_field_overlay_manager |
9 | wui_mapview_pixelfunctions |
10 | ) |
11 | |
12 | === modified file 'src/editor/editorinteractive.cc' |
13 | --- src/editor/editorinteractive.cc 2017-09-10 18:17:55 +0000 |
14 | +++ src/editor/editorinteractive.cc 2017-09-13 18:51:31 +0000 |
15 | @@ -51,7 +51,6 @@ |
16 | #include "scripting/lua_table.h" |
17 | #include "ui_basic/messagebox.h" |
18 | #include "ui_basic/progresswindow.h" |
19 | -#include "wui/field_overlay_manager.h" |
20 | #include "wui/game_tips.h" |
21 | #include "wui/interactive_base.h" |
22 | |
23 | @@ -190,9 +189,6 @@ |
24 | // TODO(unknown): get rid of cleanup_for_load, it tends to be very messy |
25 | // Instead, delete and re-create the egbase. |
26 | egbase().cleanup_for_load(); |
27 | - |
28 | - // Select a tool that doesn't care about map changes |
29 | - mutable_field_overlay_manager()->register_overlay_callback_function(nullptr); |
30 | } |
31 | |
32 | /// Called just before the editor starts, after postload, init and gfxload. |
33 | @@ -331,9 +327,14 @@ |
34 | } |
35 | } |
36 | |
37 | - // TODO(sirver): Do not use the field_overlay_manager, instead draw the |
38 | - // overlays we are interested in here directly. |
39 | - field_overlay_manager().foreach_overlay(field.fcoords, blit_overlay); |
40 | + // Draw build help. |
41 | + if (buildhelp()) { |
42 | + const auto* overlay = |
43 | + get_buildhelp_overlay(tools_->current().nodecaps_for_buildhelp(field.fcoords, ebase)); |
44 | + if (overlay != nullptr) { |
45 | + blit_overlay(overlay->pic, overlay->hotspot); |
46 | + } |
47 | + } |
48 | |
49 | // Draw the player starting position overlays. |
50 | const auto it = starting_positions.find(field.fcoords); |
51 | @@ -589,9 +590,6 @@ |
52 | toolsize_menu.update(toolsize_menu.value()); |
53 | } |
54 | } |
55 | - // A new tool has been selected. Remove all registered overlay callback |
56 | - // functions. |
57 | - mutable_field_overlay_manager()->register_overlay_callback_function(nullptr); |
58 | egbase().mutable_map()->recalc_whole_map(egbase().world()); |
59 | } |
60 | tools_->current_pointer = &primary; |
61 | @@ -680,8 +678,6 @@ |
62 | case MapWas::kGloballyMutated: |
63 | break; |
64 | } |
65 | - |
66 | - mutable_field_overlay_manager()->remove_all_overlays(); |
67 | } |
68 | |
69 | EditorInteractive::Tools* EditorInteractive::tools() { |
70 | |
71 | === modified file 'src/editor/tools/decrease_resources_tool.h' |
72 | --- src/editor/tools/decrease_resources_tool.h 2017-01-25 18:55:59 +0000 |
73 | +++ src/editor/tools/decrease_resources_tool.h 2017-09-13 18:51:31 +0000 |
74 | @@ -20,6 +20,7 @@ |
75 | #ifndef WL_EDITOR_TOOLS_DECREASE_RESOURCES_TOOL_H |
76 | #define WL_EDITOR_TOOLS_DECREASE_RESOURCES_TOOL_H |
77 | |
78 | +#include "editor/tools/set_resources_tool.h" |
79 | #include "editor/tools/tool.h" |
80 | |
81 | /// Decreases the resources of a node by a value. |
82 | @@ -45,6 +46,11 @@ |
83 | return g_gr->images().get("images/wui/editor/fsel_editor_decrease_resources.png"); |
84 | } |
85 | |
86 | + Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
87 | + const Widelands::EditorGameBase& egbase) override { |
88 | + return resource_tools_nodecaps(fcoords, egbase, cur_res_); |
89 | + } |
90 | + |
91 | int32_t get_change_by() const { |
92 | return change_by_; |
93 | } |
94 | |
95 | === modified file 'src/editor/tools/increase_resources_tool.h' |
96 | --- src/editor/tools/increase_resources_tool.h 2017-01-25 18:55:59 +0000 |
97 | +++ src/editor/tools/increase_resources_tool.h 2017-09-13 18:51:31 +0000 |
98 | @@ -57,6 +57,11 @@ |
99 | return g_gr->images().get("images/wui/editor/fsel_editor_increase_resources.png"); |
100 | } |
101 | |
102 | + Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
103 | + const Widelands::EditorGameBase& egbase) override { |
104 | + return resource_tools_nodecaps(fcoords, egbase, cur_res_); |
105 | + } |
106 | + |
107 | int32_t get_change_by() const { |
108 | return change_by_; |
109 | } |
110 | |
111 | === modified file 'src/editor/tools/set_port_space_tool.cc' |
112 | --- src/editor/tools/set_port_space_tool.cc 2017-08-13 18:02:53 +0000 |
113 | +++ src/editor/tools/set_port_space_tool.cc 2017-09-13 18:51:31 +0000 |
114 | @@ -28,16 +28,19 @@ |
115 | |
116 | using namespace Widelands; |
117 | |
118 | -/// static callback function for overlay calculation |
119 | -int32_t editor_tool_set_port_space_callback(const Widelands::FCoords& c, const Map& map) { |
120 | +namespace { |
121 | + |
122 | +Widelands::NodeCaps port_tool_nodecaps(const Widelands::FCoords& c, const Map& map) { |
123 | NodeCaps const caps = c.field->nodecaps(); |
124 | if ((caps & BUILDCAPS_SIZEMASK) == BUILDCAPS_BIG) { |
125 | if (!map.find_portdock(c).empty()) |
126 | return caps; |
127 | } |
128 | - return 0; |
129 | + return NodeCaps::CAPS_NONE; |
130 | } |
131 | |
132 | +} // namespace |
133 | + |
134 | EditorSetPortSpaceTool::EditorSetPortSpaceTool(EditorUnsetPortSpaceTool& the_unset_tool) |
135 | : EditorTool(the_unset_tool, the_unset_tool) { |
136 | } |
137 | @@ -61,7 +64,7 @@ |
138 | *map, Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius)); |
139 | do { |
140 | // check if field is valid |
141 | - if (editor_tool_set_port_space_callback(mr.location(), *map)) { |
142 | + if (port_tool_nodecaps(mr.location(), *map) != NodeCaps::CAPS_NONE) { |
143 | map->set_port_space(mr.location(), true); |
144 | Area<FCoords> a(mr.location(), 0); |
145 | map->recalc_for_field_area(world, a); |
146 | @@ -72,6 +75,12 @@ |
147 | return nr; |
148 | } |
149 | |
150 | +Widelands::NodeCaps |
151 | +EditorSetPortSpaceTool::nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
152 | + const Widelands::EditorGameBase& egbase) { |
153 | + return port_tool_nodecaps(fcoords, egbase.map()); |
154 | +} |
155 | + |
156 | int32_t EditorSetPortSpaceTool::handle_undo_impl(const Widelands::World& world, |
157 | const NodeAndTriangle<Coords>& center, |
158 | EditorInteractive& parent, |
159 | @@ -96,7 +105,7 @@ |
160 | *map, Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius)); |
161 | do { |
162 | // check if field is valid |
163 | - if (editor_tool_set_port_space_callback(mr.location(), *map)) { |
164 | + if (port_tool_nodecaps(mr.location(), *map)) { |
165 | map->set_port_space(mr.location(), false); |
166 | Area<FCoords> a(mr.location(), 0); |
167 | map->recalc_for_field_area(world, a); |
168 | @@ -114,3 +123,9 @@ |
169 | Map* map) { |
170 | return parent.tools()->set_port_space.handle_click_impl(world, center, parent, args, map); |
171 | } |
172 | + |
173 | +Widelands::NodeCaps |
174 | +EditorUnsetPortSpaceTool::nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
175 | + const Widelands::EditorGameBase& egbase) { |
176 | + return port_tool_nodecaps(fcoords, egbase.map()); |
177 | +} |
178 | |
179 | === modified file 'src/editor/tools/set_port_space_tool.h' |
180 | --- src/editor/tools/set_port_space_tool.h 2017-08-13 18:02:53 +0000 |
181 | +++ src/editor/tools/set_port_space_tool.h 2017-09-13 18:51:31 +0000 |
182 | @@ -46,6 +46,8 @@ |
183 | const Image* get_sel_impl() const override { |
184 | return g_gr->images().get(FSEL_EUPS_FILENAME); |
185 | } |
186 | + Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
187 | + const Widelands::EditorGameBase& egbase) override; |
188 | }; |
189 | |
190 | /// Sets a buildspace for ports. |
191 | @@ -68,8 +70,8 @@ |
192 | const Image* get_sel_impl() const override { |
193 | return g_gr->images().get(FSEL_ESPS_FILENAME); |
194 | } |
195 | + Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
196 | + const Widelands::EditorGameBase& egbase) override; |
197 | }; |
198 | |
199 | -int32_t editor_tool_set_port_space_callback(const Widelands::FCoords& c, const Widelands::Map& map); |
200 | - |
201 | #endif // end of include guard: WL_EDITOR_TOOLS_SET_PORT_SPACE_TOOL_H |
202 | |
203 | === modified file 'src/editor/tools/set_resources_tool.cc' |
204 | --- src/editor/tools/set_resources_tool.cc 2017-01-25 18:55:59 +0000 |
205 | +++ src/editor/tools/set_resources_tool.cc 2017-09-13 18:51:31 +0000 |
206 | @@ -85,3 +85,13 @@ |
207 | a.set_to = set_to_; |
208 | return a; |
209 | } |
210 | + |
211 | +Widelands::NodeCaps resource_tools_nodecaps(const Widelands::FCoords& fcoords, |
212 | + const Widelands::EditorGameBase& egbase, |
213 | + Widelands::DescriptionIndex resource) { |
214 | + if (egbase.map().is_resource_valid(egbase.world(), fcoords, resource)) { |
215 | + return fcoords.field->nodecaps(); |
216 | + } |
217 | + return Widelands::NodeCaps::CAPS_NONE; |
218 | +} |
219 | + |
220 | |
221 | === modified file 'src/editor/tools/set_resources_tool.h' |
222 | --- src/editor/tools/set_resources_tool.h 2017-01-25 18:55:59 +0000 |
223 | +++ src/editor/tools/set_resources_tool.h 2017-09-13 18:51:31 +0000 |
224 | @@ -24,6 +24,10 @@ |
225 | #include "logic/mapregion.h" |
226 | #include "logic/widelands.h" |
227 | |
228 | +Widelands::NodeCaps resource_tools_nodecaps(const Widelands::FCoords& fcoords, |
229 | + const Widelands::EditorGameBase& egbase, |
230 | + Widelands::DescriptionIndex resource); |
231 | + |
232 | /// Decreases the resources of a node by a value. |
233 | struct EditorSetResourcesTool : public EditorTool { |
234 | EditorSetResourcesTool() : EditorTool(*this, *this), cur_res_(0), set_to_(0) { |
235 | @@ -50,6 +54,11 @@ |
236 | return g_gr->images().get("images/wui/editor/fsel_editor_set_resources.png"); |
237 | } |
238 | |
239 | + Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
240 | + const Widelands::EditorGameBase& egbase) override { |
241 | + return resource_tools_nodecaps(fcoords, egbase, cur_res_); |
242 | + } |
243 | + |
244 | Widelands::ResourceAmount get_set_to() const { |
245 | return set_to_; |
246 | } |
247 | |
248 | === modified file 'src/editor/tools/set_starting_pos_tool.cc' |
249 | --- src/editor/tools/set_starting_pos_tool.cc 2017-08-28 12:58:24 +0000 |
250 | +++ src/editor/tools/set_starting_pos_tool.cc 2017-09-13 18:51:31 +0000 |
251 | @@ -28,17 +28,17 @@ |
252 | // global variable to pass data from callback to class |
253 | static int32_t current_player_; |
254 | |
255 | -/* |
256 | - * static callback function for overlay calculation |
257 | - */ |
258 | -int32_t editor_tool_set_starting_pos_callback(const Widelands::FCoords& c, Widelands::Map& map) { |
259 | +namespace { |
260 | + |
261 | +Widelands::NodeCaps set_starting_pos_tool_nodecaps(const Widelands::FCoords& c, |
262 | + const Widelands::Map& map) { |
263 | // Area around already placed players |
264 | Widelands::PlayerNumber const nr_players = map.get_nrplayers(); |
265 | for (Widelands::PlayerNumber p = 1, last = current_player_ - 1;; ++p) { |
266 | for (; p <= last; ++p) { |
267 | if (Widelands::Coords const sp = map.get_starting_pos(p)) { |
268 | if (map.calc_distance(sp, c) < MIN_PLACE_AROUND_PLAYERS) { |
269 | - return 0; |
270 | + return Widelands::NodeCaps::CAPS_NONE; |
271 | } |
272 | } |
273 | } |
274 | @@ -52,9 +52,11 @@ |
275 | if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_BIG) |
276 | return caps; |
277 | |
278 | - return 0; |
279 | + return Widelands::NodeCaps::CAPS_NONE; |
280 | } |
281 | |
282 | +} // namespace |
283 | + |
284 | EditorSetStartingPosTool::EditorSetStartingPosTool() : EditorTool(*this, *this, false) { |
285 | current_player_ = 1; |
286 | } |
287 | @@ -78,13 +80,20 @@ |
288 | } |
289 | |
290 | // check if field is valid |
291 | - if (editor_tool_set_starting_pos_callback(map->get_fcoords(center.node), *map)) { |
292 | + if (set_starting_pos_tool_nodecaps(map->get_fcoords(center.node), *map) != |
293 | + Widelands::NodeCaps::CAPS_NONE) { |
294 | map->set_starting_pos(current_player_, center.node); |
295 | } |
296 | } |
297 | return 1; |
298 | } |
299 | |
300 | +Widelands::NodeCaps |
301 | +EditorSetStartingPosTool::nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
302 | + const Widelands::EditorGameBase& egbase) { |
303 | + return set_starting_pos_tool_nodecaps(fcoords, egbase.map()); |
304 | +} |
305 | + |
306 | Widelands::PlayerNumber EditorSetStartingPosTool::get_current_player() const { |
307 | return current_player_; |
308 | } |
309 | |
310 | === modified file 'src/editor/tools/set_starting_pos_tool.h' |
311 | --- src/editor/tools/set_starting_pos_tool.h 2017-08-28 12:41:15 +0000 |
312 | +++ src/editor/tools/set_starting_pos_tool.h 2017-09-13 18:51:31 +0000 |
313 | @@ -25,7 +25,6 @@ |
314 | #include "editor/tools/tool.h" |
315 | #include "graphic/playercolor.h" |
316 | #include "logic/widelands.h" |
317 | -#include "wui/field_overlay_manager.h" |
318 | |
319 | // How much place should be left around a player position |
320 | // where no other player can start |
321 | @@ -49,8 +48,8 @@ |
322 | bool has_size_one() const override { |
323 | return true; |
324 | } |
325 | + Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
326 | + const Widelands::EditorGameBase&) override; |
327 | }; |
328 | |
329 | -int32_t editor_tool_set_starting_pos_callback(const Widelands::FCoords& c, Widelands::Map& map); |
330 | - |
331 | #endif // end of include guard: WL_EDITOR_TOOLS_SET_STARTING_POS_TOOL_H |
332 | |
333 | === modified file 'src/editor/tools/tool.h' |
334 | --- src/editor/tools/tool.h 2017-01-25 18:55:59 +0000 |
335 | +++ src/editor/tools/tool.h 2017-09-13 18:51:31 +0000 |
336 | @@ -26,6 +26,7 @@ |
337 | #include "editor/tools/action_args.h" |
338 | #include "graphic/graphic.h" |
339 | #include "graphic/image.h" |
340 | +#include "logic/editor_game_base.h" |
341 | #include "logic/widelands_geometry.h" |
342 | |
343 | class EditorInteractive; |
344 | @@ -99,6 +100,14 @@ |
345 | return 0; |
346 | } // non unduable tools don't need to implement this. |
347 | virtual const Image* get_sel_impl() const = 0; |
348 | + |
349 | + // Gives the tool the chance to modify the nodecaps to change what will be |
350 | + // displayed as build help. |
351 | + virtual Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords, |
352 | + const Widelands::EditorGameBase&) { |
353 | + return fcoords.field->nodecaps(); |
354 | + } |
355 | + |
356 | virtual bool operates_on_triangles() const { |
357 | return false; |
358 | } |
359 | |
360 | === modified file 'src/editor/ui_menus/player_menu.cc' |
361 | --- src/editor/ui_menus/player_menu.cc 2017-09-01 00:16:04 +0000 |
362 | +++ src/editor/ui_menus/player_menu.cc 2017-09-13 18:51:31 +0000 |
363 | @@ -33,7 +33,6 @@ |
364 | #include "ui_basic/editbox.h" |
365 | #include "ui_basic/messagebox.h" |
366 | #include "ui_basic/textarea.h" |
367 | -#include "wui/field_overlay_manager.h" |
368 | |
369 | #define UNDEFINED_TRIBE_NAME "<undefined>" |
370 | |
371 | @@ -220,13 +219,6 @@ |
372 | Widelands::PlayerNumber const nr_players = old_nr_players - 1; |
373 | assert(1 <= nr_players); |
374 | |
375 | - if (const Widelands::Coords sp = map->get_starting_pos(old_nr_players)) { |
376 | - // Remove starting position marker. |
377 | - const Image* player_image = |
378 | - playercolor_image(old_nr_players - 1, "images/players/player_position.png"); |
379 | - assert(player_image); |
380 | - menu.mutable_field_overlay_manager()->remove_overlay(sp, player_image); |
381 | - } |
382 | // if removed player was selected switch to the next highest player |
383 | if (old_nr_players == menu.tools()->set_starting_pos.get_current_player()) { |
384 | set_starting_pos_clicked(nr_players); |
385 | @@ -275,12 +267,6 @@ |
386 | |
387 | // reselect tool, so everything is in a defined state |
388 | menu.select_tool(menu.tools()->current(), EditorTool::First); |
389 | - |
390 | - // Register callback function to make sure that only valid locations are |
391 | - // selected. |
392 | - menu.mutable_field_overlay_manager()->register_overlay_callback_function( |
393 | - boost::bind(&editor_tool_set_starting_pos_callback, _1, boost::ref(*map))); |
394 | - map->recalc_whole_map(menu.egbase().world()); |
395 | update(); |
396 | } |
397 | |
398 | |
399 | === modified file 'src/editor/ui_menus/tool_change_resources_options_menu.cc' |
400 | --- src/editor/ui_menus/tool_change_resources_options_menu.cc 2017-08-19 22:22:20 +0000 |
401 | +++ src/editor/ui_menus/tool_change_resources_options_menu.cc 2017-09-13 18:51:31 +0000 |
402 | @@ -35,7 +35,6 @@ |
403 | #include "logic/map_objects/world/world.h" |
404 | #include "logic/widelands.h" |
405 | #include "logic/widelands_geometry.h" |
406 | -#include "wui/field_overlay_manager.h" |
407 | |
408 | constexpr int kMaxValue = 63; |
409 | |
410 | @@ -153,17 +152,6 @@ |
411 | increase_tool_.set_cur_res(resource_index); |
412 | increase_tool_.decrease_tool().set_cur_res(resource_index); |
413 | |
414 | - Widelands::EditorGameBase& egbase = eia().egbase(); |
415 | - Widelands::Map* map = egbase.mutable_map(); |
416 | - eia().mutable_field_overlay_manager()->register_overlay_callback_function( |
417 | - [resource_index, map, &egbase](const Widelands::FCoords& fc) -> uint32_t { |
418 | - if (map->is_resource_valid(egbase.world(), fc, resource_index)) { |
419 | - return fc.field->nodecaps(); |
420 | - } |
421 | - return 0; |
422 | - }); |
423 | - |
424 | - map->recalc_whole_map(egbase.world()); |
425 | select_correct_tool(); |
426 | update(); |
427 | } |
428 | |
429 | === modified file 'src/editor/ui_menus/tool_menu.cc' |
430 | --- src/editor/ui_menus/tool_menu.cc 2017-08-19 22:22:20 +0000 |
431 | +++ src/editor/ui_menus/tool_menu.cc 2017-09-13 18:51:31 +0000 |
432 | @@ -140,13 +140,6 @@ |
433 | } |
434 | |
435 | parent.select_tool(*current_tool_pointer, EditorTool::First); |
436 | - if (current_tool_pointer == &parent.tools()->set_port_space) { |
437 | - // Set correct overlay |
438 | - Widelands::Map* map = parent.egbase().mutable_map(); |
439 | - parent.mutable_field_overlay_manager()->register_overlay_callback_function( |
440 | - boost::bind(&editor_tool_set_port_space_callback, _1, boost::ref(*map))); |
441 | - map->recalc_whole_map(parent.egbase().world()); |
442 | - } |
443 | |
444 | if (current_registry_pointer) { |
445 | if (UI::Window* const window = current_registry_pointer->window) { |
446 | |
447 | === modified file 'src/graphic/CMakeLists.txt' |
448 | --- src/graphic/CMakeLists.txt 2017-08-28 08:33:02 +0000 |
449 | +++ src/graphic/CMakeLists.txt 2017-09-13 18:51:31 +0000 |
450 | @@ -184,7 +184,6 @@ |
451 | graphic_surface |
452 | logic |
453 | wui |
454 | - wui_field_overlay_manager |
455 | wui_mapview_pixelfunctions |
456 | ) |
457 | |
458 | |
459 | === modified file 'src/graphic/game_renderer.cc' |
460 | --- src/graphic/game_renderer.cc 2017-08-29 10:48:24 +0000 |
461 | +++ src/graphic/game_renderer.cc 2017-09-13 18:51:31 +0000 |
462 | @@ -29,7 +29,6 @@ |
463 | #include "logic/editor_game_base.h" |
464 | #include "logic/map_objects/world/world.h" |
465 | #include "logic/player.h" |
466 | -#include "wui/field_overlay_manager.h" |
467 | #include "wui/interactive_base.h" |
468 | #include "wui/mapviewpixelconstants.h" |
469 | #include "wui/mapviewpixelfunctions.h" |
470 | |
471 | === modified file 'src/logic/map.cc' |
472 | --- src/logic/map.cc 2017-09-03 09:36:11 +0000 |
473 | +++ src/logic/map.cc 2017-09-13 18:51:31 +0000 |
474 | @@ -1770,7 +1770,7 @@ |
475 | |
476 | bool Map::is_resource_valid(const Widelands::World& world, |
477 | const Widelands::FCoords& c, |
478 | - DescriptionIndex curres) { |
479 | + DescriptionIndex curres) const { |
480 | if (curres == Widelands::kNoResource) |
481 | return true; |
482 | |
483 | |
484 | === modified file 'src/logic/map.h' |
485 | --- src/logic/map.h 2017-08-31 10:55:45 +0000 |
486 | +++ src/logic/map.h 2017-09-13 18:51:31 +0000 |
487 | @@ -428,7 +428,7 @@ |
488 | */ |
489 | bool is_resource_valid(const Widelands::World& world, |
490 | const Widelands::FCoords& c, |
491 | - DescriptionIndex curres); |
492 | + DescriptionIndex curres) const; |
493 | |
494 | // The objectives that are defined in this map if it is a scenario. |
495 | const Objectives& objectives() const { |
496 | |
497 | === modified file 'src/wui/CMakeLists.txt' |
498 | --- src/wui/CMakeLists.txt 2017-09-04 05:08:56 +0000 |
499 | +++ src/wui/CMakeLists.txt 2017-09-13 18:51:31 +0000 |
500 | @@ -24,17 +24,6 @@ |
501 | wui |
502 | ) |
503 | |
504 | -wl_library(wui_field_overlay_manager |
505 | - SRCS |
506 | - field_overlay_manager.cc |
507 | - field_overlay_manager.h |
508 | - DEPENDS |
509 | - base_geometry |
510 | - graphic |
511 | - logic |
512 | - logic_widelands_geometry |
513 | -) |
514 | - |
515 | wl_library(wui_economy_options |
516 | SRCS |
517 | economy_options_window.cc |
518 | @@ -265,7 +254,6 @@ |
519 | ui_basic |
520 | wui_chat_ui |
521 | wui_economy_options |
522 | - wui_field_overlay_manager |
523 | wui_mapview |
524 | wui_mapview_pixelfunctions |
525 | wui_quicknavigation |
526 | |
527 | === modified file 'src/wui/buildingwindow.h' |
528 | --- src/wui/buildingwindow.h 2017-09-01 09:18:10 +0000 |
529 | +++ src/wui/buildingwindow.h 2017-09-13 18:51:31 +0000 |
530 | @@ -28,7 +28,6 @@ |
531 | #include "notifications/notifications.h" |
532 | #include "ui_basic/button.h" |
533 | #include "ui_basic/unique_window.h" |
534 | -#include "wui/field_overlay_manager.h" |
535 | #include "wui/interactive_gamebase.h" |
536 | #include "wui/waresdisplay.h" |
537 | |
538 | |
539 | === removed file 'src/wui/field_overlay_manager.cc' |
540 | --- src/wui/field_overlay_manager.cc 2017-08-16 05:10:15 +0000 |
541 | +++ src/wui/field_overlay_manager.cc 1970-01-01 00:00:00 +0000 |
542 | @@ -1,181 +0,0 @@ |
543 | -/* |
544 | - * Copyright (C) 2002-2017 by the Widelands Development Team |
545 | - * |
546 | - * This program is free software; you can redistribute it and/or |
547 | - * modify it under the terms of the GNU General Public License |
548 | - * as published by the Free Software Foundation; either version 2 |
549 | - * of the License, or (at your option) any later version. |
550 | - * |
551 | - * This program is distributed in the hope that it will be useful, |
552 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
553 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
554 | - * GNU General Public License for more details. |
555 | - * |
556 | - * You should have received a copy of the GNU General Public License |
557 | - * along with this program; if not, write to the Free Software |
558 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
559 | - * |
560 | - */ |
561 | - |
562 | -#include "wui/field_overlay_manager.h" |
563 | - |
564 | -#include <algorithm> |
565 | - |
566 | -#include <stdint.h> |
567 | - |
568 | -#include "graphic/graphic.h" |
569 | -#include "logic/field.h" |
570 | - |
571 | -FieldOverlayManager::FieldOverlayManager() : buildhelp_(false), current_overlay_id_(0) { |
572 | - OverlayInfo* buildhelp_info = buildhelp_infos_; |
573 | - const char* filenames[] = {"images/wui/overlays/set_flag.png", "images/wui/overlays/small.png", |
574 | - "images/wui/overlays/medium.png", "images/wui/overlays/big.png", |
575 | - "images/wui/overlays/mine.png", "images/wui/overlays/port.png"}; |
576 | - const char* const* filename = filenames; |
577 | - |
578 | - // Special case for flag, which has a different formula for hotspot_y. |
579 | - buildhelp_info->pic = g_gr->images().get(*filename); |
580 | - buildhelp_info->hotspot = |
581 | - Vector2i(buildhelp_info->pic->width() / 2, buildhelp_info->pic->height() - 1); |
582 | - |
583 | - const OverlayInfo* const buildhelp_infos_end = buildhelp_info + Widelands::Field::Buildhelp_None; |
584 | - for (;;) { // The other buildhelp overlays. |
585 | - ++buildhelp_info; |
586 | - ++filename; |
587 | - if (buildhelp_info == buildhelp_infos_end) |
588 | - break; |
589 | - buildhelp_info->pic = g_gr->images().get(*filename); |
590 | - buildhelp_info->hotspot = |
591 | - Vector2i(buildhelp_info->pic->width() / 2, buildhelp_info->pic->height() / 2); |
592 | - } |
593 | -} |
594 | - |
595 | -bool FieldOverlayManager::buildhelp() const { |
596 | - return buildhelp_; |
597 | -} |
598 | - |
599 | -void FieldOverlayManager::show_buildhelp(const bool value) { |
600 | - buildhelp_ = value; |
601 | -} |
602 | - |
603 | -int FieldOverlayManager::get_buildhelp_overlay(const Widelands::FCoords& fc) const { |
604 | - Widelands::NodeCaps const caps = |
605 | - callback_ ? static_cast<Widelands::NodeCaps>(callback_(fc)) : fc.field->nodecaps(); |
606 | - |
607 | - if (caps & Widelands::BUILDCAPS_MINE) { |
608 | - return Widelands::Field::Buildhelp_Mine; |
609 | - } |
610 | - if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_BIG) { |
611 | - if (caps & Widelands::BUILDCAPS_PORT) { |
612 | - return Widelands::Field::Buildhelp_Port; |
613 | - } |
614 | - return Widelands::Field::Buildhelp_Big; |
615 | - } |
616 | - if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_MEDIUM) { |
617 | - return Widelands::Field::Buildhelp_Medium; |
618 | - } |
619 | - if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_SMALL) { |
620 | - return Widelands::Field::Buildhelp_Small; |
621 | - } |
622 | - if (caps & Widelands::BUILDCAPS_FLAG) { |
623 | - return Widelands::Field::Buildhelp_Flag; |
624 | - } |
625 | - return Widelands::Field::Buildhelp_None; |
626 | -} |
627 | - |
628 | -void FieldOverlayManager::register_overlay(const Widelands::Coords& c, |
629 | - const Image* pic, |
630 | - const OverlayLevel& level, |
631 | - Vector2i hotspot, |
632 | - OverlayId const overlay_id) { |
633 | - if (hotspot == Vector2i::invalid()) { |
634 | - hotspot = Vector2i(pic->width() / 2, pic->height() / 2); |
635 | - } |
636 | - |
637 | - for (auto it = overlays_.find(c); it != overlays_.end() && it->first == c; ++it) |
638 | - if (it->second.pic == pic && it->second.hotspot == hotspot && it->second.level == level) { |
639 | - it->second.overlay_ids.insert(overlay_id); |
640 | - return; |
641 | - } |
642 | - |
643 | - overlays_.insert(std::pair<Widelands::Coords const, RegisteredOverlays>( |
644 | - c, RegisteredOverlays(overlay_id, pic, hotspot, level))); |
645 | - |
646 | - // Now manually sort, so that they are ordered |
647 | - // * first by c (done by std::multimap) |
648 | - // * second by levels (done manually here) |
649 | - |
650 | - // there is at least one registered |
651 | - auto it = overlays_.lower_bound(c); |
652 | - do { |
653 | - auto jt = it; |
654 | - ++jt; |
655 | - if (jt == overlays_.end()) |
656 | - break; |
657 | - if (jt->first == it->first) { |
658 | - // There are several overlays registered for this location. |
659 | - if (jt->second.level < it->second.level) { |
660 | - std::swap(it->second, jt->second); |
661 | - it = overlays_.lower_bound(c); |
662 | - } else |
663 | - ++it; |
664 | - } else |
665 | - break; // it is the last element, break this loop. |
666 | - } while (it->first == c); |
667 | -} |
668 | - |
669 | -/** |
670 | - * remove one (or many) overlays from a node or triangle |
671 | - * |
672 | - * @param pic The overlay to remove. If null, all overlays are removed. |
673 | - */ |
674 | -void FieldOverlayManager::remove_overlay(const Widelands::Coords& c, const Image* pic) { |
675 | - if (overlays_.count(c) == 0) { |
676 | - return; |
677 | - } |
678 | - auto it = overlays_.lower_bound(c); |
679 | - do { |
680 | - if (!pic || it->second.pic == pic) { |
681 | - overlays_.erase(it); |
682 | - it = overlays_.lower_bound(c); |
683 | - } else { |
684 | - ++it; |
685 | - } |
686 | - } while (it != overlays_.end() && it->first == c); |
687 | -} |
688 | - |
689 | -void FieldOverlayManager::remove_overlay(const OverlayId overlay_id) { |
690 | - for (auto it = overlays_.begin(); it != overlays_.end();) { |
691 | - it->second.overlay_ids.erase(overlay_id); |
692 | - if (it->second.overlay_ids.empty()) { |
693 | - overlays_.erase(it++); // This is necessary! |
694 | - } else { |
695 | - ++it; |
696 | - } |
697 | - } |
698 | -} |
699 | - |
700 | -void FieldOverlayManager::remove_all_overlays() { |
701 | - overlays_.clear(); |
702 | -} |
703 | - |
704 | -void FieldOverlayManager::register_overlay_callback_function(CallbackFn function) { |
705 | - callback_ = function; |
706 | -} |
707 | - |
708 | -FieldOverlayManager::OverlayId FieldOverlayManager::next_overlay_id() { |
709 | - ++current_overlay_id_; |
710 | - return current_overlay_id_; |
711 | -} |
712 | - |
713 | -bool FieldOverlayManager::is_enabled(const OverlayLevel& level) const { |
714 | - return disabled_layers_.count(level) == 0; |
715 | -} |
716 | - |
717 | -void FieldOverlayManager::set_enabled(const OverlayLevel& level, const bool enabled) { |
718 | - if (enabled) { |
719 | - disabled_layers_.erase(level); |
720 | - } else { |
721 | - disabled_layers_.insert(level); |
722 | - } |
723 | -} |
724 | |
725 | === removed file 'src/wui/field_overlay_manager.h' |
726 | --- src/wui/field_overlay_manager.h 2017-09-01 13:26:55 +0000 |
727 | +++ src/wui/field_overlay_manager.h 1970-01-01 00:00:00 +0000 |
728 | @@ -1,172 +0,0 @@ |
729 | -/* |
730 | - * Copyright (C) 2002-2017 by the Widelands Development Team |
731 | - * |
732 | - * This program is free software; you can redistribute it and/or |
733 | - * modify it under the terms of the GNU General Public License |
734 | - * as published by the Free Software Foundation; either version 2 |
735 | - * of the License, or (at your option) any later version. |
736 | - * |
737 | - * This program is distributed in the hope that it will be useful, |
738 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
739 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
740 | - * GNU General Public License for more details. |
741 | - * |
742 | - * You should have received a copy of the GNU General Public License |
743 | - * along with this program; if not, write to the Free Software |
744 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
745 | - * |
746 | - */ |
747 | - |
748 | -#ifndef WL_WUI_FIELD_OVERLAY_MANAGER_H |
749 | -#define WL_WUI_FIELD_OVERLAY_MANAGER_H |
750 | - |
751 | -#include <functional> |
752 | -#include <map> |
753 | -#include <set> |
754 | -#include <vector> |
755 | - |
756 | -#include "base/vector.h" |
757 | -#include "logic/field.h" |
758 | -#include "logic/widelands_geometry.h" |
759 | - |
760 | -class Image; |
761 | - |
762 | -/* |
763 | - * The Overlay Manager is responsible for the map overlays. He |
764 | - * manages overlays in the following way: |
765 | - * - When someone registered one (or more) special overlays |
766 | - * for a field he draws them accordingly |
767 | - * |
768 | - * about the level variable: |
769 | - * the level describe when the overlay should be drawn, lower means drawn |
770 | - * earlier. |
771 | - * |
772 | - * about overlay_id: |
773 | - * the overlay_id can be given to the register function, whenever |
774 | - * the job is finished or canceled, a simple remove_overlay |
775 | - * with the overlay_id can be called and all overlays created in the |
776 | - * job are removed. |
777 | - */ |
778 | - |
779 | -// Levels for the overlay registers. This defines in which order they will be |
780 | -// drawn. Buildhelp is special and has the value 5, i.e. every smaller will be |
781 | -// drawn below the buildhelp, everything higher above. |
782 | -// TODO(sirver): no longer used. remove. |
783 | -enum class OverlayLevel {}; |
784 | - |
785 | -struct FieldOverlayManager { |
786 | - /// A unique id identifying a registered overlay. |
787 | - using OverlayId = uint32_t; |
788 | - |
789 | - /// A function returning Field::nodecaps() for the build overlay. This can be |
790 | - /// registered to hide or change some of the nodecaps during rendering. |
791 | - using CallbackFn = std::function<int32_t(const Widelands::FCoords& coordinates)>; |
792 | - |
793 | - FieldOverlayManager(); |
794 | - |
795 | - /// Returns true if the buildhelp is currently shown. |
796 | - bool buildhelp() const; |
797 | - |
798 | - /// Defines if the buildhelp should be shown. |
799 | - void show_buildhelp(bool t); |
800 | - |
801 | - /// Register callback function. |
802 | - void register_overlay_callback_function(CallbackFn function); |
803 | - |
804 | - /// Like 'buildhelp', but for an individual layer. |
805 | - bool is_enabled(const OverlayLevel& level) const; |
806 | - void set_enabled(const OverlayLevel& level, bool value); |
807 | - |
808 | - /// Get a unique, unused id that can be passed to register_overlay. |
809 | - OverlayId next_overlay_id(); |
810 | - |
811 | - /// Register an overlay at a location (node or triangle). hotspot is the point |
812 | - /// of the picture that will be exactly over the location. If hotspot is |
813 | - /// Vector2i::invalid(), the center of the picture will be used as hotspot. |
814 | - void register_overlay(const Widelands::Coords& coords, |
815 | - const Image* pic, |
816 | - const OverlayLevel& overlay_level, |
817 | - Vector2i hotspot = Vector2i::invalid(), |
818 | - OverlayId overlay_id = 0); |
819 | - |
820 | - /// removes all overlays when pic is nullptr. |
821 | - void remove_overlay(const Widelands::Coords& coords, const Image* pic); |
822 | - |
823 | - /// remove all overlays with this overlay_id |
824 | - void remove_overlay(OverlayId overlay_id); |
825 | - |
826 | - /// Removes all overlays. |
827 | - // TODO(sirver): It would be preferable to just delete and recreate the object. |
828 | - void remove_all_overlays(); |
829 | - |
830 | - /// Calls 'func' for each of the the currently registered and enabled |
831 | - /// overlays and the buildhelp. |
832 | - template <typename T> void foreach_overlay(const Widelands::FCoords& c, T func) const { |
833 | - auto it = overlays_.lower_bound(c); |
834 | - while (it != overlays_.end() && it->first == c && |
835 | - static_cast<int>(it->second.level) <= kLevelForBuildHelp) { |
836 | - if (is_enabled(it->second.level)) { |
837 | - func(it->second.pic, it->second.hotspot); |
838 | - } |
839 | - ++it; |
840 | - } |
841 | - |
842 | - if (buildhelp_) { |
843 | - int buildhelp_overlay_index = get_buildhelp_overlay(c); |
844 | - if (buildhelp_overlay_index < Widelands::Field::Buildhelp_None) { |
845 | - auto& overlay_info = buildhelp_infos_[buildhelp_overlay_index]; |
846 | - func(overlay_info.pic, overlay_info.hotspot); |
847 | - } |
848 | - } |
849 | - |
850 | - while (it != overlays_.end() && it->first == c) { |
851 | - if (is_enabled(it->second.level)) { |
852 | - func(it->second.pic, it->second.hotspot); |
853 | - } |
854 | - ++it; |
855 | - } |
856 | - } |
857 | - |
858 | -private: |
859 | - static constexpr int kLevelForBuildHelp = 5; |
860 | - |
861 | - /// A overlay as drawn onto the screen. |
862 | - struct OverlayInfo { |
863 | - const Image* pic = nullptr; |
864 | - Vector2i hotspot = Vector2i::zero(); |
865 | - }; |
866 | - |
867 | - struct RegisteredOverlays { |
868 | - RegisteredOverlays(const OverlayId init_overlay_id, |
869 | - const Image* init_pic, |
870 | - const Vector2i init_hotspot, |
871 | - const OverlayLevel& init_level) |
872 | - : pic(init_pic), hotspot(init_hotspot), level(init_level) { |
873 | - overlay_ids.insert(init_overlay_id); |
874 | - } |
875 | - std::set<OverlayId> overlay_ids; |
876 | - const Image* pic; |
877 | - Vector2i hotspot = Vector2i::zero(); |
878 | - OverlayLevel level; |
879 | - }; |
880 | - |
881 | - // Returns the index into buildhelp_infos_ for the correct fieldcaps for |
882 | - // 'fc' according to the current 'callback_'. |
883 | - int get_buildhelp_overlay(const Widelands::FCoords& fc) const; |
884 | - |
885 | - std::multimap<const Widelands::Coords, RegisteredOverlays> overlays_; |
886 | - |
887 | - OverlayInfo buildhelp_infos_[Widelands::Field::Buildhelp_None]; |
888 | - bool buildhelp_; |
889 | - // We are inverting the logic here, since new layers are by default enabled |
890 | - // and we only support to toggle some of them off. Otherwise whenever a new |
891 | - // layer is added in 'OverlayLevel' we would also need to add it to the |
892 | - // 'enabled_layers_' set on construction. |
893 | - std::set<OverlayLevel> disabled_layers_; |
894 | - |
895 | - // this callback is used to define where overlays are drawn. |
896 | - CallbackFn callback_; |
897 | - OverlayId current_overlay_id_; |
898 | -}; |
899 | - |
900 | -#endif // end of include guard: WL_WUI_FIELD_OVERLAY_MANAGER_H |
901 | |
902 | === modified file 'src/wui/fieldaction.cc' |
903 | --- src/wui/fieldaction.cc 2017-09-03 13:03:56 +0000 |
904 | +++ src/wui/fieldaction.cc 2017-09-13 18:51:31 +0000 |
905 | @@ -41,7 +41,6 @@ |
906 | #include "wui/actionconfirm.h" |
907 | #include "wui/attack_box.h" |
908 | #include "wui/economy_options_window.h" |
909 | -#include "wui/field_overlay_manager.h" |
910 | #include "wui/game_debug_ui.h" |
911 | #include "wui/interactive_player.h" |
912 | #include "wui/waresdisplay.h" |
913 | |
914 | === modified file 'src/wui/interactive_base.cc' |
915 | --- src/wui/interactive_base.cc 2017-09-11 19:18:35 +0000 |
916 | +++ src/wui/interactive_base.cc 2017-09-13 18:51:31 +0000 |
917 | @@ -46,7 +46,6 @@ |
918 | #include "logic/widelands_geometry.h" |
919 | #include "profile/profile.h" |
920 | #include "scripting/lua_interface.h" |
921 | -#include "wui/field_overlay_manager.h" |
922 | #include "wui/game_chat_menu.h" |
923 | #include "wui/game_debug_ui.h" |
924 | #include "wui/interactive_player.h" |
925 | @@ -56,6 +55,8 @@ |
926 | #include "wui/minimap.h" |
927 | #include "wui/unique_window_handler.h" |
928 | |
929 | +namespace { |
930 | + |
931 | using Widelands::Area; |
932 | using Widelands::CoordPath; |
933 | using Widelands::Coords; |
934 | @@ -65,15 +66,39 @@ |
935 | using Widelands::MapObject; |
936 | using Widelands::TCoords; |
937 | |
938 | +int caps_to_buildhelp(const Widelands::NodeCaps caps) { |
939 | + if (caps & Widelands::BUILDCAPS_MINE) { |
940 | + return Widelands::Field::Buildhelp_Mine; |
941 | + } |
942 | + if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_BIG) { |
943 | + if (caps & Widelands::BUILDCAPS_PORT) { |
944 | + return Widelands::Field::Buildhelp_Port; |
945 | + } |
946 | + return Widelands::Field::Buildhelp_Big; |
947 | + } |
948 | + if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_MEDIUM) { |
949 | + return Widelands::Field::Buildhelp_Medium; |
950 | + } |
951 | + if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_SMALL) { |
952 | + return Widelands::Field::Buildhelp_Small; |
953 | + } |
954 | + if (caps & Widelands::BUILDCAPS_FLAG) { |
955 | + return Widelands::Field::Buildhelp_Flag; |
956 | + } |
957 | + return Widelands::Field::Buildhelp_None; |
958 | +} |
959 | + |
960 | +} // namespace |
961 | + |
962 | InteractiveBase::InteractiveBase(EditorGameBase& the_egbase, Section& global_s) |
963 | : UI::Panel(nullptr, 0, 0, g_gr->get_xres(), g_gr->get_yres()), |
964 | show_workarea_preview_(global_s.get_bool("workareapreview", true)), |
965 | + buildhelp_(false), |
966 | map_view_(this, the_egbase.map(), 0, 0, g_gr->get_xres(), g_gr->get_yres()), |
967 | // Initialize chatoveraly before the toolbar so it is below |
968 | chat_overlay_(new ChatOverlay(this, 10, 25, get_w() / 2, get_h() - 25)), |
969 | toolbar_(this, 0, 0, UI::Box::Horizontal), |
970 | quick_navigation_(&map_view_), |
971 | - field_overlay_manager_(new FieldOverlayManager()), |
972 | egbase_(the_egbase), |
973 | #ifndef NDEBUG // not in releases |
974 | display_flags_(dfDebug), |
975 | @@ -94,6 +119,33 @@ |
976 | g_gr->images().get("images/wui/overlays/workarea2.png"), |
977 | g_gr->images().get("images/wui/overlays/workarea1.png")} { |
978 | |
979 | + // Load the buildhelp icons. |
980 | + { |
981 | + BuildhelpOverlay* buildhelp_overlay = buildhelp_overlays_; |
982 | + const char* filenames[] = { |
983 | + "images/wui/overlays/set_flag.png", "images/wui/overlays/small.png", |
984 | + "images/wui/overlays/medium.png", "images/wui/overlays/big.png", |
985 | + "images/wui/overlays/mine.png", "images/wui/overlays/port.png"}; |
986 | + const char* const* filename = filenames; |
987 | + |
988 | + // Special case for flag, which has a different formula for hotspot_y. |
989 | + buildhelp_overlay->pic = g_gr->images().get(*filename); |
990 | + buildhelp_overlay->hotspot = |
991 | + Vector2i(buildhelp_overlay->pic->width() / 2, buildhelp_overlay->pic->height() - 1); |
992 | + |
993 | + const BuildhelpOverlay* const buildhelp_overlays_end = |
994 | + buildhelp_overlay + Widelands::Field::Buildhelp_None; |
995 | + for (;;) { // The other buildhelp overlays. |
996 | + ++buildhelp_overlay; |
997 | + ++filename; |
998 | + if (buildhelp_overlay == buildhelp_overlays_end) |
999 | + break; |
1000 | + buildhelp_overlay->pic = g_gr->images().get(*filename); |
1001 | + buildhelp_overlay->hotspot = |
1002 | + Vector2i(buildhelp_overlay->pic->width() / 2, buildhelp_overlay->pic->height() / 2); |
1003 | + } |
1004 | + } |
1005 | + |
1006 | resize_chat_overlay(); |
1007 | |
1008 | graphic_resolution_changed_subscriber_ = Notifications::subscribe<GraphicResolutionChanged>( |
1009 | @@ -144,6 +196,15 @@ |
1010 | } |
1011 | } |
1012 | |
1013 | +const InteractiveBase::BuildhelpOverlay* |
1014 | +InteractiveBase::get_buildhelp_overlay(const Widelands::NodeCaps caps) const { |
1015 | + const int buildhelp_overlay_index = caps_to_buildhelp(caps); |
1016 | + if (buildhelp_overlay_index < Widelands::Field::Buildhelp_None) { |
1017 | + return &buildhelp_overlays_[buildhelp_overlay_index]; |
1018 | + } |
1019 | + return nullptr; |
1020 | +} |
1021 | + |
1022 | UniqueWindowHandler& InteractiveBase::unique_windows() { |
1023 | return *unique_window_handler_; |
1024 | } |
1025 | @@ -202,16 +263,16 @@ |
1026 | } |
1027 | |
1028 | bool InteractiveBase::buildhelp() const { |
1029 | - return field_overlay_manager_->buildhelp(); |
1030 | + return buildhelp_; |
1031 | } |
1032 | |
1033 | void InteractiveBase::show_buildhelp(bool t) { |
1034 | - field_overlay_manager_->show_buildhelp(t); |
1035 | + buildhelp_ = t; |
1036 | on_buildhelp_changed(t); |
1037 | } |
1038 | |
1039 | void InteractiveBase::toggle_buildhelp() { |
1040 | - show_buildhelp(!field_overlay_manager_->buildhelp()); |
1041 | + show_buildhelp(!buildhelp()); |
1042 | } |
1043 | |
1044 | UI::Button* InteractiveBase::add_toolbar_button(const std::string& image_basename, |
1045 | |
1046 | === modified file 'src/wui/interactive_base.h' |
1047 | --- src/wui/interactive_base.h 2017-09-11 14:11:56 +0000 |
1048 | +++ src/wui/interactive_base.h 2017-09-13 18:51:31 +0000 |
1049 | @@ -37,7 +37,6 @@ |
1050 | #include "ui_basic/unique_window.h" |
1051 | #include "wui/chatoverlay.h" |
1052 | #include "wui/debugconsole.h" |
1053 | -#include "wui/field_overlay_manager.h" |
1054 | #include "wui/mapview.h" |
1055 | #include "wui/minimap.h" |
1056 | #include "wui/quicknavigation.h" |
1057 | @@ -72,6 +71,12 @@ |
1058 | std::map<Widelands::Coords, const Image*> steepness_indicators; |
1059 | }; |
1060 | |
1061 | + /// A build help overlay, i.e. small, big, mine, port ... |
1062 | + struct BuildhelpOverlay { |
1063 | + const Image* pic = nullptr; |
1064 | + Vector2i hotspot = Vector2i::zero(); |
1065 | + }; |
1066 | + |
1067 | // Manages all UniqueWindows. |
1068 | UniqueWindowHandler& unique_windows(); |
1069 | |
1070 | @@ -155,13 +160,6 @@ |
1071 | log_message(std::string(message)); |
1072 | } |
1073 | |
1074 | - const FieldOverlayManager& field_overlay_manager() const { |
1075 | - return *field_overlay_manager_; |
1076 | - } |
1077 | - FieldOverlayManager* mutable_field_overlay_manager() { |
1078 | - return field_overlay_manager_.get(); |
1079 | - } |
1080 | - |
1081 | void toggle_minimap(); |
1082 | void toggle_buildhelp(); |
1083 | |
1084 | @@ -171,10 +169,6 @@ |
1085 | // Sets the landmark for the keyboard 'key' to 'point' |
1086 | void set_landmark(size_t key, const MapView::View& view); |
1087 | |
1088 | - const RoadBuildingOverlays& road_building_overlays() const { |
1089 | - return road_building_overlays_; |
1090 | - } |
1091 | - |
1092 | MapView* map_view() { |
1093 | return &map_view_; |
1094 | } |
1095 | @@ -228,6 +222,14 @@ |
1096 | std::map<Widelands::Coords, const Image*> |
1097 | get_work_area_overlays(const Widelands::Map& map) const; |
1098 | |
1099 | + // Returns the 'BuildhelpOverlay' for 'caps' or nullptr if there is no help |
1100 | + // to be displayed on this field. |
1101 | + const BuildhelpOverlay* get_buildhelp_overlay(Widelands::NodeCaps caps) const; |
1102 | + |
1103 | + const RoadBuildingOverlays& road_building_overlays() const { |
1104 | + return road_building_overlays_; |
1105 | + } |
1106 | + |
1107 | private: |
1108 | int32_t stereo_position(Widelands::Coords position_map); |
1109 | void resize_chat_overlay(); |
1110 | @@ -244,18 +246,17 @@ |
1111 | Widelands::Coords(0, 0), |
1112 | Widelands::TCoords<>(Widelands::Coords(0, 0), Widelands::TriangleIndex::D)}, |
1113 | const uint32_t Radius = 0, |
1114 | - const Image* Pic = nullptr, |
1115 | - const FieldOverlayManager::OverlayId Jobid = 0) |
1116 | - : freeze(Freeze), triangles(Triangles), pos(Pos), radius(Radius), pic(Pic), jobid(Jobid) { |
1117 | + const Image* Pic = nullptr) |
1118 | + : freeze(Freeze), triangles(Triangles), pos(Pos), radius(Radius), pic(Pic) { |
1119 | } |
1120 | bool freeze; // don't change sel, even if mouse moves |
1121 | bool triangles; // otherwise nodes |
1122 | Widelands::NodeAndTriangle<> pos; |
1123 | uint32_t radius; |
1124 | const Image* pic; |
1125 | - FieldOverlayManager::OverlayId jobid; |
1126 | } sel_; |
1127 | |
1128 | + bool buildhelp_; |
1129 | MapView map_view_; |
1130 | ChatOverlay* chat_overlay_; |
1131 | |
1132 | @@ -270,8 +271,6 @@ |
1133 | MiniMap::Registry minimap_registry_; |
1134 | QuickNavigation quick_navigation_; |
1135 | |
1136 | - std::unique_ptr<FieldOverlayManager> field_overlay_manager_; |
1137 | - |
1138 | // The currently enabled work area previews. They are keyed by the |
1139 | // coordinate that the building that shows the work area is positioned. |
1140 | std::map<Widelands::Coords, const WorkareaInfo*> work_area_previews_; |
1141 | @@ -293,6 +292,7 @@ |
1142 | UI::UniqueWindow::Registry debugconsole_; |
1143 | std::unique_ptr<UniqueWindowHandler> unique_window_handler_; |
1144 | std::vector<const Image*> workarea_pics_; |
1145 | + BuildhelpOverlay buildhelp_overlays_[Widelands::Field::Buildhelp_None]; |
1146 | }; |
1147 | |
1148 | #endif // end of include guard: WL_WUI_INTERACTIVE_BASE_H |
1149 | |
1150 | === modified file 'src/wui/interactive_gamebase.cc' |
1151 | --- src/wui/interactive_gamebase.cc 2017-08-20 17:45:42 +0000 |
1152 | +++ src/wui/interactive_gamebase.cc 2017-09-13 18:51:31 +0000 |
1153 | @@ -137,13 +137,9 @@ |
1154 | * during single/multiplayer/scenario). |
1155 | */ |
1156 | void InteractiveGameBase::postload() { |
1157 | - auto* overlay_manager = mutable_field_overlay_manager(); |
1158 | show_buildhelp(false); |
1159 | on_buildhelp_changed(buildhelp()); |
1160 | |
1161 | - overlay_manager->register_overlay_callback_function( |
1162 | - boost::bind(&InteractiveGameBase::calculate_buildcaps, this, _1)); |
1163 | - |
1164 | // Recalc whole map for changed owner stuff |
1165 | egbase().mutable_map()->recalc_whole_map(egbase().world()); |
1166 | |
1167 | |
1168 | === modified file 'src/wui/interactive_gamebase.h' |
1169 | --- src/wui/interactive_gamebase.h 2017-08-28 07:39:59 +0000 |
1170 | +++ src/wui/interactive_gamebase.h 2017-09-13 18:51:31 +0000 |
1171 | @@ -97,7 +97,6 @@ |
1172 | |
1173 | protected: |
1174 | void draw_overlay(RenderTarget&) override; |
1175 | - virtual int32_t calculate_buildcaps(const Widelands::FCoords& c) = 0; |
1176 | |
1177 | GameMainMenuWindows main_windows_; |
1178 | ChatProvider* chat_provider_; |
1179 | |
1180 | === modified file 'src/wui/interactive_player.cc' |
1181 | --- src/wui/interactive_player.cc 2017-09-11 08:22:25 +0000 |
1182 | +++ src/wui/interactive_player.cc 2017-09-13 18:51:31 +0000 |
1183 | @@ -389,9 +389,13 @@ |
1184 | } |
1185 | } |
1186 | |
1187 | - // TODO(sirver): Do not use the field_overlay_manager, instead draw the |
1188 | - // overlays we are interested in here directly. |
1189 | - field_overlay_manager().foreach_overlay(f->fcoords, blit_overlay); |
1190 | + // Draw build help. |
1191 | + if (buildhelp()) { |
1192 | + const auto* overlay = get_buildhelp_overlay(plr.get_buildcaps(f->fcoords)); |
1193 | + if (overlay != nullptr) { |
1194 | + blit_overlay(overlay->pic, overlay->hotspot); |
1195 | + } |
1196 | + } |
1197 | |
1198 | // Blit the selection marker. |
1199 | if (f->fcoords == get_sel_pos().node) { |
1200 | @@ -425,11 +429,6 @@ |
1201 | return player_number_; |
1202 | } |
1203 | |
1204 | -int32_t InteractivePlayer::calculate_buildcaps(const Widelands::FCoords& c) { |
1205 | - assert(get_player()); |
1206 | - return get_player()->get_buildcaps(c); |
1207 | -} |
1208 | - |
1209 | /// Player has clicked on the given node; bring up the context menu. |
1210 | void InteractivePlayer::node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) { |
1211 | const Map& map = egbase().map(); |
1212 | |
1213 | === modified file 'src/wui/interactive_player.h' |
1214 | --- src/wui/interactive_player.h 2017-08-28 07:39:59 +0000 |
1215 | +++ src/wui/interactive_player.h 2017-09-13 18:51:31 +0000 |
1216 | @@ -78,7 +78,6 @@ |
1217 | } |
1218 | |
1219 | void popup_message(Widelands::MessageId, const Widelands::Message&); |
1220 | - int32_t calculate_buildcaps(const Widelands::FCoords& c) override; |
1221 | |
1222 | private: |
1223 | void cmdSwitchPlayer(const std::vector<std::string>& args); |
1224 | |
1225 | === modified file 'src/wui/interactive_spectator.cc' |
1226 | --- src/wui/interactive_spectator.cc 2017-09-01 13:26:55 +0000 |
1227 | +++ src/wui/interactive_spectator.cc 2017-09-13 18:51:31 +0000 |
1228 | @@ -117,27 +117,27 @@ |
1229 | assert(get_sel_radius() == 0); |
1230 | assert(!get_sel_triangles()); |
1231 | |
1232 | - const auto& gbase = egbase(); |
1233 | - auto* fields_to_draw = given_map_view->draw_terrain(gbase, dst); |
1234 | + const Widelands::Game& the_game = game(); |
1235 | + const Widelands::Map& map = the_game.map(); |
1236 | + auto* fields_to_draw = given_map_view->draw_terrain(the_game, dst); |
1237 | const float scale = 1.f / given_map_view->view().zoom; |
1238 | - const uint32_t gametime = gbase.get_gametime(); |
1239 | + const uint32_t gametime = the_game.get_gametime(); |
1240 | |
1241 | const auto text_to_draw = get_text_to_draw(); |
1242 | - const std::map<Widelands::Coords, const Image*> work_area_overlays = |
1243 | - get_work_area_overlays(gbase.map()); |
1244 | + const std::map<Widelands::Coords, const Image*> work_area_overlays = get_work_area_overlays(map); |
1245 | for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) { |
1246 | const FieldsToDraw::Field& field = fields_to_draw->at(idx); |
1247 | |
1248 | draw_border_markers(field, scale, *fields_to_draw, dst); |
1249 | |
1250 | Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable(); |
1251 | - if (imm != nullptr && imm->get_positions(gbase).front() == field.fcoords) { |
1252 | + if (imm != nullptr && imm->get_positions(the_game).front() == field.fcoords) { |
1253 | imm->draw(gametime, text_to_draw, field.rendertarget_pixel, scale, dst); |
1254 | } |
1255 | |
1256 | for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob; |
1257 | bob = bob->get_next_bob()) { |
1258 | - bob->draw(gbase, text_to_draw, field.rendertarget_pixel, scale, dst); |
1259 | + bob->draw(the_game, text_to_draw, field.rendertarget_pixel, scale, dst); |
1260 | } |
1261 | |
1262 | const auto blit_overlay = [dst, &field, scale](const Image* pic, const Vector2i& hotspot) { |
1263 | @@ -147,15 +147,29 @@ |
1264 | BlendMode::UseAlpha); |
1265 | }; |
1266 | |
1267 | + // Draw work area previews. |
1268 | const auto it = work_area_overlays.find(field.fcoords); |
1269 | if (it != work_area_overlays.end()) { |
1270 | const Image* pic = it->second; |
1271 | blit_overlay(pic, Vector2i(pic->width() / 2, pic->height() / 2)); |
1272 | } |
1273 | |
1274 | - // TODO(sirver): Do not use the field_overlay_manager, instead draw the |
1275 | - // overlays we are interested in here directly. |
1276 | - field_overlay_manager().foreach_overlay(field.fcoords, blit_overlay); |
1277 | + // Draw build help. |
1278 | + if (buildhelp()) { |
1279 | + auto caps = Widelands::NodeCaps::CAPS_NONE; |
1280 | + const Widelands::PlayerNumber nr_players = map.get_nrplayers(); |
1281 | + iterate_players_existing(p, nr_players, the_game, player) { |
1282 | + const Widelands::NodeCaps nc = player->get_buildcaps(field.fcoords); |
1283 | + if (nc > Widelands::NodeCaps::CAPS_NONE) { |
1284 | + caps = nc; |
1285 | + break; |
1286 | + } |
1287 | + } |
1288 | + const auto* overlay = get_buildhelp_overlay(caps); |
1289 | + if (overlay != nullptr) { |
1290 | + blit_overlay(overlay->pic, overlay->hotspot); |
1291 | + } |
1292 | + } |
1293 | |
1294 | // Blit the selection marker. |
1295 | if (field.fcoords == get_sel_pos().node) { |
1296 | @@ -175,17 +189,6 @@ |
1297 | return nullptr; |
1298 | } |
1299 | |
1300 | -int32_t InteractiveSpectator::calculate_buildcaps(const Widelands::FCoords& c) { |
1301 | - const Widelands::PlayerNumber nr_players = game().map().get_nrplayers(); |
1302 | - iterate_players_existing(p, nr_players, game(), player) { |
1303 | - const Widelands::NodeCaps nc = player->get_buildcaps(c); |
1304 | - if (nc > Widelands::NodeCaps::CAPS_NONE) { |
1305 | - return nc; |
1306 | - } |
1307 | - } |
1308 | - return Widelands::NodeCaps::CAPS_NONE; |
1309 | -} |
1310 | - |
1311 | // Toolbar button callback functions. |
1312 | void InteractiveSpectator::exit_btn() { |
1313 | if (is_multiplayer()) { |
1314 | |
1315 | === modified file 'src/wui/interactive_spectator.h' |
1316 | --- src/wui/interactive_spectator.h 2017-08-28 07:39:59 +0000 |
1317 | +++ src/wui/interactive_spectator.h 2017-09-13 18:51:31 +0000 |
1318 | @@ -48,7 +48,6 @@ |
1319 | |
1320 | private: |
1321 | void exit_btn(); |
1322 | - int32_t calculate_buildcaps(const Widelands::FCoords& c) override; |
1323 | bool can_see(Widelands::PlayerNumber) const override; |
1324 | bool can_act(Widelands::PlayerNumber) const override; |
1325 | Widelands::PlayerNumber player_number() const override; |
This is the last refactoring branch in the pipeline for now. This is a refactoring that decreases coupling and makes the clearer in many places.
It also makes overlay bugs less likely since overlays no longer need to be registered, they are just drawn as the current state of the playing field is.