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
=== modified file 'src/economy/flag.h'
--- src/economy/flag.h 2019-02-23 11:00:49 +0000
+++ src/economy/flag.h 2019-02-27 17:20:33 +0000
@@ -26,6 +26,7 @@
2626
27#include "base/macros.h"27#include "base/macros.h"
28#include "economy/routing_node.h"28#include "economy/routing_node.h"
29#include "logic/map_objects/draw_text.h"
29#include "logic/map_objects/immovable.h"30#include "logic/map_objects/immovable.h"
30#include "logic/map_objects/walkingdir.h"31#include "logic/map_objects/walkingdir.h"
3132
@@ -152,8 +153,11 @@
152 bool init(EditorGameBase&) override;153 bool init(EditorGameBase&) override;
153 void cleanup(EditorGameBase&) override;154 void cleanup(EditorGameBase&) override;
154155
155 void156 void draw(uint32_t gametime,
156 draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;157 TextToDraw draw_text,
158 const Vector2f& point_on_dst,
159 float scale,
160 RenderTarget* dst) override;
157161
158 void wake_up_capacity_queue(Game&);162 void wake_up_capacity_queue(Game&);
159163
160164
=== modified file 'src/economy/portdock.cc'
--- src/economy/portdock.cc 2019-02-23 11:00:49 +0000
+++ src/economy/portdock.cc 2019-02-27 17:20:33 +0000
@@ -140,7 +140,7 @@
140 expedition_bootstrap_->set_economy(e);140 expedition_bootstrap_->set_economy(e);
141}141}
142142
143void PortDock::draw(uint32_t, const Vector2f&, float, RenderTarget*) {143void PortDock::draw(uint32_t, const TextToDraw, const Vector2f&, float, RenderTarget*) {
144 // do nothing144 // do nothing
145}145}
146146
147147
=== modified file 'src/economy/portdock.h'
--- src/economy/portdock.h 2019-02-23 11:00:49 +0000
+++ src/economy/portdock.h 2019-02-27 17:20:33 +0000
@@ -96,8 +96,11 @@
9696
97 Flag& base_flag() override;97 Flag& base_flag() override;
98 PositionList get_positions(const EditorGameBase&) const override;98 PositionList get_positions(const EditorGameBase&) const override;
99 void99 void draw(uint32_t gametime,
100 draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;100 TextToDraw draw_text,
101 const Vector2f& point_on_dst,
102 float scale,
103 RenderTarget* dst) override;
101104
102 bool init(EditorGameBase&) override;105 bool init(EditorGameBase&) override;
103 void cleanup(EditorGameBase&) override;106 void cleanup(EditorGameBase&) override;
104107
=== modified file 'src/economy/road.h'
--- src/economy/road.h 2019-02-23 11:00:49 +0000
+++ src/economy/road.h 2019-02-27 17:20:33 +0000
@@ -130,8 +130,11 @@
130 bool init(EditorGameBase&) override;130 bool init(EditorGameBase&) override;
131 void cleanup(EditorGameBase&) override;131 void cleanup(EditorGameBase&) override;
132132
133 void133 void draw(uint32_t gametime,
134 draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;134 TextToDraw draw_text,
135 const Vector2f& point_on_dst,
136 float scale,
137 RenderTarget* dst) override;
135138
136private:139private:
137 void set_path(EditorGameBase&, const Path&);140 void set_path(EditorGameBase&, const Path&);
138141
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc 2019-02-23 11:00:49 +0000
+++ src/editor/editorinteractive.cc 2019-02-27 17:20:33 +0000
@@ -300,14 +300,14 @@
300 if (draw_immovables_) {300 if (draw_immovables_) {
301 Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();301 Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();
302 if (imm != nullptr && imm->get_positions(ebase).front() == field.fcoords) {302 if (imm != nullptr && imm->get_positions(ebase).front() == field.fcoords) {
303 imm->draw(gametime, field.rendertarget_pixel, scale, &dst);303 imm->draw(gametime, TextToDraw::kNone, field.rendertarget_pixel, scale, &dst);
304 }304 }
305 }305 }
306306
307 if (draw_bobs_) {307 if (draw_bobs_) {
308 for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;308 for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;
309 bob = bob->get_next_bob()) {309 bob = bob->get_next_bob()) {
310 bob->draw(ebase, field.rendertarget_pixel, scale, &dst);310 bob->draw(ebase, TextToDraw::kNone, field.rendertarget_pixel, scale, &dst);
311 }311 }
312 }312 }
313313
@@ -376,8 +376,6 @@
376 }376 }
377 }377 }
378 }378 }
379 // TODO(GunChleoc): If we ever implement an infrastructure tool, the building texts will need to
380 // be blitted here.
381}379}
382380
383/// Needed to get freehand painting tools (hold down mouse and move to edit).381/// Needed to get freehand painting tools (hold down mouse and move to edit).
384382
=== modified file 'src/logic/CMakeLists.txt'
--- src/logic/CMakeLists.txt 2018-11-13 12:18:10 +0000
+++ src/logic/CMakeLists.txt 2019-02-27 17:20:33 +0000
@@ -186,6 +186,7 @@
186 map_objects/buildcost.h186 map_objects/buildcost.h
187 map_objects/checkstep.cc187 map_objects/checkstep.cc
188 map_objects/checkstep.h188 map_objects/checkstep.h
189 map_objects/draw_text.h
189 map_objects/immovable.cc190 map_objects/immovable.cc
190 map_objects/immovable.h191 map_objects/immovable.h
191 map_objects/immovable_program.h192 map_objects/immovable_program.h
@@ -279,6 +280,7 @@
279 game_io280 game_io
280 graphic281 graphic
281 graphic_color282 graphic_color
283 graphic_fonthandler
282 graphic_image_io284 graphic_image_io
283 graphic_playercolor285 graphic_playercolor
284 graphic_surface286 graphic_surface
285287
=== modified file 'src/logic/map_objects/bob.cc'
--- src/logic/map_objects/bob.cc 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/bob.cc 2019-02-27 17:20:33 +0000
@@ -757,6 +757,7 @@
757/// Note that the current node is actually the node that we are walking to, not757/// Note that the current node is actually the node that we are walking to, not
758/// the the one that we start from.758/// the the one that we start from.
759void Bob::draw(const EditorGameBase& egbase,759void Bob::draw(const EditorGameBase& egbase,
760 const TextToDraw&,
760 const Vector2f& field_on_dst,761 const Vector2f& field_on_dst,
761 const float scale,762 const float scale,
762 RenderTarget* dst) const {763 RenderTarget* dst) const {
763764
=== modified file 'src/logic/map_objects/bob.h'
--- src/logic/map_objects/bob.h 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/bob.h 2019-02-27 17:20:33 +0000
@@ -25,6 +25,7 @@
25#include "economy/route.h"25#include "economy/route.h"
26#include "graphic/animation.h"26#include "graphic/animation.h"
27#include "graphic/diranimations.h"27#include "graphic/diranimations.h"
28#include "logic/map_objects/draw_text.h"
28#include "logic/map_objects/map_object.h"29#include "logic/map_objects/map_object.h"
29#include "logic/map_objects/walkingdir.h"30#include "logic/map_objects/walkingdir.h"
30#include "logic/widelands_geometry.h"31#include "logic/widelands_geometry.h"
@@ -262,8 +263,11 @@
262 // the field associated with this bob (if it is walking, that is its263 // the field associated with this bob (if it is walking, that is its
263 // starting field) in pixel space of 'dst' (including scale). The 'scale' is264 // starting field) in pixel space of 'dst' (including scale). The 'scale' is
264 // required to draw the bob in the right size.265 // required to draw the bob in the right size.
265 virtual void266 virtual void draw(const EditorGameBase&,
266 draw(const EditorGameBase&, const Vector2f& field_on_dst, float scale, RenderTarget* dst) const;267 const TextToDraw& draw_text,
268 const Vector2f& field_on_dst,
269 float scale,
270 RenderTarget* dst) const;
267271
268 // For debug272 // For debug
269 void log_general_info(const EditorGameBase&) const override;273 void log_general_info(const EditorGameBase&) const override;
270274
=== added file 'src/logic/map_objects/draw_text.h'
--- src/logic/map_objects/draw_text.h 1970-01-01 00:00:00 +0000
+++ src/logic/map_objects/draw_text.h 2019-02-27 17:20:33 +0000
@@ -0,0 +1,43 @@
1/*
2 * Copyright (C) 2006-2018 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20#ifndef WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H
21#define WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H
22
23// Only declare powers of 2 and adjust the ~ operator below if you add any values to this enum class.
24enum class TextToDraw {
25 kNone = 0,
26 kCensus = 1,
27 kStatistics = 2,
28};
29
30inline TextToDraw operator|(TextToDraw a, TextToDraw b) {
31 return static_cast<TextToDraw>(static_cast<int>(a) | static_cast<int>(b));
32}
33inline TextToDraw operator&(TextToDraw a, TextToDraw b) {
34 return static_cast<TextToDraw>(static_cast<int>(a) & static_cast<int>(b));
35}
36inline TextToDraw removeFromTextToDraw(TextToDraw base, TextToDraw remove) {
37 const int result = static_cast<int>(base) & ~static_cast<int>(remove);
38 assert(result >= 0);
39 assert(result <= 2);
40 return static_cast<TextToDraw>(result);
41}
42
43#endif // end of include guard: WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H
044
=== modified file 'src/logic/map_objects/immovable.cc'
--- src/logic/map_objects/immovable.cc 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/immovable.cc 2019-02-27 17:20:33 +0000
@@ -454,6 +454,7 @@
454}454}
455455
456void Immovable::draw(uint32_t gametime,456void Immovable::draw(uint32_t gametime,
457 const TextToDraw draw_text,
457 const Vector2f& point_on_dst,458 const Vector2f& point_on_dst,
458 float scale,459 float scale,
459 RenderTarget* dst) {460 RenderTarget* dst) {
@@ -462,12 +463,16 @@
462 }463 }
463 if (!anim_construction_total_) {464 if (!anim_construction_total_) {
464 dst->blit_animation(point_on_dst, scale, anim_, gametime - animstart_);465 dst->blit_animation(point_on_dst, scale, anim_, gametime - animstart_);
466 if (former_building_descr_) {
467 do_draw_info(draw_text, former_building_descr_->descname(), "", point_on_dst, scale, dst);
468 }
465 } else {469 } else {
466 draw_construction(gametime, point_on_dst, scale, dst);470 draw_construction(gametime, draw_text, point_on_dst, scale, dst);
467 }471 }
468}472}
469473
470void Immovable::draw_construction(const uint32_t gametime,474void Immovable::draw_construction(const uint32_t gametime,
475 const TextToDraw draw_text,
471 const Vector2f& point_on_dst,476 const Vector2f& point_on_dst,
472 const float scale,477 const float scale,
473 RenderTarget* dst) {478 RenderTarget* dst) {
@@ -506,6 +511,13 @@
506511
507 dst->blit_animation(512 dst->blit_animation(
508 point_on_dst, scale, anim_, current_frame * frametime, player_color, percent);513 point_on_dst, scale, anim_, current_frame * frametime, player_color, percent);
514
515 // Additionally, if statistics are enabled, draw a progression string
516 do_draw_info(draw_text, descr().descname(),
517 (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %
518 (boost::format(_("%i%% built")) % (100 * done / total)).str())
519 .str(),
520 point_on_dst, scale, dst);
509}521}
510522
511/**523/**
@@ -517,36 +529,6 @@
517 action_data_.reset(data);529 action_data_.reset(data);
518}530}
519531
520std::string Immovable::info_string(const MapObject::InfoStringType format) {
521 std::string result;
522 switch (format) {
523 case MapObject::InfoStringType::kCensus:
524 if (!anim_construction_total_) {
525 if (former_building_descr_) {
526 result = former_building_descr_->descname();
527 }
528 } else {
529 result = descr().descname();
530 }
531 break;
532 case MapObject::InfoStringType::kStatistics:
533 if (anim_construction_total_) {
534 result = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() %
535 (boost::format(_("%i%% built")) %
536 (100 * anim_construction_done_ / anim_construction_total_))
537 .str())
538 .str();
539 } else {
540 result = "";
541 }
542 break;
543 case MapObject::InfoStringType::kTooltip:
544 result = "";
545 break;
546 }
547 return result;
548}
549
550/*532/*
551==============================533==============================
552534
553535
=== modified file 'src/logic/map_objects/immovable.h'
--- src/logic/map_objects/immovable.h 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/immovable.h 2019-02-27 17:20:33 +0000
@@ -26,6 +26,7 @@
26#include "base/macros.h"26#include "base/macros.h"
27#include "graphic/animation.h"27#include "graphic/animation.h"
28#include "logic/map_objects/buildcost.h"28#include "logic/map_objects/buildcost.h"
29#include "logic/map_objects/draw_text.h"
29#include "logic/map_objects/map_object.h"30#include "logic/map_objects/map_object.h"
30#include "logic/widelands_geometry.h"31#include "logic/widelands_geometry.h"
31#include "notifications/note_ids.h"32#include "notifications/note_ids.h"
@@ -96,13 +97,16 @@
96 virtual PositionList get_positions(const EditorGameBase&) const = 0;97 virtual PositionList get_positions(const EditorGameBase&) const = 0;
9798
98 // Draw this immovable onto 'dst' choosing the frame appropriate for99 // Draw this immovable onto 'dst' choosing the frame appropriate for
99 // 'gametime'.100 // 'gametime'. 'draw_text' decides if census and statistics are written too.
100 // The 'coords_to_draw' are passed one to give objects that occupy multiple101 // The 'coords_to_draw' are passed one to give objects that occupy multiple
101 // fields a way to only draw themselves once. The 'point_on_dst' determines102 // fields a way to only draw themselves once. The 'point_on_dst' determines
102 // the point for the hotspot of the animation and 'scale' determines how big103 // the point for the hotspot of the animation and 'scale' determines how big
103 // the immovable will be plotted.104 // the immovable will be plotted.
104 virtual void105 virtual void draw(uint32_t gametime,
105 draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) = 0;106 TextToDraw draw_text,
107 const Vector2f& point_on_dst,
108 float scale,
109 RenderTarget* dst) = 0;
106110
107 static int32_t string_to_size(const std::string& size);111 static int32_t string_to_size(const std::string& size);
108 static std::string size_to_string(int32_t size);112 static std::string size_to_string(int32_t size);
@@ -223,8 +227,11 @@
223 bool init(EditorGameBase&) override;227 bool init(EditorGameBase&) override;
224 void cleanup(EditorGameBase&) override;228 void cleanup(EditorGameBase&) override;
225 void act(Game&, uint32_t data) override;229 void act(Game&, uint32_t data) override;
226 void230 void draw(uint32_t gametime,
227 draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;231 TextToDraw draw_text,
232 const Vector2f& point_on_dst,
233 float scale,
234 RenderTarget* dst) override;
228235
229 void switch_program(Game& game, const std::string& programname);236 void switch_program(Game& game, const std::string& programname);
230 bool construct_ware(Game& game, DescriptionIndex index);237 bool construct_ware(Game& game, DescriptionIndex index);
@@ -240,8 +247,6 @@
240 return nullptr;247 return nullptr;
241 }248 }
242249
243 std::string info_string(MapObject::InfoStringType format) override;
244
245protected:250protected:
246 // The building type that created this immovable, if any.251 // The building type that created this immovable, if any.
247 const BuildingDescr* former_building_descr_;252 const BuildingDescr* former_building_descr_;
@@ -309,6 +314,7 @@
309314
310 void increment_program_pointer();315 void increment_program_pointer();
311 void draw_construction(uint32_t gametime,316 void draw_construction(uint32_t gametime,
317 TextToDraw draw_text,
312 const Vector2f& point_on_dst,318 const Vector2f& point_on_dst,
313 float scale,319 float scale,
314 RenderTarget* dst);320 RenderTarget* dst);
315321
=== modified file 'src/logic/map_objects/map_object.cc'
--- src/logic/map_objects/map_object.cc 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/map_object.cc 2019-02-27 17:20:33 +0000
@@ -29,6 +29,7 @@
2929
30#include "base/log.h"30#include "base/log.h"
31#include "base/wexception.h"31#include "base/wexception.h"
32#include "graphic/font_handler.h"
32#include "graphic/graphic.h"33#include "graphic/graphic.h"
33#include "graphic/rendertarget.h"34#include "graphic/rendertarget.h"
34#include "graphic/text_layout.h"35#include "graphic/text_layout.h"
@@ -474,6 +475,40 @@
474 egbase.objects().remove(*this);475 egbase.objects().remove(*this);
475}476}
476477
478void MapObject::do_draw_info(const TextToDraw& draw_text,
479 const std::string& census,
480 const std::string& statictics,
481 const Vector2f& field_on_dst,
482 float scale,
483 RenderTarget* dst) const {
484 if (draw_text == TextToDraw::kNone) {
485 return;
486 }
487
488 // Rendering text is expensive, so let's just do it for only a few sizes.
489 // The formula is a bit fancy to avoid too much text overlap.
490 scale = std::round(2.f * (scale > 1.f ? std::sqrt(scale) : std::pow(scale, 2.f))) / 2.f;
491 if (scale < 1.f) {
492 return;
493 }
494 const int font_size = scale * UI_FONT_SIZE_SMALL;
495
496 // We always render this so we can have a stable position for the statistics string.
497 std::shared_ptr<const UI::RenderedText> rendered_census =
498 UI::g_fh->render(as_condensed(census, UI::Align::kCenter, font_size), 120 * scale);
499 Vector2i position = field_on_dst.cast<int>() - Vector2i(0, 48) * scale;
500 if ((draw_text & TextToDraw::kCensus) != TextToDraw::kNone) {
501 rendered_census->draw(*dst, position, UI::Align::kCenter);
502 }
503
504 if ((draw_text & TextToDraw::kStatistics) != TextToDraw::kNone && !statictics.empty()) {
505 std::shared_ptr<const UI::RenderedText> rendered_statistics =
506 UI::g_fh->render(as_condensed(statictics, UI::Align::kCenter, font_size));
507 position.y += rendered_census->height() + text_height(font_size) / 4;
508 rendered_statistics->draw(*dst, position, UI::Align::kCenter);
509 }
510}
511
477const Image* MapObject::representative_image() const {512const Image* MapObject::representative_image() const {
478 return descr().representative_image(get_owner() ? &get_owner()->get_playercolor() : nullptr);513 return descr().representative_image(get_owner() ? &get_owner()->get_playercolor() : nullptr);
479}514}
@@ -545,10 +580,6 @@
545 reserved_by_worker_ = reserve;580 reserved_by_worker_ = reserve;
546}581}
547582
548std::string MapObject::info_string(const InfoStringType) {
549 return "";
550}
551
552constexpr uint8_t kCurrentPacketVersionMapObject = 2;583constexpr uint8_t kCurrentPacketVersionMapObject = 2;
553584
554/**585/**
555586
=== modified file 'src/logic/map_objects/map_object.h'
--- src/logic/map_objects/map_object.h 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/map_object.h 2019-02-27 17:20:33 +0000
@@ -35,6 +35,7 @@
35#include "graphic/color.h"35#include "graphic/color.h"
36#include "graphic/image.h"36#include "graphic/image.h"
37#include "logic/cmd_queue.h"37#include "logic/cmd_queue.h"
38#include "logic/map_objects/draw_text.h"
38#include "logic/map_objects/tribes/training_attribute.h"39#include "logic/map_objects/tribes/training_attribute.h"
39#include "logic/widelands.h"40#include "logic/widelands.h"
40#include "scripting/lua_table.h"41#include "scripting/lua_table.h"
@@ -339,12 +340,6 @@
339 */340 */
340 void set_reserved_by_worker(bool reserve);341 void set_reserved_by_worker(bool reserve);
341342
342 enum class InfoStringType { kCensus, kStatistics, kTooltip };
343 /**
344 * Returns a census, statistics or tooltip string to be shown for this object on the map
345 */
346 virtual std::string info_string(InfoStringType);
347
348 /**343 /**
349 * Static load functions of derived classes will return a pointer to344 * Static load functions of derived classes will return a pointer to
350 * a Loader class. The caller needs to call the virtual functions345 * a Loader class. The caller needs to call the virtual functions
@@ -411,6 +406,14 @@
411406
412 virtual void cleanup(EditorGameBase&);407 virtual void cleanup(EditorGameBase&);
413408
409 /// Draws census and statistics on screen
410 void do_draw_info(const TextToDraw& draw_text,
411 const std::string& census,
412 const std::string& statictics,
413 const Vector2f& field_on_dst,
414 const float scale,
415 RenderTarget* dst) const;
416
414#ifdef _WIN32417#ifdef _WIN32
415 void molog(char const* fmt, ...) const __attribute__((format(gnu_printf, 2, 3)));418 void molog(char const* fmt, ...) const __attribute__((format(gnu_printf, 2, 3)));
416#else419#else
417420
=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/building.cc 2019-02-27 17:20:33 +0000
@@ -463,20 +463,20 @@
463 }463 }
464}464}
465465
466std::string Building::info_string(const MapObject::InfoStringType format) {466std::string Building::info_string(const InfoStringFormat& format) {
467 std::string result;467 std::string result;
468 switch (format) {468 switch (format) {
469 case MapObject::InfoStringType::kCensus:469 case InfoStringFormat::kCensus:
470 if (upcast(ConstructionSite const, constructionsite, this)) {470 if (upcast(ConstructionSite const, constructionsite, this)) {
471 result = constructionsite->building().descname();471 result = constructionsite->building().descname();
472 } else {472 } else {
473 result = descr().descname();473 result = descr().descname();
474 }474 }
475 break;475 break;
476 case MapObject::InfoStringType::kStatistics:476 case InfoStringFormat::kStatistics:
477 result = update_and_get_statistics_string();477 result = update_and_get_statistics_string();
478 break;478 break;
479 case MapObject::InfoStringType::kTooltip:479 case InfoStringFormat::kTooltip:
480 if (upcast(ProductionSite const, productionsite, this)) {480 if (upcast(ProductionSite const, productionsite, this)) {
481 result = productionsite->production_result();481 result = productionsite->production_result();
482 }482 }
@@ -606,6 +606,7 @@
606}606}
607607
608void Building::draw(uint32_t gametime,608void Building::draw(uint32_t gametime,
609 const TextToDraw draw_text,
609 const Vector2f& point_on_dst,610 const Vector2f& point_on_dst,
610 const float scale,611 const float scale,
611 RenderTarget* dst) {612 RenderTarget* dst) {
@@ -613,6 +614,24 @@
613 point_on_dst, scale, anim_, gametime - animstart_, get_owner()->get_playercolor());614 point_on_dst, scale, anim_, gametime - animstart_, get_owner()->get_playercolor());
614615
615 // door animation?616 // door animation?
617
618 // overlay strings (draw when enabled)
619 draw_info(draw_text, point_on_dst, scale, dst);
620}
621
622/*
623===============
624Draw overlay help strings when enabled.
625===============
626*/
627void Building::draw_info(const TextToDraw draw_text,
628 const Vector2f& point_on_dst,
629 const float scale,
630 RenderTarget* dst) {
631 const std::string statistics_string =
632 ((draw_text & TextToDraw::kStatistics) != TextToDraw::kNone) ? info_string(InfoStringFormat::kStatistics) : "";
633 do_draw_info(draw_text, info_string(InfoStringFormat::kCensus), statistics_string, point_on_dst,
634 scale, dst);
616}635}
617636
618int32_t637int32_t
619638
=== modified file 'src/logic/map_objects/tribes/building.h'
--- src/logic/map_objects/tribes/building.h 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/building.h 2019-02-27 17:20:33 +0000
@@ -227,6 +227,8 @@
227 using FormerBuildings = std::vector<DescriptionIndex>;227 using FormerBuildings = std::vector<DescriptionIndex>;
228228
229public:229public:
230 enum class InfoStringFormat { kCensus, kStatistics, kTooltip };
231
230 explicit Building(const BuildingDescr&);232 explicit Building(const BuildingDescr&);
231233
232 void load_finish(EditorGameBase&) override;234 void load_finish(EditorGameBase&) override;
@@ -242,7 +244,7 @@
242 }244 }
243 PositionList get_positions(const EditorGameBase&) const override;245 PositionList get_positions(const EditorGameBase&) const override;
244246
245 std::string info_string(MapObject::InfoStringType format) override;247 std::string info_string(const InfoStringFormat& format);
246248
247 // Return the overlay string that is displayed on the map view when enabled249 // Return the overlay string that is displayed on the map view when enabled
248 // by the player.250 // by the player.
@@ -337,8 +339,13 @@
337 void cleanup(EditorGameBase&) override;339 void cleanup(EditorGameBase&) override;
338 void act(Game&, uint32_t data) override;340 void act(Game&, uint32_t data) override;
339341
342 void draw(uint32_t gametime,
343 TextToDraw draw_text,
344 const Vector2f& point_on_dst,
345 float scale,
346 RenderTarget* dst) override;
340 void347 void
341 draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;348 draw_info(TextToDraw draw_text, const Vector2f& point_on_dst, float scale, RenderTarget* dst);
342349
343 void set_seeing(bool see);350 void set_seeing(bool see);
344 void set_attack_target(AttackTarget* new_attack_target);351 void set_attack_target(AttackTarget* new_attack_target);
345352
=== modified file 'src/logic/map_objects/tribes/constructionsite.cc'
--- src/logic/map_objects/tribes/constructionsite.cc 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/constructionsite.cc 2019-02-27 17:20:33 +0000
@@ -337,6 +337,7 @@
337===============337===============
338*/338*/
339void ConstructionSite::draw(uint32_t gametime,339void ConstructionSite::draw(uint32_t gametime,
340 TextToDraw draw_text,
340 const Vector2f& point_on_dst,341 const Vector2f& point_on_dst,
341 float scale,342 float scale,
342 RenderTarget* dst) {343 RenderTarget* dst) {
@@ -358,5 +359,8 @@
358 }359 }
359360
360 info_.draw(point_on_dst, scale, player_color, dst);361 info_.draw(point_on_dst, scale, player_color, dst);
362
363 // Draw help strings
364 draw_info(draw_text, point_on_dst, scale, dst);
361}365}
362} // namespace Widelands366} // namespace Widelands
363367
=== modified file 'src/logic/map_objects/tribes/constructionsite.h'
--- src/logic/map_objects/tribes/constructionsite.h 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/constructionsite.h 2019-02-27 17:20:33 +0000
@@ -120,8 +120,11 @@
120120
121 static void wares_queue_callback(Game&, InputQueue*, DescriptionIndex, Worker*, void* data);121 static void wares_queue_callback(Game&, InputQueue*, DescriptionIndex, Worker*, void* data);
122122
123 void123 void draw(uint32_t gametime,
124 draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;124 TextToDraw draw_text,
125 const Vector2f& point_on_dst,
126 float scale,
127 RenderTarget* dst) override;
125128
126private:129private:
127 int32_t fetchfromflag_; // # of wares to fetch from flag130 int32_t fetchfromflag_; // # of wares to fetch from flag
128131
=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
--- src/logic/map_objects/tribes/dismantlesite.cc 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/dismantlesite.cc 2019-02-27 17:20:33 +0000
@@ -217,6 +217,7 @@
217===============217===============
218*/218*/
219void DismantleSite::draw(uint32_t gametime,219void DismantleSite::draw(uint32_t gametime,
220 const TextToDraw draw_text,
220 const Vector2f& point_on_dst,221 const Vector2f& point_on_dst,
221 float scale,222 float scale,
222 RenderTarget* dst) {223 RenderTarget* dst) {
@@ -229,5 +230,8 @@
229 // Blit bottom part of the animation according to dismantle progress230 // Blit bottom part of the animation according to dismantle progress
230 dst->blit_animation(point_on_dst, scale, building_->get_unoccupied_animation(), tanim,231 dst->blit_animation(point_on_dst, scale, building_->get_unoccupied_animation(), tanim,
231 player_color, 100 - ((get_built_per64k() * 100) >> 16));232 player_color, 100 - ((get_built_per64k() * 100) >> 16));
233
234 // Draw help strings
235 draw_info(draw_text, point_on_dst, scale, dst);
232}236}
233} // namespace Widelands237} // namespace Widelands
234238
=== modified file 'src/logic/map_objects/tribes/dismantlesite.h'
--- src/logic/map_objects/tribes/dismantlesite.h 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/dismantlesite.h 2019-02-27 17:20:33 +0000
@@ -87,8 +87,11 @@
87 return DISMANTLESITE_STEP_TIME;87 return DISMANTLESITE_STEP_TIME;
88 }88 }
8989
90 void90 void draw(uint32_t gametime,
91 draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) override;91 TextToDraw draw_text,
92 const Vector2f& point_on_dst,
93 float scale,
94 RenderTarget* dst) override;
92};95};
93} // namespace Widelands96} // namespace Widelands
9497
9598
=== modified file 'src/logic/map_objects/tribes/ship.cc'
--- src/logic/map_objects/tribes/ship.cc 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/ship.cc 2019-02-27 17:20:33 +0000
@@ -977,53 +977,55 @@
977 ship_wakeup(game);977 ship_wakeup(game);
978}978}
979979
980std::string Ship::info_string(const MapObject::InfoStringType format) {980void Ship::draw(const EditorGameBase& egbase,
981 const TextToDraw& draw_text,
982 const Vector2f& field_on_dst,
983 const float scale,
984 RenderTarget* dst) const {
985 Bob::draw(egbase, draw_text, field_on_dst, scale, dst);
986
981 // Show ship name and current activity987 // Show ship name and current activity
982 std::string result;988 std::string statistics_string;
983 switch (format) {989 if ((draw_text & TextToDraw::kStatistics) != TextToDraw::kNone) {
984 case MapObject::InfoStringType::kCensus:
985 result = shipname_;
986 break;
987 case MapObject::InfoStringType::kStatistics: {
988 switch (ship_state_) {990 switch (ship_state_) {
989 case (ShipStates::kTransport):991 case (ShipStates::kTransport):
990 if (destination_.is_set()) {992 if (destination_.is_set()) {
991 /** TRANSLATORS: This is a ship state. The ship is currently transporting wares. */993 /** TRANSLATORS: This is a ship state. The ship is currently transporting wares. */
992 result = pgettext("ship_state", "Shipping");994 statistics_string = pgettext("ship_state", "Shipping");
993 } else {995 } else {
994 /** TRANSLATORS: This is a ship state. The ship is ready to transport wares, but has996 /** TRANSLATORS: This is a ship state. The ship is ready to transport wares, but has
995 * nothing to do. */997 * nothing to do. */
996 result = pgettext("ship_state", "Idle");998 statistics_string = pgettext("ship_state", "Idle");
997 }999 }
998 break;1000 break;
999 case (ShipStates::kExpeditionWaiting):1001 case (ShipStates::kExpeditionWaiting):
1000 /** TRANSLATORS: This is a ship state. An expedition is waiting for your commands. */1002 /** TRANSLATORS: This is a ship state. An expedition is waiting for your commands. */
1001 result = pgettext("ship_state", "Waiting");1003 statistics_string = pgettext("ship_state", "Waiting");
1002 break;1004 break;
1003 case (ShipStates::kExpeditionScouting):1005 case (ShipStates::kExpeditionScouting):
1004 /** TRANSLATORS: This is a ship state. An expedition is scouting for port spaces. */1006 /** TRANSLATORS: This is a ship state. An expedition is scouting for port spaces. */
1005 result = pgettext("ship_state", "Scouting");1007 statistics_string = pgettext("ship_state", "Scouting");
1006 break;1008 break;
1007 case (ShipStates::kExpeditionPortspaceFound):1009 case (ShipStates::kExpeditionPortspaceFound):
1008 /** TRANSLATORS: This is a ship state. An expedition has found a port space. */1010 /** TRANSLATORS: This is a ship state. An expedition has found a port space. */
1009 result = pgettext("ship_state", "Port Space Found");1011 statistics_string = pgettext("ship_state", "Port Space Found");
1010 break;1012 break;
1011 case (ShipStates::kExpeditionColonizing):1013 case (ShipStates::kExpeditionColonizing):
1012 /** TRANSLATORS: This is a ship state. An expedition is unloading wares/workers to build a1014 /** TRANSLATORS: This is a ship state. An expedition is unloading wares/workers to build a
1013 * port. */1015 * port. */
1014 result = pgettext("ship_state", "Founding a Colony");1016 statistics_string = pgettext("ship_state", "Founding a Colony");
1015 break;1017 break;
1016 case (ShipStates::kSinkRequest):1018 case (ShipStates::kSinkRequest):
1017 case (ShipStates::kSinkAnimation):1019 case (ShipStates::kSinkAnimation):
1018 break;1020 break;
1019 }1021 }
1020 result =1022 statistics_string = (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_OK.hex_value() %
1021 (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_OK.hex_value() % result).str();1023 statistics_string)
1022 } break;1024 .str();
1023 case MapObject::InfoStringType::kTooltip:
1024 result = "";
1025 }1025 }
1026 return result;1026
1027 do_draw_info(draw_text, shipname_, statistics_string, calc_drawpos(egbase, field_on_dst, scale),
1028 scale, dst);
1027}1029}
10281030
1029void Ship::log_general_info(const EditorGameBase& egbase) const {1031void Ship::log_general_info(const EditorGameBase& egbase) const {
10301032
=== modified file 'src/logic/map_objects/tribes/ship.h'
--- src/logic/map_objects/tribes/ship.h 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/ship.h 2019-02-27 17:20:33 +0000
@@ -230,7 +230,13 @@
230230
231 void exp_cancel(Game&);231 void exp_cancel(Game&);
232 void sink_ship(Game&);232 void sink_ship(Game&);
233 std::string info_string(MapObject::InfoStringType format) override;233
234protected:
235 void draw(const EditorGameBase&,
236 const TextToDraw& draw_text,
237 const Vector2f& field_on_dst,
238 float scale,
239 RenderTarget* dst) const override;
234240
235private:241private:
236 friend struct Fleet;242 friend struct Fleet;
237243
=== modified file 'src/logic/map_objects/tribes/soldier.cc'
--- src/logic/map_objects/tribes/soldier.cc 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/soldier.cc 2019-02-27 17:20:33 +0000
@@ -439,6 +439,7 @@
439 * Draw this soldier. This basically draws him as a worker, but add health points439 * Draw this soldier. This basically draws him as a worker, but add health points
440 */440 */
441void Soldier::draw(const EditorGameBase& game,441void Soldier::draw(const EditorGameBase& game,
442 const TextToDraw&,
442 const Vector2f& field_on_dst,443 const Vector2f& field_on_dst,
443 const float scale,444 const float scale,
444 RenderTarget* dst) const {445 RenderTarget* dst) const {
445446
=== modified file 'src/logic/map_objects/tribes/soldier.h'
--- src/logic/map_objects/tribes/soldier.h 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/soldier.h 2019-02-27 17:20:33 +0000
@@ -209,6 +209,7 @@
209209
210 /// Draw this soldier210 /// Draw this soldier
211 void draw(const EditorGameBase&,211 void draw(const EditorGameBase&,
212 const TextToDraw& draw_text,
212 const Vector2f& point_on_dst,213 const Vector2f& point_on_dst,
213 float scale,214 float scale,
214 RenderTarget* dst) const override;215 RenderTarget* dst) const override;
215216
=== modified file 'src/logic/map_objects/tribes/worker.cc'
--- src/logic/map_objects/tribes/worker.cc 2019-02-24 17:01:51 +0000
+++ src/logic/map_objects/tribes/worker.cc 2019-02-27 17:20:33 +0000
@@ -2996,6 +2996,7 @@
2996 * Draw the worker, taking the carried ware into account.2996 * Draw the worker, taking the carried ware into account.
2997 */2997 */
2998void Worker::draw(const EditorGameBase& egbase,2998void Worker::draw(const EditorGameBase& egbase,
2999 const TextToDraw&,
2999 const Vector2f& field_on_dst,3000 const Vector2f& field_on_dst,
3000 const float scale,3001 const float scale,
3001 RenderTarget* dst) const {3002 RenderTarget* dst) const {
30023003
=== modified file 'src/logic/map_objects/tribes/worker.h'
--- src/logic/map_objects/tribes/worker.h 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/worker.h 2019-02-27 17:20:33 +0000
@@ -182,6 +182,7 @@
182 const float scale,182 const float scale,
183 RenderTarget* dst) const;183 RenderTarget* dst) const;
184 void draw(const EditorGameBase&,184 void draw(const EditorGameBase&,
185 const TextToDraw& draw_text,
185 const Vector2f& field_on_dst,186 const Vector2f& field_on_dst,
186 float scale,187 float scale,
187 RenderTarget* dst) const override;188 RenderTarget* dst) const override;
188189
=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc 2019-02-23 11:00:49 +0000
+++ src/wui/interactive_base.cc 2019-02-27 17:20:33 +0000
@@ -223,7 +223,7 @@
223 player.is_hostile(*productionsite->get_owner())))223 player.is_hostile(*productionsite->get_owner())))
224 return set_tooltip("");224 return set_tooltip("");
225 }225 }
226 set_tooltip(productionsite->info_string(Widelands::MapObject::InfoStringType::kTooltip));226 set_tooltip(productionsite->info_string(Widelands::Building::InfoStringFormat::kTooltip));
227 return;227 return;
228 }228 }
229 set_tooltip("");229 set_tooltip("");
230230
=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h 2019-02-23 11:00:49 +0000
+++ src/wui/interactive_base.h 2019-02-27 17:20:33 +0000
@@ -47,16 +47,6 @@
47class EdgeOverlayManager;47class EdgeOverlayManager;
48class UniqueWindowHandler;48class UniqueWindowHandler;
4949
50enum TextToDraw {
51 kNone = 0,
52 kCensus = 1,
53 kStatistics = 2,
54};
55
56inline TextToDraw operator|(TextToDraw a, TextToDraw b) {
57 return static_cast<TextToDraw>(static_cast<int>(a) | static_cast<int>(b));
58}
59
60/**50/**
61 * This is used to represent the code that InteractivePlayer and51 * This is used to represent the code that InteractivePlayer and
62 * EditorInteractive share.52 * EditorInteractive share.
6353
=== modified file 'src/wui/interactive_gamebase.cc'
--- src/wui/interactive_gamebase.cc 2019-02-24 22:50:04 +0000
+++ src/wui/interactive_gamebase.cc 2019-02-27 17:20:33 +0000
@@ -56,46 +56,6 @@
56 return _("PAUSE");56 return _("PAUSE");
57}57}
5858
59// Draws census and statistics on screen for the given map object
60void draw_mapobject_infotext(RenderTarget* dst,
61 const Vector2i& init_position,
62 float scale,
63 Widelands::MapObject* mapobject,
64 const TextToDraw text_to_draw) {
65 const std::string census_string =
66 mapobject->info_string(Widelands::MapObject::InfoStringType::kCensus);
67 if (census_string.empty()) {
68 // If there is no census available for the map object, we also won't have any statistics.
69 return;
70 }
71
72 const std::string statistics_string =
73 (text_to_draw & TextToDraw::kStatistics) ?
74 mapobject->info_string(Widelands::MapObject::InfoStringType::kStatistics) :
75 "";
76 if (census_string.empty() && statistics_string.empty()) {
77 // Nothing to do
78 return;
79 }
80
81 const int font_size = scale * UI_FONT_SIZE_SMALL;
82
83 // We always render this so we can have a stable position for the statistics string.
84 std::shared_ptr<const UI::RenderedText> rendered_census =
85 UI::g_fh->render(as_condensed(census_string, UI::Align::kCenter, font_size), 120 * scale);
86 Vector2i position = init_position - Vector2i(0, 48) * scale;
87 if (text_to_draw & TextToDraw::kCensus) {
88 rendered_census->draw(*dst, position, UI::Align::kCenter);
89 }
90
91 if (!statistics_string.empty()) {
92 std::shared_ptr<const UI::RenderedText> rendered_statistics =
93 UI::g_fh->render(as_condensed(statistics_string, UI::Align::kCenter, font_size));
94 position.y += rendered_census->height() + text_height(font_size) / 4;
95 rendered_statistics->draw(*dst, position, UI::Align::kCenter);
96 }
97}
98
99} // namespace59} // namespace
10060
101InteractiveGameBase::InteractiveGameBase(Widelands::Game& g,61InteractiveGameBase::InteractiveGameBase(Widelands::Game& g,
@@ -179,34 +139,6 @@
179 }139 }
180}140}
181141
182void InteractiveGameBase::draw_mapobject_infotexts(
183 RenderTarget* dst,
184 float scale,
185 const std::vector<std::pair<Vector2i, Widelands::MapObject*>>& mapobjects_to_draw_text_for,
186 const TextToDraw text_to_draw,
187 const Widelands::Player* plr) const {
188 // Rendering text is expensive, so let's just do it for only a few sizes.
189 // The formula is a bit fancy to avoid too much text overlap.
190 const float scale_for_text =
191 std::round(2.f * (scale > 1.f ? std::sqrt(scale) : std::pow(scale, 2.f))) / 2.f;
192 if (scale_for_text < 1.f) {
193 return;
194 }
195
196 for (const auto& draw_my_text : mapobjects_to_draw_text_for) {
197 TextToDraw draw_text_for_this_mapobject = text_to_draw;
198 const Widelands::Player* owner = draw_my_text.second->get_owner();
199 if (owner != nullptr && plr != nullptr && !plr->see_all() && plr->is_hostile(*owner)) {
200 draw_text_for_this_mapobject =
201 static_cast<TextToDraw>(draw_text_for_this_mapobject & ~TextToDraw::kStatistics);
202 }
203 if (draw_text_for_this_mapobject != TextToDraw::kNone) {
204 draw_mapobject_infotext(dst, draw_my_text.first, scale_for_text, draw_my_text.second,
205 draw_text_for_this_mapobject);
206 }
207 }
208}
209
210/**142/**
211 * Called for every game after loading (from a savegame or just from a map143 * Called for every game after loading (from a savegame or just from a map
212 * during single/multiplayer/scenario).144 * during single/multiplayer/scenario).
213145
=== modified file 'src/wui/interactive_gamebase.h'
--- src/wui/interactive_gamebase.h 2019-02-23 11:00:49 +0000
+++ src/wui/interactive_gamebase.h 2019-02-27 17:20:33 +0000
@@ -102,13 +102,6 @@
102 void start() override;102 void start() override;
103103
104protected:104protected:
105 /// Draws census and statistics on screen for the listed mapobjects
106 void draw_mapobject_infotexts(
107 RenderTarget* dst,
108 float scale,
109 const std::vector<std::pair<Vector2i, Widelands::MapObject*>>& mapobjects_to_draw_text_for,
110 const TextToDraw text_to_draw,
111 const Widelands::Player* plr) const;
112 void draw_overlay(RenderTarget&) override;105 void draw_overlay(RenderTarget&) override;
113106
114 GameMainMenuWindows main_windows_;107 GameMainMenuWindows main_windows_;
115108
=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc 2019-02-23 11:00:49 +0000
+++ src/wui/interactive_player.cc 2019-02-27 17:20:33 +0000
@@ -85,21 +85,42 @@
85 return brightness / 255.;85 return brightness / 255.;
86}86}
8787
88// Draws immovable if the field matches its actual position and returns true if the immovable was88// Remove statistics from the text to draw if the player does not match the map object's owner
89// drawn there.89TextToDraw filter_text_to_draw(const TextToDraw text_to_draw, const Widelands::MapObject* object, const Widelands::Player& player) {
90bool draw_immovable_for_visible_field(const Widelands::EditorGameBase& egbase,90 TextToDraw result = text_to_draw;
91 const FieldsToDraw::Field& field,91 const Widelands::Player* owner = object->get_owner();
92 const float scale,92 if (owner != nullptr && !player.see_all() && player.is_hostile(*owner)) {
93 Widelands::BaseImmovable* const imm,93 result = removeFromTextToDraw(result, TextToDraw::kStatistics);
94 RenderTarget* dst) {94 }
95 return result;
96}
97
98void draw_immovable_for_visible_field(const Widelands::EditorGameBase& egbase,
99 const FieldsToDraw::Field& field,
100 const float scale,
101 const TextToDraw text_to_draw,
102 const Widelands::Player& player,
103 RenderTarget* dst) {
104 Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();
95 if (imm != nullptr && imm->get_positions(egbase).front() == field.fcoords) {105 if (imm != nullptr && imm->get_positions(egbase).front() == field.fcoords) {
96 imm->draw(egbase.get_gametime(), field.rendertarget_pixel, scale, dst);106 imm->draw(
97 return true;107 egbase.get_gametime(), filter_text_to_draw(text_to_draw, imm, player), field.rendertarget_pixel, scale, dst);
98 }108 }
99 return false;109}
100}110
101111void draw_bobs_for_visible_field(const Widelands::EditorGameBase& egbase,
102void draw_immovables_for_formerly_visible_field(const FieldsToDraw::Field& field,112 const FieldsToDraw::Field& field,
113 const float scale,
114 const TextToDraw text_to_draw,
115 const Widelands::Player& player,
116 RenderTarget* dst) {
117 for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;
118 bob = bob->get_next_bob()) {
119 bob->draw(egbase, filter_text_to_draw(text_to_draw, bob, player), field.rendertarget_pixel, scale, dst);
120 }
121}
122
123void draw_immovable_for_formerly_visible_field(const FieldsToDraw::Field& field,
103 const Widelands::Player::Field& player_field,124 const Widelands::Player::Field& player_field,
104 const float scale,125 const float scale,
105 RenderTarget* dst) {126 RenderTarget* dst) {
@@ -267,8 +288,7 @@
267 auto* fields_to_draw = given_map_view->draw_terrain(gbase, dst);288 auto* fields_to_draw = given_map_view->draw_terrain(gbase, dst);
268 const auto& road_building = road_building_overlays();289 const auto& road_building = road_building_overlays();
269 const std::map<Widelands::Coords, const Image*> workarea_overlays = get_workarea_overlays(map);290 const std::map<Widelands::Coords, const Image*> workarea_overlays = get_workarea_overlays(map);
270 std::vector<std::pair<Vector2i, Widelands::MapObject*>> mapobjects_to_draw_text_for;291
271 const auto text_to_draw = get_text_to_draw();
272 const float scale = 1.f / given_map_view->view().zoom;292 const float scale = 1.f / given_map_view->view().zoom;
273293
274 for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) {294 for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) {
@@ -299,21 +319,12 @@
299319
300 // Render stuff that belongs to the node.320 // Render stuff that belongs to the node.
301 if (f->vision > 1) {321 if (f->vision > 1) {
302 Widelands::BaseImmovable* imm = f->fcoords.field->get_immovable();322 const auto text_to_draw = get_text_to_draw();
303 if (draw_immovable_for_visible_field(gbase, *f, scale, imm, dst)) {323 draw_immovable_for_visible_field(gbase, *f, scale, text_to_draw, plr, dst);
304 mapobjects_to_draw_text_for.push_back(324 draw_bobs_for_visible_field(gbase, *f, scale, text_to_draw, plr, dst);
305 std::make_pair(f->rendertarget_pixel.cast<int>(), imm));
306 }
307
308 for (Widelands::Bob* bob = f->fcoords.field->get_first_bob(); bob;
309 bob = bob->get_next_bob()) {
310 bob->draw(gbase, f->rendertarget_pixel, scale, dst);
311 mapobjects_to_draw_text_for.push_back(std::make_pair(
312 bob->calc_drawpos(gbase, f->rendertarget_pixel, scale).cast<int>(), bob));
313 }
314 } else if (f->vision == 1) {325 } else if (f->vision == 1) {
315 // We never show census or statistics for objects in the fog.326 // We never show census or statistics for objects in the fog.
316 draw_immovables_for_formerly_visible_field(*f, player_field, scale, dst);327 draw_immovable_for_formerly_visible_field(*f, player_field, scale, dst);
317 }328 }
318 }329 }
319330
@@ -352,8 +363,6 @@
352 }363 }
353 }364 }
354 }365 }
355 // Blit census & Statistics.
356 draw_mapobject_infotexts(dst, scale, mapobjects_to_draw_text_for, text_to_draw, &plr);
357}366}
358367
359void InteractivePlayer::popup_message(Widelands::MessageId const id,368void InteractivePlayer::popup_message(Widelands::MessageId const id,
360369
=== modified file 'src/wui/interactive_spectator.cc'
--- src/wui/interactive_spectator.cc 2019-02-23 11:00:49 +0000
+++ src/wui/interactive_spectator.cc 2019-02-27 17:20:33 +0000
@@ -122,8 +122,6 @@
122122
123 const auto text_to_draw = get_text_to_draw();123 const auto text_to_draw = get_text_to_draw();
124 const std::map<Widelands::Coords, const Image*> workarea_overlays = get_workarea_overlays(map);124 const std::map<Widelands::Coords, const Image*> workarea_overlays = get_workarea_overlays(map);
125 std::vector<std::pair<Vector2i, Widelands::MapObject*>> mapobjects_to_draw_text_for;
126
127 for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) {125 for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) {
128 const FieldsToDraw::Field& field = fields_to_draw->at(idx);126 const FieldsToDraw::Field& field = fields_to_draw->at(idx);
129127
@@ -131,16 +129,12 @@
131129
132 Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();130 Widelands::BaseImmovable* const imm = field.fcoords.field->get_immovable();
133 if (imm != nullptr && imm->get_positions(the_game).front() == field.fcoords) {131 if (imm != nullptr && imm->get_positions(the_game).front() == field.fcoords) {
134 imm->draw(gametime, field.rendertarget_pixel, scale, dst);132 imm->draw(gametime, text_to_draw, field.rendertarget_pixel, scale, dst);
135 mapobjects_to_draw_text_for.push_back(
136 std::make_pair(field.rendertarget_pixel.cast<int>(), imm));
137 }133 }
138134
139 for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;135 for (Widelands::Bob* bob = field.fcoords.field->get_first_bob(); bob;
140 bob = bob->get_next_bob()) {136 bob = bob->get_next_bob()) {
141 bob->draw(the_game, field.rendertarget_pixel, scale, dst);137 bob->draw(the_game, text_to_draw, field.rendertarget_pixel, scale, dst);
142 mapobjects_to_draw_text_for.push_back(std::make_pair(
143 bob->calc_drawpos(the_game, field.rendertarget_pixel, scale).cast<int>(), bob));
144 }138 }
145139
146 // Draw work area previews.140 // Draw work area previews.
@@ -173,9 +167,6 @@
173 blit_field_overlay(dst, field, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);167 blit_field_overlay(dst, field, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale);
174 }168 }
175 }169 }
176
177 // Blit census & Statistics.
178 draw_mapobject_infotexts(dst, scale, mapobjects_to_draw_text_for, text_to_draw, nullptr);
179}170}
180171
181/**172/**
182173
=== modified file 'src/wui/transport_draw.cc'
--- src/wui/transport_draw.cc 2019-02-23 11:00:49 +0000
+++ src/wui/transport_draw.cc 2019-02-27 17:20:33 +0000
@@ -26,7 +26,11 @@
2626
27namespace Widelands {27namespace Widelands {
2828
29void Flag::draw(uint32_t gametime, const Vector2f& point_on_dst, float scale, RenderTarget* dst) {29void Flag::draw(uint32_t gametime,
30 const TextToDraw,
31 const Vector2f& point_on_dst,
32 float scale,
33 RenderTarget* dst) {
30 static struct {34 static struct {
31 float x, y;35 float x, y;
32 } ware_offsets[8] = {{-5.f, 1.f}, {-1.f, 3.f}, {3.f, 3.f}, {7.f, 1.f},36 } ware_offsets[8] = {{-5.f, 1.f}, {-1.f, 3.f}, {3.f, 3.f}, {7.f, 1.f},
@@ -50,6 +54,6 @@
50}54}
5155
52/** The road is drawn by the terrain renderer via marked fields. */56/** The road is drawn by the terrain renderer via marked fields. */
53void Road::draw(uint32_t, const Vector2f&, float, RenderTarget*) {57void Road::draw(uint32_t, const TextToDraw, const Vector2f&, float, RenderTarget*) {
54}58}
55} // namespace Widelands59} // namespace Widelands

Subscribers

People subscribed via source and target branches

to status/vote changes: