Merge lp:~widelands-dev/widelands/kill_overlay_manager into lp:widelands

Proposed by SirVer
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
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.

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

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.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2665. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/274941928.
Appveyor build 2486. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_kill_overlay_manager-2486.

Revision history for this message
kaputtnik (franku) wrote :

When compiling this branch:

.../kill_overlay_manager/src/editor/tools/set_port_space_tool.cc:42: Trailing whitespace at end of line
.../kill_overlay_manager/src/editor/tools/set_starting_pos_tool.cc:58: Trailing whitespace at end of line

All is working imho. In Editor i tested overlays, playing starting positions, resources and ports.

In an older save game tested the buildhelp.

review: Approve (testing)
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2666. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/275173267.
Appveyor build 2487. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_kill_overlay_manager-2487.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Goodbye, you won't be missed :)

@bunnybot merge

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/editor/CMakeLists.txt'
--- src/editor/CMakeLists.txt 2017-08-17 13:37:32 +0000
+++ src/editor/CMakeLists.txt 2017-09-13 18:51:31 +0000
@@ -108,6 +108,5 @@
108 ui_basic108 ui_basic
109 wui109 wui
110 wui_common110 wui_common
111 wui_field_overlay_manager
112 wui_mapview_pixelfunctions111 wui_mapview_pixelfunctions
113)112)
114113
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc 2017-09-10 18:17:55 +0000
+++ src/editor/editorinteractive.cc 2017-09-13 18:51:31 +0000
@@ -51,7 +51,6 @@
51#include "scripting/lua_table.h"51#include "scripting/lua_table.h"
52#include "ui_basic/messagebox.h"52#include "ui_basic/messagebox.h"
53#include "ui_basic/progresswindow.h"53#include "ui_basic/progresswindow.h"
54#include "wui/field_overlay_manager.h"
55#include "wui/game_tips.h"54#include "wui/game_tips.h"
56#include "wui/interactive_base.h"55#include "wui/interactive_base.h"
5756
@@ -190,9 +189,6 @@
190 // TODO(unknown): get rid of cleanup_for_load, it tends to be very messy189 // TODO(unknown): get rid of cleanup_for_load, it tends to be very messy
191 // Instead, delete and re-create the egbase.190 // Instead, delete and re-create the egbase.
192 egbase().cleanup_for_load();191 egbase().cleanup_for_load();
193
194 // Select a tool that doesn't care about map changes
195 mutable_field_overlay_manager()->register_overlay_callback_function(nullptr);
196}192}
197193
198/// Called just before the editor starts, after postload, init and gfxload.194/// Called just before the editor starts, after postload, init and gfxload.
@@ -331,9 +327,14 @@
331 }327 }
332 }328 }
333329
334 // TODO(sirver): Do not use the field_overlay_manager, instead draw the330 // Draw build help.
335 // overlays we are interested in here directly.331 if (buildhelp()) {
336 field_overlay_manager().foreach_overlay(field.fcoords, blit_overlay);332 const auto* overlay =
333 get_buildhelp_overlay(tools_->current().nodecaps_for_buildhelp(field.fcoords, ebase));
334 if (overlay != nullptr) {
335 blit_overlay(overlay->pic, overlay->hotspot);
336 }
337 }
337338
338 // Draw the player starting position overlays.339 // Draw the player starting position overlays.
339 const auto it = starting_positions.find(field.fcoords);340 const auto it = starting_positions.find(field.fcoords);
@@ -589,9 +590,6 @@
589 toolsize_menu.update(toolsize_menu.value());590 toolsize_menu.update(toolsize_menu.value());
590 }591 }
591 }592 }
592 // A new tool has been selected. Remove all registered overlay callback
593 // functions.
594 mutable_field_overlay_manager()->register_overlay_callback_function(nullptr);
595 egbase().mutable_map()->recalc_whole_map(egbase().world());593 egbase().mutable_map()->recalc_whole_map(egbase().world());
596 }594 }
597 tools_->current_pointer = &primary;595 tools_->current_pointer = &primary;
@@ -680,8 +678,6 @@
680 case MapWas::kGloballyMutated:678 case MapWas::kGloballyMutated:
681 break;679 break;
682 }680 }
683
684 mutable_field_overlay_manager()->remove_all_overlays();
685}681}
686682
687EditorInteractive::Tools* EditorInteractive::tools() {683EditorInteractive::Tools* EditorInteractive::tools() {
688684
=== modified file 'src/editor/tools/decrease_resources_tool.h'
--- src/editor/tools/decrease_resources_tool.h 2017-01-25 18:55:59 +0000
+++ src/editor/tools/decrease_resources_tool.h 2017-09-13 18:51:31 +0000
@@ -20,6 +20,7 @@
20#ifndef WL_EDITOR_TOOLS_DECREASE_RESOURCES_TOOL_H20#ifndef WL_EDITOR_TOOLS_DECREASE_RESOURCES_TOOL_H
21#define WL_EDITOR_TOOLS_DECREASE_RESOURCES_TOOL_H21#define WL_EDITOR_TOOLS_DECREASE_RESOURCES_TOOL_H
2222
23#include "editor/tools/set_resources_tool.h"
23#include "editor/tools/tool.h"24#include "editor/tools/tool.h"
2425
25/// Decreases the resources of a node by a value.26/// Decreases the resources of a node by a value.
@@ -45,6 +46,11 @@
45 return g_gr->images().get("images/wui/editor/fsel_editor_decrease_resources.png");46 return g_gr->images().get("images/wui/editor/fsel_editor_decrease_resources.png");
46 }47 }
4748
49 Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
50 const Widelands::EditorGameBase& egbase) override {
51 return resource_tools_nodecaps(fcoords, egbase, cur_res_);
52 }
53
48 int32_t get_change_by() const {54 int32_t get_change_by() const {
49 return change_by_;55 return change_by_;
50 }56 }
5157
=== modified file 'src/editor/tools/increase_resources_tool.h'
--- src/editor/tools/increase_resources_tool.h 2017-01-25 18:55:59 +0000
+++ src/editor/tools/increase_resources_tool.h 2017-09-13 18:51:31 +0000
@@ -57,6 +57,11 @@
57 return g_gr->images().get("images/wui/editor/fsel_editor_increase_resources.png");57 return g_gr->images().get("images/wui/editor/fsel_editor_increase_resources.png");
58 }58 }
5959
60 Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
61 const Widelands::EditorGameBase& egbase) override {
62 return resource_tools_nodecaps(fcoords, egbase, cur_res_);
63 }
64
60 int32_t get_change_by() const {65 int32_t get_change_by() const {
61 return change_by_;66 return change_by_;
62 }67 }
6368
=== modified file 'src/editor/tools/set_port_space_tool.cc'
--- src/editor/tools/set_port_space_tool.cc 2017-08-13 18:02:53 +0000
+++ src/editor/tools/set_port_space_tool.cc 2017-09-13 18:51:31 +0000
@@ -28,16 +28,19 @@
2828
29using namespace Widelands;29using namespace Widelands;
3030
31/// static callback function for overlay calculation31namespace {
32int32_t editor_tool_set_port_space_callback(const Widelands::FCoords& c, const Map& map) {32
33Widelands::NodeCaps port_tool_nodecaps(const Widelands::FCoords& c, const Map& map) {
33 NodeCaps const caps = c.field->nodecaps();34 NodeCaps const caps = c.field->nodecaps();
34 if ((caps & BUILDCAPS_SIZEMASK) == BUILDCAPS_BIG) {35 if ((caps & BUILDCAPS_SIZEMASK) == BUILDCAPS_BIG) {
35 if (!map.find_portdock(c).empty())36 if (!map.find_portdock(c).empty())
36 return caps;37 return caps;
37 }38 }
38 return 0;39 return NodeCaps::CAPS_NONE;
39}40}
4041
42} // namespace
43
41EditorSetPortSpaceTool::EditorSetPortSpaceTool(EditorUnsetPortSpaceTool& the_unset_tool)44EditorSetPortSpaceTool::EditorSetPortSpaceTool(EditorUnsetPortSpaceTool& the_unset_tool)
42 : EditorTool(the_unset_tool, the_unset_tool) {45 : EditorTool(the_unset_tool, the_unset_tool) {
43}46}
@@ -61,7 +64,7 @@
61 *map, Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius));64 *map, Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius));
62 do {65 do {
63 // check if field is valid66 // check if field is valid
64 if (editor_tool_set_port_space_callback(mr.location(), *map)) {67 if (port_tool_nodecaps(mr.location(), *map) != NodeCaps::CAPS_NONE) {
65 map->set_port_space(mr.location(), true);68 map->set_port_space(mr.location(), true);
66 Area<FCoords> a(mr.location(), 0);69 Area<FCoords> a(mr.location(), 0);
67 map->recalc_for_field_area(world, a);70 map->recalc_for_field_area(world, a);
@@ -72,6 +75,12 @@
72 return nr;75 return nr;
73}76}
7477
78Widelands::NodeCaps
79EditorSetPortSpaceTool::nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
80 const Widelands::EditorGameBase& egbase) {
81 return port_tool_nodecaps(fcoords, egbase.map());
82}
83
75int32_t EditorSetPortSpaceTool::handle_undo_impl(const Widelands::World& world,84int32_t EditorSetPortSpaceTool::handle_undo_impl(const Widelands::World& world,
76 const NodeAndTriangle<Coords>& center,85 const NodeAndTriangle<Coords>& center,
77 EditorInteractive& parent,86 EditorInteractive& parent,
@@ -96,7 +105,7 @@
96 *map, Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius));105 *map, Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius));
97 do {106 do {
98 // check if field is valid107 // check if field is valid
99 if (editor_tool_set_port_space_callback(mr.location(), *map)) {108 if (port_tool_nodecaps(mr.location(), *map)) {
100 map->set_port_space(mr.location(), false);109 map->set_port_space(mr.location(), false);
101 Area<FCoords> a(mr.location(), 0);110 Area<FCoords> a(mr.location(), 0);
102 map->recalc_for_field_area(world, a);111 map->recalc_for_field_area(world, a);
@@ -114,3 +123,9 @@
114 Map* map) {123 Map* map) {
115 return parent.tools()->set_port_space.handle_click_impl(world, center, parent, args, map);124 return parent.tools()->set_port_space.handle_click_impl(world, center, parent, args, map);
116}125}
126
127Widelands::NodeCaps
128EditorUnsetPortSpaceTool::nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
129 const Widelands::EditorGameBase& egbase) {
130 return port_tool_nodecaps(fcoords, egbase.map());
131}
117132
=== modified file 'src/editor/tools/set_port_space_tool.h'
--- src/editor/tools/set_port_space_tool.h 2017-08-13 18:02:53 +0000
+++ src/editor/tools/set_port_space_tool.h 2017-09-13 18:51:31 +0000
@@ -46,6 +46,8 @@
46 const Image* get_sel_impl() const override {46 const Image* get_sel_impl() const override {
47 return g_gr->images().get(FSEL_EUPS_FILENAME);47 return g_gr->images().get(FSEL_EUPS_FILENAME);
48 }48 }
49 Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
50 const Widelands::EditorGameBase& egbase) override;
49};51};
5052
51/// Sets a buildspace for ports.53/// Sets a buildspace for ports.
@@ -68,8 +70,8 @@
68 const Image* get_sel_impl() const override {70 const Image* get_sel_impl() const override {
69 return g_gr->images().get(FSEL_ESPS_FILENAME);71 return g_gr->images().get(FSEL_ESPS_FILENAME);
70 }72 }
73 Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
74 const Widelands::EditorGameBase& egbase) override;
71};75};
7276
73int32_t editor_tool_set_port_space_callback(const Widelands::FCoords& c, const Widelands::Map& map);
74
75#endif // end of include guard: WL_EDITOR_TOOLS_SET_PORT_SPACE_TOOL_H77#endif // end of include guard: WL_EDITOR_TOOLS_SET_PORT_SPACE_TOOL_H
7678
=== modified file 'src/editor/tools/set_resources_tool.cc'
--- src/editor/tools/set_resources_tool.cc 2017-01-25 18:55:59 +0000
+++ src/editor/tools/set_resources_tool.cc 2017-09-13 18:51:31 +0000
@@ -85,3 +85,13 @@
85 a.set_to = set_to_;85 a.set_to = set_to_;
86 return a;86 return a;
87}87}
88
89Widelands::NodeCaps resource_tools_nodecaps(const Widelands::FCoords& fcoords,
90 const Widelands::EditorGameBase& egbase,
91 Widelands::DescriptionIndex resource) {
92 if (egbase.map().is_resource_valid(egbase.world(), fcoords, resource)) {
93 return fcoords.field->nodecaps();
94 }
95 return Widelands::NodeCaps::CAPS_NONE;
96}
97
8898
=== modified file 'src/editor/tools/set_resources_tool.h'
--- src/editor/tools/set_resources_tool.h 2017-01-25 18:55:59 +0000
+++ src/editor/tools/set_resources_tool.h 2017-09-13 18:51:31 +0000
@@ -24,6 +24,10 @@
24#include "logic/mapregion.h"24#include "logic/mapregion.h"
25#include "logic/widelands.h"25#include "logic/widelands.h"
2626
27Widelands::NodeCaps resource_tools_nodecaps(const Widelands::FCoords& fcoords,
28 const Widelands::EditorGameBase& egbase,
29 Widelands::DescriptionIndex resource);
30
27/// Decreases the resources of a node by a value.31/// Decreases the resources of a node by a value.
28struct EditorSetResourcesTool : public EditorTool {32struct EditorSetResourcesTool : public EditorTool {
29 EditorSetResourcesTool() : EditorTool(*this, *this), cur_res_(0), set_to_(0) {33 EditorSetResourcesTool() : EditorTool(*this, *this), cur_res_(0), set_to_(0) {
@@ -50,6 +54,11 @@
50 return g_gr->images().get("images/wui/editor/fsel_editor_set_resources.png");54 return g_gr->images().get("images/wui/editor/fsel_editor_set_resources.png");
51 }55 }
5256
57 Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
58 const Widelands::EditorGameBase& egbase) override {
59 return resource_tools_nodecaps(fcoords, egbase, cur_res_);
60 }
61
53 Widelands::ResourceAmount get_set_to() const {62 Widelands::ResourceAmount get_set_to() const {
54 return set_to_;63 return set_to_;
55 }64 }
5665
=== modified file 'src/editor/tools/set_starting_pos_tool.cc'
--- src/editor/tools/set_starting_pos_tool.cc 2017-08-28 12:58:24 +0000
+++ src/editor/tools/set_starting_pos_tool.cc 2017-09-13 18:51:31 +0000
@@ -28,17 +28,17 @@
28// global variable to pass data from callback to class28// global variable to pass data from callback to class
29static int32_t current_player_;29static int32_t current_player_;
3030
31/*31namespace {
32 * static callback function for overlay calculation32
33 */33Widelands::NodeCaps set_starting_pos_tool_nodecaps(const Widelands::FCoords& c,
34int32_t editor_tool_set_starting_pos_callback(const Widelands::FCoords& c, Widelands::Map& map) {34 const Widelands::Map& map) {
35 // Area around already placed players35 // Area around already placed players
36 Widelands::PlayerNumber const nr_players = map.get_nrplayers();36 Widelands::PlayerNumber const nr_players = map.get_nrplayers();
37 for (Widelands::PlayerNumber p = 1, last = current_player_ - 1;; ++p) {37 for (Widelands::PlayerNumber p = 1, last = current_player_ - 1;; ++p) {
38 for (; p <= last; ++p) {38 for (; p <= last; ++p) {
39 if (Widelands::Coords const sp = map.get_starting_pos(p)) {39 if (Widelands::Coords const sp = map.get_starting_pos(p)) {
40 if (map.calc_distance(sp, c) < MIN_PLACE_AROUND_PLAYERS) {40 if (map.calc_distance(sp, c) < MIN_PLACE_AROUND_PLAYERS) {
41 return 0;41 return Widelands::NodeCaps::CAPS_NONE;
42 }42 }
43 }43 }
44 }44 }
@@ -52,9 +52,11 @@
52 if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_BIG)52 if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_BIG)
53 return caps;53 return caps;
5454
55 return 0;55 return Widelands::NodeCaps::CAPS_NONE;
56}56}
5757
58} // namespace
59
58EditorSetStartingPosTool::EditorSetStartingPosTool() : EditorTool(*this, *this, false) {60EditorSetStartingPosTool::EditorSetStartingPosTool() : EditorTool(*this, *this, false) {
59 current_player_ = 1;61 current_player_ = 1;
60}62}
@@ -78,13 +80,20 @@
78 }80 }
7981
80 // check if field is valid82 // check if field is valid
81 if (editor_tool_set_starting_pos_callback(map->get_fcoords(center.node), *map)) {83 if (set_starting_pos_tool_nodecaps(map->get_fcoords(center.node), *map) !=
84 Widelands::NodeCaps::CAPS_NONE) {
82 map->set_starting_pos(current_player_, center.node);85 map->set_starting_pos(current_player_, center.node);
83 }86 }
84 }87 }
85 return 1;88 return 1;
86}89}
8790
91Widelands::NodeCaps
92EditorSetStartingPosTool::nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
93 const Widelands::EditorGameBase& egbase) {
94 return set_starting_pos_tool_nodecaps(fcoords, egbase.map());
95}
96
88Widelands::PlayerNumber EditorSetStartingPosTool::get_current_player() const {97Widelands::PlayerNumber EditorSetStartingPosTool::get_current_player() const {
89 return current_player_;98 return current_player_;
90}99}
91100
=== modified file 'src/editor/tools/set_starting_pos_tool.h'
--- src/editor/tools/set_starting_pos_tool.h 2017-08-28 12:41:15 +0000
+++ src/editor/tools/set_starting_pos_tool.h 2017-09-13 18:51:31 +0000
@@ -25,7 +25,6 @@
25#include "editor/tools/tool.h"25#include "editor/tools/tool.h"
26#include "graphic/playercolor.h"26#include "graphic/playercolor.h"
27#include "logic/widelands.h"27#include "logic/widelands.h"
28#include "wui/field_overlay_manager.h"
2928
30// How much place should be left around a player position29// How much place should be left around a player position
31// where no other player can start30// where no other player can start
@@ -49,8 +48,8 @@
49 bool has_size_one() const override {48 bool has_size_one() const override {
50 return true;49 return true;
51 }50 }
51 Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
52 const Widelands::EditorGameBase&) override;
52};53};
5354
54int32_t editor_tool_set_starting_pos_callback(const Widelands::FCoords& c, Widelands::Map& map);
55
56#endif // end of include guard: WL_EDITOR_TOOLS_SET_STARTING_POS_TOOL_H55#endif // end of include guard: WL_EDITOR_TOOLS_SET_STARTING_POS_TOOL_H
5756
=== modified file 'src/editor/tools/tool.h'
--- src/editor/tools/tool.h 2017-01-25 18:55:59 +0000
+++ src/editor/tools/tool.h 2017-09-13 18:51:31 +0000
@@ -26,6 +26,7 @@
26#include "editor/tools/action_args.h"26#include "editor/tools/action_args.h"
27#include "graphic/graphic.h"27#include "graphic/graphic.h"
28#include "graphic/image.h"28#include "graphic/image.h"
29#include "logic/editor_game_base.h"
29#include "logic/widelands_geometry.h"30#include "logic/widelands_geometry.h"
3031
31class EditorInteractive;32class EditorInteractive;
@@ -99,6 +100,14 @@
99 return 0;100 return 0;
100 } // non unduable tools don't need to implement this.101 } // non unduable tools don't need to implement this.
101 virtual const Image* get_sel_impl() const = 0;102 virtual const Image* get_sel_impl() const = 0;
103
104 // Gives the tool the chance to modify the nodecaps to change what will be
105 // displayed as build help.
106 virtual Widelands::NodeCaps nodecaps_for_buildhelp(const Widelands::FCoords& fcoords,
107 const Widelands::EditorGameBase&) {
108 return fcoords.field->nodecaps();
109 }
110
102 virtual bool operates_on_triangles() const {111 virtual bool operates_on_triangles() const {
103 return false;112 return false;
104 }113 }
105114
=== modified file 'src/editor/ui_menus/player_menu.cc'
--- src/editor/ui_menus/player_menu.cc 2017-09-01 00:16:04 +0000
+++ src/editor/ui_menus/player_menu.cc 2017-09-13 18:51:31 +0000
@@ -33,7 +33,6 @@
33#include "ui_basic/editbox.h"33#include "ui_basic/editbox.h"
34#include "ui_basic/messagebox.h"34#include "ui_basic/messagebox.h"
35#include "ui_basic/textarea.h"35#include "ui_basic/textarea.h"
36#include "wui/field_overlay_manager.h"
3736
38#define UNDEFINED_TRIBE_NAME "<undefined>"37#define UNDEFINED_TRIBE_NAME "<undefined>"
3938
@@ -220,13 +219,6 @@
220 Widelands::PlayerNumber const nr_players = old_nr_players - 1;219 Widelands::PlayerNumber const nr_players = old_nr_players - 1;
221 assert(1 <= nr_players);220 assert(1 <= nr_players);
222221
223 if (const Widelands::Coords sp = map->get_starting_pos(old_nr_players)) {
224 // Remove starting position marker.
225 const Image* player_image =
226 playercolor_image(old_nr_players - 1, "images/players/player_position.png");
227 assert(player_image);
228 menu.mutable_field_overlay_manager()->remove_overlay(sp, player_image);
229 }
230 // if removed player was selected switch to the next highest player222 // if removed player was selected switch to the next highest player
231 if (old_nr_players == menu.tools()->set_starting_pos.get_current_player()) {223 if (old_nr_players == menu.tools()->set_starting_pos.get_current_player()) {
232 set_starting_pos_clicked(nr_players);224 set_starting_pos_clicked(nr_players);
@@ -275,12 +267,6 @@
275267
276 // reselect tool, so everything is in a defined state268 // reselect tool, so everything is in a defined state
277 menu.select_tool(menu.tools()->current(), EditorTool::First);269 menu.select_tool(menu.tools()->current(), EditorTool::First);
278
279 // Register callback function to make sure that only valid locations are
280 // selected.
281 menu.mutable_field_overlay_manager()->register_overlay_callback_function(
282 boost::bind(&editor_tool_set_starting_pos_callback, _1, boost::ref(*map)));
283 map->recalc_whole_map(menu.egbase().world());
284 update();270 update();
285}271}
286272
287273
=== modified file 'src/editor/ui_menus/tool_change_resources_options_menu.cc'
--- src/editor/ui_menus/tool_change_resources_options_menu.cc 2017-08-19 22:22:20 +0000
+++ src/editor/ui_menus/tool_change_resources_options_menu.cc 2017-09-13 18:51:31 +0000
@@ -35,7 +35,6 @@
35#include "logic/map_objects/world/world.h"35#include "logic/map_objects/world/world.h"
36#include "logic/widelands.h"36#include "logic/widelands.h"
37#include "logic/widelands_geometry.h"37#include "logic/widelands_geometry.h"
38#include "wui/field_overlay_manager.h"
3938
40constexpr int kMaxValue = 63;39constexpr int kMaxValue = 63;
4140
@@ -153,17 +152,6 @@
153 increase_tool_.set_cur_res(resource_index);152 increase_tool_.set_cur_res(resource_index);
154 increase_tool_.decrease_tool().set_cur_res(resource_index);153 increase_tool_.decrease_tool().set_cur_res(resource_index);
155154
156 Widelands::EditorGameBase& egbase = eia().egbase();
157 Widelands::Map* map = egbase.mutable_map();
158 eia().mutable_field_overlay_manager()->register_overlay_callback_function(
159 [resource_index, map, &egbase](const Widelands::FCoords& fc) -> uint32_t {
160 if (map->is_resource_valid(egbase.world(), fc, resource_index)) {
161 return fc.field->nodecaps();
162 }
163 return 0;
164 });
165
166 map->recalc_whole_map(egbase.world());
167 select_correct_tool();155 select_correct_tool();
168 update();156 update();
169}157}
170158
=== modified file 'src/editor/ui_menus/tool_menu.cc'
--- src/editor/ui_menus/tool_menu.cc 2017-08-19 22:22:20 +0000
+++ src/editor/ui_menus/tool_menu.cc 2017-09-13 18:51:31 +0000
@@ -140,13 +140,6 @@
140 }140 }
141141
142 parent.select_tool(*current_tool_pointer, EditorTool::First);142 parent.select_tool(*current_tool_pointer, EditorTool::First);
143 if (current_tool_pointer == &parent.tools()->set_port_space) {
144 // Set correct overlay
145 Widelands::Map* map = parent.egbase().mutable_map();
146 parent.mutable_field_overlay_manager()->register_overlay_callback_function(
147 boost::bind(&editor_tool_set_port_space_callback, _1, boost::ref(*map)));
148 map->recalc_whole_map(parent.egbase().world());
149 }
150143
151 if (current_registry_pointer) {144 if (current_registry_pointer) {
152 if (UI::Window* const window = current_registry_pointer->window) {145 if (UI::Window* const window = current_registry_pointer->window) {
153146
=== modified file 'src/graphic/CMakeLists.txt'
--- src/graphic/CMakeLists.txt 2017-08-28 08:33:02 +0000
+++ src/graphic/CMakeLists.txt 2017-09-13 18:51:31 +0000
@@ -184,7 +184,6 @@
184 graphic_surface184 graphic_surface
185 logic185 logic
186 wui186 wui
187 wui_field_overlay_manager
188 wui_mapview_pixelfunctions187 wui_mapview_pixelfunctions
189)188)
190189
191190
=== modified file 'src/graphic/game_renderer.cc'
--- src/graphic/game_renderer.cc 2017-08-29 10:48:24 +0000
+++ src/graphic/game_renderer.cc 2017-09-13 18:51:31 +0000
@@ -29,7 +29,6 @@
29#include "logic/editor_game_base.h"29#include "logic/editor_game_base.h"
30#include "logic/map_objects/world/world.h"30#include "logic/map_objects/world/world.h"
31#include "logic/player.h"31#include "logic/player.h"
32#include "wui/field_overlay_manager.h"
33#include "wui/interactive_base.h"32#include "wui/interactive_base.h"
34#include "wui/mapviewpixelconstants.h"33#include "wui/mapviewpixelconstants.h"
35#include "wui/mapviewpixelfunctions.h"34#include "wui/mapviewpixelfunctions.h"
3635
=== modified file 'src/logic/map.cc'
--- src/logic/map.cc 2017-09-03 09:36:11 +0000
+++ src/logic/map.cc 2017-09-13 18:51:31 +0000
@@ -1770,7 +1770,7 @@
17701770
1771bool Map::is_resource_valid(const Widelands::World& world,1771bool Map::is_resource_valid(const Widelands::World& world,
1772 const Widelands::FCoords& c,1772 const Widelands::FCoords& c,
1773 DescriptionIndex curres) {1773 DescriptionIndex curres) const {
1774 if (curres == Widelands::kNoResource)1774 if (curres == Widelands::kNoResource)
1775 return true;1775 return true;
17761776
17771777
=== modified file 'src/logic/map.h'
--- src/logic/map.h 2017-08-31 10:55:45 +0000
+++ src/logic/map.h 2017-09-13 18:51:31 +0000
@@ -428,7 +428,7 @@
428 */428 */
429 bool is_resource_valid(const Widelands::World& world,429 bool is_resource_valid(const Widelands::World& world,
430 const Widelands::FCoords& c,430 const Widelands::FCoords& c,
431 DescriptionIndex curres);431 DescriptionIndex curres) const;
432432
433 // The objectives that are defined in this map if it is a scenario.433 // The objectives that are defined in this map if it is a scenario.
434 const Objectives& objectives() const {434 const Objectives& objectives() const {
435435
=== modified file 'src/wui/CMakeLists.txt'
--- src/wui/CMakeLists.txt 2017-09-04 05:08:56 +0000
+++ src/wui/CMakeLists.txt 2017-09-13 18:51:31 +0000
@@ -24,17 +24,6 @@
24 wui24 wui
25)25)
2626
27wl_library(wui_field_overlay_manager
28 SRCS
29 field_overlay_manager.cc
30 field_overlay_manager.h
31 DEPENDS
32 base_geometry
33 graphic
34 logic
35 logic_widelands_geometry
36)
37
38wl_library(wui_economy_options27wl_library(wui_economy_options
39 SRCS28 SRCS
40 economy_options_window.cc29 economy_options_window.cc
@@ -265,7 +254,6 @@
265 ui_basic254 ui_basic
266 wui_chat_ui255 wui_chat_ui
267 wui_economy_options256 wui_economy_options
268 wui_field_overlay_manager
269 wui_mapview257 wui_mapview
270 wui_mapview_pixelfunctions258 wui_mapview_pixelfunctions
271 wui_quicknavigation259 wui_quicknavigation
272260
=== modified file 'src/wui/buildingwindow.h'
--- src/wui/buildingwindow.h 2017-09-01 09:18:10 +0000
+++ src/wui/buildingwindow.h 2017-09-13 18:51:31 +0000
@@ -28,7 +28,6 @@
28#include "notifications/notifications.h"28#include "notifications/notifications.h"
29#include "ui_basic/button.h"29#include "ui_basic/button.h"
30#include "ui_basic/unique_window.h"30#include "ui_basic/unique_window.h"
31#include "wui/field_overlay_manager.h"
32#include "wui/interactive_gamebase.h"31#include "wui/interactive_gamebase.h"
33#include "wui/waresdisplay.h"32#include "wui/waresdisplay.h"
3433
3534
=== removed file 'src/wui/field_overlay_manager.cc'
--- src/wui/field_overlay_manager.cc 2017-08-16 05:10:15 +0000
+++ src/wui/field_overlay_manager.cc 1970-01-01 00:00:00 +0000
@@ -1,181 +0,0 @@
1/*
2 * Copyright (C) 2002-2017 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19
20#include "wui/field_overlay_manager.h"
21
22#include <algorithm>
23
24#include <stdint.h>
25
26#include "graphic/graphic.h"
27#include "logic/field.h"
28
29FieldOverlayManager::FieldOverlayManager() : buildhelp_(false), current_overlay_id_(0) {
30 OverlayInfo* buildhelp_info = buildhelp_infos_;
31 const char* filenames[] = {"images/wui/overlays/set_flag.png", "images/wui/overlays/small.png",
32 "images/wui/overlays/medium.png", "images/wui/overlays/big.png",
33 "images/wui/overlays/mine.png", "images/wui/overlays/port.png"};
34 const char* const* filename = filenames;
35
36 // Special case for flag, which has a different formula for hotspot_y.
37 buildhelp_info->pic = g_gr->images().get(*filename);
38 buildhelp_info->hotspot =
39 Vector2i(buildhelp_info->pic->width() / 2, buildhelp_info->pic->height() - 1);
40
41 const OverlayInfo* const buildhelp_infos_end = buildhelp_info + Widelands::Field::Buildhelp_None;
42 for (;;) { // The other buildhelp overlays.
43 ++buildhelp_info;
44 ++filename;
45 if (buildhelp_info == buildhelp_infos_end)
46 break;
47 buildhelp_info->pic = g_gr->images().get(*filename);
48 buildhelp_info->hotspot =
49 Vector2i(buildhelp_info->pic->width() / 2, buildhelp_info->pic->height() / 2);
50 }
51}
52
53bool FieldOverlayManager::buildhelp() const {
54 return buildhelp_;
55}
56
57void FieldOverlayManager::show_buildhelp(const bool value) {
58 buildhelp_ = value;
59}
60
61int FieldOverlayManager::get_buildhelp_overlay(const Widelands::FCoords& fc) const {
62 Widelands::NodeCaps const caps =
63 callback_ ? static_cast<Widelands::NodeCaps>(callback_(fc)) : fc.field->nodecaps();
64
65 if (caps & Widelands::BUILDCAPS_MINE) {
66 return Widelands::Field::Buildhelp_Mine;
67 }
68 if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_BIG) {
69 if (caps & Widelands::BUILDCAPS_PORT) {
70 return Widelands::Field::Buildhelp_Port;
71 }
72 return Widelands::Field::Buildhelp_Big;
73 }
74 if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_MEDIUM) {
75 return Widelands::Field::Buildhelp_Medium;
76 }
77 if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_SMALL) {
78 return Widelands::Field::Buildhelp_Small;
79 }
80 if (caps & Widelands::BUILDCAPS_FLAG) {
81 return Widelands::Field::Buildhelp_Flag;
82 }
83 return Widelands::Field::Buildhelp_None;
84}
85
86void FieldOverlayManager::register_overlay(const Widelands::Coords& c,
87 const Image* pic,
88 const OverlayLevel& level,
89 Vector2i hotspot,
90 OverlayId const overlay_id) {
91 if (hotspot == Vector2i::invalid()) {
92 hotspot = Vector2i(pic->width() / 2, pic->height() / 2);
93 }
94
95 for (auto it = overlays_.find(c); it != overlays_.end() && it->first == c; ++it)
96 if (it->second.pic == pic && it->second.hotspot == hotspot && it->second.level == level) {
97 it->second.overlay_ids.insert(overlay_id);
98 return;
99 }
100
101 overlays_.insert(std::pair<Widelands::Coords const, RegisteredOverlays>(
102 c, RegisteredOverlays(overlay_id, pic, hotspot, level)));
103
104 // Now manually sort, so that they are ordered
105 // * first by c (done by std::multimap)
106 // * second by levels (done manually here)
107
108 // there is at least one registered
109 auto it = overlays_.lower_bound(c);
110 do {
111 auto jt = it;
112 ++jt;
113 if (jt == overlays_.end())
114 break;
115 if (jt->first == it->first) {
116 // There are several overlays registered for this location.
117 if (jt->second.level < it->second.level) {
118 std::swap(it->second, jt->second);
119 it = overlays_.lower_bound(c);
120 } else
121 ++it;
122 } else
123 break; // it is the last element, break this loop.
124 } while (it->first == c);
125}
126
127/**
128 * remove one (or many) overlays from a node or triangle
129 *
130 * @param pic The overlay to remove. If null, all overlays are removed.
131 */
132void FieldOverlayManager::remove_overlay(const Widelands::Coords& c, const Image* pic) {
133 if (overlays_.count(c) == 0) {
134 return;
135 }
136 auto it = overlays_.lower_bound(c);
137 do {
138 if (!pic || it->second.pic == pic) {
139 overlays_.erase(it);
140 it = overlays_.lower_bound(c);
141 } else {
142 ++it;
143 }
144 } while (it != overlays_.end() && it->first == c);
145}
146
147void FieldOverlayManager::remove_overlay(const OverlayId overlay_id) {
148 for (auto it = overlays_.begin(); it != overlays_.end();) {
149 it->second.overlay_ids.erase(overlay_id);
150 if (it->second.overlay_ids.empty()) {
151 overlays_.erase(it++); // This is necessary!
152 } else {
153 ++it;
154 }
155 }
156}
157
158void FieldOverlayManager::remove_all_overlays() {
159 overlays_.clear();
160}
161
162void FieldOverlayManager::register_overlay_callback_function(CallbackFn function) {
163 callback_ = function;
164}
165
166FieldOverlayManager::OverlayId FieldOverlayManager::next_overlay_id() {
167 ++current_overlay_id_;
168 return current_overlay_id_;
169}
170
171bool FieldOverlayManager::is_enabled(const OverlayLevel& level) const {
172 return disabled_layers_.count(level) == 0;
173}
174
175void FieldOverlayManager::set_enabled(const OverlayLevel& level, const bool enabled) {
176 if (enabled) {
177 disabled_layers_.erase(level);
178 } else {
179 disabled_layers_.insert(level);
180 }
181}
1820
=== removed file 'src/wui/field_overlay_manager.h'
--- src/wui/field_overlay_manager.h 2017-09-01 13:26:55 +0000
+++ src/wui/field_overlay_manager.h 1970-01-01 00:00:00 +0000
@@ -1,172 +0,0 @@
1/*
2 * Copyright (C) 2002-2017 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19
20#ifndef WL_WUI_FIELD_OVERLAY_MANAGER_H
21#define WL_WUI_FIELD_OVERLAY_MANAGER_H
22
23#include <functional>
24#include <map>
25#include <set>
26#include <vector>
27
28#include "base/vector.h"
29#include "logic/field.h"
30#include "logic/widelands_geometry.h"
31
32class Image;
33
34/*
35 * The Overlay Manager is responsible for the map overlays. He
36 * manages overlays in the following way:
37 * - When someone registered one (or more) special overlays
38 * for a field he draws them accordingly
39 *
40 * about the level variable:
41 * the level describe when the overlay should be drawn, lower means drawn
42 * earlier.
43 *
44 * about overlay_id:
45 * the overlay_id can be given to the register function, whenever
46 * the job is finished or canceled, a simple remove_overlay
47 * with the overlay_id can be called and all overlays created in the
48 * job are removed.
49 */
50
51// Levels for the overlay registers. This defines in which order they will be
52// drawn. Buildhelp is special and has the value 5, i.e. every smaller will be
53// drawn below the buildhelp, everything higher above.
54// TODO(sirver): no longer used. remove.
55enum class OverlayLevel {};
56
57struct FieldOverlayManager {
58 /// A unique id identifying a registered overlay.
59 using OverlayId = uint32_t;
60
61 /// A function returning Field::nodecaps() for the build overlay. This can be
62 /// registered to hide or change some of the nodecaps during rendering.
63 using CallbackFn = std::function<int32_t(const Widelands::FCoords& coordinates)>;
64
65 FieldOverlayManager();
66
67 /// Returns true if the buildhelp is currently shown.
68 bool buildhelp() const;
69
70 /// Defines if the buildhelp should be shown.
71 void show_buildhelp(bool t);
72
73 /// Register callback function.
74 void register_overlay_callback_function(CallbackFn function);
75
76 /// Like 'buildhelp', but for an individual layer.
77 bool is_enabled(const OverlayLevel& level) const;
78 void set_enabled(const OverlayLevel& level, bool value);
79
80 /// Get a unique, unused id that can be passed to register_overlay.
81 OverlayId next_overlay_id();
82
83 /// Register an overlay at a location (node or triangle). hotspot is the point
84 /// of the picture that will be exactly over the location. If hotspot is
85 /// Vector2i::invalid(), the center of the picture will be used as hotspot.
86 void register_overlay(const Widelands::Coords& coords,
87 const Image* pic,
88 const OverlayLevel& overlay_level,
89 Vector2i hotspot = Vector2i::invalid(),
90 OverlayId overlay_id = 0);
91
92 /// removes all overlays when pic is nullptr.
93 void remove_overlay(const Widelands::Coords& coords, const Image* pic);
94
95 /// remove all overlays with this overlay_id
96 void remove_overlay(OverlayId overlay_id);
97
98 /// Removes all overlays.
99 // TODO(sirver): It would be preferable to just delete and recreate the object.
100 void remove_all_overlays();
101
102 /// Calls 'func' for each of the the currently registered and enabled
103 /// overlays and the buildhelp.
104 template <typename T> void foreach_overlay(const Widelands::FCoords& c, T func) const {
105 auto it = overlays_.lower_bound(c);
106 while (it != overlays_.end() && it->first == c &&
107 static_cast<int>(it->second.level) <= kLevelForBuildHelp) {
108 if (is_enabled(it->second.level)) {
109 func(it->second.pic, it->second.hotspot);
110 }
111 ++it;
112 }
113
114 if (buildhelp_) {
115 int buildhelp_overlay_index = get_buildhelp_overlay(c);
116 if (buildhelp_overlay_index < Widelands::Field::Buildhelp_None) {
117 auto& overlay_info = buildhelp_infos_[buildhelp_overlay_index];
118 func(overlay_info.pic, overlay_info.hotspot);
119 }
120 }
121
122 while (it != overlays_.end() && it->first == c) {
123 if (is_enabled(it->second.level)) {
124 func(it->second.pic, it->second.hotspot);
125 }
126 ++it;
127 }
128 }
129
130private:
131 static constexpr int kLevelForBuildHelp = 5;
132
133 /// A overlay as drawn onto the screen.
134 struct OverlayInfo {
135 const Image* pic = nullptr;
136 Vector2i hotspot = Vector2i::zero();
137 };
138
139 struct RegisteredOverlays {
140 RegisteredOverlays(const OverlayId init_overlay_id,
141 const Image* init_pic,
142 const Vector2i init_hotspot,
143 const OverlayLevel& init_level)
144 : pic(init_pic), hotspot(init_hotspot), level(init_level) {
145 overlay_ids.insert(init_overlay_id);
146 }
147 std::set<OverlayId> overlay_ids;
148 const Image* pic;
149 Vector2i hotspot = Vector2i::zero();
150 OverlayLevel level;
151 };
152
153 // Returns the index into buildhelp_infos_ for the correct fieldcaps for
154 // 'fc' according to the current 'callback_'.
155 int get_buildhelp_overlay(const Widelands::FCoords& fc) const;
156
157 std::multimap<const Widelands::Coords, RegisteredOverlays> overlays_;
158
159 OverlayInfo buildhelp_infos_[Widelands::Field::Buildhelp_None];
160 bool buildhelp_;
161 // We are inverting the logic here, since new layers are by default enabled
162 // and we only support to toggle some of them off. Otherwise whenever a new
163 // layer is added in 'OverlayLevel' we would also need to add it to the
164 // 'enabled_layers_' set on construction.
165 std::set<OverlayLevel> disabled_layers_;
166
167 // this callback is used to define where overlays are drawn.
168 CallbackFn callback_;
169 OverlayId current_overlay_id_;
170};
171
172#endif // end of include guard: WL_WUI_FIELD_OVERLAY_MANAGER_H
1730
=== modified file 'src/wui/fieldaction.cc'
--- src/wui/fieldaction.cc 2017-09-03 13:03:56 +0000
+++ src/wui/fieldaction.cc 2017-09-13 18:51:31 +0000
@@ -41,7 +41,6 @@
41#include "wui/actionconfirm.h"41#include "wui/actionconfirm.h"
42#include "wui/attack_box.h"42#include "wui/attack_box.h"
43#include "wui/economy_options_window.h"43#include "wui/economy_options_window.h"
44#include "wui/field_overlay_manager.h"
45#include "wui/game_debug_ui.h"44#include "wui/game_debug_ui.h"
46#include "wui/interactive_player.h"45#include "wui/interactive_player.h"
47#include "wui/waresdisplay.h"46#include "wui/waresdisplay.h"
4847
=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc 2017-09-11 19:18:35 +0000
+++ src/wui/interactive_base.cc 2017-09-13 18:51:31 +0000
@@ -46,7 +46,6 @@
46#include "logic/widelands_geometry.h"46#include "logic/widelands_geometry.h"
47#include "profile/profile.h"47#include "profile/profile.h"
48#include "scripting/lua_interface.h"48#include "scripting/lua_interface.h"
49#include "wui/field_overlay_manager.h"
50#include "wui/game_chat_menu.h"49#include "wui/game_chat_menu.h"
51#include "wui/game_debug_ui.h"50#include "wui/game_debug_ui.h"
52#include "wui/interactive_player.h"51#include "wui/interactive_player.h"
@@ -56,6 +55,8 @@
56#include "wui/minimap.h"55#include "wui/minimap.h"
57#include "wui/unique_window_handler.h"56#include "wui/unique_window_handler.h"
5857
58namespace {
59
59using Widelands::Area;60using Widelands::Area;
60using Widelands::CoordPath;61using Widelands::CoordPath;
61using Widelands::Coords;62using Widelands::Coords;
@@ -65,15 +66,39 @@
65using Widelands::MapObject;66using Widelands::MapObject;
66using Widelands::TCoords;67using Widelands::TCoords;
6768
69int caps_to_buildhelp(const Widelands::NodeCaps caps) {
70 if (caps & Widelands::BUILDCAPS_MINE) {
71 return Widelands::Field::Buildhelp_Mine;
72 }
73 if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_BIG) {
74 if (caps & Widelands::BUILDCAPS_PORT) {
75 return Widelands::Field::Buildhelp_Port;
76 }
77 return Widelands::Field::Buildhelp_Big;
78 }
79 if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_MEDIUM) {
80 return Widelands::Field::Buildhelp_Medium;
81 }
82 if ((caps & Widelands::BUILDCAPS_SIZEMASK) == Widelands::BUILDCAPS_SMALL) {
83 return Widelands::Field::Buildhelp_Small;
84 }
85 if (caps & Widelands::BUILDCAPS_FLAG) {
86 return Widelands::Field::Buildhelp_Flag;
87 }
88 return Widelands::Field::Buildhelp_None;
89}
90
91} // namespace
92
68InteractiveBase::InteractiveBase(EditorGameBase& the_egbase, Section& global_s)93InteractiveBase::InteractiveBase(EditorGameBase& the_egbase, Section& global_s)
69 : UI::Panel(nullptr, 0, 0, g_gr->get_xres(), g_gr->get_yres()),94 : UI::Panel(nullptr, 0, 0, g_gr->get_xres(), g_gr->get_yres()),
70 show_workarea_preview_(global_s.get_bool("workareapreview", true)),95 show_workarea_preview_(global_s.get_bool("workareapreview", true)),
96 buildhelp_(false),
71 map_view_(this, the_egbase.map(), 0, 0, g_gr->get_xres(), g_gr->get_yres()),97 map_view_(this, the_egbase.map(), 0, 0, g_gr->get_xres(), g_gr->get_yres()),
72 // Initialize chatoveraly before the toolbar so it is below98 // Initialize chatoveraly before the toolbar so it is below
73 chat_overlay_(new ChatOverlay(this, 10, 25, get_w() / 2, get_h() - 25)),99 chat_overlay_(new ChatOverlay(this, 10, 25, get_w() / 2, get_h() - 25)),
74 toolbar_(this, 0, 0, UI::Box::Horizontal),100 toolbar_(this, 0, 0, UI::Box::Horizontal),
75 quick_navigation_(&map_view_),101 quick_navigation_(&map_view_),
76 field_overlay_manager_(new FieldOverlayManager()),
77 egbase_(the_egbase),102 egbase_(the_egbase),
78#ifndef NDEBUG // not in releases103#ifndef NDEBUG // not in releases
79 display_flags_(dfDebug),104 display_flags_(dfDebug),
@@ -94,6 +119,33 @@
94 g_gr->images().get("images/wui/overlays/workarea2.png"),119 g_gr->images().get("images/wui/overlays/workarea2.png"),
95 g_gr->images().get("images/wui/overlays/workarea1.png")} {120 g_gr->images().get("images/wui/overlays/workarea1.png")} {
96121
122 // Load the buildhelp icons.
123 {
124 BuildhelpOverlay* buildhelp_overlay = buildhelp_overlays_;
125 const char* filenames[] = {
126 "images/wui/overlays/set_flag.png", "images/wui/overlays/small.png",
127 "images/wui/overlays/medium.png", "images/wui/overlays/big.png",
128 "images/wui/overlays/mine.png", "images/wui/overlays/port.png"};
129 const char* const* filename = filenames;
130
131 // Special case for flag, which has a different formula for hotspot_y.
132 buildhelp_overlay->pic = g_gr->images().get(*filename);
133 buildhelp_overlay->hotspot =
134 Vector2i(buildhelp_overlay->pic->width() / 2, buildhelp_overlay->pic->height() - 1);
135
136 const BuildhelpOverlay* const buildhelp_overlays_end =
137 buildhelp_overlay + Widelands::Field::Buildhelp_None;
138 for (;;) { // The other buildhelp overlays.
139 ++buildhelp_overlay;
140 ++filename;
141 if (buildhelp_overlay == buildhelp_overlays_end)
142 break;
143 buildhelp_overlay->pic = g_gr->images().get(*filename);
144 buildhelp_overlay->hotspot =
145 Vector2i(buildhelp_overlay->pic->width() / 2, buildhelp_overlay->pic->height() / 2);
146 }
147 }
148
97 resize_chat_overlay();149 resize_chat_overlay();
98150
99 graphic_resolution_changed_subscriber_ = Notifications::subscribe<GraphicResolutionChanged>(151 graphic_resolution_changed_subscriber_ = Notifications::subscribe<GraphicResolutionChanged>(
@@ -144,6 +196,15 @@
144 }196 }
145}197}
146198
199const InteractiveBase::BuildhelpOverlay*
200InteractiveBase::get_buildhelp_overlay(const Widelands::NodeCaps caps) const {
201 const int buildhelp_overlay_index = caps_to_buildhelp(caps);
202 if (buildhelp_overlay_index < Widelands::Field::Buildhelp_None) {
203 return &buildhelp_overlays_[buildhelp_overlay_index];
204 }
205 return nullptr;
206}
207
147UniqueWindowHandler& InteractiveBase::unique_windows() {208UniqueWindowHandler& InteractiveBase::unique_windows() {
148 return *unique_window_handler_;209 return *unique_window_handler_;
149}210}
@@ -202,16 +263,16 @@
202}263}
203264
204bool InteractiveBase::buildhelp() const {265bool InteractiveBase::buildhelp() const {
205 return field_overlay_manager_->buildhelp();266 return buildhelp_;
206}267}
207268
208void InteractiveBase::show_buildhelp(bool t) {269void InteractiveBase::show_buildhelp(bool t) {
209 field_overlay_manager_->show_buildhelp(t);270 buildhelp_ = t;
210 on_buildhelp_changed(t);271 on_buildhelp_changed(t);
211}272}
212273
213void InteractiveBase::toggle_buildhelp() {274void InteractiveBase::toggle_buildhelp() {
214 show_buildhelp(!field_overlay_manager_->buildhelp());275 show_buildhelp(!buildhelp());
215}276}
216277
217UI::Button* InteractiveBase::add_toolbar_button(const std::string& image_basename,278UI::Button* InteractiveBase::add_toolbar_button(const std::string& image_basename,
218279
=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h 2017-09-11 14:11:56 +0000
+++ src/wui/interactive_base.h 2017-09-13 18:51:31 +0000
@@ -37,7 +37,6 @@
37#include "ui_basic/unique_window.h"37#include "ui_basic/unique_window.h"
38#include "wui/chatoverlay.h"38#include "wui/chatoverlay.h"
39#include "wui/debugconsole.h"39#include "wui/debugconsole.h"
40#include "wui/field_overlay_manager.h"
41#include "wui/mapview.h"40#include "wui/mapview.h"
42#include "wui/minimap.h"41#include "wui/minimap.h"
43#include "wui/quicknavigation.h"42#include "wui/quicknavigation.h"
@@ -72,6 +71,12 @@
72 std::map<Widelands::Coords, const Image*> steepness_indicators;71 std::map<Widelands::Coords, const Image*> steepness_indicators;
73 };72 };
7473
74 /// A build help overlay, i.e. small, big, mine, port ...
75 struct BuildhelpOverlay {
76 const Image* pic = nullptr;
77 Vector2i hotspot = Vector2i::zero();
78 };
79
75 // Manages all UniqueWindows.80 // Manages all UniqueWindows.
76 UniqueWindowHandler& unique_windows();81 UniqueWindowHandler& unique_windows();
7782
@@ -155,13 +160,6 @@
155 log_message(std::string(message));160 log_message(std::string(message));
156 }161 }
157162
158 const FieldOverlayManager& field_overlay_manager() const {
159 return *field_overlay_manager_;
160 }
161 FieldOverlayManager* mutable_field_overlay_manager() {
162 return field_overlay_manager_.get();
163 }
164
165 void toggle_minimap();163 void toggle_minimap();
166 void toggle_buildhelp();164 void toggle_buildhelp();
167165
@@ -171,10 +169,6 @@
171 // Sets the landmark for the keyboard 'key' to 'point'169 // Sets the landmark for the keyboard 'key' to 'point'
172 void set_landmark(size_t key, const MapView::View& view);170 void set_landmark(size_t key, const MapView::View& view);
173171
174 const RoadBuildingOverlays& road_building_overlays() const {
175 return road_building_overlays_;
176 }
177
178 MapView* map_view() {172 MapView* map_view() {
179 return &map_view_;173 return &map_view_;
180 }174 }
@@ -228,6 +222,14 @@
228 std::map<Widelands::Coords, const Image*>222 std::map<Widelands::Coords, const Image*>
229 get_work_area_overlays(const Widelands::Map& map) const;223 get_work_area_overlays(const Widelands::Map& map) const;
230224
225 // Returns the 'BuildhelpOverlay' for 'caps' or nullptr if there is no help
226 // to be displayed on this field.
227 const BuildhelpOverlay* get_buildhelp_overlay(Widelands::NodeCaps caps) const;
228
229 const RoadBuildingOverlays& road_building_overlays() const {
230 return road_building_overlays_;
231 }
232
231private:233private:
232 int32_t stereo_position(Widelands::Coords position_map);234 int32_t stereo_position(Widelands::Coords position_map);
233 void resize_chat_overlay();235 void resize_chat_overlay();
@@ -244,18 +246,17 @@
244 Widelands::Coords(0, 0),246 Widelands::Coords(0, 0),
245 Widelands::TCoords<>(Widelands::Coords(0, 0), Widelands::TriangleIndex::D)},247 Widelands::TCoords<>(Widelands::Coords(0, 0), Widelands::TriangleIndex::D)},
246 const uint32_t Radius = 0,248 const uint32_t Radius = 0,
247 const Image* Pic = nullptr,249 const Image* Pic = nullptr)
248 const FieldOverlayManager::OverlayId Jobid = 0)250 : freeze(Freeze), triangles(Triangles), pos(Pos), radius(Radius), pic(Pic) {
249 : freeze(Freeze), triangles(Triangles), pos(Pos), radius(Radius), pic(Pic), jobid(Jobid) {
250 }251 }
251 bool freeze; // don't change sel, even if mouse moves252 bool freeze; // don't change sel, even if mouse moves
252 bool triangles; // otherwise nodes253 bool triangles; // otherwise nodes
253 Widelands::NodeAndTriangle<> pos;254 Widelands::NodeAndTriangle<> pos;
254 uint32_t radius;255 uint32_t radius;
255 const Image* pic;256 const Image* pic;
256 FieldOverlayManager::OverlayId jobid;
257 } sel_;257 } sel_;
258258
259 bool buildhelp_;
259 MapView map_view_;260 MapView map_view_;
260 ChatOverlay* chat_overlay_;261 ChatOverlay* chat_overlay_;
261262
@@ -270,8 +271,6 @@
270 MiniMap::Registry minimap_registry_;271 MiniMap::Registry minimap_registry_;
271 QuickNavigation quick_navigation_;272 QuickNavigation quick_navigation_;
272273
273 std::unique_ptr<FieldOverlayManager> field_overlay_manager_;
274
275 // The currently enabled work area previews. They are keyed by the274 // The currently enabled work area previews. They are keyed by the
276 // coordinate that the building that shows the work area is positioned.275 // coordinate that the building that shows the work area is positioned.
277 std::map<Widelands::Coords, const WorkareaInfo*> work_area_previews_;276 std::map<Widelands::Coords, const WorkareaInfo*> work_area_previews_;
@@ -293,6 +292,7 @@
293 UI::UniqueWindow::Registry debugconsole_;292 UI::UniqueWindow::Registry debugconsole_;
294 std::unique_ptr<UniqueWindowHandler> unique_window_handler_;293 std::unique_ptr<UniqueWindowHandler> unique_window_handler_;
295 std::vector<const Image*> workarea_pics_;294 std::vector<const Image*> workarea_pics_;
295 BuildhelpOverlay buildhelp_overlays_[Widelands::Field::Buildhelp_None];
296};296};
297297
298#endif // end of include guard: WL_WUI_INTERACTIVE_BASE_H298#endif // end of include guard: WL_WUI_INTERACTIVE_BASE_H
299299
=== modified file 'src/wui/interactive_gamebase.cc'
--- src/wui/interactive_gamebase.cc 2017-08-20 17:45:42 +0000
+++ src/wui/interactive_gamebase.cc 2017-09-13 18:51:31 +0000
@@ -137,13 +137,9 @@
137 * during single/multiplayer/scenario).137 * during single/multiplayer/scenario).
138 */138 */
139void InteractiveGameBase::postload() {139void InteractiveGameBase::postload() {
140 auto* overlay_manager = mutable_field_overlay_manager();
141 show_buildhelp(false);140 show_buildhelp(false);
142 on_buildhelp_changed(buildhelp());141 on_buildhelp_changed(buildhelp());
143142
144 overlay_manager->register_overlay_callback_function(
145 boost::bind(&InteractiveGameBase::calculate_buildcaps, this, _1));
146
147 // Recalc whole map for changed owner stuff143 // Recalc whole map for changed owner stuff
148 egbase().mutable_map()->recalc_whole_map(egbase().world());144 egbase().mutable_map()->recalc_whole_map(egbase().world());
149145
150146
=== modified file 'src/wui/interactive_gamebase.h'
--- src/wui/interactive_gamebase.h 2017-08-28 07:39:59 +0000
+++ src/wui/interactive_gamebase.h 2017-09-13 18:51:31 +0000
@@ -97,7 +97,6 @@
9797
98protected:98protected:
99 void draw_overlay(RenderTarget&) override;99 void draw_overlay(RenderTarget&) override;
100 virtual int32_t calculate_buildcaps(const Widelands::FCoords& c) = 0;
101100
102 GameMainMenuWindows main_windows_;101 GameMainMenuWindows main_windows_;
103 ChatProvider* chat_provider_;102 ChatProvider* chat_provider_;
104103
=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc 2017-09-11 08:22:25 +0000
+++ src/wui/interactive_player.cc 2017-09-13 18:51:31 +0000
@@ -389,9 +389,13 @@
389 }389 }
390 }390 }
391391
392 // TODO(sirver): Do not use the field_overlay_manager, instead draw the392 // Draw build help.
393 // overlays we are interested in here directly.393 if (buildhelp()) {
394 field_overlay_manager().foreach_overlay(f->fcoords, blit_overlay);394 const auto* overlay = get_buildhelp_overlay(plr.get_buildcaps(f->fcoords));
395 if (overlay != nullptr) {
396 blit_overlay(overlay->pic, overlay->hotspot);
397 }
398 }
395399
396 // Blit the selection marker.400 // Blit the selection marker.
397 if (f->fcoords == get_sel_pos().node) {401 if (f->fcoords == get_sel_pos().node) {
@@ -425,11 +429,6 @@
425 return player_number_;429 return player_number_;
426}430}
427431
428int32_t InteractivePlayer::calculate_buildcaps(const Widelands::FCoords& c) {
429 assert(get_player());
430 return get_player()->get_buildcaps(c);
431}
432
433/// Player has clicked on the given node; bring up the context menu.432/// Player has clicked on the given node; bring up the context menu.
434void InteractivePlayer::node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) {433void InteractivePlayer::node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) {
435 const Map& map = egbase().map();434 const Map& map = egbase().map();
436435
=== modified file 'src/wui/interactive_player.h'
--- src/wui/interactive_player.h 2017-08-28 07:39:59 +0000
+++ src/wui/interactive_player.h 2017-09-13 18:51:31 +0000
@@ -78,7 +78,6 @@
78 }78 }
7979
80 void popup_message(Widelands::MessageId, const Widelands::Message&);80 void popup_message(Widelands::MessageId, const Widelands::Message&);
81 int32_t calculate_buildcaps(const Widelands::FCoords& c) override;
8281
83private:82private:
84 void cmdSwitchPlayer(const std::vector<std::string>& args);83 void cmdSwitchPlayer(const std::vector<std::string>& args);
8584
=== modified file 'src/wui/interactive_spectator.cc'
--- src/wui/interactive_spectator.cc 2017-09-01 13:26:55 +0000
+++ src/wui/interactive_spectator.cc 2017-09-13 18:51:31 +0000
@@ -117,27 +117,27 @@
117 assert(get_sel_radius() == 0);117 assert(get_sel_radius() == 0);
118 assert(!get_sel_triangles());118 assert(!get_sel_triangles());
119119
120 const auto& gbase = egbase();120 const Widelands::Game& the_game = game();
121 auto* fields_to_draw = given_map_view->draw_terrain(gbase, dst);121 const Widelands::Map& map = the_game.map();
122 auto* fields_to_draw = given_map_view->draw_terrain(the_game, dst);
122 const float scale = 1.f / given_map_view->view().zoom;123 const float scale = 1.f / given_map_view->view().zoom;
123 const uint32_t gametime = gbase.get_gametime();124 const uint32_t gametime = the_game.get_gametime();
124125
125 const auto text_to_draw = get_text_to_draw();126 const auto text_to_draw = get_text_to_draw();
126 const std::map<Widelands::Coords, const Image*> work_area_overlays =127 const std::map<Widelands::Coords, const Image*> work_area_overlays = get_work_area_overlays(map);
127 get_work_area_overlays(gbase.map());
128 for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) {128 for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) {
129 const FieldsToDraw::Field& field = fields_to_draw->at(idx);129 const FieldsToDraw::Field& field = fields_to_draw->at(idx);
130130
131 draw_border_markers(field, scale, *fields_to_draw, dst);131 draw_border_markers(field, scale, *fields_to_draw, dst);
132132
133 Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();133 Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();
134 if (imm != nullptr && imm->get_positions(gbase).front() == field.fcoords) {134 if (imm != nullptr && imm->get_positions(the_game).front() == field.fcoords) {
135 imm->draw(gametime, text_to_draw, field.rendertarget_pixel, scale, dst);135 imm->draw(gametime, text_to_draw, field.rendertarget_pixel, scale, dst);
136 }136 }
137137
138 for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;138 for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;
139 bob = bob->get_next_bob()) {139 bob = bob->get_next_bob()) {
140 bob->draw(gbase, text_to_draw, field.rendertarget_pixel, scale, dst);140 bob->draw(the_game, text_to_draw, field.rendertarget_pixel, scale, dst);
141 }141 }
142142
143 const auto blit_overlay = [dst, &field, scale](const Image* pic, const Vector2i& hotspot) {143 const auto blit_overlay = [dst, &field, scale](const Image* pic, const Vector2i& hotspot) {
@@ -147,15 +147,29 @@
147 BlendMode::UseAlpha);147 BlendMode::UseAlpha);
148 };148 };
149149
150 // Draw work area previews.
150 const auto it = work_area_overlays.find(field.fcoords);151 const auto it = work_area_overlays.find(field.fcoords);
151 if (it != work_area_overlays.end()) {152 if (it != work_area_overlays.end()) {
152 const Image* pic = it->second;153 const Image* pic = it->second;
153 blit_overlay(pic, Vector2i(pic->width() / 2, pic->height() / 2));154 blit_overlay(pic, Vector2i(pic->width() / 2, pic->height() / 2));
154 }155 }
155156
156 // TODO(sirver): Do not use the field_overlay_manager, instead draw the157 // Draw build help.
157 // overlays we are interested in here directly.158 if (buildhelp()) {
158 field_overlay_manager().foreach_overlay(field.fcoords, blit_overlay);159 auto caps = Widelands::NodeCaps::CAPS_NONE;
160 const Widelands::PlayerNumber nr_players = map.get_nrplayers();
161 iterate_players_existing(p, nr_players, the_game, player) {
162 const Widelands::NodeCaps nc = player->get_buildcaps(field.fcoords);
163 if (nc > Widelands::NodeCaps::CAPS_NONE) {
164 caps = nc;
165 break;
166 }
167 }
168 const auto* overlay = get_buildhelp_overlay(caps);
169 if (overlay != nullptr) {
170 blit_overlay(overlay->pic, overlay->hotspot);
171 }
172 }
159173
160 // Blit the selection marker.174 // Blit the selection marker.
161 if (field.fcoords == get_sel_pos().node) {175 if (field.fcoords == get_sel_pos().node) {
@@ -175,17 +189,6 @@
175 return nullptr;189 return nullptr;
176}190}
177191
178int32_t InteractiveSpectator::calculate_buildcaps(const Widelands::FCoords& c) {
179 const Widelands::PlayerNumber nr_players = game().map().get_nrplayers();
180 iterate_players_existing(p, nr_players, game(), player) {
181 const Widelands::NodeCaps nc = player->get_buildcaps(c);
182 if (nc > Widelands::NodeCaps::CAPS_NONE) {
183 return nc;
184 }
185 }
186 return Widelands::NodeCaps::CAPS_NONE;
187}
188
189// Toolbar button callback functions.192// Toolbar button callback functions.
190void InteractiveSpectator::exit_btn() {193void InteractiveSpectator::exit_btn() {
191 if (is_multiplayer()) {194 if (is_multiplayer()) {
192195
=== modified file 'src/wui/interactive_spectator.h'
--- src/wui/interactive_spectator.h 2017-08-28 07:39:59 +0000
+++ src/wui/interactive_spectator.h 2017-09-13 18:51:31 +0000
@@ -48,7 +48,6 @@
4848
49private:49private:
50 void exit_btn();50 void exit_btn();
51 int32_t calculate_buildcaps(const Widelands::FCoords& c) override;
52 bool can_see(Widelands::PlayerNumber) const override;51 bool can_see(Widelands::PlayerNumber) const override;
53 bool can_act(Widelands::PlayerNumber) const override;52 bool can_act(Widelands::PlayerNumber) const override;
54 Widelands::PlayerNumber player_number() const override;53 Widelands::PlayerNumber player_number() const override;

Subscribers

People subscribed via source and target branches

to status/vote changes: