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

Proposed by SirVer
Status: Merged
Merged at revision: 8436
Proposed branch: lp:~widelands-dev/widelands/pass_through_infos
Merge into: lp:widelands
Diff against target: 977 lines (+201/-200)
18 files modified
src/editor/editorinteractive.cc (+21/-11)
src/editor/editorinteractive.h (+5/-1)
src/graphic/game_renderer.cc (+2/-21)
src/graphic/game_renderer.h (+8/-27)
src/logic/map_objects/tribes/ship.h (+1/-1)
src/scripting/lua_ui.cc (+6/-3)
src/wui/CMakeLists.txt (+0/-1)
src/wui/fieldaction.cc (+0/-1)
src/wui/interactive_base.cc (+22/-24)
src/wui/interactive_base.h (+4/-14)
src/wui/interactive_gamebase.h (+7/-1)
src/wui/interactive_player.cc (+22/-5)
src/wui/interactive_player.h (+3/-1)
src/wui/interactive_spectator.cc (+20/-4)
src/wui/interactive_spectator.h (+3/-1)
src/wui/mapview.cc (+24/-54)
src/wui/mapview.h (+22/-14)
src/wui/watchwindow.cc (+31/-16)
To merge this branch: bzr merge lp:~widelands-dev/widelands/pass_through_infos
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+329691@code.launchpad.net

Commit message

Further untangle Interactive* classes.

- MapView no longer has knowledge of InteractiveBase instead it takes the Map. This means that InteractiveBase contains more of its own logic (like freeze of the selection marker).
- Give the Interacitve* classes their own draw() functions. Differentiating logic of drawing (for example visibility of fields and so on) can be moved into these functions to detangle the drawing code some more. This allowed to move draw_bobs() and draw_immovables() logic out of InteractiveBase into EditorInteractive.
- InteractiveBase::map_clicked and *::node_action() takes the node_and_triangle that was clicked instead of side loading it through the current fsel position.
- This fixes bug 1711816 with black terrains on fullscreen switch.

Description of the change

See commit message.

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

1 nit, rest LGTM.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2597. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/268933229.
Appveyor build 2419. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_pass_through_infos-2419.

Revision history for this message
SirVer (sirver) wrote :

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2600. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/269106599.
Appveyor build 2422. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_pass_through_infos-2422.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc 2017-08-20 17:45:42 +0000
+++ src/editor/editorinteractive.cc 2017-08-28 07:40:41 +0000
@@ -164,7 +164,9 @@
164 set_display_flag(InteractiveBase::dfDebug, false);164 set_display_flag(InteractiveBase::dfDebug, false);
165#endif165#endif
166166
167 map_view()->fieldclicked.connect(boost::bind(&EditorInteractive::map_clicked, this, false));167 map_view()->field_clicked.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
168 map_clicked(node_and_triangle, false);
169 });
168170
169 // Subscribe to changes of the resource type on a field..171 // Subscribe to changes of the resource type on a field..
170 field_resource_changed_subscriber_ =172 field_resource_changed_subscriber_ =
@@ -288,9 +290,10 @@
288 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);290 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
289}291}
290292
291void EditorInteractive::map_clicked(bool should_draw) {293void EditorInteractive::map_clicked(const Widelands::NodeAndTriangle<>& node_and_triangle,
294 const bool should_draw) {
292 history_->do_action(tools_->current(), tools_->use_tool, *egbase().mutable_map(),295 history_->do_action(tools_->current(), tools_->use_tool, *egbase().mutable_map(),
293 egbase().world(), get_sel_pos(), *this, should_draw);296 egbase().world(), node_and_triangle, *this, should_draw);
294 set_need_save(true);297 set_need_save(true);
295}298}
296299
@@ -308,14 +311,23 @@
308 return InteractiveBase::handle_mousepress(btn, x, y);311 return InteractiveBase::handle_mousepress(btn, x, y);
309}312}
310313
314void EditorInteractive::draw(RenderTarget& dst) {
315 const GameRenderer::Overlays overlays{get_text_to_draw(), {}};
316 map_view()->draw_map_view(
317 egbase(), overlays,
318 draw_immovables_ ? GameRenderer::DrawImmovables::kYes : GameRenderer::DrawImmovables::kNo,
319 draw_bobs_ ? GameRenderer::DrawBobs::kYes : GameRenderer::DrawBobs::kNo, nullptr, &dst);
320}
321
311/// Needed to get freehand painting tools (hold down mouse and move to edit).322/// Needed to get freehand painting tools (hold down mouse and move to edit).
312void EditorInteractive::set_sel_pos(Widelands::NodeAndTriangle<> const sel) {323void EditorInteractive::set_sel_pos(Widelands::NodeAndTriangle<> const sel) {
313 bool const target_changed = tools_->current().operates_on_triangles() ?324 bool const target_changed = tools_->current().operates_on_triangles() ?
314 sel.triangle != get_sel_pos().triangle :325 sel.triangle != get_sel_pos().triangle :
315 sel.node != get_sel_pos().node;326 sel.node != get_sel_pos().node;
316 InteractiveBase::set_sel_pos(sel);327 InteractiveBase::set_sel_pos(sel);
317 if (target_changed && is_painting_)328 if (target_changed && is_painting_) {
318 map_clicked(true);329 map_clicked(sel, true);
330 }
319}331}
320332
321void EditorInteractive::set_sel_radius_and_update_menu(uint32_t const val) {333void EditorInteractive::set_sel_radius_and_update_menu(uint32_t const val) {
@@ -350,15 +362,13 @@
350}362}
351363
352void EditorInteractive::toggle_immovables() {364void EditorInteractive::toggle_immovables() {
353 const bool value = !draw_immovables();365 draw_immovables_ = !draw_immovables_;
354 set_draw_immovables(value);366 toggle_immovables_->set_perm_pressed(draw_immovables_);
355 toggle_immovables_->set_perm_pressed(value);
356}367}
357368
358void EditorInteractive::toggle_bobs() {369void EditorInteractive::toggle_bobs() {
359 const bool value = !draw_bobs();370 draw_bobs_ = !draw_bobs_;
360 set_draw_bobs(value);371 toggle_bobs_->set_perm_pressed(draw_bobs_);
361 toggle_bobs_->set_perm_pressed(value);
362}372}
363373
364bool EditorInteractive::handle_key(bool const down, SDL_Keysym const code) {374bool EditorInteractive::handle_key(bool const down, SDL_Keysym const code) {
365375
=== modified file 'src/editor/editorinteractive.h'
--- src/editor/editorinteractive.h 2017-08-17 13:37:32 +0000
+++ src/editor/editorinteractive.h 2017-08-28 07:40:41 +0000
@@ -97,7 +97,7 @@
97 void start() override;97 void start() override;
98 void think() override;98 void think() override;
9999
100 void map_clicked(bool draw = false);100 void map_clicked(const Widelands::NodeAndTriangle<>& node_and_triangle, bool draw);
101 void set_sel_pos(Widelands::NodeAndTriangle<>) override;101 void set_sel_pos(Widelands::NodeAndTriangle<>) override;
102 void set_sel_radius_and_update_menu(uint32_t);102 void set_sel_radius_and_update_menu(uint32_t);
103 void start_painting();103 void start_painting();
@@ -107,6 +107,7 @@
107 bool handle_key(bool down, SDL_Keysym) override;107 bool handle_key(bool down, SDL_Keysym) override;
108 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;108 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;
109 bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y) override;109 bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y) override;
110 void draw(RenderTarget&) override;
110111
111 void select_tool(EditorTool&, EditorTool::ToolIndex);112 void select_tool(EditorTool&, EditorTool::ToolIndex);
112113
@@ -188,6 +189,9 @@
188189
189 std::unique_ptr<Tools> tools_;190 std::unique_ptr<Tools> tools_;
190 std::unique_ptr<EditorHistory> history_;191 std::unique_ptr<EditorHistory> history_;
192
193 bool draw_immovables_ = true;
194 bool draw_bobs_ = true;
191};195};
192196
193#endif // end of include guard: WL_EDITOR_EDITORINTERACTIVE_H197#endif // end of include guard: WL_EDITOR_EDITORINTERACTIVE_H
194198
=== modified file 'src/graphic/game_renderer.cc'
--- src/graphic/game_renderer.cc 2017-08-19 22:22:20 +0000
+++ src/graphic/game_renderer.cc 2017-08-28 07:40:41 +0000
@@ -279,32 +279,13 @@
279GameRenderer::~GameRenderer() {279GameRenderer::~GameRenderer() {
280}280}
281281
282void GameRenderer::rendermap(const Widelands::EditorGameBase& egbase,282void GameRenderer::render(const EditorGameBase& egbase,
283 const Vector2f& viewpoint,
284 const float zoom,
285 const Widelands::Player& player,
286 const Overlays& overlays,
287 RenderTarget* dst) {
288 draw(egbase, viewpoint, zoom, overlays, DrawImmovables::kYes, DrawBobs::kYes, &player, dst);
289}
290
291void GameRenderer::rendermap(const Widelands::EditorGameBase& egbase,
292 const Vector2f& viewpoint,
293 const float zoom,
294 const Overlays& overlays,
295 const DrawImmovables& draw_immovables,
296 const DrawBobs& draw_bobs,
297 RenderTarget* dst) {
298 draw(egbase, viewpoint, zoom, overlays, draw_immovables, draw_bobs, nullptr, dst);
299}
300
301void GameRenderer::draw(const EditorGameBase& egbase,
302 const Vector2f& viewpoint,283 const Vector2f& viewpoint,
303 const float zoom,284 const float zoom,
285 const Player* player,
304 const Overlays& overlays,286 const Overlays& overlays,
305 const DrawImmovables& draw_immovables,287 const DrawImmovables& draw_immovables,
306 const DrawBobs& draw_bobs,288 const DrawBobs& draw_bobs,
307 const Player* player,
308 RenderTarget* dst) {289 RenderTarget* dst) {
309 assert(viewpoint.x >= 0); // divisions involving negative numbers are bad290 assert(viewpoint.x >= 0); // divisions involving negative numbers are bad
310 assert(viewpoint.y >= 0);291 assert(viewpoint.y >= 0);
311292
=== modified file 'src/graphic/game_renderer.h'
--- src/graphic/game_renderer.h 2017-08-16 08:59:09 +0000
+++ src/graphic/game_renderer.h 2017-08-28 07:40:41 +0000
@@ -49,39 +49,20 @@
49 GameRenderer();49 GameRenderer();
50 ~GameRenderer();50 ~GameRenderer();
5151
52 // Renders the map from a player's point of view into the given drawing52 // Renders the map from a 'player's point of view (or omniscient if nullptr)
53 // window. The 'viewpoint' is the top left screens pixel map pixel and53 // into the given drawing window. The 'viewpoint' is the top left screens
54 // 'scale' is the magnification of the view.54 // pixel map pixel and 'scale' is the magnification of the view.
55 void rendermap(const Widelands::EditorGameBase& egbase,55 void render(const Widelands::EditorGameBase& egbase,
56 const Vector2f& viewpoint,
57 float scale,
58 const Widelands::Player& player,
59 const Overlays& overlays,
60 RenderTarget* dst);
61
62 // Renders the map from an omniscient perspective. This is used
63 // for spectators, players that see all, and in the editor. Only in the editor we allow toggling
64 // of immovables and bobs.
65 void rendermap(const Widelands::EditorGameBase& egbase,
66 const Vector2f& viewpoint,
67 float scale,
68 const Overlays& overlays,
69 const DrawImmovables& draw_immovables,
70 const DrawBobs& draw_bobs,
71 RenderTarget* dst);
72
73private:
74 // Draw the map for the given parameters (see rendermap). 'player'
75 // can be nullptr in which case the whole map is drawn.
76 void draw(const Widelands::EditorGameBase& egbase,
77 const Vector2f& viewpoint,56 const Vector2f& viewpoint,
78 float scale,57 float zoom,
58 const Widelands::Player* player,
79 const Overlays& overlays,59 const Overlays& overlays,
80 const DrawImmovables& draw_immovables,60 const DrawImmovables& draw_immovables,
81 const DrawBobs& draw_bobs,61 const DrawBobs& draw_bobs,
82 const Widelands::Player* player,
83 RenderTarget* dst);62 RenderTarget* dst);
8463
64private:
65
85 // This is owned and handled by us, but handed to the RenderQueue, so we66 // This is owned and handled by us, but handed to the RenderQueue, so we
86 // basically promise that this stays valid for one frame.67 // basically promise that this stays valid for one frame.
87 FieldsToDraw fields_to_draw_;68 FieldsToDraw fields_to_draw_;
8869
=== modified file 'src/logic/map_objects/tribes/ship.h'
--- src/logic/map_objects/tribes/ship.h 2017-08-16 14:30:17 +0000
+++ src/logic/map_objects/tribes/ship.h 2017-08-28 07:40:41 +0000
@@ -59,7 +59,7 @@
5959
60 Serial serial;60 Serial serial;
6161
62 enum class Action { kRefresh, kClose, kNoPortLeft };62 enum class Action { kClose, kNoPortLeft };
63 const Action action;63 const Action action;
6464
65 NoteShipWindow(Serial init_serial, const Action& init_action)65 NoteShipWindow(Serial init_serial, const Action& init_action)
6666
=== modified file 'src/scripting/lua_ui.cc'
--- src/scripting/lua_ui.cc 2017-08-18 02:28:27 +0000
+++ src/scripting/lua_ui.cc 2017-08-28 07:40:41 +0000
@@ -575,9 +575,12 @@
575 :type field: :class:`wl.map.Field`575 :type field: :class:`wl.map.Field`
576*/576*/
577int LuaMapView::click(lua_State* L) {577int LuaMapView::click(lua_State* L) {
578 get()->map_view()->mouse_to_field(578 const auto field = *get_user_class<LuaMaps::LuaField>(L, 2);
579 (*get_user_class<LuaMaps::LuaField>(L, 2))->coords(), MapView::Transition::Jump);579 get()->map_view()->mouse_to_field(field->coords(), MapView::Transition::Jump);
580 get()->map_view()->fieldclicked();580
581 Widelands::NodeAndTriangle<> node_and_triangle;
582 node_and_triangle.node = field->coords();
583 get()->map_view()->field_clicked(node_and_triangle);
581 return 0;584 return 0;
582}585}
583586
584587
=== modified file 'src/wui/CMakeLists.txt'
--- src/wui/CMakeLists.txt 2017-08-11 20:01:03 +0000
+++ src/wui/CMakeLists.txt 2017-08-28 07:40:41 +0000
@@ -111,7 +111,6 @@
111 logic_widelands_geometry111 logic_widelands_geometry
112 ui_basic112 ui_basic
113 widelands_ball_of_mud113 widelands_ball_of_mud
114 wui
115 wui_mapview_pixelfunctions114 wui_mapview_pixelfunctions
116)115)
117116
118117
=== modified file 'src/wui/fieldaction.cc'
--- src/wui/fieldaction.cc 2017-08-19 22:22:20 +0000
+++ src/wui/fieldaction.cc 2017-08-28 07:40:41 +0000
@@ -255,7 +255,6 @@
255 workarea_preview_overlay_id_(0),255 workarea_preview_overlay_id_(0),
256 attack_box_(nullptr) {256 attack_box_(nullptr) {
257 ib->set_sel_freeze(true);257 ib->set_sel_freeze(true);
258
259 set_center_panel(&tabpanel_);258 set_center_panel(&tabpanel_);
260}259}
261260
262261
=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc 2017-08-19 22:22:20 +0000
+++ src/wui/interactive_base.cc 2017-08-28 07:40:41 +0000
@@ -67,8 +67,7 @@
67InteractiveBase::InteractiveBase(EditorGameBase& the_egbase, Section& global_s)67InteractiveBase::InteractiveBase(EditorGameBase& the_egbase, Section& global_s)
68 : UI::Panel(nullptr, 0, 0, g_gr->get_xres(), g_gr->get_yres()),68 : UI::Panel(nullptr, 0, 0, g_gr->get_xres(), g_gr->get_yres()),
69 show_workarea_preview_(global_s.get_bool("workareapreview", true)),69 show_workarea_preview_(global_s.get_bool("workareapreview", true)),
70 // TODO(sirver): MapView should no longer have knowledge of InteractiveBase.70 map_view_(this, the_egbase.map(), 0, 0, g_gr->get_xres(), g_gr->get_yres()),
71 map_view_(this, 0, 0, g_gr->get_xres(), g_gr->get_yres(), *this),
72 // Initialize chatoveraly before the toolbar so it is below71 // Initialize chatoveraly before the toolbar so it is below
73 chat_overlay_(new ChatOverlay(this, 10, 25, get_w() / 2, get_h() - 25)),72 chat_overlay_(new ChatOverlay(this, 10, 25, get_w() / 2, get_h() - 25)),
74 toolbar_(this, 0, 0, UI::Box::Horizontal),73 toolbar_(this, 0, 0, UI::Box::Horizontal),
@@ -83,8 +82,6 @@
83 lastframe_(SDL_GetTicks()),82 lastframe_(SDL_GetTicks()),
84 frametime_(0),83 frametime_(0),
85 avg_usframetime_(0),84 avg_usframetime_(0),
86 draw_immovables_(true),
87 draw_bobs_(true),
88 road_buildhelp_overlay_jobid_(0),85 road_buildhelp_overlay_jobid_(0),
89 buildroad_(nullptr),86 buildroad_(nullptr),
90 road_build_player_(0),87 road_build_player_(0),
@@ -115,6 +112,14 @@
115112
116 toolbar_.set_layout_toplevel(true);113 toolbar_.set_layout_toplevel(true);
117 map_view_.changeview.connect([this] { mainview_move(); });114 map_view_.changeview.connect([this] { mainview_move(); });
115 map_view()->field_clicked.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
116 set_sel_pos(node_and_triangle);
117 });
118 map_view_.track_selection.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
119 if (!sel_.freeze) {
120 set_sel_pos(node_and_triangle);
121 }
122 });
118123
119 set_border_snap_distance(global_s.get_int("border_snap_distance", 0));124 set_border_snap_distance(global_s.get_int("border_snap_distance", 0));
120 set_panel_snap_distance(global_s.get_int("panel_snap_distance", 10));125 set_panel_snap_distance(global_s.get_int("panel_snap_distance", 10));
@@ -202,6 +207,19 @@
202 sel_.pic = image;207 sel_.pic = image;
203 set_sel_pos(get_sel_pos()); // redraw208 set_sel_pos(get_sel_pos()); // redraw
204}209}
210
211TextToDraw InteractiveBase::get_text_to_draw() const {
212 TextToDraw text_to_draw = TextToDraw::kNone;
213 auto display_flags = get_display_flags();
214 if (display_flags & InteractiveBase::dfShowCensus) {
215 text_to_draw = text_to_draw | TextToDraw::kCensus;
216 }
217 if (display_flags & InteractiveBase::dfShowStatistics) {
218 text_to_draw = text_to_draw | TextToDraw::kStatistics;
219 }
220 return text_to_draw;
221}
222
205void InteractiveBase::unset_sel_picture() {223void InteractiveBase::unset_sel_picture() {
206 set_sel_picture(g_gr->images().get("images/ui_basic/fsel.png"));224 set_sel_picture(g_gr->images().get("images/ui_basic/fsel.png"));
207}225}
@@ -215,22 +233,6 @@
215 on_buildhelp_changed(t);233 on_buildhelp_changed(t);
216}234}
217235
218bool InteractiveBase::draw_bobs() const {
219 return draw_bobs_;
220}
221
222void InteractiveBase::set_draw_bobs(const bool value) {
223 draw_bobs_ = value;
224}
225
226bool InteractiveBase::draw_immovables() const {
227 return draw_immovables_;
228}
229
230void InteractiveBase::set_draw_immovables(const bool value) {
231 draw_immovables_ = value;
232}
233
234void InteractiveBase::toggle_buildhelp() {236void InteractiveBase::toggle_buildhelp() {
235 show_buildhelp(!field_overlay_manager_->buildhelp());237 show_buildhelp(!field_overlay_manager_->buildhelp());
236}238}
@@ -344,10 +346,6 @@
344 UI::Panel::think();346 UI::Panel::think();
345}347}
346348
347void InteractiveBase::draw(RenderTarget& dst) {
348 map_view_.draw(dst);
349}
350
351bool InteractiveBase::handle_mousepress(uint8_t btn, int32_t x, int32_t y) {349bool InteractiveBase::handle_mousepress(uint8_t btn, int32_t x, int32_t y) {
352 return map_view_.handle_mousepress(btn, x, y);350 return map_view_.handle_mousepress(btn, x, y);
353}351}
354352
=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h 2017-08-17 15:34:45 +0000
+++ src/wui/interactive_base.h 2017-08-28 07:40:41 +0000
@@ -85,7 +85,6 @@
85 virtual Widelands::Player* get_player() const = 0;85 virtual Widelands::Player* get_player() const = 0;
8686
87 void think() override;87 void think() override;
88 void draw(RenderTarget&) override;
89 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;88 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;
90 bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y) override;89 bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y) override;
91 bool90 bool
@@ -97,9 +96,6 @@
97 const Widelands::NodeAndTriangle<>& get_sel_pos() const {96 const Widelands::NodeAndTriangle<>& get_sel_pos() const {
98 return sel_.pos;97 return sel_.pos;
99 }98 }
100 bool get_sel_freeze() const {
101 return sel_.freeze;
102 }
10399
104 // Returns true if the buildhelp is currently displayed.100 // Returns true if the buildhelp is currently displayed.
105 bool buildhelp() const;101 bool buildhelp() const;
@@ -107,14 +103,6 @@
107 // Sets if the buildhelp should be displayed. Will also call on_buildhelp_changed().103 // Sets if the buildhelp should be displayed. Will also call on_buildhelp_changed().
108 void show_buildhelp(bool t);104 void show_buildhelp(bool t);
109105
110 // Returns true if bobs or immovables should be rendered.
111 bool draw_bobs() const;
112 bool draw_immovables() const;
113
114 // Sets if bobs or immovables should be rendered.
115 void set_draw_bobs(bool value);
116 void set_draw_immovables(bool value);
117
118 /**106 /**
119 * sel_triangles determines whether the mouse pointer selects triangles.107 * sel_triangles determines whether the mouse pointer selects triangles.
120 * (False meas that it selects nodes.)108 * (False meas that it selects nodes.)
@@ -224,10 +212,14 @@
224 ChatOverlay* chat_overlay() {212 ChatOverlay* chat_overlay() {
225 return chat_overlay_;213 return chat_overlay_;
226 }214 }
215
227 UI::Box* toolbar() {216 UI::Box* toolbar() {
228 return &toolbar_;217 return &toolbar_;
229 }218 }
230219
220 // Returns the information which overlay text should currently be drawn.
221 TextToDraw get_text_to_draw() const;
222
231private:223private:
232 int32_t stereo_position(Widelands::Coords position_map);224 int32_t stereo_position(Widelands::Coords position_map);
233 void resize_chat_overlay();225 void resize_chat_overlay();
@@ -284,8 +276,6 @@
284 uint32_t lastframe_; // system time (milliseconds)276 uint32_t lastframe_; // system time (milliseconds)
285 uint32_t frametime_; // in millseconds277 uint32_t frametime_; // in millseconds
286 uint32_t avg_usframetime_; // in microseconds!278 uint32_t avg_usframetime_; // in microseconds!
287 bool draw_immovables_;
288 bool draw_bobs_;
289279
290 FieldOverlayManager::OverlayId road_buildhelp_overlay_jobid_;280 FieldOverlayManager::OverlayId road_buildhelp_overlay_jobid_;
291 Widelands::CoordPath* buildroad_; // path for the new road281 Widelands::CoordPath* buildroad_; // path for the new road
292282
=== modified file 'src/wui/interactive_gamebase.h'
--- src/wui/interactive_gamebase.h 2017-08-13 18:02:53 +0000
+++ src/wui/interactive_gamebase.h 2017-08-28 07:40:41 +0000
@@ -67,7 +67,13 @@
67 virtual bool can_act(Widelands::PlayerNumber) const = 0;67 virtual bool can_act(Widelands::PlayerNumber) const = 0;
68 virtual Widelands::PlayerNumber player_number() const = 0;68 virtual Widelands::PlayerNumber player_number() const = 0;
6969
70 virtual void node_action() = 0;70 // Only the 'InteractiveGameBase' has all information of what should be
71 // drawn into a map_view (i.e. which overlays are available). The
72 // 'WatchWindow' does not have this information, but needs to draw
73 // 'map_views', hence this function.
74 virtual void draw_map_view(MapView* given_map_view, RenderTarget* dst) = 0;
75
76 virtual void node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) = 0;
71 const PlayerType& get_playertype() const {77 const PlayerType& get_playertype() const {
72 return playertype_;78 return playertype_;
73 }79 }
7480
=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc 2017-08-18 02:28:27 +0000
+++ src/wui/interactive_player.cc 2017-08-28 07:40:41 +0000
@@ -114,7 +114,9 @@
114 };114 };
115115
116 set_player_number(plyn);116 set_player_number(plyn);
117 map_view()->fieldclicked.connect(boost::bind(&InteractivePlayer::node_action, this));117 map_view()->field_clicked.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
118 node_action(node_and_triangle);
119 });
118120
119 adjust_toolbar_position();121 adjust_toolbar_position();
120122
@@ -169,6 +171,21 @@
169 }171 }
170}172}
171173
174void InteractivePlayer::draw(RenderTarget& dst) {
175 // Bail out if the game isn't actually loaded.
176 // This fixes a crash with displaying an error dialog during loading.
177 if (!game().is_loaded())
178 return;
179
180 draw_map_view(map_view(), &dst);
181}
182
183void InteractivePlayer::draw_map_view(MapView* given_map_view, RenderTarget* dst) {
184 const GameRenderer::Overlays overlays{get_text_to_draw(), road_building_preview()};
185 given_map_view->draw_map_view(egbase(), overlays, GameRenderer::DrawImmovables::kYes,
186 GameRenderer::DrawBobs::kYes, &player(), dst);
187}
188
172void InteractivePlayer::popup_message(Widelands::MessageId const id,189void InteractivePlayer::popup_message(Widelands::MessageId const id,
173 const Widelands::Message& message) {190 const Widelands::Message& message) {
174 message_menu_.create();191 message_menu_.create();
@@ -191,13 +208,13 @@
191}208}
192209
193/// Player has clicked on the given node; bring up the context menu.210/// Player has clicked on the given node; bring up the context menu.
194void InteractivePlayer::node_action() {211void InteractivePlayer::node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) {
195 const Map& map = egbase().map();212 const Map& map = egbase().map();
196 if (1 < player().vision(Map::get_index(get_sel_pos().node, map.get_width()))) {213 if (1 < player().vision(Map::get_index(node_and_triangle.node, map.get_width()))) {
197 // Special case for buildings214 // Special case for buildings
198 if (upcast(Building, building, map.get_immovable(get_sel_pos().node)))215 if (upcast(Building, building, map.get_immovable(node_and_triangle.node)))
199 if (can_see(building->owner().player_number())) {216 if (can_see(building->owner().player_number())) {
200 show_building_window(get_sel_pos().node, false);217 show_building_window(node_and_triangle.node, false);
201 return;218 return;
202 }219 }
203220
204221
=== modified file 'src/wui/interactive_player.h'
--- src/wui/interactive_player.h 2017-08-13 18:02:53 +0000
+++ src/wui/interactive_player.h 2017-08-28 07:40:41 +0000
@@ -51,8 +51,9 @@
51 bool can_see(Widelands::PlayerNumber) const override;51 bool can_see(Widelands::PlayerNumber) const override;
52 bool can_act(Widelands::PlayerNumber) const override;52 bool can_act(Widelands::PlayerNumber) const override;
53 Widelands::PlayerNumber player_number() const override;53 Widelands::PlayerNumber player_number() const override;
54 void draw_map_view(MapView* given_map_view, RenderTarget* dst) override;
5455
55 void node_action() override;56 void node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) override;
5657
57 bool handle_key(bool down, SDL_Keysym) override;58 bool handle_key(bool down, SDL_Keysym) override;
5859
@@ -70,6 +71,7 @@
70 // For load71 // For load
71 void cleanup_for_load() override;72 void cleanup_for_load() override;
72 void think() override;73 void think() override;
74 void draw(RenderTarget& dst) override;
7375
74 void set_flag_to_connect(const Widelands::Coords& location) {76 void set_flag_to_connect(const Widelands::Coords& location) {
75 flag_to_connect_ = location;77 flag_to_connect_ = location;
7678
=== modified file 'src/wui/interactive_spectator.cc'
--- src/wui/interactive_spectator.cc 2017-08-18 02:28:27 +0000
+++ src/wui/interactive_spectator.cc 2017-08-28 07:40:41 +0000
@@ -95,7 +95,23 @@
95 adjust_toolbar_position();95 adjust_toolbar_position();
9696
97 // Setup all screen elements97 // Setup all screen elements
98 map_view()->fieldclicked.connect(boost::bind(&InteractiveSpectator::node_action, this));98 map_view()->field_clicked.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
99 node_action(node_and_triangle);
100 });
101}
102
103void InteractiveSpectator::draw(RenderTarget& dst) {
104 // This fixes a crash with displaying an error dialog during loading.
105 if (!game().is_loaded())
106 return;
107
108 draw_map_view(map_view(), &dst);
109}
110
111void InteractiveSpectator::draw_map_view(MapView* given_map_view, RenderTarget* dst) {
112 const GameRenderer::Overlays overlays{get_text_to_draw(), road_building_preview()};
113 given_map_view->draw_map_view(egbase(), overlays, GameRenderer::DrawImmovables::kYes,
114 GameRenderer::DrawBobs::kYes, nullptr, dst);
99}115}
100116
101/**117/**
@@ -140,10 +156,10 @@
140/**156/**
141 * Observer has clicked on the given node; bring up the context menu.157 * Observer has clicked on the given node; bring up the context menu.
142 */158 */
143void InteractiveSpectator::node_action() {159void InteractiveSpectator::node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) {
144 // Special case for buildings160 // Special case for buildings
145 if (is_a(Widelands::Building, egbase().map().get_immovable(get_sel_pos().node))) {161 if (is_a(Widelands::Building, egbase().map().get_immovable(node_and_triangle.node))) {
146 show_building_window(get_sel_pos().node, false);162 show_building_window(node_and_triangle.node, false);
147 return;163 return;
148 }164 }
149165
150166
=== modified file 'src/wui/interactive_spectator.h'
--- src/wui/interactive_spectator.h 2017-08-13 18:02:53 +0000
+++ src/wui/interactive_spectator.h 2017-08-28 07:40:41 +0000
@@ -43,6 +43,8 @@
43 Widelands::Player* get_player() const override;43 Widelands::Player* get_player() const override;
4444
45 bool handle_key(bool down, SDL_Keysym) override;45 bool handle_key(bool down, SDL_Keysym) override;
46 void draw(RenderTarget& dst) override;
47 void draw_map_view(MapView* given_map_view, RenderTarget* dst) override;
4648
47private:49private:
48 void exit_btn();50 void exit_btn();
@@ -50,7 +52,7 @@
50 bool can_see(Widelands::PlayerNumber) const override;52 bool can_see(Widelands::PlayerNumber) const override;
51 bool can_act(Widelands::PlayerNumber) const override;53 bool can_act(Widelands::PlayerNumber) const override;
52 Widelands::PlayerNumber player_number() const override;54 Widelands::PlayerNumber player_number() const override;
53 void node_action() override;55 void node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) override;
5456
55private:57private:
56 UI::UniqueWindow::Registry chat_;58 UI::UniqueWindow::Registry chat_;
5759
=== modified file 'src/wui/mapview.cc'
--- src/wui/mapview.cc 2017-08-18 02:28:27 +0000
+++ src/wui/mapview.cc 2017-08-28 07:40:41 +0000
@@ -23,15 +23,11 @@
2323
24#include "base/macros.h"24#include "base/macros.h"
25#include "base/math.h"25#include "base/math.h"
26#include "graphic/game_renderer.h"
27#include "graphic/graphic.h"26#include "graphic/graphic.h"
28#include "graphic/rendertarget.h"27#include "graphic/rendertarget.h"
29#include "logic/map.h"
30#include "logic/map_objects/draw_text.h"28#include "logic/map_objects/draw_text.h"
31#include "logic/player.h"29#include "logic/player.h"
32#include "wlapplication.h"30#include "wlapplication.h"
33#include "wui/interactive_base.h"
34#include "wui/interactive_player.h"
35#include "wui/mapviewpixelfunctions.h"31#include "wui/mapviewpixelfunctions.h"
3632
37namespace {33namespace {
@@ -295,10 +291,10 @@
295}291}
296292
297MapView::MapView(293MapView::MapView(
298 UI::Panel* parent, int32_t x, int32_t y, uint32_t w, uint32_t h, InteractiveBase& player)294 UI::Panel* parent, const Widelands::Map& map, int32_t x, int32_t y, uint32_t w, uint32_t h)
299 : UI::Panel(parent, x, y, w, h),295 : UI::Panel(parent, x, y, w, h),
296 map_(map),
300 renderer_(new GameRenderer()),297 renderer_(new GameRenderer()),
301 intbase_(player),
302 view_(),298 view_(),
303 last_mouse_pos_(Vector2i::zero()),299 last_mouse_pos_(Vector2i::zero()),
304 dragging_(false) {300 dragging_(false) {
@@ -343,9 +339,12 @@
343 NEVER_HERE();339 NEVER_HERE();
344}340}
345341
346void MapView::draw(RenderTarget& dst) {342void MapView::draw_map_view(const Widelands::EditorGameBase& egbase,
347 Widelands::EditorGameBase& egbase = intbase_.egbase();343 const GameRenderer::Overlays& overlays,
348344 const GameRenderer::DrawImmovables& draw_immovables,
345 const GameRenderer::DrawBobs& draw_bobs,
346 const Widelands::Player* player,
347 RenderTarget* dst) {
349 uint32_t now = SDL_GetTicks();348 uint32_t now = SDL_GetTicks();
350 while (!view_plans_.empty()) {349 while (!view_plans_.empty()) {
351 auto& plan = view_plans_.front();350 auto& plan = view_plans_.front();
@@ -385,44 +384,15 @@
385 break;384 break;
386 }385 }
387386
388 if (upcast(Widelands::Game, game, &egbase)) {387 renderer_->render(
389 // Bail out if the game isn't actually loaded.388 egbase, view_.viewpoint, view_.zoom, player, overlays, draw_immovables, draw_bobs, dst);
390 // This fixes a crash with displaying an error dialog during loading.
391 if (!game->is_loaded())
392 return;
393 }
394
395 TextToDraw text_to_draw = TextToDraw::kNone;
396 auto display_flags = intbase_.get_display_flags();
397 if (display_flags & InteractiveBase::dfShowCensus) {
398 text_to_draw = text_to_draw | TextToDraw::kCensus;
399 }
400 if (display_flags & InteractiveBase::dfShowStatistics) {
401 text_to_draw = text_to_draw | TextToDraw::kStatistics;
402 }
403
404 if (upcast(InteractivePlayer const, interactive_player, &intbase_)) {
405 const GameRenderer::Overlays overlays{
406 text_to_draw, interactive_player->road_building_preview()};
407 renderer_->rendermap(
408 egbase, view_.viewpoint, view_.zoom, interactive_player->player(), overlays, &dst);
409 } else {
410 const auto draw_immovables = intbase_.draw_immovables() ? GameRenderer::DrawImmovables::kYes :
411 GameRenderer::DrawImmovables::kNo;
412 const auto draw_bobs =
413 intbase_.draw_bobs() ? GameRenderer::DrawBobs::kYes : GameRenderer::DrawBobs::kNo;
414 const GameRenderer::Overlays overlays{static_cast<TextToDraw>(text_to_draw), {}};
415 renderer_->rendermap(
416 egbase, view_.viewpoint, view_.zoom, overlays, draw_immovables, draw_bobs, &dst);
417 }
418}389}
419390
420void MapView::set_view(const View& target_view, const Transition& transition) {391void MapView::set_view(const View& target_view, const Transition& transition) {
421 const Widelands::Map& map = intbase_.egbase().map();
422 switch (transition) {392 switch (transition) {
423 case Transition::Jump: {393 case Transition::Jump: {
424 view_ = target_view;394 view_ = target_view;
425 MapviewPixelFunctions::normalize_pix(map, &view_.viewpoint);395 MapviewPixelFunctions::normalize_pix(map_, &view_.viewpoint);
426 changeview();396 changeview();
427 return;397 return;
428 }398 }
@@ -430,7 +400,7 @@
430 case Transition::Smooth: {400 case Transition::Smooth: {
431 const TimestampedView current = animation_target_view();401 const TimestampedView current = animation_target_view();
432 const auto plan =402 const auto plan =
433 plan_map_transition(current.t, map, current.view, target_view, get_w(), get_h());403 plan_map_transition(current.t, map_, current.view, target_view, get_w(), get_h());
434 if (!plan.empty()) {404 if (!plan.empty()) {
435 view_plans_.push_back(plan);405 view_plans_.push_back(plan);
436 }406 }
@@ -440,13 +410,12 @@
440}410}
441411
442void MapView::scroll_to_field(const Widelands::Coords& c, const Transition& transition) {412void MapView::scroll_to_field(const Widelands::Coords& c, const Transition& transition) {
443 const Widelands::Map& map = intbase_.egbase().map();
444 assert(0 <= c.x);413 assert(0 <= c.x);
445 assert(c.x < map.get_width());414 assert(c.x < map_.get_width());
446 assert(0 <= c.y);415 assert(0 <= c.y);
447 assert(c.y < map.get_height());416 assert(c.y < map_.get_height());
448417
449 const Vector2f in_mappixel = MapviewPixelFunctions::to_map_pixel(map.get_fcoords(c));418 const Vector2f in_mappixel = MapviewPixelFunctions::to_map_pixel(map_.get_fcoords(c));
450 scroll_to_map_pixel(in_mappixel, transition);419 scroll_to_map_pixel(in_mappixel, transition);
451}420}
452421
@@ -458,7 +427,7 @@
458}427}
459428
460MapView::ViewArea MapView::view_area() const {429MapView::ViewArea MapView::view_area() const {
461 return ViewArea(get_view_area(view_, get_w(), get_h()), intbase_.egbase().map());430 return ViewArea(get_view_area(view_, get_w(), get_h()), map_);
462}431}
463432
464const MapView::View& MapView::view() const {433const MapView::View& MapView::view() const {
@@ -482,8 +451,8 @@
482bool MapView::handle_mousepress(uint8_t const btn, int32_t const x, int32_t const y) {451bool MapView::handle_mousepress(uint8_t const btn, int32_t const x, int32_t const y) {
483 if (btn == SDL_BUTTON_LEFT) {452 if (btn == SDL_BUTTON_LEFT) {
484 stop_dragging();453 stop_dragging();
485 track_sel(Vector2i(x, y));454 const auto node_and_triangle = track_sel(Vector2i(x, y));
486 fieldclicked();455 field_clicked(node_and_triangle);
487 } else if (btn == SDL_BUTTON_RIGHT) {456 } else if (btn == SDL_BUTTON_RIGHT) {
488 dragging_ = true;457 dragging_ = true;
489 grab_mouse(true);458 grab_mouse(true);
@@ -513,8 +482,7 @@
513 }482 }
514 }483 }
515484
516 if (!intbase_.get_sel_freeze())485 track_sel(Vector2i(x, y));
517 track_sel(Vector2i(x, y));
518 return true;486 return true;
519}487}
520488
@@ -571,10 +539,12 @@
571 return !view_plans_.empty() || !mouse_plans_.empty();539 return !view_plans_.empty() || !mouse_plans_.empty();
572}540}
573541
574void MapView::track_sel(const Vector2i& p) {542Widelands::NodeAndTriangle<> MapView::track_sel(const Vector2i& p) {
575 Vector2f p_in_map = to_map(p);543 Vector2f p_in_map = to_map(p);
576 intbase_.set_sel_pos(MapviewPixelFunctions::calc_node_and_triangle(544 const auto node_and_triangle =
577 intbase_.egbase().map(), p_in_map.x, p_in_map.y));545 MapviewPixelFunctions::calc_node_and_triangle(map_, p_in_map.x, p_in_map.y);
546 track_selection(node_and_triangle);
547 return node_and_triangle;
578}548}
579549
580bool MapView::handle_key(bool down, SDL_Keysym code) {550bool MapView::handle_key(bool down, SDL_Keysym code) {
581551
=== modified file 'src/wui/mapview.h'
--- src/wui/mapview.h 2017-08-17 15:34:45 +0000
+++ src/wui/mapview.h 2017-08-28 07:40:41 +0000
@@ -28,12 +28,12 @@
2828
29#include "base/rect.h"29#include "base/rect.h"
30#include "base/vector.h"30#include "base/vector.h"
31#include "graphic/game_renderer.h"
31#include "logic/map.h"32#include "logic/map.h"
32#include "logic/widelands_geometry.h"33#include "logic/widelands_geometry.h"
33#include "ui_basic/panel.h"34#include "ui_basic/panel.h"
3435
35class GameRenderer;36class GameRenderer;
36class InteractiveBase;
3737
38/**38/**
39 * Implements a view of a map. It is used to render a valid map on the screen.39 * Implements a view of a map. It is used to render a valid map on the screen.
@@ -101,18 +101,21 @@
101 };101 };
102102
103 MapView(UI::Panel* const parent,103 MapView(UI::Panel* const parent,
104 const Widelands::Map& map,
104 const int32_t x,105 const int32_t x,
105 const int32_t y,106 const int32_t y,
106 const uint32_t w,107 const uint32_t w,
107 const uint32_t h,108 const uint32_t h);
108 InteractiveBase&);
109 virtual ~MapView();109 virtual ~MapView();
110110
111 // Called whenever the view changed, also during automatic animations.111 // Called whenever the view changed, also during automatic animations.
112 boost::signals2::signal<void()> changeview;112 boost::signals2::signal<void()> changeview;
113113
114 // Called when the user clicked on a field.114 // Called when the user clicked on a field.
115 boost::signals2::signal<void()> fieldclicked;115 boost::signals2::signal<void(const Widelands::NodeAndTriangle<>&)> field_clicked;
116
117 // Called when the field under the mouse cursor has changed.
118 boost::signals2::signal<void(const Widelands::NodeAndTriangle<>&)> track_selection;
116119
117 // Defines if an animation should be immediate (one-frame) or nicely120 // Defines if an animation should be immediate (one-frame) or nicely
118 // animated for the user to follow.121 // animated for the user to follow.
@@ -156,13 +159,18 @@
156 // True if a 'Transition::Smooth' animation is playing.159 // True if a 'Transition::Smooth' animation is playing.
157 bool is_animating() const;160 bool is_animating() const;
158161
159 void draw(RenderTarget&) override;162 // Not overriden from UI::Panel, instead we expect to be passed the data through.
160 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;163 void draw_map_view(const Widelands::EditorGameBase& egbase,
161 bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y) override;164 const GameRenderer::Overlays& overlays,
162 bool165 const GameRenderer::DrawImmovables& draw_immovables,
163 handle_mousemove(uint8_t state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff) override;166 const GameRenderer::DrawBobs& draw_bobs,
164 bool handle_mousewheel(uint32_t which, int32_t x, int32_t y) override;167 const Widelands::Player* player,
165 bool handle_key(bool down, SDL_Keysym code) override;168 RenderTarget* dst);
169 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y);
170 bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y);
171 bool handle_mousemove(uint8_t state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff);
172 bool handle_mousewheel(uint32_t which, int32_t x, int32_t y);
173 bool handle_key(bool down, SDL_Keysym code);
166174
167private:175private:
168 void stop_dragging();176 void stop_dragging();
@@ -175,14 +183,14 @@
175 // current mouse) if we are not animating.183 // current mouse) if we are not animating.
176 TimestampedMouse animation_target_mouse() const;184 TimestampedMouse animation_target_mouse() const;
177185
178 // Move the sel to the given mouse position. Does not honour sel freeze.186 // Turns 'm' into the corresponding NodeAndTrinangle and calls 'track_selection'.
179 void track_sel(const Vector2i& m);187 Widelands::NodeAndTriangle<> track_sel(const Vector2i& m);
180188
181 Vector2f to_panel(const Vector2f& map_pixel) const;189 Vector2f to_panel(const Vector2f& map_pixel) const;
182 Vector2f to_map(const Vector2i& panel_pixel) const;190 Vector2f to_map(const Vector2i& panel_pixel) const;
183191
192 const Widelands::Map& map_;
184 std::unique_ptr<GameRenderer> renderer_;193 std::unique_ptr<GameRenderer> renderer_;
185 InteractiveBase& intbase_;
186 View view_;194 View view_;
187 Vector2i last_mouse_pos_;195 Vector2i last_mouse_pos_;
188 bool dragging_;196 bool dragging_;
189197
=== modified file 'src/wui/watchwindow.cc'
--- src/wui/watchwindow.cc 2017-08-20 17:45:42 +0000
+++ src/wui/watchwindow.cc 2017-08-28 07:40:41 +0000
@@ -58,7 +58,7 @@
58 ~WatchWindow();58 ~WatchWindow();
5959
60 Widelands::Game& game() const {60 Widelands::Game& game() const {
61 return dynamic_cast<InteractiveGameBase&>(*get_parent()).game();61 return parent_.game();
62 }62 }
6363
64 boost::signals2::signal<void(Vector2f)> warp_mainview;64 boost::signals2::signal<void(Vector2f)> warp_mainview;
@@ -72,6 +72,7 @@
72protected:72protected:
73 void think() override;73 void think() override;
74 void stop_tracking_by_drag();74 void stop_tracking_by_drag();
75 void draw(RenderTarget&) override;
7576
76private:77private:
77 void do_follow();78 void do_follow();
@@ -79,7 +80,8 @@
79 void view_button_clicked(uint8_t index);80 void view_button_clicked(uint8_t index);
80 void set_current_view(uint8_t idx, bool save_previous = true);81 void set_current_view(uint8_t idx, bool save_previous = true);
8182
82 MapView mapview_;83 InteractiveGameBase& parent_;
84 MapView map_view_;
83 uint32_t last_visit_;85 uint32_t last_visit_;
84 bool single_window_;86 bool single_window_;
85 uint8_t cur_index_;87 uint8_t cur_index_;
@@ -96,7 +98,8 @@
96 uint32_t const h,98 uint32_t const h,
97 bool const init_single_window)99 bool const init_single_window)
98 : UI::Window(&parent, "watch", x, y, w, h, _("Watch")),100 : UI::Window(&parent, "watch", x, y, w, h, _("Watch")),
99 mapview_(this, 0, 0, 200, 166, parent),101 parent_(parent),
102 map_view_(this, game().map(), 0, 0, 200, 166),
100 last_visit_(game().get_gametime()),103 last_visit_(game().get_gametime()),
101 single_window_(init_single_window),104 single_window_(init_single_window),
102 cur_index_(0) {105 cur_index_(0) {
@@ -124,13 +127,25 @@
124 closebtn->sigclicked.connect(boost::bind(&WatchWindow::close_cur_view, this));127 closebtn->sigclicked.connect(boost::bind(&WatchWindow::close_cur_view, this));
125 }128 }
126129
127 mapview_.fieldclicked.connect(boost::bind(&InteractiveGameBase::node_action, &parent));130 map_view_.field_clicked.connect([&parent](const Widelands::NodeAndTriangle<>& node_and_triangle) {
128 mapview_.changeview.connect([this] { stop_tracking_by_drag(); });131 parent.map_view()->field_clicked(node_and_triangle);
132 });
133 map_view_.track_selection.connect([&parent](const Widelands::NodeAndTriangle<>& node_and_triangle) {
134 parent.map_view()->track_selection(node_and_triangle);
135 });
136 map_view_.changeview.connect([this] { stop_tracking_by_drag(); });
129 warp_mainview.connect([&parent](const Vector2f& map_pixel) {137 warp_mainview.connect([&parent](const Vector2f& map_pixel) {
130 parent.map_view()->scroll_to_map_pixel(map_pixel, MapView::Transition::Smooth);138 parent.map_view()->scroll_to_map_pixel(map_pixel, MapView::Transition::Smooth);
131 });139 });
132}140}
133141
142void WatchWindow::draw(RenderTarget& dst) {
143 UI::Window::draw(dst);
144 if (!is_minimal()) {
145 parent_.draw_map_view(&map_view_, &dst);
146 }
147}
148
134/**149/**
135 * Add a view to a watchwindow, if there is space left.150 * Add a view to a watchwindow, if there is space left.
136 *151 *
@@ -141,10 +156,10 @@
141 return;156 return;
142 WatchWindowView view;157 WatchWindowView view;
143158
144 mapview_.scroll_to_field(coords, MapView::Transition::Jump);159 map_view_.scroll_to_field(coords, MapView::Transition::Jump);
145160
146 view.tracking = nullptr;161 view.tracking = nullptr;
147 view.view = mapview_.view();162 view.view = map_view_.view();
148 last_visit_ = game().get_gametime();163 last_visit_ = game().get_gametime();
149164
150 views_.push_back(view);165 views_.push_back(view);
@@ -161,7 +176,7 @@
161// Saves the coordinates of a view if it was already shown (and possibly moved)176// Saves the coordinates of a view if it was already shown (and possibly moved)
162void WatchWindow::save_coords() {177void WatchWindow::save_coords() {
163 auto& view = views_[cur_index_];178 auto& view = views_[cur_index_];
164 view.view = mapview_.view();179 view.view = map_view_.view();
165}180}
166181
167// Enables/Disables buttons for views_182// Enables/Disables buttons for views_
@@ -188,7 +203,7 @@
188 view_btns_[idx]->set_perm_pressed(true);203 view_btns_[idx]->set_perm_pressed(true);
189 }204 }
190 cur_index_ = idx;205 cur_index_ = idx;
191 mapview_.set_view(views_[cur_index_].view, MapView::Transition::Jump);206 map_view_.set_view(views_[cur_index_].view, MapView::Transition::Jump);
192}207}
193208
194WatchWindow::~WatchWindow() {209WatchWindow::~WatchWindow() {
@@ -197,7 +212,7 @@
197212
198/*213/*
199===============214===============
200Update the mapview_ if we're tracking something.215Update the map_view_ if we're tracking something.
201===============216===============
202*/217*/
203void WatchWindow::think() {218void WatchWindow::think() {
@@ -220,19 +235,19 @@
220 // Not in sight235 // Not in sight
221 views_[cur_index_].tracking = nullptr;236 views_[cur_index_].tracking = nullptr;
222 } else {237 } else {
223 mapview_.scroll_to_map_pixel(pos, MapView::Transition::Jump);238 map_view_.scroll_to_map_pixel(pos, MapView::Transition::Jump);
224 }239 }
225 }240 }
226}241}
227242
228/*243/*
229===============244===============
230When the user drags the mapview_, we stop tracking.245When the user drags the map_view_, we stop tracking.
231===============246===============
232*/247*/
233void WatchWindow::stop_tracking_by_drag() {248void WatchWindow::stop_tracking_by_drag() {
234 // Disable switching while dragging249 // Disable switching while dragging
235 if (mapview_.is_dragging()) {250 if (map_view_.is_dragging()) {
236 last_visit_ = game().get_gametime();251 last_visit_ = game().get_gametime();
237 views_[cur_index_].tracking = nullptr;252 views_[cur_index_].tracking = nullptr;
238 }253 }
@@ -251,7 +266,7 @@
251 } else {266 } else {
252 // Find the nearest bob. Other object types can not move and are267 // Find the nearest bob. Other object types can not move and are
253 // therefore not of interest.268 // therefore not of interest.
254 Vector2f center_map_pixel = mapview_.view_area().rect().center();269 Vector2f center_map_pixel = map_view_.view_area().rect().center();
255 const Widelands::Map& map = g.map();270 const Widelands::Map& map = g.map();
256 MapviewPixelFunctions::normalize_pix(map, &center_map_pixel);271 MapviewPixelFunctions::normalize_pix(map, &center_map_pixel);
257 std::vector<Widelands::Bob*> bobs;272 std::vector<Widelands::Bob*> bobs;
@@ -289,10 +304,10 @@
289/**304/**
290 * Called when the "go to" button is clicked.305 * Called when the "go to" button is clicked.
291 *306 *
292 * Cause the main mapview_ to jump to our current position.307 * Cause the main map_view_ to jump to our current position.
293 */308 */
294void WatchWindow::do_goto() {309void WatchWindow::do_goto() {
295 warp_mainview(mapview_.view_area().rect().center());310 warp_mainview(map_view_.view_area().rect().center());
296}311}
297312
298/**313/**

Subscribers

People subscribed via source and target branches

to status/vote changes: