← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/fh1-editorhelp into lp:widelands

 

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

Commit message:
Started converting the in-game help to the new font renderer

- The encyclopedia can now handle both font renderers
- The new font renderer will now return empty rendered text for newline nodes rather than crashing
- Converted all editor help to new font renderer
- Converted "General" tab of the Tribal Encyclopedia to new font renderer

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/fh1-editorhelp/+merge/335283

Started converting the in-game help to the new font renderer.

The renderer will now return empty rendered text for newline nodes rather than crashing, since I can't find the bug, and it has been holding things up for a year now. So, I decided to work around this bug, which is less bad then the bugs in the old font renderer.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/fh1-editorhelp into lp:widelands.
=== modified file 'data/scripting/editor/editor_controls.lua'
--- data/scripting/editor/editor_controls.lua	2017-08-16 05:33:50 +0000
+++ data/scripting/editor/editor_controls.lua	2017-12-16 17:04:57 +0000
@@ -1,4 +1,4 @@
-include "scripting/formatting.lua"
+include "scripting/richtext.lua"
 include "txts/help/common_helptexts.lua"
 
 local toggle_minimap_hotkey = help_toggle_minimap_hotkey()
@@ -10,50 +10,40 @@
 return {
    title = _"Controls",
    text =
-      rt(
-         h2(_"Keyboard Shortcuts") ..
-         p(
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey("F1"), _"Help") ..
-            -- TRANSLATORS: This is an access key combination.
-            dl(help_format_hotkey("H"), _"Toggle main menu") ..
-            -- TRANSLATORS: This is an access key combination. The hotkey is 't'
-            dl(help_format_hotkey("T"), _"Toggle tools menu") ..
-            toggle_minimap_hotkey ..
-            toggle_building_spaces_hotkey ..
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey("Ctrl + 1"), _"Toggle building spaces") ..
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey("Ctrl + 2"), _"Toggle immovables display") ..
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey("Ctrl + 3"), _"Toggle animals display") ..
-            -- TRANSLATORS: This is an access key combination. The hotkey is 'p'
-            dl(help_format_hotkey("Ctrl + 4"), _"Toggle resources display") ..
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey("P"), _"Toggle player menu") ..
-            -- 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.
-            dl(help_format_hotkey("Ctrl + Y"), _"Redo") ..
-            -- TRANSLATORS: This is an access key combination. The hotkey is 'i'
-            dl(help_format_hotkey("I"), _"Activate information tool") ..
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey(pgettext("hotkey", "Ctrl + L")), _"Load map") ..
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey(pgettext("hotkey", "Ctrl + S")), _"Save map") ..
+      h2(_"Keyboard Shortcuts") ..
+      p(
+         -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
+         dl(help_format_hotkey("F1"), _"Help") ..
+         -- TRANSLATORS: This is an access key combination.
+         dl(help_format_hotkey("H"), _"Toggle main menu") ..
+         -- TRANSLATORS: This is an access key combination. The hotkey is 't'
+         dl(help_format_hotkey("T"), _"Toggle tools menu") ..
+         toggle_minimap_hotkey ..
+         toggle_building_spaces_hotkey ..
+         -- TRANSLATORS: This is an access key combination. The hotkey is 'p'
+         dl(help_format_hotkey("P"), _"Toggle player menu") ..
+         -- 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.
+         dl(help_format_hotkey("Ctrl + Y"), _"Redo") ..
+         -- TRANSLATORS: This is an access key combination. The hotkey is 'i'
+         dl(help_format_hotkey("I"), _"Activate information tool") ..
+         -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
+         dl(help_format_hotkey(pgettext("hotkey", "Ctrl + L")), _"Load map") ..
+         -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
+         dl(help_format_hotkey(pgettext("hotkey", "Ctrl + S")), _"Save map") ..
             toggle_fullscreen_hotkey
-         ) ..
+      ) ..
 
-         h2(_"Tools") ..
-         p(
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey(pgettext("hotkey", "0-9")), _"Change tool size") ..
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey(pgettext("hotkey", "Click")), _"Place new elements on the map, or increase map elements by the value selected by ‘Increase/Decrease value’") ..
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey(pgettext("hotkey", "Shift + Click")), _"Remove elements from the map, or decrease map elements by the value selected by ‘Increase/Decrease value’") ..
-            -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
-            dl(help_format_hotkey(pgettext("hotkey", "Ctrl + Click")), _"Set map elements to the value selected by ‘Set Value’")
-         )
+      h2(_"Tools") ..
+      p(
+         -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
+         dl(help_format_hotkey(pgettext("hotkey", "0-9")), _"Change tool size") ..
+         -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
+         dl(help_format_hotkey(pgettext("hotkey", "Click")), _"Place new elements on the map, or increase map elements by the value selected by ‘Increase/Decrease value’") ..
+         -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
+         dl(help_format_hotkey(pgettext("hotkey", "Shift + Click")), _"Remove elements from the map, or decrease map elements by the value selected by ‘Increase/Decrease value’") ..
+         -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
+         dl(help_format_hotkey(pgettext("hotkey", "Ctrl + Click")), _"Set map elements to the value selected by ‘Set Value’")
       )
 }

=== modified file 'data/scripting/editor/editor_introduction.lua'
--- data/scripting/editor/editor_introduction.lua	2016-05-01 09:57:58 +0000
+++ data/scripting/editor/editor_introduction.lua	2017-12-16 17:04:57 +0000
@@ -1,4 +1,4 @@
-include "scripting/formatting.lua"
+include "scripting/richtext.lua"
 include "txts/help/common_helptexts.lua"
 
 local online_help = help_online_help()
@@ -8,13 +8,11 @@
 return {
    title = _"The Widelands Editor",
    text =
-      rt(
-         h1(_"Introduction") ..
-
-         p(_"This editor is intended for players who would like to design their own maps to use with Widelands.") ..
-         p(_"As you can see, this editor is heavy work in progress and as the editor becomes better and better, this text will also get longer and more complete.") ..
-
-         online_help ..
-         p(_"The wiki also includes a short tutorial on how to build a map.")
-      )
+      h1(_"Introduction") ..
+
+      p(_"This editor is intended for players who would like to design their own maps to use with Widelands.") ..
+      p(_"As you can see, this editor is heavy work in progress and as the editor becomes better and better, this text will also get longer and more complete.") ..
+
+      online_help ..
+      p(_"The wiki also includes a short tutorial on how to build a map.")
 }

=== removed file 'data/scripting/editor/format_editor.lua'
--- data/scripting/editor/format_editor.lua	2016-09-01 15:43:01 +0000
+++ data/scripting/editor/format_editor.lua	1970-01-01 00:00:00 +0000
@@ -1,31 +0,0 @@
--- RST
--- format_editor.lua
--- -----------------
---
--- Functions used in the ingame editor help windows for formatting the text and pictures.
-
-include "scripting/formatting.lua"
-
--- RST
--- .. function:: picture_li(imagepath, text)
---
---    Places a paragraph of text to the right of an image
-
---    :arg imagepath: the full path to the image file
---    :arg text: the text to be placed next to the image
---
---    :returns: the text wrapped in a paragraph and placed next to the image
-function picture_li(imagepath, text)
-   return "<rt image=" .. imagepath .. " image-align=left>"
-      .. p(text) .. "</rt>"
-end
-
--- RST
--- .. function:: spacer()
---
---    Adds a little space between two paragraphs
---
---    :returns: a small empty paragraph
-function spacer()
-   return rt(p("font-size=3", ""))
-end

=== modified file 'data/scripting/editor/terrain_help.lua'
--- data/scripting/editor/terrain_help.lua	2016-09-01 15:23:25 +0000
+++ data/scripting/editor/terrain_help.lua	2017-12-16 17:04:57 +0000
@@ -5,7 +5,7 @@
 -- This script returns a formatted entry for the terrain help in the editor.
 -- Pass the internal terrain name to the coroutine to select the terrain type.
 
-include "scripting/editor/format_editor.lua"
+include "scripting/richtext.lua"
 
 return {
    func = function(terrain_name)
@@ -13,25 +13,25 @@
       local world = wl.World();
       local terrain = wl.Editor():get_terrain_description(terrain_name)
 
-      local result = picture_li(terrain.representative_image, "")
+      local result = li_image(terrain.representative_image, "")
 
       -- Resources
       local valid_resources = terrain.valid_resources
       if (#valid_resources > 0) then
-         result = result .. spacer() .. rt(h2(_"Resources"))
+         result = result .. h2(_"Resources")
          if (#valid_resources > 0) then
             -- TRANSLATORS: A header in the editor help
-            result = result .. rt(h3(ngettext(
-               "Valid Resource:", "Valid Resources:", #valid_resources)))
+            result = result .. h3(ngettext(
+               "Valid Resource:", "Valid Resources:", #valid_resources))
             for count, resource in pairs(valid_resources) do
-               result = result .. picture_li(
+               result = result .. li_image(
                   resource.representative_image, resource.descname)
             end
          end
 
          local default_resource = terrain.default_resource
          if (default_resource ~= nil) then
-            result = result .. text_line(_"Default:",
+            result = result .. inline_header(_"Default:",
                -- TRANSLATORS: e.g. "5x Water"
                _"%1%x %2%":bformat(terrain.default_resource_amount, default_resource.descname))
          end
@@ -59,21 +59,22 @@
 
       local tree_string = ""
       for k,v in ipairs(tree_list) do
-         tree_string = tree_string .. picture_li(v.tree.representative_image,
-            v.tree.species .. ("<br>%2.1f%%"):bformat(100 * v.probability)) .. spacer()
+         tree_string = tree_string .. li_image(v.tree.representative_image,
+            v.tree.species .. ("<br>%2.1f%%"):bformat(100 * v.probability)) .. vspace(3)
       end
 
       -- TRANSLATORS: A header in the editor help
-      result = result .. spacer() .. rt(h2(_"Probability of trees growing")) .. spacer()
+      result = result .. vspace(3) .. h2(vspace(12) .. _"Probability of trees growing") .. vspace(3)
 
       if (tree_string ~="") then
          result = result .. tree_string
       else
-         result = result .. rt(p(_"No trees will grow here."))
+         result = result .. p(_"No trees will grow here.")
       end
+
       return {
          title = terrain.descname,
-         text = result
+         text = div("width=100%", result)
       }
    end
 }

=== modified file 'data/scripting/editor/tips.lua'
--- data/scripting/editor/tips.lua	2016-10-19 09:00:29 +0000
+++ data/scripting/editor/tips.lua	2017-12-16 17:04:57 +0000
@@ -1,18 +1,17 @@
-include "scripting/formatting.lua"
+include "scripting/richtext.lua"
 
 function get_editor_tips()
    include "txts/tips/editor.lua"
    return tips
 end
 
-local text = paragraphdivider()
+local text = ""
 for index, contents in pairs(get_editor_tips()) do
-   text = text .. listitem_bullet(contents["text"])
+   text = text .. li(contents["text"])
 end
-text = text .. "</p>"
 
 set_textdomain("widelands_editor")
 return {
   title = _"Tips",
-  text = rt(text)
+  text = text
 }

=== modified file 'data/scripting/editor/tree_help.lua'
--- data/scripting/editor/tree_help.lua	2016-09-01 15:23:25 +0000
+++ data/scripting/editor/tree_help.lua	2017-12-16 17:04:57 +0000
@@ -5,17 +5,17 @@
 -- This script returns a formatted entry for the tree help in the editor.
 -- Pass the internal tree name to the coroutine to select the tree type.
 
-include "scripting/editor/format_editor.lua"
+include "scripting/richtext.lua"
 
 return {
    func = function(tree_name)
       set_textdomain("widelands_editor")
       local world = wl.World();
       local tree = wl.Editor():get_immovable_description(tree_name)
-      local result = picture_li(tree.representative_image, "")
+      local result = li_image(tree.representative_image, "")
 
       -- TRANSLATORS: A header in the editor help. Terrains preferred by a type of tree.
-      result = result .. rt(p("font-size=3", "")) .. rt(h2(_"Preferred terrains")) .. spacer()
+      result = result .. h2(_"Preferred terrains")
       terrain_list = {}
       for i, terrain in ipairs(world.terrain_descriptions) do
          local probability = tree:probability_to_grow(terrain)
@@ -34,11 +34,11 @@
       end
 
       for k,v in ipairs(terrain_list) do
-         result = result .. picture_li(v.terrain.representative_image,
+         result = result .. li_image(v.terrain.representative_image,
                -- TRANSLATORS: Terrain name (Climate)
                (_"%1% (%2%)"):bformat(v.terrain.descname, v.terrain.editor_category.descname) ..
                "<br>" .. ("%2.1f%%"):bformat(100 * v.probability)
-            ) .. spacer()
+            ) .. vspace(3)
       end
       return {
          title = tree.species,

=== modified file 'data/scripting/richtext.lua'
--- data/scripting/richtext.lua	2017-07-03 10:16:59 +0000
+++ data/scripting/richtext.lua	2017-12-16 17:04:57 +0000
@@ -124,9 +124,9 @@
 --    :returns: A paragraph with text formatted as heading.
 function h1(text_or_color, text)
    if text then
-      return p_font("", "size=18 bold=1 color=".. text_or_color, vspace(6) .. text .. vspace(1))
+      return p_font("", "size=18 bold=1 color=".. text_or_color, vspace(12) .. text .. vspace(1))
    else
-      return p_font("", "size=18 bold=1 color=D1D1D1", vspace(6) .. text_or_color .. vspace(1))
+      return p_font("", "size=18 bold=1 color=D1D1D1", vspace(12) .. text_or_color .. vspace(1))
    end
 end
 
@@ -138,7 +138,7 @@
 --
 --    :returns: A paragraph with text formatted as heading.
 function h2(text)
-   return p_font("", "size=14 bold=1 color=D1D1D1", vspace(6) .. text .. vspace(1))
+   return p_font("", "size=14 bold=1 color=D1D1D1", vspace(12) .. text .. vspace(1))
 end
 
 -- RST
@@ -150,7 +150,7 @@
 --    :returns: A paragraph with text formatted as heading.
 --
 function h3(text)
-   return p_font("", "size=13 color=D1D1D1", vspace(4) .. text .. vspace(1))
+   return p_font("", "size=13 color=D1D1D1", vspace(6) .. text .. vspace(1))
 end
 
 -- RST
@@ -307,9 +307,9 @@
 --    :returns: a p tag containint the formatted text
 function li(text_or_symbol, text)
    if text then
-      return p(text_or_symbol .. " " .. text .. vspace(6))
+      return div(p(text_or_symbol)) .. div(p(space(6))) .. div("width=*", p(text .. vspace(6)))
    else
-      return p("• " .. text_or_symbol .. vspace(6))
+      return div(p("•")) .. div(p(space(6))) .. div("width=*", p(text_or_symbol .. vspace(6)))
    end
 end
 
@@ -336,12 +336,13 @@
 --    :arg text: the text to be placed next to the image
 --
 --    :returns: the text wrapped in a paragraph and placed next to the image, The outer tag is a div.
-function li_image(imagepath, text_width_percent, text)
-   return p("<br>") .. div("width=100%", "") ..
-         div(p(img(imagepath))) ..
+function li_image(imagepath, text)
+   return
+      div("width=100%",
+         div(p(vspace(6) .. img(imagepath) .. space(6))) ..
          div(p(space(6))) ..
-         div("width="..text_width_percent.."%", p(text)) ..
-         div("width=100%", "")
+         div("width=*", p(vspace(6) .. text .. vspace(12)))
+      )
 end
 
 -- RST
@@ -423,3 +424,18 @@
       return ("<div>") .. text_or_attributes .. "</div>"
    end
 end
+
+-- RST
+-- .. function:: inline_header(t1, t2)
+--
+--    Creates a line of h3 formatted text followed by normal paragraph text.
+--
+--    :arg t1: text in h3 format.
+--    :arg t2: text in p format.
+--    :returns: header text followed by normal text.
+--
+function inline_header(header, text)
+   return
+      div("width=100%",  font("size=13 color=D1D1D1", header .. " ") ..
+      font("size=12", text))
+end

=== modified file 'data/tribes/scripting/help/controls.lua'
--- data/tribes/scripting/help/controls.lua	2017-02-24 10:29:59 +0000
+++ data/tribes/scripting/help/controls.lua	2017-12-16 17:04:57 +0000
@@ -1,6 +1,6 @@
 set_textdomain("tribes_encyclopedia")
 
-include "scripting/formatting.lua"
+include "scripting/richtext.lua"
 include "txts/help/common_helptexts.lua"
 
 local toggle_minimap_hotkey = help_toggle_minimap_hotkey()
@@ -12,7 +12,6 @@
 return {
    title = _"Controls",
    text =
-      rt(
          h2(_"Window Control") ..
          p(
                -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
@@ -103,5 +102,4 @@
                -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
                dl(help_format_hotkey(pgettext("hotkey", "Delete")), _"Archive/Restore the current message")
           )
-      )
 }

=== modified file 'data/tribes/scripting/help/introduction.lua'
--- data/tribes/scripting/help/introduction.lua	2016-04-02 08:21:25 +0000
+++ data/tribes/scripting/help/introduction.lua	2017-12-16 17:04:57 +0000
@@ -1,13 +1,11 @@
 set_textdomain("tribes_encyclopedia")
 
-include "scripting/formatting.lua"
+include "scripting/richtext.lua"
 include "txts/help/common_helptexts.lua"
 
 return {
    title = _"About Widelands",
    text =
-      rt(
          help_introduction() ..
          help_online_help()
-      )
 }

=== modified file 'data/tribes/scripting/help/tips.lua'
--- data/tribes/scripting/help/tips.lua	2017-01-23 08:38:07 +0000
+++ data/tribes/scripting/help/tips.lua	2017-12-16 17:04:57 +0000
@@ -1,4 +1,4 @@
-include "scripting/formatting.lua"
+include "scripting/richtext.lua"
 
 function get_general_tips()
    include "txts/tips/general_game.lua"
@@ -31,11 +31,10 @@
 end
 
 function format_tips(tips)
-   local text = paragraphdivider()
+   local text = ""
    for index, contents in pairs(tips) do
-      text = text .. listitem_bullet(contents["text"])
+      text = text .. li(contents["text"])
    end
-   text = text .. "</p>"
    return text
 end
 
@@ -69,7 +68,7 @@
       set_textdomain("tribes_encyclopedia")
       return {
         title = _"Tips",
-        text = rt(text)
+        text = text
       }
    end
 }

=== modified file 'data/txts/help/common_helptexts.lua'
--- data/txts/help/common_helptexts.lua	2016-03-27 07:32:33 +0000
+++ data/txts/help/common_helptexts.lua	2017-12-16 17:04:57 +0000
@@ -2,7 +2,7 @@
 -- e.g. for the readme and general in-game help
 -- This cuts down on string maintenance.
 
-include "scripting/formatting.lua"
+include "scripting/richtext.lua"
 
 function help_online_help()
    set_textdomain("texts")

=== modified file 'src/graphic/text/rt_parse.cc'
--- src/graphic/text/rt_parse.cc	2017-05-13 08:36:05 +0000
+++ src/graphic/text/rt_parse.cc	2017-12-16 17:04:57 +0000
@@ -280,6 +280,7 @@
 		tc.allowed_children.insert("p");
 		tc.allowed_children.insert("font");
 		tc.allowed_children.insert("div");
+		tc.allowed_children.insert("img");
 		tc.text_allowed = true;
 		tc.has_closing_tag = true;
 		tag_constraints_["font"] = tc;

=== modified file 'src/graphic/text/rt_render.cc'
--- src/graphic/text/rt_render.cc	2017-12-10 03:03:53 +0000
+++ src/graphic/text/rt_render.cc	2017-12-16 17:04:57 +0000
@@ -678,7 +678,11 @@
 		return 0;
 	}
 	std::shared_ptr<UI::RenderedText> render(TextureCache* /* texture_cache */) override {
-		NEVER_HERE();
+		// TODO(GunChleoc): When using div width=*, some newline nodes are not being consumed.
+		// Since it is working as expected otherwise and I can't find the problem, let's fix this some other time.
+		// Testing can be done with the editor terrains/trees help
+		// NEVER_HERE();
+		return std::shared_ptr<UI::RenderedText>(new UI::RenderedText());
 	}
 	bool is_non_mandatory_space() const override {
 		return true;
@@ -819,6 +823,7 @@
 		}
 
 		for (std::shared_ptr<RenderNode> n : nodes_to_render_) {
+			// TODO(GunChleoc): With div width=*, we are getting newline nodes here, which should have been consumed
 			const auto& renderme = n->render(texture_cache);
 			for (auto& rendered_rect : renderme->rects) {
 				if (rendered_rect->was_visited()) {

=== modified file 'src/wui/encyclopedia_window.cc'
--- src/wui/encyclopedia_window.cc	2017-06-11 20:09:05 +0000
+++ src/wui/encyclopedia_window.cc	2017-12-16 17:04:57 +0000
@@ -40,7 +40,7 @@
 
 constexpr int kPadding = 5;
 constexpr int kTabHeight = 35;
-
+// TODO(GunChleoc): Remove when all help is converted to new font renderer
 const std::string heading(const std::string& text) {
 	return ((boost::format("<rt><p font-size=18 font-weight=bold font-color=D1D1D1>"
 	                       "%s<br></p><p font-size=8> <br></p></rt>") %
@@ -173,9 +173,19 @@
 			cr->resume();
 			table = cr->pop_table();
 		}
-		contents_.at(tab_name)->set_text(
-		   (boost::format("%s%s") % heading(table->get_string("title")) % table->get_string("text"))
-		      .str());
+
+		// TODO(GunChleoc): Remove this when all in-game help has been converted.
+		try {
+			contents_.at(tab_name)->force_new_renderer();
+			contents_.at(tab_name)->set_text(as_message(table->get_string("title"), table->get_string("text")));
+		} catch (const std::exception& e) {
+			log("Encyclopedia: falling back to OLD font renderer: %s\n", e.what());
+			contents_.at(tab_name)->force_new_renderer(false);
+			contents_.at(tab_name)->set_text(
+			   (boost::format("%s%s") % heading(table->get_string("title")) % table->get_string("text"))
+			      .str());
+		}
+
 	} catch (LuaError& err) {
 		contents_.at(tab_name)->set_text(err.what());
 	}


Follow ups