← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/toggle_immovables into lp:widelands

 

SirVer has proposed merging lp:~widelands-dev/widelands/toggle_immovables into lp:widelands with lp:~widelands-dev/widelands/toggle_resources as a prerequisite.

Commit message:
Make display of bobs and immovables toggable.

Hotkey for bob is "a" for "Animal" and for immovables is the in bug 1649958 suggested "w".

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/toggle_immovables/+merge/328977
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/toggle_immovables into lp:widelands.
=== added file 'data/images/wui/menus/menu_toggle_bobs.png'
Binary files data/images/wui/menus/menu_toggle_bobs.png	1970-01-01 00:00:00 +0000 and data/images/wui/menus/menu_toggle_bobs.png	2017-08-14 13:55:39 +0000 differ
=== added file 'data/images/wui/menus/menu_toggle_immovables.png'
Binary files data/images/wui/menus/menu_toggle_immovables.png	1970-01-01 00:00:00 +0000 and data/images/wui/menus/menu_toggle_immovables.png	2017-08-14 13:55:39 +0000 differ
=== modified file 'data/scripting/editor/editor_controls.lua'
--- data/scripting/editor/editor_controls.lua	2017-08-14 13:55:39 +0000
+++ data/scripting/editor/editor_controls.lua	2017-08-14 13:55:39 +0000
@@ -25,6 +25,10 @@
             dl(help_format_hotkey("P"), _"Toggle player menu") ..
             -- TRANSLATORS: This is an access key combination. The hotkey is 'q'
             dl(help_format_hotkey("Q"), _"Toggle resources display") ..
+            -- TRANSLATORS: This is an access key combination. The hotkey is 'w'
+            dl(help_format_hotkey("W"), _"Toggle immovables display") ..
+            -- TRANSLATORS: This is an access key combination. The hotkey is 'a'
+            dl(help_format_hotkey("A"), _"Toggle animals display") ..
             -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
             dl(help_format_hotkey("Ctrl + Z"), _"Undo") ..
             -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.

=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc	2017-08-14 13:55:39 +0000
+++ src/editor/editorinteractive.cc	2017-08-14 13:55:39 +0000
@@ -122,6 +122,14 @@
 	   "wui/menus/menu_toggle_resources", "resources", _("Show Resources (on/off)"));
 	toggle_resources_->set_perm_pressed(true);
 	toggle_resources_->sigclicked.connect([this]() { toggle_resources(); });
+	toggle_immovables_ = add_toolbar_button(
+	   "wui/menus/menu_toggle_immovables", "immovables", _("Show Immovables (on/off)"));
+	toggle_immovables_->set_perm_pressed(true);
+	toggle_immovables_->sigclicked.connect([this]() { toggle_immovables(); });
+	toggle_bobs_ = add_toolbar_button(
+	   "wui/menus/menu_toggle_bobs", "animals", _("Show Animals (on/off)"));
+	toggle_bobs_->set_perm_pressed(true);
+	toggle_bobs_->sigclicked.connect([this]() { toggle_bobs(); });
 
 	toolbar_.add_space(15);
 
@@ -339,6 +347,18 @@
 	toggle_resources_->set_perm_pressed(value);
 }
 
+void EditorInteractive::toggle_immovables() {
+	const bool value = !draw_immovables();
+	set_draw_immovables(value);
+	toggle_immovables_->set_perm_pressed(value);
+}
+
+void EditorInteractive::toggle_bobs() {
+	const bool value = !draw_bobs();
+	set_draw_bobs(value);
+	toggle_bobs_->set_perm_pressed(value);
+}
+
 bool EditorInteractive::handle_key(bool const down, SDL_Keysym const code) {
 	bool handled = InteractiveBase::handle_key(down, code);
 
@@ -413,6 +433,11 @@
 			handled = true;
 			break;
 
+		case SDLK_a:
+			toggle_bobs();
+			handled = true;
+			break;
+
 		case SDLK_c:
 			set_display_flag(
 			   InteractiveBase::dfShowCensus, !get_display_flag(InteractiveBase::dfShowCensus));
@@ -461,6 +486,11 @@
 			handled = true;
 			break;
 
+		case SDLK_w:
+			toggle_immovables();
+			handled = true;
+			break;
+
 		case SDLK_y:
 			if (code.mod & (KMOD_LCTRL | KMOD_RCTRL))
 				history_->redo_action(egbase().world());

=== modified file 'src/editor/editorinteractive.h'
--- src/editor/editorinteractive.h	2017-08-14 13:55:39 +0000
+++ src/editor/editorinteractive.h	2017-08-14 13:55:39 +0000
@@ -157,6 +157,8 @@
 	void on_buildhelp_changed(const bool value) override;
 
 	void toggle_resources();
+	void toggle_immovables();
+	void toggle_bobs();
 
 	//  state variables
 	bool need_save_;
@@ -181,6 +183,8 @@
 
 	UI::Button* toggle_buildhelp_;
 	UI::Button* toggle_resources_;
+	UI::Button* toggle_immovables_;
+	UI::Button* toggle_bobs_;
 	UI::Button* undo_;
 	UI::Button* redo_;
 

=== modified file 'src/graphic/game_renderer.cc'
--- src/graphic/game_renderer.cc	2017-08-14 13:55:39 +0000
+++ src/graphic/game_renderer.cc	2017-08-14 13:55:39 +0000
@@ -96,7 +96,7 @@
 	return brightness / 255.;
 }
 
-void draw_objects_for_visible_field(const EditorGameBase& egbase,
+void draw_immovables_for_visible_field(const EditorGameBase& egbase,
                                     const FieldsToDraw::Field& field,
                                     const float zoom,
                                     const TextToDraw text_to_draw,
@@ -111,10 +111,17 @@
 			draw_text_for_this_immovable =
 			   static_cast<TextToDraw>(draw_text_for_this_immovable & ~TextToDraw::kStatistics);
 		}
-
 		imm->draw(
 		   egbase.get_gametime(), draw_text_for_this_immovable, field.rendertarget_pixel, zoom, dst);
 	}
+}
+
+void draw_bobs_for_visible_field(const EditorGameBase& egbase,
+                                    const FieldsToDraw::Field& field,
+                                    const float zoom,
+                                    const TextToDraw text_to_draw,
+                                    const Player* player,
+                                    RenderTarget* dst) {
 	for (Bob* bob = field.fcoords.field->get_first_bob(); bob; bob = bob->get_next_bob()) {
 		TextToDraw draw_text_for_this_bob = text_to_draw;
 		const Player* owner = bob->get_owner();
@@ -127,7 +134,7 @@
 	}
 }
 
-void draw_objects_for_formerly_visible_field(const FieldsToDraw::Field& field,
+void draw_immovables_for_formerly_visible_field(const FieldsToDraw::Field& field,
                                              const Player::Field& player_field,
                                              const float zoom,
                                              RenderTarget* dst) {
@@ -209,6 +216,8 @@
                   const FieldsToDraw& fields_to_draw,
                   const Player* player,
                   const TextToDraw text_to_draw,
+						const GameRenderer::DrawImmovables& draw_immovables,
+						const GameRenderer::DrawBobs& draw_bobs,
                   RenderTarget* dst) {
 	for (size_t current_index = 0; current_index < fields_to_draw.size(); ++current_index) {
 		const FieldsToDraw::Field& field = fields_to_draw.at(current_index);
@@ -220,7 +229,7 @@
 		const FieldsToDraw::Field& bln = fields_to_draw.at(field.bln_index);
 		const FieldsToDraw::Field& brn = fields_to_draw.at(field.brn_index);
 
-		if (field.is_border) {
+		if (field.is_border && draw_immovables == GameRenderer::DrawImmovables::kYes) {
 			assert(field.owner != nullptr);
 			uint32_t const anim_idx = field.owner->tribe().frontier_animation();
 			if (field.vision) {
@@ -237,14 +246,19 @@
 		}
 
 		if (1 < field.vision) {  // Render stuff that belongs to the node.
-			draw_objects_for_visible_field(egbase, field, zoom, text_to_draw, player, dst);
-		} else if (field.vision == 1) {
+			if (draw_immovables == GameRenderer::DrawImmovables::kYes) {
+				draw_immovables_for_visible_field(egbase, field, zoom, text_to_draw, player, dst);
+			}
+			if (draw_bobs == GameRenderer::DrawBobs::kYes) {
+				draw_bobs_for_visible_field(egbase, field, zoom, text_to_draw, player, dst);
+			}
+		} else if (field.vision == 1 && draw_immovables == GameRenderer::DrawImmovables::kYes) {
 			// We never show census or statistics for objects in the fog.
 			assert(player != nullptr);
 			const Map& map = egbase.map();
 			const Player::Field& player_field =
 			   player->fields()[map.get_index(field.fcoords, map.get_width())];
-			draw_objects_for_formerly_visible_field(field, player_field, zoom, dst);
+			draw_immovables_for_formerly_visible_field(field, player_field, zoom, dst);
 		}
 
 		egbase.get_ibase()->field_overlay_manager().foreach_overlay(
@@ -271,21 +285,25 @@
                              const Widelands::Player& player,
                              const Overlays& overlays,
                              RenderTarget* dst) {
-	draw(egbase, viewpoint, zoom, overlays, &player, dst);
+	draw(egbase, viewpoint, zoom, overlays, DrawImmovables::kYes, DrawBobs::kYes, &player, dst);
 }
 
 void GameRenderer::rendermap(const Widelands::EditorGameBase& egbase,
                              const Vector2f& viewpoint,
                              const float zoom,
                              const Overlays& overlays,
+                             const DrawImmovables& draw_immovables,
+                             const DrawBobs& draw_bobs,
                              RenderTarget* dst) {
-	draw(egbase, viewpoint, zoom, overlays, nullptr, dst);
+	draw(egbase, viewpoint, zoom, overlays, draw_immovables, draw_bobs, nullptr, dst);
 }
 
 void GameRenderer::draw(const EditorGameBase& egbase,
                         const Vector2f& viewpoint,
                         const float zoom,
                         const Overlays& overlays,
+                        const DrawImmovables& draw_immovables,
+                        const DrawBobs& draw_bobs,
                         const Player* player,
                         RenderTarget* dst) {
 	assert(viewpoint.x >= 0);  // divisions involving negative numbers are bad
@@ -410,5 +428,6 @@
 	i.program_id = RenderQueue::Program::kTerrainRoad;
 	RenderQueue::instance().enqueue(i);
 
-	draw_objects(egbase, scale, fields_to_draw_, player, overlays.text_to_draw, dst);
+	draw_objects(egbase, scale, fields_to_draw_, player, overlays.text_to_draw, draw_immovables,
+	             draw_bobs, dst);
 }

=== modified file 'src/graphic/game_renderer.h'
--- src/graphic/game_renderer.h	2017-08-12 20:13:24 +0000
+++ src/graphic/game_renderer.h	2017-08-14 13:55:39 +0000
@@ -43,6 +43,9 @@
 		std::map<Widelands::Coords, uint8_t> road_building_preview;
 	};
 
+	enum class DrawImmovables { kNo, kYes };
+	enum class DrawBobs { kNo, kYes };
+
 	GameRenderer();
 	~GameRenderer();
 
@@ -57,11 +60,14 @@
 	               RenderTarget* dst);
 
 	// Renders the map from an omniscient perspective. This is used
-	// for spectators, players that see all, and in the editor.
+	// for spectators, players that see all, and in the editor. Only in the editor we allow toggling
+	// of immovables and bobs.
 	void rendermap(const Widelands::EditorGameBase& egbase,
 	               const Vector2f& viewpoint,
 	               float scale,
 	               const Overlays& overlays,
+						const DrawImmovables& draw_immovables,
+						const DrawBobs& draw_bobs,
 	               RenderTarget* dst);
 
 private:
@@ -71,6 +77,8 @@
 	          const Vector2f& viewpoint,
 	          float scale,
 	          const Overlays& overlays,
+	          const DrawImmovables& draw_immovables,
+	          const DrawBobs& draw_bobs,
 	          const Widelands::Player* player,
 	          RenderTarget* dst);
 

=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc	2017-08-14 13:55:39 +0000
+++ src/wui/interactive_base.cc	2017-08-14 13:55:39 +0000
@@ -93,6 +93,8 @@
      lastframe_(SDL_GetTicks()),
      frametime_(0),
      avg_usframetime_(0),
+	  draw_immovables_(true),
+	  draw_bobs_(true),
      road_buildhelp_overlay_jobid_(0),
      buildroad_(nullptr),
      road_build_player_(0),
@@ -223,6 +225,22 @@
 	on_buildhelp_changed(t);
 }
 
+bool InteractiveBase::draw_bobs() const {
+	return draw_bobs_;
+}
+
+void InteractiveBase::set_draw_bobs(const bool value) {
+	draw_bobs_ = value;
+}
+
+bool InteractiveBase::draw_immovables() const {
+	return draw_immovables_;
+}
+
+void InteractiveBase::set_draw_immovables(const bool value) {
+	draw_immovables_ = value;
+}
+
 void InteractiveBase::toggle_buildhelp() {
 	show_buildhelp(!field_overlay_manager_->buildhelp());
 }

=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h	2017-08-12 08:19:27 +0000
+++ src/wui/interactive_base.h	2017-08-14 13:55:39 +0000
@@ -100,6 +100,14 @@
 	// Sets if the buildhelp should be displayed. Will also call on_buildhelp_changed().
 	void show_buildhelp(bool t);
 
+	// Returns true if bobs or immovables should be rendered.
+	bool draw_bobs() const;
+	bool draw_immovables() const;
+
+	// Sets if bobs or immovables should be rendered.
+	void set_draw_bobs(bool value);
+	void set_draw_immovables(bool value);
+
 	/**
 	 * sel_triangles determines whether the mouse pointer selects triangles.
 	 * (False meas that it selects nodes.)
@@ -256,6 +264,8 @@
 	uint32_t lastframe_;        //  system time (milliseconds)
 	uint32_t frametime_;        //  in millseconds
 	uint32_t avg_usframetime_;  //  in microseconds!
+	bool draw_immovables_;
+	bool draw_bobs_;
 
 	FieldOverlayManager::OverlayId road_buildhelp_overlay_jobid_;
 	Widelands::CoordPath* buildroad_;  //  path for the new road

=== modified file 'src/wui/mapview.cc'
--- src/wui/mapview.cc	2017-08-12 20:13:24 +0000
+++ src/wui/mapview.cc	2017-08-14 13:55:39 +0000
@@ -407,8 +407,13 @@
 		renderer_->rendermap(
 		   egbase, view_.viewpoint, view_.zoom, interactive_player->player(), overlays, &dst);
 	} else {
+		const auto draw_immovables = intbase().draw_immovables() ?
+		                                  GameRenderer::DrawImmovables::kYes :
+		                                  GameRenderer::DrawImmovables::kNo;
+		const auto draw_bobs =
+		   intbase().draw_bobs() ? GameRenderer::DrawBobs::kYes : GameRenderer::DrawBobs::kNo;
 		const GameRenderer::Overlays overlays{static_cast<TextToDraw>(text_to_draw), {}};
-		renderer_->rendermap(egbase, view_.viewpoint, view_.zoom, overlays, &dst);
+		renderer_->rendermap(egbase, view_.viewpoint, view_.zoom, overlays, draw_immovables, draw_bobs, &dst);
 	}
 }
 


Follow ups