Merge lp:~widelands-dev/widelands/bug-1796364-blinking-buildings into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 9000
Proposed branch: lp:~widelands-dev/widelands/bug-1796364-blinking-buildings
Merge into: lp:widelands
Diff against target: 1092 lines (+272/-221)
32 files modified
src/economy/flag.h (+6/-2)
src/economy/portdock.cc (+1/-1)
src/economy/portdock.h (+5/-2)
src/economy/road.h (+5/-2)
src/editor/editorinteractive.cc (+2/-4)
src/logic/CMakeLists.txt (+2/-0)
src/logic/map_objects/bob.cc (+1/-0)
src/logic/map_objects/bob.h (+6/-2)
src/logic/map_objects/draw_text.h (+43/-0)
src/logic/map_objects/immovable.cc (+13/-31)
src/logic/map_objects/immovable.h (+13/-7)
src/logic/map_objects/map_object.cc (+35/-4)
src/logic/map_objects/map_object.h (+9/-6)
src/logic/map_objects/tribes/building.cc (+23/-4)
src/logic/map_objects/tribes/building.h (+9/-2)
src/logic/map_objects/tribes/constructionsite.cc (+4/-0)
src/logic/map_objects/tribes/constructionsite.h (+5/-2)
src/logic/map_objects/tribes/dismantlesite.cc (+4/-0)
src/logic/map_objects/tribes/dismantlesite.h (+5/-2)
src/logic/map_objects/tribes/ship.cc (+21/-19)
src/logic/map_objects/tribes/ship.h (+7/-1)
src/logic/map_objects/tribes/soldier.cc (+1/-0)
src/logic/map_objects/tribes/soldier.h (+1/-0)
src/logic/map_objects/tribes/worker.cc (+1/-0)
src/logic/map_objects/tribes/worker.h (+1/-0)
src/wui/interactive_base.cc (+1/-1)
src/wui/interactive_base.h (+0/-10)
src/wui/interactive_gamebase.cc (+0/-68)
src/wui/interactive_gamebase.h (+0/-7)
src/wui/interactive_player.cc (+40/-31)
src/wui/interactive_spectator.cc (+2/-11)
src/wui/transport_draw.cc (+6/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1796364-blinking-buildings
Reviewer Review Type Date Requested Status
hessenfarmer playtest Approve
Klaus Halfmann debug Abstain
Review via email: mp+359348@code.launchpad.net

Commit message

Remove z-layering fix for building texts introduced in r8847 because it is buggy and can make building animations disappear

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

Continuous integration builds have changed state:

Travis build 4280. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/459059413.
Appveyor build 4074. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1796364_blinking_buildings-4074.

Revision history for this message
Arty (artydent) wrote :

Started reviewing the code. Have one diff comment so far. Will continue later tonight.

Revision history for this message
Arty (artydent) wrote :

I finished looking over it but admittedly not too deeply because it's just old code re-enabled. Code looks fine (aside from the ~ operator mentioned in the diff comment).

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have added some asserts to the ~ operator and a comment to the enum class.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4330. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/467624954.
Appveyor build 4125. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1796364_blinking_buildings-4125.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Hmm I don get these travis Errors,
one looks like a timeout, next one hapens only att a pecific compile?

/home/travis/build/widelands/widelands/doc/sphinx/source/autogen_ai_hints.rst:117:
Definition list ends without a blank line; unexpected unindent.

Will try to test this anyway

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Uhm, the savegame fails me:
Assertion failed: (result >= 0), function operator~, file ../src/logic/map_objects/draw_text.h, line 38.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Oops was killed with:
Assertion failed: (result >= 0), function operator~, file
../src/logic/map_objects/draw_text.h, line 38.

will ty to reproduce this in a debugger.

review: Needs Fixing (testplay)
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

I attached a Debuugger and starte to play my latest youtube Video:
https://www.magentacloud.de/share/tu4ayusx.k
   Fie_: FRI01_H50_End.wgf

The asser ht me amost immediatedly when Itried to open the Map.

The TextToDraw Enum was 3 which is out of range, hence the assert.

Gun: I assume he latest merge to trunk broke something?

As I have never seen this blinking anywhere I hae no idea
what do about this now. Maybe it does not happen on OSX?

Benedikt: can you provide a videdo of this blinking?

review: Abstain (debug)
Revision history for this message
kaputtnik (franku) wrote :

A video is added to the bugreport in comment 1.

I have merged trunk into this branch, so appveyor should give a windows executable.

Funnily playing the saved game, with was saved with revision r8874, do work with this branch after merging trunk (so r8913).

Didn't saw those blinking buildings also.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Oops, Benedikt is playing in Frisian/Platdütsch that complicates the Issue :-)

I pulled the branch again and will try tommorow, hopefully merging trunk fixed
the Assertion.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4385. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/475766568.
Appveyor build 4177. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1796364_blinking_buildings-4177.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

A Debug builds now shows this, too:

https://travis-ci.org/widelands/widelands/jobs/475766582
widelands: /home/travis/build/widelands/widelands/src/logic/map_objects/draw_text.h:38:
TextToDraw operator~(TextToDraw): Assertion `result >= 0' failed.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I could reproduce the assert error and it should be fixed now.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4437. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/490952737.
Appveyor build 4225. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1796364_blinking_buildings-4225.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4473. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/493472851.
Appveyor build 4261. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1796364_blinking_buildings-4261.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

I will test a windows debug build tonight.

@ Klaus could you test this another time as well?

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Tested with the latest win debug build from appveyor.

no crashes and I couldn't see any blinking buildings or similar.

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

Continuous integration builds have changed state:

Travis build 4536. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/499415843.
Appveyor build 4323. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1796364_blinking_buildings-4323.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

@GunChleoc

From my side this is ready to merge. Travis is not green due to a transient failure.
But as I am not an expert for this code I'll leave the decision for merging to you

Revision history for this message
GunChleoc (gunchleoc) wrote :

I overlooked that Arty had already done a code review. So, this is ready now, thanks

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 4536. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/499415843.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

@bunnybot merge force

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/economy/flag.h'
2--- src/economy/flag.h 2019-02-23 11:00:49 +0000
3+++ src/economy/flag.h 2019-02-27 17:20:33 +0000
4@@ -26,6 +26,7 @@
5
6 #include "base/macros.h"
7 #include "economy/routing_node.h"
8+#include "logic/map_objects/draw_text.h"
9 #include "logic/map_objects/immovable.h"
10 #include "logic/map_objects/walkingdir.h"
11
12@@ -152,8 +153,11 @@
13 bool init(EditorGameBase&) override;
14 void cleanup(EditorGameBase&) override;
15
16- void
17- draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;
18+ void draw(uint32_t gametime,
19+ TextToDraw draw_text,
20+ const Vector2f& point_on_dst,
21+ float scale,
22+ RenderTarget* dst) override;
23
24 void wake_up_capacity_queue(Game&);
25
26
27=== modified file 'src/economy/portdock.cc'
28--- src/economy/portdock.cc 2019-02-23 11:00:49 +0000
29+++ src/economy/portdock.cc 2019-02-27 17:20:33 +0000
30@@ -140,7 +140,7 @@
31 expedition_bootstrap_->set_economy(e);
32 }
33
34-void PortDock::draw(uint32_t, const Vector2f&, float, RenderTarget*) {
35+void PortDock::draw(uint32_t, const TextToDraw, const Vector2f&, float, RenderTarget*) {
36 // do nothing
37 }
38
39
40=== modified file 'src/economy/portdock.h'
41--- src/economy/portdock.h 2019-02-23 11:00:49 +0000
42+++ src/economy/portdock.h 2019-02-27 17:20:33 +0000
43@@ -96,8 +96,11 @@
44
45 Flag& base_flag() override;
46 PositionList get_positions(const EditorGameBase&) const override;
47- void
48- draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;
49+ void draw(uint32_t gametime,
50+ TextToDraw draw_text,
51+ const Vector2f& point_on_dst,
52+ float scale,
53+ RenderTarget* dst) override;
54
55 bool init(EditorGameBase&) override;
56 void cleanup(EditorGameBase&) override;
57
58=== modified file 'src/economy/road.h'
59--- src/economy/road.h 2019-02-23 11:00:49 +0000
60+++ src/economy/road.h 2019-02-27 17:20:33 +0000
61@@ -130,8 +130,11 @@
62 bool init(EditorGameBase&) override;
63 void cleanup(EditorGameBase&) override;
64
65- void
66- draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;
67+ void draw(uint32_t gametime,
68+ TextToDraw draw_text,
69+ const Vector2f& point_on_dst,
70+ float scale,
71+ RenderTarget* dst) override;
72
73 private:
74 void set_path(EditorGameBase&, const Path&);
75
76=== modified file 'src/editor/editorinteractive.cc'
77--- src/editor/editorinteractive.cc 2019-02-23 11:00:49 +0000
78+++ src/editor/editorinteractive.cc 2019-02-27 17:20:33 +0000
79@@ -300,14 +300,14 @@
80 if (draw_immovables_) {
81 Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();
82 if (imm != nullptr && imm->get_positions(ebase).front() == field.fcoords) {
83- imm->draw(gametime, field.rendertarget_pixel, scale, &dst);
84+ imm->draw(gametime, TextToDraw::kNone, field.rendertarget_pixel, scale, &dst);
85 }
86 }
87
88 if (draw_bobs_) {
89 for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;
90 bob = bob->get_next_bob()) {
91- bob->draw(ebase, field.rendertarget_pixel, scale, &dst);
92+ bob->draw(ebase, TextToDraw::kNone, field.rendertarget_pixel, scale, &dst);
93 }
94 }
95
96@@ -376,8 +376,6 @@
97 }
98 }
99 }
100- // TODO(GunChleoc): If we ever implement an infrastructure tool, the building texts will need to
101- // be blitted here.
102 }
103
104 /// Needed to get freehand painting tools (hold down mouse and move to edit).
105
106=== modified file 'src/logic/CMakeLists.txt'
107--- src/logic/CMakeLists.txt 2018-11-13 12:18:10 +0000
108+++ src/logic/CMakeLists.txt 2019-02-27 17:20:33 +0000
109@@ -186,6 +186,7 @@
110 map_objects/buildcost.h
111 map_objects/checkstep.cc
112 map_objects/checkstep.h
113+ map_objects/draw_text.h
114 map_objects/immovable.cc
115 map_objects/immovable.h
116 map_objects/immovable_program.h
117@@ -279,6 +280,7 @@
118 game_io
119 graphic
120 graphic_color
121+ graphic_fonthandler
122 graphic_image_io
123 graphic_playercolor
124 graphic_surface
125
126=== modified file 'src/logic/map_objects/bob.cc'
127--- src/logic/map_objects/bob.cc 2019-02-23 11:00:49 +0000
128+++ src/logic/map_objects/bob.cc 2019-02-27 17:20:33 +0000
129@@ -757,6 +757,7 @@
130 /// Note that the current node is actually the node that we are walking to, not
131 /// the the one that we start from.
132 void Bob::draw(const EditorGameBase& egbase,
133+ const TextToDraw&,
134 const Vector2f& field_on_dst,
135 const float scale,
136 RenderTarget* dst) const {
137
138=== modified file 'src/logic/map_objects/bob.h'
139--- src/logic/map_objects/bob.h 2019-02-23 11:00:49 +0000
140+++ src/logic/map_objects/bob.h 2019-02-27 17:20:33 +0000
141@@ -25,6 +25,7 @@
142 #include "economy/route.h"
143 #include "graphic/animation.h"
144 #include "graphic/diranimations.h"
145+#include "logic/map_objects/draw_text.h"
146 #include "logic/map_objects/map_object.h"
147 #include "logic/map_objects/walkingdir.h"
148 #include "logic/widelands_geometry.h"
149@@ -262,8 +263,11 @@
150 // the field associated with this bob (if it is walking, that is its
151 // starting field) in pixel space of 'dst' (including scale). The 'scale' is
152 // required to draw the bob in the right size.
153- virtual void
154- draw(const EditorGameBase&, const Vector2f& field_on_dst, float scale, RenderTarget* dst) const;
155+ virtual void draw(const EditorGameBase&,
156+ const TextToDraw& draw_text,
157+ const Vector2f& field_on_dst,
158+ float scale,
159+ RenderTarget* dst) const;
160
161 // For debug
162 void log_general_info(const EditorGameBase&) const override;
163
164=== added file 'src/logic/map_objects/draw_text.h'
165--- src/logic/map_objects/draw_text.h 1970-01-01 00:00:00 +0000
166+++ src/logic/map_objects/draw_text.h 2019-02-27 17:20:33 +0000
167@@ -0,0 +1,43 @@
168+/*
169+ * Copyright (C) 2006-2018 by the Widelands Development Team
170+ *
171+ * This program is free software; you can redistribute it and/or
172+ * modify it under the terms of the GNU General Public License
173+ * as published by the Free Software Foundation; either version 2
174+ * of the License, or (at your option) any later version.
175+ *
176+ * This program is distributed in the hope that it will be useful,
177+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
178+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
179+ * GNU General Public License for more details.
180+ *
181+ * You should have received a copy of the GNU General Public License
182+ * along with this program; if not, write to the Free Software
183+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
184+ *
185+ */
186+
187+#ifndef WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H
188+#define WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H
189+
190+// Only declare powers of 2 and adjust the ~ operator below if you add any values to this enum class.
191+enum class TextToDraw {
192+ kNone = 0,
193+ kCensus = 1,
194+ kStatistics = 2,
195+};
196+
197+inline TextToDraw operator|(TextToDraw a, TextToDraw b) {
198+ return static_cast<TextToDraw>(static_cast<int>(a) | static_cast<int>(b));
199+}
200+inline TextToDraw operator&(TextToDraw a, TextToDraw b) {
201+ return static_cast<TextToDraw>(static_cast<int>(a) & static_cast<int>(b));
202+}
203+inline TextToDraw removeFromTextToDraw(TextToDraw base, TextToDraw remove) {
204+ const int result = static_cast<int>(base) & ~static_cast<int>(remove);
205+ assert(result >= 0);
206+ assert(result <= 2);
207+ return static_cast<TextToDraw>(result);
208+}
209+
210+#endif // end of include guard: WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H
211
212=== modified file 'src/logic/map_objects/immovable.cc'
213--- src/logic/map_objects/immovable.cc 2019-02-23 11:00:49 +0000
214+++ src/logic/map_objects/immovable.cc 2019-02-27 17:20:33 +0000
215@@ -454,6 +454,7 @@
216 }
217
218 void Immovable::draw(uint32_t gametime,
219+ const TextToDraw draw_text,
220 const Vector2f& point_on_dst,
221 float scale,
222 RenderTarget* dst) {
223@@ -462,12 +463,16 @@
224 }
225 if (!anim_construction_total_) {
226 dst->blit_animation(point_on_dst, scale, anim_, gametime - animstart_);
227+ if (former_building_descr_) {
228+ do_draw_info(draw_text, former_building_descr_->descname(), "", point_on_dst, scale, dst);
229+ }
230 } else {
231- draw_construction(gametime, point_on_dst, scale, dst);
232+ draw_construction(gametime, draw_text, point_on_dst, scale, dst);
233 }
234 }
235
236 void Immovable::draw_construction(const uint32_t gametime,
237+ const TextToDraw draw_text,
238 const Vector2f& point_on_dst,
239 const float scale,
240 RenderTarget* dst) {
241@@ -506,6 +511,13 @@
242
243 dst->blit_animation(
244 point_on_dst, scale, anim_, current_frame * frametime, player_color, percent);
245+
246+ // Additionally, if statistics are enabled, draw a progression string
247+ do_draw_info(draw_text, descr().descname(),
248+ (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %
249+ (boost::format(_("%i%% built")) % (100 * done / total)).str())
250+ .str(),
251+ point_on_dst, scale, dst);
252 }
253
254 /**
255@@ -517,36 +529,6 @@
256 action_data_.reset(data);
257 }
258
259-std::string Immovable::info_string(const MapObject::InfoStringType format) {
260- std::string result;
261- switch (format) {
262- case MapObject::InfoStringType::kCensus:
263- if (!anim_construction_total_) {
264- if (former_building_descr_) {
265- result = former_building_descr_->descname();
266- }
267- } else {
268- result = descr().descname();
269- }
270- break;
271- case MapObject::InfoStringType::kStatistics:
272- if (anim_construction_total_) {
273- result = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %
274- (boost::format(_("%i%% built")) %
275- (100 * anim_construction_done_ / anim_construction_total_))
276- .str())
277- .str();
278- } else {
279- result = "";
280- }
281- break;
282- case MapObject::InfoStringType::kTooltip:
283- result = "";
284- break;
285- }
286- return result;
287-}
288-
289 /*
290 ==============================
291
292
293=== modified file 'src/logic/map_objects/immovable.h'
294--- src/logic/map_objects/immovable.h 2019-02-23 11:00:49 +0000
295+++ src/logic/map_objects/immovable.h 2019-02-27 17:20:33 +0000
296@@ -26,6 +26,7 @@
297 #include "base/macros.h"
298 #include "graphic/animation.h"
299 #include "logic/map_objects/buildcost.h"
300+#include "logic/map_objects/draw_text.h"
301 #include "logic/map_objects/map_object.h"
302 #include "logic/widelands_geometry.h"
303 #include "notifications/note_ids.h"
304@@ -96,13 +97,16 @@
305 virtual PositionList get_positions(const EditorGameBase&) const = 0;
306
307 // Draw this immovable onto 'dst' choosing the frame appropriate for
308- // 'gametime'.
309+ // 'gametime'. 'draw_text' decides if census and statistics are written too.
310 // The 'coords_to_draw' are passed one to give objects that occupy multiple
311 // fields a way to only draw themselves once. The 'point_on_dst' determines
312 // the point for the hotspot of the animation and 'scale' determines how big
313 // the immovable will be plotted.
314- virtual void
315- draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) = 0;
316+ virtual void draw(uint32_t gametime,
317+ TextToDraw draw_text,
318+ const Vector2f& point_on_dst,
319+ float scale,
320+ RenderTarget* dst) = 0;
321
322 static int32_t string_to_size(const std::string& size);
323 static std::string size_to_string(int32_t size);
324@@ -223,8 +227,11 @@
325 bool init(EditorGameBase&) override;
326 void cleanup(EditorGameBase&) override;
327 void act(Game&, uint32_t data) override;
328- void
329- draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;
330+ void draw(uint32_t gametime,
331+ TextToDraw draw_text,
332+ const Vector2f& point_on_dst,
333+ float scale,
334+ RenderTarget* dst) override;
335
336 void switch_program(Game& game, const std::string& programname);
337 bool construct_ware(Game& game, DescriptionIndex index);
338@@ -240,8 +247,6 @@
339 return nullptr;
340 }
341
342- std::string info_string(MapObject::InfoStringType format) override;
343-
344 protected:
345 // The building type that created this immovable, if any.
346 const BuildingDescr* former_building_descr_;
347@@ -309,6 +314,7 @@
348
349 void increment_program_pointer();
350 void draw_construction(uint32_t gametime,
351+ TextToDraw draw_text,
352 const Vector2f& point_on_dst,
353 float scale,
354 RenderTarget* dst);
355
356=== modified file 'src/logic/map_objects/map_object.cc'
357--- src/logic/map_objects/map_object.cc 2019-02-23 11:00:49 +0000
358+++ src/logic/map_objects/map_object.cc 2019-02-27 17:20:33 +0000
359@@ -29,6 +29,7 @@
360
361 #include "base/log.h"
362 #include "base/wexception.h"
363+#include "graphic/font_handler.h"
364 #include "graphic/graphic.h"
365 #include "graphic/rendertarget.h"
366 #include "graphic/text_layout.h"
367@@ -474,6 +475,40 @@
368 egbase.objects().remove(*this);
369 }
370
371+void MapObject::do_draw_info(const TextToDraw& draw_text,
372+ const std::string& census,
373+ const std::string& statictics,
374+ const Vector2f& field_on_dst,
375+ float scale,
376+ RenderTarget* dst) const {
377+ if (draw_text == TextToDraw::kNone) {
378+ return;
379+ }
380+
381+ // Rendering text is expensive, so let's just do it for only a few sizes.
382+ // The formula is a bit fancy to avoid too much text overlap.
383+ scale = std::round(2.f * (scale > 1.f ? std::sqrt(scale) : std::pow(scale, 2.f))) / 2.f;
384+ if (scale < 1.f) {
385+ return;
386+ }
387+ const int font_size = scale * UI_FONT_SIZE_SMALL;
388+
389+ // We always render this so we can have a stable position for the statistics string.
390+ std::shared_ptr<const UI::RenderedText> rendered_census =
391+ UI::g_fh->render(as_condensed(census, UI::Align::kCenter, font_size), 120 * scale);
392+ Vector2i position = field_on_dst.cast<int>() - Vector2i(0, 48) * scale;
393+ if ((draw_text & TextToDraw::kCensus) != TextToDraw::kNone) {
394+ rendered_census->draw(*dst, position, UI::Align::kCenter);
395+ }
396+
397+ if ((draw_text & TextToDraw::kStatistics) != TextToDraw::kNone && !statictics.empty()) {
398+ std::shared_ptr<const UI::RenderedText> rendered_statistics =
399+ UI::g_fh->render(as_condensed(statictics, UI::Align::kCenter, font_size));
400+ position.y += rendered_census->height() + text_height(font_size) / 4;
401+ rendered_statistics->draw(*dst, position, UI::Align::kCenter);
402+ }
403+}
404+
405 const Image* MapObject::representative_image() const {
406 return descr().representative_image(get_owner() ? &get_owner()->get_playercolor() : nullptr);
407 }
408@@ -545,10 +580,6 @@
409 reserved_by_worker_ = reserve;
410 }
411
412-std::string MapObject::info_string(const InfoStringType) {
413- return "";
414-}
415-
416 constexpr uint8_t kCurrentPacketVersionMapObject = 2;
417
418 /**
419
420=== modified file 'src/logic/map_objects/map_object.h'
421--- src/logic/map_objects/map_object.h 2019-02-23 11:00:49 +0000
422+++ src/logic/map_objects/map_object.h 2019-02-27 17:20:33 +0000
423@@ -35,6 +35,7 @@
424 #include "graphic/color.h"
425 #include "graphic/image.h"
426 #include "logic/cmd_queue.h"
427+#include "logic/map_objects/draw_text.h"
428 #include "logic/map_objects/tribes/training_attribute.h"
429 #include "logic/widelands.h"
430 #include "scripting/lua_table.h"
431@@ -339,12 +340,6 @@
432 */
433 void set_reserved_by_worker(bool reserve);
434
435- enum class InfoStringType { kCensus, kStatistics, kTooltip };
436- /**
437- * Returns a census, statistics or tooltip string to be shown for this object on the map
438- */
439- virtual std::string info_string(InfoStringType);
440-
441 /**
442 * Static load functions of derived classes will return a pointer to
443 * a Loader class. The caller needs to call the virtual functions
444@@ -411,6 +406,14 @@
445
446 virtual void cleanup(EditorGameBase&);
447
448+ /// Draws census and statistics on screen
449+ void do_draw_info(const TextToDraw& draw_text,
450+ const std::string& census,
451+ const std::string& statictics,
452+ const Vector2f& field_on_dst,
453+ const float scale,
454+ RenderTarget* dst) const;
455+
456 #ifdef _WIN32
457 void molog(char const* fmt, ...) const __attribute__((format(gnu_printf, 2, 3)));
458 #else
459
460=== modified file 'src/logic/map_objects/tribes/building.cc'
461--- src/logic/map_objects/tribes/building.cc 2019-02-23 11:00:49 +0000
462+++ src/logic/map_objects/tribes/building.cc 2019-02-27 17:20:33 +0000
463@@ -463,20 +463,20 @@
464 }
465 }
466
467-std::string Building::info_string(const MapObject::InfoStringType format) {
468+std::string Building::info_string(const InfoStringFormat& format) {
469 std::string result;
470 switch (format) {
471- case MapObject::InfoStringType::kCensus:
472+ case InfoStringFormat::kCensus:
473 if (upcast(ConstructionSite const, constructionsite, this)) {
474 result = constructionsite->building().descname();
475 } else {
476 result = descr().descname();
477 }
478 break;
479- case MapObject::InfoStringType::kStatistics:
480+ case InfoStringFormat::kStatistics:
481 result = update_and_get_statistics_string();
482 break;
483- case MapObject::InfoStringType::kTooltip:
484+ case InfoStringFormat::kTooltip:
485 if (upcast(ProductionSite const, productionsite, this)) {
486 result = productionsite->production_result();
487 }
488@@ -606,6 +606,7 @@
489 }
490
491 void Building::draw(uint32_t gametime,
492+ const TextToDraw draw_text,
493 const Vector2f& point_on_dst,
494 const float scale,
495 RenderTarget* dst) {
496@@ -613,6 +614,24 @@
497 point_on_dst, scale, anim_, gametime - animstart_, get_owner()->get_playercolor());
498
499 // door animation?
500+
501+ // overlay strings (draw when enabled)
502+ draw_info(draw_text, point_on_dst, scale, dst);
503+}
504+
505+/*
506+===============
507+Draw overlay help strings when enabled.
508+===============
509+*/
510+void Building::draw_info(const TextToDraw draw_text,
511+ const Vector2f& point_on_dst,
512+ const float scale,
513+ RenderTarget* dst) {
514+ const std::string statistics_string =
515+ ((draw_text & TextToDraw::kStatistics) != TextToDraw::kNone) ? info_string(InfoStringFormat::kStatistics) : "";
516+ do_draw_info(draw_text, info_string(InfoStringFormat::kCensus), statistics_string, point_on_dst,
517+ scale, dst);
518 }
519
520 int32_t
521
522=== modified file 'src/logic/map_objects/tribes/building.h'
523--- src/logic/map_objects/tribes/building.h 2019-02-23 11:00:49 +0000
524+++ src/logic/map_objects/tribes/building.h 2019-02-27 17:20:33 +0000
525@@ -227,6 +227,8 @@
526 using FormerBuildings = std::vector<DescriptionIndex>;
527
528 public:
529+ enum class InfoStringFormat { kCensus, kStatistics, kTooltip };
530+
531 explicit Building(const BuildingDescr&);
532
533 void load_finish(EditorGameBase&) override;
534@@ -242,7 +244,7 @@
535 }
536 PositionList get_positions(const EditorGameBase&) const override;
537
538- std::string info_string(MapObject::InfoStringType format) override;
539+ std::string info_string(const InfoStringFormat& format);
540
541 // Return the overlay string that is displayed on the map view when enabled
542 // by the player.
543@@ -337,8 +339,13 @@
544 void cleanup(EditorGameBase&) override;
545 void act(Game&, uint32_t data) override;
546
547+ void draw(uint32_t gametime,
548+ TextToDraw draw_text,
549+ const Vector2f& point_on_dst,
550+ float scale,
551+ RenderTarget* dst) override;
552 void
553- draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;
554+ draw_info(TextToDraw draw_text, const Vector2f& point_on_dst, float scale, RenderTarget* dst);
555
556 void set_seeing(bool see);
557 void set_attack_target(AttackTarget* new_attack_target);
558
559=== modified file 'src/logic/map_objects/tribes/constructionsite.cc'
560--- src/logic/map_objects/tribes/constructionsite.cc 2019-02-23 11:00:49 +0000
561+++ src/logic/map_objects/tribes/constructionsite.cc 2019-02-27 17:20:33 +0000
562@@ -337,6 +337,7 @@
563 ===============
564 */
565 void ConstructionSite::draw(uint32_t gametime,
566+ TextToDraw draw_text,
567 const Vector2f& point_on_dst,
568 float scale,
569 RenderTarget* dst) {
570@@ -358,5 +359,8 @@
571 }
572
573 info_.draw(point_on_dst, scale, player_color, dst);
574+
575+ // Draw help strings
576+ draw_info(draw_text, point_on_dst, scale, dst);
577 }
578 } // namespace Widelands
579
580=== modified file 'src/logic/map_objects/tribes/constructionsite.h'
581--- src/logic/map_objects/tribes/constructionsite.h 2019-02-23 11:00:49 +0000
582+++ src/logic/map_objects/tribes/constructionsite.h 2019-02-27 17:20:33 +0000
583@@ -120,8 +120,11 @@
584
585 static void wares_queue_callback(Game&, InputQueue*, DescriptionIndex, Worker*, void* data);
586
587- void
588- draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;
589+ void draw(uint32_t gametime,
590+ TextToDraw draw_text,
591+ const Vector2f& point_on_dst,
592+ float scale,
593+ RenderTarget* dst) override;
594
595 private:
596 int32_t fetchfromflag_; // # of wares to fetch from flag
597
598=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
599--- src/logic/map_objects/tribes/dismantlesite.cc 2019-02-23 11:00:49 +0000
600+++ src/logic/map_objects/tribes/dismantlesite.cc 2019-02-27 17:20:33 +0000
601@@ -217,6 +217,7 @@
602 ===============
603 */
604 void DismantleSite::draw(uint32_t gametime,
605+ const TextToDraw draw_text,
606 const Vector2f& point_on_dst,
607 float scale,
608 RenderTarget* dst) {
609@@ -229,5 +230,8 @@
610 // Blit bottom part of the animation according to dismantle progress
611 dst->blit_animation(point_on_dst, scale, building_->get_unoccupied_animation(), tanim,
612 player_color, 100 - ((get_built_per64k() * 100) >> 16));
613+
614+ // Draw help strings
615+ draw_info(draw_text, point_on_dst, scale, dst);
616 }
617 } // namespace Widelands
618
619=== modified file 'src/logic/map_objects/tribes/dismantlesite.h'
620--- src/logic/map_objects/tribes/dismantlesite.h 2019-02-23 11:00:49 +0000
621+++ src/logic/map_objects/tribes/dismantlesite.h 2019-02-27 17:20:33 +0000
622@@ -87,8 +87,11 @@
623 return DISMANTLESITE_STEP_TIME;
624 }
625
626- void
627- draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;
628+ void draw(uint32_t gametime,
629+ TextToDraw draw_text,
630+ const Vector2f& point_on_dst,
631+ float scale,
632+ RenderTarget* dst) override;
633 };
634 } // namespace Widelands
635
636
637=== modified file 'src/logic/map_objects/tribes/ship.cc'
638--- src/logic/map_objects/tribes/ship.cc 2019-02-23 11:00:49 +0000
639+++ src/logic/map_objects/tribes/ship.cc 2019-02-27 17:20:33 +0000
640@@ -977,53 +977,55 @@
641 ship_wakeup(game);
642 }
643
644-std::string Ship::info_string(const MapObject::InfoStringType format) {
645+void Ship::draw(const EditorGameBase& egbase,
646+ const TextToDraw& draw_text,
647+ const Vector2f& field_on_dst,
648+ const float scale,
649+ RenderTarget* dst) const {
650+ Bob::draw(egbase, draw_text, field_on_dst, scale, dst);
651+
652 // Show ship name and current activity
653- std::string result;
654- switch (format) {
655- case MapObject::InfoStringType::kCensus:
656- result = shipname_;
657- break;
658- case MapObject::InfoStringType::kStatistics: {
659+ std::string statistics_string;
660+ if ((draw_text & TextToDraw::kStatistics) != TextToDraw::kNone) {
661 switch (ship_state_) {
662 case (ShipStates::kTransport):
663 if (destination_.is_set()) {
664 /** TRANSLATORS: This is a ship state. The ship is currently transporting wares. */
665- result = pgettext("ship_state", "Shipping");
666+ statistics_string = pgettext("ship_state", "Shipping");
667 } else {
668 /** TRANSLATORS: This is a ship state. The ship is ready to transport wares, but has
669 * nothing to do. */
670- result = pgettext("ship_state", "Idle");
671+ statistics_string = pgettext("ship_state", "Idle");
672 }
673 break;
674 case (ShipStates::kExpeditionWaiting):
675 /** TRANSLATORS: This is a ship state. An expedition is waiting for your commands. */
676- result = pgettext("ship_state", "Waiting");
677+ statistics_string = pgettext("ship_state", "Waiting");
678 break;
679 case (ShipStates::kExpeditionScouting):
680 /** TRANSLATORS: This is a ship state. An expedition is scouting for port spaces. */
681- result = pgettext("ship_state", "Scouting");
682+ statistics_string = pgettext("ship_state", "Scouting");
683 break;
684 case (ShipStates::kExpeditionPortspaceFound):
685 /** TRANSLATORS: This is a ship state. An expedition has found a port space. */
686- result = pgettext("ship_state", "Port Space Found");
687+ statistics_string = pgettext("ship_state", "Port Space Found");
688 break;
689 case (ShipStates::kExpeditionColonizing):
690 /** TRANSLATORS: This is a ship state. An expedition is unloading wares/workers to build a
691 * port. */
692- result = pgettext("ship_state", "Founding a Colony");
693+ statistics_string = pgettext("ship_state", "Founding a Colony");
694 break;
695 case (ShipStates::kSinkRequest):
696 case (ShipStates::kSinkAnimation):
697 break;
698 }
699- result =
700- (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_OK.hex_value() % result).str();
701- } break;
702- case MapObject::InfoStringType::kTooltip:
703- result = "";
704+ statistics_string = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_OK.hex_value() %
705+ statistics_string)
706+ .str();
707 }
708- return result;
709+
710+ do_draw_info(draw_text, shipname_, statistics_string, calc_drawpos(egbase, field_on_dst, scale),
711+ scale, dst);
712 }
713
714 void Ship::log_general_info(const EditorGameBase& egbase) const {
715
716=== modified file 'src/logic/map_objects/tribes/ship.h'
717--- src/logic/map_objects/tribes/ship.h 2019-02-23 11:00:49 +0000
718+++ src/logic/map_objects/tribes/ship.h 2019-02-27 17:20:33 +0000
719@@ -230,7 +230,13 @@
720
721 void exp_cancel(Game&);
722 void sink_ship(Game&);
723- std::string info_string(MapObject::InfoStringType format) override;
724+
725+protected:
726+ void draw(const EditorGameBase&,
727+ const TextToDraw& draw_text,
728+ const Vector2f& field_on_dst,
729+ float scale,
730+ RenderTarget* dst) const override;
731
732 private:
733 friend struct Fleet;
734
735=== modified file 'src/logic/map_objects/tribes/soldier.cc'
736--- src/logic/map_objects/tribes/soldier.cc 2019-02-23 11:00:49 +0000
737+++ src/logic/map_objects/tribes/soldier.cc 2019-02-27 17:20:33 +0000
738@@ -439,6 +439,7 @@
739 * Draw this soldier. This basically draws him as a worker, but add health points
740 */
741 void Soldier::draw(const EditorGameBase& game,
742+ const TextToDraw&,
743 const Vector2f& field_on_dst,
744 const float scale,
745 RenderTarget* dst) const {
746
747=== modified file 'src/logic/map_objects/tribes/soldier.h'
748--- src/logic/map_objects/tribes/soldier.h 2019-02-23 11:00:49 +0000
749+++ src/logic/map_objects/tribes/soldier.h 2019-02-27 17:20:33 +0000
750@@ -209,6 +209,7 @@
751
752 /// Draw this soldier
753 void draw(const EditorGameBase&,
754+ const TextToDraw& draw_text,
755 const Vector2f& point_on_dst,
756 float scale,
757 RenderTarget* dst) const override;
758
759=== modified file 'src/logic/map_objects/tribes/worker.cc'
760--- src/logic/map_objects/tribes/worker.cc 2019-02-24 17:01:51 +0000
761+++ src/logic/map_objects/tribes/worker.cc 2019-02-27 17:20:33 +0000
762@@ -2996,6 +2996,7 @@
763 * Draw the worker, taking the carried ware into account.
764 */
765 void Worker::draw(const EditorGameBase& egbase,
766+ const TextToDraw&,
767 const Vector2f& field_on_dst,
768 const float scale,
769 RenderTarget* dst) const {
770
771=== modified file 'src/logic/map_objects/tribes/worker.h'
772--- src/logic/map_objects/tribes/worker.h 2019-02-23 11:00:49 +0000
773+++ src/logic/map_objects/tribes/worker.h 2019-02-27 17:20:33 +0000
774@@ -182,6 +182,7 @@
775 const float scale,
776 RenderTarget* dst) const;
777 void draw(const EditorGameBase&,
778+ const TextToDraw& draw_text,
779 const Vector2f& field_on_dst,
780 float scale,
781 RenderTarget* dst) const override;
782
783=== modified file 'src/wui/interactive_base.cc'
784--- src/wui/interactive_base.cc 2019-02-23 11:00:49 +0000
785+++ src/wui/interactive_base.cc 2019-02-27 17:20:33 +0000
786@@ -223,7 +223,7 @@
787 player.is_hostile(*productionsite->get_owner())))
788 return set_tooltip("");
789 }
790- set_tooltip(productionsite->info_string(Widelands::MapObject::InfoStringType::kTooltip));
791+ set_tooltip(productionsite->info_string(Widelands::Building::InfoStringFormat::kTooltip));
792 return;
793 }
794 set_tooltip("");
795
796=== modified file 'src/wui/interactive_base.h'
797--- src/wui/interactive_base.h 2019-02-23 11:00:49 +0000
798+++ src/wui/interactive_base.h 2019-02-27 17:20:33 +0000
799@@ -47,16 +47,6 @@
800 class EdgeOverlayManager;
801 class UniqueWindowHandler;
802
803-enum TextToDraw {
804- kNone = 0,
805- kCensus = 1,
806- kStatistics = 2,
807-};
808-
809-inline TextToDraw operator|(TextToDraw a, TextToDraw b) {
810- return static_cast<TextToDraw>(static_cast<int>(a) | static_cast<int>(b));
811-}
812-
813 /**
814 * This is used to represent the code that InteractivePlayer and
815 * EditorInteractive share.
816
817=== modified file 'src/wui/interactive_gamebase.cc'
818--- src/wui/interactive_gamebase.cc 2019-02-24 22:50:04 +0000
819+++ src/wui/interactive_gamebase.cc 2019-02-27 17:20:33 +0000
820@@ -56,46 +56,6 @@
821 return _("PAUSE");
822 }
823
824-// Draws census and statistics on screen for the given map object
825-void draw_mapobject_infotext(RenderTarget* dst,
826- const Vector2i& init_position,
827- float scale,
828- Widelands::MapObject* mapobject,
829- const TextToDraw text_to_draw) {
830- const std::string census_string =
831- mapobject->info_string(Widelands::MapObject::InfoStringType::kCensus);
832- if (census_string.empty()) {
833- // If there is no census available for the map object, we also won't have any statistics.
834- return;
835- }
836-
837- const std::string statistics_string =
838- (text_to_draw & TextToDraw::kStatistics) ?
839- mapobject->info_string(Widelands::MapObject::InfoStringType::kStatistics) :
840- "";
841- if (census_string.empty() && statistics_string.empty()) {
842- // Nothing to do
843- return;
844- }
845-
846- const int font_size = scale * UI_FONT_SIZE_SMALL;
847-
848- // We always render this so we can have a stable position for the statistics string.
849- std::shared_ptr<const UI::RenderedText> rendered_census =
850- UI::g_fh->render(as_condensed(census_string, UI::Align::kCenter, font_size), 120 * scale);
851- Vector2i position = init_position - Vector2i(0, 48) * scale;
852- if (text_to_draw & TextToDraw::kCensus) {
853- rendered_census->draw(*dst, position, UI::Align::kCenter);
854- }
855-
856- if (!statistics_string.empty()) {
857- std::shared_ptr<const UI::RenderedText> rendered_statistics =
858- UI::g_fh->render(as_condensed(statistics_string, UI::Align::kCenter, font_size));
859- position.y += rendered_census->height() + text_height(font_size) / 4;
860- rendered_statistics->draw(*dst, position, UI::Align::kCenter);
861- }
862-}
863-
864 } // namespace
865
866 InteractiveGameBase::InteractiveGameBase(Widelands::Game& g,
867@@ -179,34 +139,6 @@
868 }
869 }
870
871-void InteractiveGameBase::draw_mapobject_infotexts(
872- RenderTarget* dst,
873- float scale,
874- const std::vector<std::pair<Vector2i, Widelands::MapObject*>>& mapobjects_to_draw_text_for,
875- const TextToDraw text_to_draw,
876- const Widelands::Player* plr) const {
877- // Rendering text is expensive, so let's just do it for only a few sizes.
878- // The formula is a bit fancy to avoid too much text overlap.
879- const float scale_for_text =
880- std::round(2.f * (scale > 1.f ? std::sqrt(scale) : std::pow(scale, 2.f))) / 2.f;
881- if (scale_for_text < 1.f) {
882- return;
883- }
884-
885- for (const auto& draw_my_text : mapobjects_to_draw_text_for) {
886- TextToDraw draw_text_for_this_mapobject = text_to_draw;
887- const Widelands::Player* owner = draw_my_text.second->get_owner();
888- if (owner != nullptr && plr != nullptr && !plr->see_all() && plr->is_hostile(*owner)) {
889- draw_text_for_this_mapobject =
890- static_cast<TextToDraw>(draw_text_for_this_mapobject & ~TextToDraw::kStatistics);
891- }
892- if (draw_text_for_this_mapobject != TextToDraw::kNone) {
893- draw_mapobject_infotext(dst, draw_my_text.first, scale_for_text, draw_my_text.second,
894- draw_text_for_this_mapobject);
895- }
896- }
897-}
898-
899 /**
900 * Called for every game after loading (from a savegame or just from a map
901 * during single/multiplayer/scenario).
902
903=== modified file 'src/wui/interactive_gamebase.h'
904--- src/wui/interactive_gamebase.h 2019-02-23 11:00:49 +0000
905+++ src/wui/interactive_gamebase.h 2019-02-27 17:20:33 +0000
906@@ -102,13 +102,6 @@
907 void start() override;
908
909 protected:
910- /// Draws census and statistics on screen for the listed mapobjects
911- void draw_mapobject_infotexts(
912- RenderTarget* dst,
913- float scale,
914- const std::vector<std::pair<Vector2i, Widelands::MapObject*>>& mapobjects_to_draw_text_for,
915- const TextToDraw text_to_draw,
916- const Widelands::Player* plr) const;
917 void draw_overlay(RenderTarget&) override;
918
919 GameMainMenuWindows main_windows_;
920
921=== modified file 'src/wui/interactive_player.cc'
922--- src/wui/interactive_player.cc 2019-02-23 11:00:49 +0000
923+++ src/wui/interactive_player.cc 2019-02-27 17:20:33 +0000
924@@ -85,21 +85,42 @@
925 return brightness / 255.;
926 }
927
928-// Draws immovable if the field matches its actual position and returns true if the immovable was
929-// drawn there.
930-bool draw_immovable_for_visible_field(const Widelands::EditorGameBase& egbase,
931- const FieldsToDraw::Field& field,
932- const float scale,
933- Widelands::BaseImmovable* const imm,
934- RenderTarget* dst) {
935+// Remove statistics from the text to draw if the player does not match the map object's owner
936+TextToDraw filter_text_to_draw(const TextToDraw text_to_draw, const Widelands::MapObject* object, const Widelands::Player& player) {
937+ TextToDraw result = text_to_draw;
938+ const Widelands::Player* owner = object->get_owner();
939+ if (owner != nullptr && !player.see_all() && player.is_hostile(*owner)) {
940+ result = removeFromTextToDraw(result, TextToDraw::kStatistics);
941+ }
942+ return result;
943+}
944+
945+void draw_immovable_for_visible_field(const Widelands::EditorGameBase& egbase,
946+ const FieldsToDraw::Field& field,
947+ const float scale,
948+ const TextToDraw text_to_draw,
949+ const Widelands::Player& player,
950+ RenderTarget* dst) {
951+ Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();
952 if (imm != nullptr && imm->get_positions(egbase).front() == field.fcoords) {
953- imm->draw(egbase.get_gametime(), field.rendertarget_pixel, scale, dst);
954- return true;
955- }
956- return false;
957-}
958-
959-void draw_immovables_for_formerly_visible_field(const FieldsToDraw::Field& field,
960+ imm->draw(
961+ egbase.get_gametime(), filter_text_to_draw(text_to_draw, imm, player), field.rendertarget_pixel, scale, dst);
962+ }
963+}
964+
965+void draw_bobs_for_visible_field(const Widelands::EditorGameBase& egbase,
966+ const FieldsToDraw::Field& field,
967+ const float scale,
968+ const TextToDraw text_to_draw,
969+ const Widelands::Player& player,
970+ RenderTarget* dst) {
971+ for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;
972+ bob = bob->get_next_bob()) {
973+ bob->draw(egbase, filter_text_to_draw(text_to_draw, bob, player), field.rendertarget_pixel, scale, dst);
974+ }
975+}
976+
977+void draw_immovable_for_formerly_visible_field(const FieldsToDraw::Field& field,
978 const Widelands::Player::Field& player_field,
979 const float scale,
980 RenderTarget* dst) {
981@@ -267,8 +288,7 @@
982 auto* fields_to_draw = given_map_view->draw_terrain(gbase, dst);
983 const auto& road_building = road_building_overlays();
984 const std::map<Widelands::Coords, const Image*> workarea_overlays = get_workarea_overlays(map);
985- std::vector<std::pair<Vector2i, Widelands::MapObject*>> mapobjects_to_draw_text_for;
986- const auto text_to_draw = get_text_to_draw();
987+
988 const float scale = 1.f / given_map_view->view().zoom;
989
990 for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) {
991@@ -299,21 +319,12 @@
992
993 // Render stuff that belongs to the node.
994 if (f->vision > 1) {
995- Widelands::BaseImmovable* imm = f->fcoords.field->get_immovable();
996- if (draw_immovable_for_visible_field(gbase, *f, scale, imm, dst)) {
997- mapobjects_to_draw_text_for.push_back(
998- std::make_pair(f->rendertarget_pixel.cast<int>(), imm));
999- }
1000-
1001- for (Widelands::Bob* bob = f->fcoords.field->get_first_bob(); bob;
1002- bob = bob->get_next_bob()) {
1003- bob->draw(gbase, f->rendertarget_pixel, scale, dst);
1004- mapobjects_to_draw_text_for.push_back(std::make_pair(
1005- bob->calc_drawpos(gbase, f->rendertarget_pixel, scale).cast<int>(), bob));
1006- }
1007+ const auto text_to_draw = get_text_to_draw();
1008+ draw_immovable_for_visible_field(gbase, *f, scale, text_to_draw, plr, dst);
1009+ draw_bobs_for_visible_field(gbase, *f, scale, text_to_draw, plr, dst);
1010 } else if (f->vision == 1) {
1011 // We never show census or statistics for objects in the fog.
1012- draw_immovables_for_formerly_visible_field(*f, player_field, scale, dst);
1013+ draw_immovable_for_formerly_visible_field(*f, player_field, scale, dst);
1014 }
1015 }
1016
1017@@ -352,8 +363,6 @@
1018 }
1019 }
1020 }
1021- // Blit census & Statistics.
1022- draw_mapobject_infotexts(dst, scale, mapobjects_to_draw_text_for, text_to_draw, &plr);
1023 }
1024
1025 void InteractivePlayer::popup_message(Widelands::MessageId const id,
1026
1027=== modified file 'src/wui/interactive_spectator.cc'
1028--- src/wui/interactive_spectator.cc 2019-02-23 11:00:49 +0000
1029+++ src/wui/interactive_spectator.cc 2019-02-27 17:20:33 +0000
1030@@ -122,8 +122,6 @@
1031
1032 const auto text_to_draw = get_text_to_draw();
1033 const std::map<Widelands::Coords, const Image*> workarea_overlays = get_workarea_overlays(map);
1034- std::vector<std::pair<Vector2i, Widelands::MapObject*>> mapobjects_to_draw_text_for;
1035-
1036 for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) {
1037 const FieldsToDraw::Field& field = fields_to_draw->at(idx);
1038
1039@@ -131,16 +129,12 @@
1040
1041 Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();
1042 if (imm != nullptr && imm->get_positions(the_game).front() == field.fcoords) {
1043- imm->draw(gametime, field.rendertarget_pixel, scale, dst);
1044- mapobjects_to_draw_text_for.push_back(
1045- std::make_pair(field.rendertarget_pixel.cast<int>(), imm));
1046+ imm->draw(gametime, text_to_draw, field.rendertarget_pixel, scale, dst);
1047 }
1048
1049 for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;
1050 bob = bob->get_next_bob()) {
1051- bob->draw(the_game, field.rendertarget_pixel, scale, dst);
1052- mapobjects_to_draw_text_for.push_back(std::make_pair(
1053- bob->calc_drawpos(the_game, field.rendertarget_pixel, scale).cast<int>(), bob));
1054+ bob->draw(the_game, text_to_draw, field.rendertarget_pixel, scale, dst);
1055 }
1056
1057 // Draw work area previews.
1058@@ -173,9 +167,6 @@
1059 blit_field_overlay(dst, field, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);
1060 }
1061 }
1062-
1063- // Blit census & Statistics.
1064- draw_mapobject_infotexts(dst, scale, mapobjects_to_draw_text_for, text_to_draw, nullptr);
1065 }
1066
1067 /**
1068
1069=== modified file 'src/wui/transport_draw.cc'
1070--- src/wui/transport_draw.cc 2019-02-23 11:00:49 +0000
1071+++ src/wui/transport_draw.cc 2019-02-27 17:20:33 +0000
1072@@ -26,7 +26,11 @@
1073
1074 namespace Widelands {
1075
1076-void Flag::draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) {
1077+void Flag::draw(uint32_t gametime,
1078+ const TextToDraw,
1079+ const Vector2f& point_on_dst,
1080+ float scale,
1081+ RenderTarget* dst) {
1082 static struct {
1083 float x, y;
1084 } ware_offsets[8] = {{-5.f, 1.f}, {-1.f, 3.f}, {3.f, 3.f}, {7.f, 1.f},
1085@@ -50,6 +54,6 @@
1086 }
1087
1088 /** The road is drawn by the terrain renderer via marked fields. */
1089-void Road::draw(uint32_t, const Vector2f&, float, RenderTarget*) {
1090+void Road::draw(uint32_t, const TextToDraw, const Vector2f&, float, RenderTarget*) {
1091 }
1092 } // namespace Widelands

Subscribers

People subscribed via source and target branches

to status/vote changes: