← Back to team overview

widelands-dev team mailing list archive

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

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/map_hint_space into lp:widelands.

Commit message:
MultilineTextarea now generates an empty line for "\n\n" rather than just a line break. Added "HINTS:" label to map hints in mapdetails.cc.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/map_hint_space/+merge/285407

- MultilineTextarea now generates an empty line for "\n\n" rather than just a line break.
- Added "HINTS:" label to map hints in mapdetails.cc.

Requested by:

https://bugs.launchpad.net/widelands/+bug/1542813/comments/6
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/map_hint_space into lp:widelands.
=== modified file 'src/ui_basic/multilinetextarea.cc'
--- src/ui_basic/multilinetextarea.cc	2016-02-03 18:09:15 +0000
+++ src/ui_basic/multilinetextarea.cc	2016-02-08 20:40:19 +0000
@@ -86,10 +86,7 @@
 	for (int i = 0; i < 2; ++i) {
 		if (text_.compare(0, 3, "<rt")) {
 			isrichtext = false;
-			std::string text_to_render = richtext_escape(text_);
-			boost::replace_all(text_to_render, "\n", "<br>");
-			const Image* text_im = UI::g_fh1->render(as_uifont(text_to_render, style_.font->size(), style_.fg),
-																  get_eff_w() - 2 * RICHTEXT_MARGIN);
+			const Image* text_im = UI::g_fh1->render(make_richtext(), get_eff_w() - 2 * RICHTEXT_MARGIN);
 			height = text_im->height();
 		} else {
 			isrichtext = true;
@@ -145,11 +142,7 @@
 	if (isrichtext) {
 		rt.draw(dst, Point(RICHTEXT_MARGIN, RICHTEXT_MARGIN - scrollbar_.get_scrollpos()));
 	} else {
-		std::string text_to_render = richtext_escape(text_);
-		boost::replace_all(text_to_render, "\n", "<br>");
-		const Image* text_im =
-				UI::g_fh1->render(as_aligned(text_to_render, align_, style_.font->size(), style_.fg),
-										get_eff_w() - 2 * RICHTEXT_MARGIN);
+		const Image* text_im = UI::g_fh1->render(make_richtext(), get_eff_w() - 2 * RICHTEXT_MARGIN);
 
 		uint32_t blit_width = std::min(text_im->width(), static_cast<int>(get_eff_w()));
 		uint32_t blit_height = std::min(text_im->height(), static_cast<int>(get_inner_h()));
@@ -188,4 +181,11 @@
 	scrollbar_.set_scrollpos(0);
 }
 
+std::string MultilineTextarea::make_richtext() {
+	std::string temp = richtext_escape(text_);
+	boost::replace_all(temp, "\n\n", "<br>&nbsp;<br>"); // Double paragraphs should generate an empty line.
+	boost::replace_all(temp, "\n", "<br>");
+	return as_aligned(temp, align_, style_.font->size(), style_.fg);
+}
+
 } // namespace UI

=== modified file 'src/ui_basic/multilinetextarea.h'
--- src/ui_basic/multilinetextarea.h	2016-02-03 18:09:15 +0000
+++ src/ui_basic/multilinetextarea.h	2016-02-08 20:40:19 +0000
@@ -74,6 +74,12 @@
 	void recompute();
 	void scrollpos_changed(int32_t pixels);
 
+	/**
+	 * This prepares a non-richtext text for rendering. It escapes the source text and
+	 * turns \n into <br> tags as needed, then creates the richtext style wrappers.
+	 */
+	std::string make_richtext();
+
 	std::string text_;
 	UI::TextStyle style_;
 	Align align_;

=== modified file 'src/wui/mapdetails.cc'
--- src/wui/mapdetails.cc	2015-12-17 09:36:59 +0000
+++ src/wui/mapdetails.cc	2016-02-08 20:40:19 +0000
@@ -131,8 +131,10 @@
 		author_label_.set_text(ngettext("Author:", "Authors:", mapdata.authors.get_number()));
 		author_.set_text(mapdata.authors.get_names());
 		descr_label_.set_text(_("Description:"));
-		descr_.set_text(mapdata.description +
-										  (mapdata.hint.empty() ? "" : (std::string("\n\n") + mapdata.hint)));
+		descr_.set_text(
+					mapdata.description +
+					/** TRANSLATORS: Map hint header when selecting a map. */
+					(mapdata.hint.empty() ? "" : (std::string("\n\n") + _("HINT:") + "\n" + mapdata.hint)));
 
 		// Show / hide suggested teams
 		if (mapdata.suggested_teams.empty()) {


Follow ups