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
1=== modified file 'src/editor/editorinteractive.cc'
2--- src/editor/editorinteractive.cc 2017-08-20 17:45:42 +0000
3+++ src/editor/editorinteractive.cc 2017-08-28 07:40:41 +0000
4@@ -164,7 +164,9 @@
5 set_display_flag(InteractiveBase::dfDebug, false);
6 #endif
7
8- map_view()->fieldclicked.connect(boost::bind(&EditorInteractive::map_clicked, this, false));
9+ map_view()->field_clicked.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
10+ map_clicked(node_and_triangle, false);
11+ });
12
13 // Subscribe to changes of the resource type on a field..
14 field_resource_changed_subscriber_ =
15@@ -288,9 +290,10 @@
16 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
17 }
18
19-void EditorInteractive::map_clicked(bool should_draw) {
20+void EditorInteractive::map_clicked(const Widelands::NodeAndTriangle<>& node_and_triangle,
21+ const bool should_draw) {
22 history_->do_action(tools_->current(), tools_->use_tool, *egbase().mutable_map(),
23- egbase().world(), get_sel_pos(), *this, should_draw);
24+ egbase().world(), node_and_triangle, *this, should_draw);
25 set_need_save(true);
26 }
27
28@@ -308,14 +311,23 @@
29 return InteractiveBase::handle_mousepress(btn, x, y);
30 }
31
32+void EditorInteractive::draw(RenderTarget& dst) {
33+ const GameRenderer::Overlays overlays{get_text_to_draw(), {}};
34+ map_view()->draw_map_view(
35+ egbase(), overlays,
36+ draw_immovables_ ? GameRenderer::DrawImmovables::kYes : GameRenderer::DrawImmovables::kNo,
37+ draw_bobs_ ? GameRenderer::DrawBobs::kYes : GameRenderer::DrawBobs::kNo, nullptr, &dst);
38+}
39+
40 /// Needed to get freehand painting tools (hold down mouse and move to edit).
41 void EditorInteractive::set_sel_pos(Widelands::NodeAndTriangle<> const sel) {
42 bool const target_changed = tools_->current().operates_on_triangles() ?
43 sel.triangle != get_sel_pos().triangle :
44 sel.node != get_sel_pos().node;
45 InteractiveBase::set_sel_pos(sel);
46- if (target_changed && is_painting_)
47- map_clicked(true);
48+ if (target_changed && is_painting_) {
49+ map_clicked(sel, true);
50+ }
51 }
52
53 void EditorInteractive::set_sel_radius_and_update_menu(uint32_t const val) {
54@@ -350,15 +362,13 @@
55 }
56
57 void EditorInteractive::toggle_immovables() {
58- const bool value = !draw_immovables();
59- set_draw_immovables(value);
60- toggle_immovables_->set_perm_pressed(value);
61+ draw_immovables_ = !draw_immovables_;
62+ toggle_immovables_->set_perm_pressed(draw_immovables_);
63 }
64
65 void EditorInteractive::toggle_bobs() {
66- const bool value = !draw_bobs();
67- set_draw_bobs(value);
68- toggle_bobs_->set_perm_pressed(value);
69+ draw_bobs_ = !draw_bobs_;
70+ toggle_bobs_->set_perm_pressed(draw_bobs_);
71 }
72
73 bool EditorInteractive::handle_key(bool const down, SDL_Keysym const code) {
74
75=== modified file 'src/editor/editorinteractive.h'
76--- src/editor/editorinteractive.h 2017-08-17 13:37:32 +0000
77+++ src/editor/editorinteractive.h 2017-08-28 07:40:41 +0000
78@@ -97,7 +97,7 @@
79 void start() override;
80 void think() override;
81
82- void map_clicked(bool draw = false);
83+ void map_clicked(const Widelands::NodeAndTriangle<>& node_and_triangle, bool draw);
84 void set_sel_pos(Widelands::NodeAndTriangle<>) override;
85 void set_sel_radius_and_update_menu(uint32_t);
86 void start_painting();
87@@ -107,6 +107,7 @@
88 bool handle_key(bool down, SDL_Keysym) override;
89 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;
91+ void draw(RenderTarget&) override;
92
93 void select_tool(EditorTool&, EditorTool::ToolIndex);
94
95@@ -188,6 +189,9 @@
96
97 std::unique_ptr<Tools> tools_;
98 std::unique_ptr<EditorHistory> history_;
99+
100+ bool draw_immovables_ = true;
101+ bool draw_bobs_ = true;
102 };
103
104 #endif // end of include guard: WL_EDITOR_EDITORINTERACTIVE_H
105
106=== modified file 'src/graphic/game_renderer.cc'
107--- src/graphic/game_renderer.cc 2017-08-19 22:22:20 +0000
108+++ src/graphic/game_renderer.cc 2017-08-28 07:40:41 +0000
109@@ -279,32 +279,13 @@
110 GameRenderer::~GameRenderer() {
111 }
112
113-void GameRenderer::rendermap(const Widelands::EditorGameBase& egbase,
114- const Vector2f& viewpoint,
115- const float zoom,
116- const Widelands::Player& player,
117- const Overlays& overlays,
118- RenderTarget* dst) {
119- draw(egbase, viewpoint, zoom, overlays, DrawImmovables::kYes, DrawBobs::kYes, &player, dst);
120-}
121-
122-void GameRenderer::rendermap(const Widelands::EditorGameBase& egbase,
123- const Vector2f& viewpoint,
124- const float zoom,
125- const Overlays& overlays,
126- const DrawImmovables& draw_immovables,
127- const DrawBobs& draw_bobs,
128- RenderTarget* dst) {
129- draw(egbase, viewpoint, zoom, overlays, draw_immovables, draw_bobs, nullptr, dst);
130-}
131-
132-void GameRenderer::draw(const EditorGameBase& egbase,
133+void GameRenderer::render(const EditorGameBase& egbase,
134 const Vector2f& viewpoint,
135 const float zoom,
136+ const Player* player,
137 const Overlays& overlays,
138 const DrawImmovables& draw_immovables,
139 const DrawBobs& draw_bobs,
140- const Player* player,
141 RenderTarget* dst) {
142 assert(viewpoint.x >= 0); // divisions involving negative numbers are bad
143 assert(viewpoint.y >= 0);
144
145=== modified file 'src/graphic/game_renderer.h'
146--- src/graphic/game_renderer.h 2017-08-16 08:59:09 +0000
147+++ src/graphic/game_renderer.h 2017-08-28 07:40:41 +0000
148@@ -49,39 +49,20 @@
149 GameRenderer();
150 ~GameRenderer();
151
152- // Renders the map from a player's point of view into the given drawing
153- // window. The 'viewpoint' is the top left screens pixel map pixel and
154- // 'scale' is the magnification of the view.
155- void rendermap(const Widelands::EditorGameBase& egbase,
156- const Vector2f& viewpoint,
157- float scale,
158- const Widelands::Player& player,
159- const Overlays& overlays,
160- RenderTarget* dst);
161-
162- // Renders the map from an omniscient perspective. This is used
163- // for spectators, players that see all, and in the editor. Only in the editor we allow toggling
164- // of immovables and bobs.
165- void rendermap(const Widelands::EditorGameBase& egbase,
166- const Vector2f& viewpoint,
167- float scale,
168- const Overlays& overlays,
169- const DrawImmovables& draw_immovables,
170- const DrawBobs& draw_bobs,
171- RenderTarget* dst);
172-
173-private:
174- // Draw the map for the given parameters (see rendermap). 'player'
175- // can be nullptr in which case the whole map is drawn.
176- void draw(const Widelands::EditorGameBase& egbase,
177+ // Renders the map from a 'player's point of view (or omniscient if nullptr)
178+ // into the given drawing window. The 'viewpoint' is the top left screens
179+ // pixel map pixel and 'scale' is the magnification of the view.
180+ void render(const Widelands::EditorGameBase& egbase,
181 const Vector2f& viewpoint,
182- float scale,
183+ float zoom,
184+ const Widelands::Player* player,
185 const Overlays& overlays,
186 const DrawImmovables& draw_immovables,
187 const DrawBobs& draw_bobs,
188- const Widelands::Player* player,
189 RenderTarget* dst);
190
191+private:
192+
193 // This is owned and handled by us, but handed to the RenderQueue, so we
194 // basically promise that this stays valid for one frame.
195 FieldsToDraw fields_to_draw_;
196
197=== modified file 'src/logic/map_objects/tribes/ship.h'
198--- src/logic/map_objects/tribes/ship.h 2017-08-16 14:30:17 +0000
199+++ src/logic/map_objects/tribes/ship.h 2017-08-28 07:40:41 +0000
200@@ -59,7 +59,7 @@
201
202 Serial serial;
203
204- enum class Action { kRefresh, kClose, kNoPortLeft };
205+ enum class Action { kClose, kNoPortLeft };
206 const Action action;
207
208 NoteShipWindow(Serial init_serial, const Action& init_action)
209
210=== modified file 'src/scripting/lua_ui.cc'
211--- src/scripting/lua_ui.cc 2017-08-18 02:28:27 +0000
212+++ src/scripting/lua_ui.cc 2017-08-28 07:40:41 +0000
213@@ -575,9 +575,12 @@
214 :type field: :class:`wl.map.Field`
215 */
216 int LuaMapView::click(lua_State* L) {
217- get()->map_view()->mouse_to_field(
218- (*get_user_class<LuaMaps::LuaField>(L, 2))->coords(), MapView::Transition::Jump);
219- get()->map_view()->fieldclicked();
220+ const auto field = *get_user_class<LuaMaps::LuaField>(L, 2);
221+ get()->map_view()->mouse_to_field(field->coords(), MapView::Transition::Jump);
222+
223+ Widelands::NodeAndTriangle<> node_and_triangle;
224+ node_and_triangle.node = field->coords();
225+ get()->map_view()->field_clicked(node_and_triangle);
226 return 0;
227 }
228
229
230=== modified file 'src/wui/CMakeLists.txt'
231--- src/wui/CMakeLists.txt 2017-08-11 20:01:03 +0000
232+++ src/wui/CMakeLists.txt 2017-08-28 07:40:41 +0000
233@@ -111,7 +111,6 @@
234 logic_widelands_geometry
235 ui_basic
236 widelands_ball_of_mud
237- wui
238 wui_mapview_pixelfunctions
239 )
240
241
242=== modified file 'src/wui/fieldaction.cc'
243--- src/wui/fieldaction.cc 2017-08-19 22:22:20 +0000
244+++ src/wui/fieldaction.cc 2017-08-28 07:40:41 +0000
245@@ -255,7 +255,6 @@
246 workarea_preview_overlay_id_(0),
247 attack_box_(nullptr) {
248 ib->set_sel_freeze(true);
249-
250 set_center_panel(&tabpanel_);
251 }
252
253
254=== modified file 'src/wui/interactive_base.cc'
255--- src/wui/interactive_base.cc 2017-08-19 22:22:20 +0000
256+++ src/wui/interactive_base.cc 2017-08-28 07:40:41 +0000
257@@ -67,8 +67,7 @@
258 InteractiveBase::InteractiveBase(EditorGameBase& the_egbase, Section& global_s)
259 : UI::Panel(nullptr, 0, 0, g_gr->get_xres(), g_gr->get_yres()),
260 show_workarea_preview_(global_s.get_bool("workareapreview", true)),
261- // TODO(sirver): MapView should no longer have knowledge of InteractiveBase.
262- map_view_(this, 0, 0, g_gr->get_xres(), g_gr->get_yres(), *this),
263+ map_view_(this, the_egbase.map(), 0, 0, g_gr->get_xres(), g_gr->get_yres()),
264 // Initialize chatoveraly before the toolbar so it is below
265 chat_overlay_(new ChatOverlay(this, 10, 25, get_w() / 2, get_h() - 25)),
266 toolbar_(this, 0, 0, UI::Box::Horizontal),
267@@ -83,8 +82,6 @@
268 lastframe_(SDL_GetTicks()),
269 frametime_(0),
270 avg_usframetime_(0),
271- draw_immovables_(true),
272- draw_bobs_(true),
273 road_buildhelp_overlay_jobid_(0),
274 buildroad_(nullptr),
275 road_build_player_(0),
276@@ -115,6 +112,14 @@
277
278 toolbar_.set_layout_toplevel(true);
279 map_view_.changeview.connect([this] { mainview_move(); });
280+ map_view()->field_clicked.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
281+ set_sel_pos(node_and_triangle);
282+ });
283+ map_view_.track_selection.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
284+ if (!sel_.freeze) {
285+ set_sel_pos(node_and_triangle);
286+ }
287+ });
288
289 set_border_snap_distance(global_s.get_int("border_snap_distance", 0));
290 set_panel_snap_distance(global_s.get_int("panel_snap_distance", 10));
291@@ -202,6 +207,19 @@
292 sel_.pic = image;
293 set_sel_pos(get_sel_pos()); // redraw
294 }
295+
296+TextToDraw InteractiveBase::get_text_to_draw() const {
297+ TextToDraw text_to_draw = TextToDraw::kNone;
298+ auto display_flags = get_display_flags();
299+ if (display_flags & InteractiveBase::dfShowCensus) {
300+ text_to_draw = text_to_draw | TextToDraw::kCensus;
301+ }
302+ if (display_flags & InteractiveBase::dfShowStatistics) {
303+ text_to_draw = text_to_draw | TextToDraw::kStatistics;
304+ }
305+ return text_to_draw;
306+}
307+
308 void InteractiveBase::unset_sel_picture() {
309 set_sel_picture(g_gr->images().get("images/ui_basic/fsel.png"));
310 }
311@@ -215,22 +233,6 @@
312 on_buildhelp_changed(t);
313 }
314
315-bool InteractiveBase::draw_bobs() const {
316- return draw_bobs_;
317-}
318-
319-void InteractiveBase::set_draw_bobs(const bool value) {
320- draw_bobs_ = value;
321-}
322-
323-bool InteractiveBase::draw_immovables() const {
324- return draw_immovables_;
325-}
326-
327-void InteractiveBase::set_draw_immovables(const bool value) {
328- draw_immovables_ = value;
329-}
330-
331 void InteractiveBase::toggle_buildhelp() {
332 show_buildhelp(!field_overlay_manager_->buildhelp());
333 }
334@@ -344,10 +346,6 @@
335 UI::Panel::think();
336 }
337
338-void InteractiveBase::draw(RenderTarget& dst) {
339- map_view_.draw(dst);
340-}
341-
342 bool InteractiveBase::handle_mousepress(uint8_t btn, int32_t x, int32_t y) {
343 return map_view_.handle_mousepress(btn, x, y);
344 }
345
346=== modified file 'src/wui/interactive_base.h'
347--- src/wui/interactive_base.h 2017-08-17 15:34:45 +0000
348+++ src/wui/interactive_base.h 2017-08-28 07:40:41 +0000
349@@ -85,7 +85,6 @@
350 virtual Widelands::Player* get_player() const = 0;
351
352 void think() override;
353- void draw(RenderTarget&) override;
354 bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;
355 bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y) override;
356 bool
357@@ -97,9 +96,6 @@
358 const Widelands::NodeAndTriangle<>& get_sel_pos() const {
359 return sel_.pos;
360 }
361- bool get_sel_freeze() const {
362- return sel_.freeze;
363- }
364
365 // Returns true if the buildhelp is currently displayed.
366 bool buildhelp() const;
367@@ -107,14 +103,6 @@
368 // Sets if the buildhelp should be displayed. Will also call on_buildhelp_changed().
369 void show_buildhelp(bool t);
370
371- // Returns true if bobs or immovables should be rendered.
372- bool draw_bobs() const;
373- bool draw_immovables() const;
374-
375- // Sets if bobs or immovables should be rendered.
376- void set_draw_bobs(bool value);
377- void set_draw_immovables(bool value);
378-
379 /**
380 * sel_triangles determines whether the mouse pointer selects triangles.
381 * (False meas that it selects nodes.)
382@@ -224,10 +212,14 @@
383 ChatOverlay* chat_overlay() {
384 return chat_overlay_;
385 }
386+
387 UI::Box* toolbar() {
388 return &toolbar_;
389 }
390
391+ // Returns the information which overlay text should currently be drawn.
392+ TextToDraw get_text_to_draw() const;
393+
394 private:
395 int32_t stereo_position(Widelands::Coords position_map);
396 void resize_chat_overlay();
397@@ -284,8 +276,6 @@
398 uint32_t lastframe_; // system time (milliseconds)
399 uint32_t frametime_; // in millseconds
400 uint32_t avg_usframetime_; // in microseconds!
401- bool draw_immovables_;
402- bool draw_bobs_;
403
404 FieldOverlayManager::OverlayId road_buildhelp_overlay_jobid_;
405 Widelands::CoordPath* buildroad_; // path for the new road
406
407=== modified file 'src/wui/interactive_gamebase.h'
408--- src/wui/interactive_gamebase.h 2017-08-13 18:02:53 +0000
409+++ src/wui/interactive_gamebase.h 2017-08-28 07:40:41 +0000
410@@ -67,7 +67,13 @@
411 virtual bool can_act(Widelands::PlayerNumber) const = 0;
412 virtual Widelands::PlayerNumber player_number() const = 0;
413
414- virtual void node_action() = 0;
415+ // Only the 'InteractiveGameBase' has all information of what should be
416+ // drawn into a map_view (i.e. which overlays are available). The
417+ // 'WatchWindow' does not have this information, but needs to draw
418+ // 'map_views', hence this function.
419+ virtual void draw_map_view(MapView* given_map_view, RenderTarget* dst) = 0;
420+
421+ virtual void node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) = 0;
422 const PlayerType& get_playertype() const {
423 return playertype_;
424 }
425
426=== modified file 'src/wui/interactive_player.cc'
427--- src/wui/interactive_player.cc 2017-08-18 02:28:27 +0000
428+++ src/wui/interactive_player.cc 2017-08-28 07:40:41 +0000
429@@ -114,7 +114,9 @@
430 };
431
432 set_player_number(plyn);
433- map_view()->fieldclicked.connect(boost::bind(&InteractivePlayer::node_action, this));
434+ map_view()->field_clicked.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
435+ node_action(node_and_triangle);
436+ });
437
438 adjust_toolbar_position();
439
440@@ -169,6 +171,21 @@
441 }
442 }
443
444+void InteractivePlayer::draw(RenderTarget& dst) {
445+ // Bail out if the game isn't actually loaded.
446+ // This fixes a crash with displaying an error dialog during loading.
447+ if (!game().is_loaded())
448+ return;
449+
450+ draw_map_view(map_view(), &dst);
451+}
452+
453+void InteractivePlayer::draw_map_view(MapView* given_map_view, RenderTarget* dst) {
454+ const GameRenderer::Overlays overlays{get_text_to_draw(), road_building_preview()};
455+ given_map_view->draw_map_view(egbase(), overlays, GameRenderer::DrawImmovables::kYes,
456+ GameRenderer::DrawBobs::kYes, &player(), dst);
457+}
458+
459 void InteractivePlayer::popup_message(Widelands::MessageId const id,
460 const Widelands::Message& message) {
461 message_menu_.create();
462@@ -191,13 +208,13 @@
463 }
464
465 /// Player has clicked on the given node; bring up the context menu.
466-void InteractivePlayer::node_action() {
467+void InteractivePlayer::node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) {
468 const Map& map = egbase().map();
469- if (1 < player().vision(Map::get_index(get_sel_pos().node, map.get_width()))) {
470+ if (1 < player().vision(Map::get_index(node_and_triangle.node, map.get_width()))) {
471 // Special case for buildings
472- if (upcast(Building, building, map.get_immovable(get_sel_pos().node)))
473+ if (upcast(Building, building, map.get_immovable(node_and_triangle.node)))
474 if (can_see(building->owner().player_number())) {
475- show_building_window(get_sel_pos().node, false);
476+ show_building_window(node_and_triangle.node, false);
477 return;
478 }
479
480
481=== modified file 'src/wui/interactive_player.h'
482--- src/wui/interactive_player.h 2017-08-13 18:02:53 +0000
483+++ src/wui/interactive_player.h 2017-08-28 07:40:41 +0000
484@@ -51,8 +51,9 @@
485 bool can_see(Widelands::PlayerNumber) const override;
486 bool can_act(Widelands::PlayerNumber) const override;
487 Widelands::PlayerNumber player_number() const override;
488+ void draw_map_view(MapView* given_map_view, RenderTarget* dst) override;
489
490- void node_action() override;
491+ void node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) override;
492
493 bool handle_key(bool down, SDL_Keysym) override;
494
495@@ -70,6 +71,7 @@
496 // For load
497 void cleanup_for_load() override;
498 void think() override;
499+ void draw(RenderTarget& dst) override;
500
501 void set_flag_to_connect(const Widelands::Coords& location) {
502 flag_to_connect_ = location;
503
504=== modified file 'src/wui/interactive_spectator.cc'
505--- src/wui/interactive_spectator.cc 2017-08-18 02:28:27 +0000
506+++ src/wui/interactive_spectator.cc 2017-08-28 07:40:41 +0000
507@@ -95,7 +95,23 @@
508 adjust_toolbar_position();
509
510 // Setup all screen elements
511- map_view()->fieldclicked.connect(boost::bind(&InteractiveSpectator::node_action, this));
512+ map_view()->field_clicked.connect([this](const Widelands::NodeAndTriangle<>& node_and_triangle) {
513+ node_action(node_and_triangle);
514+ });
515+}
516+
517+void InteractiveSpectator::draw(RenderTarget& dst) {
518+ // This fixes a crash with displaying an error dialog during loading.
519+ if (!game().is_loaded())
520+ return;
521+
522+ draw_map_view(map_view(), &dst);
523+}
524+
525+void InteractiveSpectator::draw_map_view(MapView* given_map_view, RenderTarget* dst) {
526+ const GameRenderer::Overlays overlays{get_text_to_draw(), road_building_preview()};
527+ given_map_view->draw_map_view(egbase(), overlays, GameRenderer::DrawImmovables::kYes,
528+ GameRenderer::DrawBobs::kYes, nullptr, dst);
529 }
530
531 /**
532@@ -140,10 +156,10 @@
533 /**
534 * Observer has clicked on the given node; bring up the context menu.
535 */
536-void InteractiveSpectator::node_action() {
537+void InteractiveSpectator::node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) {
538 // Special case for buildings
539- if (is_a(Widelands::Building, egbase().map().get_immovable(get_sel_pos().node))) {
540- show_building_window(get_sel_pos().node, false);
541+ if (is_a(Widelands::Building, egbase().map().get_immovable(node_and_triangle.node))) {
542+ show_building_window(node_and_triangle.node, false);
543 return;
544 }
545
546
547=== modified file 'src/wui/interactive_spectator.h'
548--- src/wui/interactive_spectator.h 2017-08-13 18:02:53 +0000
549+++ src/wui/interactive_spectator.h 2017-08-28 07:40:41 +0000
550@@ -43,6 +43,8 @@
551 Widelands::Player* get_player() const override;
552
553 bool handle_key(bool down, SDL_Keysym) override;
554+ void draw(RenderTarget& dst) override;
555+ void draw_map_view(MapView* given_map_view, RenderTarget* dst) override;
556
557 private:
558 void exit_btn();
559@@ -50,7 +52,7 @@
560 bool can_see(Widelands::PlayerNumber) const override;
561 bool can_act(Widelands::PlayerNumber) const override;
562 Widelands::PlayerNumber player_number() const override;
563- void node_action() override;
564+ void node_action(const Widelands::NodeAndTriangle<>& node_and_triangle) override;
565
566 private:
567 UI::UniqueWindow::Registry chat_;
568
569=== modified file 'src/wui/mapview.cc'
570--- src/wui/mapview.cc 2017-08-18 02:28:27 +0000
571+++ src/wui/mapview.cc 2017-08-28 07:40:41 +0000
572@@ -23,15 +23,11 @@
573
574 #include "base/macros.h"
575 #include "base/math.h"
576-#include "graphic/game_renderer.h"
577 #include "graphic/graphic.h"
578 #include "graphic/rendertarget.h"
579-#include "logic/map.h"
580 #include "logic/map_objects/draw_text.h"
581 #include "logic/player.h"
582 #include "wlapplication.h"
583-#include "wui/interactive_base.h"
584-#include "wui/interactive_player.h"
585 #include "wui/mapviewpixelfunctions.h"
586
587 namespace {
588@@ -295,10 +291,10 @@
589 }
590
591 MapView::MapView(
592- UI::Panel* parent, int32_t x, int32_t y, uint32_t w, uint32_t h, InteractiveBase& player)
593+ UI::Panel* parent, const Widelands::Map& map, int32_t x, int32_t y, uint32_t w, uint32_t h)
594 : UI::Panel(parent, x, y, w, h),
595+ map_(map),
596 renderer_(new GameRenderer()),
597- intbase_(player),
598 view_(),
599 last_mouse_pos_(Vector2i::zero()),
600 dragging_(false) {
601@@ -343,9 +339,12 @@
602 NEVER_HERE();
603 }
604
605-void MapView::draw(RenderTarget& dst) {
606- Widelands::EditorGameBase& egbase = intbase_.egbase();
607-
608+void MapView::draw_map_view(const Widelands::EditorGameBase& egbase,
609+ const GameRenderer::Overlays& overlays,
610+ const GameRenderer::DrawImmovables& draw_immovables,
611+ const GameRenderer::DrawBobs& draw_bobs,
612+ const Widelands::Player* player,
613+ RenderTarget* dst) {
614 uint32_t now = SDL_GetTicks();
615 while (!view_plans_.empty()) {
616 auto& plan = view_plans_.front();
617@@ -385,44 +384,15 @@
618 break;
619 }
620
621- if (upcast(Widelands::Game, game, &egbase)) {
622- // Bail out if the game isn't actually loaded.
623- // This fixes a crash with displaying an error dialog during loading.
624- if (!game->is_loaded())
625- return;
626- }
627-
628- TextToDraw text_to_draw = TextToDraw::kNone;
629- auto display_flags = intbase_.get_display_flags();
630- if (display_flags & InteractiveBase::dfShowCensus) {
631- text_to_draw = text_to_draw | TextToDraw::kCensus;
632- }
633- if (display_flags & InteractiveBase::dfShowStatistics) {
634- text_to_draw = text_to_draw | TextToDraw::kStatistics;
635- }
636-
637- if (upcast(InteractivePlayer const, interactive_player, &intbase_)) {
638- const GameRenderer::Overlays overlays{
639- text_to_draw, interactive_player->road_building_preview()};
640- renderer_->rendermap(
641- egbase, view_.viewpoint, view_.zoom, interactive_player->player(), overlays, &dst);
642- } else {
643- const auto draw_immovables = intbase_.draw_immovables() ? GameRenderer::DrawImmovables::kYes :
644- GameRenderer::DrawImmovables::kNo;
645- const auto draw_bobs =
646- intbase_.draw_bobs() ? GameRenderer::DrawBobs::kYes : GameRenderer::DrawBobs::kNo;
647- const GameRenderer::Overlays overlays{static_cast<TextToDraw>(text_to_draw), {}};
648- renderer_->rendermap(
649- egbase, view_.viewpoint, view_.zoom, overlays, draw_immovables, draw_bobs, &dst);
650- }
651+ renderer_->render(
652+ egbase, view_.viewpoint, view_.zoom, player, overlays, draw_immovables, draw_bobs, dst);
653 }
654
655 void MapView::set_view(const View& target_view, const Transition& transition) {
656- const Widelands::Map& map = intbase_.egbase().map();
657 switch (transition) {
658 case Transition::Jump: {
659 view_ = target_view;
660- MapviewPixelFunctions::normalize_pix(map, &view_.viewpoint);
661+ MapviewPixelFunctions::normalize_pix(map_, &view_.viewpoint);
662 changeview();
663 return;
664 }
665@@ -430,7 +400,7 @@
666 case Transition::Smooth: {
667 const TimestampedView current = animation_target_view();
668 const auto plan =
669- plan_map_transition(current.t, map, current.view, target_view, get_w(), get_h());
670+ plan_map_transition(current.t, map_, current.view, target_view, get_w(), get_h());
671 if (!plan.empty()) {
672 view_plans_.push_back(plan);
673 }
674@@ -440,13 +410,12 @@
675 }
676
677 void MapView::scroll_to_field(const Widelands::Coords& c, const Transition& transition) {
678- const Widelands::Map& map = intbase_.egbase().map();
679 assert(0 <= c.x);
680- assert(c.x < map.get_width());
681+ assert(c.x < map_.get_width());
682 assert(0 <= c.y);
683- assert(c.y < map.get_height());
684+ assert(c.y < map_.get_height());
685
686- const Vector2f in_mappixel = MapviewPixelFunctions::to_map_pixel(map.get_fcoords(c));
687+ const Vector2f in_mappixel = MapviewPixelFunctions::to_map_pixel(map_.get_fcoords(c));
688 scroll_to_map_pixel(in_mappixel, transition);
689 }
690
691@@ -458,7 +427,7 @@
692 }
693
694 MapView::ViewArea MapView::view_area() const {
695- return ViewArea(get_view_area(view_, get_w(), get_h()), intbase_.egbase().map());
696+ return ViewArea(get_view_area(view_, get_w(), get_h()), map_);
697 }
698
699 const MapView::View& MapView::view() const {
700@@ -482,8 +451,8 @@
701 bool MapView::handle_mousepress(uint8_t const btn, int32_t const x, int32_t const y) {
702 if (btn == SDL_BUTTON_LEFT) {
703 stop_dragging();
704- track_sel(Vector2i(x, y));
705- fieldclicked();
706+ const auto node_and_triangle = track_sel(Vector2i(x, y));
707+ field_clicked(node_and_triangle);
708 } else if (btn == SDL_BUTTON_RIGHT) {
709 dragging_ = true;
710 grab_mouse(true);
711@@ -513,8 +482,7 @@
712 }
713 }
714
715- if (!intbase_.get_sel_freeze())
716- track_sel(Vector2i(x, y));
717+ track_sel(Vector2i(x, y));
718 return true;
719 }
720
721@@ -571,10 +539,12 @@
722 return !view_plans_.empty() || !mouse_plans_.empty();
723 }
724
725-void MapView::track_sel(const Vector2i& p) {
726+Widelands::NodeAndTriangle<> MapView::track_sel(const Vector2i& p) {
727 Vector2f p_in_map = to_map(p);
728- intbase_.set_sel_pos(MapviewPixelFunctions::calc_node_and_triangle(
729- intbase_.egbase().map(), p_in_map.x, p_in_map.y));
730+ const auto node_and_triangle =
731+ MapviewPixelFunctions::calc_node_and_triangle(map_, p_in_map.x, p_in_map.y);
732+ track_selection(node_and_triangle);
733+ return node_and_triangle;
734 }
735
736 bool MapView::handle_key(bool down, SDL_Keysym code) {
737
738=== modified file 'src/wui/mapview.h'
739--- src/wui/mapview.h 2017-08-17 15:34:45 +0000
740+++ src/wui/mapview.h 2017-08-28 07:40:41 +0000
741@@ -28,12 +28,12 @@
742
743 #include "base/rect.h"
744 #include "base/vector.h"
745+#include "graphic/game_renderer.h"
746 #include "logic/map.h"
747 #include "logic/widelands_geometry.h"
748 #include "ui_basic/panel.h"
749
750 class GameRenderer;
751-class InteractiveBase;
752
753 /**
754 * Implements a view of a map. It is used to render a valid map on the screen.
755@@ -101,18 +101,21 @@
756 };
757
758 MapView(UI::Panel* const parent,
759+ const Widelands::Map& map,
760 const int32_t x,
761 const int32_t y,
762 const uint32_t w,
763- const uint32_t h,
764- InteractiveBase&);
765+ const uint32_t h);
766 virtual ~MapView();
767
768 // Called whenever the view changed, also during automatic animations.
769 boost::signals2::signal<void()> changeview;
770
771 // Called when the user clicked on a field.
772- boost::signals2::signal<void()> fieldclicked;
773+ boost::signals2::signal<void(const Widelands::NodeAndTriangle<>&)> field_clicked;
774+
775+ // Called when the field under the mouse cursor has changed.
776+ boost::signals2::signal<void(const Widelands::NodeAndTriangle<>&)> track_selection;
777
778 // Defines if an animation should be immediate (one-frame) or nicely
779 // animated for the user to follow.
780@@ -156,13 +159,18 @@
781 // True if a 'Transition::Smooth' animation is playing.
782 bool is_animating() const;
783
784- void draw(RenderTarget&) override;
785- bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;
786- bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y) override;
787- bool
788- handle_mousemove(uint8_t state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff) override;
789- bool handle_mousewheel(uint32_t which, int32_t x, int32_t y) override;
790- bool handle_key(bool down, SDL_Keysym code) override;
791+ // Not overriden from UI::Panel, instead we expect to be passed the data through.
792+ void draw_map_view(const Widelands::EditorGameBase& egbase,
793+ const GameRenderer::Overlays& overlays,
794+ const GameRenderer::DrawImmovables& draw_immovables,
795+ const GameRenderer::DrawBobs& draw_bobs,
796+ const Widelands::Player* player,
797+ RenderTarget* dst);
798+ bool handle_mousepress(uint8_t btn, int32_t x, int32_t y);
799+ bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y);
800+ bool handle_mousemove(uint8_t state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff);
801+ bool handle_mousewheel(uint32_t which, int32_t x, int32_t y);
802+ bool handle_key(bool down, SDL_Keysym code);
803
804 private:
805 void stop_dragging();
806@@ -175,14 +183,14 @@
807 // current mouse) if we are not animating.
808 TimestampedMouse animation_target_mouse() const;
809
810- // Move the sel to the given mouse position. Does not honour sel freeze.
811- void track_sel(const Vector2i& m);
812+ // Turns 'm' into the corresponding NodeAndTrinangle and calls 'track_selection'.
813+ Widelands::NodeAndTriangle<> track_sel(const Vector2i& m);
814
815 Vector2f to_panel(const Vector2f& map_pixel) const;
816 Vector2f to_map(const Vector2i& panel_pixel) const;
817
818+ const Widelands::Map& map_;
819 std::unique_ptr<GameRenderer> renderer_;
820- InteractiveBase& intbase_;
821 View view_;
822 Vector2i last_mouse_pos_;
823 bool dragging_;
824
825=== modified file 'src/wui/watchwindow.cc'
826--- src/wui/watchwindow.cc 2017-08-20 17:45:42 +0000
827+++ src/wui/watchwindow.cc 2017-08-28 07:40:41 +0000
828@@ -58,7 +58,7 @@
829 ~WatchWindow();
830
831 Widelands::Game& game() const {
832- return dynamic_cast<InteractiveGameBase&>(*get_parent()).game();
833+ return parent_.game();
834 }
835
836 boost::signals2::signal<void(Vector2f)> warp_mainview;
837@@ -72,6 +72,7 @@
838 protected:
839 void think() override;
840 void stop_tracking_by_drag();
841+ void draw(RenderTarget&) override;
842
843 private:
844 void do_follow();
845@@ -79,7 +80,8 @@
846 void view_button_clicked(uint8_t index);
847 void set_current_view(uint8_t idx, bool save_previous = true);
848
849- MapView mapview_;
850+ InteractiveGameBase& parent_;
851+ MapView map_view_;
852 uint32_t last_visit_;
853 bool single_window_;
854 uint8_t cur_index_;
855@@ -96,7 +98,8 @@
856 uint32_t const h,
857 bool const init_single_window)
858 : UI::Window(&parent, "watch", x, y, w, h, _("Watch")),
859- mapview_(this, 0, 0, 200, 166, parent),
860+ parent_(parent),
861+ map_view_(this, game().map(), 0, 0, 200, 166),
862 last_visit_(game().get_gametime()),
863 single_window_(init_single_window),
864 cur_index_(0) {
865@@ -124,13 +127,25 @@
866 closebtn->sigclicked.connect(boost::bind(&WatchWindow::close_cur_view, this));
867 }
868
869- mapview_.fieldclicked.connect(boost::bind(&InteractiveGameBase::node_action, &parent));
870- mapview_.changeview.connect([this] { stop_tracking_by_drag(); });
871+ map_view_.field_clicked.connect([&parent](const Widelands::NodeAndTriangle<>& node_and_triangle) {
872+ parent.map_view()->field_clicked(node_and_triangle);
873+ });
874+ map_view_.track_selection.connect([&parent](const Widelands::NodeAndTriangle<>& node_and_triangle) {
875+ parent.map_view()->track_selection(node_and_triangle);
876+ });
877+ map_view_.changeview.connect([this] { stop_tracking_by_drag(); });
878 warp_mainview.connect([&parent](const Vector2f& map_pixel) {
879 parent.map_view()->scroll_to_map_pixel(map_pixel, MapView::Transition::Smooth);
880 });
881 }
882
883+void WatchWindow::draw(RenderTarget& dst) {
884+ UI::Window::draw(dst);
885+ if (!is_minimal()) {
886+ parent_.draw_map_view(&map_view_, &dst);
887+ }
888+}
889+
890 /**
891 * Add a view to a watchwindow, if there is space left.
892 *
893@@ -141,10 +156,10 @@
894 return;
895 WatchWindowView view;
896
897- mapview_.scroll_to_field(coords, MapView::Transition::Jump);
898+ map_view_.scroll_to_field(coords, MapView::Transition::Jump);
899
900 view.tracking = nullptr;
901- view.view = mapview_.view();
902+ view.view = map_view_.view();
903 last_visit_ = game().get_gametime();
904
905 views_.push_back(view);
906@@ -161,7 +176,7 @@
907 // Saves the coordinates of a view if it was already shown (and possibly moved)
908 void WatchWindow::save_coords() {
909 auto& view = views_[cur_index_];
910- view.view = mapview_.view();
911+ view.view = map_view_.view();
912 }
913
914 // Enables/Disables buttons for views_
915@@ -188,7 +203,7 @@
916 view_btns_[idx]->set_perm_pressed(true);
917 }
918 cur_index_ = idx;
919- mapview_.set_view(views_[cur_index_].view, MapView::Transition::Jump);
920+ map_view_.set_view(views_[cur_index_].view, MapView::Transition::Jump);
921 }
922
923 WatchWindow::~WatchWindow() {
924@@ -197,7 +212,7 @@
925
926 /*
927 ===============
928-Update the mapview_ if we're tracking something.
929+Update the map_view_ if we're tracking something.
930 ===============
931 */
932 void WatchWindow::think() {
933@@ -220,19 +235,19 @@
934 // Not in sight
935 views_[cur_index_].tracking = nullptr;
936 } else {
937- mapview_.scroll_to_map_pixel(pos, MapView::Transition::Jump);
938+ map_view_.scroll_to_map_pixel(pos, MapView::Transition::Jump);
939 }
940 }
941 }
942
943 /*
944 ===============
945-When the user drags the mapview_, we stop tracking.
946+When the user drags the map_view_, we stop tracking.
947 ===============
948 */
949 void WatchWindow::stop_tracking_by_drag() {
950 // Disable switching while dragging
951- if (mapview_.is_dragging()) {
952+ if (map_view_.is_dragging()) {
953 last_visit_ = game().get_gametime();
954 views_[cur_index_].tracking = nullptr;
955 }
956@@ -251,7 +266,7 @@
957 } else {
958 // Find the nearest bob. Other object types can not move and are
959 // therefore not of interest.
960- Vector2f center_map_pixel = mapview_.view_area().rect().center();
961+ Vector2f center_map_pixel = map_view_.view_area().rect().center();
962 const Widelands::Map& map = g.map();
963 MapviewPixelFunctions::normalize_pix(map, &center_map_pixel);
964 std::vector<Widelands::Bob*> bobs;
965@@ -289,10 +304,10 @@
966 /**
967 * Called when the "go to" button is clicked.
968 *
969- * Cause the main mapview_ to jump to our current position.
970+ * Cause the main map_view_ to jump to our current position.
971 */
972 void WatchWindow::do_goto() {
973- warp_mainview(mapview_.view_area().rect().center());
974+ warp_mainview(map_view_.view_area().rect().center());
975 }
976
977 /**

Subscribers

People subscribed via source and target branches

to status/vote changes: