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